Create a ordering of values that allows them to be sorted. This omits registers that are only ever read.
(ir: FuncIR)
| 265 | |
| 266 | |
| 267 | def 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 |
no test coverage detected
searching dependent graphs…