[pypy-svn] r48271 - in pypy/dist/pypy/translator/backendopt: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Sat Nov 3 18:09:47 CET 2007
Author: cfbolz
Date: Sat Nov 3 18:09:47 2007
New Revision: 48271
Modified:
pypy/dist/pypy/translator/backendopt/coalloc.py
pypy/dist/pypy/translator/backendopt/test/test_coalloc.py
Log:
another test, tweaks
Modified: pypy/dist/pypy/translator/backendopt/coalloc.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/coalloc.py (original)
+++ pypy/dist/pypy/translator/backendopt/coalloc.py Sat Nov 3 18:09:47 2007
@@ -316,17 +316,18 @@
continue
tovarstate = adi.getstate(op.args[-1])
fromvarstate = adi.getstate(op.args[0])
- if (len(tovarstate.creation_points) != 1 or
- len(fromvarstate.creation_points) != 1):
+ if len(tovarstate.creation_points) != 1:
continue
- fromcrep = fromvarstate.creation_points.keys()[0]
+ fromcreps = set(fromvarstate.creation_points.keys())
tocrep = tovarstate.creation_points.keys()[0]
if not tocrep.creation_method.startswith("malloc"):
continue
- if fromcrep.creation_method.startswith("malloc"):
- continue # also recently malloced
+ for fromcrep in fromcreps:
+ if fromcrep.creation_method.startswith("malloc"):
+ continue # also recently malloced
- num = do_coalloc(adi, graph, fromcrep, tocrep)
+ num = do_coalloc(adi, graph, op.args[0], block,
+ fromcreps, tocrep)
if num:
look_at.append(graph)
@@ -335,24 +336,28 @@
return total
-def do_coalloc(adi, graph, fromcrep, tocrep):
- result = 0
- for block, op in graph.iterblockops():
- if not op.opname.startswith("malloc"):
- continue
- # find coallocation var
- if fromcrep.creation_method == "constant":
- coallocvar = fromcrep.constant
- else:
+def do_coalloc(adi, graph, fromvar, setblock, fromcreps, tocrep):
+ def find_coalloc_var():
+ if block is setblock:
+ return fromvar
+ for fromcrep in fromcreps:
+ if fromcrep.creation_method == "constant":
+ return fromcrep.constant
+ for fromcrep in fromcreps:
for var in block.inputargs:
varstate = adi.getstate(var)
assert len(varstate.creation_points) == 1
crep = varstate.creation_points.keys()[0]
if crep is fromcrep:
- coallocvar = var
- break
- else:
- continue
+ return var
+ return None
+ result = 0
+ for block, op in graph.iterblockops():
+ if not op.opname.startswith("malloc"):
+ continue
+ coallocvar = find_coalloc_var()
+ if coallocvar is None:
+ continue
op.opname = "coalloc" + op.opname[len("malloc"):]
op.args.insert(1, coallocvar)
mallocvarstate = adi.getstate(op.result)
Modified: pypy/dist/pypy/translator/backendopt/test/test_coalloc.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_coalloc.py (original)
+++ pypy/dist/pypy/translator/backendopt/test/test_coalloc.py Sat Nov 3 18:09:47 2007
@@ -33,7 +33,8 @@
assert op.opname != "malloc"
else:
assert num == must_remove
- t.view()
+ if conftest.option.view:
+ t.view()
res = interp.eval_graph(graph, args)
assert res == expected_result
return t
@@ -171,3 +172,17 @@
return 4
t = check_malloc_to_coalloc(f, [], [], 4, must_remove=1)
+def test_coalloc_with_arg_several_creationpoints():
+ class A(object):
+ pass
+ a1 = A()
+ def g(cond, b):
+ if cond:
+ b = a1
+ b.x = A()
+ def f(cond):
+ a2 = A()
+ g(cond, a2)
+ return 4
+ t = check_malloc_to_coalloc(f, [bool], [True], 4, must_remove=1)
+
More information about the Pypy-commit
mailing list