[pypy-commit] pypy stm: Directly access also any array present as a field on the
arigo
noreply at buildbot.pypy.org
Tue Jan 24 16:49:12 CET 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r51716:00a838f5088a
Date: 2012-01-24 15:50 +0100
http://bitbucket.org/pypy/pypy/changeset/00a838f5088a/
Log: Directly access also any array present as a field on the
stm_access_directly object.
diff --git a/pypy/translator/stm/test/test_transform.py b/pypy/translator/stm/test/test_transform.py
--- a/pypy/translator/stm/test/test_transform.py
+++ b/pypy/translator/stm/test/test_transform.py
@@ -141,7 +141,7 @@
assert summary(graph) == {'setinteriorfield': 1}
res = eval_stm_graph(interp, graph, [p], stm_mode="regular_transaction")
-def test_getfield_access_directly():
+def test_getfield_setfield_access_directly():
class P:
x = 42
_stm_access_directly_ = True
@@ -154,6 +154,42 @@
'getfield': 1, 'setfield': 3, 'int_add': 1}
res = eval_stm_graph(interp, graph, [], stm_mode="regular_transaction")
+def test_arrayitem_access_directly():
+ class P1:
+ pass
+ class P2:
+ _stm_access_directly_ = True
+ for P in [P1, P2]:
+ def func(n):
+ p = P()
+ p.lst = [0]
+ p.lst[0] = n
+ return p.lst[0]
+ interp, graph = get_interpreter(func, [42])
+ #
+ from pypy.translator.backendopt.inline import auto_inline_graphs
+ translator = interp.typer.annotator.translator
+ auto_inline_graphs(translator, translator.graphs, 16.0)
+ if option.view:
+ graph.show()
+ #
+ transform_graph(graph)
+ if P is P1:
+ assert 'stm_getfield' in summary(graph)
+ assert 'stm_setfield' in summary(graph)
+ assert 'stm_getarrayitem' in summary(graph)
+ assert 'stm_setarrayitem' in summary(graph)
+ elif P is P2:
+ assert 'stm_getfield' not in summary(graph)
+ assert 'stm_setfield' not in summary(graph)
+ assert 'stm_getarrayitem' not in summary(graph)
+ assert 'stm_setarrayitem' not in summary(graph)
+ else:
+ assert 0
+ res = eval_stm_graph(interp, graph, [42],
+ stm_mode="regular_transaction")
+ assert res == 42
+
def test_unsupported_operation():
def func(n):
n += 1
diff --git a/pypy/translator/stm/transform.py b/pypy/translator/stm/transform.py
--- a/pypy/translator/stm/transform.py
+++ b/pypy/translator/stm/transform.py
@@ -43,6 +43,7 @@
return
newoperations = []
self.current_block = block
+ self.array_of_stm_access_directly = set()
for i, op in enumerate(block.operations):
self.current_op_index = i
try:
@@ -64,6 +65,7 @@
assert res is None
block.operations = newoperations
self.current_block = None
+ self.array_of_stm_access_directly = None
def transform_graph(self, graph):
for block in graph.iterblocks():
@@ -112,8 +114,10 @@
STRUCT = op.args[0].concretetype.TO
if op.result.concretetype is lltype.Void:
op1 = op
- elif (STRUCT._immutable_field(op.args[1].value) or
- 'stm_access_directly' in STRUCT._hints):
+ elif STRUCT._immutable_field(op.args[1].value):
+ op1 = op
+ elif 'stm_access_directly' in STRUCT._hints:
+ self.array_of_stm_access_directly.add(op.result)
op1 = op
elif STRUCT._gckind == 'raw':
turn_inevitable(newoperations, "getfield-raw")
@@ -142,6 +146,8 @@
op1 = op
elif ARRAY._immutable_field():
op1 = op
+ elif op.args[0] in self.array_of_stm_access_directly:
+ op1 = op
elif ARRAY._gckind == 'raw':
turn_inevitable(newoperations, "getarrayitem-raw")
op1 = op
@@ -155,6 +161,8 @@
op1 = op
elif ARRAY._immutable_field():
op1 = op
+ elif op.args[0] in self.array_of_stm_access_directly:
+ op1 = op
elif ARRAY._gckind == 'raw':
turn_inevitable(newoperations, "setarrayitem-raw")
op1 = op
@@ -219,6 +227,13 @@
## self.seen_gc_stack_bottom = True
newoperations.append(op)
+ def stt_same_as(self, newoperations, op):
+ if op.args[0] in self.array_of_stm_access_directly:
+ self.array_of_stm_access_directly.add(op.result)
+ newoperations.append(op)
+
+ stt_cast_pointer = stt_same_as
+
def transform_graph(graph):
# for tests: only transforms one graph
More information about the pypy-commit
mailing list