Register allocation (source code)

= Register allocation

<Register allocation> maps temporary values or virtual registers in a <compiler>'s representation to a limited supply of physical <processor registers>. A value's <live range> covers where it may still be needed. Overlapping <live ranges> constrain which values can share a <processor register>; <register spilling> moves some storage into <computer memory> when necessary.<The LLVM Target-Independent Code Generator>[Live Intervals and Register Allocation]{ref}

For example, in `a=x+y; b=a*z`, the <processor register> holding `a` can hold `b` after `a`'s final use, if the target operation permits. If both values are needed later, overwriting `a` would lose required information. An <interference graph> represents simultaneous storage requirements, connecting <register allocation> to <graph coloring>. Real targets add constraints from register classes, reserved registers, <calling conventions> and particular <machine instructions>; minimizing the number of names alone does not solve the whole problem.