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

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Jan 16 15:40:05 CET 2006


Author: cfbolz
Date: Mon Jan 16 15:40:04 2006
New Revision: 22223

Modified:
   pypy/dist/pypy/translator/backendopt/escape.py
   pypy/dist/pypy/translator/backendopt/test/test_escape.py
Log:
don't convert mallocs that are in loops to allocas


Modified: pypy/dist/pypy/translator/backendopt/escape.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/escape.py	(original)
+++ pypy/dist/pypy/translator/backendopt/escape.py	Mon Jan 16 15:40:04 2006
@@ -394,6 +394,7 @@
 def malloc_to_stack(t):
     aib = AbstractDataFlowInterpreter(t)
     for graph in t.graphs:
+        loop_blocks = find_loop_blocks(graph)
         for block in graph.iterblocks():
             for op in block.operations:
                 if op.opname == 'malloc':
@@ -403,7 +404,7 @@
                     varstate = aib.getstate(op.result)
                     assert len(varstate.creation_points) == 1
                     crep = varstate.creation_points.keys()[0]
-                    if not crep.escapes:
+                    if not crep.escapes and block not in loop_blocks:
                         print "moving object from heap to stack %s in %s" % (op, graph.name)
                         op.opname = 'flavored_malloc'
                         op.args.insert(0, inputconst(lltype.Void, 'stack'))

Modified: pypy/dist/pypy/translator/backendopt/test/test_escape.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_escape.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_escape.py	Mon Jan 16 15:40:04 2006
@@ -412,3 +412,16 @@
         return g(a)
     t = check_malloc_removal(f, [], [], 4)
 
+def test_dont_alloca_in_loops():
+    class A(object):
+        pass
+    def f(x):
+        result = 0
+        for i in range(x):
+            a = A()
+            a.i = i
+            result += a.i
+        return result
+    t = check_malloc_removal(f, [int], [3], 3,must_remove=False)
+    graph = graphof(t, f)
+    assert graph.startblock.exits[0].target.exits[0].target.operations[0].opname == "malloc"



More information about the Pypy-commit mailing list