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

fijal at codespeak.net fijal at codespeak.net
Tue May 19 18:11:48 CEST 2009


Author: fijal
Date: Tue May 19 18:11:47 2009
New Revision: 65315

Modified:
   pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize2.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize2.py
Log:
more of optimizations. It's wrong with regard to aliasing and other things,
but that's in-progress


Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize2.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize2.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize2.py	Tue May 19 18:11:47 2009
@@ -1,7 +1,7 @@
 
 """ Simplified optimize.py
 """
-from pypy.jit.metainterp.resoperation import rop
+from pypy.jit.metainterp.resoperation import rop, ResOperation
 from pypy.jit.metainterp.history import Const, Box
 
 class InstanceNode(object):
@@ -11,7 +11,8 @@
             assert isinstance(source, Const)
         self.const = const
         self.cls = None
-        self.field_cache = {}
+        self.cleanfields = {}
+        self.dirtyfields = {}
 
     def __repr__(self):
         flags = ''
@@ -107,6 +108,24 @@
                 self.optimize_guard(op)
                 newoperations.append(op)
                 continue
+            elif op.opnum == rop.GETFIELD_GC:
+                instnode = self.getnode(op.args[0])
+                descr = op.descr
+                node = instnode.cleanfields.get(descr, None)
+                if node is not None:
+                    self.nodes[op.result] = node
+                    continue
+                else:
+                    instnode.cleanfields[descr] = self.getnode(op.result)
+            elif op.opnum == rop.SETFIELD_GC:
+                instnode = self.getnode(op.args[0])
+                descr = op.descr
+                node = self.getnode(op.args[1])
+                instnode.dirtyfields[descr] = node
+                instnode.cleanfields[descr] = node
+                l = self.field_caches.setdefault(descr, [])
+                l.append((instnode, node))
+                continue
             # default handler
             op = op.clone()
             op.args = self.new_arguments(op)
@@ -121,12 +140,23 @@
                     instnode = InstanceNode(box.constbox(), const=True)
                     self.nodes[box] = instnode
                     continue
+            elif not op.has_no_side_effect():
+                self.clean_up_caches(newoperations)
             newoperations.append(op)
         print "Length of the loop:", len(newoperations)
         self.loop.operations = newoperations
+
+    def clean_up_caches(self, newoperations):
+        for descr, v in self.field_caches.iteritems():
+            for instnode, fieldnode in v:
+                newoperations.append(ResOperation(rop.SETFIELD_GC,
+                    [instnode.source, fieldnode.source], None, descr))
+                del instnode.cleanfields[descr]
+                del instnode.dirtyfields[descr]
     
     def optimize_loop(self, loop):
         self.nodes = {}
+        self.field_caches = {}
         self.loop = loop
         self.find_nodes()
         self.optimize_operations()

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize2.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize2.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize2.py	Tue May 19 18:11:47 2009
@@ -60,7 +60,6 @@
         ])
 
 def test_remove_consecutive_getfields():
-    py.test.skip("in progress")
     n1 = BoxInt()
     n2 = BoxInt()
     n3 = BoxInt()
@@ -76,3 +75,21 @@
         ResOperation(rop.INT_ADD, [n1, n1], n3),
         ])
     
+def test_setfield_getfield_clean_cache():
+    n1 = BoxInt()
+    n2 = BoxInt()
+    n3 = BoxInt()
+    ops = [
+        ResOperation(rop.GETFIELD_GC, [nodebox], n1, nodedescr),
+        ResOperation(rop.SETFIELD_GC, [nodebox, ConstInt(3)], None, nodedescr),
+        ResOperation(rop.GETFIELD_GC, [nodebox], n2, nodedescr),
+        ResOperation(rop.CALL, [n2], None),
+    ]
+    loop = newloop([nodebox], ops)
+    optimize_loop(None, [], loop)
+    equaloplists(loop.operations, [
+        ResOperation(rop.GETFIELD_GC, [nodebox], n1, nodedescr),
+        ResOperation(rop.SETFIELD_GC, [nodebox, ConstInt(3)], None, nodedescr),
+        ResOperation(rop.CALL, [ConstInt(3)], None),
+        ])
+



More information about the Pypy-commit mailing list