当前位置: 首页>>代码示例>>Python>>正文


Python all.backend_optimizations函数代码示例

本文整理汇总了Python中pypy.translator.backendopt.all.backend_optimizations函数的典型用法代码示例。如果您正苦于以下问题:Python backend_optimizations函数的具体用法?Python backend_optimizations怎么用?Python backend_optimizations使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了backend_optimizations函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: backend_optimize

 def backend_optimize(self, **flags):
     # only optimize the newly created graphs
     from pypy.translator.backendopt.all import backend_optimizations
     translator = self.rtyper.annotator.translator
     newgraphs = translator.graphs[self.original_graph_count:]
     self.original_graph_count = len(translator.graphs)
     backend_optimizations(translator, newgraphs, secondary=True, **flags)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:annlowlevel.py

示例2: _build_gen

def _build_gen(func, annotation, graph=None, backendopt=True):
    try: 
        func = func.im_func
    except AttributeError: 
        pass
    t = TranslationContext()
    if graph is not None:
        graph.func = func
        ann = t.buildannotator()
        inputcells = [ann.typeannotation(a) for a in annotation]
        ann.build_graph_types(graph, inputcells)
        t.graphs.insert(0, graph)
    else:
        ann = t.buildannotator()
        ann.build_types(func, annotation)

    if getoption('view'):
       t.view()

    t.buildrtyper(type_system="ootype").specialize()
    if backendopt:
        check_virtual_methods(ootype.ROOT)
        backend_optimizations(t)
    
    main_graph = t.graphs[0]

    if getoption('view'):
       t.view()

    if getoption('wd'):
        tmpdir = py.path.local('.')
    else:
        tmpdir = udir

    return GenCli(tmpdir, t, TestEntryPoint(main_graph, True))
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:35,代码来源:runtest.py

示例3: getcompiled

def getcompiled(func, view=conftest.option.view, use_boehm=False):
    from pypy.translator.translator import TranslationContext
    from pypy.translator.backendopt.all import backend_optimizations

    from pypy.translator.c import gc
    from pypy.translator.c.genc import CExtModuleBuilder

    global t # allow us to view later
    t = TranslationContext()
    t.buildannotator().build_types(func, get_annotation(func))
    t.buildrtyper().specialize()
    t.checkgraphs()

    gcpolicy = None
    if use_boehm:
        gcpolicy = gc.BoehmGcPolicy

    cbuilder = CExtModuleBuilder(t, func, t.config, gcpolicy=gcpolicy)
    cbuilder.generate_source()
    cbuilder.compile()

    backend_optimizations(t)
    if view:
        t.viewcg()
    return getattr(cbuilder.import_module(), func.__name__)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:25,代码来源:test_extension.py

示例4: _build_gen

def _build_gen(func, annotation, graph=None, backendopt=True, exctrans=False,
               annotatorpolicy=None, nowrap=False):
    try: 
        func = func.im_func
    except AttributeError: 
        pass
    t = TranslationContext()
    if graph is not None:
        graph.func = func
        ann = t.buildannotator(policy=annotatorpolicy)
        inputcells = [ann.typeannotation(a) for a in annotation]
        ann.build_graph_types(graph, inputcells)
        t.graphs.insert(0, graph)
    else:
        ann = t.buildannotator(policy=annotatorpolicy)
        ann.build_types(func, annotation)

    if getoption('view'):
       t.view()

    t.buildrtyper(type_system="ootype").specialize()
    if backendopt:
        check_virtual_methods(ootype.ROOT)
        backend_optimizations(t)
    
    main_graph = t.graphs[0]

    if getoption('view'):
       t.view()
       
    return _build_gen_from_graph(main_graph, t, exctrans, nowrap)
开发者ID:ieure,项目名称:pypy,代码行数:31,代码来源:runtest.py

