示例#1
0
    def __init__(self,
                 translator,
                 policy=None,
                 backendopt=True,
                 CPUClass=None,
                 ProfilerClass=EmptyProfiler,
                 **kwds):
        pyjitpl._warmrunnerdesc = self  # this is a global for debugging only!
        self.set_translator(translator)
        self.memory_manager = memmgr.MemoryManager()
        self.build_cpu(CPUClass, **kwds)
        self.inline_inlineable_portals()
        self.find_portals()
        self.codewriter = codewriter.CodeWriter(self.cpu, self.jitdrivers_sd)
        if policy is None:
            policy = JitPolicy()
        policy.set_supports_floats(self.cpu.supports_floats)
        policy.set_supports_longlong(self.cpu.supports_longlong)
        policy.set_supports_singlefloats(self.cpu.supports_singlefloats)
        graphs = self.codewriter.find_all_graphs(policy)
        policy.dump_unsafe_loops()
        self.check_access_directly_sanity(graphs)
        if backendopt:
            self.prejit_optimizations(policy, graphs)
        elif self.opt.listops:
            self.prejit_optimizations_minimal_inline(policy, graphs)

        self.build_meta_interp(
            ProfilerClass, translator.config.translation.jit_opencoder_model)
        self.make_args_specifications()
        #
        from rpython.jit.metainterp.virtualref import VirtualRefInfo
        vrefinfo = VirtualRefInfo(self)
        self.codewriter.setup_vrefinfo(vrefinfo)
        #
        from rpython.jit.metainterp import counter
        if self.cpu.translate_support_code:
            self.jitcounter = counter.JitCounter(translator=translator)
        else:
            self.jitcounter = counter.DeterministicJitCounter()
        #
        self.hooks = policy.jithookiface
        self.make_virtualizable_infos()
        self.make_driverhook_graphs()
        self.make_enter_functions()
        self.rewrite_jit_merge_points(policy)

        verbose = False  # not self.cpu.translate_support_code
        self.rewrite_access_helpers()
        self.create_jit_entry_points()
        jitcodes = self.codewriter.make_jitcodes(verbose=verbose)
        self.metainterp_sd.jitcodes = jitcodes
        self.rewrite_can_enter_jits()
        self.rewrite_set_param_and_get_stats()
        self.rewrite_force_virtual(vrefinfo)
        self.rewrite_jitcell_accesses()
        self.rewrite_force_quasi_immutable()
        self.add_finish()
        self.metainterp_sd.finish_setup(self.codewriter)
示例#2
0
def test_without_floats():
    graph = support.getgraph(lambda x: x + 3.2, [5.4])
    policy = JitPolicy()
    policy.set_supports_floats(True)
    assert policy.look_inside_graph(graph)
    policy = JitPolicy()
    policy.set_supports_floats(False)
    assert not policy.look_inside_graph(graph)
示例#3
0
def jitpolicy(self):
    if "PythonPlugin" in system.optional_plugins:
        from pypy.module.pypyjit.policy import PyPyJitPolicy
        from pypy.module.pypyjit.hooks import pypy_hooks
        return PyPyJitPolicy(pypy_hooks)
    elif "JitHooks" in system.optional_plugins:
        from rsqueakvm.plugins.vmdebugging.hooks import jitiface
        return JitPolicy(jitiface)
    else:
        return JitPolicy()
示例#4
0
    def test_trace_next_iteration_hash(self):
        driver = JitDriver(greens=['s'], reds=['i'], name="name")

        class Hashes(object):
            check = False

            def __init__(self):
                self.l = []
                self.t = []

        hashes = Hashes()

        class Hooks(JitHookInterface):
            def before_compile(self, debug_info):
                pass

            def after_compile(self, debug_info):
                for op in debug_info.operations:
                    if op.is_guard():
                        hashes.l.append(op.getdescr().get_jitcounter_hash())

            def before_compile_bridge(self, debug_info):
                pass

            def after_compile_bridge(self, debug_info):
                hashes.t.append(debug_info.fail_descr.get_jitcounter_hash())

        hooks = Hooks()

        @dont_look_inside
        def foo():
            if hashes.l:
                for item in hashes.l:
                    jit_hooks.trace_next_iteration_hash("name", item)

        def loop(i, s):
            while i > 0:
                driver.jit_merge_point(s=s, i=i)
                foo()
                if i == 3:
                    i -= 1
                i -= 1

        def main(s, check):
            hashes.check = check
            loop(10, s)

        self.meta_interp(main, [1, 0], policy=JitPolicy(hooks))
        assert len(hashes.l) == 4
        assert len(hashes.t) == 0
        self.meta_interp(main, [1, 1], policy=JitPolicy(hooks))
        assert len(hashes.t) == 1
