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…

  1. 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 ...

Get LLVM Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.