示例5: wrap_stackless_function

    def wrap_stackless_function(self, fn):
        def entry_point(argv):
            os.write(1, str(fn())+"\n")
            return 0

        from pypy.config.pypyoption import get_pypy_config
        config = get_pypy_config(translating=True)
        config.translation.gc = self.gcpolicy
        config.translation.stackless = True
        if self.stacklessgc:
            config.translation.gcrootfinder = "stackless"
        t = TranslationContext(config=config)
        self.t = t
        t.buildannotator().build_types(entry_point, [s_list_of_strings])
        t.buildrtyper().specialize()
        if self.backendopt:
            backend_optimizations(t)

        from pypy.translator.transform import insert_ll_stackcheck
        insert_ll_stackcheck(t)

        cbuilder = CStandaloneBuilder(t, entry_point, config=config)
        cbuilder.stackless = True
        cbuilder.generate_source()
        cbuilder.compile()
        res = cbuilder.cmdexec('')
        return int(res.strip())
开发者ID:antoine1fr,项目名称:pygirl,代码行数:27,代码来源:test_stackless.py

示例6: hannotate

def hannotate(func, argtypes, policy=P_DEFAULT, annotator=False, inline=None,
              backendoptimize=False):
    # build the normal ll graphs for ll_function
    t = TranslationContext()
    a = t.buildannotator()
    a.build_types(func, argtypes)
    rtyper = t.buildrtyper()
    rtyper.specialize()
    if inline:
        auto_inlining(t, threshold=inline)
    if backendoptimize:
        from pypy.translator.backendopt.all import backend_optimizations
        backend_optimizations(t)
    graph1 = graphof(t, func)

    # build hint annotator types
    hannotator = HintAnnotator(base_translator=t, policy=policy)
    hs = hannotator.build_types(graph1, [SomeLLAbstractConstant(v.concretetype,
                                                                {OriginFlags(): True})
                                         for v in graph1.getargs()])
    hannotator.simplify()
    t = hannotator.translator
    if conftest.option.view:
        t.view()
    if annotator:
        return hs, hannotator
    else:
        return hs
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:28,代码来源:test_annotator.py

示例7: test_llexternal_with_callback

    def test_llexternal_with_callback(self):
        from pypy.rpython.lltypesystem.rffi import llexternal
        from pypy.rpython.lltypesystem import lltype

        class Abc:
            pass
        abc = Abc()

        FUNC = lltype.FuncType([lltype.Signed], lltype.Signed)
        z = llexternal('z', [lltype.Ptr(FUNC)], lltype.Signed)
        def g(n):
            abc.foobar = n
            return n + 1
        def f(x):
            return z(g)
        t, wa = self.translate(f, [int])
        fgraph = graphof(t, f)
        backend_optimizations(t)
        assert fgraph.startblock.operations[0].opname == 'direct_call'

        result = wa.analyze(fgraph.startblock.operations[0])
        assert len(result) == 1
        (struct, T, name), = result
        assert struct == "struct"
        assert name.endswith("foobar")
开发者ID:alkorzt,项目名称:pypy,代码行数:25,代码来源:test_writeanalyze.py

示例8: backend_optimize

 def backend_optimize(self, **flags):
     # only optimize the newly created graphs
     from pypy.translator.backendopt.all import backend_optimizations
     translator = self.rtyper.annotator.translator
     newgraphs = self.newgraphs.keys()
     backend_optimizations(translator, newgraphs, secondary=True, **flags)
     self.newgraphs.clear()
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:annlowlevel.py

示例9: test_llexternal

    def test_llexternal(self):
        from pypy.rpython.lltypesystem.rffi import llexternal
        from pypy.rpython.lltypesystem import lltype
        z = llexternal('z', [lltype.Signed], lltype.Signed)
        def f(x):
            return z(x)
        t, ra = self.translate(f, [int])
        fgraph = graphof(t, f)
        backend_optimizations(t)
        assert fgraph.startblock.operations[0].opname == 'direct_call'

        result = ra.can_raise(fgraph.startblock.operations[0])
        assert not result

        z = lltype.functionptr(lltype.FuncType([lltype.Signed], lltype.Signed),
                               'foobar')
        def g(x):
            return z(x)
        t, ra = self.translate(g, [int])
        ggraph = graphof(t, g)

        assert ggraph.startblock.operations[0].opname == 'direct_call'

        result = ra.can_raise(ggraph.startblock.operations[0])
        assert result
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:25,代码来源:test_canraise.py

