[LLVMdev] Clarification about callee saved regs and MachineRegisterInfo::isPhyRegUsed

Jakob Stoklund Olesen stoklund at 2pi.dk
Sun Jan 27 16:35:22 PST 2013

On Jan 27, 2013, at 6:50 AM, matic at nimp.co.uk wrote:

> I am confused about the call to isPhyRegUsed in calculateCalleeSavedRegisters:
> if (Fn.getRegInfo().isPhysRegUsed(Reg)) {
>       // If the reg is modified, save it!
>       CSI.push_back(CalleeSavedInfo(Reg));
>     }
> It seems that isPhyRegUsed returns true if the register is read or written in the function.
> If this is right, why do we save a register if it is only read in the function ?? I would have expected that calculateCalleeSavedRegisters use another function which would return true only when the register is written, something like "isPhyRegWritten".

Hi Sebastien,

I don't think there is a good reason it works that way. The distinction hasn't been important yet, I'd guess.

> The ARM backend don't have this problem because it use a BX_RET instruction, which is just a BX which implicitly use LR as operand. Seems like a workaround solution...
Some CodeGen passes treat return instructions specially. That is why there is a BX_RET instruction. Look for isReturn().


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130127/12cbea24/attachment.html>

More information about the llvm-dev mailing list