Author: Armin Rigo <[email protected]>
Branch: stmgc-c7
Changeset: r70811:b8dc286ffdb4
Date: 2014-04-21 17:24 +0200
http://bitbucket.org/pypy/pypy/changeset/b8dc286ffdb4/

Log:    Kill stm_set_location again, and instead add a reference to a
        StmLocation object to every ResOp. Should allow better location
        information in case operations are reordered (like setfields).

diff --git a/rpython/jit/backend/llgraph/runner.py 
b/rpython/jit/backend/llgraph/runner.py
--- a/rpython/jit/backend/llgraph/runner.py
+++ b/rpython/jit/backend/llgraph/runner.py
@@ -1039,9 +1039,6 @@
     def execute_stm_transaction_break(self, _, really_wanted):
         pass
 
-    def execute_stm_set_location(self, _, int, ref):
-        pass
-
     def execute_keepalive(self, descr, x):
         pass
 
diff --git a/rpython/jit/metainterp/compile.py 
b/rpython/jit/metainterp/compile.py
--- a/rpython/jit/metainterp/compile.py
+++ b/rpython/jit/metainterp/compile.py
@@ -515,12 +515,13 @@
     TY_REF          = 0x04
     TY_FLOAT        = 0x06
 
-    def store_final_boxes(self, guard_op, boxes, metainterp_sd, stm_location):
+    def store_final_boxes(self, guard_op, boxes, metainterp_sd):
         guard_op.setfailargs(boxes)
         self.rd_count = len(boxes)
         self.guard_opnum = guard_op.getopnum()
-        if stm_location is not None:    # constant-folded
-            self.stm_location_int, self.stm_location_ref = stm_location
+        if guard_op.stm_location is not None:    # constant-folded if not stm
+            self.stm_location_int = guard_op.stm_location.num
+            self.stm_location_ref = guard_op.stm_location.ref
         #
         if metainterp_sd.warmrunnerdesc is not None:   # for tests
             jitcounter = metainterp_sd.warmrunnerdesc.jitcounter
diff --git a/rpython/jit/metainterp/executor.py 
b/rpython/jit/metainterp/executor.py
--- a/rpython/jit/metainterp/executor.py
+++ b/rpython/jit/metainterp/executor.py
@@ -346,7 +346,6 @@
                          rop.CALL_MALLOC_NURSERY_VARSIZE_FRAME,
                          rop.LABEL,
                          rop.STM_READ,
-                         rop.STM_SET_LOCATION,
                          ):      # list of opcodes never executed by pyjitpl
                 continue
             raise AssertionError("missing %r" % (key,))
diff --git a/rpython/jit/metainterp/history.py 
b/rpython/jit/metainterp/history.py
--- a/rpython/jit/metainterp/history.py
+++ b/rpython/jit/metainterp/history.py
@@ -761,20 +761,27 @@
 # ____________________________________________________________
 
 
+class StmLocation(object):
+    def __init__(self, num, ref):
+        self.num = num
+        self.ref = ref
+
+
 class History(object):
-    def __init__(self):
+    def __init__(self, metainterp_sd):
         self.inputargs = None
         self.operations = []
+        self.config = metainterp_sd.config
+        self.stm_location = None
 
     def record(self, opnum, argboxes, resbox, descr=None):
         op = ResOperation(opnum, argboxes, resbox, descr)
-        self.operations.append(op)
+        self.record_op(op)
         return op
 
-    def substitute_operation(self, position, opnum, argboxes, descr=None):
-        resbox = self.operations[position].result
-        op = ResOperation(opnum, argboxes, resbox, descr)
-        self.operations[position] = op
+    def record_op(self, op):
+        op.stm_location = self.stm_location
+        self.operations.append(op)
 
 # ____________________________________________________________
 
diff --git a/rpython/jit/metainterp/optimizeopt/optimizer.py 
b/rpython/jit/metainterp/optimizeopt/optimizer.py
--- a/rpython/jit/metainterp/optimizeopt/optimizer.py
+++ b/rpython/jit/metainterp/optimizeopt/optimizer.py
@@ -360,12 +360,6 @@
             self.call_pure_results = loop.call_pure_results
             self.stm_info = loop.stm_info
 
-        if metainterp_sd.config.translation.stm:
-            from rpython.rtyper.lltypesystem import lltype, llmemory
-            self.stm_location = (0, lltype.nullptr(llmemory.GCREF.TO))
-        else:
-            self.stm_location = None
-
         self.set_optimizations(optimizations)
         self.setup()
 
@@ -577,8 +571,7 @@
                 raise resume.TagOverflow
         except resume.TagOverflow:
             raise compile.giveup()
