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

Function make_value_ordering

mypyc/transform/refcount.py:267–298  ·  view source on GitHub ↗

Create a ordering of values that allows them to be sorted. This omits registers that are only ever read.

(ir: FuncIR)

Source from the content-addressed store, hash-verified

265
266
267def make_value_ordering(ir: FuncIR) -> dict[Value, int]:
268 """Create a ordering of values that allows them to be sorted.
269
270 This omits registers that are only ever read.
271 """
272 # TODO: Never initialized values??
273 result: dict[Value, int] = {}
274 n = 0
275
276 for arg in ir.arg_regs:
277 result[arg] = n
278 n += 1
279
280 for block in ir.blocks:
281 for op in block.ops:
282 if (
283 isinstance(op, LoadAddress)
284 and isinstance(op.src, Register)
285 and op.src not in result
286 ):
287 # Taking the address of a register allows initialization.
288 result[op.src] = n
289 n += 1
290 if isinstance(op, Assign):
291 if op.dest not in result:
292 result[op.dest] = n
293 n += 1
294 elif op not in result:
295 result[op] = n
296 n += 1
297
298 return result

Callers 1

insert_ref_count_opcodesFunction · 0.85

Calls 1

isinstanceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…