示例#5
0
    def __init__(self, translator, policy=None, backendopt=True, CPUClass=None,
                 ProfilerClass=EmptyProfiler, **kwds):
        pyjitpl._warmrunnerdesc = self   # this is a global for debugging only!
        self.set_translator(translator)
        self.memory_manager = memmgr.MemoryManager()
        self.build_cpu(CPUClass, **kwds)
        self.inline_inlineable_portals()
        self.find_portals()
        self.codewriter = codewriter.CodeWriter(self.cpu, self.jitdrivers_sd)
        if policy is None:
            policy = JitPolicy()
        policy.set_supports_floats(self.cpu.supports_floats)
        policy.set_supports_longlong(self.cpu.supports_longlong)
        policy.set_supports_singlefloats(self.cpu.supports_singlefloats)
        graphs = self.codewriter.find_all_graphs(policy)
        policy.dump_unsafe_loops()
        self.check_access_directly_sanity(graphs)
        if backendopt:
            self.prejit_optimizations(policy, graphs)
        elif self.opt.listops:
            self.prejit_optimizations_minimal_inline(policy, graphs)

        self.build_meta_interp(ProfilerClass,
                             translator.config.translation.jit_opencoder_model)
        self.make_args_specifications()
        #
        from rpython.jit.metainterp.virtualref import VirtualRefInfo
        vrefinfo = VirtualRefInfo(self)
        self.codewriter.setup_vrefinfo(vrefinfo)
        #
        from rpython.jit.metainterp import counter
        if self.cpu.translate_support_code:
            self.jitcounter = counter.JitCounter(translator=translator)
        else:
            self.jitcounter = counter.DeterministicJitCounter()
        #
        self.hooks = policy.jithookiface
        self.make_virtualizable_infos()
        self.make_driverhook_graphs()
        self.make_enter_functions()
        self.rewrite_jit_merge_points(policy)

        verbose = False # not self.cpu.translate_support_code
        self.rewrite_access_helpers()
        self.create_jit_entry_points()
        jitcodes = self.codewriter.make_jitcodes(verbose=verbose)
        self.metainterp_sd.jitcodes = jitcodes
        self.rewrite_can_enter_jits()
        self.rewrite_set_param_and_get_stats()
        self.rewrite_force_virtual(vrefinfo)
        self.rewrite_jitcell_accesses()
        self.rewrite_force_quasi_immutable()
        self.add_finish()
        self.metainterp_sd.finish_setup(self.codewriter)
示例#6
0
def test_without_floats():
    graph = support.getgraph(lambda x: x+3.2, [5.4])
    policy = JitPolicy()
    policy.set_supports_floats(True)
    assert policy.look_inside_graph(graph)
    policy = JitPolicy()
    policy.set_supports_floats(False)
    assert not policy.look_inside_graph(graph)
示例#7
0
def jitpolicy(driver):
    try:
        from rpython.jit.codewriter.policy import JitPolicy
        return JitPolicy()
    except ImportError:
        raise NotImplemented(
            "Abandon if we are unable to use RPython's JitPolicy")
示例#8
0
def test_dont_look_inside():
    @jit.dont_look_inside
    def h(x):
        return x + 3

    graph = support.getgraph(h, [5])
    assert not JitPolicy().look_inside_graph(graph)
示例#9
0
def test_elidable():
    @jit.elidable
    def g(x):
        return x + 2

    graph = support.getgraph(g, [5])
    assert not JitPolicy().look_inside_graph(graph)
