def test_guess_call_kind_and_calls_from_graphs(): class portal_runner_obj: graph = object() class FakeJitDriverSD: portal_runner_ptr = portal_runner_obj g = object() g1 = object() cc = CallControl(jitdrivers_sd=[FakeJitDriverSD()]) cc.candidate_graphs = [g, g1] op = SpaceOperation('direct_call', [Constant(portal_runner_obj)], Variable()) assert cc.guess_call_kind(op) == 'recursive' op = SpaceOperation('direct_call', [Constant(object())], Variable()) assert cc.guess_call_kind(op) == 'residual' class funcptr: class graph: class func: oopspec = "spec" op = SpaceOperation('direct_call', [Constant(funcptr)], Variable()) assert cc.guess_call_kind(op) == 'builtin' class funcptr: graph = g op = SpaceOperation('direct_call', [Constant(funcptr)], Variable()) res = cc.graphs_from(op) assert res == [g] assert cc.guess_call_kind(op) == 'regular' class funcptr: graph = object() op = SpaceOperation('direct_call', [Constant(funcptr)], Variable()) res = cc.graphs_from(op) assert res is None assert cc.guess_call_kind(op) == 'residual' h = object() op = SpaceOperation('indirect_call', [Variable(), Constant([g, g1, h])], Variable()) res = cc.graphs_from(op) assert res == [g, g1] assert cc.guess_call_kind(op) == 'regular' op = SpaceOperation('indirect_call', [Variable(), Constant([h])], Variable()) res = cc.graphs_from(op) assert res is None assert cc.guess_call_kind(op) == 'residual'
def test_graphs_from_direct_call(): cc = CallControl() F = lltype.FuncType([], lltype.Signed) f = lltype.functionptr(F, 'f', graph='fgraph') v = varoftype(lltype.Signed) op = SpaceOperation('direct_call', [Constant(f, lltype.Ptr(F))], v) # lst = cc.graphs_from(op, {}.__contains__) assert lst is None # residual call # lst = cc.graphs_from(op, {'fgraph': True}.__contains__) assert lst == ['fgraph'] # normal call
def test_graphs_from_indirect_call(): cc = CallControl() F = lltype.FuncType([], lltype.Signed) v = varoftype(lltype.Signed) graphlst = ["f1graph", "f2graph"] op = SpaceOperation("indirect_call", [varoftype(lltype.Ptr(F)), Constant(graphlst, lltype.Void)], v) # lst = cc.graphs_from(op, {"f1graph": True, "f2graph": True}.__contains__) assert lst == ["f1graph", "f2graph"] # normal indirect call # lst = cc.graphs_from(op, {"f1graph": True}.__contains__) assert lst == ["f1graph"] # indirect call, look only inside some graphs # lst = cc.graphs_from(op, {}.__contains__) assert lst is None # indirect call, don't look inside any graph
def test_graphs_from_no_target(): cc = CallControl() F = lltype.FuncType([], lltype.Signed) v = varoftype(lltype.Signed) op = SpaceOperation("indirect_call", [varoftype(lltype.Ptr(F)), Constant(None, lltype.Void)], v) lst = cc.graphs_from(op, {}.__contains__) assert lst is None