[pypy-svn] r62873 - in pypy/branch/pyjitpl5/pypy/translator/backendopt: . test

arigo at codespeak.net arigo at codespeak.net
Thu Mar 12 10:57:44 CET 2009


Author: arigo
Date: Thu Mar 12 10:57:42 2009
New Revision: 62873

Modified:
   pypy/branch/pyjitpl5/pypy/translator/backendopt/inline.py
   pypy/branch/pyjitpl5/pypy/translator/backendopt/test/test_inline.py
Log:
Merge a checkin by cfbolz:
    
    Write a simple inlining heuristic that never inlines graphs that
    have an oopspec attached.



Modified: pypy/branch/pyjitpl5/pypy/translator/backendopt/inline.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/translator/backendopt/inline.py	(original)
+++ pypy/branch/pyjitpl5/pypy/translator/backendopt/inline.py	Thu Mar 12 10:57:42 2009
@@ -624,6 +624,12 @@
     return (0.9999 * measure_median_execution_cost(graph) +
             count), True
 
+def inlining_heuristic_no_oopspec(graph):
+    try:
+        oopspec = graph.func.oopspec
+    except AttributeError:
+        return inlining_heuristic(graph)
+    return (sys.maxint, True)
 
 def inlinable_static_callers(graphs):
     ok_to_call = dict.fromkeys(graphs)

Modified: pypy/branch/pyjitpl5/pypy/translator/backendopt/test/test_inline.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/translator/backendopt/test/test_inline.py	(original)
+++ pypy/branch/pyjitpl5/pypy/translator/backendopt/test/test_inline.py	Thu Mar 12 10:57:42 2009
@@ -9,6 +9,7 @@
 from pypy.translator.backendopt.inline import collect_called_graphs
 from pypy.translator.backendopt.inline import measure_median_execution_cost
 from pypy.translator.backendopt.inline import instrument_inline_candidates
+from pypy.translator.backendopt.inline import inlining_heuristic_no_oopspec
 from pypy.translator.backendopt.checkvirtual import check_virtual_methods
 from pypy.translator.translator import TranslationContext, graphof
 from pypy.rpython.llinterp import LLInterpreter
@@ -92,7 +93,7 @@
         return eval_func
 
     def check_auto_inlining(self, func, sig, multiplier=None, call_count_check=False,
-                            checkvirtual=False, remove_same_as=False):
+                            checkvirtual=False, remove_same_as=False, heuristic=None):
         t = self.translate(func, sig)
         if checkvirtual:
             check_virtual_methods()
@@ -114,7 +115,11 @@
             for graph in t.graphs:
                 removenoops.remove_same_as(graph)
             
-        auto_inlining(t, threshold, call_count_pred=call_count_pred)
+        if heuristic is not None:
+            kwargs = {"heuristic": heuristic}
+        else:
+            kwargs = {}
+        auto_inlining(t, threshold, call_count_pred=call_count_pred, **kwargs)
 
         sanity_check(t)
         if option.view:
@@ -597,6 +602,24 @@
         res = eval_func([])
         assert res == 5
 
+    def test_no_oopspec_inliner(self):
+        def f():
+            tot = 0
+            for item in [1,2,3]:
+                tot += item
+            return tot
+
+        eval_func, t = self.check_auto_inlining(
+            f, [], heuristic=inlining_heuristic_no_oopspec)
+        f_graph = graphof(t, f)
+        called_graphs = collect_called_graphs(f_graph, t, include_oosend=False)
+        print called_graphs
+        assert len(called_graphs) == 4 # newlist, setitem, getitem, length
+
+        result = eval_func([])
+        assert result == 6
+
+
 
 class TestInlineOOType(OORtypeMixin, BaseTestInline):
 



More information about the Pypy-commit mailing list