Stream: git-cranelift

Topic: cranelift / Issue #247 Coloring: Register hints


view this post on Zulip GitHub (Feb 28 2020 at 23:24):

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:

There are also cases where the register hint is not a specific register, but rather a subset of the top-level register class:

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