[pypy-commit] pypy stmgc-c7: In stm mode, stick the 'next_instr' and the 'pycode' arguments (an int

arigo noreply at buildbot.pypy.org
Sun Apr 20 13:48:03 CEST 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r70801:8fb2e2faf420
Date: 2014-04-20 13:43 +0200
http://bitbucket.org/pypy/pypy/changeset/8fb2e2faf420/

Log:	In stm mode, stick the 'next_instr' and the 'pycode' arguments (an
	int and a ref from the greenkey) on the guard's descrs.

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,6 +1039,9 @@
     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,10 +515,12 @@
     TY_REF          = 0x04
     TY_FLOAT        = 0x06
 
-    def store_final_boxes(self, guard_op, boxes, metainterp_sd):
+    def store_final_boxes(self, guard_op, boxes, metainterp_sd, stm_location):
         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 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,6 +346,7 @@
                          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/jitdriver.py b/rpython/jit/metainterp/jitdriver.py
--- a/rpython/jit/metainterp/jitdriver.py
+++ b/rpython/jit/metainterp/jitdriver.py
@@ -18,6 +18,7 @@
     #    self.warmstate         ... rpython.jit.metainterp.warmspot
     #    self.handle_jitexc_from_bh rpython.jit.metainterp.warmspot
     #    self.no_loop_header    ... rpython.jit.metainterp.warmspot
+    #    self.stm_report_location.. rpython.jit.metainterp.warmspot
     #    self.portal_finishtoken... rpython.jit.metainterp.pyjitpl
     #    self.propagate_exc_descr.. rpython.jit.metainterp.pyjitpl
     #    self.index             ... rpython.jit.codewriter.call
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,6 +360,12 @@
             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()
 
@@ -571,7 +577,8 @@
                 raise resume.TagOverflow
         except resume.TagOverflow:
             raise compile.giveup()
-        descr.store_final_boxes(op, newboxes, self.metainterp_sd)
+        descr.store_final_boxes(op, newboxes, self.metainterp_sd,
+                                self.stm_location)
         #
         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
@@ -83,13 +83,18 @@
                 self._set_break_wanted(True)
             self.keep_but_ignore_gnf = False
             self.emit_operation(op)
-        
-        
+
+    def optimize_DEBUG_MERGE_POINT(self, 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 = op.getarg(3 + idx_num).getint()
+            ref = op.getarg(3 + idx_ref).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
@@ -2077,6 +2077,14 @@
                                              deadframe)
             if self.resumekey_original_loop_token is None:   # very rare case
                 raise SwitchToBlackhole(Counters.ABORT_BRIDGE)
+            #
+            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)
+            #
             self.interpret()
         except SwitchToBlackhole, stb:
             self.run_blackhole_interp_to_cancel_tracing(stb)
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
@@ -504,6 +504,7 @@
     '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
@@ -65,7 +65,62 @@
             'guard_no_exception':1,
             'call_may_force':1})
 
+    def test_debug_merge_points(self):
+        myjitdriver = JitDriver(greens = ['a'], reds = ['x', 'res'])
+        def g(a, x):
+            res = 0
+            while x > 0:
+                myjitdriver.jit_merge_point(a=a, x=x, res=res)
+                res += x
+                x -= 1
+                a = -a
+            return res
+        res = self.meta_interp(g, [42, 10], translationoptions={"stm":True})
+        assert res == 55
+        self.check_resops(debug_merge_point=6)
+        #
+        from rpython.jit.metainterp.warmspot import get_stats
+        loops = get_stats().get_all_loops()
+        assert len(loops) == 1
+        got = []
+        for op in loops[0]._all_operations():
+            if op.getopname() == "debug_merge_point":
+                got.append(op.getarglist()[-1].value)
+        assert got == [42, -42, 42, 42, -42, 42]
 
+    def test_stm_report_location(self):
+        myjitdriver = JitDriver(greens = ['a', 'r'], reds = ['x', 'res'],
+                                stm_report_location = [0, 1])
+        class Code(object):
+            pass
+        def g(a, r, x):
+            res = 0
+            while x > 0:
+                myjitdriver.jit_merge_point(a=a, r=r, x=x, res=res)
+                res += x
+                x -= 1
+                a = -a
+            return res
+        def main(a, x):
+            r = Code()
+            res = -1
+            n = 7
+            while n > 0:
+                res = g(a, r, x)
+                n -= 1
+            return res
+        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)
+        [op] = seen
+        assert op.getarg(0).getint() == -42
 
 
 class TestLLtype(STMTests, LLJitMixin):
diff --git a/rpython/jit/metainterp/warmspot.py b/rpython/jit/metainterp/warmspot.py
--- a/rpython/jit/metainterp/warmspot.py
+++ b/rpython/jit/metainterp/warmspot.py
@@ -389,6 +389,7 @@
         graph.func._dont_inline_ = True
         graph.func._jit_unroll_safe_ = True
         jd.jitdriver = block.operations[pos].args[1].value
+        jd.stm_report_location = jd.jitdriver.stm_report_location
         jd.portal_runner_ptr = "<not set so far>"
         jd.result_type = history.getkind(jd.portal_graph.getreturnvar()
                                          .concretetype)[0]
diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -484,13 +484,15 @@
     inline_jit_merge_point = False
     _store_last_enter_jit = None
     stm_do_transaction_breaks = False
+    stm_report_location = None
 
     def __init__(self, greens=None, reds=None, virtualizables=None,
                  get_jitcell_at=None, set_jitcell_at=None,
                  get_printable_location=None, confirm_enter_jit=None,
                  can_never_inline=None, should_unroll_one_iteration=None,
                  name='jitdriver', check_untranslated=True,
-                 stm_do_transaction_breaks=None):
+                 stm_do_transaction_breaks=None,
+                 stm_report_location=None):
         if greens is not None:
             self.greens = greens
         self.name = name
@@ -528,6 +530,8 @@
         self.check_untranslated = check_untranslated
         if stm_do_transaction_breaks is not None:
             self.stm_do_transaction_breaks = stm_do_transaction_breaks
+        if stm_report_location is not None:
+            self.stm_report_location = stm_report_location
 
     def _freeze_(self):
         return True


More information about the pypy-commit mailing list