[pypy-svn] r78315 - in pypy/branch/jit-unroll-loops/pypy/jit/metainterp: optimizeopt test

hakanardo at codespeak.net hakanardo at codespeak.net
Tue Oct 26 19:57:58 CEST 2010


Author: hakanardo
Date: Tue Oct 26 19:57:57 2010
New Revision: 78315

Modified:
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/optimizer.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/unroll.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/virtualize.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_virtual.py
Log:
virtuals with circular refs

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/optimizer.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/optimizer.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/optimizer.py	Tue Oct 26 19:57:57 2010
@@ -47,9 +47,14 @@
     def get_key_box(self):
         return self.box
 
-    # FIXME: Reise get_args_for_fail instead?
-    def get_forced_boxes(self):
-        return [self.force_box()]
+    # FIXME: Reuse get_args_for_fail instead?
+    def get_forced_boxes(self, already_seen):
+        key = self.get_key_box()
+        if key in already_seen:
+            return []
+        box = self.force_box()
+        already_seen.append(self.get_key_box())
+        return [box]
 
     def get_args_for_fail(self, modifier):
         pass

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/unroll.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/unroll.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/unroll.py	Tue Oct 26 19:57:57 2010
@@ -52,7 +52,7 @@
         
         inputargs = []
         for arg in jump_args:
-            for a in self.getvalue(arg).get_forced_boxes():
+            for a in self.getvalue(arg).get_forced_boxes([]):
                 if not isinstance(a, Const):
                     inputargs.append(a)
 
@@ -75,7 +75,7 @@
                 args = []
                 #for arg in newop.getarglist():
                 for arg in [argmap[a] for a in inputargs]:
-                    args.extend(self.getvalue(arg).get_forced_boxes())
+                    args.extend(self.getvalue(arg).get_forced_boxes([]))
                 newop.initarglist(args + inputargs[len(args):])
 
             #print 'P: ', str(newop)
@@ -104,7 +104,7 @@
                             jmp = self.optimizer.newoperations[-1]
                             if jmp.getopnum() == rop.JUMP:
                                 newval = self.getvalue(argmap[a])
-                                newarg = newval.get_forced_boxes()
+                                newarg = newval.get_forced_boxes([])
                                 jmp.initarglist(jmp.getarglist() + newarg)
 
         return inputargs

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/virtualize.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/virtualize.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/virtualize.py	Tue Oct 26 19:57:57 2010
@@ -121,13 +121,17 @@
                 fieldvalue = self._fields[ofs]
                 fieldvalue.get_args_for_fail(modifier)
 
-    # FIXME: circular references
-    def get_forced_boxes(self):
+    def get_forced_boxes(self, already_seen):
+        key = self.get_key_box()
+        if key in already_seen:
+            return []
+        already_seen.append(key)
         if self.box is None:
             lst = self._get_field_descr_list()
             fieldboxes = []
             for ofs in lst:
-                fieldboxes.extend(self._fields[ofs].get_forced_boxes())
+                boxes = self._fields[ofs].get_forced_boxes(already_seen)
+                fieldboxes.extend(boxes)
             return fieldboxes
         else:
             return [self.box]
@@ -204,11 +208,15 @@
     def _make_virtual(self, modifier):
         return modifier.make_varray(self.arraydescr)
 
-    def get_forced_boxes(self):
+    def get_forced_boxes(self, already_seen):
+        key = self.get_key_box()
+        if key in already_seen:
+            return []
+        already_seen.append(key)
         if self.box is None:
             boxes = []
             for itemvalue in self._items:
-                boxes.extend(itemvalue.get_forced_boxes())
+                boxes.extend(itemvalue.get_forced_boxes(already_seen))
             return boxes
         else:
             return [self.box]

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_virtual.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_virtual.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_virtual.py	Tue Oct 26 19:57:57 2010
@@ -34,6 +34,32 @@
         self.check_loops(new=0, new_with_vtable=0,
                                 getfield_gc=0, setfield_gc=0)
 
+    def test_virtualized_circular1(self):
+        class MyNode():
+            pass
+        myjitdriver = JitDriver(greens = [], reds = ['n', 'node'])
+        def f(n):
+            node = MyNode()
+            node.value = 0
+            node.extra = 0
+            node.ref = node
+            while n > 0:
+                myjitdriver.can_enter_jit(n=n, node=node)
+                myjitdriver.jit_merge_point(n=n, node=node)
+                next = MyNode()
+                next.value = node.ref.value + n
+                next.extra = node.ref.extra + 1
+                next.ref = next
+                node = next
+                n -= 1
+            return node.value * node.extra
+        assert f(10) == 55 * 10
+        res = self.meta_interp(f, [10])
+        assert res == 55 * 10
+        self.check_loop_count(1)
+        self.check_loops(new=0, new_with_vtable=0,
+                                getfield_gc=0, setfield_gc=0)
+
     def test_virtualized_float(self):
         myjitdriver = JitDriver(greens = [], reds = ['n', 'node'])
         def f(n):



More information about the Pypy-commit mailing list