Conceptual difference between "Unallocatable" and "Reserved" registers.


I’m writing to ask the differences between a “reserved” register and an “unallocable” register. In X86 backend, for example, the stack pointer register and instruction pointer are reserved but allocatable. In the Doxygen document of function llvm::TargetRegisterInfo::getReservedRegs, it says that a reserved register is one that has particular uses and should be considered unavailable at all times. If it is unavailable at all times, why not make such a reserved register unallocatable? Thanks!

Lei Mou

Hi Aries,

Thank you for your reply. I understand that the registers you mentioned should not be used at will. The problem I don’t understand is why not make these registers unallocatable. Since in, only floating point stack registers ST0 to ST7 and status flag registers are defined as not allocatable, while special registers such as ESP/EIP/EBP are defined as allocatable but reserved (in X86RegisterInfo.cpp).

Since these registers also have special usage, why not specify them as unallocatable, instead of allocatable but reserved? I hope I made myself clear. Thanks.

Lei Mou

Registers are partitioned into three disjoint sets:

  1. Allocatable registers.
  2. Reserved registers.
  3. The rest: Unallocatable, unreserved registers.

The set of reserved registers is not known to TableGen, and it can vary for different sub-targets, and even different functions. The reserved registers for a function are computed by the TRI::getReservedRegs(MF) hook.

A register is allocatable if it belongs to at least one allocatable register class AND it is not reserved.

See RegisterClassInfo.h, in particular the isAllocatable() function.

The third set of unallocatable, unreserved registers usually only contains the flags. It is different from the reserved registers because the register allocator is still tracking liveness of these registers. The reserved registers are mostly ignored for liveness tracking.


Thank you very much for the information!

Yours Sincerely,
Lei Mou