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

arigo at codespeak.net arigo at codespeak.net
Mon Jul 20 23:09:13 CEST 2009


Author: arigo
Date: Mon Jul 20 23:09:12 2009
New Revision: 66460

Modified:
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py
Log:
In-progress.


Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py	Mon Jul 20 23:09:12 2009
@@ -89,6 +89,9 @@
     def getfield(self, ofs):
         return self._fields[ofs]
 
+    def getfield_default(self, ofs, default):
+        return self._fields.get(ofs, default)
+
     def setfield(self, ofs, fieldvalue):
         self._fields[ofs] = fieldvalue
 
@@ -102,25 +105,21 @@
 class __extend__(SpecNode):
     def setup_virtual_node(self, optimizer, box, newinputargs):
         newinputargs.append(box)
-    def teardown_virtual_node(self, optimizer, box, newexitargs):
-        newexitargs.append(box)
+    def teardown_virtual_node(self, optimizer, value, newexitargs):
+        newexitargs.append(value.force_box())
 
 class __extend__(VirtualInstanceSpecNode):
     def setup_virtual_node(self, optimizer, box, newinputargs):
-        import py; py.test.skip("in-progress")
-        vbox = optimizer.make_virtual(box, self.known_class)
+        vvalue = optimizer.make_virtual(box)
         for ofs, subspecnode in self.fields:
             subbox = optimizer.new_box(ofs)
-            vbox.fields[ofs] = subbox
+            vvalue.setfield(ofs, optimizer.getvalue(subbox))
             subspecnode.setup_virtual_node(optimizer, subbox, newinputargs)
-    def teardown_virtual_node(self, optimizer, box, newexitargs):
-        assert isinstance(box, VirtualBox) and box.escaped_to is None
+    def teardown_virtual_node(self, optimizer, value, newexitargs):
+        assert value.is_virtual()
         for ofs, subspecnode in self.fields:
-            try:
-                subbox = box.fields[ofs]
-            except KeyError:
-                subbox = optimizer.new_const(ofs)
-            subspecnode.teardown_virtual_node(optimizer, subbox, newexitargs)
+            subvalue = value.getfield_default(ofs, optimizer.new_const(ofs))
+            subspecnode.teardown_virtual_node(optimizer, subvalue, newexitargs)
 
 
 class Optimizer(object):
@@ -155,6 +154,11 @@
     def known_nonnull(self, box):
         return self.getvalue(box).is_nonnull()
 
+    def make_virtual(self, box):
+        vvalue = VirtualValue(self)
+        self.make_equal_to(box, vvalue)
+        return vvalue
+
     def new_box(self, fieldofs):
         if fieldofs.is_pointer_field():
             if not self.cpu.is_oo:
@@ -198,8 +202,7 @@
                 self.optimize_default(op)
         self.loop.operations = self.newoperations
 
-    def emit_operation(self, op):
-        must_clone = True
+    def emit_operation(self, op, must_clone=True):
         for i in range(len(op.args)):
             arg = op.args[i]
             if arg in self.values:
@@ -223,15 +226,17 @@
         # otherwise, the operation remains
         self.emit_operation(op)
 
-    def XXX_optimize_JUMP(self, op):
+    def optimize_JUMP(self, op):
         orgop = self.loop.operations[-1]
         exitargs = []
         specnodes = orgop.jump_target.specnodes
         assert len(op.args) == len(specnodes)
         for i in range(len(specnodes)):
-            specnodes[i].teardown_virtual_node(self, op.args[i], exitargs)
+            value = self.getvalue(op.args[i])
+            specnodes[i].teardown_virtual_node(self, value, exitargs)
+        op = op.clone()
         op.args = exitargs
-        #XXX return op
+        self.emit_operation(op, must_clone=False)
 
     def optimize_guard(self, op):
         value = self.getvalue(op.args[0])

Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py	Mon Jul 20 23:09:12 2009
@@ -376,7 +376,46 @@
         # to be complete, we also check the no-opt case where most comparisons
         # are not removed.  The exact set of comparisons removed depends on
         # the details of the algorithm...
-        expected2 = ops
+        expected2 = """
+        [p0, p1, p2]
+        i1 = oononnull(p0)
+        guard_true(i1)
+          fail()
+        i2 = ooisnull(p0)
+        guard_false(i2)
+          fail()
+        i3 = oononnull(p0)
+        guard_true(i3)
+          fail()
+        i4 = ooisnull(p0)
+        guard_false(i4)
+          fail()
+        i5 = oononnull(p0)
+        guard_true(i5)
+          fail()
+        i6 = ooisnull(p0)
+        guard_false(i6)
+          fail()
+        i7 = ooisnot(p0, p1)
+        guard_true(i7)
+          fail()
+        i8 = oois(p0, p1)
+        guard_false(i8)
+          fail()
+        i9 = ooisnot(p0, p2)
+        guard_true(i9)
+          fail()
+        i10 = oois(p0, p2)
+        guard_false(i10)
+          fail()
+        i11 = ooisnot(p2, p1)
+        guard_true(i11)
+          fail()
+        i12 = oois(p2, p1)
+        guard_false(i12)
+          fail()
+        jump(p0, p1, p2)
+        """
         self.optimize_loop(ops, 'Not, Not, Not', expected2)
 
     def test_virtual_default_field(self):



More information about the Pypy-commit mailing list