alexcrichton transferred Issue #247:
See also the discussion of biased coloring in #189.
The register coloring pass is currently assigning simply the first available register to new register values. This can be improved with register hints to reduce the amount of register shuffling needed in the following cases:
- An instruction requires an input operand in a specific register. For example, Intel's dynamic shift instructions require the shift amount in
%rcx
.- A value passed as a call argument must be in a register specified by the ABI.
- Values belonging to the same virtual register should preferably be assigned the same physical register to minimize shuffling before branches.
There are also cases where the register hint is not a specific register, but rather a subset of the top-level register class:
- Some instructions only accept a subset of registers. For example some of Intel's addressing modes can't use
%r12
and others can't use%r13
.- If a value is live across a call, it should be in one of the callee-saved registers. (SpiderMonkey doesn't have CSRs).
The
LiveRange::affinity
field is already used to track register class hints. When a value is used by an instruction with a reduced register class constraint, the affinity is intersected with the constraint. These hints are currently ignored, and we just assign registers from the top-level register class.Individual register hints are not tracked anywhere. They could be computed by the reload pass.
Constraint processing
Hints, whether for register sets or singletons, require the constraint solver to be a bit more clever. It should use the hints as much as possible, but ignore them before failing to find a solution.
Anti-hints
Sometimes a hint can't be used because another value is already using the register we want. We can prevent this by trying to avoid assigning value to registers where they will get in the way later.
This can be done using a data structure similar to LLVM's register matrix. Whenever a value is given a hint (during the reload pass), its live range is inserted into the register matrix for the corresponding unit. The coloring pass can then check live ranges against the matrix to see if there is a conflict with other hinted values.
Last updated: Oct 23 2024 at 20:03 UTC