[pypy-svn] r32296 - in pypy/dist/pypy: jit/hintannotator jit/timeshifter rpython

arigo at codespeak.net arigo at codespeak.net
Thu Sep 14 11:06:07 CEST 2006


Author: arigo
Date: Thu Sep 14 11:06:05 2006
New Revision: 32296

Modified:
   pypy/dist/pypy/jit/hintannotator/bookkeeper.py
   pypy/dist/pypy/jit/hintannotator/model.py
   pypy/dist/pypy/jit/timeshifter/rtyper.py
   pypy/dist/pypy/rpython/normalizecalls.py
Log:
(pedronis, arigo)

Started to normalize the annotations of multiply-called graphs in the
hintannotator.  Tests missing.  (Intermediate check-in before I upgrade
subversion)


Modified: pypy/dist/pypy/jit/hintannotator/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/bookkeeper.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/bookkeeper.py	Thu Sep 14 11:06:05 2006
@@ -2,6 +2,7 @@
 from pypy.objspace.flow.model import copygraph, SpaceOperation
 from pypy.annotation import model as annmodel
 from pypy.rpython.lltypesystem import lltype
+from pypy.tool.algo.unionfind import UnionFind
 
 TLS = tlsobject()
 
@@ -47,6 +48,14 @@
             return graph
 
 
+class TsGraphCallFamily:
+    def __init__(self, tsgraph):
+        self.tsgraphs = {tsgraph: True}
+
+    def update(self, other):
+        self.tsgraphs.update(other.tsgraphs)
+
+
 class HintBookkeeper(object):
 
     def __init__(self, hannotator):
@@ -54,6 +63,7 @@
         self.originflags = {}
         self.virtual_containers = {}
         self.descs = {}
+        self.tsgraph_maximal_call_families = UnionFind(TsGraphCallFamily)
         self.annotator = hannotator
         # circular imports hack
         global hintmodel
@@ -170,9 +180,11 @@
         graph = desc.specialize(args_hs, key=key, alt_name=alt_name)
         return graph
 
-    def graph_call(self, graph, fixed, args_hs):
+    def graph_call(self, graph, fixed, args_hs, tsgraph_accum=None):
         input_args_hs = list(args_hs)
         graph = self.get_graph_for_call(graph, fixed, input_args_hs)
+        if tsgraph_accum is not None:
+            tsgraph_accum.append(graph)     # save this if the caller cares
 
         # propagate fixing of arguments in the function to the caller
         for inp_arg_hs, arg_hs in zip(input_args_hs, args_hs):
@@ -200,6 +212,18 @@
             hs_res = hintmodel.reorigin(hs_res, *deps_hs)
         return hs_res
 
+    def graph_family_call(self, graph, fixed, args_hs):
+        tsgraphs = []
+        results_hs = []
+        for graph in graph_list:
+            results_hs.append(self.graph_call(graph, fixed, args_hs, tsgraphs))
+        # put the tsgraphs in the same call family
+        call_families = self.tsgraph_maximal_call_families
+        _, rep, callfamily = call_families.find(tsgraphs[0])
+        for tsgraph in tsgraphs[1:]:
+            _, rep, callfamily = call_families.union(rep, tsgraph)
+        return annmodel.unionof(*results_hs)
+
 # get current bookkeeper
 
 def getbookkeeper():

Modified: pypy/dist/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/model.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/model.py	Thu Sep 14 11:06:05 2006
@@ -280,9 +280,7 @@
 
         bookkeeper = getbookkeeper()
         fixed = bookkeeper.myorigin().read_fixed()
-        results_hs = [bookkeeper.graph_call(graph, fixed, args_hs)
-                      for graph in graph_list]
-        hs_res = annmodel.unionof(*results_hs)
+        hs_res = bookkeeper.graph_family_call(graph_list, fixed, args_hs)
 
         if isinstance(hs_res, SomeLLAbstractConstant):
             hs_res.myorigin = bookkeeper.myorigin()

Modified: pypy/dist/pypy/jit/timeshifter/rtyper.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rtyper.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rtyper.py	Thu Sep 14 11:06:05 2006
@@ -17,8 +17,19 @@
 
     offers_exceptiondata = False
     
-    def perform_normalizations(self, rtyper):
-        pass   # for now
+    def perform_normalizations(self, hrtyper):
+        from pypy.rpython import normalizecalls
+        hannotator = hrtyper.annotator
+        call_families = hannotator.bookkeeper.tsgraph_maximal_call_families
+        while True:
+            progress = False
+            for callfamily in call_families.infos():
+                graphs = callfamily.tsgraphs.keys()
+                progress |= normalizecalls.normalize_calltable_row_annotation(
+                    hannotator,
+                    graphs)
+            if not progress:
+                break   # done
 
 HintTypeSystem.instance = HintTypeSystem()
 

Modified: pypy/dist/pypy/rpython/normalizecalls.py
==============================================================================
--- pypy/dist/pypy/rpython/normalizecalls.py	(original)
+++ pypy/dist/pypy/rpython/normalizecalls.py	Thu Sep 14 11:06:05 2006
@@ -39,7 +39,8 @@
         progress = False
         for shape, table in callfamily.calltables.items():
             for row in table:
-                progress |= normalize_calltable_row_annotation(annotator, row)
+                progress |= normalize_calltable_row_annotation(annotator,
+                                                               row.values())
         if not progress:
             return   # done
         assert not callfamily.normalized, "change in call family normalisation"
@@ -126,10 +127,9 @@
             did_something = True
     return did_something
 
-def normalize_calltable_row_annotation(annotator, row):
-    if len(row) <= 1:
+def normalize_calltable_row_annotation(annotator, graphs):
+    if len(graphs) <= 1:
         return False   # nothing to do
-    graphs = row.values()
     graph_bindings = {}
     for graph in graphs:
         graph_bindings[graph] = [annotator.binding(v)



More information about the Pypy-commit mailing list