[pypy-svn] r25615 - in pypy/dist/pypy/translator/backendopt: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Sun Apr 9 13:18:07 CEST 2006
Author: cfbolz
Date: Sun Apr 9 13:18:06 2006
New Revision: 25615
Modified:
pypy/dist/pypy/translator/backendopt/mallocprediction.py
pypy/dist/pypy/translator/backendopt/test/test_mallocprediction.py
Log:
make malloc prediction work for indirect_calls
Modified: pypy/dist/pypy/translator/backendopt/mallocprediction.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/mallocprediction.py (original)
+++ pypy/dist/pypy/translator/backendopt/mallocprediction.py Sun Apr 9 13:18:06 2006
@@ -54,6 +54,8 @@
if op.opname == "indirect_call":
for var in op.args[:-1]:
varstate = adi.getstate(var)
+ if varstate is None:
+ continue
for crep in varstate.creation_points:
if crep in interesting_creps:
del interesting_creps[crep]
Modified: pypy/dist/pypy/translator/backendopt/test/test_mallocprediction.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_mallocprediction.py (original)
+++ pypy/dist/pypy/translator/backendopt/test/test_mallocprediction.py Sun Apr 9 13:18:06 2006
@@ -84,6 +84,38 @@
callgraph, caller_candidates = check_inlining(t, graph, [0], 3 * 42)
assert callgraph[graph] == {g2graph: True}
+def test_indirect_call():
+ class A(object):
+ pass
+ def f1(a, i):
+ return a.x
+ def f2(a, i):
+ return a.x + 1
+ def g1(a, i):
+ return a
+ def g2(a, i):
+ return None
+ def f(i):
+ a1 = A()
+ a2 = A()
+ a1.x = 1
+ a2.x = 2
+ if i:
+ f = f1
+ g = g1
+ else:
+ f = f2
+ g = g2
+ x = f(a1, 0)
+ a0 = g(a2, 1)
+ if a0 is not None:
+ return 43
+ else:
+ return 42
+ t, graph = rtype(f, [int])
+ callgraph, caller_candidate = check_inlining(t, graph, [0], 42)
+ assert caller_candidate == {}
+
def test_pystone():
from pypy.translator.goal.targetrpystonex import make_target_definition
entrypoint, _, _ = make_target_definition(10)
More information about the Pypy-commit
mailing list