-        descr.store_final_boxes(op, newboxes, self.metainterp_sd,
-                                self.stm_location)
+        descr.store_final_boxes(op, newboxes, self.metainterp_sd)
         #
         if op.getopnum() == rop.GUARD_VALUE:
             if self.getvalue(op.getarg(0)) in self.bool_boxes:
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
@@ -84,25 +84,6 @@
             self.keep_but_ignore_gnf = False
             self.emit_operation(op)
 
-    def optimize_DEBUG_MERGE_POINT(self, op):
-        self.emit_operation(op)
-        jdindex = op.getarg(0).getint()
-        jd = self.optimizer.metainterp_sd.warmrunnerdesc.jitdrivers_sd[jdindex]
-        report_location = jd.stm_report_location
-        if report_location is not None:
-            idx_num, idx_ref = report_location
-            num_box = op.getarg(3 + idx_num)
-            ref_box = op.getarg(3 + idx_ref)
-            loc_op = ResOperation(rop.STM_SET_LOCATION, [num_box, ref_box],
-                                  None)
-            self.optimize_STM_SET_LOCATION(loc_op)
-
-    def optimize_STM_SET_LOCATION(self, op):
-        num = op.getarg(0).getint()
-        ref = op.getarg(1).getref_base()
-        self.optimizer.stm_location = (num, ref)
-        self.emit_operation(op)
-
 
 dispatch_opt = make_dispatcher_method(OptSTM, 'optimize_',
                                       default=OptSTM.default_emit)
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
@@ -1123,6 +1123,15 @@
         debug_print(loc)
         args = [ConstInt(jd_index), ConstInt(portal_call_depth), 
ConstInt(current_call_id)] + greenkey
         self.metainterp.history.record(rop.DEBUG_MERGE_POINT, args, None)
+        #
+        if self.metainterp.staticdata.config.translation.stm:
+            report_location = jitdriver_sd.stm_report_location
+            if report_location is not None:
+                idx_num, idx_ref = report_location
+                num = greenkey[idx_num].getint()
+                ref = greenkey[idx_ref].getref_base()
+                location = history.StmLocation(num, ref)
+                self.metainterp.history.stm_location = location
 
     @arguments("box", "label")
     def opimpl_goto_if_exception_mismatch(self, vtablebox, next_exc_target):
@@ -1857,7 +1866,7 @@
             self.framestack[-1].pc = saved_pc
 
     def create_empty_history(self):
-        self.history = history.History()
+        self.history = history.History(self.staticdata)
         self.staticdata.stats.set_history(self.history)
 
     def _all_constants(self, *boxes):
@@ -2080,10 +2089,9 @@
             #
             if (self.staticdata.config.translation.stm and
                     isinstance(key, compile.ResumeGuardDescr)):
-                self.history.record(rop.STM_SET_LOCATION,
-                                    [ConstInt(key.stm_location_int),
-                                     ConstPtr(key.stm_location_ref)],
-                                    None)
+                location = history.StmLocation(key.stm_location_int,
+                                               key.stm_location_ref)
+                self.history.stm_location = location
             #
             self.interpret()
         except SwitchToBlackhole, stb:
@@ -2424,7 +2432,7 @@
         rstack._stack_criticalcode_start()
         try:
             self.portal_call_depth = -1 # always one portal around
-            self.history = history.History()
+            self.history = history.History(self.staticdata)
             inputargs_and_holes = self.rebuild_state_after_failure(resumedescr,
                                                                    deadframe)
             self.history.inputargs = [box for box in inputargs_and_holes if 
box]
@@ -2694,23 +2702,22 @@
     def record_result_of_call_pure(self, resbox):
         """ Patch a CALL into a CALL_PURE.
         """
-        op = self.history.operations[-1]
+        op = self.history.operations.pop()
         assert op.getopnum() == rop.CALL
         resbox_as_const = resbox.constbox()
         for i in range(op.numargs()):
             if not isinstance(op.getarg(i), Const):
                 break
         else:
-            # all-constants: remove the CALL operation now and propagate a
+            # all-constants: keep the CALL operation removed, and propagate a
             # constant result
-            self.history.operations.pop()
             return resbox_as_const
         # not all constants (so far): turn CALL into CALL_PURE, which might
         # be either removed later by optimizeopt or turned back into CALL.
         arg_consts = [a.constbox() for a in op.getarglist()]
         self.call_pure_results[arg_consts] = resbox_as_const
         newop = op.copy_and_change(rop.CALL_PURE, args=op.getarglist())