示例#10
0
    def test_on_compile_bridge(self):
        called = []

        class MyJitIface(JitHookInterface):
            def after_compile(self, di):
                called.append("compile")

            def after_compile_bridge(self, di):
                called.append("compile_bridge")

            def before_compile_bridge(self, di):
                called.append("before_compile_bridge")

        driver = JitDriver(greens=['n', 'm'], reds=['i'])

        def loop(n, m):
            i = 0
            while i < n + m:
                driver.can_enter_jit(n=n, m=m, i=i)
                driver.jit_merge_point(n=n, m=m, i=i)
                if i >= 4:
                    i += 2
                i += 1

        self.meta_interp(loop, [1, 10], policy=JitPolicy(MyJitIface()))
        assert called == ["compile", "before_compile_bridge", "compile_bridge"]
示例#11
0
def test_loops():
    def g(x):
        i = 0
        while i < x:
            i += 1
        return i

    graph = support.getgraph(g, [5])
    assert not JitPolicy().look_inside_graph(graph)
示例#12
0
def test_unroll_safe():
    @jit.unroll_safe
    def h(x):
        i = 0
        while i < x:
            i += 1
        return i

    graph = support.getgraph(h, [5])
    assert JitPolicy().look_inside_graph(graph)
示例#13
0
文件: jithip.py 项目: youaani/hippyvm
def apply_jit(interp, graph, CPUClass):
    from rpython.jit.metainterp import warmspot

    print 'warmspot.jittify_and_run() started...'
    policy = JitPolicy()
    warmspot.jittify_and_run(interp,
                             graph, [],
                             policy=policy,
                             listops=True,
                             CPUClass=CPUClass,
                             backendopt=True,
                             inline=True)
示例#14
0
    def test_on_compile(self):
        called = []

        class MyJitIface(JitHookInterface):
            def after_compile(self, di):
                called.append(("compile", di.greenkey[1].getint(),
                               di.greenkey[0].getint(), di.type))

            def before_compile(self, di):
                called.append(("optimize", di.greenkey[1].getint(),
                               di.greenkey[0].getint(), di.type))

            #def before_optimize(self, jitdriver, logger, looptoken, oeprations,
            #                   type, greenkey):
            #    called.append(("trace", greenkey[1].getint(),
            #                   greenkey[0].getint(), type))

        iface = MyJitIface()

        driver = JitDriver(greens=['n', 'm'], reds=['i'])

        def loop(n, m):
            i = 0
            while i < n + m:
                driver.can_enter_jit(n=n, m=m, i=i)
                driver.jit_merge_point(n=n, m=m, i=i)
                i += 1

        self.meta_interp(loop, [1, 4], policy=JitPolicy(iface))
        assert called == [  #("trace", 4, 1, "loop"),
            ("optimize", 4, 1, "loop"), ("compile", 4, 1, "loop")
        ]
        self.meta_interp(loop, [2, 4], policy=JitPolicy(iface))
        assert called == [  #("trace", 4, 1, "loop"),
            ("optimize", 4, 1, "loop"),
            ("compile", 4, 1, "loop"),
            #("trace", 4, 2, "loop"),
            ("optimize", 4, 2, "loop"),
            ("compile", 4, 2, "loop")
        ]
示例#15
0
def jittest(driver):
    graph = driver.translator._graphof(driver.entry_point)
    interp = LLInterpreter(driver.translator.rtyper)

    get_policy = driver.extra.get('jitpolicy', None)
    if get_policy is None:
        from rpython.jit.codewriter.policy import JitPolicy
        jitpolicy = JitPolicy()
    else:
        jitpolicy = get_policy(driver)

    from rpython.jit.backend.llgraph.runner import LLGraphCPU
    apply_jit(jitpolicy, interp, graph, LLGraphCPU)
示例#16
0
def test_str_join():
    def f(x, y):
        return "hello".join([str(x), str(y), "bye"])

    graph = support.getgraph(f, [5, 83])
    for block in graph.iterblocks():
        for op in block.operations:
            if op.opname == 'direct_call':
                funcptr = op.args[0].value
                called_graph = funcptr._obj.graph
                if JitPolicy().look_inside_graph(called_graph):
                    # the calls to join() and str() should be residual
                    mod = called_graph.func.__module__
                    assert (mod == 'rpython.rtyper.rlist'
                            or mod == 'rpython.rtyper.lltypesystem.rlist')
