Author: Richard Plangger <[email protected]>
Branch: new-jit-log
Changeset: r83803:794f3f697344
Date: 2016-04-21 10:18 +0200
http://bitbucket.org/pypy/pypy/changeset/794f3f697344/
Log: working on the API for get_location (nearly done)
diff --git a/pypy/module/pypyjit/interp_jit.py
b/pypy/module/pypyjit/interp_jit.py
--- a/pypy/module/pypyjit/interp_jit.py
+++ b/pypy/module/pypyjit/interp_jit.py
@@ -49,12 +49,8 @@
name = bytecode.co_name
if not name:
name = ""
- # we can probably do better at co_firstlineno?
- return (bytecode.co_filename,
- bytecode.co_firstlineno,
- name,
- intmask(next_instr),
- opname)
+ return "shshs", [bytecode.co_filename, bytecode.co_firstlineno,
+ name, intmask(next_instr), opname]
def should_unroll_one_iteration(next_instr, is_being_profiled, bytecode):
return (bytecode.co_flags & CO_GENERATOR) != 0
diff --git a/rpython/jit/backend/llsupport/test/ztranslation_test.py
b/rpython/jit/backend/llsupport/test/ztranslation_test.py
--- a/rpython/jit/backend/llsupport/test/ztranslation_test.py
+++ b/rpython/jit/backend/llsupport/test/ztranslation_test.py
@@ -3,7 +3,7 @@
from rpython.rlib.jit import JitDriver, unroll_parameters, set_param
from rpython.rlib.jit import PARAMETERS, dont_look_inside
from rpython.rlib.jit import promote, _get_virtualizable_token
-from rpython.rlib import jit_hooks, rposix
+from rpython.rlib import jit_hooks, rposix, jitlog
from rpython.rlib.objectmodel import keepalive_until_here
from rpython.rlib.rthread import ThreadLocalReference, ThreadLocalField
from rpython.jit.backend.detect_cpu import getcpuclass
@@ -48,8 +48,11 @@
lltype.Float, macro=True, releasegil=True,
compilation_info=eci)
+ @jitlog.returns(jitlog.MP_FILENAME,
+ jitlog.MP_LINENO,
+ jitlog.MP_INDEX)
def get_location():
- return "file", 0, "func", 0, "opcode"
+ return ("/home.py",0,0)
jitdriver = JitDriver(greens = [],
reds = ['total', 'frame', 'j'],
diff --git a/rpython/jit/metainterp/jitlog.py b/rpython/jit/metainterp/jitlog.py
--- a/rpython/jit/metainterp/jitlog.py
+++ b/rpython/jit/metainterp/jitlog.py
@@ -5,6 +5,7 @@
from rpython.rlib.objectmodel import we_are_translated
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
from rpython.rlib.objectmodel import compute_unique_id, always_inline
+from rpython.rlib import jitlog as jl
import sys
import weakref
import struct
@@ -32,6 +33,7 @@
MARK_JITLOG_COUNTER = 0x20
MARK_START_TRACE = 0x21
+MARK_INIT_MERGE_POINT = 0x22
MARK_JITLOG_HEADER = 0x23
MARK_JITLOG_DEBUG_MERGE_POINT = 0x24
@@ -71,6 +73,18 @@
else:
return encode_le_64bit(val)
+def encode_type(type, value):
+ if type == "s":
+ return encode_str(value)
+ elif type == "q":
+ return encode_le_64bit(value)
+ elif type == "i":
+ return encode_le_32bit(value)
+ elif type == "h":
+ return encode_le_32bit(value)
+ else:
+ raise NotImplementedError
+
def assemble_header():
version = JITLOG_VERSION_16BIT_LE
count = len(resoperations.opname)
@@ -110,7 +124,7 @@
else:
content.append(encode_str('loop'))
content.append(encode_le_addr(int(entry_bridge)))
- self.cintf._write_marked(MARK_START_TRACE, ''.join(content))
+ self._write_marked(MARK_START_TRACE, ''.join(content))
self.trace_id += 1
def _write_marked(self, mark, line):
@@ -161,6 +175,7 @@
self.tag = tag
self.mc = mc
self.logger = logger
+ self.merge_point_file = None
def write_trace(self, trace):
ops = []
@@ -169,9 +184,9 @@
ops.append(i.next())
self.write(i.inputargs, ops)
- def write(self, args, ops, faildescr=None, ops_offset={}):
+ def write(self, args, ops, ops_offset={}):
log = self.logger
- log._write_marked(self.tag, encode_le_addr(self.trace_id))
+ log._write_marked(self.tag, encode_le_addr(self.logger.trace_id))
# input args
str_args = [self.var_to_str(arg) for arg in args]
@@ -196,16 +211,40 @@
self.memo = {}
+ def encode_once(self):
+ pass
+
def encode_debug_info(self, op):
log = self.logger
jd_sd = self.metainterp_sd.jitdrivers_sd[op.getarg(0).getint()]
- filename, lineno, enclosed, index, opname =
jd_sd.warmstate.get_location(op.getarglist()[3:])
+ if not jd_sd.warmstate.get_location:
+ return
+ types = jd_sd.warmstate.get_location_types
+ values = jd_sd.warmstate.get_location(op.getarglist()[3:])
+ if values is None:
+ # indicates that this function is not provided to the jit driver
+ return
+
+ if self.merge_point_file is None:
+ # first time visiting a merge point
+ positions = jd_sd.warmstate.get_location_positions
+ encoded_types = []
+ for i, (semantic_type, _) in enumerate(positions):
+ encoded_types.append(chr(semantic_type))
+ if semantic_type == jl.MP_FILENAME:
+ self.common_prefix = values[i]
+ log._write_marked(MARK_INIT_MERGE_POINT, ''.join(encoded_types))
+
+
+ # the types have already been written
line = []
- line.append(encode_str(filename or ""))
- line.append(encode_le_16bit(lineno))
- line.append(encode_str(enclosed or ""))
- line.append(encode_le_64bit(index))
- line.append(encode_str(opname or ""))
+ for i,(sem_type,gen_type) in enumerate(types):
+ value = values[i]
+ if sem_type == jl.PM_FILENAME:
+ self.common_prefix = os.path.commonpath([self.common_prefix,
value])
+ log._write_marked(MARK_COMMON_PREFIX, chr(jl.PM_FILENAME) + \
+
encode_str(self.common_prefix))
+ line.append(encode_type(gen_type, value))
log._write_marked(MARK_JITLOG_DEBUG_MERGE_POINT, ''.join(line))
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
@@ -6,6 +6,7 @@
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.annotator.dictdef import DictDef
from rpython.rtyper.llinterp import LLException
from rpython.rtyper.test.test_llinterp import get_interpreter, clear_tcache
from rpython.flowspace.model import SpaceOperation, Variable, Constant
@@ -563,14 +564,12 @@
jd._maybe_compile_and_run_fn = maybe_compile_and_run
def make_driverhook_graphs(self):
- s_Str = annmodel.SomeString()
- s_Str_None = annmodel.SomeString(can_be_None=True)
- s_Int = annmodel.SomeInteger()
#
annhelper = MixLevelHelperAnnotator(self.translator.rtyper)
for jd in self.jitdrivers_sd:
jd._printable_loc_ptr = self._make_hook_graph(jd,
- annhelper, jd.jitdriver.get_printable_location, s_Str)
+ annhelper, jd.jitdriver.get_printable_location,
+ annmodel.SomeString())
jd._get_unique_id_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.get_unique_id, annmodel.SomeInteger())
jd._confirm_enter_jit_ptr = self._make_hook_graph(jd,
@@ -581,9 +580,36 @@
jd._should_unroll_one_iteration_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.should_unroll_one_iteration,
annmodel.s_Bool)
- s_Tuple = annmodel.SomeTuple([s_Str_None, s_Int, s_Str_None,
s_Int, s_Str_None])
+ #
+ s_Str = annmodel.SomeString(no_nul=True)
+ s_Int = annmodel.SomeInteger()
+ items = []
+ types = ()
+ pos = ()
+ if jd.jitdriver.get_location:
+ assert hasattr(jd.jitdriver.get_location, '_loc_types'), """
+ You must decorate your get_location function:
+
+ from rpython.rlib import jitlog as jl
+ @jl.returns(jl.MP_FILENAME, jl.MP_XXX, ...)
+ def get_loc(your, green, keys):
+ name = "x.txt" # extract it from your green keys
+ return (name, ...)
+ """
+ types = jd.jitdriver.get_location._loc_types
+ del jd.jitdriver.get_location._loc_types
+ #
+ for _,type in types:
+ if type == 's':
+ items.append(s_Str)
+ elif type == 'i':
+ items.append(s_Int)
+ else:
+ raise NotImplementedError
+ s_Tuple = annmodel.SomeTuple(items)
jd._get_location_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.get_location, s_Tuple)
+ jd._get_loc_types = types
annhelper.finish()
def _make_hook_graph(self, jitdriver_sd, annhelper, func,
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
@@ -6,6 +6,7 @@
from rpython.rlib.debug import debug_start, debug_stop, debug_print
from rpython.rlib.debug import have_debug_prints_for
from rpython.rlib.jit import PARAMETERS
+from rpython.rlib import jitlog
from rpython.rlib.nonconst import NonConstant
from rpython.rlib.objectmodel import specialize, we_are_translated, r_dict
from rpython.rlib.rarithmetic import intmask, r_uint
@@ -678,26 +679,33 @@
drivername = jitdriver.name
else:
drivername = '<unknown jitdriver>'
- # get_location new API
+ # get_location returns
get_location_ptr = self.jitdriver_sd._get_location_ptr
- if get_location_ptr is None:
- missing_get_loc = '(%s: no get_location)' % drivername
- def get_location(greenkey):
- return (missing_get_loc, 0, '', 0, '')
- else:
+ if get_location_ptr is not None:
+ types = self.jitdriver_sd._get_loc_types
unwrap_greenkey = self.make_unwrap_greenkey()
+ unrolled_types = unrolling_iterable(enumerate(types))
def get_location(greenkey):
greenargs = unwrap_greenkey(greenkey)
fn = support.maybe_on_top_of_llinterp(rtyper, get_location_ptr)
tuple_ptr = fn(*greenargs)
- # it seems there is no "hltuple" function
- return (hlstr(tuple_ptr.item0),
- intmask(tuple_ptr.item1),
- hlstr(tuple_ptr.item2),
- intmask(tuple_ptr.item3),
- hlstr(tuple_ptr.item4)
- )
- self.get_location = get_location
+ #
+ flag = intmask(tuple_ptr.item0)
+ value_tuple = tuple_ptr.item1
+ ntuple = ()
+ for i,(_,t) in unrolled_types:
+ if t == "s":
+ ntuple += (hlstr(getattr(value_tuple, 'item' +
str(i))),)
+ elif t == "i":
+ ntuple += (intmask(getattr(value_tuple, 'item' +
str(i))),)
+ else:
+ raise NotImplementedError
+ return flag, ntuple
+ self.get_location_types = types
+ self.get_location = get_location
+ else:
+ self.get_location_types = None
+ self.get_location = None
#
printable_loc_ptr = self.jitdriver_sd._printable_loc_ptr
if printable_loc_ptr is None:
diff --git a/rpython/rlib/jitlog.py b/rpython/rlib/jitlog.py
new file mode 100644
--- /dev/null
+++ b/rpython/rlib/jitlog.py
@@ -0,0 +1,28 @@
+
+# generic parameters
+MP_STR = (0x0, "s")
+MP_INT = (0x0, "i")
+
+# concrete parameters
+MP_FILENAME = (0x1, "s")
+MP_LINENO = (0x2, "i")
+MP_INDEX = (0x4, "i")
+MP_ENCLOSING = (0x8, "s")
+MP_OPCODE = (0x10, "s")
+
+def get_type(flag):
+ pass
+
+def returns(*args):
+ """ Decorate your get_location function to specify the types.
+ Use MP_* constant as parameters. An example impl for get_location
+ would return the following:
+
+ @returns(MP_FILENAME, MP_LINENO)
+ def get_location(...):
+ return ("a.py", 0)
+ """
+ def decor(method):
+ method._loc_types = args
+ return method
+ return decor
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit