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

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Mar 14 14:07:10 CET 2006


Author: cfbolz
Date: Tue Mar 14 14:07:03 2006
New Revision: 24359

Modified:
   pypy/dist/pypy/translator/backendopt/inline.py
   pypy/dist/pypy/translator/backendopt/test/test_inline.py
Log:
don't inline direct_calls that have a cleanup attached. test.
a disabled test that tests whether the inlines contained in the to be inlined
function are copied


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 14:07:03 2006
@@ -60,6 +60,9 @@
         subgraph, block, index_operation = callsites.pop()
         if find_callsites(subgraph, subgraph):
             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")
         _inline_function(translator, graph, block, index_operation)
         checkgraph(graph)
         count += 1

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 14:07:03 2006
@@ -11,6 +11,7 @@
 from pypy.rpython.llinterp import LLInterpreter
 from pypy.rpython.rarithmetic import ovfcheck
 from pypy.translator.test.snippet import is_perfect_number
+from pypy.conftest import option
 
 def no_missing_concretetype(node):
     if isinstance(node, Block):
@@ -380,4 +381,44 @@
         return 1
     assert x4() == 1
     py.test.raises(CannotInline, check_inline, x3, x4, [])
-
+    
+def test_dont_inline_with_cleanups():
+    from pypy.objspace.flow.model import Variable, SpaceOperation, Constant
+    from pypy.rpython.lltypesystem.lltype import Signed
+    import math
+    def f(x):
+        return math.sqrt(x)
+    def g(x):
+        return f(x)
+    t = translate(g, [int])
+    graph = graphof(t, f)
+    ggraph = graphof(t, g)
+    xvar = ggraph.startblock.inputargs[0]
+    result = Variable()
+    result.concretetype = Signed
+    cleanupop = SpaceOperation("int_add", [Constant(1, Signed), xvar], result)
+    cleanup = ((cleanupop, ), (cleanupop, ))
+    ggraph.startblock.operations[0].cleanup = cleanup
+    py.test.raises(CannotInline, inline_function, t, f, ggraph)
+
+def DONOTtest_inline_copies_cleanups():
+    from pypy.objspace.flow.model import Variable, SpaceOperation, Constant
+    from pypy.rpython.lltypesystem.lltype import Signed
+    import math
+    def f(x):
+        return math.sqrt(x)
+    def g(x):
+        return f(x)
+    t = translate(g, [int])
+    graph = graphof(t, f)
+    ggraph = graphof(t, g)
+    xvar = graph.startblock.inputargs[0]
+    result = Variable()
+    result.concretetype = Signed
+    cleanupop = SpaceOperation("int_add", [Constant(1, Signed), xvar], result)
+    cleanup = ((cleanupop, ), (cleanupop, ))
+    graph.startblock.operations[0].cleanup = cleanup
+    inline_function(t, f, ggraph)
+    assert ggraph.startblock.operations[0].cleanup == cleanup
+    if option.view: 
+        t.view()



More information about the Pypy-commit mailing list