Author: Hakan Ardo <[email protected]>
Branch: jit-short_from_state
Changeset: r45276:94d5f21f714f
Date: 2011-07-02 07:53 +0200
http://bitbucket.org/pypy/pypy/changeset/94d5f21f714f/

Log:    some supoprt for caching setitems across loop bondaries

diff --git a/pypy/jit/metainterp/optimizeopt/heap.py 
b/pypy/jit/metainterp/optimizeopt/heap.py
--- a/pypy/jit/metainterp/optimizeopt/heap.py
+++ b/pypy/jit/metainterp/optimizeopt/heap.py
@@ -91,7 +91,7 @@
             # field.
             structvalue = optheap.getvalue(op.getarg(0))
             fieldvalue  = optheap.getvalue(op.getarglist()[-1])
-            self.remember_field_value(structvalue, fieldvalue)
+            self.remember_field_value(structvalue, fieldvalue, op)
 
     def clear(self):
         self._cached_fields.clear()
@@ -121,9 +121,21 @@
                                              potential_ops, descr):
         if self._lazy_setfield is not None:
             return
-        for structvalue, op in self._cached_fields_getfield_op.iteritems():
+        for structvalue in self._cached_fields_getfield_op.keys():
+            op = self._cached_fields_getfield_op[structvalue]
             if op and structvalue in self._cached_fields:
-                potential_ops[op.result] = op
+                if op.getopnum() == rop.SETFIELD_GC:
+                    result = op.getarg(1)
+                    if result in potential_ops:
+                        result = result.clonebox()
+                        # XXX this will not allow for chains of operations
+                    getop = ResOperation(rop.GETFIELD_GC, [op.getarg(0)],
+                                         result, op.getdescr())
+                    potential_ops[result] = getop
+                    self._cached_fields_getfield_op[structvalue] = getop
+                    self._cached_fields[structvalue] = 
optimizer.getvalue(result)
+                elif op.result is not None:
+                    potential_ops[op.result] = op
 
 
 class BogusPureField(JitException):
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py 
b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -6412,6 +6412,23 @@
         """
         self.optimize_loop(ops, expected)
 
+    def test_setgetfield_counter(self):
+        ops = """
+        [p1]
+        i2 = getfield_gc(p1, descr=valuedescr)
+        i3 = int_add(i2, 1)
+        setfield_gc(p1, i3, descr=valuedescr)
+        jump(p1)
+        """
+        expected = """
+        [p1, i1]
+        i2 = int_add(i1, 1)
+        setfield_gc(p1, i2, descr=valuedescr)
+        jump(p1, i2)
+        """
+        self.optimize_loop(ops, expected)
+        
+
 class TestLLtype(OptimizeOptTest, LLtypeMixin):
     pass
         
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to