Author: Antonio Cuni <[email protected]>
Branch: core-only-tracing
Changeset: r51527:655088dbaa64
Date: 2012-01-20 12:01 +0100
http://bitbucket.org/pypy/pypy/changeset/655088dbaa64/

Log:    (antocuni, arigo, romain): introduce the is_core flag on JitCodes,
        which will be used to select which graphs to inline when tracing in
        core-only mode

diff --git a/pypy/jit/codewriter/call.py b/pypy/jit/codewriter/call.py
--- a/pypy/jit/codewriter/call.py
+++ b/pypy/jit/codewriter/call.py
@@ -53,6 +53,7 @@
                                                           ll_args, ll_res)
                 todo.append(c_func.value._obj.graph)
         candidate_graphs = set(todo)
+        core_candidate_graphs = set(todo)
 
         def callers():
             graph = top_graph
@@ -77,8 +78,11 @@
                     assert is_candidate(graph)
                     todo.append(graph)
                     candidate_graphs.add(graph)
+                    if policy.is_core_graph(graph):
+                        core_candidate_graphs.add(graph)
                     coming_from[graph] = top_graph
         self.candidate_graphs = candidate_graphs
+        self.core_candidate_graphs = core_candidate_graphs
         return candidate_graphs
 
     def graphs_from(self, op, is_candidate=None):
@@ -148,6 +152,9 @@
         # used only after find_all_graphs()
         return graph in self.candidate_graphs
 
+    def is_core(self, graph):
+        return graph in self.core_candidate_graphs
+
     def grab_initial_jitcodes(self):
         for jd in self.jitdrivers_sd:
             jd.mainjitcode = self.get_jitcode(jd.portal_graph)
@@ -164,8 +171,9 @@
             return self.jitcodes[graph]
         except KeyError:
             fnaddr, calldescr = self.get_jitcode_calldescr(graph)
+            is_core = self.is_core(graph)
             jitcode = JitCode(graph.name, fnaddr, calldescr,
-                              called_from=called_from)
+                              called_from=called_from, is_core=is_core)
             self.jitcodes[graph] = jitcode
             self.unfinished_graphs.append(graph)
             return jitcode
diff --git a/pypy/jit/codewriter/jitcode.py b/pypy/jit/codewriter/jitcode.py
--- a/pypy/jit/codewriter/jitcode.py
+++ b/pypy/jit/codewriter/jitcode.py
@@ -8,11 +8,12 @@
     _empty_r = []
     _empty_f = []
 
-    def __init__(self, name, fnaddr=None, calldescr=None, called_from=None):
+    def __init__(self, name, fnaddr=None, calldescr=None, called_from=None, 
is_core=False):
         self.name = name
         self.fnaddr = fnaddr
         self.calldescr = calldescr
         self.is_portal = False
+        self.is_core = is_core
         self._called_from = called_from   # debugging
         self._ssarepr     = None          # debugging
 
diff --git a/pypy/jit/codewriter/policy.py b/pypy/jit/codewriter/policy.py
--- a/pypy/jit/codewriter/policy.py
+++ b/pypy/jit/codewriter/policy.py
@@ -38,6 +38,9 @@
     def look_inside_function(self, func):
         return True # look into everything by default
 
+    def is_core_graph(self, graph):
+        return True
+
     def _reject_function(self, func):
         if hasattr(func, '_jit_look_inside_'):
             return not func._jit_look_inside_
diff --git a/pypy/jit/codewriter/test/test_call.py 
b/pypy/jit/codewriter/test/test_call.py
--- a/pypy/jit/codewriter/test/test_call.py
+++ b/pypy/jit/codewriter/test/test_call.py
@@ -10,6 +10,9 @@
     def look_inside_graph(self, graph):
         return True
 
+    def is_core_graph(self, graph):
+        return True
+
 
 def test_graphs_from_direct_call():
     cc = CallControl()
@@ -159,6 +162,7 @@
                 return lltype.functionptr(F, 'bar')
     #
     cc = CallControl(FakeCPU(FakeRTyper()))
+    cc.core_candidate_graphs = set()
     class somegraph:
         name = "foo"
     jitcode = cc.get_jitcode(somegraph)
@@ -210,3 +214,33 @@
     op = block.operations[-1]
     call_descr = cc.getcalldescr(op)
     assert call_descr.extrainfo.has_random_effects()
+
+
+def test_mark_jitcode_as_core():
+    from pypy.jit.codewriter.test.test_flatten import FakeCPU
+
+    class MyPolicy:
+        def look_inside_graph(self, graph):
+            return graph.name in ('f', 'g')
+        
+        def is_core_graph(self, graph):
+            if graph.name == 'f':
+                return True
+            return False
+
+    def g(x):
+        return x + 2
+    def f(x):
+        return g(x) + 1
+    rtyper = support.annotate(f, [7])
+    jitdriver_sd = FakeJitDriverSD(rtyper.annotator.translator.graphs[0])
+    cc = CallControl(jitdrivers_sd=[jitdriver_sd])
+    res = cc.find_all_graphs(MyPolicy())
+    # hack hack hack
+    cc.cpu = FakeCPU(rtyper)
+    cc.rtyper = rtyper
+    graphs = dict([(graph.name, graph) for graph in res])
+    jitcode_f = cc.get_jitcode(graphs['f'])
+    jitcode_g = cc.get_jitcode(graphs['g'])
+    assert jitcode_f.is_core
+    assert not jitcode_g.is_core
diff --git a/pypy/jit/codewriter/test/test_codewriter.py 
b/pypy/jit/codewriter/test/test_codewriter.py
--- a/pypy/jit/codewriter/test/test_codewriter.py
+++ b/pypy/jit/codewriter/test/test_codewriter.py
@@ -40,6 +40,9 @@
     def look_inside_graph(self, graph):
         return graph.name != 'dont_look'
 
+    def is_core_graph(self, graph):
+        return True
+
 class FakeJitDriverSD:
     def __init__(self, portal_graph):
         self.portal_graph = portal_graph
@@ -162,6 +165,9 @@
             name = graph.name
             return not (name.startswith('instantiate_') and
                         name.endswith('A2'))
+
+        def is_core_graph(self, graph):
+            return True
     class A1:
         pass
     class A2(A1):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to