[pypy-svn] r30212 - in pypy/dist/pypy/translator/backendopt: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Wed Jul 19 11:09:35 CEST 2006
Author: cfbolz
Date: Wed Jul 19 11:09:33 2006
New Revision: 30212
Modified:
pypy/dist/pypy/translator/backendopt/support.py
pypy/dist/pypy/translator/backendopt/test/test_support.py
Log:
finding backedges was broken. alas, this does not explain why the malloc->stack
transformation breaks pypy-c :-(
Modified: pypy/dist/pypy/translator/backendopt/support.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/support.py (original)
+++ pypy/dist/pypy/translator/backendopt/support.py Wed Jul 19 11:09:33 2006
@@ -124,19 +124,24 @@
calls[graph][called_graph] = block
return calls
-def find_backedges(graph):
+def find_backedges(graph, block=None, seen=None, seeing=None):
"""finds the backedges in the flow graph"""
- scheduled = [graph.startblock]
- seen = {}
backedges = []
- while scheduled:
- current = scheduled.pop()
- seen[current] = True
- for link in current.exits:
- if link.target in seen:
+ if block is None:
+ block = graph.startblock
+ if seen is None:
+ seen = {block: None}
+ if seeing is None:
+ seeing = {}
+ seeing[block] = True
+ for link in block.exits:
+ if link.target in seen:
+ if link.target in seeing:
backedges.append(link)
- else:
- scheduled.append(link.target)
+ else:
+ seen[link.target] = None
+ backedges.extend(find_backedges(graph, link.target, seen, seeing))
+ del seeing[block]
return backedges
def compute_reachability(graph):
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 Wed Jul 19 11:09:33 2006
@@ -126,3 +126,62 @@
loop_blocks = find_loop_blocks(graph)
assert len(loop_blocks) == 4
+def test_find_loop_blocks_simple():
+ def f(a):
+ if a <= 0:
+ return 1
+ return f(a - 1)
+ t = TranslationContext()
+ t.buildannotator().build_types(f, [int])
+ t.buildrtyper().specialize()
+ graph = graphof(t, f)
+ backedges = find_backedges(graph)
+ assert backedges == []
+ loop_blocks = find_loop_blocks(graph)
+ assert len(loop_blocks) == 0
+
+def test_find_loop_blocks2():
+ class A:
+ pass
+ def f(n):
+ a1 = A()
+ a1.x = 1
+ a2 = A()
+ a2.x = 2
+ if n > 0:
+ a = a1
+ else:
+ a = a2
+ return a.x
+ t = TranslationContext()
+ t.buildannotator().build_types(f, [int])
+ t.buildrtyper().specialize()
+ graph = graphof(t, f)
+ backedges = find_backedges(graph)
+ assert backedges == []
+ loop_blocks = find_loop_blocks(graph)
+ assert len(loop_blocks) == 0
+
+def test_find_loop_blocks3():
+ import os
+ def ps(loops):
+ return 42.0, 42.1
+ def f(loops):
+ benchtime, stones = ps(abs(loops))
+ s = '' # annotator happiness
+ if loops >= 0:
+ s = ("RPystone(%s) time for %d passes = %f" %
+ (23, loops, benchtime) + '\n' + (
+ "This machine benchmarks at %f pystones/second" % stones))
+ os.write(1, s)
+ if loops == 12345:
+ f(loops-1)
+ t = TranslationContext()
+ t.buildannotator().build_types(f, [int])
+ t.buildrtyper().specialize()
+ graph = graphof(t, f)
+ backedges = find_backedges(graph)
+ assert backedges == []
+ loop_blocks = find_loop_blocks(graph)
+ assert len(loop_blocks) == 0
+
More information about the Pypy-commit
mailing list