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

arigo at codespeak.net arigo at codespeak.net
Tue Aug 25 19:22:22 CEST 2009


Author: arigo
Date: Tue Aug 25 19:22:21 2009
New Revision: 67205

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/optimizeopt.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimizefindnode.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimizeopt.py
Log:
Tests and (hopefully) fix.  I'm not 100% convinced that the fix
is the Best Possible Solution, but it's a minimal change...


Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py	Tue Aug 25 19:22:21 2009
@@ -396,6 +396,9 @@
     def nonconstbox(self):
         return self
 
+    def changevalue_box(self, srcbox):
+        raise NotImplementedError
+
     def __repr__(self):
         result = str(self)
         if self._extended_display:
@@ -457,6 +460,9 @@
     def repr_rpython(self):
         return repr_rpython(self, 'bi')
 
+    def changevalue_box(self, srcbox):
+        self.changevalue_int(srcbox.getint())
+
     changevalue_int = __init__
 
 class BoxPtr(Box):
@@ -491,6 +497,9 @@
     def repr_rpython(self):
         return repr_rpython(self, 'bp')
 
+    def changevalue_box(self, srcbox):
+        self.changevalue_ptr(srcbox.getptr_base())
+
     _getrepr_ = repr_pointer
     changevalue_ptr = __init__
 
@@ -529,6 +538,9 @@
     def repr_rpython(self):
         return repr_rpython(self, 'bo')
 
+    def changevalue_box(self, srcbox):
+        self.changevalue_obj(srcbox.getobj())
+
     _getrepr_ = repr_object
     changevalue_obj = __init__
 

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/optimizeopt.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/optimizeopt.py	Tue Aug 25 19:22:21 2009
@@ -30,15 +30,16 @@
 
 # ____________________________________________________________
 
-LEVEL_UNKNOWN    = 0
-LEVEL_NONNULL    = 1
-LEVEL_KNOWNCLASS = 2     # might also mean KNOWNARRAYDESCR, for arrays
-LEVEL_CONSTANT   = 3
+LEVEL_UNKNOWN    = '\x00'
+LEVEL_NONNULL    = '\x01'
+LEVEL_KNOWNCLASS = '\x02'     # might also mean KNOWNARRAYDESCR, for arrays
+LEVEL_CONSTANT   = '\x03'
 
 
 class OptValue(object):
-    _attrs_ = ('box', 'level', '_fields')
+    _attrs_ = ('box', 'level', 'missing', '_fields')
     level = LEVEL_UNKNOWN
+    missing = False   # is True if we don't know the value yet (for virtuals)
     _fields = None
 
     def __init__(self, box):
@@ -55,6 +56,14 @@
     def get_args_for_fail(self, modifier):
         pass
 
+    def initialize_if_missing(self, srcbox):
+        if self.missing:
+            dstbox = self.box
+            if dstbox is not None:
+                assert isinstance(dstbox, Box)
+                dstbox.changevalue_box(srcbox)
+            self.missing = False
+
     def is_constant(self):
         return self.level == LEVEL_CONSTANT
 
@@ -281,7 +290,9 @@
         for ofs, subspecnode in self.fields:
             subbox = optimizer.new_box(ofs)
             subspecnode.setup_virtual_node(optimizer, subbox, newinputargs)
-            vvalue.setfield(ofs, optimizer.getvalue(subbox))
+            vvaluefield = optimizer.getvalue(subbox)
+            vvaluefield.missing = True
+            vvalue.setfield(ofs, vvaluefield)
     def _setup_virtual_node_1(self, optimizer, box):
         raise NotImplementedError
     def teardown_virtual_node(self, optimizer, value, newexitargs):
@@ -305,7 +316,9 @@
             subbox = optimizer.new_box_item(self.arraydescr)
             subspecnode = self.items[index]
             subspecnode.setup_virtual_node(optimizer, subbox, newinputargs)
-            vvalue.setitem(index, optimizer.getvalue(subbox))
+            vvalueitem = optimizer.getvalue(subbox)
+            vvalueitem.missing = True
+            vvalue.setitem(index, vvalueitem)
     def teardown_virtual_node(self, optimizer, value, newexitargs):
         assert value.is_virtual()
         const = optimizer.new_const_item(self.arraydescr)
@@ -346,7 +359,6 @@
                 return box
         else:
             return box
-        
 
     def getvalue(self, box):
         box = self.getinterned(box)
