[pypy-svn] r40479 - in pypy/branch/jit-virtual-world/pypy/translator: . backendopt

arigo at codespeak.net arigo at codespeak.net
Wed Mar 14 13:50:37 CET 2007


Author: arigo
Date: Wed Mar 14 13:50:31 2007
New Revision: 40479

Modified:
   pypy/branch/jit-virtual-world/pypy/translator/backendopt/support.py
   pypy/branch/jit-virtual-world/pypy/translator/transform.py
Log:
(arre, pedronis, arigo)

Fix a bug in the call graph generation (the dict couldn't represent
a function that contains several calls to another).


Modified: pypy/branch/jit-virtual-world/pypy/translator/backendopt/support.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/translator/backendopt/support.py	(original)
+++ pypy/branch/jit-virtual-world/pypy/translator/backendopt/support.py	Wed Mar 14 13:50:31 2007
@@ -105,24 +105,20 @@
     afterblock.operations[pos:pos] = generate_keepalive(keep_alive_vars)
     return splitlink
 
-def calculate_call_graph(translator):
-    calls = {}
-    for graph in translator.graphs:
-        if getattr(getattr(graph, "func", None), "suggested_primitive", False):
-            continue
-        calls[graph] = {}
-        for block in graph.iterblocks():
-            for op in block.operations:
-                if op.opname == "direct_call":
-                    called_graph = get_graph(op.args[0], translator)
-                    if called_graph is not None:
-                        calls[graph][called_graph] = block
-                if op.opname == "indirect_call":
-                    graphs = op.args[-1].value
-                    if graphs is not None:
-                        for called_graph in graphs:
-                            calls[graph][called_graph] = block
-    return calls
+def find_calls_from(translator, graph):
+    if getattr(getattr(graph, "func", None), "suggested_primitive", False):
+        return
+    for block in graph.iterblocks():
+        for op in block.operations:
+            if op.opname == "direct_call":
+                called_graph = get_graph(op.args[0], translator)
+                if called_graph is not None:
+                    yield block, called_graph
+            if op.opname == "indirect_call":
+                graphs = op.args[-1].value
+                if graphs is not None:
+                    for called_graph in graphs:
+                        yield block, called_graph
 
 def find_backedges(graph, block=None, seen=None, seeing=None):
     """finds the backedges in the flow graph"""

Modified: pypy/branch/jit-virtual-world/pypy/translator/transform.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/translator/transform.py	(original)
+++ pypy/branch/jit-virtual-world/pypy/translator/transform.py	Wed Mar 14 13:50:31 2007
@@ -180,7 +180,7 @@
         caller_block.operations.insert(0, unwind_op)
 
 def insert_ll_stackcheck(translator):
-    from pypy.translator.backendopt.support import calculate_call_graph
+    from pypy.translator.backendopt.support import find_calls_from
     from pypy.rpython.module.ll_stack import ll_stack_check
     from pypy.tool.algo.graphlib import Edge, make_edge_dict, break_cycles
     rtyper = translator.rtyper
@@ -188,12 +188,11 @@
     rtyper.specialize_more_blocks()
     stack_check_ptr = rtyper.getcallable(graph)
     stack_check_ptr_const = Constant(stack_check_ptr, lltype.typeOf(stack_check_ptr))
-    call_graph = calculate_call_graph(translator)
     edges = []
     graphs_to_patch = {}
     insert_in = {}
-    for caller, all_callees in call_graph.iteritems():
-        for callee, block in all_callees.iteritems():
+    for caller in translator.graphs:
+        for block, callee in find_calls_from(translator, caller):
             if getattr(getattr(callee, 'func', None),
                        'insert_stack_check_here', False):
                 insert_in[callee.startblock] = True



More information about the Pypy-commit mailing list