示例#17
0
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)

    graph = support.getgraph(h, [5])
    assert JitPolicy().look_inside_graph(graph)
示例#18
0
文件: driver.py 项目: zcxowwww/pypy
 def task_pyjitpl_lltype(self):
     """ Generate bytecodes for JIT and flow the JIT helper functions
     lltype version
     """
     from rpython.jit.codewriter.policy import JitPolicy
     get_policy = self.extra.get('jitpolicy', None)
     if get_policy is None:
         self.jitpolicy = JitPolicy()
     else:
         self.jitpolicy = get_policy(self)
     #
     from rpython.jit.metainterp.warmspot import apply_jit
     apply_jit(self.translator, policy=self.jitpolicy,
               backend_name=self.config.translation.jit_backend, inline=True)
     #
     self.log.info("the JIT compiler was generated")
示例#19
0
def test_access_directly_but_not_seen():
    class X:
        _virtualizable_ = ["a"]

    def h(x, y):
        w = 0
        for i in range(y):
            w += 4
        return w

    def f(y):
        x = jit.hint(X(), access_directly=True)
        h(x, y)

    rtyper = support.annotate(f, [3])
    h_graph = rtyper.annotator.translator.graphs[1]
    assert h_graph.func is h
    py.test.raises(ValueError, JitPolicy().look_inside_graph, h_graph)
示例#20
0
    def test_abort_quasi_immut(self):
        reasons = []

        class MyJitIface(JitHookInterface):
            def on_abort(self, reason, jitdriver, greenkey, greenkey_repr,
                         logops, ops):
                assert jitdriver is myjitdriver
                assert len(greenkey) == 1
                reasons.append(reason)
                assert greenkey_repr == 'blah'
                assert len(ops) > 1

        iface = MyJitIface()

        myjitdriver = JitDriver(greens=['foo'],
                                reds=['x', 'total'],
                                get_printable_location=lambda *args: 'blah')

        class Foo:
            _immutable_fields_ = ['a?']

            def __init__(self, a):
                self.a = a

        def f(a, x):
            foo = Foo(a)
            total = 0
            while x > 0:
                myjitdriver.jit_merge_point(foo=foo, x=x, total=total)
                # read a quasi-immutable field out of a Constant
                total += foo.a
                foo.a += 1
                x -= 1
            return total

        #
        assert f(100, 7) == 721
        res = self.meta_interp(f, [100, 7], policy=JitPolicy(iface))
        assert res == 721
        assert reasons == [Counters.ABORT_FORCE_QUASIIMMUT] * 2
示例#21
0
    def test_one(self):
        py.test.skip("needs thread-locals in the JIT, which is only available "
                     "after translation")
        visited = []

        def helper():
            stack = cintf.vmprof_tl_stack.getraw()
            if stack:
                # not during tracing
                visited.append(stack.c_value)
            else:
                visited.append(0)

        llfn = llhelper(lltype.Ptr(lltype.FuncType([], lltype.Void)), helper)

        driver = jit.JitDriver(greens=[], reds='auto')

        def f(n):
            i = 0
            while i < n:
                driver.jit_merge_point()
                i += 1
                llfn()

        class Hooks(jit.JitHookInterface):
            def after_compile(self, debug_info):
                self.raw_start = debug_info.asminfo.rawstart

        hooks = Hooks()

        null = lltype.nullptr(cintf.VMPROFSTACK)
        cintf.vmprof_tl_stack.setraw(null)  # make it empty
        self.meta_interp(f, [10], policy=JitPolicy(hooks))
        v = set(visited)
        assert 0 in v
        v.remove(0)
        assert len(v) == 1
        assert 0 <= list(v)[0] - hooks.raw_start <= 10 * 1024
        assert cintf.vmprof_tl_stack.getraw() == null