@@ -623,6 +635,7 @@
             # optimizefindnode should ensure that fieldvalue is found
             fieldvalue = value.getfield(op.descr, None)
             assert fieldvalue is not None
+            fieldvalue.initialize_if_missing(op.result)
             self.make_equal_to(op.result, fieldvalue)
         else:
             # check if the field was read from another getfield_gc just before
@@ -688,6 +701,7 @@
             # optimizefindnode should ensure that itemvalue is found
             itemvalue = value.getitem(indexbox.getint(), None)
             assert itemvalue is not None
+            itemvalue.initialize_if_missing(op.result)
             self.make_equal_to(op.result, itemvalue)
         else:
             value.make_nonnull()

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimizefindnode.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimizefindnode.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimizefindnode.py	Tue Aug 25 19:22:21 2009
@@ -67,6 +67,7 @@
     ssize = cpu.sizeof(S)
     adescr = cpu.fielddescrof(S, 'a')
     bdescr = cpu.fielddescrof(S, 'b')
+    sbox = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S)))
     arraydescr2 = cpu.arraydescrof(lltype.GcArray(lltype.Ptr(S)))
 
     cpu.class_sizes = {cpu.cast_adr_to_int(node_vtable_adr): cpu.sizeof(NODE),
@@ -106,6 +107,7 @@
     ssize = cpu.typedescrof(S)
     adescr = cpu.fielddescrof(S, 'a')
     bdescr = cpu.fielddescrof(S, 'b')
+    sbox = BoxObj(ootype.cast_to_object(ootype.new(S)))
     arraydescr2 = cpu.arraydescrof(ootype.Array(S))
 
     # force a consistent order

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimizeopt.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimizeopt.py	Tue Aug 25 19:22:21 2009
@@ -1041,6 +1041,66 @@
         """
         self.optimize_loop(ops, 'Not, Not', ops)
 
+    def test_bug_1(self):
+        ops = """
+        [i0, p1]
+        p4 = getfield_gc(p1, descr=nextdescr)
+        i2 = ooisnull(p4)
+        guard_false(i2)
+            fail()
+        escape(p4)
+        #
+        p2 = new_with_vtable(ConstClass(node_vtable))
+        p3 = escape()
+        setfield_gc(p2, p3, descr=nextdescr)
+        jump(i0, p2)
+        """
+        expected = """
+        [i0, p4]
+        i2 = ooisnull(p4)
+        guard_false(i2)
+            fail()
+        escape(p4)
+        #
+        p3 = escape()
+        jump(i0, p3)
+        """
+        self.optimize_loop(ops, 'Not, Virtual(node_vtable, nextdescr=Not)',
+                           expected, i2=0,
+                           p1=self.nodebox.value,
+                           p2=self.nodebox.value,
+                           p3=self.nodebox.value,
+                           p4=self.nodebox.value)
+
+    def test_bug_2(self):
+        ops = """
+        [i0, p1]
+        p4 = getarrayitem_gc(p1, 0, descr=arraydescr2)
+        i2 = ooisnull(p4)
+        guard_false(i2)
+            fail()
+        escape(p4)
+        #
+        p2 = new_array(1, descr=arraydescr2)
+        p3 = escape()
+        setarrayitem_gc(p2, 0, p3, descr=arraydescr2)
+        jump(i0, p2)
+        """
+        expected = """
+        [i0, p4]
+        i2 = ooisnull(p4)
+        guard_false(i2)
+            fail()
+        escape(p4)
+        #
+        p3 = escape()
+        jump(i0, p3)
+        """
+        self.optimize_loop(ops, 'Not, VArray(arraydescr2, Not)',
+                           expected, i2=0,
+                           p3=self.sbox.value,
+                           p4=self.sbox.value)
+
     # ----------
 
     def make_fail_descr(self):
@@ -1216,7 +1276,8 @@
             fail(i3, i2, p3, descr=fdescr)
         jump(i2, 1, i3, p3)
         """
-        self.optimize_loop(ops, 'Not, Not, Not, Not', expected, i1=1)
+        self.optimize_loop(ops, 'Not, Not, Not, Not', expected, i1=1,
+                           p3=self.nodebox.value)
         self.check_expanded_fail_descr('''p1, i3
             where p1 is a node_vtable, valuedescr=1, nextdescr=p2
             where p2 is a node_vtable, valuedescr=i2, nextdescr=p3



More information about the Pypy-commit mailing list