Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: guard-compatible Changeset: r85355:8729edc0c66a Date: 2016-06-22 14:56 +0200 http://bitbucket.org/pypy/pypy/changeset/8729edc0c66a/
Log: start emitting guards from infos, bit of a pain 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 @@ -24,6 +24,7 @@ return None raise AssertionError("bad rettype") + class CompatibilityCondition(object): """ A collections of conditions that an object needs to fulfil. """ def __init__(self, ptr): @@ -105,10 +106,17 @@ return copied_op, QuasiimmutGetfieldAndPureCallCondition( op, qmutdescr, optimizer) + def emit_conditions(self, op, short, optimizer): + """ re-emit the conditions about variable op into the short preamble + """ + for cond in self.conditions: + cond.emit_condition(op, short, optimizer) + def repr_of_conditions(self, argrepr="?"): return "\n".join([cond.repr(argrepr) for cond in self.conditions]) + class Condition(object): def __init__(self, optimizer): self.metainterp_sd = optimizer.metainterp_sd @@ -138,6 +146,9 @@ def repr(self): return "" + def emit_condition(self, op, short, optimizer): + raise NotImplementedError("abstract base class") + def _repr_const(self, arg): from rpython.jit.metainterp.history import ConstInt, ConstFloat, ConstPtr from rpython.rtyper.annlowlevel import llstr, hlstr @@ -211,6 +222,30 @@ return False return True + def emit_condition(self, op, short, optimizer): + from rpython.jit.metainterp.history import INT, REF, FLOAT, VOID + from rpython.jit.metainterp.resoperation import rop, ResOperation + # woah, mess + args = self.args[:] + args[1] = op + descr = self.descr + rettype = descr.get_result_type() + if rettype == INT: + call_op = ResOperation(rop.CALL_PURE_I, args, descr) + elif rettype == FLOAT: + call_op = ResOperation(rop.CALL_PURE_F, args, descr) + elif rettype == REF: + call_op = ResOperation(rop.CALL_PURE_R, args, descr) + else: + assert rettype == VOID + # XXX maybe we should forbid this + call_op = ResOperation(rop.CALL_PURE_R, args, descr) + short.append(call_op) + return + short.append(call_op) + short.append(ResOperation(rop.GUARD_VALUE, [call_op, self.res])) + + def repr(self, argrepr="?"): addr = self.args[0].getaddr() funcname = self.metainterp_sd.get_name_from_address(addr) diff --git a/rpython/jit/metainterp/optimizeopt/info.py b/rpython/jit/metainterp/optimizeopt/info.py --- a/rpython/jit/metainterp/optimizeopt/info.py +++ b/rpython/jit/metainterp/optimizeopt/info.py @@ -78,7 +78,13 @@ pass def make_guards(self, op, short, optimizer): - pass + compat_cond = self._compatibility_conditions + if compat_cond is None: + return + short.append( + ResOperation(rop.GUARD_COMPATIBLE, [ + op, compat_cond.known_valid])) + compat_cond.emit_conditions(op, short, optimizer) @specialize.arg(2) def get_constant_string_spec(self, string_optimizer, mode): diff --git a/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py b/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py --- a/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py +++ b/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py @@ -26,6 +26,8 @@ def __init__(self, cpu): self.cpu = cpu self.optearlyforce = None + self.metainterp_sd = None + self._last_debug_merge_point = None class BaseTestGenerateGuards(BaseTest): def setup_class(self): @@ -465,6 +467,45 @@ """ self.compare(guards, expected, [box]) + def test_guard_compatible(self): + from rpython.jit.metainterp.compatible import CompatibilityCondition + value1 = info.PtrInfo() + ptr = "fakeptr" + value1._compatibility_conditions = CompatibilityCondition( + ConstPtr(self.myptr)) + box = InputArgRef() + guards = [] + value1.make_guards(box, guards, FakeOptimizer(self.cpu)) + expected = """ + [p0] + guard_compatible(p0, ConstPtr(myptr)) [] + """ + self.compare(guards, expected, [box]) + + def test_guard_compatible_with_conditions(self): + from rpython.jit.metainterp.compatible import CompatibilityCondition + optimizer = FakeOptimizer(self.cpu) + value1 = info.PtrInfo() + ptr = "fakeptr" + ccond = value1._compatibility_conditions = CompatibilityCondition( + ConstPtr(self.myptr)) + op = ResOperation( + rop.CALL_PURE_I, [ConstInt(123), ConstPtr(self.myptr)], + descr=self.plaincalldescr) + copied_op, cond = ccond.prepare_const_arg_call( + op, optimizer) + ccond.record_condition(cond, ConstInt(5), optimizer) + box = InputArgRef() + guards = [] + value1.make_guards(box, guards, FakeOptimizer(self.cpu)) + expected = """ + [p0] + guard_compatible(p0, ConstPtr(myptr)) [] + i1 = call_pure_i(123, p0, descr=plaincalldescr) + guard_value(i1, 5) [] + """ + self.compare(guards, expected, [box]) + def test_equal_inputargs(self): classbox = self.cpu.ts.cls_of_box(InputArgRef(self.nodeaddr)) value = info.InstancePtrInfo(None, classbox) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit