Author: Maciej Fijalkowski <[email protected]>
Branch: remember-tracing-counts
Changeset: r79611:60a87ed91e06
Date: 2015-09-14 10:26 +0200
http://bitbucket.org/pypy/pypy/changeset/60a87ed91e06/
Log: access JitCell from the interpreter
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
@@ -156,6 +156,20 @@
assert jit_hooks.stats_get_times_value(None, Counters.TRACING) == 0
self.meta_interp(main, [], ProfilerClass=EmptyProfiler)
+ def test_get_jitcell_at_key(self):
+ driver = JitDriver(greens = ['s'], reds = ['i'], name='jit')
+
+ def loop(i, s):
+ while i > s:
+ driver.jit_merge_point(i=i, s=s)
+ i -= 1
+
+ def main(s):
+ loop(30, s)
+ assert jit_hooks.get_jitcell_at_key("jit", s)
+ assert not jit_hooks.get_jitcell_at_key("jit", s + 1)
+
+ self.meta_interp(main, [5])
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
@@ -1,9 +1,9 @@
-import sys
+import sys, py
from rpython.tool.sourcetools import func_with_new_name
from rpython.rtyper.lltypesystem import lltype, llmemory
from rpython.rtyper.annlowlevel import (llhelper, MixLevelHelperAnnotator,
- cast_base_ptr_to_instance, hlstr)
+ cast_base_ptr_to_instance, hlstr, cast_instance_to_gcref)
from rpython.rtyper.llannotation import lltype_to_annotation
from rpython.annotator import model as annmodel
from rpython.rtyper.llinterp import LLException
@@ -236,6 +236,7 @@
self.rewrite_can_enter_jits()
self.rewrite_set_param_and_get_stats()
self.rewrite_force_virtual(vrefinfo)
+ self.rewrite_jitcell_accesses()
self.rewrite_force_quasi_immutable()
self.add_finish()
self.metainterp_sd.finish_setup(self.codewriter)
@@ -598,6 +599,45 @@
(_, jd._PTR_ASSEMBLER_HELPER_FUNCTYPE) = self.cpu.ts.get_FuncType(
[llmemory.GCREF, llmemory.GCREF], ASMRESTYPE)
+ def rewrite_jitcell_accesses(self):
+ jitdrivers_by_name = {}
+ for jd in self.jitdrivers_sd:
+ name = jd.jitdriver.name
+ if name != 'jitdriver':
+ jitdrivers_by_name[name] = jd
+ m = _find_jit_marker(self.translator.graphs, 'get_jitcell_at_key',
+ False)
+ accessors = {}
+
+ def get_accessor(jitdriver_name, function, ARGS):
+ a = accessors.get(jitdriver_name)
+ if a:
+ return a
+ 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'])
+ accessors[jitdriver_name] = ll_ptr
+ return ll_ptr
+
+ for graph, block, index in m:
+ op = block.operations[index]
+ jitdriver_name = op.args[1].value
+ JitCell = jitdrivers_by_name[jitdriver_name].warmstate.JitCell
+ ARGS = [x.concretetype for x in op.args[2:]]
+ accessor = get_accessor(jitdriver_name, JitCell.get_jitcell,
+ ARGS)
+ v_result = op.result
+ c_accessor = Constant(accessor, concretetype=lltype.Void)
+ newop = SpaceOperation('direct_call', [c_accessor] + op.args[2:],
+ v_result)
+ block.operations[index] = newop
+
def rewrite_can_enter_jits(self):
sublists = {}
for jd in self.jitdrivers_sd:
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
@@ -5,6 +5,7 @@
cast_base_ptr_to_instance, llstr)
from rpython.rtyper.extregistry import ExtRegistryEntry
from rpython.rtyper.lltypesystem import llmemory, lltype
+from rpython.flowspace.model import Constant
from rpython.rtyper import rclass
@@ -127,3 +128,24 @@
@register_helper(lltype.Ptr(LOOP_RUN_CONTAINER))
def stats_get_loop_run_times(warmrunnerdesc):
return warmrunnerdesc.metainterp_sd.cpu.get_all_loop_runs()
+
+# ---------------------- jitcell interface ----------------------
+
+def get_jitcell_at_key(name, *greenkey):
+ raise Exception("need to run translated")
+
+class GetJitCellEntry(ExtRegistryEntry):
+ _about_ = get_jitcell_at_key
+
+ def compute_result_annotation(self, s_name, *args_s):
+ assert s_name.is_constant()
+ return SomePtr(llmemory.GCREF)
+
+ 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)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit