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

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Mar 14 20:22:58 CET 2006


Author: cfbolz
Date: Tue Mar 14 20:22:54 2006
New Revision: 24368

Modified:
   pypy/dist/pypy/rpython/memory/gctransform.py
   pypy/dist/pypy/translator/backendopt/inline.py
   pypy/dist/pypy/translator/simplify.py
Log:
inline push/pop of the roots and malloc in the gctransformer when possible


Modified: pypy/dist/pypy/rpython/memory/gctransform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform.py	(original)
+++ pypy/dist/pypy/rpython/memory/gctransform.py	Tue Mar 14 20:22:54 2006
@@ -35,13 +35,15 @@
 class GCTransformer(object):
     finished = False
 
-    def __init__(self, translator):
+    def __init__(self, translator, inline=False):
         self.translator = translator
         self.seen_graphs = {}
         if translator:
             self.mixlevelannotator = MixLevelHelperAnnotator(translator.rtyper)
         else:
             self.mixlevelannotator = None
+        self.inline = inline
+        self.graphs_to_inline = {}
 
     def get_lltype_of_exception_value(self):
         if self.translator is not None and self.translator.rtyper is not None:
@@ -78,6 +80,13 @@
         v = Variable('vanishing_exc_value')
         v.concretetype = self.get_lltype_of_exception_value()
         graph.exc_cleanup = (v, self.pop_alive(v))
+        if self.inline:
+            from pypy.translator.backendopt import inline
+            for inline_graph in self.graphs_to_inline:
+                try:
+                    inline.inline_function(self.translator, inline_graph, graph)
+                except inline.CannotInline:
+                    pass
 
     def transform_block(self, block):
         newops = []
@@ -545,8 +554,8 @@
 class BoehmGCTransformer(GCTransformer):
     gc_header_offset = gc.GCHeaderOffset(lltype.Void)
 
-    def __init__(self, translator):
-        super(BoehmGCTransformer, self).__init__(translator)
+    def __init__(self, translator, inline=False):
+        super(BoehmGCTransformer, self).__init__(translator, inline=inline)
         self.finalizer_funcptrs = {}
 
     def push_alive_nopyobj(self, var):
@@ -647,7 +656,7 @@
 class FrameworkGCTransformer(BoehmGCTransformer):
 
     def __init__(self, translator):
-        super(FrameworkGCTransformer, self).__init__(translator)
+        super(FrameworkGCTransformer, self).__init__(translator, inline=True)
         class GCData(object):
             from pypy.rpython.memory.gc import MarkSweepGC as GCClass
             startheapsize = 640*1024    # XXX adjust
@@ -791,8 +800,11 @@
         self.frameworkgc_setup_ptr = self.graph2funcptr(frameworkgc_setup_graph,
                                                         attach_empty_cleanup=True)
         self.push_root_ptr = self.graph2funcptr(push_root_graph)
+        self.graphs_to_inline[push_root_graph] = True
         self.pop_root_ptr  = self.graph2funcptr(pop_root_graph)
+        self.graphs_to_inline[pop_root_graph] = True
         self.malloc_ptr    = self.graph2funcptr(malloc_graph, True)
+        self.graphs_to_inline[malloc_graph] = True
 
     def graph2funcptr(self, graph, attach_empty_cleanup=False):
         self.seen_graphs[graph] = True

Modified: pypy/dist/pypy/translator/backendopt/inline.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/inline.py	(original)
+++ pypy/dist/pypy/translator/backendopt/inline.py	Tue Mar 14 20:22:54 2006
@@ -62,7 +62,9 @@
             raise CannotInline("inlining a recursive function")
         operation = block.operations[index_operation]
         if getattr(operation, "cleanup", None) is not None:
-            raise CannotInline("cannot inline a function with cleanup attached")
+            finallyops, exceptops = operation.cleanup
+            if finallyops or exceptops:
+                raise CannotInline("cannot inline a function with cleanup attached")
         _inline_function(translator, graph, block, index_operation)
         checkgraph(graph)
         count += 1
@@ -132,6 +134,8 @@
         return result
 
     def copy_cleanup(self, cleanup):
+        if cleanup is None:
+            return None
         if cleanup in self._copied_cleanups:
             return self._copied_cleanups[cleanup]
         finallyops, exceptops = cleanup

Modified: pypy/dist/pypy/translator/simplify.py
==============================================================================
--- pypy/dist/pypy/translator/simplify.py	(original)
+++ pypy/dist/pypy/translator/simplify.py	Tue Mar 14 20:22:54 2006
@@ -307,8 +307,10 @@
                     return renaming.get(v, v)
                 def rename_op(op):
                     args = [rename(a) for a in op.args]
-                    if getattr(op, "cleanup", None) is not None:
-                        if op.cleanup not in cache_cleanups:
+                    if hasattr(op, "cleanup"):
+                        if op.cleanup is None:
+                            cleanup = None
+                        elif op.cleanup not in cache_cleanups:
                             finallyops, exceptops = op.cleanup
                             cleanup = (tuple([rename_op(fo) for fo in finallyops]),
                                        tuple([rename_op(eo) for eo in exceptops]))



More information about the Pypy-commit mailing list