示例10: test_idempotent

    def test_idempotent(self):
        def s(x):
            res = 0
            i = 1
            while i <= x:
                res += i
                i += 1
            return res

        def g(x):
            return s(100) + s(1) + x 

        def idempotent(n1, n2):
            c = [i for i in range(n2)]
            return 33 + big() + g(10)

        t  = self.translateopt(idempotent, [int, int], raisingop2direct_call=True,
                          constfold=False)
        digest1 = md5digest(t)

        digest2 = md5digest(t)
        assert digest1 == digest2

        #XXX Inlining and constfold are currently non-idempotent.
        #    Maybe they just renames variables but the graph changes in some way.
        backend_optimizations(t, raisingop2direct_call=True,
                              inline_threshold=0, constfold=False)
        digest3 = md5digest(t)
        assert digest1 == digest3
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:29,代码来源:test_all.py

示例11: gengraph

def gengraph(func, argtypes=[], viewbefore='auto', policy=None,
             type_system="lltype", backendopt=False, config=None,
             **extraconfigopts):
    t = TranslationContext(config=config)
    t.config.set(**extraconfigopts)
    a = t.buildannotator(policy=policy)
    timelog("annotating", a.build_types, func, argtypes, main_entry_point=True)
    if viewbefore == 'auto':
        viewbefore = getattr(conftest.option, 'view', False)
    if viewbefore:
        a.simplify()
        t.view()
    global typer # we need it for find_exception
    typer = t.buildrtyper(type_system=type_system)
    timelog("rtyper-specializing", typer.specialize) 
    #t.view()
    timelog("checking graphs", t.checkgraphs) 
    if backendopt:
        from pypy.translator.backendopt.all import backend_optimizations
        backend_optimizations(t)
        timelog("checking graphs", t.checkgraphs)
        if viewbefore:
            t.view()
    desc = t.annotator.bookkeeper.getdesc(func)
    graph = desc.specialize(argtypes)
    return t, typer, graph
开发者ID:ieure,项目名称:pypy,代码行数:26,代码来源:test_llinterp.py

示例12: test_dont_remove_with__del__

    def test_dont_remove_with__del__(self):
        import os
        delcalls = [0]
        class A(object):
            nextid = 0
            def __init__(self):
                self.id = self.nextid
                self.nextid += 1

            def __del__(self):
                delcalls[0] += 1
                os.write(1, "__del__\n")

        def f(x=int):
            a = A()
            i = 0
            while i < x:
                a = A()
                os.write(1, str(delcalls[0]) + "\n")
                i += 1
            return 1
        t = TranslationContext()
        t.buildannotator().build_types(f, [int])
        t.buildrtyper().specialize()
        graph = graphof(t, f)
        backend_optimizations(t)
        op = graph.startblock.exits[0].target.exits[1].target.operations[0]
        assert op.opname == "malloc"
开发者ID:antoine1fr,项目名称:pygirl,代码行数:28,代码来源:test_malloc.py

示例13: translate

def translate(func, argtypes, backend_optimize=True):
    t = TranslationContext()
    t.buildannotator().build_types(func, argtypes)
    t.buildrtyper().specialize()
    if backend_optimize:
        backend_optimizations(t)
    return graphof(t, func), t
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_simplify.py

示例14: task_prehannotatebackendopt_lltype

 def task_prehannotatebackendopt_lltype(self):
     from pypy.translator.backendopt.all import backend_optimizations
     backend_optimizations(self.translator,
                           inline_threshold=0,
                           merge_if_blocks=True,
                           constfold=True,
                           raisingop2direct_call=False,
                           remove_asserts=True)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:8,代码来源:driver.py

示例15: translate

def translate(func, argtypes, backendopt=False):
    t = TranslationContext()
    t.buildannotator().build_types(func, argtypes)
    t.buildrtyper(type_system="ootype").specialize()

    if backendopt:
        backend_optimizations(t, merge_if_blocks=True)
    return t
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:test_treebuilder.py


注:本文中的pypy.translator.backendopt.all.backend_optimizations函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。