[pypy-svn] r40480 - pypy/branch/jit-virtual-world/pypy/jit/goal

arigo at codespeak.net arigo at codespeak.net
Wed Mar 14 13:51:19 CET 2007


Author: arigo
Date: Wed Mar 14 13:51:18 2007
New Revision: 40480

Modified:
   pypy/branch/jit-virtual-world/pypy/jit/goal/jitstep.py
   pypy/branch/jit-virtual-world/pypy/jit/goal/targetjit.py
Log:
(arre, pedronis, arigo)

Heuristics for now to timeshift all graphs leading to add__Int_Int.
Crashes ATM on missing 'int_add_ovf' support in the front- and back-end.


Modified: pypy/branch/jit-virtual-world/pypy/jit/goal/jitstep.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/jit/goal/jitstep.py	(original)
+++ pypy/branch/jit-virtual-world/pypy/jit/goal/jitstep.py	Wed Mar 14 13:51:18 2007
@@ -1,3 +1,4 @@
+import types
 from pypy.module.pypyjit.interp_jit import PORTAL
 
 from pypy.objspace.flow.model import checkgraph
@@ -10,7 +11,14 @@
 
 class PyPyHintAnnotatorPolicy(HintAnnotatorPolicy):
 
+    def __init__(self, timeshift_graphs):
+        HintAnnotatorPolicy.__init__(self, novirtualcontainer = True,
+                                           oopspec = True)
+        self.timeshift_graphs = timeshift_graphs
+
     def look_inside_graph(self, graph):
+        if graph in self.timeshift_graphs:
+            return True
         try:
             func = graph.func
         except AttributeError:
@@ -26,20 +34,109 @@
         return True
 
 forbidden_modules = {'pypy.interpreter.gateway': True,
-                     'pypy.interpreter.baseobjspace': True,
+                     #'pypy.interpreter.baseobjspace': True,
                      'pypy.interpreter.typedef': True,
                      'pypy.interpreter.eval': True,
                      'pypy.interpreter.function': True,
                      'pypy.interpreter.pytraceback': True,
                      }
 
-POLICY = PyPyHintAnnotatorPolicy(novirtualcontainer = True,
-                                 oopspec = True)
+def enumerate_reachable_graphs(translator, startgraph):
+    from pypy.translator.backendopt.support import find_calls_from
+    pending = [(startgraph, None)]
+    yield pending[0]
+    seen = {startgraph: True}
+    while pending:
+        yield None     # hack: a separator meaning "length increases now"
+        nextlengthlist = []
+        nextseen = {}
+        for node in pending:
+            head, tail = node
+            for block, callee in find_calls_from(translator, head):
+                if callee not in seen:
+                    newnode = callee, node
+                    yield newnode
+                    nextlengthlist.append(newnode)
+                    nextseen[callee] = True
+        pending = nextlengthlist
+        seen.update(nextseen)
+    yield None
+
+def graphs_on_the_path_to(translator, startgraph, targetgraphs):
+    targetgraphs = targetgraphs.copy()
+    result = {}
+    found = {}
+    for node in enumerate_reachable_graphs(translator, startgraph):
+        if node is None:  # hack: a separator meaning "length increases now"
+            for graph in found:
+                del targetgraphs[graph]
+            found.clear()
+            if not targetgraphs:
+                return result
+        elif node[0] in targetgraphs:
+            found[node[0]] = True
+            while node is not None:
+                head, tail = node
+                result[head] = True
+                node = tail
+    raise Exception("did not reach all targets:\nmissing %r" % (
+        targetgraphs.keys(),))
+
+
+def timeshift_graphs(t, portal_graph):
+    result_graphs = {}
+
+    def _graph(func):
+        func = getattr(func, 'im_func', func)
+        return graphof(t, func)
+
+    def seefunc(fromfunc, *tofuncs):
+        targetgraphs = {}
+        for tofunc in tofuncs:
+            targetgraphs[_graph(tofunc)] = True
+        graphs = graphs_on_the_path_to(t, _graph(fromfunc), targetgraphs)
+        result_graphs.update(graphs)
+
+    def seepath(*path):
+        for i in range(1, len(path)):
+            seefunc(path[i-1], path[i])
+
+    # --------------------
+    import pypy
+    seepath(pypy.interpreter.pyframe.PyFrame.BINARY_ADD,
+            pypy.objspace.descroperation.DescrOperation.add,
+            pypy.objspace.std.intobject.add__Int_Int,
+            pypy.objspace.std.inttype.wrapint,
+            pypy.objspace.std.intobject.W_IntObject.__init__)
+    seepath(pypy.objspace.descroperation._invoke_binop,
+            pypy.objspace.descroperation._check_notimplemented)
+    seepath(pypy.objspace.descroperation.DescrOperation.add,
+            pypy.objspace.std.Space.type)
+    #seepath(pypy.objspace.descroperation.DescrOperation.xxx,
+    #        pypy.objspace.std.typeobject.W_TypeObject.lookup,
+    #        pypy.objspace.std.typeobject.W_TypeObject.getdictvalue_w)
+    seepath(pypy.objspace.descroperation.DescrOperation.add,
+            pypy.objspace.std.typeobject.W_TypeObject.lookup_where,
+            pypy.objspace.std.typeobject.W_TypeObject.getdictvalue_w)
+    # --------------------
+
+    return result_graphs
+
 
 def hintannotate(drv):
     t = drv.translator
     portal_graph = graphof(t, PORTAL)
-    
+
+    POLICY = PyPyHintAnnotatorPolicy(timeshift_graphs(t, portal_graph))
+
+    graphnames = [str(_g) for _g in POLICY.timeshift_graphs]
+    graphnames.sort()
+    print '-' * 20
+    for graphname in graphnames:
+        print graphname
+    print '-' * 20
+    import pdb; pdb.set_trace()
+
     hannotator = HintAnnotator(base_translator=t, policy=POLICY)
     hs = hannotator.build_types(portal_graph,
                                 [SomeLLAbstractConstant(v.concretetype,

Modified: pypy/branch/jit-virtual-world/pypy/jit/goal/targetjit.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/jit/goal/targetjit.py	(original)
+++ pypy/branch/jit-virtual-world/pypy/jit/goal/targetjit.py	Wed Mar 14 13:51:18 2007
@@ -46,10 +46,12 @@
         return super(PyPyJITTarget, self).target(driver, args)
 
     def handle_config(self, config):
+        super(PyPyJITTarget, self).handle_config(config)
         config.translation.fork_before = 'hintannotate'
         config.translation.backendopt.inline_threshold = 20.1
 
     def handle_translate_config(self, translateconfig):
+        super(PyPyJITTarget, self).handle_translate_config(translateconfig)
         translateconfig.goals = ['timeshift']
 
 



More information about the Pypy-commit mailing list