Skip to content

Commit 8ff054d

Browse files
committed
[llvm] Consistently respect naked fn attribute in TargetFrameLowering::hasFP().
Some targets (e.g. PPC and Hexagon) already did this. I think it's best to do this consistently so that frontend authors don't run into inconsistent results when they emit naked functions. For example, in Zig, we had to change our emit code to also set frame-pointer=none to get reliable results across targets.
1 parent 675c748 commit 8ff054d

17 files changed

+90
-0
lines changed

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,11 @@ bool AArch64FrameLowering::canUseRedZone(const MachineFunction &MF) const {
478478
/// hasFP - Return true if the specified function should have a dedicated frame
479479
/// pointer register.
480480
bool AArch64FrameLowering::hasFP(const MachineFunction &MF) const {
481+
// Naked functions have no stack frame pushed, so we don't have a frame
482+
// pointer.
483+
if (MF.getFunction().hasFnAttribute(Attribute::Naked))
484+
return false;
485+
481486
const MachineFrameInfo &MFI = MF.getFrameInfo();
482487
const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
483488

llvm/lib/Target/ARC/ARCFrameLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,11 @@ MachineBasicBlock::iterator ARCFrameLowering::eliminateCallFramePseudoInstr(
488488
}
489489

490490
bool ARCFrameLowering::hasFP(const MachineFunction &MF) const {
491+
// Naked functions have no stack frame pushed, so we don't have a frame
492+
// pointer.
493+
if (MF.getFunction().hasFnAttribute(Attribute::Naked))
494+
return false;
495+
491496
const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
492497
bool HasFP = MF.getTarget().Options.DisableFramePointerElim(MF) ||
493498
MF.getFrameInfo().hasVarSizedObjects() ||

llvm/lib/Target/ARM/ARMFrameLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ bool ARMFrameLowering::enableCalleeSaveSkip(const MachineFunction &MF) const {
200200
/// pointer register. This is true if the function has variable sized allocas
201201
/// or if frame pointer elimination is disabled.
202202
bool ARMFrameLowering::hasFP(const MachineFunction &MF) const {
203+
// Naked functions have no stack frame pushed, so we don't have a frame
204+
// pointer.
205+
if (MF.getFunction().hasFnAttribute(Attribute::Naked))
206+
return false;
207+
203208
const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
204209
const MachineFrameInfo &MFI = MF.getFrameInfo();
205210

llvm/lib/Target/AVR/AVRFrameLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ void AVRFrameLowering::emitEpilogue(MachineFunction &MF,
233233
// Notice that strictly this is not a frame pointer because it contains SP after
234234
// frame allocation instead of having the original SP in function entry.
235235
bool AVRFrameLowering::hasFP(const MachineFunction &MF) const {
236+
// Naked functions have no stack frame pushed, so we don't have a frame
237+
// pointer.
238+
if (MF.getFunction().hasFnAttribute(Attribute::Naked))
239+
return false;
240+
236241
const AVRMachineFunctionInfo *FuncInfo = MF.getInfo<AVRMachineFunctionInfo>();
237242

238243
return (FuncInfo->getHasSpills() || FuncInfo->getHasAllocas() ||

llvm/lib/Target/CSKY/CSKYFrameLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ static Register getFPReg(const CSKYSubtarget &STI) { return CSKY::R8; }
3434
static Register getBPReg(const CSKYSubtarget &STI) { return CSKY::R7; }
3535

3636
bool CSKYFrameLowering::hasFP(const MachineFunction &MF) const {
37+
// Naked functions have no stack frame pushed, so we don't have a frame
38+
// pointer.
39+
if (MF.getFunction().hasFnAttribute(Attribute::Naked))
40+
return false;
41+
3742
const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
3843

3944
const MachineFrameInfo &MFI = MF.getFrameInfo();

llvm/lib/Target/LoongArch/LoongArchFrameLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ using namespace llvm;
3232
// disabled, if it needs dynamic stack realignment, if the function has
3333
// variable sized allocas, or if the frame address is taken.
3434
bool LoongArchFrameLowering::hasFP(const MachineFunction &MF) const {
35+
// Naked functions have no stack frame pushed, so we don't have a frame
36+
// pointer.
37+
if (MF.getFunction().hasFnAttribute(Attribute::Naked))
38+
return false;
39+
3540
const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
3641

3742
const MachineFrameInfo &MFI = MF.getFrameInfo();

llvm/lib/Target/M68k/M68kFrameLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ M68kFrameLowering::M68kFrameLowering(const M68kSubtarget &STI, Align Alignment)
4141
}
4242

4343
bool M68kFrameLowering::hasFP(const MachineFunction &MF) const {
44+
// Naked functions have no stack frame pushed, so we don't have a frame
45+
// pointer.
46+
if (MF.getFunction().hasFnAttribute(Attribute::Naked))
47+
return false;
48+
4449
const MachineFrameInfo &MFI = MF.getFrameInfo();
4550
const TargetRegisterInfo *TRI = STI.getRegisterInfo();
4651

llvm/lib/Target/MSP430/MSP430FrameLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ MSP430FrameLowering::MSP430FrameLowering(const MSP430Subtarget &STI)
3131
STI(STI), TII(*STI.getInstrInfo()), TRI(STI.getRegisterInfo()) {}
3232

3333
bool MSP430FrameLowering::hasFP(const MachineFunction &MF) const {
34+
// Naked functions have no stack frame pushed, so we don't have a frame
35+
// pointer.
36+
if (MF.getFunction().hasFnAttribute(Attribute::Naked))
37+
return false;
38+
3439
const MachineFrameInfo &MFI = MF.getFrameInfo();
3540

3641
return (MF.getTarget().Options.DisableFramePointerElim(MF) ||

llvm/lib/Target/Mips/MipsFrameLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ const MipsFrameLowering *MipsFrameLowering::create(const MipsSubtarget &ST) {
9191
// if it needs dynamic stack realignment, if frame pointer elimination is
9292
// disabled, or if the frame address is taken.
9393
bool MipsFrameLowering::hasFP(const MachineFunction &MF) const {
94+
// Naked functions have no stack frame pushed, so we don't have a frame
95+
// pointer.
96+
if (MF.getFunction().hasFnAttribute(Attribute::Naked))
97+
return false;
98+
9499
const MachineFrameInfo &MFI = MF.getFrameInfo();
95100
const TargetRegisterInfo *TRI = STI.getRegisterInfo();
96101

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ static Register getMaxPushPopReg(const MachineFunction &MF,
310310
// disabled, if it needs dynamic stack realignment, if the function has
311311
// variable sized allocas, or if the frame address is taken.
312312
bool RISCVFrameLowering::hasFP(const MachineFunction &MF) const {
313+
// Naked functions have no stack frame pushed, so we don't have a frame
314+
// pointer.
315+
if (MF.getFunction().hasFnAttribute(Attribute::Naked))
316+
return false;
317+
313318
const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
314319

315320
const MachineFrameInfo &MFI = MF.getFrameInfo();

0 commit comments

Comments
 (0)