[pypy-commit] pypy stm-gc: Replace hacking around an llop with just a function fishing around

arigo noreply at buildbot.pypy.org
Mon Apr 30 12:49:25 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm-gc
Changeset: r54824:cacf5488f1a5
Date: 2012-04-30 12:49 +0200
http://bitbucket.org/pypy/pypy/changeset/cacf5488f1a5/

Log:	Replace hacking around an llop with just a function fishing around
	in the config.

diff --git a/pypy/rlib/rgc.py b/pypy/rlib/rgc.py
--- a/pypy/rlib/rgc.py
+++ b/pypy/rlib/rgc.py
@@ -18,6 +18,12 @@
     """
     pass
 
+def stm_is_enabled():
+    """Check if we are translating with STM enabled or no.  This function
+    is here rather than in rstm.py to avoid that you have to import rstm.py.
+    """
+    return None   # means 'not translated at all'
+
 # ____________________________________________________________
 # Annotation and specialization
 
@@ -50,6 +56,18 @@
         return hop.genop('gc_set_max_heap_size', [v_nbytes],
                          resulttype=lltype.Void)
 
+class StmIsEnabled(ExtRegistryEntry):
+    _about_ = stm_is_enabled
+
+    def compute_result_annotation(self):
+        config = self.bookkeeper.annotator.translator.config
+        result = config.translation.stm
+        return self.bookkeeper.immutablevalue(result)
+
+    def specialize_call(self, hop):
+        hop.exception_cannot_occur()
+        return hop.inputconst(lltype.Bool, hop.s_result.const)
+
 def can_move(p):
     """Check if the GC object 'p' is at an address that can move.
     Must not be called with None.  With non-moving GCs, it is always False.
@@ -159,7 +177,7 @@
     if isinstance(TP.OF, lltype.Ptr) and TP.OF.TO._gckind == 'gc':
         # perform a write barrier that copies necessary flags from
         # source to dest
