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

fijal at codespeak.net fijal at codespeak.net
Fri Feb 13 16:57:27 CET 2009


Author: fijal
Date: Fri Feb 13 16:57:26 2009
New Revision: 61838

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py
Log:
A first go. This already simplifies stuff a bit, but probably also breaks
something else.


Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py	Fri Feb 13 16:57:26 2009
@@ -72,6 +72,7 @@
         self.cls = None
         self.origfields = {}
         self.curfields = {}
+        self.cleanfields = {}
 
     def escape_if_startbox(self, memo):
         if self in memo:
@@ -142,6 +143,7 @@
         if self.const:       flags += 'c'
         if self.virtual:     flags += 'v'
         if self.virtualized: flags += 'V'
+        if self.dirty:       flags += 'd'
         return "<InstanceNode %s (%s)>" % (self.source, flags)
 
 
@@ -376,11 +378,17 @@
                 continue
             elif opname == 'getfield_gc':
                 instnode = self.nodes[op.args[0]]
+                ofs = op.args[1].getint()
                 if instnode.virtual or instnode.virtualized:
-                    ofs = op.args[1].getint()
                     assert ofs in instnode.curfields    # xxx
                     self.nodes[op.results[0]] = instnode.curfields[ofs]
                     continue
+                else:
+                    if ofs in instnode.cleanfields:
+                        self.nodes[op.results[0]] = instnode.cleanfields[ofs]
+                        continue
+                    else:
+                        instnode.cleanfields[ofs] = InstanceNode(op.results[0])
             elif opname == 'new_with_vtable':
                 # self.nodes[op.results[0]] keep the value from Steps (1,2)
                 instnode = self.nodes[op.results[0]]
@@ -415,6 +423,7 @@
                     self.nodes[box] = instnode
                     continue
             # default handling of arguments and return value(s)
+            self.cleanup_clean_fields(op.args)
             op = self.replace_arguments(op)
             if opname in always_pure_operations:
                 for box in op.args:
@@ -434,6 +443,11 @@
         newoperations[0].specnodes = self.specnodes
         self.loop.operations = newoperations
 
+    def cleanup_clean_fields(self, args):
+        for arg in args:
+            if not isinstance(arg, Const):
+                self.nodes[arg].cleanfields = {}
+
     def match_exactly(self, old_loop):
         old_operations = old_loop.operations
         old_mp = old_operations[0]

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py	Fri Feb 13 16:57:26 2009
@@ -521,6 +521,38 @@
 
 # ____________________________________________________________
 
+class K0:
+    locals().update(A.__dict__)    # :-)
+    sum3 = BoxInt(3)
+    v3 = BoxInt(4)
+    ops = [
+        MergePoint('merge_point', [sum, n1], []),
+        ResOperation('guard_class', [n1, ConstAddr(node_vtable, cpu)], []),
+        ResOperation('getfield_gc', [n1, ConstInt(ofs_value)], [v]),
+        ResOperation('int_sub', [v, ConstInt(1)], [v2]),
+        ResOperation('int_add', [sum, v], [sum2]),
+        ResOperation('getfield_gc', [n1, ConstInt(ofs_value)], [v3]),
+        ResOperation('int_add', [sum2, v3], [sum3]),
+        ResOperation('escape', [n1], []),
+        Jump('jump', [sum3, n1], []),
+        ]
+
+def test_K0_optimize_loop():
+    spec = PerfectSpecializer(Loop(K0.ops))
+    spec.find_nodes()
+    spec.intersect_input_and_output()
+    spec.optimize_loop()
+    equaloplists(spec.loop.operations, [
+        MergePoint('merge_point', [K0.sum, K0.n1], []),
+        ResOperation('getfield_gc', [K0.n1, ConstInt(K0.ofs_value)], [K0.v]),
+        ResOperation('int_sub', [K0.v, ConstInt(1)], [K0.v2]),
+        ResOperation('int_add', [K0.sum, K0.v], [K0.sum2]),
+        ResOperation('int_add', [K0.sum2, K0.v], [K0.sum3]),
+        ResOperation('escape', [K0.n1], []),
+        Jump('jump', [K0.sum3, K0.n1], []),
+    ])
+
+
 class K:
     locals().update(A.__dict__)    # :-)
     sum3 = BoxInt(3)
@@ -537,7 +569,6 @@
         ]
 
 def test_K_optimize_loop():
-    py.test.skip("in-progress")
     spec = PerfectSpecializer(Loop(K.ops))
     spec.find_nodes()
     spec.intersect_input_and_output()
@@ -549,7 +580,6 @@
         ResOperation('int_add', [K.sum2, K.v], [K.sum3]),
         Jump('jump', [K.sum3, K.n1, K.v], []),
     ])
-    assert spec.loop.prologue == [(K.n1, K.v, K.ofs_value)]
 
 # ____________________________________________________________
 
@@ -570,7 +600,6 @@
         ]
 
 def test_L_optimize_loop():
-    py.test.skip("in-progress")
     spec = PerfectSpecializer(Loop(L.ops))
     spec.find_nodes()
     spec.intersect_input_and_output()
@@ -603,21 +632,17 @@
         ]
 
 def test_M_optimize_loop():
-    py.test.skip("in-progress")
     spec = PerfectSpecializer(Loop(L.ops))
     spec.find_nodes()
     spec.intersect_input_and_output()
     spec.optimize_loop()
-    # XXX why do we expect that?  I'd rather say that n1 is passed around
-    # as an escaped until the first getfield_gc instead of generating
-    # a getfield_gc eagerly after the 'escape'...
     equaloplists(spec.loop.operations, [
-        MergePoint('merge_point', [L.sum, L.n1, L.v], []),
+        MergePoint('merge_point', [L.sum, L.n1], []),
+        ResOperation('getfield_gc', [L.n1, ConstInt(L.ofs_value)], [L.v]),
         ResOperation('int_sub', [L.v, ConstInt(1)], [L.v2]),
         ResOperation('int_add', [L.sum, L.v], [L.sum2]),
         ResOperation('escape', [L.n1], []),
-        ResOperation('getfield_gc', [n1, ConstInt(ofs_value)], [v3]),
-        Jump('jump', [L.sum2, L.n1, L.v3], []),
+        Jump('jump', [L.sum2, L.n1], []),
     ])
-    assert spec.loop.prologue == [(L.n1, L.v, L.ofs_value)]
+    assert spec.loop.prologue == []
 



More information about the Pypy-commit mailing list