Register Allocation, Interference, and Spilling

Convert overlapping live ranges into register constraints and see how spilling changes both code cost and liveness.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Simultaneously needed values interfere
  2. Spilling changes the input to allocation

Simultaneously needed values interfere

Make one graph vertex per virtual value and connect pairs that need distinct storage at the same point. Assigning physical registers becomes a coloring problem with target-specific constraints. With two registers, three pairwise interfering values require a spill or another transformation. A value whose live range ends before another begins may reuse the same register, even when the names differ.

Spilling changes the input to allocation

A spill places selected values in memory and inserts stores and loads. Reloads create short new live ranges and add instructions that can affect the surrounding allocation. A value used in a tight loop can be more expensive to spill than a rarely used one. Liveness derives the overlap conditions. Calling conventions constrain which registers can retain values across call boundaries.[1][2]

References

  1. Andrew C. Myers, Cornell CS 4120: Compiler Course Notes ↩
  2. LLVM Project, LLVM Language Reference Manual ↩