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

fijal at codespeak.net fijal at codespeak.net
Thu Feb 12 14:19:52 CET 2009


Author: fijal
Date: Thu Feb 12 14:19:51 2009
New Revision: 61779

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py
Log:
(arigo, fijal)
Fix the bug by reinventing a bit logic about escaping.
We're too fried to make sure that we did the right thing and
definitely too fried to think about efficiency :-)


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	Thu Feb 12 14:19:51 2009
@@ -121,7 +121,6 @@
         self.startbox = startbox
         self.const = const
         self.virtual = False
-        self.star = False
         self.cls = None
         self.origfields = {}
         self.curfields = {}
@@ -135,13 +134,11 @@
         for node in self.curfields.values():
             node.escape_if_startbox(memo)
 
-    def set_escaping_flag(self, other):
-        if not self.escaped:
-            for ofs, node in self.origfields.items():
-                if ofs in other.curfields:
-                    node.set_escaping_flag(other.curfields[ofs])
-        else:
-            other.escaped = True
+    def add_to_dependency_graph(self, other, dep_graph):
+        dep_graph.append((self, other))
+        for ofs, node in self.origfields.items():
+            if ofs in other.curfields:
+                node.add_to_dependency_graph(other.curfields[ofs], dep_graph)
 
     def intersect(self, other):
         if not other.cls:
@@ -175,6 +172,14 @@
         for ofs, subspecnode in specnode.fields:
             self.curfields[ofs].adapt_to(subspecnode)
 
+    def __repr__(self):
+        flags = ''
+        if self.escaped:     flags += 'e'
+        if self.startbox:    flags += 's'
+        if self.const:       flags += 'c'
+        if self.virtual:     flags += 'v'
+        return "<InstanceNode %s (%s)>" % (self.source, flags)
+
 
 def optimize_loop(metainterp, old_loops, operations):
     if not metainterp._specialize:         # for tests only
@@ -211,6 +216,7 @@
     def __init__(self, operations):
         self.operations = operations
         self.nodes = {}
+        self.dependency_graph = []
 
     def getnode(self, box):
         try:
@@ -240,6 +246,8 @@
                 field = fieldbox.getint()
                 fieldnode = self.getnode(op.args[2])
                 instnode.curfields[field] = fieldnode
+                if opname == 'setfield_gc_ptr':
+                    self.dependency_graph.append((instnode, fieldnode))
                 continue
             elif opname.startswith('getfield_gc_'):
                 instnode = self.getnode(op.args[0])
@@ -255,6 +263,7 @@
                     fieldnode = InstanceNode(box, escaped=False)
                     if instnode.startbox:
                         fieldnode.startbox = True
+                    self.dependency_graph.append((instnode, fieldnode))
                     instnode.origfields[field] = fieldnode
                 self.nodes[box] = fieldnode
                 continue
@@ -262,7 +271,6 @@
                 instnode = self.getnode(op.args[0])
                 if instnode.cls is None:
                     instnode.cls = InstanceNode(op.args[1])
-                instnode.cls.star = True
                 continue
             elif opname not in ('oois', 'ooisnot',
                                 'ooisnull', 'oononnull'):
@@ -282,7 +290,17 @@
         for i in range(len(end_args)):
             box = self.operations[0].args[i]
             other_box = end_args[i]
-            self.nodes[box].set_escaping_flag(self.nodes[other_box])
+            self.nodes[box].add_to_dependency_graph(self.nodes[other_box],
+                                                    self.dependency_graph)
+        # XXX find efficient algorithm, we're too fried for that by now
+        done = False
+        while not done:
+            done = True
+            for instnode, fieldnode in self.dependency_graph:
+                if instnode.escaped:
+                    if not fieldnode.escaped:
+                        fieldnode.escaped = True
+                        done = False
 
     def intersect_input_and_output(self):
         # Step (3)

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	Thu Feb 12 14:19:51 2009
@@ -99,7 +99,6 @@
     assert spec.nodes[A.sum] is not spec.nodes[A.sum2]
     assert spec.nodes[A.n1] is not spec.nodes[A.n2]
     assert spec.nodes[A.n1].cls.source.value == node_vtable_adr
-    assert spec.nodes[A.n1].cls.star
     assert not spec.nodes[A.n1].escaped
     assert spec.nodes[A.n2].cls.source.value == node_vtable_adr
     assert not spec.nodes[A.n2].escaped



More information about the Pypy-commit mailing list