Insert reference count inc/dec opcodes to a function. This is the entry point to this module.
(ir: FuncIR)
| 58 | |
| 59 | |
| 60 | def 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 | |
| 92 | def is_maybe_undefined(post_must_defined: set[Value], src: Value) -> bool: |
searching dependent graphs…