本文整理汇总了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)
示例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))
示例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__)
示例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)
示例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())
示例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
示例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")
示例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()
示例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
示例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
示例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
示例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"
示例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
示例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)
示例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