コード例 #1
0
ファイル: test_codewriter.py プロジェクト: xx312022850/pypy
def test_find_all_graphs_loops():
    def g(x):
        i = 0
        while i < x:
            i += 1
        return i

    @jit.unroll_safe
    def h(x):
        i = 0
        while i < x:
            i += 1
        return i

    def f(x):
        i = 0
        while i < x * x:
            i += g(x) + h(x)
        return i

    rtyper = support.annotate(f, [7])
    cw = CodeWriter(rtyper)
    jitpolicy = JitPolicy()
    translator = rtyper.annotator.translator
    res = cw.find_all_graphs(translator.graphs[0],
                             None,
                             jitpolicy,
                             supports_floats=True)
    funcs = set([graph.func for graph in res])
    assert funcs == set([f, h])
コード例 #2
0
ファイル: test_codewriter.py プロジェクト: xx312022850/pypy
def test_find_all_graphs_without_floats():
    def g(x):
        return int(x * 12.5)

    def f(x):
        return g(x) + 1

    rtyper = support.annotate(f, [7])
    cw = CodeWriter(rtyper)
    jitpolicy = JitPolicy()
    translator = rtyper.annotator.translator
    res = cw.find_all_graphs(translator.graphs[0],
                             None,
                             jitpolicy,
                             supports_floats=True)
    funcs = set([graph.func for graph in res])
    assert funcs == set([f, g])

    cw = CodeWriter(rtyper)
    res = cw.find_all_graphs(translator.graphs[0],
                             None,
                             jitpolicy,
                             supports_floats=False)
    funcs = [graph.func for graph in res]
    assert funcs == [f]
コード例 #3
0
ファイル: test_codewriter.py プロジェクト: xx312022850/pypy
def test_find_all_graphs():
    def f(x):
        if x < 0:
            return f(-x)
        return x + 1

    @jit.purefunction
    def g(x):
        return x + 2

    @jit.dont_look_inside
    def h(x):
        return x + 3

    def i(x):
        return f(x) * g(x) * h(x)

    rtyper = support.annotate(i, [7])
    cw = CodeWriter(rtyper)
    jitpolicy = JitPolicy()
    res = cw.find_all_graphs(rtyper.annotator.translator.graphs[0], None,
                             jitpolicy, True)
    translator = rtyper.annotator.translator

    funcs = set([graph.func for graph in res])
    assert funcs == set([i, f])
コード例 #4
0
ファイル: test_codewriter.py プロジェクト: xx312022850/pypy
def test_find_all_graphs_str_join():
    def i(x, y):
        return "hello".join([str(x), str(y), "bye"])

    rtyper = support.annotate(i, [7, 100])
    cw = CodeWriter(rtyper)
    jitpolicy = JitPolicy()
    translator = rtyper.annotator.translator
    # does not explode
    cw.find_all_graphs(translator.graphs[0], None, jitpolicy, True)
コード例 #5
0
    def __init__(self, translator, policy=None, backendopt=True, CPUClass=None,
                 optimizer=None, **kwds):
        pyjitpl._warmrunnerdesc = self   # this is a global for debugging only!
        if policy is None:
            policy = JitPolicy()
        self.set_translator(translator)
        self.find_portal()
        self.make_leave_jit_graph()
        self.codewriter = codewriter.CodeWriter(self.rtyper)
        graphs = self.codewriter.find_all_graphs(self.portal_graph,
                                                 self.leave_graph,
                                                 policy,
                                                 CPUClass.supports_floats)
        policy.dump_unsafe_loops()
        self.check_access_directly_sanity(graphs)
        if backendopt:
            self.prejit_optimizations(policy, graphs)

        self.build_meta_interp(CPUClass, **kwds)
        self.make_args_specification()
        #
        from pypy.jit.metainterp.virtualref import VirtualRefInfo
        self.metainterp_sd.virtualref_info = VirtualRefInfo(self)
        if self.jitdriver.virtualizables:
            from pypy.jit.metainterp.virtualizable import VirtualizableInfo
            self.metainterp_sd.virtualizable_info = VirtualizableInfo(self)
        #
        self.make_exception_classes()
        self.make_driverhook_graphs()
        self.make_enter_function()
        self.rewrite_jit_merge_point(policy)
                
        self.codewriter.generate_bytecode(self.metainterp_sd,
                                          self.portal_graph,
                                          self.leave_graph,
                                          self.portal_runner_ptr
                                          )
        self.rewrite_can_enter_jit()
        self.rewrite_set_param()
        self.rewrite_force_virtual()
        self.add_finish()
        self.metainterp_sd.finish_setup(optimizer=optimizer)
