Open d5bfafaa-05ff-4c34-845c-3d10c8ba0197 opened 6 years ago
According to the ELF 32-bit ABI: Register r2 is reserved for system use and should not be changed by application code.
Correct me if I am misunderstanding the linked discussion as well as the purpose of this PR. It seems that clang's behaviour is correct but conservative.
Basically, if we had -ffixed-r2, it would simply do what we currently do without the option.
And the purpose of this PR is to relax this "always reserved" behaviour to respect -ffixed-r2 so that the register allocator would have one more register to work with?
Here's the context from the kernel patch:
https://lore.kernel.org/linuxppc-dev/20181105231207.GB5994@gate.crashing.org/
The option is called -ffixed-reg in the gcc manual.
I am not sure what conditions you are referring to where we need not reserve R2 on PPC32. Can you elaborate a bit? Also, can you provide a link to the GCC option? I can't find it in the GCC manual.
Extended Description
The PowerPC 32-bit port always reserves r2:
lib/Target/PowerPC/PPCRegisterInfo.cpp:
// The SVR4 ABI reserves r2 and r13 if (Subtarget.isSVR4ABI()) { // We only reserve r2 if we need to use the TOC pointer. If we have no // explicit uses of the TOC pointer (meaning we're a leaf function with // no constant-pool loads, etc.) and we have no potential uses inside an // inline asm block, then we can treat r2 has an ordinary callee-saved // register. const PPCFunctionInfo *FuncInfo = MF.getInfo();
if (!TM.isPPC64() || FuncInfo->usesTOCBasePtr() || MF.hasInlineAsm())
markSuperRegs(Reserved, PPC::R2); // System-reserved register
markSuperRegs(Reserved, PPC::R13); // Small Data Area pointer register
}
This is useful for eg. Linux kernel, but other programs many not need to reserve r2 and could instead allow the compiler to use it.
In order to support this clang would need a -ffixed-r2 flag (similar to GCC) that allows programs such Linux to reserve r2.