def test_bridge_from_interpreter_4(self): jitdriver = JitDriver(reds = ['n', 'k'], greens = []) def f(n, k): while n > 0: jitdriver.can_enter_jit(n=n, k=k) jitdriver.jit_merge_point(n=n, k=k) if k: n -= 2 else: n -= 1 return n + k from pypy.rpython.test.test_llinterp import get_interpreter, clear_tcache from pypy.jit.metainterp.warmspot import WarmRunnerDesc interp, graph = get_interpreter(f, [0, 0], backendopt=False, inline_threshold=0, type_system=self.type_system) clear_tcache() translator = interp.typer.annotator.translator translator.config.translation.gc = "boehm" warmrunnerdesc = WarmRunnerDesc(translator, CPUClass=self.CPUClass) warmrunnerdesc.state.set_param_threshold(3) # for tests warmrunnerdesc.state.set_param_trace_eagerness(0) # for tests warmrunnerdesc.finish() for n, k in [(20, 0), (20, 1)]: interp.eval_graph(graph, [n, k])
def meta_interp( self, function, args, repeat=1, inline=False, trace_limit=sys.maxint, backendopt=None, listcomp=False, **kwds ): # XXX ignored from pypy.jit.metainterp.warmspot import WarmRunnerDesc from pypy.annotation.listdef import s_list_of_strings from pypy.annotation import model as annmodel for arg in args: assert is_valid_int(arg) self.pre_translation_hook() t = self._get_TranslationContext() t.config.translation.type_system = self.type_system # force typesystem-specific options if listcomp: t.config.translation.list_comprehension_operations = True arglist = ", ".join(["int(argv[%d])" % (i + 1) for i in range(len(args))]) if len(args) == 1: arglist += "," arglist = "(%s)" % arglist if repeat != 1: src = py.code.Source( """ def entry_point(argv): args = %s res = function(*args) for k in range(%d - 1): res = function(*args) print res return 0 """ % (arglist, repeat) ) else: src = py.code.Source( """ def entry_point(argv): args = %s res = function(*args) print res return 0 """ % (arglist,) ) exec src.compile() in locals() t.buildannotator().build_types(function, [int] * len(args), main_entry_point=True) t.buildrtyper(type_system=self.type_system).specialize() warmrunnerdesc = WarmRunnerDesc(t, translate_support_code=True, CPUClass=self.CPUClass, **kwds) for jd in warmrunnerdesc.jitdrivers_sd: jd.warmstate.set_param_threshold(3) # for tests jd.warmstate.set_param_trace_eagerness(2) # for tests jd.warmstate.set_param_trace_limit(trace_limit) jd.warmstate.set_param_inlining(inline) jd.warmstate.set_param_enable_opts(ALL_OPTS_NAMES) mixlevelann = warmrunnerdesc.annhelper entry_point_graph = mixlevelann.getgraph(entry_point, [s_list_of_strings], annmodel.SomeInteger()) warmrunnerdesc.finish() self.post_translation_hook() return self._compile_and_run(t, entry_point, entry_point_graph, args)
def test_bridge_from_interpreter_4(self): jitdriver = JitDriver(reds=['n', 'k'], greens=[]) def f(n, k): while n > 0: jitdriver.can_enter_jit(n=n, k=k) jitdriver.jit_merge_point(n=n, k=k) if k: n -= 2 else: n -= 1 return n + k from pypy.rpython.test.test_llinterp import get_interpreter, clear_tcache from pypy.jit.metainterp.warmspot import WarmRunnerDesc interp, graph = get_interpreter(f, [0, 0], backendopt=False, inline_threshold=0, type_system=self.type_system) clear_tcache() translator = interp.typer.annotator.translator translator.config.translation.gc = "boehm" warmrunnerdesc = WarmRunnerDesc(translator, CPUClass=self.CPUClass) warmrunnerdesc.state.set_param_threshold(3) # for tests warmrunnerdesc.state.set_param_trace_eagerness(0) # for tests warmrunnerdesc.finish() for n, k in [(20, 0), (20, 1)]: interp.eval_graph(graph, [n, k])
def meta_interp(self, function, args, repeat=1, inline=False, trace_limit=sys.maxint, backendopt=None, listcomp=False, **kwds): # XXX ignored from pypy.jit.metainterp.warmspot import WarmRunnerDesc from pypy.annotation.listdef import s_list_of_strings from pypy.annotation import model as annmodel for arg in args: assert isinstance(arg, int) self.pre_translation_hook() t = self._get_TranslationContext() t.config.translation.type_system = self.type_system # force typesystem-specific options if listcomp: t.config.translation.list_comprehension_operations = True arglist = ", ".join( ['int(argv[%d])' % (i + 1) for i in range(len(args))]) if len(args) == 1: arglist += ',' arglist = '(%s)' % arglist if repeat != 1: src = py.code.Source(""" def entry_point(argv): args = %s res = function(*args) for k in range(%d - 1): res = function(*args) print res return 0 """ % (arglist, repeat)) else: src = py.code.Source(""" def entry_point(argv): args = %s res = function(*args) print res return 0 """ % (arglist, )) exec src.compile() in locals() t.buildannotator().build_types(function, [int] * len(args)) t.buildrtyper(type_system=self.type_system).specialize() warmrunnerdesc = WarmRunnerDesc(t, translate_support_code=True, CPUClass=self.CPUClass, **kwds) warmrunnerdesc.state.set_param_threshold(3) # for tests warmrunnerdesc.state.set_param_trace_eagerness(2) # for tests warmrunnerdesc.state.set_param_trace_limit(trace_limit) warmrunnerdesc.state.set_param_inlining(inline) warmrunnerdesc.state.set_param_optimizer(OPTIMIZER_FULL) mixlevelann = warmrunnerdesc.annhelper entry_point_graph = mixlevelann.getgraph(entry_point, [s_list_of_strings], annmodel.SomeInteger()) warmrunnerdesc.finish() self.post_translation_hook() return self._compile_and_run(t, entry_point, entry_point_graph, args)