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

Function update_register_assignments_to_set_bitmap

mypyc/transform/uninit.py:171–199  ·  view source on GitHub ↗

Update some assignments to registers to also set a bit in a bitmap. The bitmaps are used to track if a local variable has been assigned to. Modifies blocks.

(
    blocks: list[BasicBlock], bitmap_registers: list[Register], bitmap_backed: list[Register]
)

Source from the content-addressed store, hash-verified

169
170
171def update_register_assignments_to_set_bitmap(
172 blocks: list[BasicBlock], bitmap_registers: list[Register], bitmap_backed: list[Register]
173) -> None:
174 """Update some assignments to registers to also set a bit in a bitmap.
175
176 The bitmaps are used to track if a local variable has been assigned to.
177
178 Modifies blocks.
179 """
180 for block in blocks:
181 if any(isinstance(op, Assign) and op.dest in bitmap_backed for op in block.ops):
182 new_ops: list[Op] = []
183 for op in block.ops:
184 if isinstance(op, Assign) and op.dest in bitmap_backed:
185 index = bitmap_backed.index(op.dest)
186 new_ops.append(op)
187 reg = bitmap_registers[index // BITMAP_BITS]
188 new = IntOp(
189 bitmap_rprimitive,
190 reg,
191 Integer(1 << (index & (BITMAP_BITS - 1)), bitmap_rprimitive),
192 IntOp.OR,
193 op.line,
194 )
195 new_ops.append(new)
196 new_ops.append(Assign(reg, new))
197 else:
198 new_ops.append(op)
199 block.ops = new_ops

Callers 1

split_blocks_at_uninitsFunction · 0.85

Calls 7

IntOpClass · 0.90
IntegerClass · 0.90
AssignClass · 0.90
anyFunction · 0.85
isinstanceFunction · 0.85
indexMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…