[pypy-svn] r25935 - in pypy/dist/pypy/translator/backendopt: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Apr 18 11:58:39 CEST 2006
Author: arigo
Date: Tue Apr 18 11:58:38 2006
New Revision: 25935
Modified:
pypy/dist/pypy/translator/backendopt/malloc.py
pypy/dist/pypy/translator/backendopt/test/test_malloc.py
Log:
Minimal support for FixedSizeArray in malloc removal.
Modified: pypy/dist/pypy/translator/backendopt/malloc.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/malloc.py (original)
+++ pypy/dist/pypy/translator/backendopt/malloc.py Tue Apr 18 11:58:38 2006
@@ -142,12 +142,18 @@
("setfield", 0),
("getsubstruct", 0),
("keepalive", 0)])
+ MAYBE_VALID = dict.fromkeys([("getarrayitem", 0),
+ ("setarrayitem", 0),
+ ("getarraysubstruct", 0)])
for up in info.usepoints:
if up[0] != "op":
return False
kind, node, op, index = up
if (op.opname, index) in VALID:
continue # ok
+ if (op.opname, index) in MAYBE_VALID:
+ if isinstance(op.args[1], Constant):
+ continue # ok if the index is constant
return False
# must not remove mallocs of structures that have a RTTI with a destructor
@@ -224,17 +230,21 @@
for arg in op.args[1:]: # should be the first arg only
assert arg not in vars
if op.args and op.args[0] in vars:
- if op.opname == "getfield":
+ if op.opname in ("getfield", "getarrayitem"):
S = op.args[0].concretetype.TO
fldname = op.args[1].value
+ if op.opname == "getarrayitem":
+ fldname = 'item%d' % fldname
newop = SpaceOperation("same_as",
[newvarsmap[S, fldname]],
op.result)
newops.append(newop)
last_removed_access = len(newops)
- elif op.opname == "setfield":
+ elif op.opname in ("setfield", "setarrayitem"):
S = op.args[0].concretetype.TO
fldname = op.args[1].value
+ if op.opname == "setarrayitem":
+ fldname = 'item%d' % fldname
assert (S, fldname) in newvarsmap
newvarsmap[S, fldname] = op.args[2]
last_removed_access = len(newops)
@@ -247,9 +257,11 @@
# via one pointer must be reflected in the other.
elif op.opname == 'keepalive':
last_removed_access = len(newops)
- elif op.opname == "getsubstruct":
+ elif op.opname in ("getsubstruct", "getarraysubstruct"):
S = op.args[0].concretetype.TO
fldname = op.args[1].value
+ if op.opname == "getarraysubstruct":
+ fldname = 'item%d' % fldname
equiv = equivalent_substruct(S, fldname)
if equiv:
# exactly like a cast_pointer
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 Tue Apr 18 11:58:38 2006
@@ -182,3 +182,17 @@
return b.z - b.s.x
check(fn, [int, int], [100, 58], 42)
+
+def test_fixedsizearray():
+ from pypy.rpython.lltypesystem import lltype
+ A = lltype.FixedSizeArray(lltype.Signed, 3)
+ S = lltype.GcStruct('S', ('a', A))
+
+ def fn(n1, n2):
+ s = lltype.malloc(S)
+ a = s.a
+ a[0] = n1
+ a[2] = n2
+ return a[0]-a[2]
+
+ check(fn, [int, int], [100, 42], 58)
More information about the Pypy-commit
mailing list