コード例 #6
0
ファイル: test_basic.py プロジェクト: xx312022850/pypy
    def interp_operations(self, f, args, **kwds):
        from pypy.jit.metainterp import simple_optimize

        class DoneWithThisFrame(Exception):
            pass

        class DoneWithThisFrameRef(DoneWithThisFrame):
            def __init__(self, cpu, *args):
                DoneWithThisFrame.__init__(self, *args)

        class FakeWarmRunnerState:
            def attach_unoptimized_bridge_from_interp(self, greenkey, newloop):
                pass

            # pick the optimizer this way
            optimize_loop = staticmethod(simple_optimize.optimize_loop)
            optimize_bridge = staticmethod(simple_optimize.optimize_bridge)

            trace_limit = sys.maxint
            debug_level = 2

        metainterp, rtyper = _get_bare_metainterp(f, args, self.CPUClass,
                                                  self.type_system, **kwds)
        metainterp.staticdata.state = FakeWarmRunnerState()
        metainterp.staticdata.state.cpu = metainterp.staticdata.cpu
        if hasattr(self, 'finish_metainterp_for_interp_operations'):
            self.finish_metainterp_for_interp_operations(metainterp)
        portal_graph = rtyper.annotator.translator.graphs[0]
        cw = codewriter.CodeWriter(rtyper)

        graphs = cw.find_all_graphs(portal_graph, None, JitPolicy(),
                                    self.CPUClass.supports_floats)
        cw._start(metainterp.staticdata, None)
        portal_graph.func._jit_unroll_safe_ = True
        maingraph = cw.make_one_bytecode((portal_graph, None), False)
        cw.finish_making_bytecodes()
        metainterp.staticdata.portal_code = maingraph
        metainterp.staticdata._class_sizes = cw.class_sizes
        metainterp.staticdata.DoneWithThisFrameInt = DoneWithThisFrame
        metainterp.staticdata.DoneWithThisFrameRef = DoneWithThisFrameRef
        metainterp.staticdata.DoneWithThisFrameFloat = DoneWithThisFrame
        self.metainterp = metainterp
        try:
            metainterp.compile_and_run_once(*args)
        except DoneWithThisFrame, e:
            #if conftest.option.view:
            #    metainterp.stats.view()
            return e.args[0]
コード例 #7
0
ファイル: test_codewriter.py プロジェクト: xx312022850/pypy
def test_unroll_safe_and_inline():
    @jit.unroll_safe
    def h(x):
        i = 0
        while i < x:
            i += 1
        return i

    h._always_inline_ = True

    def g(x):
        return h(x)

    rtyper = support.annotate(g, [7])
    cw = CodeWriter(rtyper)
    jitpolicy = JitPolicy()
    translator = rtyper.annotator.translator
    res = cw.find_all_graphs(translator.graphs[0],
                             None,
                             jitpolicy,
                             supports_floats=True)
    funcs = set([graph.func for graph in res])
    assert funcs == set([g, h])
コード例 #8
0
 def jitpolicy(*args):
     from pypy.jit.metainterp.policy import JitPolicy
     return JitPolicy()
コード例 #9
0
def jitpolicy(driver):
    return JitPolicy()
コード例 #10
0
def jitpolicy(driver):
    from pypy.jit.metainterp.policy import JitPolicy
    return JitPolicy()
コード例 #11
0
ファイル: targettlc.py プロジェクト: xx312022850/pypy
def jitpolicy(driver):
    """Returns the JIT policy to use when translating."""
    return JitPolicy()