def test_optimize_method(): def fn(n): if n > 0: x = B(n) else: x = C(n) return x.meth(100) interp, graph = get_interpreter(fn, [-1000], taggedpointers=True) t = interp.typer.annotator.translator t.config.translation.backendopt.constfold = True backend_optimizations(t) if option.view: t.view() LLFrame = interp.frame_class class MyFrame(LLFrame): def op_indirect_call(self, f, *args): raise AssertionError("this call should be optimized away") interp.frame_class = MyFrame res = interp.eval_graph(graph, [-1000]) assert res == -897
def test_constfold(): layoutbuilder = TypeLayoutBuilder(FakeGC) tid1 = layoutbuilder.get_type_id(GC_A) tid2 = layoutbuilder.get_type_id(GC_S3) class MockGC: def set_query_functions(self, is_varsize, has_gcptr_in_varsize, is_gcarrayofgcptr, *rest): self.is_varsize = is_varsize self.has_gcptr_in_varsize = has_gcptr_in_varsize self.is_gcarrayofgcptr = is_gcarrayofgcptr gc = MockGC() layoutbuilder.initialize_gc_query_function(gc) # def f(): return (1 * gc.is_varsize(tid1) + 10 * gc.has_gcptr_in_varsize(tid1) + 100 * gc.is_gcarrayofgcptr(tid1) + 1000 * gc.is_varsize(tid2) + 10000 * gc.has_gcptr_in_varsize(tid2) + 100000 * gc.is_gcarrayofgcptr(tid2)) interp, graph = get_interpreter(f, [], backendopt=True) assert interp.eval_graph(graph, []) == 11001 assert graph.startblock.exits[0].args == [Constant(11001, lltype.Signed)]
def test_constfold(): layoutbuilder = TypeLayoutBuilder(FakeGC) tid1 = layoutbuilder.get_type_id(GC_A) tid2 = layoutbuilder.get_type_id(GC_S3) class MockGC: def set_query_functions(self, is_varsize, has_gcptr_in_varsize, is_gcarrayofgcptr, *rest): self.is_varsize = is_varsize self.has_gcptr_in_varsize = has_gcptr_in_varsize self.is_gcarrayofgcptr = is_gcarrayofgcptr gc = MockGC() layoutbuilder.initialize_gc_query_function(gc) # def f(): return (1 * gc.is_varsize(tid1) + 10 * gc.has_gcptr_in_varsize(tid1) + 100 * gc.is_gcarrayofgcptr(tid1) + 1000 * gc.is_varsize(tid2) + 10000 * gc.has_gcptr_in_varsize(tid2) + 100000 * gc.is_gcarrayofgcptr(tid2)) interp, graph = get_interpreter(f, [], backendopt=True) assert interp.eval_graph(graph, []) == 11001 assert graph.startblock.exits[0].args == [Constant(11001, lltype.Signed)]
def interpret(func, values): interp, graph = get_interpreter(func, values) t = interp.typer.annotator.translator if t not in _already_transformed: etrafo = exceptiontransform.ExceptionTransformer(t) etrafo.transform_completely() _already_transformed[t] = True return interp.eval_graph(graph, values)
def interpret(func, values): interp, graph = get_interpreter(func, values) t = interp.typer.annotator.translator if t not in _already_transformed: etrafo = exceptiontransform.ExceptionTransformer(t) etrafo.transform_completely() _already_transformed[t] = True return interp.eval_graph(graph, values)
def interpret(self, fn, args): interp, graph = get_interpreter(fn, args, view=False, viewbefore=False, type_system=self.type_system) if option.view: interp.typer.annotator.translator.view() build_trees(graph) if option.view: interp.typer.annotator.translator.view() return interp.eval_graph(graph, args)
def interpret(func, values, view=False, viewbefore=False, policy=None): interp, graph = get_interpreter(func, values, view, viewbefore, policy, type_system='ootype') for g in interp.typer.annotator.translator.graphs: check_only_ootype(g) return interp.eval_graph(graph, values)
def interpret(self, fn, args): interp, graph = get_interpreter(fn, args, view=False, viewbefore=False, type_system=self.type_system) if option.view: interp.typer.annotator.translator.view() build_trees(graph) if option.view: interp.typer.annotator.translator.view() return interp.eval_graph(graph, args)
def ll_meta_interp(function, args, backendopt=False, listcomp=False, translationoptions={}, **kwds): if listcomp: extraconfigopts = {'translation.list_comprehension_operations': True} else: extraconfigopts = {} for key, value in translationoptions.items(): extraconfigopts['translation.' + key] = value interp, graph = get_interpreter(function, args, backendopt=False, # will be done below **extraconfigopts) clear_tcache() return jittify_and_run(interp, graph, args, backendopt=backendopt, **kwds)
def run_debug(argv): from rpython.rtyper.test.test_llinterp import get_interpreter # first annotate and rtype try: interp, graph = get_interpreter(entry_point, [], backendopt=False, #config=config, #type_system=config.translation.type_system, policy=Policy()) except Exception, e: print '%s: %s' % (e.__class__, e) pdb.post_mortem(sys.exc_info()[2]) raise
def run_debug(argv): from rpython.rtyper.test.test_llinterp import get_interpreter # first annotate and rtype try: interp, graph = get_interpreter(entry_point, [], backendopt=False, #config=config, #type_system=config.translation.type_system, policy=Policy()) except Exception, e: print '%s: %s' % (e.__class__, e) pdb.post_mortem(sys.exc_info()[2]) raise
def test_run_translation(): from pypy.tool.ann_override import PyPyAnnotatorPolicy from rpython.rtyper.test.test_llinterp import get_interpreter # first annotate and rtype try: interp, graph = get_interpreter(entry_point, [], backendopt=False, config=config, policy=PyPyAnnotatorPolicy(space)) except Exception, e: print '%s: %s' % (e.__class__, e) pdb.post_mortem(sys.exc_info()[2]) raise
def test_run_translation(): from pypy.tool.ann_override import PyPyAnnotatorPolicy from rpython.rtyper.test.test_llinterp import get_interpreter # first annotate and rtype try: interp, graph = get_interpreter(entry_point, [], backendopt=False, config=config, policy=PyPyAnnotatorPolicy(space)) except Exception, e: print '%s: %s' % (e.__class__, e) pdb.post_mortem(sys.exc_info()[2]) raise
def ll_meta_interp(function, args, backendopt=False, type_system='lltype', listcomp=False, translationoptions={}, **kwds): if listcomp: extraconfigopts = {'translation.list_comprehension_operations': True} else: extraconfigopts = {} for key, value in translationoptions.items(): extraconfigopts['translation.' + key] = value interp, graph = get_interpreter(function, args, backendopt=False, # will be done below type_system=type_system, **extraconfigopts) clear_tcache() return jittify_and_run(interp, graph, args, backendopt=backendopt, **kwds)
def get_runner(f, exceptedop, types): values = [t() for t in types] interp, graph = get_interpreter(f, values) for op in support.graph_operations(graph): if op.opname == exceptedop: break else: assert False, "op %r not found!"%(exceptedop,) t = interp.typer.annotator.translator # FIIISH! raisingop2direct_call.raisingop2direct_call(t, [graph]) def ret(*args): assert map(type, args) == types return interp.eval_graph(graph, args) return ret
def test_run_translation(): from rpython.rtyper.test.test_llinterp import get_interpreter from rpython.translator.goal import unixcheckpoint from rpython.config.translationoption import get_combined_translation_config from rpython.config.translationoption import set_opt_level config = get_combined_translation_config(translating=True) config.translation.gc = 'boehm' set_opt_level(config, level='jit') config.translation.backendopt.inline_threshold = 0.1 try: interp, graph = get_interpreter(run, [], backendopt=False, config=config) except Exception, e: print '%s: %s' % (e.__class__, e) pdb.post_mortem(sys.exc_info()[2]) raise
def test_run_translation(): from rpython.rtyper.test.test_llinterp import get_interpreter from rpython.translator.goal import unixcheckpoint from rpython.config.translationoption import get_combined_translation_config from rpython.config.translationoption import set_opt_level config = get_combined_translation_config(translating=True) config.translation.gc = 'boehm' set_opt_level(config, level='jit') config.translation.backendopt.inline_threshold = 0.1 try: interp, graph = get_interpreter(run, [], backendopt=False, config=config) except Exception, e: print '%s: %s' % (e.__class__, e) pdb.post_mortem(sys.exc_info()[2]) raise
def test_untagged_subclasses(): def g(x): return x.attrvalue # should not produce a call to ll_unboxed_getclass def fn(n): y = C(12) if n > 0: x = B(5) else: x = D(5) return g(x) interp, graph = get_interpreter(fn, [-1000], taggedpointers=True) t = interp.typer.annotator.translator ggraph = graphof(t, g) assert summary(ggraph) == {'cast_pointer': 2, 'getfield': 2} res = interp.eval_graph(graph, [-1000]) assert res == 68 res = interp.eval_graph(graph, [3]) assert res == 66
def test_run_translation(): from pypy.tool.ann_override import PyPyAnnotatorPolicy from rpython.rtyper.test.test_llinterp import get_interpreter # first annotate and rtype try: interp, graph = get_interpreter(entry_point, [], backendopt=False, config=config, policy=PyPyAnnotatorPolicy(space)) except Exception as e: print '%s: %s' % (e.__class__, e) pdb.post_mortem(sys.exc_info()[2]) raise # parent process loop: spawn a child, wait for the child to finish, # print a message, and restart unixcheckpoint.restartable_point(auto='run') from rpython.jit.codewriter.codewriter import CodeWriter CodeWriter.debug = True from pypy.tool.pypyjit_child import run_child run_child(globals(), locals())
def test_optimize_method(): def fn(n): if n > 0: x = B(n) else: x = C(n) return x.meth(100) interp, graph = get_interpreter(fn, [-1000], taggedpointers=True) t = interp.typer.annotator.translator t.config.translation.backendopt.constfold = True backend_optimizations(t) if option.view: t.view() LLFrame = interp.frame_class class MyFrame(LLFrame): def op_indirect_call(self, f, *args): raise AssertionError("this call should be optimized away") interp.frame_class = MyFrame res = interp.eval_graph(graph, [-1000]) assert res == -897
def test_untagged_subclasses(): def g(x): return x.attrvalue # should not produce a call to ll_unboxed_getclass def fn(n): y = C(12) if n > 0: x = B(5) else: x = D(5) return g(x) interp, graph = get_interpreter(fn, [-1000], taggedpointers=True) t = interp.typer.annotator.translator ggraph = graphof(t, g) assert summary(ggraph) == {'cast_pointer': 2, 'getfield': 2} res = interp.eval_graph(graph, [-1000]) assert res == 68 res = interp.eval_graph(graph, [3]) assert res == 66
def test_run_translation(): from pypy.tool.ann_override import PyPyAnnotatorPolicy from rpython.rtyper.test.test_llinterp import get_interpreter # first annotate and rtype try: interp, graph = get_interpreter(entry_point, [], backendopt=False, config=config, policy=PyPyAnnotatorPolicy(space)) except Exception as e: print '%s: %s' % (e.__class__, e) pdb.post_mortem(sys.exc_info()[2]) raise # parent process loop: spawn a child, wait for the child to finish, # print a message, and restart unixcheckpoint.restartable_point(auto='run') from rpython.jit.codewriter.codewriter import CodeWriter CodeWriter.debug = True from pypy.tool.pypyjit_child import run_child run_child(globals(), locals())
def interpret(self, func, values, **kwds): interp, graph = get_interpreter(func, values, **kwds) gcwrapper.prepare_graphs_and_create_gc(interp, self.GCClass, self.GC_PARAMS) return interp.eval_graph(graph, values)
def interpret(self, func, values, **kwds): interp, graph = get_interpreter(func, values, **kwds) gcwrapper.prepare_graphs_and_create_gc(interp, self.GCClass, self.GC_PARAMS) return interp.eval_graph(graph, values)
def interpret(func, values, view=False, viewbefore=False, policy=None): interp, graph = get_interpreter(func, values, view, viewbefore, policy, type_system="ootype") for g in interp.typer.annotator.translator.graphs: check_only_ootype(g) return interp.eval_graph(graph, values)