[pypy-commit] pypy better-storesink: forward the size of an object from malloc_varsize to getarraysize
cfbolz
pypy.commits at gmail.com
Wed Oct 12 11:46:34 EDT 2016
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: better-storesink
Changeset: r87725:5a4c1641fe8b
Date: 2016-09-19 22:18 +0200
http://bitbucket.org/pypy/pypy/changeset/5a4c1641fe8b/
Log: forward the size of an object from malloc_varsize to getarraysize
diff --git a/rpython/translator/backendopt/cse.py b/rpython/translator/backendopt/cse.py
--- a/rpython/translator/backendopt/cse.py
+++ b/rpython/translator/backendopt/cse.py
@@ -263,6 +263,11 @@
# they run the risk of being passed around too much
self._clear_heapcache_for_effects(
{('struct', T, op.args[1].value)})
+ if op.opname == "malloc_varsize":
+ # we can remember the size of the malloced object
+ key = ("getarraysize", lltype.Signed,
+ (representative_arg(op.result), ))
+ self.purecache[key] = op.args[2]
if has_side_effects(op):
self._clear_heapcache_for_effects_of_op(op)
diff --git a/rpython/translator/backendopt/test/test_cse.py b/rpython/translator/backendopt/test/test_cse.py
--- a/rpython/translator/backendopt/test/test_cse.py
+++ b/rpython/translator/backendopt/test/test_cse.py
@@ -13,13 +13,15 @@
t.buildrtyper().specialize()
return t
- def check(self, f, argtypes, **expected):
+ def check(self, f, argtypes, fullopts=False, **expected):
from rpython.translator.backendopt import inline, all, constfold
t = self.translate(f, argtypes)
getfields = 0
graph = graphof(t, f)
if option.view:
t.view()
+ if fullopts:
+ all.backend_optimizations(t)
removenoops.remove_same_as(graph)
checkgraph(graph)
cse = CSE(t)
@@ -529,6 +531,15 @@
return res
self.check(f, [int], getfield=3)
+ def test_malloc_varsize_getarraysize(self):
+ def f(i):
+ if i == 1:
+ l = [1]
+ else:
+ l = [2, 3]
+ return len(l)
+ self.check(f, [int], fullopts=True, getarraysize=0)
+
def fakevar(name='v'):
var = Variable(name)
More information about the pypy-commit
mailing list