[pypy-svn] r17587 - in pypy/dist/pypy/translator/backendopt: . test
arigo at codespeak.net
arigo at codespeak.net
Fri Sep 16 11:04:43 CEST 2005
Author: arigo
Date: Fri Sep 16 11:04:41 2005
New Revision: 17587
Modified:
pypy/dist/pypy/translator/backendopt/malloc.py
pypy/dist/pypy/translator/backendopt/test/test_malloc.py
Log:
Finally, with a good remove_identical_vars(), a sufficient condition for
disabling malloc removal is to see if the pointer variable is ever duplicated
along a link. So the fix is easy, after all. (Good to be more awake than
yesterday evening :-)
Modified: pypy/dist/pypy/translator/backendopt/malloc.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/malloc.py (original)
+++ pypy/dist/pypy/translator/backendopt/malloc.py Fri Sep 16 11:04:41 2005
@@ -71,9 +71,18 @@
if isinstance(node.last_exc_value, Variable):
set_creation_point(node.prevblock, node.last_exc_value,
"last_exc_value")
- for i in range(len(node.args)):
- union(node.prevblock, node.args[i],
+ d = {}
+ for i, arg in enumerate(node.args):
+ union(node.prevblock, arg,
node.target, node.target.inputargs[i])
+ if isinstance(arg, Variable):
+ if arg in d:
+ # same variable present several times in link.args
+ # consider it as a 'use' of the variable, which
+ # will disable malloc optimization (aliasing problems)
+ set_use_point(node.prevblock, arg, "dup", node, i)
+ else:
+ d[arg] = True
traverse(visit, graph)
return lifetimes.infos()
Modified: pypy/dist/pypy/translator/backendopt/test/test_malloc.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_malloc.py (original)
+++ pypy/dist/pypy/translator/backendopt/test/test_malloc.py Fri Sep 16 11:04:41 2005
@@ -17,13 +17,14 @@
assert count1 == 0 # number of mallocs left
assert count2 == 0 # number of direct_calls left
-def check(fn, signature, args, expected_result):
+def check(fn, signature, args, expected_result, must_be_removed=True):
t = Translator(fn)
t.annotate(signature)
t.specialize()
graph = t.getflowgraph()
remove_simple_mallocs(graph)
- check_malloc_removed(graph)
+ if must_be_removed:
+ check_malloc_removed(graph)
interp = LLInterpreter(t.flowgraphs, t.rtyper)
res = interp.eval_function(fn, args)
assert res == expected_result
@@ -95,4 +96,4 @@
a = a2
a.x = 12
return a1.x
- check(fn6, [int], [1], 12)
+ check(fn6, [int], [1], 12, must_be_removed=False)
More information about the Pypy-commit
mailing list