-        if llop.stm_is_enabled(lltype.Bool) or (
+        if stm_is_enabled() or (
            not llop.gc_writebarrier_before_copy(lltype.Bool, source, dest,
                                                 source_start, dest_start,
                                                 length)):
@@ -200,7 +218,7 @@
     field = getattr(p, TP._names[0])
     setattr(newp, TP._names[0], field)
 
-    if llop.stm_is_enabled(lltype.Bool):
+    if stm_is_enabled():
         # do the copying element by element
         i = 0
         while i < smallerlength:
diff --git a/pypy/rlib/rstm.py b/pypy/rlib/rstm.py
--- a/pypy/rlib/rstm.py
+++ b/pypy/rlib/rstm.py
@@ -8,6 +8,7 @@
 from pypy.rlib.nonconst import NonConstant
 from pypy.translator.stm.stmgcintf import StmOperations
 
+from pypy.rlib.rgc import stm_is_enabled     # re-exported here
 
 
 NUM_THREADS_DEFAULT = 4     # XXX for now
diff --git a/pypy/rlib/test/test_rstm.py b/pypy/rlib/test/test_rstm.py
--- a/pypy/rlib/test/test_rstm.py
+++ b/pypy/rlib/test/test_rstm.py
@@ -135,3 +135,6 @@
     assert tl.getvalue() is p2
     tl.setvalue(None)
     assert tl.getvalue() is None
+
+def test_stm_is_enabled():
+    assert rstm.stm_is_enabled() is None    # not translated
diff --git a/pypy/rpython/lltypesystem/lloperation.py b/pypy/rpython/lltypesystem/lloperation.py
--- a/pypy/rpython/lltypesystem/lloperation.py
+++ b/pypy/rpython/lltypesystem/lloperation.py
@@ -399,7 +399,6 @@
     # direct_calls and maybe several casts, but it looks less heavy-weight
     # to keep them as operations until the genc stage)
 
-    'stm_is_enabled':         LLOp(canrun=True),  # sideeffects: test_lltyped.py
     'stm_getfield':           LLOp(sideeffects=False, canrun=True),
     'stm_getarrayitem':       LLOp(sideeffects=False, canrun=True),
     'stm_getinteriorfield':   LLOp(sideeffects=False, canrun=True),
diff --git a/pypy/rpython/lltypesystem/opimpl.py b/pypy/rpython/lltypesystem/opimpl.py
--- a/pypy/rpython/lltypesystem/opimpl.py
+++ b/pypy/rpython/lltypesystem/opimpl.py
@@ -623,9 +623,6 @@
     from pypy.rlib.rtimer import read_timestamp
     return read_timestamp()
 
-def op_stm_is_enabled():
-    return False
-
 def op_stm_start_transaction():
     pass
 
diff --git a/pypy/rpython/lltypesystem/rffi.py b/pypy/rpython/lltypesystem/rffi.py
--- a/pypy/rpython/lltypesystem/rffi.py
+++ b/pypy/rpython/lltypesystem/rffi.py
@@ -716,8 +716,7 @@
         string is already nonmovable.  Must be followed by a
         free_nonmovingbuffer call.
         """
-        from pypy.rpython.lltypesystem.lloperation import llop
-        if llop.stm_is_enabled(lltype.Bool) or rgc.can_move(data):
+        if rgc.stm_is_enabled() or rgc.can_move(data):
             count = len(data)
             buf = lltype.malloc(TYPEP.TO, count, flavor='raw')
             for i in range(count):
@@ -741,8 +740,7 @@
         # if 'buf' points inside 'data'.  This is only possible if we
         # followed the 2nd case in get_nonmovingbuffer(); in the first case,
         # 'buf' points to its own raw-malloced memory.
-        from pypy.rpython.lltypesystem.lloperation import llop
-        if llop.stm_is_enabled(lltype.Bool):
+        if rgc.stm_is_enabled():
             followed_2nd_path = False
         else:
             data = llstrtype(data)
diff --git a/pypy/rpython/lltypesystem/rstr.py b/pypy/rpython/lltypesystem/rstr.py
--- a/pypy/rpython/lltypesystem/rstr.py
+++ b/pypy/rpython/lltypesystem/rstr.py
@@ -5,7 +5,7 @@
 from pypy.rlib.objectmodel import _hash_string, enforceargs
 from pypy.rlib.objectmodel import keepalive_until_here
 from pypy.rlib.debug import ll_assert
-from pypy.rlib import jit
+from pypy.rlib import jit, rgc
 from pypy.rlib.rarithmetic import ovfcheck
 from pypy.rpython.robject import PyObjRepr, pyobj_repr
 from pypy.rpython.rmodel import inputconst, IntegerRepr
@@ -20,7 +20,6 @@
 from pypy.rpython.rmodel import Repr
 from pypy.rpython.lltypesystem import llmemory
 from pypy.tool.sourcetools import func_with_new_name
-from pypy.rpython.lltypesystem.lloperation import llop
 
 # ____________________________________________________________
 #
@@ -77,7 +76,7 @@
         # STM requires the slow character-by-character version,
         # which at least works without forcing the transaction
         # to become inevitable
-        if llop.stm_is_enabled(Bool):
+        if rgc.stm_is_enabled():
             i = 0
             while i < length:
                 dst.chars[dststart + i] = src.chars[srcstart + i]
diff --git a/pypy/translator/c/src/mem.h b/pypy/translator/c/src/mem.h
--- a/pypy/translator/c/src/mem.h
+++ b/pypy/translator/c/src/mem.h
@@ -259,5 +259,3 @@
 #define OP_GC_GET_RPY_TYPE_INDEX(x, r)   r = -1
 #define OP_GC_IS_RPY_INSTANCE(x, r)      r = 0
 #define OP_GC_DUMP_RPY_HEAP(fd, r)       r = 0
-
-#define OP_STM_IS_ENABLED(r)             r = 0
diff --git a/pypy/translator/c/test/test_lltyped.py b/pypy/translator/c/test/test_lltyped.py
--- a/pypy/translator/c/test/test_lltyped.py
+++ b/pypy/translator/c/test/test_lltyped.py
@@ -903,16 +903,3 @@
             return rstring_to_float(s)
         fn = self.getcompiled(llf, [int])
         assert fn(0) == 42.3
-
-    def test_stm_is_enabled(self):
-        from pypy.rpython.lltypesystem import lltype
-        from pypy.rpython.lltypesystem.lloperation import llop
-        # note that right now the situation of lloperation is a bit messy.
-        # stm_is_enabled is not "sideeffects=False" because otherwise
-        # it is constant-folded away by backendopt/constfold.py.
-        assert llop.stm_is_enabled.sideeffects == True
-        #
-        def llf(i):
-            return int(llop.stm_is_enabled(lltype.Bool))
-        fn = self.getcompiled(llf, [int])
-        assert fn(0) == 0
diff --git a/pypy/translator/stm/test/targetdemo.py b/pypy/translator/stm/test/targetdemo.py
--- a/pypy/translator/stm/test/targetdemo.py
+++ b/pypy/translator/stm/test/targetdemo.py
@@ -96,7 +96,7 @@
 
 def entry_point(argv):
     print "hello world"
-    assert llop.stm_is_enabled(lltype.Bool)
+    assert rstm.stm_is_enabled()
     if len(argv) > 1:
         glob.NUM_THREADS = int(argv[1])
         if len(argv) > 2:
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
@@ -162,11 +162,6 @@
             self.count_write_barrier += 1
         newoperations.append(op)
 
-    def stt_stm_is_enabled(self, newoperations, op):
-        c_True = Constant(True, lltype.Bool)
-        op = SpaceOperation('same_as', [c_True], op.result)
-        newoperations.append(op)
-
     def stt_malloc(self, newoperations, op):
         flags = op.args[1].value
         if flags['flavor'] == 'gc':


More information about the pypy-commit mailing list