[pypy-svn] r66204 - in pypy/branch/pyjitpl5/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Tue Jul 14 14:44:43 CEST 2009


Author: arigo
Date: Tue Jul 14 14:44:42 2009
New Revision: 66204

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py
Log:
After a guard_value, replace the Box with the corresponding Const
everywhere it is stored, in addition to returning it.  Allows
better code to be generated for a case like the one shown in
test_virtualizable, without needing hint(promote=True) all over
the place.


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	Tue Jul 14 14:44:42 2009
@@ -896,6 +896,7 @@
         if isinstance(box, Box):
             promoted_box = box.constbox()
             self.generate_guard(pc, rop.GUARD_VALUE, box, [promoted_box])
+            self.metainterp.replace_box(box, promoted_box)
             return promoted_box
         else:
             return box     # no promotion needed, already a Const
@@ -1644,6 +1645,18 @@
                                     descr=vinfo.array_descrs[k])
         assert i + 1 == len(self.virtualizable_boxes)
 
+    def replace_box(self, oldbox, newbox):
+        for frame in self.framestack:
+            boxes = frame.env
+            for i in range(len(boxes)):
+                if boxes[i] is oldbox:
+                    boxes[i] = newbox
+        if self.staticdata.virtualizable_info is not None:
+            boxes = self.virtualizable_boxes
+            for i in range(len(boxes)):
+                if boxes[i] is oldbox:
+                    boxes[i] = newbox
+
 
 class GenerateMergePoint(Exception):
     def __init__(self, args, target_loop):

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py	Tue Jul 14 14:44:42 2009
@@ -3,6 +3,7 @@
 from pypy.rpython.annlowlevel import llhelper
 from pypy.jit.metainterp.policy import StopAtXPolicy
 from pypy.rlib.jit import JitDriver, hint
+from pypy.rlib.rarithmetic import intmask
 from pypy.jit.metainterp.test.test_basic import LLJitMixin, OOJitMixin
 from pypy.rpython.lltypesystem.rvirtualizable2 import VABLERTIPTR
 from pypy.rpython.lltypesystem.rvirtualizable2 import VirtualizableAccessor
@@ -641,6 +642,33 @@
                      " only sometimes, so that it's not seen during tracing")
 
 
+    def test_promote_index_in_virtualizable_list(self):
+        jitdriver = JitDriver(greens = [], reds = ['frame', 'n'],
+                              virtualizables = ['frame'])
+        class Frame(object):
+            _virtualizable2_ = ['stackpos', 'stack[*]']
+
+        def f(n):
+            frame = Frame()
+            frame.stack = [42, 0, 0]
+            frame.stackpos = 1
+            while n > 0:
+                jitdriver.can_enter_jit(frame=frame, n=n)
+                jitdriver.jit_merge_point(frame=frame, n=n)
+                popped = frame.stack[frame.stackpos]
+                frame.stackpos -= 1
+                to_push = intmask(popped * 3)
+                frame.stack[frame.stackpos] = to_push
+                frame.stackpos += 1
+                n -= 1
+            return frame.stack[0]
+
+        res = self.meta_interp(f, [70], listops=True)
+        assert res == intmask(42 ** 70)
+        self.check_loops(int_add=0,
+                         int_sub=1)   # for 'n -= 1' only
+
+
 class TestOOtype(#ExplicitVirtualizableTests,
                  ImplicitVirtualizableTests,
                  OOJitMixin):



More information about the Pypy-commit mailing list