[pypy-commit] pypy stm: Adjust PyFrame and the stm transformer.

arigo noreply at buildbot.pypy.org
Tue Jan 24 16:49:16 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r51719:3ae2aedede04
Date: 2012-01-24 16:33 +0100
http://bitbucket.org/pypy/pypy/changeset/3ae2aedede04/

Log:	Adjust PyFrame and the stm transformer.

diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -40,6 +40,7 @@
     __metaclass__ = extendabletype
 
     _stm_access_directly_ = True
+    _immutable_fields_ = ['locals_stack_w->...', 'cells->...']
 
     frame_finished_execution = False
     last_instr               = -1
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
@@ -159,7 +159,10 @@
         pass
     class P2:
         _stm_access_directly_ = True
-    for P in [P1, P2]:
+    class P3:
+        _stm_access_directly_ = True
+        _immutable_fields_ = ['lst->...']
+    for P in [P1, P2, P2]:
         def func(n):
             p = P()
             p.lst = [0]
@@ -174,18 +177,10 @@
             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) --- xxx
-        else:
-            assert 0
+        assert ('stm_getfield' in summary(graph)) == (P is P1)
+        assert ('stm_setfield' in summary(graph)) == (P is P1)
+        assert ('stm_getarrayitem' in summary(graph)) == (P is not P3)
+        #assert ('stm_setarrayitem' in summary(graph)) == (P is not P3) -- xxx
         res = eval_stm_graph(interp, graph, [42],
                              stm_mode="regular_transaction")
         assert res == 42
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
@@ -4,6 +4,7 @@
 from pypy.translator.stm import _rffi_stm
 from pypy.translator.unsimplify import varoftype, copyvar
 from pypy.rpython.lltypesystem import lltype, lloperation
+from pypy.rpython import rclass
 
 
 ALWAYS_ALLOW_OPERATIONS = set([
@@ -43,7 +44,7 @@
             return
         newoperations = []
         self.current_block = block
-        self.array_of_stm_access_directly = set()
+        self.access_directly = set()
         for i, op in enumerate(block.operations):
             self.current_op_index = i
             try:
@@ -65,7 +66,7 @@
                 assert res is None
         block.operations = newoperations
         self.current_block = None
-        self.array_of_stm_access_directly = None
+        self.access_directly = None
 
     def transform_graph(self, graph):
         for block in graph.iterblocks():
@@ -117,7 +118,14 @@
         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)
+            try:
+                immfld = STRUCT._hints['immutable_fields']
+            except KeyError:
+                pass
+            else:
+                rank = immfld._fields.get(op.args[1].value, None)
+                if rank is rclass.IR_MUTABLE_OWNED:
+                    self.access_directly.add(op.result)
             op1 = op
         elif STRUCT._gckind == 'raw':
             turn_inevitable(newoperations, "getfield-raw")
@@ -146,7 +154,7 @@
             op1 = op
         elif ARRAY._immutable_field():
             op1 = op
-        elif op.args[0] in self.array_of_stm_access_directly:
+        elif op.args[0] in self.access_directly:
             op1 = op
         elif ARRAY._gckind == 'raw':
             turn_inevitable(newoperations, "getarrayitem-raw")
@@ -161,7 +169,7 @@
             op1 = op
         elif ARRAY._immutable_field():
             op1 = op
-        elif op.args[0] in self.array_of_stm_access_directly:
+        elif op.args[0] in self.access_directly:
             op1 = op
         elif ARRAY._gckind == 'raw':
             turn_inevitable(newoperations, "setarrayitem-raw")
@@ -228,8 +236,8 @@
         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)
+        if op.args[0] in self.access_directly:
+            self.access_directly.add(op.result)
         newoperations.append(op)
 
     stt_cast_pointer = stt_same_as


More information about the pypy-commit mailing list