[pypy-commit] pypy stmgc-c4: partly moved transaction break logic from pyjitpl to optimizeopt

Raemi noreply at buildbot.pypy.org
Mon Jan 13 16:39:53 CET 2014


Author: Remi Meier <remi.meier at gmail.com>
Branch: stmgc-c4
Changeset: r68647:da15e05409ad
Date: 2014-01-13 14:56 +0100
http://bitbucket.org/pypy/pypy/changeset/da15e05409ad/

Log:	partly moved transaction break logic from pyjitpl to optimizeopt

diff --git a/rpython/jit/metainterp/optimizeopt/stm.py b/rpython/jit/metainterp/optimizeopt/stm.py
--- a/rpython/jit/metainterp/optimizeopt/stm.py
+++ b/rpython/jit/metainterp/optimizeopt/stm.py
@@ -13,35 +13,33 @@
     to unconditional ones.
     """
     def __init__(self):
-        self.remove_next_break = False
-        self.remove_next_gnf = False
+        self.remove_next_gnf = False # guard_not_forced
 
     def propagate_forward(self, op):
         dispatch_opt(self, op)
 
-    def _seen_unconditional_break(self):
-        return self.optimizer.stm_info.get('seen_unconditional_break', False)
+    def _break_wanted(self):
+        return self.optimizer.stm_info.get('break_wanted', True)
+    
+    def _set_break_wanted(self, val):
+        self.optimizer.stm_info['break_wanted'] = val
         
     def optimize_CALL(self, op):
         effectinfo = op.getdescr().get_extra_info()
         oopspecindex = effectinfo.oopspecindex
         if oopspecindex == EffectInfo.OS_JIT_STM_SHOULD_BREAK_TRANSACTION:
-            if not self._seen_unconditional_break():
-                self.make_constant_int(op.result, False)
-                return
-            else:
-                self.remove_next_break = True
+            self._set_break_wanted(False)
         self.emit_operation(op)
 
 
     def optimize_STM_TRANSACTION_BREAK(self, op):
-        self.optimizer.stm_info['seen_unconditional_break'] = True
+        assert not self.remove_next_gnf
         
-        if self.remove_next_break:
-            self.remove_next_break = False
+        if self._break_wanted():
+            self._set_break_wanted(False)
+            self.emit_operation(op)
+        else:
             self.remove_next_gnf = True
-        else:
-            self.emit_operation(op)
 
     def optimize_GUARD_NOT_FORCED(self, op):
         if self.remove_next_gnf:
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_stm.py b/rpython/jit/metainterp/optimizeopt/test/test_stm.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_stm.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_stm.py
@@ -20,38 +20,14 @@
     namespace.update(locals())
         
     
-    def test_simple(self):
-        ops = """
-        []
-        stm_transaction_break()
-        guard_not_forced() []
-        jump()
-        """
-        expected = ops
-        self.optimize_loop(ops, expected)
-
     def test_unrolled_loop(self):
         ops = """
         []
         i0 = call(123, descr=sbtdescr)
-        stm_transaction_break()
-        guard_not_forced() []
-        guard_false(i0) []
-        jump()
-        """
-        preamble = """
-        []
-        stm_transaction_break()
-        guard_not_forced() []
-        jump()
-        """
-        expected = """
-        []
-        i0 = call(123, descr=sbtdescr)
         guard_false(i0) []
         jump()
         """
-        self.optimize_loop(ops, expected, expected_preamble=preamble)
+        self.optimize_loop(ops, ops, expected_preamble=ops)
 
     def test_unrolled_loop2(self):
         ops = """
@@ -60,8 +36,6 @@
         guard_not_forced() []
 
         i0 = call(123, descr=sbtdescr)
-        stm_transaction_break()
-        guard_not_forced() []
         guard_false(i0) []
 
         jump()
@@ -78,9 +52,6 @@
         """
         expected = """
         []
-        stm_transaction_break()
-        guard_not_forced() []
-
         i0 = call(123, descr=sbtdescr)
         guard_false(i0) []
         jump()
