Author: Maciej Fijalkowski <[email protected]>
Branch: improve-consecutive-dict-lookups
Changeset: r70097:3bf5dd780599
Date: 2014-03-19 20:28 +0200
http://bitbucket.org/pypy/pypy/changeset/3bf5dd780599/

Log:    implement interiorfieldsupport for writeanalyzer

diff --git a/rpython/translator/backendopt/test/test_writeanalyze.py 
b/rpython/translator/backendopt/test/test_writeanalyze.py
--- a/rpython/translator/backendopt/test/test_writeanalyze.py
+++ b/rpython/translator/backendopt/test/test_writeanalyze.py
@@ -353,3 +353,23 @@
 
         result = wa.analyze(fgraph.startblock.operations[-1])
         assert list(result) == [("struct", lltype.Ptr(S), "x")]
+
+    def test_interiorfield(self):
+        A = lltype.GcArray(lltype.Struct('x', ('x', lltype.Signed),
+                                         ('y', lltype.Signed)))
+
+        def g(x):
+            a = lltype.malloc(A, 1)
+            a[0].y = 3
+            return f(a, x)
+        
+        def f(a, x):
+            a[0].x = x
+            return a[0].y
+
+        t, wa = self.translate(g, [int])
+        ggraph = graphof(t, g)
+        result = wa.analyze(ggraph.startblock.operations[-1])
+        res = list(result)
+        assert ('readinteriorfield', lltype.Ptr(A), 'y') in res
+        assert ('interiorfield', lltype.Ptr(A), 'x') in res
diff --git a/rpython/translator/backendopt/writeanalyze.py 
b/rpython/translator/backendopt/writeanalyze.py
--- a/rpython/translator/backendopt/writeanalyze.py
+++ b/rpython/translator/backendopt/writeanalyze.py
@@ -45,11 +45,18 @@
         elif op.opname == "setarrayitem":
             if graphinfo is None or not graphinfo.is_fresh_malloc(op.args[0]):
                 return self._array_result(op.args[0].concretetype)
+        elif op.opname == "setinteriorfield":
+            if graphinfo is None or not graphinfo.is_fresh_malloc(op.args[0]):
+                return self._interiorfield_result(op.args[0].concretetype,
+                                                  op.args[2].value)
         return empty_set
 
     def _array_result(self, TYPE):
         return frozenset([("array", TYPE)])
 
+    def _interiorfield_result(self, TYPE, fieldname):
+        return frozenset([("interiorfield", TYPE, fieldname)])
+
     def compute_graph_info(self, graph):
         return FreshMallocs(graph)
 
@@ -99,4 +106,8 @@
         elif op.opname == "getarrayitem":
             return frozenset([
                 ("readarray", op.args[0].concretetype)])
+        elif op.opname == "getinteriorfield":
+            return frozenset([
+                ("readinteriorfield", op.args[0].concretetype,
+                 op.args[2].value)])
         return WriteAnalyzer.analyze_simple_operation(self, op, graphinfo)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to