[pypy-svn] r47701 - in pypy/dist/pypy: rpython/memory/gctransform translator/backendopt

fijal at codespeak.net fijal at codespeak.net
Mon Oct 22 10:51:24 CEST 2007


Author: fijal
Date: Mon Oct 22 10:51:21 2007
New Revision: 47701

Modified:
   pypy/dist/pypy/rpython/memory/gctransform/transform.py
   pypy/dist/pypy/translator/backendopt/inline.py
Log:
Speed up inlining (especially important when inlining helpers)


Modified: pypy/dist/pypy/rpython/memory/gctransform/transform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform/transform.py	(original)
+++ pypy/dist/pypy/rpython/memory/gctransform/transform.py	Mon Oct 22 10:51:21 2007
@@ -19,6 +19,7 @@
 from pypy.rlib.rarithmetic import ovfcheck
 import sets, os, sys
 from pypy.rpython.lltypesystem.lloperation import llop
+from pypy.translator.simplify import join_blocks, cleanup_graph
 
 def var_ispyobj(var):
     if hasattr(var, 'concretetype'):
@@ -141,11 +142,12 @@
                     # XXX quite inefficient: we go over the function lots of times
                     inline.inline_function(self.translator, inline_graph, graph,
                                            self.lltype_to_classdef,
-                                           raise_analyzer)
+                                           raise_analyzer,
+                                           cleanup=False)
                 except inline.CannotInline, e:
                     print 'CANNOT INLINE:', e
                     print '\t%s into %s' % (inline_graph, graph)
-            checkgraph(graph)
+            cleanup_graph(graph)
 
     def compute_borrowed_vars(self, graph):
         # the input args are borrowed, and stay borrowed for as long as they

Modified: pypy/dist/pypy/translator/backendopt/inline.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/inline.py	(original)
+++ pypy/dist/pypy/translator/backendopt/inline.py	Mon Oct 22 10:51:21 2007
@@ -100,10 +100,10 @@
         return False
 
 def inline_function(translator, inline_func, graph, lltype_to_classdef,
-                    raise_analyzer, call_count_pred=None):
+                    raise_analyzer, call_count_pred=None, cleanup=True):
     inliner = Inliner(translator, graph, inline_func, lltype_to_classdef,
                       raise_analyzer = raise_analyzer,
-                      call_count_pred=call_count_pred)
+                      call_count_pred=call_count_pred, cleanup=cleanup)
     return inliner.inline_all()
 
 def simple_inline_function(translator, inline_func, graph):
@@ -178,9 +178,11 @@
                  inline_guarded_calls=False,
                  inline_guarded_calls_no_matter_what=False,
                  raise_analyzer=None,
-                 call_count_pred=None):
+                 call_count_pred=None,
+                 cleanup=True):
         self.translator = translator
         self.graph = graph
+        self.do_cleanup = cleanup
         self.inline_guarded_calls = inline_guarded_calls
         # if this argument is set, the inliner will happily produce wrong code!
         # it is used by the exception transformation
@@ -213,7 +215,8 @@
             operation = block.operations[index_operation]
             self.inline_once(block, index_operation)
             count += 1
-        self.cleanup()
+        if self.do_cleanup:
+            self.cleanup()
         return count
 
     def get_graph_from_op(self, op):
@@ -512,12 +515,14 @@
                  inline_guarded_calls=False,
                  inline_guarded_calls_no_matter_what=False,
                  raise_analyzer=None,
-                 call_count_pred=None):
+                 call_count_pred=None,
+                 cleanup=True):
         BaseInliner.__init__(self, translator, graph, lltype_to_classdef,
                              inline_guarded_calls,
                              inline_guarded_calls_no_matter_what,
                              raise_analyzer,
-                             call_count_pred)
+                             call_count_pred,
+                             cleanup)
         self.inline_func = inline_func
         # to simplify exception matching
         join_blocks(graph)
@@ -683,7 +688,9 @@
                   callgraph=None,
                   call_count_pred=None,
                   heuristic=inlining_heuristic):
+    
     assert threshold is not None and threshold != 1
+    to_cleanup = {}
     from heapq import heappush, heappop, heapreplace, heapify
     callers = {}     # {graph: {graphs-that-call-it}}
     callees = {}     # {graph: {graphs-that-it-calls}}
@@ -699,7 +706,6 @@
     lltype_to_classdef = translator.rtyper.lltype_to_classdef_mapping()
     raise_analyzer = RaiseAnalyzer(translator)
     count = 0
-
     while heap:
         weight, _, graph = heap[0]
         if not valid_weight.get(graph):
@@ -744,7 +750,8 @@
             try:
                 subcount = inline_function(translator, graph, parentgraph,
                                            lltype_to_classdef, raise_analyzer,
-                                           call_count_pred)
+                                           call_count_pred, cleanup=False)
+                to_cleanup[graph] = True
                 res = bool(subcount)
             except CannotInline:
                 try_again[graph] = True
@@ -763,6 +770,8 @@
                     del try_again[parentgraph]
                     heappush(heap, (0.0, -len(callers[parentgraph]), parentgraph))
                 valid_weight[parentgraph] = False
+    for graph in to_cleanup:
+        cleanup_graph(graph)
     return count
 
 def auto_inline_graphs(translator, graphs, threshold, call_count_pred=None,



More information about the Pypy-commit mailing list