MCPcopy Index your code
hub / github.com/python/mypy / insert_ref_count_opcodes

Function insert_ref_count_opcodes

mypyc/transform/refcount.py:60–89  ·  view source on GitHub ↗

Insert reference count inc/dec opcodes to a function. This is the entry point to this module.

(ir: FuncIR)

Source from the content-addressed store, hash-verified

58
59
60def insert_ref_count_opcodes(ir: FuncIR) -> None:
61 """Insert reference count inc/dec opcodes to a function.
62
63 This is the entry point to this module.
64 """
65 cfg = get_cfg(ir.blocks)
66 values = all_values(ir.arg_regs, ir.blocks)
67
68 borrowed = {value for value in values if value.is_borrowed}
69 args: set[Value] = set(ir.arg_regs)
70 live = analyze_live_regs(ir.blocks, cfg)
71 borrow = analyze_borrowed_arguments(ir.blocks, cfg, borrowed)
72 defined = analyze_must_defined_regs(ir.blocks, cfg, args, values, strict_errors=True)
73 ordering = make_value_ordering(ir)
74 cache: BlockCache = {}
75 for block in ir.blocks.copy():
76 if isinstance(block.ops[-1], (Branch, Goto)):
77 insert_branch_inc_and_decrefs(
78 block,
79 cache,
80 ir.blocks,
81 live.before,
82 borrow.before,
83 borrow.after,
84 defined.after,
85 ordering,
86 )
87 transform_block(block, live.before, live.after, borrow.before, defined.after)
88
89 cleanup_cfg(ir.blocks)
90
91
92def is_maybe_undefined(post_must_defined: set[Value], src: Value) -> bool:

Callers 4

run_caseMethod · 0.90
run_caseMethod · 0.90
run_caseMethod · 0.90
compile_scc_to_irFunction · 0.90

Calls 12

get_cfgFunction · 0.90
all_valuesFunction · 0.90
analyze_live_regsFunction · 0.90
cleanup_cfgFunction · 0.90
setClass · 0.85
make_value_orderingFunction · 0.85
isinstanceFunction · 0.85
transform_blockFunction · 0.70
copyMethod · 0.45

Tested by 3

run_caseMethod · 0.72
run_caseMethod · 0.72
run_caseMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…