[pypy-commit] pypy stm-gc: Use GcSource to implement the StmLocalTracker.

arigo noreply at buildbot.pypy.org
Thu Feb 16 12:24:40 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm-gc
Changeset: r52546:5dcd567383ed
Date: 2012-02-16 12:23 +0100
http://bitbucket.org/pypy/pypy/changeset/5dcd567383ed/

Log:	Use GcSource to implement the StmLocalTracker.

diff --git a/pypy/translator/stm/localtracker.py b/pypy/translator/stm/localtracker.py
--- a/pypy/translator/stm/localtracker.py
+++ b/pypy/translator/stm/localtracker.py
@@ -1,3 +1,5 @@
+from pypy.translator.stm.gcsource import GcSource
+from pypy.objspace.flow.model import Variable, Constant, SpaceOperation
 
 
 RETURNS_LOCAL_POINTER = set([
@@ -14,16 +16,19 @@
 
     def __init__(self, translator):
         self.translator = translator
-        # a set of variables in the graphs that contain a known-to-be-local
-        # pointer.
-        self.locals = set()
+        self.gsrc = GcSource(translator)
 
-    def track_and_propagate_locals(self):
-        for graph in self.translator.graphs:
-            self.propagate_from_graph(graph)
-
-    def propagate_from_graph(self, graph):
-        for block in graph.iterblocks():
-            for op in block.operations:
-                if op.opname in RETURNS_LOCAL_POINTER:
-                    self.locals.add(op.result)
+    def is_local(self, variable):
+        assert isinstance(variable, Variable)
+        for src in self.gsrc[variable]:
+            if isinstance(src, SpaceOperation):
+                if src.opname not in RETURNS_LOCAL_POINTER:
+                    return False
+            elif isinstance(src, Constant):
+                if src.value:     # a NULL pointer is still valid as local
+                    return False
+            elif src is None:
+                return False
+            else:
+                raise AssertionError(src)
+        return True
diff --git a/pypy/translator/stm/test/test_localtracker.py b/pypy/translator/stm/test/test_localtracker.py
--- a/pypy/translator/stm/test/test_localtracker.py
+++ b/pypy/translator/stm/test/test_localtracker.py
@@ -2,6 +2,7 @@
 from pypy.translator.translator import TranslationContext, graphof
 from pypy.conftest import option
 from pypy.rlib.jit import hint
+from pypy.rlib.nonconst import NonConstant
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.extregistry import ExtRegistryEntry
 from pypy.annotation import model as annmodel
@@ -19,13 +20,12 @@
             t.view()
         localtracker = StmLocalTracker(t)
         self.localtracker = localtracker
-        localtracker.track_and_propagate_locals()
         return localtracker
 
     def check(self, expected_names):
         got_local_names = set()
         for name, v in self.translator._seen_locals.items():
-            if v in self.localtracker.locals:
+            if self.localtracker.is_local(v):
                 got_local_names.add(name)
         assert got_local_names == set(expected_names)
 
@@ -41,7 +41,7 @@
         self.check([])
 
     def test_freshly_allocated(self):
-        z = lltype.malloc(S)
+        z = [lltype.malloc(S), lltype.malloc(S)]
         def f(n):
             x = lltype.malloc(S)
             x.n = n
@@ -49,8 +49,8 @@
             y.n = n+1
             _see(x, 'x')
             _see(y, 'y')
-            _see(z, 'z')
-            return x.n, y.n, z.n
+            _see(z[n % 2], 'z')
+            return x.n, y.n
         #
         self.translate(f, [int])
         self.check(['x', 'y'])      # x and y are locals; z is prebuilt
@@ -104,6 +104,18 @@
         self.translate(f, [int])
         self.check(['x'])      # x is local
 
+    def test_none_variable_is_local(self):
+        def f(n):
+            if n > 5:
+                x = lltype.nullptr(S)
+            else:
+                x = lltype.malloc(S)
+                x.n = n
+            _see(x, 'x')
+        #
+        localtracker = self.translate(f, [int])
+        self.check(['x'])
+
     def test_freshly_allocated_to_g(self):
         def g(x):
             _see(x, 'x')


More information about the pypy-commit mailing list