regalloc.rs
regalloc.rs copied to clipboard
Support rematerialization of values
The register allocator should be able to decide to recompute a value rather than reload it from a slot, in cases where this is cheap. (E.g., if a value produced by an add has been spilled, and its two arguments are still in registers, then it's better to redo the add than perform a memory load.)
This will probably require at least the following:
- A way for the client to communicate to the register allocator that some instructions compute their defs based only on their uses, without referring to any other state (e.g., memory), such that cloning that instruction and replacing the regs appropriately will produce an instruction that computes the same value later.
- A way for the client to provide costs of operations, and spills/fills, to the allocator.
- Support in the allocators for choosing to rematerialize.
See discussion in #14 for more. This work would probably also cover immediates (cheaper to recreate the immediate value than to spill and reload it).