本文整理汇总了Python中pypy.objspace.flow.model.checkgraph函数的典型用法代码示例。如果您正苦于以下问题:Python checkgraph函数的具体用法?Python checkgraph怎么用?Python checkgraph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了checkgraph函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: split_graph_and_record_jitdriver
def split_graph_and_record_jitdriver(self, graph, block, pos):
op = block.operations[pos]
jd = JitDriverStaticData()
jd._jit_merge_point_pos = (graph, op)
args = op.args[2:]
s_binding = self.translator.annotator.binding
jd._portal_args_s = [s_binding(v) for v in args]
graph = copygraph(graph)
graph.startblock.isstartblock = False
[jmpp] = find_jit_merge_points([graph])
graph.startblock = support.split_before_jit_merge_point(*jmpp)
graph.startblock.isstartblock = True
# a crash in the following checkgraph() means that you forgot
# to list some variable in greens=[] or reds=[] in JitDriver.
checkgraph(graph)
for v in graph.getargs():
assert isinstance(v, Variable)
assert len(dict.fromkeys(graph.getargs())) == len(graph.getargs())
self.translator.graphs.append(graph)
jd.portal_graph = graph
# it's a bit unbelievable to have a portal without func
assert hasattr(graph, "func")
graph.func._dont_inline_ = True
graph.func._jit_unroll_safe_ = True
jd.jitdriver = block.operations[pos].args[1].value
jd.portal_runner_ptr = "<not set so far>"
jd.result_type = history.getkind(jd.portal_graph.getreturnvar()
.concretetype)[0]
self.jitdrivers_sd.append(jd)
示例2: builder
def builder(translator, func):
# build a hacked graph that doesn't take a *arg any more, but
# individual extra arguments
graph = translator.buildflowgraph(func)
argnames, vararg, kwarg = graph.signature
assert vararg, "graph should have a *arg at this point"
assert not kwarg, "where does this **arg come from??"
argscopy = [Variable(v) for v in graph.getargs()]
starargs = [Variable('stararg%d'%i) for i in range(nb_extra_args)]
newstartblock = Block(argscopy[:-1] + starargs)
newtup = SpaceOperation('newtuple', starargs, argscopy[-1])
newstartblock.operations.append(newtup)
newstartblock.closeblock(Link(argscopy, graph.startblock))
graph.startblock.isstartblock = False
graph.startblock = newstartblock
newstartblock.isstartblock = True
argnames += tuple(['.star%d' % i for i in range(nb_extra_args)])
graph.signature = argnames, None, None
# note that we can mostly ignore defaults: if nb_extra_args > 0,
# then defaults aren't applied. if nb_extra_args == 0, then this
# just removes the *arg and the defaults keep their meaning.
if nb_extra_args > 0:
graph.defaults = None # shouldn't be used in this case
checkgraph(graph)
return graph
示例3: test_wrong_startblock_incref
def test_wrong_startblock_incref():
class B(object):
pass
def g(b):
while True:
b.x -= 10
if b.x < 0:
return b.x
def f(n):
b = B()
b.x = n
return g(b)
# XXX obscure: remove the first empty block in the graph of 'g'
t = TranslationContext()
graph = t.buildflowgraph(g)
assert graph.startblock.operations == []
graph.startblock = graph.startblock.exits[0].target
from pypy.objspace.flow.model import checkgraph
checkgraph(graph)
t._prebuilt_graphs[g] = graph
fn = compile_func(f, [int], t)
res = fn(112)
assert res == -8
示例4: remove_asserts
def remove_asserts(translator, graphs):
rtyper = translator.rtyper
clsdef = translator.annotator.bookkeeper.getuniqueclassdef(AssertionError)
r_AssertionError = rclass.getclassrepr(rtyper, clsdef)
ll_AssertionError = r_AssertionError.convert_const(AssertionError)
total_count = [0, 0]
for graph in graphs:
count = 0
morework = True
while morework:
morework = False
eliminate_empty_blocks(graph)
join_blocks(graph)
for link in graph.iterlinks():
if (link.target is graph.exceptblock
and isinstance(link.args[0], Constant)
and link.args[0].value == ll_AssertionError):
if kill_assertion_link(graph, link):
count += 1
morework = True
break
else:
total_count[0] += 1
if translator.config.translation.verbose:
log.removeassert("cannot remove an assert from %s" % (graph.name,))
if count:
# now melt away the (hopefully) dead operation that compute
# the condition
total_count[1] += count
if translator.config.translation.verbose:
log.removeassert("removed %d asserts in %s" % (count, graph.name))
checkgraph(graph)
#transform_dead_op_vars(graph, translator)
log.removeassert("Could not remove %d asserts, but removed %d asserts." % tuple(total_count))
示例5: find_portal
def find_portal(self):
graphs = self.translator.graphs
self.jit_merge_point_pos = find_jit_merge_point(graphs)
graph, block, pos = self.jit_merge_point_pos
op = block.operations[pos]
args = op.args[2:]
s_binding = self.translator.annotator.binding
self.portal_args_s = [s_binding(v) for v in args]
graph = copygraph(graph)
graph.startblock.isstartblock = False
graph.startblock = support.split_before_jit_merge_point(
*find_jit_merge_point([graph]))
graph.startblock.isstartblock = True
# a crash in the following checkgraph() means that you forgot
# to list some variable in greens=[] or reds=[] in JitDriver.
checkgraph(graph)
for v in graph.getargs():
assert isinstance(v, Variable)
assert len(dict.fromkeys(graph.getargs())) == len(graph.getargs())
self.translator.graphs.append(graph)
self.portal_graph = graph
# it's a bit unbelievable to have a portal without func
assert hasattr(graph, "func")
graph.func._dont_inline_ = True
graph.func._jit_unroll_safe_ = True
self.jitdriver = block.operations[pos].args[1].value
示例6: checkgraphs
def checkgraphs(self, blocks):
seen = {}
for block in blocks:
graph = self.annotated[block]
if graph not in seen:
checkgraph(graph)
seen[graph] = True
示例7: check_graph
def check_graph(graph, args, expected_result, t):
if conftest.option.view:
t.view()
checkgraph(graph)
interp = LLInterpreter(t.rtyper)
res = interp.eval_graph(graph, args)
assert res == expected_result
示例8: simplify_graph
def simplify_graph(graph, passes=True): # can take a list of passes to apply, True meaning all
"""inplace-apply all the existing optimisations to the graph."""
if passes is True:
passes = all_passes
checkgraph(graph)
for pass_ in passes:
pass_(graph)
checkgraph(graph)
示例9: show_incremental_progress
def show_incremental_progress(gv_func):
from pypy import conftest
graph = _getgraph(gv_func)
fixduplicatevars(graph)
flowmodel.checkgraph(graph)
if conftest.option.view:
eliminate_empty_blocks(graph)
graph.show()
示例10: merge_if_blocks_once
def merge_if_blocks_once(graph):
"""Convert consecutive blocks that all compare a variable (of Primitive type)
with a constant into one block with multiple exits. The backends can in
turn output this block as a switch statement.
"""
candidates = [block for block in graph.iterblocks()
if is_chain_block(block, first=True)]
entrymap = mkentrymap(graph)
for firstblock in candidates:
chain = []
checkvars = []
varmap = {} # {var in a block in the chain: var in the first block}
for var in firstblock.exits[0].args:
varmap[var] = var
for var in firstblock.exits[1].args:
varmap[var] = var
def add_to_varmap(var, newvar):
if isinstance(var, Variable):
varmap[newvar] = varmap[var]
else:
varmap[newvar] = var
current = firstblock
while 1:
# check whether the chain can be extended with the block that follows the
# False link
checkvar = [var for var in current.operations[-1].args
if isinstance(var, Variable)][0]
case = [var for var in current.operations[-1].args
if isinstance(var, Constant)][0]
chain.append((current, case))
checkvars.append(checkvar)
falseexit = current.exits[0]
assert not falseexit.exitcase
trueexit = current.exits[1]
targetblock = falseexit.target
if len(entrymap[targetblock]) != 1:
break
if checkvar not in falseexit.args:
break
newcheckvar = targetblock.inputargs[falseexit.args.index(checkvar)]
if not is_chain_block(targetblock):
break
if newcheckvar not in targetblock.operations[0].args:
break
for i, var in enumerate(trueexit.args):
add_to_varmap(var, trueexit.target.inputargs[i])
for i, var in enumerate(falseexit.args):
add_to_varmap(var, falseexit.target.inputargs[i])
current = targetblock
if len(chain) > 1:
break
else:
return False
merge_chain(chain, checkvars[0], varmap, graph)
checkgraph(graph)
return True
示例11: finish
def finish(self):
# compute the final masterarray by copying over the masterarray1,
# which is a list of dicts of attributes
if SAVE_STATISTICS:
import cPickle
cPickle.dump(self.stats, open('stackless-stats.pickle', 'wb'))
# fun fun fun patching the call_function_retval_xyz() functions!
for RESTYPE, typename in frame.STORAGE_TYPES_AND_FIELDS:
rettype_index = STORAGE_TYPES.index(RESTYPE)
cache = self.signaturecodes[rettype_index]
if not cache:
continue # not used anyway, don't produce a broken empty switch
func = getattr(code, 'call_function_retval_' + typename)
desc = self.translator.annotator.bookkeeper.getdesc(func)
graph = desc.getuniquegraph()
[v_fnaddr, v_signature_index] = graph.getargs()
block = model.Block([v_fnaddr, v_signature_index])
block.exitswitch = v_signature_index
block.isstartblock = True
graph.startblock = block
switchlinks = []
for ARGTYPES, signature_index in cache.items():
# XXX because of type erasure, the following cast is
# kind of invalid, but we hope that nobody will notice
FUNCTYPE = lltype.Ptr(lltype.FuncType(ARGTYPES, RESTYPE))
v_fnaddr1 = varoftype(v_fnaddr.concretetype)
callblock = model.Block([v_fnaddr1])
llops = LowLevelOpList()
args_v = [model.Constant(TYPE._defl(), concretetype=TYPE)
for TYPE in ARGTYPES]
v_res = llops.genop('adr_call', [v_fnaddr1] + args_v,
resulttype = RESTYPE)
callblock.operations[:] = llops
callblock.closeblock(model.Link([v_res], graph.returnblock))
link = model.Link([v_fnaddr], callblock)
link.exitcase = signature_index
link.llexitcase = signature_index
switchlinks.append(link)
block.closeblock(*switchlinks)
model.checkgraph(graph)
self.is_finished = True
masterarray = lltype.malloc(frame.FRAME_INFO_ARRAY,
len(self.masterarray1),
immortal=True)
for dst, src in zip(masterarray, self.masterarray1):
dst.fnaddr, dst.info = src
# horrors in the same spirit as in rpython.memory.gctransform
# (shorter, though)
ll_global_state = self.ll_global_state.value
ll_global_state.inst_masterarray = masterarray
return [masterarray]
示例12: virtualize_mallocs
def virtualize_mallocs(translator, graphs, verbose=False):
newgraphs = graphs[:]
mallocv = MallocVirtualizer(newgraphs, translator.rtyper, verbose)
while mallocv.remove_mallocs_once():
pass
for graph in newgraphs:
checkgraph(graph)
join_blocks(graph)
assert newgraphs[:len(graphs)] == graphs
del newgraphs[:len(graphs)]
translator.graphs.extend(newgraphs)
示例13: test_split_blocks_simple
def test_split_blocks_simple():
for i in range(4):
def f(x, y):
z = x + y
w = x * y
return z + w
graph, t = translate(f, [int, int])
split_block(t.annotator, graph.startblock, i)
checkgraph(graph)
interp = LLInterpreter(t.rtyper)
result = interp.eval_graph(graph, [1, 2])
assert result == 5
示例14: _buildgraph
def _buildgraph(graph):
assert graph.startblock.operations[0].opname == 'debug_assert'
del graph.startblock.operations[0]
# rgenop makes graphs that use the same variable in several blocks,
fixduplicatevars(graph) # fix this now
flowmodel.checkgraph(graph)
eliminate_empty_blocks(graph)
# we cannot call join_blocks(graph) here! It has a subtle problem:
# it copies operations between blocks without renaming op.result.
# See test_promotion.test_many_promotions for a failure.
graph.rgenop = True
return graph
示例15: transform_graph
def transform_graph(self, graph):
if graph in self.minimal_transform:
if self.minimalgctransformer:
self.minimalgctransformer.transform_graph(graph)
del self.minimal_transform[graph]
return
if graph in self.seen_graphs:
return
self.seen_graphs[graph] = True
self.links_to_split = {} # link -> vars to pop_alive across the link
# for sanity, we need an empty block at the start of the graph
inserted_empty_startblock = False
if not starts_with_empty_block(graph):
insert_empty_startblock(self.translator.annotator, graph)
inserted_empty_startblock = True
is_borrowed = self.compute_borrowed_vars(graph)
for block in graph.iterblocks():
self.transform_block(block, is_borrowed)
for link, livecounts in self.links_to_split.iteritems():
llops = LowLevelOpList()
for var, livecount in livecounts.iteritems():
for i in range(livecount):
self.pop_alive(var, llops)
for i in range(-livecount):
self.push_alive(var, llops)
if llops:
if link.prevblock.exitswitch is None:
link.prevblock.operations.extend(llops)
else:
insert_empty_block(self.translator.annotator, link, llops)
# remove the empty block at the start of the graph, which should
# still be empty (but let's check)
if starts_with_empty_block(graph) and inserted_empty_startblock:
old_startblock = graph.startblock
graph.startblock.isstartblock = False
graph.startblock = graph.startblock.exits[0].target
graph.startblock.isstartblock = True
checkgraph(graph)
self.links_to_split = None
v = Variable('vanishing_exc_value')
v.concretetype = self.get_lltype_of_exception_value()
llops = LowLevelOpList()
self.pop_alive(v, llops)
graph.exc_cleanup = (v, list(llops))
return is_borrowed # xxx for tests only