IT lexicon › Programming › Register allocation

Register allocation

Programming På svenska → Updated: 2026-11-05

The compiler pass that decides which values get to live in the CPU's scarce registers and which have to be spilled to the stack.

A program may juggle thousands of temporaries; x86-64 offers sixteen general-purpose registers. Whatever doesn't fit is "spilled" to the stack and reloaded on demand, which costs memory accesses in exactly the inner loops where it hurts most.

Gregory Chaitin at IBM framed the problem as graph colouring in 1982: values that are live at the same time share an edge, and each colour is a register. Optimal colouring is NP-complete, so every practical allocator is a heuristic. JIT compilers, which can't afford to build graphs, often use linear scan (1999), a single sweep over live ranges. The platform ABI's rules about which registers a function must preserve make the puzzle tighter still.

← Back to the lexicon