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

Function transform_block

mypyc/transform/refcount.py:110–158  ·  view source on GitHub ↗
(
    block: BasicBlock,
    pre_live: AnalysisDict[Value],
    post_live: AnalysisDict[Value],
    pre_borrow: AnalysisDict[Value],
    post_must_defined: AnalysisDict[Value],
)

Source from the content-addressed store, hash-verified

108
109
110def transform_block(
111 block: BasicBlock,
112 pre_live: AnalysisDict[Value],
113 post_live: AnalysisDict[Value],
114 pre_borrow: AnalysisDict[Value],
115 post_must_defined: AnalysisDict[Value],
116) -> None:
117 old_ops = block.ops
118 ops: list[Op] = []
119 for i, op in enumerate(old_ops):
120 key = (block, i)
121
122 assert op not in pre_live[key]
123 dest = op.dest if isinstance(op, Assign) else op
124 stolen = op.stolen()
125
126 # Incref any references that are being stolen that stay live, were borrowed,
127 # or are stolen more than once by this operation.
128 for j, src in enumerate(stolen):
129 if src in post_live[key] or src in pre_borrow[key] or src in stolen[:j]:
130 maybe_append_inc_ref(ops, src)
131 # For assignments to registers that were already live,
132 # decref the old value.
133 if dest not in pre_borrow[key] and dest in pre_live[key]:
134 assert isinstance(op, Assign), op
135 maybe_append_dec_ref(ops, dest, post_must_defined, key)
136
137 # Strip KeepAlive. Its only purpose is to help with this transform.
138 if not isinstance(op, KeepAlive):
139 ops.append(op)
140
141 # Control ops don't have any space to insert ops after them, so
142 # their inc/decrefs get inserted by insert_branch_inc_and_decrefs.
143 if isinstance(op, ControlOp):
144 continue
145
146 for src in op.unique_sources():
147 # Decrement source that won't be live afterwards.
148 if src not in post_live[key] and src not in pre_borrow[key] and src not in stolen:
149 maybe_append_dec_ref(ops, src, post_must_defined, key)
150 # Decrement the destination if it is dead after the op and
151 # wasn't a borrowed RegisterOp
152 if (
153 not dest.is_void
154 and dest not in post_live[key]
155 and not (isinstance(op, RegisterOp) and dest.is_borrowed)
156 ):
157 maybe_append_dec_ref(ops, dest, post_must_defined, key)
158 block.ops = ops
159
160
161def insert_branch_inc_and_decrefs(

Callers 1

insert_ref_count_opcodesFunction · 0.70

Calls 7

enumerateFunction · 0.85
isinstanceFunction · 0.85
maybe_append_inc_refFunction · 0.85
maybe_append_dec_refFunction · 0.85
appendMethod · 0.80
unique_sourcesMethod · 0.80
stolenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…