Register Allocation and Calling Conventions (original) (raw)
I’ve been delving into compiler theory, specifically how they compile source code into machine code. However, there’s something that all papers on register selection seem to ignore, which I’m struggling to understand. Most of the papers I’ve read only focus on the current function they’re working on, ignoring the existence of any functions that might be called within.
Compilers generally adhere to calling conventions, where some registers are callee-saved and others are caller-saved. Despite this, they often allow arguments to be passed through registers instead of just the stack. So, how do compilers ensure that register allocation within a function doesn’t interfere with the designated registers of the calling convention? If no care is taken, it would create useless copies for each call from the argument register to the actual position register and vice versa.