[pypy-svn] r24366 - in pypy/dist/pypy/translator: . backendopt backendopt/test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Mar 14 19:00:24 CET 2006


Author: cfbolz
Date: Tue Mar 14 19:00:17 2006
New Revision: 24366

Modified:
   pypy/dist/pypy/translator/backendopt/inline.py
   pypy/dist/pypy/translator/backendopt/test/test_inline.py
   pypy/dist/pypy/translator/simplify.py
Log:
make inlining and one of the simplifications used by inlining do the right
thing wrt cleanups. this should make it possible to use inlining together with
push/pop of roots in the gcs soon.


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 19:00:17 2006
@@ -93,6 +93,7 @@
         self.varmap = {}
         self.beforeblock = block
         self._copied_blocks = {}
+        self._copied_cleanups = {}
         self.op = block.operations[index_operation]
         self.graph_to_inline = self.op.args[0].value._obj.graph
         self.exception_guarded = False
@@ -125,7 +126,24 @@
         
     def copy_operation(self, op):
         args = [self.get_new_name(arg) for arg in op.args]
-        return SpaceOperation(op.opname, args, self.get_new_name(op.result))
+        result = SpaceOperation(op.opname, args, self.get_new_name(op.result))
+        if getattr(op, "cleanup", None) is not None:
+            result.cleanup = self.copy_cleanup(op.cleanup)
+        return result
+
+    def copy_cleanup(self, cleanup):
+        if cleanup in self._copied_cleanups:
+            return self._copied_cleanups[cleanup]
+        finallyops, exceptops = cleanup
+        copyfinallyops = []
+        for op in finallyops:
+            copyfinallyops.append(self.copy_operation(op))
+        copyexceptops = []
+        for op in exceptops:
+            copyexceptops.append(self.copy_operation(op))    
+        copycleanup = (tuple(copyfinallyops), tuple(copyexceptops))
+        self._copied_cleanups[cleanup] = copycleanup
+        return copycleanup
 
     def copy_block(self, block):
         if block in self._copied_blocks:

Modified: pypy/dist/pypy/translator/backendopt/test/test_inline.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_inline.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_inline.py	Tue Mar 14 19:00:17 2006
@@ -401,7 +401,7 @@
     ggraph.startblock.operations[0].cleanup = cleanup
     py.test.raises(CannotInline, inline_function, t, f, ggraph)
 
-def DONOTtest_inline_copies_cleanups():
+def test_inline_copies_cleanups():
     from pypy.objspace.flow.model import Variable, SpaceOperation, Constant
     from pypy.rpython.lltypesystem.lltype import Signed
     import math
@@ -419,6 +419,6 @@
     cleanup = ((cleanupop, ), (cleanupop, ))
     graph.startblock.operations[0].cleanup = cleanup
     inline_function(t, f, ggraph)
-    assert ggraph.startblock.operations[0].cleanup == cleanup
-    if option.view: 
+    if option.view:
         t.view()
+    assert hasattr(ggraph.startblock.operations[0], "cleanup")

Modified: pypy/dist/pypy/translator/simplify.py
==============================================================================
--- pypy/dist/pypy/translator/simplify.py	(original)
+++ pypy/dist/pypy/translator/simplify.py	Tue Mar 14 19:00:17 2006
@@ -300,14 +300,27 @@
                 len(entrymap[link.target]) == 1 and
                 link.target.exits):  # stop at the returnblock
                 renaming = {}
+                cache_cleanups = {}
                 for vprev, vtarg in zip(link.args, link.target.inputargs):
                     renaming[vtarg] = vprev
                 def rename(v):
                     return renaming.get(v, v)
-                for op in link.target.operations:
+                def rename_op(op):
                     args = [rename(a) for a in op.args]
-                    op = SpaceOperation(op.opname, args, rename(op.result))
-                    link.prevblock.operations.append(op)
+                    if getattr(op, "cleanup", None) is not None:
+                        if 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]))
+                            cache_cleanups[op.cleanup] = cleanup
+                        else:
+                            cleanup = cache_cleanups[op.cleanup] 
+                        op = SpaceOperation(op.opname, args, rename(op.result), cleanup=cleanup)
+                    else:
+                        op = SpaceOperation(op.opname, args, rename(op.result))
+                    return op
+                for op in link.target.operations:
+                    link.prevblock.operations.append(rename_op(op))
                 exits = []
                 for exit in link.target.exits:
                     newexit = exit.copy(rename)



More information about the Pypy-commit mailing list