[pypy-svn] r70423 - in pypy/trunk/pypy/jit: backend/llgraph metainterp metainterp/test

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Jan 7 14:18:10 CET 2010


Author: cfbolz
Date: Thu Jan  7 14:18:09 2010
New Revision: 70423

Modified:
   pypy/trunk/pypy/jit/backend/llgraph/llimpl.py
   pypy/trunk/pypy/jit/metainterp/optimizeopt.py
   pypy/trunk/pypy/jit/metainterp/test/test_optimizeopt.py
Log:
Tiny optimization: when forcing a virtual, don't generate code for setting
fields to NULL, since malloc returns zero-filled objects.

This works fine with the x86 backend, but needs a fix in the llgraph backend to
actually zero the memory (at least for structs, arrays have always been zeroed).


Modified: pypy/trunk/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/llgraph/llimpl.py	(original)
+++ pypy/trunk/pypy/jit/backend/llgraph/llimpl.py	Thu Jan  7 14:18:09 2010
@@ -1067,7 +1067,7 @@
     else:
         # for tests, a random emulated ll_inst will do
         if Class not in _pseudo_exceptions:
-            ll_inst = lltype.malloc(rclass.OBJECT)
+            ll_inst = lltype.malloc(rclass.OBJECT, zero=True)
             ll_inst.typeptr = lltype.malloc(rclass.OBJECT_VTABLE,
                                             immortal=True)
             _pseudo_exceptions[Class] = LLException(ll_inst.typeptr, ll_inst)
@@ -1209,7 +1209,7 @@
 
 def do_new(size):
     TYPE = symbolic.Size2Type[size]
-    x = lltype.malloc(TYPE)
+    x = lltype.malloc(TYPE, zero=True)
     return cast_to_ptr(x)
 
 def do_new_array(arraynum, count):

Modified: pypy/trunk/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/optimizeopt.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/optimizeopt.py	Thu Jan  7 14:18:09 2010
@@ -207,6 +207,8 @@
             iteritems = list(iteritems)
             iteritems.sort(key = lambda (x,y): x.sort_key())
         for ofs, value in iteritems:
+            if value.is_null():
+                continue
             subbox = value.force_box()
             op = ResOperation(rop.SETFIELD_GC, [box, subbox], None,
                               descr=ofs)
@@ -293,6 +295,8 @@
         for index in range(len(self._items)):
             subvalue = self._items[index]
             if subvalue is not self.constvalue:
+                if subvalue.is_null():
+                    continue
                 subbox = subvalue.force_box()
                 op = ResOperation(rop.SETARRAYITEM_GC,
                                   [box, ConstInt(index), subbox], None,

Modified: pypy/trunk/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_optimizeopt.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_optimizeopt.py	Thu Jan  7 14:18:09 2010
@@ -925,6 +925,26 @@
         """
         self.optimize_loop(ops, 'Not', expected)
 
+    def test_nonvirtual_dont_write_null_fields_on_force(self):
+        ops = """
+        [i]
+        p1 = new_with_vtable(ConstClass(node_vtable))
+        setfield_gc(p1, i, descr=valuedescr)
+        i1 = getfield_gc(p1, descr=valuedescr)
+        setfield_gc(p1, 0, descr=valuedescr)
+        escape(p1)
+        i2 = getfield_gc(p1, descr=valuedescr)
+        jump(i2)
+        """
+        expected = """
+        [i]
+        p1 = new_with_vtable(ConstClass(node_vtable))
+        escape(p1)
+        i2 = getfield_gc(p1, descr=valuedescr)
+        jump(i2)
+        """
+        self.optimize_loop(ops, 'Not', expected)
+
     def test_getfield_gc_pure_1(self):
         ops = """
         [i]
@@ -1025,6 +1045,24 @@
         """
         self.optimize_loop(ops, 'Not, Not', expected)
 
+    def test_nonvirtual_array_dont_write_null_fields_on_force(self):
+        ops = """
+        [i1]
+        p1 = new_array(5, descr=arraydescr)
+        setarrayitem_gc(p1, 0, i1, descr=arraydescr)
+        setarrayitem_gc(p1, 1, 0, descr=arraydescr)
+        escape(p1)
+        jump(i1)
+        """
+        expected = """
+        [i1]
+        p1 = new_array(5, descr=arraydescr)
+        setarrayitem_gc(p1, 0, i1, descr=arraydescr)
+        escape(p1)
+        jump(i1)
+        """
+        self.optimize_loop(ops, 'Not', expected)
+
     def test_varray_2(self):
         ops = """
         [i0, p1]



More information about the Pypy-commit mailing list