示例#22
0
    def test_are_hooks_enabled(self):
        reasons = []

        class MyJitIface(JitHookInterface):
            def are_hooks_enabled(self):
                return False

            def on_abort(self, reason, jitdriver, greenkey, greenkey_repr,
                         logops, ops):
                reasons.append(reason)

        iface = MyJitIface()

        myjitdriver = JitDriver(greens=['foo'],
                                reds=['x', 'total'],
                                get_printable_location=lambda *args: 'blah')

        class Foo:
            _immutable_fields_ = ['a?']

            def __init__(self, a):
                self.a = a

        def f(a, x):
            foo = Foo(a)
            total = 0
            while x > 0:
                myjitdriver.jit_merge_point(foo=foo, x=x, total=total)
                total += foo.a
                foo.a += 1
                x -= 1
            return total

        #
        assert f(100, 7) == 721
        res = self.meta_interp(f, [100, 7], policy=JitPolicy(iface))
        assert res == 721
        assert reasons == []
示例#23
0
def jitpolicy(driver):
    return JitPolicy()
示例#24
0
def jitpolicy(driver):
    from rpython.jit.codewriter.policy import JitPolicy
    return JitPolicy()
示例#25
0
def jitpolicy(driver):
    return JitPolicy(jithookiface=DebugIFace())
示例#26
0
 def __init__(self):
     JitPolicy.__init__(self, DebugIFace())
示例#27
0
def jitpolicy(driver):
    return JitPolicy(TyphonJitHooks())
示例#28
0
def _get_jitcodes(testself,
                  CPUClass,
                  func,
                  values,
                  supports_floats=True,
                  supports_longlong=False,
                  supports_singlefloats=False,
                  translationoptions={},
                  **kwds):
    from rpython.jit.codewriter import support

    class FakeJitCell(object):
        __product_token = None

        def get_procedure_token(self):
            return self.__product_token

        def set_procedure_token(self, token):
            self.__product_token = token

    class FakeWarmRunnerState(object):
        def attach_procedure_to_interp(self, greenkey, procedure_token):
            assert greenkey == []
            self._cell.set_procedure_token(procedure_token)

        def helper_func(self, FUNCPTR, func):
            from rpython.rtyper.annlowlevel import llhelper
            return llhelper(FUNCPTR, func)

        def get_unique_id(self, *args):
            return 0

        def get_location_str(self, args):
            return 'location'

        class JitCell:
            @staticmethod
            def get_jit_cell_at_key(greenkey):
                assert greenkey == []
                return FakeWarmRunnerState._cell

        _cell = FakeJitCell()

        trace_limit = sys.maxint
        enable_opts = ALL_OPTS_DICT
        vec = True

    if kwds.pop('disable_optimizations', False):
        FakeWarmRunnerState.enable_opts = {}

    func._jit_unroll_safe_ = True
    rtyper = support.annotate(func,
                              values,
                              translationoptions=translationoptions)
    graphs = rtyper.annotator.translator.graphs
    testself.all_graphs = graphs
    result_kind = history.getkind(graphs[0].getreturnvar().concretetype)[0]

    class FakeJitDriverSD:
        num_green_args = 0
        portal_graph = graphs[0]
        virtualizable_info = None
        greenfield_info = None
        result_type = result_kind
        portal_runner_ptr = "???"
        vec = False

    stats = history.Stats(None)
    cpu = CPUClass(rtyper, stats, None, False)
    cw = codewriter.CodeWriter(cpu, [FakeJitDriverSD()])
    cw.debug = True
    testself.cw = cw
    if supports_floats and not cpu.supports_floats:
        py.test.skip("this test requires supports_floats=True")
    if supports_longlong and not cpu.supports_longlong:
        py.test.skip("this test requires supports_longlong=True")
    if supports_singlefloats and not cpu.supports_singlefloats:
        py.test.skip("this test requires supports_singlefloats=True")
    policy = JitPolicy()
    policy.set_supports_floats(supports_floats)
    policy.set_supports_longlong(supports_longlong)
    policy.set_supports_singlefloats(supports_singlefloats)
    graphs = cw.find_all_graphs(policy)
    if kwds.get("backendopt"):
        backend_optimizations(rtyper.annotator.translator, graphs=graphs)
    #
    testself.warmrunnerstate = FakeWarmRunnerState()
    testself.warmrunnerstate.cpu = cpu
    FakeJitDriverSD.warmstate = testself.warmrunnerstate
    if hasattr(testself, 'finish_setup_for_interp_operations'):
        testself.finish_setup_for_interp_operations()
    #
    cw.make_jitcodes(verbose=True)
    return stats
