On the document about writing an LLVM backend, I became to wonder what the 'virtual register' is in the following statement.
"You also need to define register classes to contain these registers, such as the integer register class and floating-point register class, so that you can allocate virtual registers to instructions from these sets, and let the target-independent register allocator automatically choose the actual architected registers. (Writing an LLVM backend @ llvm.org)"
Would you mind telling me the difference between 'virtual register' and just 'register'?
Thank you so much.
Sure. A "virtual" register represents a variable that's may reside in
a register. LLVM assumes that there are an infinite amount of
registers for variables to reside in. (This isn't true, of course, but
it's a fiction which allows the optimizations to work without having
to worry about physical registers, which are machine-dependent.) This
delision continues until register allocation, which assigns variables
to actual physical registers.
A virtual register is not one that exists on the hardware. It is a
place holder used during instruction selection, but before register
allocation. The target of the instruction selector is machine code
using mostly virtual registers (physical registers can exist at this
phase, but with some restrictions). There are an unlimited number of
virtual registers to use. The register allocator is responsible for
replacing the virtual registers with architectural registers.