[pypy-svn] r24884 - in pypy/branch/explicit-exceptions/translator: backendopt c

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Mar 23 16:39:59 CET 2006


Author: cfbolz
Date: Thu Mar 23 16:39:59 2006
New Revision: 24884

Modified:
   pypy/branch/explicit-exceptions/translator/backendopt/inline.py
   pypy/branch/explicit-exceptions/translator/c/exceptiontransform.py
Log:
(mwh, arre, pedronis)

introduce a OneShotInliner to be used by the exceptiontransform. Avoids some of the overdoing
of the normal Inliner.



Modified: pypy/branch/explicit-exceptions/translator/backendopt/inline.py
==============================================================================
--- pypy/branch/explicit-exceptions/translator/backendopt/inline.py	(original)
+++ pypy/branch/explicit-exceptions/translator/backendopt/inline.py	Thu Mar 23 16:39:59 2006
@@ -101,19 +101,11 @@
                 return True
     return False
 
-class Inliner(object):
-    def __init__(self, translator, graph, inline_func, inline_guarded_calls=False,
+class BaseInliner(object):
+    def __init__(self, translator, graph, inline_guarded_calls=False,
                  inline_guarded_calls_no_matter_what=False):
         self.translator = translator
         self.graph = graph
-        self.inline_func = inline_func
-        # to simplify exception matching
-        join_blocks(graph)
-        # find callsites *after* joining blocks...
-        callsites = find_callsites(graph, inline_func)
-        self.block_to_index = {}
-        for g, block, i in callsites:
-            self.block_to_index.setdefault(block, {})[i] = g
         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
@@ -223,7 +215,6 @@
         newlink.last_exc_value = self.get_new_name(link.last_exc_value)
         if hasattr(link, 'llexitcase'):
             newlink.llexitcase = link.llexitcase
-        return newlink
         
     def generate_keepalive(self, vars):
         keepalive_ops = []
@@ -406,6 +397,29 @@
         join_blocks(self.graph)
         remove_identical_vars(self.graph)
 
+class Inliner(BaseInliner):
+    def __init__(self, translator, graph, inline_func, inline_guarded_calls=False,
+                 inline_guarded_calls_no_matter_what=False):
+        BaseInliner.__init__(self, translator, graph, 
+                             inline_guarded_calls, inline_guarded_calls_no_matter_what)
+        self.inline_func = inline_func
+        # to simplify exception matching
+        join_blocks(graph)
+        # find callsites *after* joining blocks...
+        callsites = find_callsites(graph, inline_func)
+        self.block_to_index = {}
+        for g, block, i in callsites:
+            self.block_to_index.setdefault(block, {})[i] = g
+
+class OneShotInliner(BaseInliner):
+    def __init__(self, translator, graph, inline_guarded_calls=False,
+                 inline_guarded_calls_no_matter_what=False):
+         BaseInliner.__init__(self, translator, graph, 
+                              inline_guarded_calls, inline_guarded_calls_no_matter_what)
+
+    def search_for_calls(self, block):
+        pass
+
 
 def _inline_function(translator, graph, block, index_operation):
     inline_func = block.operations[index_operation].args[0].value._obj._callable

Modified: pypy/branch/explicit-exceptions/translator/c/exceptiontransform.py
==============================================================================
--- pypy/branch/explicit-exceptions/translator/c/exceptiontransform.py	(original)
+++ pypy/branch/explicit-exceptions/translator/c/exceptiontransform.py	Thu Mar 23 16:39:59 2006
@@ -1,3 +1,4 @@
+from pypy.translator.simplify import join_blocks
 from pypy.translator.unsimplify import copyvar, split_block
 from pypy.translator.backendopt import canraise, inline
 from pypy.objspace.flow.model import Block, Constant, Variable, Link, \
@@ -90,13 +91,14 @@
         from the current graph with a special value (False/-1/-1.0/null).
         Because of the added exitswitch we need an additional block.
         """
+        join_blocks(graph)
         for block in list(graph.iterblocks()): #collect the blocks before changing them
             self.transform_block(graph, block)
+        self.transform_except_block(graph, graph.exceptblock)
         checkgraph(graph)
 
     def transform_block(self, graph, block):
         if block is graph.exceptblock:
-            self.transform_except_block(graph, block)
             return
         elif block is graph.returnblock:
             return
@@ -148,10 +150,9 @@
         #non-exception case
         block.exits[0].exitcase = block.exits[0].llexitcase = None
         # use the dangerous second True flag :-)
-        inliner = inline.Inliner(self.translator, graph, proxygraph, True, True)
-        count = inliner.inline_all()
-        assert count > 0, "didn't inline"
-        block.exits[0].exitcase = block.exits[0].llexitcase = False
+        inliner = inline.OneShotInliner(self.translator, graph, True, True)
+        inliner.inline_once(block, len(block.operations)-1)
+        #block.exits[0].exitcase = block.exits[0].llexitcase = False
 
     def create_proxy_graph(self, op):
         """ creates a graph which calls the original function, checks for



More information about the Pypy-commit mailing list