def test_inline2(self): harder = """ int callee(int i) { (void) print(i); while (i < 10) { i = i + 1; return i * 2; } return i; } int caller() { int x = 4; while (x < 10) { (void) print(x); x = call(callee, list(x)); } return x; } """ mod = from_c(harder) func = mod.get_function("caller") verify(func) result = interp.run(func) [callsite] = findallops(func, 'call') inline.inline(func, callsite) cfa.run(func) verify(func)
def test_inline2(self): harder = textwrap.dedent(""" int callee(int i) { (void) print(i); while (i < 10) { i = i + 1; return i * 2; } return i; } int caller() { int x = 4; while (x < 10) { (void) print(x); x = call(callee, list(x)); } return x; } """) mod = from_c(harder) func = mod.get_function("caller") verify(func) result = interp.run(func) [callsite] = findallops(func, 'call') inline.inline(func, callsite) cfa.run(func) verify(func)
def test_inline2(self): harder = textwrap.dedent(""" int callee(int i) { (void) print(i); while (i < 10) { i = i + 1; return i * 2; } return i; } int caller() { int x = 4; while (x < 10) { (void) print(x); x = call(callee, list(x)); } return x; } """) mod = from_c(harder) func = mod.get_function("caller") verify(func) result = interp.run(func) [callsite] = findallops(func, 'call') inline.inline(func, callsite) cfa.run(func) verify(func) # TODO: update phi when splitting blocks result2 = interp.run(func) assert result == result2
def test_inline(self): simple = """ #include <pykit_ir.h> int callee(int i) { return i * i; } int caller(int i) { int x = call(callee, list(i)); return x; } """ mod = from_c(simple) func = mod.get_function("caller") [callsite] = findallops(func, 'call') inline.inline(func, callsite) cfa.run(func) verify(func) assert interp.run(func, args=[10]) == 100 assert len(list(func.blocks)) == 1 assert opcodes(func) == ['mul', 'ret']
def test_inline(self): simple = textwrap.dedent(""" #include <pykit_ir.h> int callee(int i) { return i * i; } int caller(int i) { int x = call(callee, list(i)); return x; } """) mod = from_c(simple) func = mod.get_function("caller") [callsite] = findallops(func, 'call') inline.inline(func, callsite) cfa.run(func) verify(func) assert interp.run(func, args=[10]) == 100 assert len(list(func.blocks)) == 1 assert opcodes(func) == ['mul', 'ret']
def test_inline(self): simple = textwrap.dedent(""" #include <pykit_ir.h> int callee(int i) { return i * i; } int caller(int i) { int x = call(callee, list(i)); return x; } """) mod = from_c(simple) func = mod.get_function("caller") [callsite] = findallops(func, 'call') inline.inline(func, callsite) cfa.run(func) verify(func) assert interp.run(func, args=[10]) == 100 assert len(list(func.blocks)) == 1 self.assertEqual([o for o in opcodes(func) if o != 'convert'], ['mul', 'ret'])
def inliner(func, env): """ Inline numba functions with 'inline=True' """ envs = env['numba.state.envs'] for op in func.ops: if op.opcode == 'call': # See if we are messaging a static receiver f, args = op.args if isinstance(f, Function): # See if `f` was defined with `inline=True` e = envs[f] options = e['numba.state.options'] if options.get('inline'): valuemap = inline.inline(func, op) update_context(env, e, valuemap)
def inline_callee(func, call, env, callee_env): valuemap = inline.inline(func, call) update_context(env, callee_env, valuemap) return valuemap