1. Pypy
  2. Untitled project
  3. pypy

Commits

Remi Meier  committed f7e20f9

test and fix transaction break removal

  • Participants
  • Parent commits 195b15f
  • Branches stmgc-c4

Comments (0)

Files changed (8)

File rpython/jit/codewriter/effectinfo.py

View file
     OS_JIT_FORCE_VIRTUAL        = 120
     OS_JIT_FORCE_VIRTUALIZABLE  = 121
 
+    OS_JIT_STM_SHOULD_BREAK_TRANSACTION = 130
+
     # for debugging:
     _OS_CANRAISE = set([
         OS_NONE, OS_STR2UNICODE, OS_LIBFFI_CALL, OS_RAW_MALLOC_VARSIZE_CHAR,

File rpython/jit/metainterp/compile.py

View file
     name = metainterp.staticdata.stats.name_for_new_loop()
     loop = TreeLoop(name_prefix + name)
     loop.call_pure_results = metainterp.call_pure_results
+    loop.stm_info = {}
     return loop
 
 

File rpython/jit/metainterp/history.py

View file
     inputargs = None
     operations = None
     call_pure_results = None
+    stm_info = None
     logops = None
     quasi_immutable_deps = None
     resume_at_jump_descr = None

File rpython/jit/metainterp/optimizeopt/optimizer.py

View file
         self.optearlyforce = None
         if loop is not None:
             self.call_pure_results = loop.call_pure_results
+            self.stm_info = loop.stm_info
 
         self.set_optimizations(optimizations)
         self.setup()

File rpython/jit/metainterp/optimizeopt/stm.py

View file
 from rpython.jit.metainterp.optimizeopt.util import make_dispatcher_method
 from rpython.jit.metainterp.resoperation import (opboolinvers, opboolreflex, rop,
     ResOperation)
-
+from rpython.jit.codewriter.effectinfo import EffectInfo
 
 class OptSTM(Optimization):
     """
     to unconditional ones.
     """
     def __init__(self):
-        pass
-    
-    def new(self):
-        return OptSTM()
+        self.remove_next_break = False
+        self.remove_next_gnf = False
 
     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 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.emit_operation(op)
 
+
     def optimize_STM_TRANSACTION_BREAK(self, op):
-        self.emit_operation(op)
+        self.optimizer.stm_info['seen_unconditional_break'] = True
+        
+        if self.remove_next_break:
+            self.remove_next_break = False
+            self.remove_next_gnf = True
+        else:
+            self.emit_operation(op)
+
+    def optimize_GUARD_NOT_FORCED(self, op):
+        if self.remove_next_gnf:
+            self.remove_next_gnf = False
+        else:
+            self.emit_operation(op)
+        
+        
 
 dispatch_opt = make_dispatcher_method(OptSTM, 'optimize_',
                                       default=OptSTM.emit_operation)

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

View file
-from rpython.jit.metainterp.optimizeopt.test.test_optimizebasic import (
-    BaseTestBasic,)
+from rpython.jit.metainterp.optimizeopt.test.test_optimizeopt import (
+    BaseTestWithUnroll,)
 from rpython.jit.metainterp.optimizeopt.test.test_util import LLtypeMixin
+from rpython.jit.codewriter.effectinfo import EffectInfo
+from rpython.rtyper.lltypesystem import lltype, rclass, rffi, llmemory
 
 
+class TestSTM(BaseTestWithUnroll, LLtypeMixin):
+    stm = True
 
-
-class BaseTestSTM(BaseTestBasic):
-    stm = True
+    FUNC = lltype.FuncType([], lltype.Signed)
+    sbtdescr = LLtypeMixin.cpu.calldescrof(
+        FUNC, FUNC.ARGS, FUNC.RESULT,
+        EffectInfo([], [], [], [],
+                   EffectInfo.EF_CANNOT_RAISE,
+                   oopspecindex=EffectInfo.OS_JIT_STM_SHOULD_BREAK_TRANSACTION,
+                   can_invalidate=False)
+    )
+    namespace = LLtypeMixin.namespace.copy()
+    namespace.update(locals())
+        
     
     def test_simple(self):
         ops = """
         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)
 
+    def test_unrolled_loop2(self):
+        ops = """
+        []
+        stm_transaction_break()
+        guard_not_forced() []
 
-class TestLLtype(BaseTestSTM, LLtypeMixin):
-    pass
+        i0 = call(123, descr=sbtdescr)
+        stm_transaction_break()
+        guard_not_forced() []
+        guard_false(i0) []
 
+        jump()
+        """
+        preamble = """
+        []
+        stm_transaction_break()
+        guard_not_forced() []
 
+        i0 = call(123, descr=sbtdescr)
+        guard_false(i0) []
+        
+        jump()
+        """
+        expected = """
+        []
+        stm_transaction_break()
+        guard_not_forced() []
+
+        i0 = call(123, descr=sbtdescr)
+        guard_false(i0) []
+        jump()
+        """
+        self.optimize_loop(ops, expected, expected_preamble=preamble)
+
+    def test_not_disable_opt(self):
+        ops = """
+        [p1]
+        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)
+
+        jump(p1)
+        """
+        expected = """
+        [p1]
+        i0 = call(123, descr=sbtdescr)
+        guard_false(i0) []
+        
+        jump(p1)
+        """
+        self.optimize_loop(ops, expected, expected_preamble=preamble)
+
+
+
+
+
+
+
+
+
+        

File rpython/jit/metainterp/optimizeopt/test/test_util.py

View file
         assert equaloplists(optimized.operations,
                             expected.operations, False, remap, text_right)
 
-    def _do_optimize_loop(self, loop, call_pure_results):
+    def _do_optimize_loop(self, loop, call_pure_results,
+                          stm_info):
         from rpython.jit.metainterp.optimizeopt import optimize_trace
         from rpython.jit.metainterp.optimizeopt.util import args_dict
 
         self.loop = loop
         loop.call_pure_results = args_dict()
+        loop.stm_info = stm_info
         if call_pure_results is not None:
             for k, v in call_pure_results.items():
                 loop.call_pure_results[list(k)] = v
         preamble.operations = [ResOperation(rop.LABEL, inputargs, None, descr=TargetToken(token))] + \
                               operations +  \
                               [ResOperation(rop.LABEL, jump_args, None, descr=token)]
-        self._do_optimize_loop(preamble, call_pure_results)
+        stm_info = {}
+        self._do_optimize_loop(preamble, call_pure_results, stm_info)
 
         assert preamble.operations[-1].getopnum() == rop.LABEL
 
         assert loop.operations[0].getopnum() == rop.LABEL
         loop.inputargs = loop.operations[0].getarglist()
 
-        self._do_optimize_loop(loop, call_pure_results)
+        self._do_optimize_loop(loop, call_pure_results, stm_info)
         extra_same_as = []
         while loop.operations[0].getopnum() != rop.LABEL:
             extra_same_as.append(loop.operations[0])

File rpython/jit/metainterp/pyjitpl.py

View file
 
             ei = EffectInfo([], [], [], [],
                             EffectInfo.EF_CANNOT_RAISE,
+                            oopspecindex=EffectInfo.OS_JIT_STM_SHOULD_BREAK_TRANSACTION,
                             can_invalidate=False)
             
             self.stm_should_break_transaction_descr = (