[pypy-svn] r20274 - in pypy/branch/somepbc-refactoring/pypy: rpython translator

arigo at codespeak.net arigo at codespeak.net
Sat Nov 26 13:15:17 CET 2005


Author: arigo
Date: Sat Nov 26 13:15:15 2005
New Revision: 20274

Modified:
   pypy/branch/somepbc-refactoring/pypy/rpython/rtyper.py
   pypy/branch/somepbc-refactoring/pypy/translator/annrpython.py
   pypy/branch/somepbc-refactoring/pypy/translator/translator.py
Log:
Compute the cross-graphs call graph during annotation and rtyping in the
appropriate places, instead of with a mix of buildflowgraph() arguments fixed
by post-processing.  In the branch we cannot give meaningful call information
to buildflowgraph() anyway.



Modified: pypy/branch/somepbc-refactoring/pypy/rpython/rtyper.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/rtyper.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/rtyper.py	Sat Nov 26 13:15:15 2005
@@ -280,7 +280,7 @@
         # specialize all the operations, as far as possible
         if block.operations == ():   # return or except block
             return
-        newops = LowLevelOpList(self)
+        newops = LowLevelOpList(self, block)
         varmapping = {}
         for v in block.getvariables():
             varmapping[v] = v    # records existing Variables
@@ -362,7 +362,7 @@
                     a, using_repr=self.exceptiondata.r_exception_value)
 
             inputargs_reprs = self.setup_block_entry(link.target)
-            newops = LowLevelOpList(self)
+            newops = LowLevelOpList(self, block)
             newlinkargs = {}
             for i in range(len(link.args)):
                 a1 = link.args[i]
@@ -712,8 +712,12 @@
     llop_raising_exceptions = None
     implicit_exceptions_checked = None
 
-    def __init__(self, rtyper):
+    def __init__(self, rtyper, originalblock):
         self.rtyper = rtyper
+        self.originalblock = originalblock
+
+    def getparentgraph(self):
+        return self.rtyper.annotator.annotated[self.originalblock]
 
     def convertvar(self, v, r_from, r_to):
         assert isinstance(v, (Variable, Constant))
@@ -774,6 +778,10 @@
             ll_function = ll_function.im_func
 
         graph = annotate_lowlevel_helper(rtyper.annotator, ll_function, args_s)
+        rtyper.annotator.translator.update_call_graph(
+            caller_graph = self.getparentgraph(),
+            callee_graph = graph,
+            position_tag = object())
 
         # build the 'direct_call' operation
         f = self.rtyper.getcallable(graph)

Modified: pypy/branch/somepbc-refactoring/pypy/translator/annrpython.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/annrpython.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/annrpython.py	Sat Nov 26 13:15:15 2005
@@ -267,8 +267,10 @@
     def recursivecall(self, graph, whence, inputcells): # whence = position_key|callback taking the annotator, graph 
         if isinstance(whence, tuple):
             parent_graph, parent_block, parent_index = position_key = whence
+            tag = parent_block, parent_index
+            self.translator.update_call_graph(parent_graph, graph, tag)
         else:
-            parent_graph = position_key = None
+            position_key = None
         self._register_returnvar(graph)
         # self.notify[graph.returnblock] is a dictionary of call
         # points to this func which triggers a reflow whenever the

Modified: pypy/branch/somepbc-refactoring/pypy/translator/translator.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/translator.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/translator.py	Sat Nov 26 13:15:15 2005
@@ -34,9 +34,8 @@
         self.callgraph = {}   # {opaque_tag: (caller-graph, callee-graph)}
         self._prebuilt_graphs = {}   # only used by the pygame viewer
         # the following is an index into self.functions from where to check
-        #self._callgraph_complete = 0
 
-    def buildflowgraph(self, func, called_by_graph=None, call_tag=None):
+    def buildflowgraph(self, func):
         """Get the flow graph for a function."""
         if not isinstance(func, types.FunctionType):
             raise TypeError("buildflowgraph() expects a function, "
@@ -54,12 +53,13 @@
             if self.flags.get('verbose'):
                 log.done(func.__name__)
             self.graphs.append(graph)   # store the graph in our list
-        if called_by_graph:
-            # update the call graph
-            key = called_by_graph, graph, call_tag
-            self.callgraph[key] = called_by_graph, graph
         return graph
 
+    def update_call_graph(self, caller_graph, callee_graph, position_tag):
+        # update the call graph
+        key = caller_graph, callee_graph, position_tag
+        self.callgraph[key] = caller_graph, callee_graph
+
     def buildannotator(self, policy=None):
         if self.annotator is not None:
             raise ValueError("we already have an annotator")
@@ -156,13 +156,11 @@
         raise TypeError, "don't know about %r" % x
 
     def specialize(self, **flags):
-        #self._callgraph_complete = 0
         rtyper = self.buildrtyper(
             type_system=flags.pop("type_system", "lltype"))
         rtyper.specialize(**flags)
 
     def backend_optimizations(self, **kwds):
-        #self._callgraph_complete = 0
         from pypy.translator.backendopt.all import backend_optimizations
         backend_optimizations(self, **kwds)
 
@@ -337,32 +335,3 @@
         """Disassembles underlying Python function to bytecodes."""
         from dis import dis
         dis(self.entrypoint)
-
-    def get_complete_callgraph(self):
-        FIX_ME
-        if self._callgraph_complete < len(self.functions):
-            self._complete_callgraph()
-        return self.callgraph
-    complete_callgraph = property(get_complete_callgraph)
-
-    def _complete_callgraph(self):
-        # walk through all functions, which may grow
-        # if we pull new graphs in.
-        graphs = self.flowgraphs
-        funcs = self.functions
-        complete = self._callgraph_complete
-        while complete < len(funcs):
-            sofar = len(funcs)
-            for func in funcs[complete:]:
-                graph = graphs[func]
-                for block in graph.iterblocks():
-                    for op in block.operations:
-                        if op.opname == 'direct_call':
-                            fnarg = op.args[0]
-                            if isinstance(fnarg, Constant):
-                                fnptr = fnarg.value
-                                fn = fnptr._obj._callable
-                                fg = self.getflowgraph(fn, called_by = func,
-                                                       call_tag = block)
-            complete = sofar
-        self._callgraph_complete = complete



More information about the Pypy-commit mailing list