Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: guard-compatible Changeset: r87248:4f02e3d3f6f9 Date: 2016-08-23 15:03 +0100 http://bitbucket.org/pypy/pypy/changeset/4f02e3d3f6f9/
Log: add debug prints to at least have a chance to figure out what is going on diff --git a/rpython/jit/metainterp/compatible.py b/rpython/jit/metainterp/compatible.py --- a/rpython/jit/metainterp/compatible.py +++ b/rpython/jit/metainterp/compatible.py @@ -2,6 +2,8 @@ from rpython.jit.metainterp.history import newconst from rpython.jit.codewriter import longlong from rpython.jit.metainterp.resoperation import rop +from rpython.rlib.debug import (have_debug_prints, debug_start, debug_stop, + debug_print) def do_call(cpu, argboxes, descr): from rpython.jit.metainterp.history import INT, REF, FLOAT, VOID @@ -64,8 +66,11 @@ self.last_quasi_immut_field_op = op def check_compat(self, cpu, ref): - for cond in self.conditions: - if not cond.check(cpu, ref): + for i, cond in enumerate(self.conditions): + res = cond.check_and_return_result_if_different(cpu, ref) + if res is not None: + if have_debug_prints(): + debug_print("incompatible condition", i, ", got", cond._repr_const(res), ":", cond.repr()) return False return True @@ -168,7 +173,7 @@ if const is None: return False ref = const.getref_base() - if cond.check(cpu, ref): + if cond.check_and_return_result_if_different(cpu, ref) is None: if not have_guard: # NB: the guard_compatible here needs to use const, # otherwise the optimizer will just complain @@ -254,7 +259,9 @@ self.debug_mp_str = s self.rpyfunc = None - def check(self, cpu, ref): + def check_and_return_result_if_different(self, cpu, ref): + """ checks the condition using ref as an argument to the function. if + the result is different, return the result. otherwise return None. """ raise NotImplementedError def activate(self, ref, optimizer): @@ -309,8 +316,7 @@ self.descr = op.getdescr() self.rpyfunc = op.rpyfunc - def check(self, cpu, ref): - from rpython.rlib.debug import debug_print, debug_start, debug_stop + def check_and_return_result_if_different(self, cpu, ref): calldescr = self.descr # change exactly the first argument arglist = self.args @@ -318,15 +324,17 @@ try: res = do_call(cpu, arglist, calldescr) except Exception: - debug_start("jit-guard-compatible") - debug_print("call to elidable_compatible function raised") - debug_stop("jit-guard-compatible") + if have_debug_prints(): + debug_start("jit-guard-compatible") + debug_print("call to elidable_compatible function raised") + debug_print(self.repr()) + debug_stop("jit-guard-compatible") return False finally: arglist[1] = None if not res.same_constant(self.res): - return False - return True + return res + return None def same_cond(self, other, res=None): if type(other) is not PureCallCondition: @@ -433,7 +441,7 @@ self.mutatefielddescr) qmut.register_loop_token(loop_token.loop_token_wref) - def check(self, cpu, ref): + def check_and_return_result_if_different(self, cpu, ref): from rpython.rlib.debug import debug_print, debug_start, debug_stop from rpython.jit.metainterp.quasiimmut import QuasiImmutDescr calldescr = self.descr @@ -444,15 +452,17 @@ try: res = do_call(cpu, arglist, calldescr) except Exception: - debug_start("jit-guard-compatible") - debug_print("call to elidable_compatible function raised") - debug_stop("jit-guard-compatible") + if have_debug_prints(): + debug_start("jit-guard-compatible") + debug_print("call to elidable_compatible function raised") + debug_print(self.repr()) + debug_stop("jit-guard-compatible") return False finally: arglist[1] = arglist[2] = None if not res.same_constant(self.res): - return False - return True + return res + return None def same_cond(self, other, res=None): if type(other) is not QuasiimmutGetfieldAndPureCallCondition: 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 @@ -1,7 +1,7 @@ import weakref from rpython.rtyper.lltypesystem import lltype, llmemory from rpython.rtyper.annlowlevel import cast_instance_to_gcref -from rpython.rlib.objectmodel import we_are_translated +from rpython.rlib.objectmodel import we_are_translated, compute_unique_id from rpython.rlib.debug import debug_start, debug_stop, debug_print, have_debug_prints from rpython.rlib.rarithmetic import r_uint, intmask from rpython.rlib import rstack @@ -1110,18 +1110,31 @@ """ # need to do the checking oldest to newest, to check the most specific # condition first - if self._compatibility_conditions: - if self._compatibility_conditions.check_compat_and_activate( - cpu, ref, self.rd_loop_token): - return self._compatibility_conditions.jump_target - for _compatibility_conditions in self.other_compat_conditions: - if _compatibility_conditions.check_compat_and_activate( - cpu, ref, self.rd_loop_token): - return _compatibility_conditions.jump_target - # none of the other conditions matched. if we have a - # fallback_jump_target, go there (otherwise we run the risk of - # producing arbitrary amounts of code) - return self.fallback_jump_target + debug_start("jit-guard-compatible") + try: + if have_debug_prints(): + debug_print("Guard0x%x check compatibility of" % (compute_unique_id(self), ), ref) + if self._compatibility_conditions: + if self._compatibility_conditions.check_compat_and_activate( + cpu, ref, self.rd_loop_token): + debug_print("first guard is compatible") + return self._compatibility_conditions.jump_target + for i, _compatibility_conditions in enumerate(self.other_compat_conditions): + if _compatibility_conditions.check_compat_and_activate( + cpu, ref, self.rd_loop_token): + debug_print("attached guard", i, "is compatible") + return _compatibility_conditions.jump_target + if have_debug_prints(): + if self.fallback_jump_target: + debug_print("all incompatible, going to fallback") + else: + debug_print("all incompatible, failing") + # none of the other conditions matched. if we have a + # fallback_jump_target, go there (otherwise we run the risk of + # producing arbitrary amounts of code) + return self.fallback_jump_target + finally: + debug_stop("jit-guard-compatible") def compile_and_attach(self, metainterp, new_loop, orig_inputargs): # if new_loop starts with another guard_compatible on the same argument _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit