Allocating registers
Register allocation is the task of assigning physical registers to virtual registers. Virtual registers can be infinite, but the physical registers for a machine are limited. So, register allocation is aimed at maximizing the number of physical registers getting assigned to virtual registers. In this recipe, we will see how registers are represented in LLVM, how can we tinker with the register information, the steps taking place, and built-in register allocators.
Getting ready
You need to build and install LLVM.
How to do it…
To see how registers are represented in LLVM, open the
build-folder/lib/Target/X86/X86GenRegisterInfo.inc
file and check out the first few lines, which show that registers are represented as integers:namespace X86 { enum { NoRegister, AH = 1, AL = 2, AX = 3, BH = 4, BL = 5, BP = 6, BPL = 7, BX = 8, CH = 9, …
For architectures that have registers that share the same physical location, check out the
RegisterInfo.td
file of that architecture...