Register allocation is the process of deciding how to map program variables onto a fixed set of registers. The canonical approach, graph coloring, was proposed in 1981, with countless other approaches explored since then. Compilers transform programs into single static assignment form, breaking variables into unique names, and potentially introducing auxiliary variables for temporaries. Assigning registers involves considering variable lifetimes and splitting them accordingly. Algorithms like linear scan and graph coloring help in the process, but finding an optimal solution is challenging due to the NP-complete nature of the problem. Real architectures introduce additional complexities, such as instruction support and calling conventions, making register allocation a vital compiler task.
https://langdev.stackexchange.com/questions/4325/how-do-modern-compilers-choose-which-variables-to-put-in-registers