[llvm-dev] Finding caller-saved registers at a function call site

Matthias Braun via llvm-dev llvm-dev at lists.llvm.org
Wed Jun 22 14:32:37 PDT 2016

> On Jun 22, 2016, at 2:01 PM, Sanjoy Das via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> Hi Rob,
> Rob Lyerly via llvm-dev wrote:
> > I'm looking for a way to get all the caller-saved registers (both the
> > register and the stack slot at which it was saved) for a given function
> > call site in the backend.  What's the best way to grab this
> > information?  Is it possible to get this information if I have the
> > MachineInstr of the function call?  I'm currently targeting the AArch64
> > & X86 backends.
> You should be able to use the RegMask operand to the MachineInstr to
> discover the registers that are preserved or clobbered by the call
> according to the calling convention.  For reference, you might want to
> look at `getRegMask` and `gatherMaximalPreservedRegisters` in
> http://reviews.llvm.org/D21115.
> As far as discovering the slot to which it is spilled, I have no idea.
> CC'ing Matthias for this.

Just to be sure: You are not talking about callee saved registers (the ones that are usually saved in the prologue and restored in the epilogue of a function)?

As Sanjoy already mentioned: Registers are marked as clobbered/preserved with a RegMask operand on the call instruction. Often some values that are live accross a function get spilled because we have no callee saved (preserved) register left for them. The question of what values are in caller save registers is therefore an odd one: Of course there are no values live in caller save registers at the call site because that would be invalid. We have spill slots for certain values (all those that live across a call but didn't make it into a callee saved register) but there is no notion of a spill slot for a caller saved register %EDX for example.

- Matthias

More information about the llvm-dev mailing list