-        self.history.operations[-1] = newop
+        self.history.record_op(newop)
         return resbox
 
     def direct_assembler_call(self, targetjitdriver_sd):
@@ -2727,7 +2734,7 @@
         warmrunnerstate = targetjitdriver_sd.warmstate
         token = warmrunnerstate.get_assembler_token(greenargs)
         op = op.copy_and_change(rop.CALL_ASSEMBLER, args=args, descr=token)
-        self.history.operations.append(op)
+        self.history.record_op(op)
         #
         # To fix an obscure issue, make sure the vable stays alive
         # longer than the CALL_ASSEMBLER operation.  We do it by
diff --git a/rpython/jit/metainterp/resoperation.py 
b/rpython/jit/metainterp/resoperation.py
--- a/rpython/jit/metainterp/resoperation.py
+++ b/rpython/jit/metainterp/resoperation.py
@@ -22,6 +22,7 @@
     name = ""
     pc = 0
     opnum = 0
+    stm_location = None
     _cls_has_bool_result = False
 
     _attrs_ = ('result',)
@@ -92,6 +93,7 @@
         if descr is not None:
             descr = descr.clone_if_mutable()
         op = ResOperation(self.getopnum(), args[:], self.result, descr)
+        op.stm_location = self.stm_location
         if not we_are_translated():
             op.name = self.name
             op.pc = self.pc
@@ -504,7 +506,6 @@
     'COND_CALL_GC_WB_ARRAY/2d', # [objptr, arrayindex] (write barr. for array)
     'DEBUG_MERGE_POINT/*',      # debugging only
     'JIT_DEBUG/*',              # debugging only
-    'STM_SET_LOCATION/2',
     'VIRTUAL_REF_FINISH/2',   # removed before it's passed to the backend
     'COPYSTRCONTENT/5',       # src, dst, srcstart, dststart, length
     'COPYUNICODECONTENT/5',
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
@@ -88,6 +88,29 @@
                 got.append(op.getarglist()[-1].value)
         assert got == [42, -42, 42, 42, -42, 42]
 
+    def check_stm_locations(self, operations=None, cur_location="???"):
+        if operations is None:
+            from rpython.jit.metainterp.warmspot import get_stats
+            loop = get_stats().get_all_loops()[0]
+            operations = loop.operations
+        #
+        for op in operations:
+            if op.getopname() == "debug_merge_point":
+                num_box, ref_box = op.getarglist()[-2:]
+                num = num_box.getint()
+                ref = ref_box.getref_base()
+                cur_location = (num, ref)
+            elif op.getopname() in ("label", "finish", "jump"):
+                pass
+            else:
+                stmloc = op.stm_location
+                assert stmloc is not None, op
+                assert cur_location == (stmloc.num, stmloc.ref)
+                if (op.is_guard() and
+                        hasattr(op.getdescr(), '_debug_suboperations')):
+                    subops = op.getdescr()._debug_suboperations
+                    self.check_stm_locations(subops, cur_location)
+
     def test_stm_report_location(self):
         myjitdriver = JitDriver(greens = ['a', 'r'], reds = ['x', 'res'],
                                 stm_report_location = [0, 1])
@@ -112,17 +135,7 @@
         res = self.meta_interp(main, [42, 10], translationoptions={"stm":True})
         assert res == 55
         self.check_resops(debug_merge_point=6)
-        self.check_resops(stm_set_location=6)    # on the main loop
-        #
-        from rpython.jit.metainterp.warmspot import get_stats
-        seen = []
-        for loop in get_stats().get_all_loops():
-            for op in loop._all_operations():
-                if op.getopname() == "stm_set_location":
-                    seen.append(op)
-        assert len(seen) == 6 + 1
-        op = seen[-1]
-        assert op.getarg(0).getint() == -42
+        self.check_stm_locations()
 
     def test_stm_report_location_2(self):
         myjitdriver = JitDriver(greens = ['a', 'r'], reds = ['x', 'res', 'n'],
@@ -150,17 +163,7 @@
         res = self.meta_interp(main, [42, 10], translationoptions={"stm":True})
         assert res == 55
         self.check_resops(debug_merge_point=6)
-        #
-        from rpython.jit.metainterp.warmspot import get_stats
-        seen = []
-        for loop in get_stats().get_all_loops():
-            for op in loop._all_operations():
-                if op.getopname() == "stm_set_location":
-                    seen.append(op)
-        assert len(seen) == 6 + 2
-        [op1, op2] = seen[-2:]
-        assert op1.getarg(0).getint() == -42
-        assert op2.getarg(0).getint() == -42
+        self.check_stm_locations()
 
 
 class TestLLtype(STMTests, LLJitMixin):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to