Commits

Remi Meier committed da15e05

partly moved transaction break logic from pyjitpl to optimizeopt

Comments (0)

Files changed (4)

rpython/jit/metainterp/optimizeopt/stm.py

     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:

rpython/jit/metainterp/optimizeopt/test/test_stm.py

     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 = """
         guard_not_forced() []
 
         i0 = call(123, descr=sbtdescr)
-        stm_transaction_break()
-        guard_not_forced() []
         guard_false(i0) []
 
         jump()
         """
         expected = """
         []
-        stm_transaction_break()
-        guard_not_forced() []
-
         i0 = call(123, descr=sbtdescr)
         guard_false(i0) []
         jump()
     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 = """
         """
         self.optimize_loop(ops, expected, expected_preamble=preamble)
 
-
+    # def test_dont_remove_first_tb(self):
+    #     ops = """
+    #     []
+    #     stm_transaction_break()
+    #     guard_not_forced() []
+        
 
 
 

rpython/jit/metainterp/pyjitpl.py

     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
                 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()
             # 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
 
         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):

rpython/jit/metainterp/test/test_stm.py

     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
             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():
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.