-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[PowerPC] Utilize getReservedRegs to find asm clobberable registers. #107863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -380,23 +380,24 @@ BitVector PPCRegisterInfo::getReservedRegs(const MachineFunction &MF) const { | |
|
|
||
| markSuperRegs(Reserved, PPC::VRSAVE); | ||
|
|
||
| const PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>(); | ||
| bool UsesTOCBasePtr = FuncInfo->usesTOCBasePtr(); | ||
| // 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<PPCFunctionInfo>(); | ||
| if (!TM.isPPC64() || FuncInfo->usesTOCBasePtr() || MF.hasInlineAsm()) | ||
| markSuperRegs(Reserved, PPC::R2); // System-reserved register | ||
| markSuperRegs(Reserved, PPC::R13); // Small Data Area pointer register | ||
| if (!TM.isPPC64() || UsesTOCBasePtr || MF.hasInlineAsm()) | ||
| markSuperRegs(Reserved, PPC::R2); // System-reserved register. | ||
| markSuperRegs(Reserved, PPC::R13); // Small Data Area pointer register. | ||
| } | ||
|
|
||
| // Always reserve r2 on AIX for now. | ||
| // TODO: Make r2 allocatable on AIX/XCOFF for some leaf functions. | ||
| if (Subtarget.isAIXABI()) | ||
| markSuperRegs(Reserved, PPC::R2); // System-reserved register | ||
| // We only reserve r2 if we need to use the TOC pointer on AIX. | ||
| if (!TM.isPPC64() || UsesTOCBasePtr || MF.hasInlineAsm()) | ||
| markSuperRegs(Reserved, PPC::R2); // System-reserved register. | ||
|
||
|
|
||
| // On PPC64, r13 is the thread pointer. Never allocate this register. | ||
| if (TM.isPPC64()) | ||
|
|
@@ -441,14 +442,12 @@ BitVector PPCRegisterInfo::getReservedRegs(const MachineFunction &MF) const { | |
|
|
||
| bool PPCRegisterInfo::isAsmClobberable(const MachineFunction &MF, | ||
| MCRegister PhysReg) const { | ||
| // We cannot use getReservedRegs() to find the registers that are not asm | ||
| // clobberable because there are some reserved registers which can be | ||
| // clobbered by inline asm. For example, when LR is clobbered, the register is | ||
| // saved and restored. We will hardcode the registers that are not asm | ||
| // cloberable in this function. | ||
|
|
||
| // The stack pointer (R1/X1) is not clobberable by inline asm | ||
| return PhysReg != PPC::R1 && PhysReg != PPC::X1; | ||
| // CTR and LR registers are always reserved, but they are asm clobberable. | ||
| if (PhysReg == PPC::CTR || PhysReg == PPC::CTR8 || PhysReg == PPC::LR || | ||
| PhysReg == PPC::LR8) | ||
| return true; | ||
|
|
||
| return !getReservedRegs(MF).test(PhysReg); | ||
| } | ||
|
|
||
| bool PPCRegisterInfo::requiresFrameIndexScavenging(const MachineFunction &MF) const { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| ; RUN: llc < %s -mtriple=powerpc-unknown-aix-xcoff -verify-machineinstrs \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a 64-bit run line, too? |
||
| ; RUN: -mcpu=pwr7 -mattr=+altivec -O0 2>&1 | FileCheck %s | ||
|
|
||
| ; CHECK: warning: inline asm clobber list contains reserved registers: R2 | ||
| ; CHECK-NEXT: note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour. | ||
|
|
||
| @a = external global i32, align 4 | ||
|
|
||
| define void @bar() { | ||
| store i32 0, ptr @a, align 4 | ||
| call void asm sideeffect "li 2, 1", "~{r2}"() | ||
| ret void | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.