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

Function cleanup_cfg

mypyc/analysis/dataflow.py:136–160  ·  view source on GitHub ↗

Cleanup the control flow graph. This eliminates obviously dead basic blocks and eliminates blocks that contain nothing but a single jump. There is a lot more that could be done.

(blocks: list[BasicBlock])

Source from the content-addressed store, hash-verified

134
135
136def cleanup_cfg(blocks: list[BasicBlock]) -> None:
137 """Cleanup the control flow graph.
138
139 This eliminates obviously dead basic blocks and eliminates blocks that contain
140 nothing but a single jump.
141
142 There is a lot more that could be done.
143 """
144 changed = True
145 while changed:
146 # First collapse any jumps to basic block that only contain a goto
147 for block in blocks:
148 for i, tgt in enumerate(block.terminator.targets()):
149 block.terminator.set_target(i, get_real_target(tgt))
150
151 # Then delete any blocks that have no predecessors
152 changed = False
153 cfg = get_cfg(blocks)
154 orig_blocks = blocks.copy()
155 blocks.clear()
156 for i, block in enumerate(orig_blocks):
157 if i == 0 or cfg.pred[block]:
158 blocks.append(block)
159 else:
160 changed = True
161
162
163T = TypeVar("T")

Callers 2

insert_ref_count_opcodesFunction · 0.90
insert_uninit_checksFunction · 0.90

Calls 8

enumerateFunction · 0.85
get_real_targetFunction · 0.85
get_cfgFunction · 0.85
appendMethod · 0.80
targetsMethod · 0.45
set_targetMethod · 0.45
copyMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…