[pypy-svn] r32549 - in pypy/dist/pypy/translator/backendopt: . test

pedronis at codespeak.net pedronis at codespeak.net
Thu Sep 21 00:32:00 CEST 2006


Author: pedronis
Date: Thu Sep 21 00:31:57 2006
New Revision: 32549

Modified:
   pypy/dist/pypy/translator/backendopt/support.py
   pypy/dist/pypy/translator/backendopt/test/test_support.py
Log:
issue258 testing

fixed compute_reachability. with a simple test.

didn't seem to make any difference (size/speed/breakage) on a whole PyPy translation (?)



Modified: pypy/dist/pypy/translator/backendopt/support.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/support.py	(original)
+++ pypy/dist/pypy/translator/backendopt/support.py	Thu Sep 21 00:31:57 2006
@@ -146,17 +146,20 @@
 
 def compute_reachability(graph):
     reachable = {}
-    for block in graph.iterblocks():
+    blocks = list(graph.iterblocks())
+    for block in reversed(blocks): # this order should make the reuse path more likely
         reach = {}
         scheduled = [block]
         while scheduled:
             current = scheduled.pop()
             for link in current.exits:
                 if link.target in reachable:
+                    reach[link.target] = True
                     reach = setunion(reach, reachable[link.target])
                     continue
                 if link.target not in reach:
                     reach[link.target] = True
+                    scheduled.append(link.target)
         reachable[block] = reach
     return reachable
 

Modified: pypy/dist/pypy/translator/backendopt/test/test_support.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_support.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_support.py	Thu Sep 21 00:31:57 2006
@@ -2,7 +2,7 @@
 from pypy.translator.translator import TranslationContext, graphof
 from pypy.translator.backendopt.support import \
      needs_conservative_livevar_calculation, split_block_with_keepalive, \
-     find_loop_blocks, find_backedges
+     find_loop_blocks, find_backedges, compute_reachability
 
 from pypy.rpython.rtyper import LowLevelOpList
 from pypy.rpython.lltypesystem import lltype
@@ -90,6 +90,27 @@
     assert 'keepalive' in [op.opname for op in link.target.operations]
 
 #__________________________________________________________
+# test compute_reachability
+
+def test_simple_compute_reachability():
+    def f(x):
+        if x < 0:
+            if x == -1:
+                return x+1
+            else:
+                return x+2
+        else:
+            if x == 1:
+                return x-1
+            else:
+                return x-2
+    t = TranslationContext()
+    g = t.buildflowgraph(f)
+    reach = compute_reachability(g)
+    assert len(reach[g.startblock]) == 7
+    assert len(reach[g.startblock.exits[0].target]) == 3
+    assert len(reach[g.startblock.exits[1].target]) == 3
+#__________________________________________________________
 # test loop detection
 
 def test_find_backedges():



More information about the Pypy-commit mailing list