[pypy-svn] r77110 - in pypy/branch/resoperation-refactoring/pypy/jit/metainterp: . optimizeopt
antocuni at codespeak.net
antocuni at codespeak.net
Thu Sep 16 14:41:42 CEST 2010
Author: antocuni
Date: Thu Sep 16 14:41:40 2010
New Revision: 77110
Modified:
pypy/branch/resoperation-refactoring/pypy/jit/metainterp/compile.py
pypy/branch/resoperation-refactoring/pypy/jit/metainterp/graphpage.py
pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizefindnode.py
pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/heap.py
pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/optimizer.py
pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/rewrite.py
pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/virtualize.py
pypy/branch/resoperation-refactoring/pypy/jit/metainterp/pyjitpl.py
pypy/branch/resoperation-refactoring/pypy/jit/metainterp/resoperation.py
pypy/branch/resoperation-refactoring/pypy/jit/metainterp/simple_optimize.py
Log:
(antocuni, david) use the new ResOperation interface a bit here and there until test_basic passes
Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/compile.py (original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/compile.py Thu Sep 16 14:41:40 2010
@@ -238,7 +238,7 @@
def make_a_counter_per_value(self, guard_value_op):
assert guard_value_op.opnum == rop.GUARD_VALUE
- box = guard_value_op.args[0]
+ box = guard_value_op.getarg(0)
try:
i = guard_value_op.fail_args.index(box)
except ValueError:
@@ -546,7 +546,7 @@
# e.g. loop_tokens_done_with_this_frame_void[0]
# Replace the operation with the real operation we want, i.e. a FINISH
descr = target_loop_token.finishdescr
- args = [op.getarg(i) for i in range(op.numargs())]
+ args = op.sliceargs(0, op.numargs())
new_op = ResOperation(rop.FINISH, args, None, descr=descr)
new_loop.operations[-1] = new_op
Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/graphpage.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/graphpage.py (original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/graphpage.py Thu Sep 16 14:41:40 2010
@@ -191,7 +191,9 @@
def getlinks(self):
boxes = {}
for op in self.all_operations:
- for box in op.args + [op.result]:
+ args = op.sliceargs(0, op.numargs())
+ args.append(op.result)
+ for box in args:
if getattr(box, 'is_box', False):
boxes[box] = True
links = {}
Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizefindnode.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizefindnode.py (original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizefindnode.py Thu Sep 16 14:41:40 2010
@@ -160,7 +160,8 @@
break
else:
# all constant arguments: we can constant-fold
- argboxes = [self.get_constant_box(arg) for arg in op.args]
+ argboxes = [self.get_constant_box(op.getarg(i))
+ for i in range(op.numargs())]
resbox = execute_nonspec(self.cpu, None,
op.opnum, argboxes, op.descr)
self.set_constant_node(op.result, resbox.constbox())
Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/heap.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/heap.py (original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/heap.py Thu Sep 16 14:41:40 2010
@@ -45,7 +45,7 @@
op = self.lazy_setfields.get(descr, None)
if op is None:
return None
- return self.getvalue(op.args[1])
+ return self.getvalue(op.getarg(1))
return d.get(value, None)
def cache_arrayitem_value(self, descr, value, indexvalue, fieldvalue, write=False):
@@ -167,9 +167,10 @@
# - CALL_MAY_FORCE: "call_may_force/setfield_gc/guard_not_forced"
# - is_ovf(): "int_add_ovf/setfield_gc/guard_no_overflow"
opnum = prevop.opnum
+ lastop_args = lastop.sliceargs(0, lastop.numargs())
if ((prevop.is_comparison() or opnum == rop.CALL_MAY_FORCE
or prevop.is_ovf())
- and prevop.result not in lastop.args):
+ and prevop.result not in lastop_args):
newoperations[-2] = lastop
newoperations[-1] = prevop
@@ -189,9 +190,9 @@
# the only really interesting case that we need to handle in the
# guards' resume data is that of a virtual object that is stored
# into a field of a non-virtual object.
- value = self.getvalue(op.args[0])
+ value = self.getvalue(op.getarg(0))
assert not value.is_virtual() # it must be a non-virtual
- fieldvalue = self.getvalue(op.args[1])
+ fieldvalue = self.getvalue(op.getarg(1))
if fieldvalue.is_virtual():
# this is the case that we leave to resume.py
pendingfields.append((descr, value.box,
@@ -207,11 +208,11 @@
if write:
self.lazy_setfields_descrs.append(op.descr)
else:
- if self.getvalue(op1.args[0]) is not value:
+ if self.getvalue(op1.getarg(0)) is not value:
self.force_lazy_setfield(op.descr)
def optimize_GETFIELD_GC(self, op):
- value = self.getvalue(op.args[0])
+ value = self.getvalue(op.getarg(0))
self.force_lazy_setfield_if_necessary(op, value)
# check if the field was read from another getfield_gc just before
# or has been written to recently
@@ -228,16 +229,16 @@
self.cache_field_value(op.descr, value, fieldvalue)
def optimize_SETFIELD_GC(self, op):
- value = self.getvalue(op.args[0])
- fieldvalue = self.getvalue(op.args[1])
+ value = self.getvalue(op.getarg(0))
+ fieldvalue = self.getvalue(op.getarg(1))
self.force_lazy_setfield_if_necessary(op, value, write=True)
self.lazy_setfields[op.descr] = op
# remember the result of future reads of the field
self.cache_field_value(op.descr, value, fieldvalue, write=True)
def optimize_GETARRAYITEM_GC(self, op):
- value = self.getvalue(op.args[0])
- indexvalue = self.getvalue(op.args[1])
+ value = self.getvalue(op.getarg(0))
+ indexvalue = self.getvalue(op.getarg(1))
fieldvalue = self.read_cached_arrayitem(op.descr, value, indexvalue)
if fieldvalue is not None:
self.make_equal_to(op.result, fieldvalue)
@@ -249,9 +250,9 @@
def optimize_SETARRAYITEM_GC(self, op):
self.emit_operation(op)
- value = self.getvalue(op.args[0])
- fieldvalue = self.getvalue(op.args[2])
- indexvalue = self.getvalue(op.args[1])
+ value = self.getvalue(op.getarg(0))
+ fieldvalue = self.getvalue(op.getarg(2))
+ indexvalue = self.getvalue(op.getarg(1))
self.cache_arrayitem_value(op.descr, value, indexvalue, fieldvalue,
write=True)
Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/optimizer.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/optimizer.py (original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/optimizer.py Thu Sep 16 14:41:40 2010
@@ -349,12 +349,12 @@
descr.store_final_boxes(op, newboxes)
#
if op.opnum == rop.GUARD_VALUE:
- if self.getvalue(op.args[0]) in self.bool_boxes:
+ if self.getvalue(op.getarg(0)) in self.bool_boxes:
# Hack: turn guard_value(bool) into guard_true/guard_false.
# This is done after the operation is emitted, to let
# store_final_boxes_in_guard set the guard_opnum field
# of the descr to the original rop.GUARD_VALUE.
- constvalue = op.args[1].getint()
+ constvalue = op.getarg(1).getint()
if constvalue == 0:
opnum = rop.GUARD_FALSE
elif constvalue == 1:
@@ -362,7 +362,7 @@
else:
raise AssertionError("uh?")
op.opnum = opnum
- op.args = [op.args[0]]
+ op.args = [op.getarg(0)]
else:
# a real GUARD_VALUE. Make it use one counter per value.
descr.make_a_counter_per_value(op)
@@ -390,7 +390,8 @@
break
else:
# all constant arguments: constant-fold away
- argboxes = [self.get_constant_box(arg) for arg in op.args]
+ argboxes = [self.get_constant_box(op.getarg(i))
+ for i in range(op.numargs())]
resbox = execute_nonspec(self.cpu, None,
op.opnum, argboxes, op.descr)
self.make_constant(op.result, resbox.constbox())
Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/rewrite.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/rewrite.py (original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/rewrite.py Thu Sep 16 14:41:40 2010
@@ -128,7 +128,8 @@
self.emit_operation(op)
def optimize_CALL_PURE(self, op):
- for arg in op.args:
+ for i in range(op.numargs()):
+ arg = op.getarg(i)
if self.get_constant_box(arg) is None:
break
else:
@@ -136,7 +137,8 @@
self.make_constant(op.result, op.getarg(0))
return
# replace CALL_PURE with just CALL
- self.emit_operation(ResOperation(rop.CALL, op.args[1:], op.result,
+ args = op.sliceargs(1, op.numargs())
+ self.emit_operation(ResOperation(rop.CALL, args, op.result,
op.descr))
def optimize_guard(self, op, constbox, emit_operation=True):
value = self.getvalue(op.getarg(0))
@@ -178,7 +180,8 @@
old_guard_op = self.optimizer.newoperations[value.last_guard_index]
old_opnum = old_guard_op.opnum
old_guard_op.opnum = rop.GUARD_VALUE
- old_guard_op.args = [old_guard_op.getarg(0), op.getarg(1)]
+ # XXX XXX: implement it when the refactoring is complete
+ old_guard_op._args = [old_guard_op.getarg(0), op.getarg(1)]
# hack hack hack. Change the guard_opnum on
# old_guard_op.descr so that when resuming,
# the operation is not skipped by pyjitpl.py.
@@ -217,7 +220,8 @@
# it was a guard_nonnull, which we replace with a
# guard_nonnull_class.
old_guard_op.opnum = rop.GUARD_NONNULL_CLASS
- old_guard_op.args = [old_guard_op.getarg(0), op.getarg(1)]
+ # XXX XXX: implement it when the refactoring is complete
+ old_guard_op._args = [old_guard_op.getarg(0), op.getarg(1)]
# hack hack hack. Change the guard_opnum on
# old_guard_op.descr so that when resuming,
# the operation is not skipped by pyjitpl.py.
Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/virtualize.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/virtualize.py (original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/virtualize.py Thu Sep 16 14:41:40 2010
@@ -292,7 +292,7 @@
for i in range(len(specnodes)):
value = self.getvalue(op.getarg(i))
specnodes[i].teardown_virtual_node(self, value, exitargs)
- op.args = exitargs[:]
+ op.setarglist(exitargs[:])
self.emit_operation(op)
def optimize_VIRTUAL_REF(self, op):
@@ -441,7 +441,7 @@
return # 0-length arraycopy
descr = op.getarg(0)
assert isinstance(descr, AbstractDescr)
- args = [op.getarg(i) for i in range(1, op.numargs())]
+ args = op.sliceargs(1, op.numargs())
self.emit_operation(ResOperation(rop.CALL, args, op.result,
descr))
Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/pyjitpl.py Thu Sep 16 14:41:40 2010
@@ -2090,7 +2090,7 @@
op = self.history.operations[-1]
assert op.opnum == rop.CALL
resbox_as_const = resbox.constbox()
- for i in op.numarg():
+ for i in range(op.numargs()):
if not isinstance(op.getarg(i), Const):
break
else:
@@ -2101,7 +2101,7 @@
# not all constants (so far): turn CALL into CALL_PURE, which might
# be either removed later by optimizeopt or turned back into CALL.
op.opnum = rop.CALL_PURE
- # XXX XXX replace...
+ # XXX XXX replace when the resoperation refactoring has been finished
op._args = [resbox_as_const] + op._args
return resbox
Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/resoperation.py (original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/resoperation.py Thu Sep 16 14:41:40 2010
@@ -21,6 +21,12 @@
self.result = result
self.setdescr(descr)
+ # XXX: just for debugging during the refactoring, kill me
+ def __setattr__(self, attr, value):
+ if attr == 'args':
+ import pdb;pdb.set_trace()
+ object.__setattr__(self, attr, value)
+
def getarg(self, i):
return self._args[i]
@@ -30,6 +36,12 @@
def numargs(self):
return len(self._args)
+ def setarglist(self, args):
+ self._args = args
+
+ def sliceargs(self, start, stop):
+ return [self.getarg(i) for i in range(start, stop)]
+
def setdescr(self, descr):
# for 'call', 'new', 'getfield_gc'...: the descr is a prebuilt
# instance provided by the backend holding details about the type
Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/simple_optimize.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/simple_optimize.py (original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/simple_optimize.py Thu Sep 16 14:41:40 2010
@@ -14,11 +14,13 @@
if op.opnum == rop.ARRAYCOPY:
descr = op.args[0]
assert isinstance(descr, AbstractDescr)
- op = ResOperation(rop.CALL, op.args[1:], op.result, descr=descr)
+ args = op.sliceargs(1, op.numargs())
+ op = ResOperation(rop.CALL, args, op.result, descr=descr)
elif op.opnum == rop.CALL_PURE:
- op = ResOperation(rop.CALL, op.args[1:], op.result, op.descr)
+ args = op.sliceargs(1, op.numargs())
+ op = ResOperation(rop.CALL, args, op.result, op.descr)
elif op.opnum == rop.VIRTUAL_REF:
- op = ResOperation(rop.SAME_AS, [op.args[0]], op.result)
+ op = ResOperation(rop.SAME_AS, [op.getarg(0)], op.result)
elif op.opnum == rop.VIRTUAL_REF_FINISH:
return []
return [op]
More information about the Pypy-commit
mailing list