本文整理汇总了Python中pykit.ir.Builder.replace_predecessor方法的典型用法代码示例。如果您正苦于以下问题:Python Builder.replace_predecessor方法的具体用法?Python Builder.replace_predecessor怎么用?Python Builder.replace_predecessor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pykit.ir.Builder
的用法示例。
在下文中一共展示了Builder.replace_predecessor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: consume_yields
# 需要导入模块: from pykit.ir import Builder [as 别名]
# 或者: from pykit.ir.Builder import replace_predecessor [as 别名]
def consume_yields(func, consumer, generator_func, valuemap):
b = Builder(func)
copier = lambda x : x
loop = consumer.loop
inlined_values = set(valuemap.values())
for block in func.blocks:
if block in inlined_values:
for op in block.ops:
if op.opcode == 'yield':
# -- Replace 'yield' by the loop body -- #
b.position_after(op)
_, resume = b.splitblock()
# Copy blocks
blocks = [copier(block) for block in loop.blocks]
# Insert blocks
prev = op.block
for block in blocks:
func.add_block(block, after=prev)
prev = block
# Fix wiring
b.jump(blocks[0])
b.position_at_end(blocks[-1])
b.jump(resume)
# We just introduced a bunch of copied blocks
func.reset_uses()
# Update phis with new predecessor
b.replace_predecessor(loop.tail, op.block, loop.head)
b.replace_predecessor(loop.tail, op.block, loop.head)
# Replace next() by value produced by yield
value = op.args[0]
consumer.next.replace_uses(value)
op.delete()
# We don't need these anymore
consumer.next.delete()