4 ms·
Why does it only have six registers? The end user probably doesn't want to write a register allocator.
by rjeli 6y ago
Why does it only have six registers? The end user probably doesn't want to write a register allocator.
- AlexAltea 6y agoMight not be the reason, but six registers make it trivial to write a backend for 32-bit x86 CPUs, since they offer 8 general-purpose registers minus 2 typically used for stack pointer and base (ESP, EBP respectively). That leaves 6 registers usable by compilers: EAX, EDX, ECX, EBX, ESI, EDI. To my knowledge, any other architecture targeted by GNU lightning offers more registers, so this magic number is effectively the largest number of registers one can offer where register allocation would become trivial for all architectures.
- tom_mellior 6y ago"Six registers are not very much, but this restriction was forced by the need to target CISC architectures which, like the x86, are poor of registers; anyway, backends can specify the actual number of available registers with the calls JIT_R_NUM (for caller-save registers) and JIT_V_NUM (for callee-save registers)." (https://www.gnu.org/software/lightning/manual/lightning.html#The-instruction-set https://www.gnu.org/software/lightning/manual/lightning.html...) There used to be a boardly similar library called libjit https://www.gnu.org/software/libjit/ https://www.gnu.org/software/libjit/ which was slightly higher level: It offered an arbitrary number of virtual registers. It took care of register allocation, I don't recall how sophisticated it was. The docs call it "global" allocation, i.e., taking the whole function into account at once, as opposed to local allocation that considers blocks in isolation.
- cout 6y agoIt wasn't very sophisticated when I used it 12 years ago, but it was "good enough". I know work has been done since then on the register allocator. No idea what the current state is.