示例#29
0
文件: target.py 项目: gigasquid/pixie
 def __init__(self):
     JitPolicy.__init__(self, DebugIFace())
示例#30
0
def jitpolicy(self):
    return JitPolicy()
示例#31
0
文件: support.py 项目: mozillazg/pypy
def _get_jitcodes(testself, CPUClass, func, values,
                  supports_floats=True,
                  supports_longlong=False,
                  supports_singlefloats=False,
                  translationoptions={}, **kwds):
    from rpython.jit.codewriter import support

    class FakeJitCell(object):
        __product_token = None
        def get_procedure_token(self):
            return self.__product_token
        def set_procedure_token(self, token):
            self.__product_token = token

    class FakeWarmRunnerState(object):
        def attach_procedure_to_interp(self, greenkey, procedure_token):
            assert greenkey == []
            self._cell.set_procedure_token(procedure_token)

        def helper_func(self, FUNCPTR, func):
            from rpython.rtyper.annlowlevel import llhelper
            return llhelper(FUNCPTR, func)

        def get_unique_id(self, *args):
            return 0

        def get_location_str(self, args):
            return 'location'

        class JitCell:
            @staticmethod
            def get_jit_cell_at_key(greenkey):
                assert greenkey == []
                return FakeWarmRunnerState._cell
        _cell = FakeJitCell()

        trace_limit = sys.maxint
        enable_opts = ALL_OPTS_DICT
        vec = True

    if kwds.pop('disable_optimizations', False):
        FakeWarmRunnerState.enable_opts = {}

    func._jit_unroll_safe_ = True
    rtyper = support.annotate(func, values,
                              translationoptions=translationoptions)
    graphs = rtyper.annotator.translator.graphs
    testself.all_graphs = graphs
    result_kind = history.getkind(graphs[0].getreturnvar().concretetype)[0]


    class FakeJitDriver:
        name = 'fakejitdriver'

    class FakeJitDriverSD:
        num_green_args = 0
        portal_graph = graphs[0]
        virtualizable_info = None
        greenfield_info = None
        result_type = result_kind
        portal_runner_ptr = "???"
        vec = False
        jitdriver = FakeJitDriver()

    stats = history.Stats(None)
    cpu = CPUClass(rtyper, stats, None, False)
    cw = codewriter.CodeWriter(cpu, [FakeJitDriverSD()])
    cw.debug = True
    testself.cw = cw
    if supports_floats and not cpu.supports_floats:
        py.test.skip("this test requires supports_floats=True")
    if supports_longlong and not cpu.supports_longlong:
        py.test.skip("this test requires supports_longlong=True")
    if supports_singlefloats and not cpu.supports_singlefloats:
        py.test.skip("this test requires supports_singlefloats=True")
    policy = JitPolicy()
    policy.set_supports_floats(supports_floats)
    policy.set_supports_longlong(supports_longlong)
    policy.set_supports_singlefloats(supports_singlefloats)
    graphs = cw.find_all_graphs(policy)
    if kwds.get("backendopt"):
        backend_optimizations(rtyper.annotator.translator, graphs=graphs)
    #
    testself.warmrunnerstate = FakeWarmRunnerState()
    testself.warmrunnerstate.cpu = cpu
    FakeJitDriverSD.warmstate = testself.warmrunnerstate
    if hasattr(testself, 'finish_setup_for_interp_operations'):
        testself.finish_setup_for_interp_operations()
    #
    cw.make_jitcodes(verbose=True)
    return stats
示例#32
0
def jitpolicy(self):
    if "JitHooks" in system.optional_plugins:
        from rsqueakvm.plugins.vmdebugging.hooks import jitiface
        return JitPolicy(jitiface)
    else:
        return JitPolicy()
示例#33
0
def test_regular_function():
    graph = support.getgraph(lambda x: x + 3, [5])
    assert JitPolicy().look_inside_graph(graph)