@@ -90,22 +61,18 @@
     def test_not_disable_opt(self):
         ops = """
         [p1]
+        i1 = getfield_gc(p1, descr=adescr)
+
         i0 = call(123, descr=sbtdescr)
-        stm_transaction_break()
-        guard_not_forced() []
         guard_false(i0) []
-
-        i1 = getfield_gc(p1, descr=adescr)
-        
         jump(p1)
         """
         preamble = """
         [p1]
-        stm_transaction_break()
-        guard_not_forced() []
-
         i1 = getfield_gc(p1, descr=adescr)
-
+        
+        i0 = call(123, descr=sbtdescr)
+        guard_false(i0) []
         jump(p1)
         """
         expected = """
@@ -117,7 +84,12 @@
         """
         self.optimize_loop(ops, expected, expected_preamble=preamble)
 
-
+    # def test_dont_remove_first_tb(self):
+    #     ops = """
+    #     []
+    #     stm_transaction_break()
+    #     guard_not_forced() []
+        
 
 
 
diff --git a/rpython/jit/metainterp/pyjitpl.py b/rpython/jit/metainterp/pyjitpl.py
--- a/rpython/jit/metainterp/pyjitpl.py
+++ b/rpython/jit/metainterp/pyjitpl.py
@@ -202,31 +202,7 @@
     def opimpl_stm_should_break_transaction(self, if_there_is_no_other):
         val = bool(if_there_is_no_other)
         mi = self.metainterp
-        if mi.stm_break_wanted:
-            # after call_release_gil and similar we want to have
-            # stm_transaction_break that may disable optimizations,
-            # but they would have been disabled anyways by the call
-            self._record_stm_transaction_break()
-            mi.stm_break_wanted = False
-            return ConstInt(0)
-        elif val:
-            # Never ignore these. As long as we don't track the info
-            # if we are atomic, this could be the only possible
-            # transaction break in the loop (they are the most
-            # likely ones):
-            # loop: stmts -> inc_atomic -> stmts -> dec_atomic ->
-            #       transaction_break -> loop_end
-            #
-            # we insert:
-            #   i0 = call(should_break_transaction)
-            #     stm_transaction_break()
-            #     guard_not_forced()
-            #   guard_false(i0)
-            #
-            # the stm_transaction_break() and its guard,
-            #   OR
-            # the call(should_break_transaction) and its guard,
-            # or both are going to be removed by optimizeopt
+        if val:
             resbox = history.BoxInt(0)
             funcptr = mi.staticdata.stm_should_break_transaction
             funcdescr = mi.staticdata.stm_should_break_transaction_descr
@@ -235,15 +211,9 @@
                 rop.CALL, resbox, funcdescr,
                 [ConstInt(heaptracker.adr2int(funcaddr)),])
             #
-            # ALSO generate an stm_transaction_break
-            # This is needed to be able to transform the guard
-            # into an unconditional TB during optimizeopt
-            # if wanted...
-            self._record_stm_transaction_break()
-            #
             return resbox
         else:
-            # we ignore this one.
+            self._record_stm_transaction_break()
             return ConstInt(0)
 
     @arguments()
@@ -1469,7 +1439,6 @@
             # XXX refactor: direct_libffi_call() is a hack
             if effectinfo.oopspecindex == effectinfo.OS_LIBFFI_CALL:
                 self.metainterp.direct_libffi_call()
-            self.metainterp.stm_break_wanted = True
             return resbox
         else:
             effect = effectinfo.extraeffect
@@ -1740,11 +1709,6 @@
 
         self.call_ids = []
         self.current_call_id = 0
-
-        # for stm: placement of stm_break_point, used by MIFrame
-        self.stm_break_wanted = False
-        self.stm_insert_first_break = True
-
         
 
     def retrace_needed(self, trace):
diff --git a/rpython/jit/metainterp/test/test_stm.py b/rpython/jit/metainterp/test/test_stm.py
--- a/rpython/jit/metainterp/test/test_stm.py
+++ b/rpython/jit/metainterp/test/test_stm.py
@@ -12,9 +12,9 @@
     def test_simple(self):
         def g():
             return rstm.jit_stm_should_break_transaction(False)
-        res = self.interp_operations(g, [])
+        res = self.interp_operations(g, [], translationoptions={"stm":True})
         assert res == False
-        self.check_operations_history({})
+        self.check_operations_history(stm_transaction_break=1)
 
     def test_not_removed(self):
         import time
@@ -30,7 +30,7 @@
             return rstm.jit_stm_should_break_transaction(True)
         res = self.interp_operations(g, [], translationoptions={"stm":True})
         assert res == False
-        self.check_operations_history(call=1, stm_transaction_break=1)
+        self.check_operations_history(call=1, stm_transaction_break=0)
 
     def test_transaction_break(self):
         def g():


More information about the pypy-commit mailing list