def indirect_residual_call_test(argtypes, restype, expectedkind): # an indirect call that is residual in all cases is very similar to # a residual direct call op = get_direct_call_op(argtypes, restype) op.opname = "indirect_call" op.args[0] = varoftype(op.args[0].concretetype) op.args.append(Constant(["somegraph1", "somegraph2"], lltype.Void)) tr = Transformer(FakeCPU(), FakeResidualIndirectCallControl()) tr.graph = "someinitialgraph" oplist = tr.rewrite_operation(op) op0, op1 = oplist reskind = getkind(restype)[0] assert op0.opname == "residual_call_%s_%s" % (expectedkind, reskind) assert op0.result == op.result assert op0.args[0] == op.args[0] assert op0.args[-1] == "calldescr" assert len(op0.args) == 1 + len(expectedkind) + 1 for sublist, kind1 in zip(op0.args[1:-1], expectedkind): assert sublist.kind.startswith(kind1) assert list(sublist) == [v for v in op.args[1:] if getkind(v.concretetype) == sublist.kind] for v in op.args[1:]: kind = getkind(v.concretetype) assert kind == "void" or kind[0] in expectedkind assert op1.opname == "-live-" assert op1.args == []
def test_int_abs(): v1 = varoftype(lltype.Signed) v2 = varoftype(lltype.Signed) op = SpaceOperation("int_abs", [v1], v2) tr = Transformer(FakeCPU(), FakeRegularCallControl()) tr.graph = "somemaingraph" oplist = tr.rewrite_operation(op) assert oplist[0].opname == "inline_call_ir_i" assert oplist[0].args[0] == "somejitcode"
def direct_call_test(argtypes, restype, expectedkind): op = get_direct_call_op(argtypes, restype) tr = Transformer(FakeCPU(), FakeRegularCallControl()) tr.graph = "someinitialgraph" oplist = tr.rewrite_operation(op) op0, op1 = oplist reskind = getkind(restype)[0] assert op0.opname == "inline_call_%s_%s" % (expectedkind, reskind) assert op0.result == op.result assert op0.args[0] == "somejitcode" assert len(op0.args) == 1 + len(expectedkind) for sublist, kind1 in zip(op0.args[1:], expectedkind): assert sublist.kind.startswith(kind1) assert list(sublist) == [v for v in op.args[1:] if getkind(v.concretetype) == sublist.kind] for v in op.args[1:]: kind = getkind(v.concretetype) assert kind == "void" or kind[0] in expectedkind assert op1.opname == "-live-" assert op1.args == []
def test_quasi_immutable_setfield(): from rpython.rtyper.rclass import FieldListAccessor, IR_QUASIIMMUTABLE accessor = FieldListAccessor() accessor.initialize(None, {"inst_x": IR_QUASIIMMUTABLE}) v1 = varoftype(lltype.Signed) STRUCT = lltype.GcStruct( "struct", ("inst_x", lltype.Signed), ("mutate_x", rclass.OBJECTPTR), hints={"immutable_fields": accessor} ) for v_x in [const(lltype.malloc(STRUCT)), varoftype(lltype.Ptr(STRUCT))]: op = SpaceOperation( "jit_force_quasi_immutable", [v_x, Constant("mutate_x", lltype.Void)], varoftype(lltype.Void) ) tr = Transformer(FakeCPU(), FakeRegularCallControl()) tr.graph = "currentgraph" op0, op1 = tr.rewrite_operation(op) assert op0.opname == "-live-" assert op1.opname == "jit_force_quasi_immutable" assert op1.args[0] == v_x assert op1.args[1] == ("fielddescr", STRUCT, "mutate_x")
def indirect_regular_call_test(argtypes, restype, expectedkind): # a regular indirect call is preceded by a guard_value on the # function address, so that pyjitpl can know which jitcode to follow from rpython.jit.codewriter.flatten import IndirectCallTargets op = get_direct_call_op(argtypes, restype) op.opname = "indirect_call" op.args[0] = varoftype(op.args[0].concretetype) op.args.append(Constant(["somegraph1", "somegraph2"], lltype.Void)) tr = Transformer(FakeCPU(), FakeRegularIndirectCallControl()) tr.graph = "someinitialgraph" oplist = tr.rewrite_operation(op) op0gv, op1gv, op0, op1 = oplist assert op0gv.opname == "-live-" assert op0gv.args == [] assert op1gv.opname == "int_guard_value" assert op1gv.args == [op.args[0]] assert op1gv.result is None # reskind = getkind(restype)[0] assert op0.opname == "residual_call_%s_%s" % (expectedkind, reskind) assert op0.result == op.result assert op0.args[0] == op.args[0] assert isinstance(op0.args[1], IndirectCallTargets) assert op0.args[1].lst == ["somejitcode1", "somejitcode2"] assert op0.args[-1] == "calldescr" assert len(op0.args) == 2 + len(expectedkind) + 1 for sublist, kind1 in zip(op0.args[2:-1], expectedkind): assert sublist.kind.startswith(kind1) assert list(sublist) == [v for v in op.args[1:] if getkind(v.concretetype) == sublist.kind] for v in op.args[1:]: kind = getkind(v.concretetype) assert kind == "void" or kind[0] in expectedkind # Note: we still expect a -live- here, even though canraise() returns # False, because this 'residual_call' will likely call further jitcodes # which can do e.g. guard_class or other stuff requiring anyway a -live-. assert op1.opname == "-live-" assert op1.args == []