Author: Maciej Fijalkowski <[email protected]>
Branch: remember-tracing-counts
Changeset: r79614:df24639b3a95
Date: 2015-09-14 11:15 +0200
http://bitbucket.org/pypy/pypy/changeset/df24639b3a95/

Log:    implement dont_trace_here hook

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
@@ -1582,8 +1582,9 @@
                 resbox = self.metainterp.execute_and_record_varargs(
                     rop.CALL_MAY_FORCE_F, allboxes, descr=descr)
             elif tp == 'v':
-                resbox = self.metainterp.execute_and_record_varargs(
+                self.metainterp.execute_and_record_varargs(
                     rop.CALL_MAY_FORCE_N, allboxes, descr=descr)
+                resbox = None
             else:
                 assert False
             self.metainterp.vrefs_after_residual_call()
@@ -2961,6 +2962,8 @@
         opnum = OpHelpers.call_assembler_for_descr(op.getdescr())
         op = op.copy_and_change(opnum, args=args, descr=token)
         self.history.operations.append(op)
+        if opnum == rop.CALL_ASSEMBLER_N:
+            op = None
         #
         # 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/test/test_jitiface.py 
b/rpython/jit/metainterp/test/test_jitiface.py
--- a/rpython/jit/metainterp/test/test_jitiface.py
+++ b/rpython/jit/metainterp/test/test_jitiface.py
@@ -175,6 +175,31 @@
         self.meta_interp(main, [5])
         self.check_jitcell_token_count(2)
 
+    def test_dont_trace_here(self):
+        driver = JitDriver(greens = ['s'], reds = ['i', 'k'], name='jit')
+
+        def loop(i, s):
+            k = 4
+            while i > 0:
+                driver.jit_merge_point(k=k, i=i, s=s)
+                if s == 1:
+                    loop(3, 0)
+                k -= 1
+                i -= 1
+                if k == 0:
+                    k = 4
+                    driver.can_enter_jit(k=k, i=i, s=s)
+
+        def main(s, check):
+            if check:
+                jit_hooks.dont_trace_here("jit", 0)
+            loop(30, s)
+
+        self.meta_interp(main, [1, 0], inline=True)
+        self.check_resops(call_assembler_n=0)
+        self.meta_interp(main, [1, 1], inline=True)
+        self.check_resops(call_assembler_n=8)
+
 class LLJitHookInterfaceTests(JitHookInterfaceTests):
     # use this for any backend, instead of the super class
     
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
@@ -617,7 +617,8 @@
             if name != 'jitdriver':
                 jitdrivers_by_name[name] = jd
         m = _find_jit_markers(self.translator.graphs,
-                              ('get_jitcell_at_key', 'trace_next_iteration'))
+                              ('get_jitcell_at_key', 'trace_next_iteration',
+                               'dont_trace_here'))
         accessors = {}
 
         def get_accessor(name, jitdriver_name, function, ARGS):
@@ -627,12 +628,20 @@
             d = {'function': function,
                  'cast_instance_to_gcref': cast_instance_to_gcref}
             arg_spec = ", ".join([("arg%d" % i) for i in range(len(ARGS))])
-            exec py.code.Source("""
-            def accessor(%s):
-                return cast_instance_to_gcref(function(%s))
-            """ % (arg_spec, arg_spec)).compile() in d
-            FUNC = lltype.Ptr(lltype.FuncType(ARGS, llmemory.GCREF))
-            ll_ptr = self.helper_func(FUNC, d['accessor'])
+            if name == 'get_jitcell_at_key':
+                exec py.code.Source("""
+                def accessor(%s):
+                    return cast_instance_to_gcref(function(%s))
+                """ % (arg_spec, arg_spec)).compile() in d
+                FUNC = lltype.Ptr(lltype.FuncType(ARGS, llmemory.GCREF))
+            else:
+                exec py.code.Source("""
+                def accessor(%s):
+                    function(%s)
+                """ % (arg_spec, arg_spec)).compile() in d
+                FUNC = lltype.Ptr(lltype.FuncType(ARGS, lltype.Void))
+            func = d['accessor']
+            ll_ptr = self.helper_func(FUNC, func)
             accessors[(name, jitdriver_name)] = ll_ptr
             return ll_ptr
 
@@ -643,6 +652,8 @@
             ARGS = [x.concretetype for x in op.args[2:]]
             if op.args[0].value == 'get_jitcell_at_key':
                 func = JitCell.get_jitcell
+            elif op.args[0].value == 'dont_trace_here':
+                func = JitCell.dont_trace_here
             else:
                 func = JitCell._trace_next_iteration
             accessor = get_accessor(op.args[0].value,
diff --git a/rpython/jit/metainterp/warmstate.py 
b/rpython/jit/metainterp/warmstate.py
--- a/rpython/jit/metainterp/warmstate.py
+++ b/rpython/jit/metainterp/warmstate.py
@@ -555,6 +555,10 @@
             @staticmethod
             def ensure_jit_cell_at_key(greenkey):
                 greenargs = unwrap_greenkey(greenkey)
+                return JitCell._ensure_jit_cell_at_key(*greenargs)
+
+            @staticmethod
+            def _ensure_jit_cell_at_key(*greenargs):
                 hash = JitCell.get_uhash(*greenargs)
                 cell = jitcounter.lookup_chain(hash)
                 while cell is not None:
@@ -565,6 +569,11 @@
                 newcell = JitCell(*greenargs)
                 jitcounter.install_new_cell(hash, newcell)
                 return newcell
+
+            @staticmethod
+            def dont_trace_here(*greenargs):
+                cell = JitCell._ensure_jit_cell_at_key(*greenargs)
+                cell.flags |= JC_DONT_TRACE_HERE
         #
         self.JitCell = JitCell
         return JitCell
diff --git a/rpython/rlib/jit_hooks.py b/rpython/rlib/jit_hooks.py
--- a/rpython/rlib/jit_hooks.py
+++ b/rpython/rlib/jit_hooks.py
@@ -131,39 +131,29 @@
 
 # ---------------------- jitcell interface ----------------------
 
-def get_jitcell_at_key(name, *greenkey):
-    raise Exception("need to run translated")
+def _new_hook(name, resulttype):
+    def hook(name, *greenkey):
+        raise Exception("need to run translated")
+    hook.func_name = name
 
-class GetJitCellEntry(ExtRegistryEntry):
-    _about_ = get_jitcell_at_key
+    class GetJitCellEntry(ExtRegistryEntry):
+        _about_ = hook
 
-    def compute_result_annotation(self, s_name, *args_s):
-        assert s_name.is_constant()
-        return SomePtr(llmemory.GCREF)
+        def compute_result_annotation(self, s_name, *args_s):
+            assert s_name.is_constant()
+            return resulttype
 
-    def specialize_call(self, hop):
-        c_jitdriver = Constant(hop.args_s[0].const, concretetype=lltype.Void)
-        c_name = Constant("get_jitcell_at_key", concretetype=lltype.Void)
-        hop.exception_cannot_occur()
-        args_v = [hop.inputarg(arg, arg=i + 1)
-                  for i, arg in enumerate(hop.args_r[1:])]
-        return hop.genop('jit_marker', [c_name, c_jitdriver] + args_v,
-                         resulttype=hop.r_result)
+        def specialize_call(self, hop):
+            c_jitdriver = Constant(hop.args_s[0].const, 
concretetype=lltype.Void)
+            c_name = Constant(name, concretetype=lltype.Void)
+            hop.exception_cannot_occur()
+            args_v = [hop.inputarg(arg, arg=i + 1)
+                      for i, arg in enumerate(hop.args_r[1:])]
+            return hop.genop('jit_marker', [c_name, c_jitdriver] + args_v,
+                             resulttype=hop.r_result)
 
-def trace_next_iteration(name, *greenkey):
-    raise Exception("need to run translated")
+    return hook
 
-class TraceNextIterationEntry(ExtRegistryEntry):
-    _about_ = trace_next_iteration
-
-    def compute_result_annotation(self, s_name, *args_s):
-        assert s_name.is_constant()
-
-    def specialize_call(self, hop):
-        c_jitdriver = Constant(hop.args_s[0].const, concretetype=lltype.Void)
-        c_name = Constant("trace_next_iteration", concretetype=lltype.Void)
-        hop.exception_cannot_occur()
-        args_v = [hop.inputarg(arg, arg=i + 1)
-                  for i, arg in enumerate(hop.args_r[1:])]
-        return hop.genop('jit_marker', [c_name, c_jitdriver] + args_v,
-                         resulttype=hop.r_result)
+get_jitcell_at_key = _new_hook('get_jitcell_at_key', SomePtr(llmemory.GCREF))
+trace_next_iteration = _new_hook('trace_next_iteration', None)
+dont_trace_here = _new_hook('dont_trace_here', None)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to