[pypy-svn] r63096 - in pypy/branch/pyjitpl5/pypy/jit: backend/llgraph metainterp metainterp/test
arigo at codespeak.net
arigo at codespeak.net
Thu Mar 19 20:12:51 CET 2009
Author: arigo
Date: Thu Mar 19 20:12:50 2009
New Revision: 63096
Modified:
pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_loop.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py
Log:
Change 'liveboxes' to not be allowed to contain Consts any more.
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py Thu Mar 19 20:12:50 2009
@@ -134,8 +134,8 @@
llimpl.compile_add_failnum(c, len(self.guard_ops))
self.guard_ops.append(op)
for box in op.liveboxes:
- if isinstance(box, history.Box):
- llimpl.compile_add_livebox(c, var2index[box])
+ assert isinstance(box, history.Box)
+ llimpl.compile_add_livebox(c, var2index[box])
if op.opnum == rop.MERGE_POINT:
self.jumptarget2loop[op] = c, i
if from_guard is not None:
@@ -175,19 +175,8 @@
if gf.returns:
return gf.retbox
- def getrealbox(self, guard_op, argindex):
- box = None
- i = 0
- j = argindex
- while j >= 0:
- box = guard_op.liveboxes[i]
- i += 1
- if isinstance(box, history.Box):
- j -= 1
- return box
-
def getvaluebox(self, frame, guard_op, argindex):
- box = self.getrealbox(guard_op, argindex)
+ box = guard_op.liveboxes[argindex]
if isinstance(box, history.BoxInt):
value = llimpl.frame_int_getvalue(frame, argindex)
return history.BoxInt(value)
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py Thu Mar 19 20:12:50 2009
@@ -441,6 +441,8 @@
def prepare_rebuild_ops(self, instnode, liveboxes, rebuild_ops, memo):
box = instnode.source
+ if not isinstance(box, Box):
+ return box
if box in memo:
return memo[box]
if instnode.virtual:
@@ -519,12 +521,12 @@
for node in self.nodes.values():
for ofs, subnode in node.dirtyfields.items():
box = node.source
- if box not in memo:
+ if box not in memo and isinstance(box, Box):
liveboxes.append(box)
memo[box] = box
#index = (rev_boxes[box] << FLAG_SHIFT) | FLAG_BOXES_FROM_FRAME
fieldbox = subnode.source
- if fieldbox not in memo:
+ if fieldbox not in memo and isinstance(fieldbox, Box):
liveboxes.append(fieldbox)
memo[fieldbox] = fieldbox
#fieldindex = ((rev_boxes[fieldbox] << FLAG_SHIFT) |
@@ -545,8 +547,9 @@
# end of code for dirtyfields support
if not we_are_translated():
- items = [box for box in liveboxes if isinstance(box, Box)]
- assert len(dict.fromkeys(items)) == len(items)
+ for box in liveboxes:
+ assert isinstance(box, Box)
+ assert len(dict.fromkeys(liveboxes)) == len(liveboxes)
op.args = self.new_arguments(op)
op.liveboxes = liveboxes
@@ -862,7 +865,7 @@
if resbox is not None:
currentvalues[op.result] = resbox
# done
- return get_in_list(currentvalues, guard_op.unoptboxes)
+ return [currentvalues[box] for box in guard_op.unoptboxes]
def partition(array, left, right):
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py Thu Mar 19 20:12:50 2009
@@ -598,15 +598,19 @@
#self.starts_with_greens()
#assert len(argboxes) == len(self.graph.getargs())
- def setup_resume_at_op(self, pc, envlength, liveboxes, lbindex,
+ def setup_resume_at_op(self, pc, const_part, liveboxes, lbindex,
exception_target):
if not we_are_translated():
check_args(*liveboxes)
self.pc = pc
- self.env = liveboxes[lbindex:lbindex+envlength]
self.exception_target = exception_target
- assert len(self.env) == envlength
- return lbindex + envlength
+ self.env = []
+ for box in const_part:
+ if box is None:
+ box = liveboxes[lbindex]
+ lbindex += 1
+ self.env.append(box)
+ return lbindex
def run_one_step(self):
# Execute the frame forward. This method contains a loop that leaves
@@ -628,18 +632,26 @@
return
if isinstance(self.metainterp.history, history.BlackHole):
return
+ saved_pc = self.pc
+ self.pc = pc
+ # XXX 'key' should be shared, either partially or if possible totally
+ key = []
liveboxes = []
for frame in self.metainterp.framestack:
+ const_part = []
for framebox in frame.env:
assert framebox is not None
- liveboxes.append(framebox)
+ if isinstance(framebox, Box):
+ liveboxes.append(framebox)
+ framebox = None
+ const_part.append(framebox)
+ key.append((frame.jitcode, frame.pc, const_part,
+ frame.exception_target))
if box is not None:
extraargs = [box] + extraargs
guard_op = self.metainterp.history.record(opnum, extraargs, None)
guard_op.liveboxes = liveboxes
- saved_pc = self.pc
- self.pc = pc
- guard_op.key = self.metainterp.record_state()
+ guard_op.key = key
self.pc = saved_pc
return guard_op
@@ -941,12 +953,10 @@
boxes_from_frame = []
index = 0
for box in guard_op.liveboxes:
- if isinstance(box, Box):
- newbox = self.cpu.getvaluebox(guard_failure.frame,
- guard_op, index)
- index += 1
- else:
- newbox = box
+ assert isinstance(box, Box)
+ newbox = self.cpu.getvaluebox(guard_failure.frame,
+ guard_op, index)
+ index += 1
boxes_from_frame.append(newbox)
if guard_op.rebuild_ops is not None:
newboxes = optimize.rebuild_boxes_from_guard_failure(
@@ -979,20 +989,12 @@
self._debug_history.append(['guard_failure', None, None])
self.framestack = []
nbindex = 0
- for jitcode, pc, envlength, exception_target in key:
+ for jitcode, pc, const_part, exception_target in key:
f = self.newframe(jitcode)
- nbindex = f.setup_resume_at_op(pc, envlength, newboxes, nbindex,
+ nbindex = f.setup_resume_at_op(pc, const_part, newboxes, nbindex,
exception_target)
assert nbindex == len(newboxes), "too many newboxes!"
- def record_state(self):
- # XXX this whole function should do a sharing
- key = []
- for frame in self.framestack:
- key.append((frame.jitcode, frame.pc, len(frame.env),
- frame.exception_target))
- return key
-
# ____________________________________________________________
# construction-time interface
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_loop.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_loop.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_loop.py Thu Mar 19 20:12:50 2009
@@ -5,6 +5,7 @@
from pypy.jit.metainterp.test.test_basic import LLJitMixin
from pypy.jit.metainterp.policy import StopAtXPolicy
from pypy.jit.metainterp.resoperation import rop
+from pypy.jit.metainterp import history
class TestLoop(LLJitMixin):
specialize = False
@@ -163,6 +164,13 @@
self.check_loop_count(1)
# the 'char_eq' and following 'guard' should be constant-folded
self.check_loops(char_eq=0, guard_true=1, guard_false=0)
+ if self.basic:
+ for op in get_stats().loops[0].operations:
+ if op.getopname() == 'guard_true':
+ liveboxes = op.liveboxes
+ assert len(liveboxes) == 2 # x, y (in some order)
+ assert isinstance(liveboxes[0], history.BoxInt)
+ assert isinstance(liveboxes[1], history.BoxInt)
def test_interp_many_paths(self):
myjitdriver = JitDriver(greens = ['i'], reds = ['x', 'node'])
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py Thu Mar 19 20:12:50 2009
@@ -453,10 +453,11 @@
])
guard_op = spec.loop.operations[-2]
assert guard_op.getopname() == 'guard_true'
- assert guard_op.liveboxes == [G.sum2, ConstInt(124)]
+ assert guard_op.liveboxes == [G.sum2]
vt = cpu.cast_adr_to_int(node_vtable_adr)
assert ([op.getopname() for op in guard_op.rebuild_ops] ==
['new_with_vtable', 'setfield_gc'])
+ assert guard_op.rebuild_ops[1].args[1] == ConstInt(124)
# ____________________________________________________________
More information about the Pypy-commit
mailing list