Skip to content

[llvm] Consistently respect naked fn attribute in TargetFrameLowering::hasFP() #106014

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

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion llvm/include/llvm/CodeGen/TargetFrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ class TargetFrameLowering {
/// hasFP - Return true if the specified function should have a dedicated
/// frame pointer register. For most targets this is true only if the function
/// has variable sized allocas or if frame pointer elimination is disabled.
virtual bool hasFP(const MachineFunction &MF) const = 0;
/// For all targets, this is false if the function has the naked attribute
/// since there is no prologue to set up the frame pointer.
bool hasFP(const MachineFunction &MF) const {
return !MF.getFunction().hasFnAttribute(Attribute::Naked) && hasFPImpl(MF);
}

/// hasReservedCallFrame - Under normal circumstances, when a frame pointer is
/// not required, we reserve argument space for call sites in the function
Expand Down Expand Up @@ -477,6 +481,9 @@ class TargetFrameLowering {
/// targets can emit remarks based on the final frame layout.
virtual void emitRemarks(const MachineFunction &MF,
MachineOptimizationRemarkEmitter *ORE) const {};

protected:
virtual bool hasFPImpl(const MachineFunction &MF) const = 0;
};

} // End llvm namespace
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,9 @@ bool AArch64FrameLowering::canUseRedZone(const MachineFunction &MF) const {
getSVEStackSize(MF) || LowerQRegCopyThroughMem);
}

/// hasFP - Return true if the specified function should have a dedicated frame
/// pointer register.
bool AArch64FrameLowering::hasFP(const MachineFunction &MF) const {
/// hasFPImpl - Return true if the specified function should have a dedicated
/// frame pointer register.
bool AArch64FrameLowering::hasFPImpl(const MachineFunction &MF) const {
const MachineFrameInfo &MFI = MF.getFrameInfo();
const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();

Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/AArch64/AArch64FrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class AArch64FrameLowering : public TargetFrameLowering {
/// Can this function use the red zone for local allocations.
bool canUseRedZone(const MachineFunction &MF) const;

bool hasFP(const MachineFunction &MF) const override;
bool hasReservedCallFrame(const MachineFunction &MF) const override;

bool assignCalleeSavedSpillSlots(MachineFunction &MF,
Expand Down Expand Up @@ -125,6 +124,9 @@ class AArch64FrameLowering : public TargetFrameLowering {
orderFrameObjects(const MachineFunction &MF,
SmallVectorImpl<int> &ObjectsToAllocate) const override;

protected:
bool hasFPImpl(const MachineFunction &MF) const override;

private:
/// Returns true if a homogeneous prolog or epilog code can be emitted
/// for the size optimization. If so, HOM_Prolog/HOM_Epilog pseudo
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/AMDGPU/R600FrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ class R600FrameLowering : public AMDGPUFrameLowering {
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
Register &FrameReg) const override;

bool hasFP(const MachineFunction &MF) const override {
return false;
}
protected:
bool hasFPImpl(const MachineFunction &MF) const override { return false; }
};

} // end namespace llvm
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,7 @@ static bool frameTriviallyRequiresSP(const MachineFrameInfo &MFI) {
// The FP for kernels is always known 0, so we never really need to setup an
// explicit register for it. However, DisableFramePointerElim will force us to
// use a register for it.
bool SIFrameLowering::hasFP(const MachineFunction &MF) const {
bool SIFrameLowering::hasFPImpl(const MachineFunction &MF) const {
const MachineFrameInfo &MFI = MF.getFrameInfo();

// For entry & chain functions we can use an immediate offset in most cases,
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Target/AMDGPU/SIFrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class SIFrameLowering final : public AMDGPUFrameLowering {
MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI) const override;

protected:
bool hasFPImpl(const MachineFunction &MF) const override;

private:
void emitEntryFunctionFlatScratchInit(MachineFunction &MF,
MachineBasicBlock &MBB,
Expand All @@ -82,8 +85,6 @@ class SIFrameLowering final : public AMDGPUFrameLowering {
Register ScratchWaveOffsetReg) const;

public:
bool hasFP(const MachineFunction &MF) const override;

bool requiresStackPointerReference(const MachineFunction &MF) const;
};

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/ARC/ARCFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ MachineBasicBlock::iterator ARCFrameLowering::eliminateCallFramePseudoInstr(
return MBB.erase(I);
}

bool ARCFrameLowering::hasFP(const MachineFunction &MF) const {
bool ARCFrameLowering::hasFPImpl(const MachineFunction &MF) const {
const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
bool HasFP = MF.getTarget().Options.DisableFramePointerElim(MF) ||
MF.getFrameInfo().hasVarSizedObjects() ||
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Target/ARC/ARCFrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class ARCFrameLowering : public TargetFrameLowering {
void processFunctionBeforeFrameFinalized(MachineFunction &MF,
RegScavenger *RS) const override;

bool hasFP(const MachineFunction &MF) const override;

MachineBasicBlock::iterator
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
MachineBasicBlock::iterator I) const override;
Expand All @@ -64,6 +62,9 @@ class ARCFrameLowering : public TargetFrameLowering {
llvm::MachineFunction &, const llvm::TargetRegisterInfo *,
std::vector<llvm::CalleeSavedInfo> &) const override;

protected:
bool hasFPImpl(const MachineFunction &MF) const override;

private:
void adjustStackToMatchRecords(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI,
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Target/ARM/ARMFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@ bool ARMFrameLowering::enableCalleeSaveSkip(const MachineFunction &MF) const {
return true;
}

/// hasFP - Return true if the specified function should have a dedicated frame
/// pointer register. This is true if the function has variable sized allocas
/// or if frame pointer elimination is disabled.
bool ARMFrameLowering::hasFP(const MachineFunction &MF) const {
/// hasFPImpl - Return true if the specified function should have a dedicated
/// frame pointer register. This is true if the function has variable sized
/// allocas or if frame pointer elimination is disabled.
bool ARMFrameLowering::hasFPImpl(const MachineFunction &MF) const {
const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
const MachineFrameInfo &MFI = MF.getFrameInfo();

Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/ARM/ARMFrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class ARMFrameLowering : public TargetFrameLowering {

bool enableCalleeSaveSkip(const MachineFunction &MF) const override;

bool hasFP(const MachineFunction &MF) const override;
bool isFPReserved(const MachineFunction &MF) const;
bool requiresAAPCSFrameRecord(const MachineFunction &MF) const;
bool hasReservedCallFrame(const MachineFunction &MF) const override;
Expand Down Expand Up @@ -87,6 +86,9 @@ class ARMFrameLowering : public TargetFrameLowering {
const SpillSlot *
getCalleeSavedSpillSlots(unsigned &NumEntries) const override;

protected:
bool hasFPImpl(const MachineFunction &MF) const override;

private:
void emitPushInst(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
ArrayRef<CalleeSavedInfo> CSI, unsigned StmOpc,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AVR/AVRFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void AVRFrameLowering::emitEpilogue(MachineFunction &MF,
//
// Notice that strictly this is not a frame pointer because it contains SP after
// frame allocation instead of having the original SP in function entry.
bool AVRFrameLowering::hasFP(const MachineFunction &MF) const {
bool AVRFrameLowering::hasFPImpl(const MachineFunction &MF) const {
const AVRMachineFunctionInfo *FuncInfo = MF.getInfo<AVRMachineFunctionInfo>();

return (FuncInfo->getHasSpills() || FuncInfo->getHasAllocas() ||
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/AVR/AVRFrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class AVRFrameLowering : public TargetFrameLowering {
public:
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
bool hasFP(const MachineFunction &MF) const override;
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI,
ArrayRef<CalleeSavedInfo> CSI,
Expand All @@ -38,6 +37,9 @@ class AVRFrameLowering : public TargetFrameLowering {
MachineBasicBlock::iterator
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI) const override;

protected:
bool hasFPImpl(const MachineFunction &MF) const override;
};

} // end namespace llvm
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/BPF/BPFFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

using namespace llvm;

bool BPFFrameLowering::hasFP(const MachineFunction &MF) const { return true; }
bool BPFFrameLowering::hasFPImpl(const MachineFunction &MF) const {
return true;
}

void BPFFrameLowering::emitPrologue(MachineFunction &MF,
MachineBasicBlock &MBB) const {}
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/BPF/BPFFrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class BPFFrameLowering : public TargetFrameLowering {
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;

bool hasFP(const MachineFunction &MF) const override;
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
RegScavenger *RS) const override;

Expand All @@ -35,6 +34,9 @@ class BPFFrameLowering : public TargetFrameLowering {
MachineBasicBlock::iterator MI) const override {
return MBB.erase(MI);
}

protected:
bool hasFPImpl(const MachineFunction &MF) const override;
};
}
#endif
2 changes: 1 addition & 1 deletion llvm/lib/Target/CSKY/CSKYFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static Register getFPReg(const CSKYSubtarget &STI) { return CSKY::R8; }
// callee saved register to save the value.
static Register getBPReg(const CSKYSubtarget &STI) { return CSKY::R7; }

bool CSKYFrameLowering::hasFP(const MachineFunction &MF) const {
bool CSKYFrameLowering::hasFPImpl(const MachineFunction &MF) const {
const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();

const MachineFrameInfo &MFI = MF.getFrameInfo();
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/CSKY/CSKYFrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ class CSKYFrameLowering : public TargetFrameLowering {
MutableArrayRef<CalleeSavedInfo> CSI,
const TargetRegisterInfo *TRI) const override;

bool hasFP(const MachineFunction &MF) const override;
bool hasBP(const MachineFunction &MF) const;

bool hasReservedCallFrame(const MachineFunction &MF) const override;

MachineBasicBlock::iterator
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI) const override;

protected:
bool hasFPImpl(const MachineFunction &MF) const override;
};
} // namespace llvm
#endif
3 changes: 2 additions & 1 deletion llvm/lib/Target/DirectX/DirectXFrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class DirectXFrameLowering : public TargetFrameLowering {
void emitPrologue(MachineFunction &, MachineBasicBlock &) const override {}
void emitEpilogue(MachineFunction &, MachineBasicBlock &) const override {}

bool hasFP(const MachineFunction &) const override { return false; }
protected:
bool hasFPImpl(const MachineFunction &) const override { return false; }
};
} // namespace llvm
#endif // LLVM_DIRECTX_DIRECTXFRAMELOWERING_H
5 changes: 1 addition & 4 deletions llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,10 +1144,7 @@ void HexagonFrameLowering::insertCFIInstructionsAt(MachineBasicBlock &MBB,
}
}

bool HexagonFrameLowering::hasFP(const MachineFunction &MF) const {
if (MF.getFunction().hasFnAttribute(Attribute::Naked))
return false;

bool HexagonFrameLowering::hasFPImpl(const MachineFunction &MF) const {
auto &MFI = MF.getFrameInfo();
auto &HRI = *MF.getSubtarget<HexagonSubtarget>().getRegisterInfo();
bool HasExtraAlign = HRI.hasStackRealignment(MF);
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/Hexagon/HexagonFrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class HexagonFrameLowering : public TargetFrameLowering {

StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
Register &FrameReg) const override;
bool hasFP(const MachineFunction &MF) const override;

const SpillSlot *getCalleeSavedSpillSlots(unsigned &NumEntries)
const override {
Expand All @@ -114,6 +113,9 @@ class HexagonFrameLowering : public TargetFrameLowering {

void insertCFIInstructions(MachineFunction &MF) const;

protected:
bool hasFPImpl(const MachineFunction &MF) const override;

private:
using CSIVect = std::vector<CalleeSavedInfo>;

Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Target/Lanai/LanaiFrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ class LanaiFrameLowering : public TargetFrameLowering {
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
MachineBasicBlock::iterator I) const override;

bool hasFP(const MachineFunction & /*MF*/) const override { return true; }

void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
RegScavenger *RS = nullptr) const override;

protected:
bool hasFPImpl(const MachineFunction & /*MF*/) const override { return true; }
};

} // namespace llvm
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/LoongArch/LoongArchFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using namespace llvm;
// pointer register. This is true if frame pointer elimination is
// disabled, if it needs dynamic stack realignment, if the function has
// variable sized allocas, or if the frame address is taken.
bool LoongArchFrameLowering::hasFP(const MachineFunction &MF) const {
bool LoongArchFrameLowering::hasFPImpl(const MachineFunction &MF) const {
const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();

const MachineFrameInfo &MFI = MF.getFrameInfo();
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/LoongArch/LoongArchFrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ class LoongArchFrameLowering : public TargetFrameLowering {
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
Register &FrameReg) const override;

bool hasFP(const MachineFunction &MF) const override;
bool hasBP(const MachineFunction &MF) const;

uint64_t getFirstSPAdjustAmount(const MachineFunction &MF) const;

bool enableShrinkWrapping(const MachineFunction &MF) const override;

protected:
bool hasFPImpl(const MachineFunction &MF) const override;

private:
void determineFrameLayout(MachineFunction &MF) const;
void adjustReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/M68k/M68kFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ M68kFrameLowering::M68kFrameLowering(const M68kSubtarget &STI, Align Alignment)
StackPtr = TRI->getStackRegister();
}

bool M68kFrameLowering::hasFP(const MachineFunction &MF) const {
bool M68kFrameLowering::hasFPImpl(const MachineFunction &MF) const {
const MachineFrameInfo &MFI = MF.getFrameInfo();
const TargetRegisterInfo *TRI = STI.getRegisterInfo();

Expand Down
13 changes: 7 additions & 6 deletions llvm/lib/Target/M68k/M68kFrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ class M68kFrameLowering : public TargetFrameLowering {
MutableArrayRef<CalleeSavedInfo> CSI,
const TargetRegisterInfo *TRI) const override;

/// Return true if the specified function should have a dedicated frame
/// pointer register. This is true if the function has variable sized
/// allocas, if it needs dynamic stack realignment, if frame pointer
/// elimination is disabled, or if the frame address is taken.
bool hasFP(const MachineFunction &MF) const override;

/// Under normal circumstances, when a frame pointer is not required, we
/// reserve argument space for call sites in the function immediately on
/// entry to the current function. This eliminates the need for add/sub sp
Expand Down Expand Up @@ -166,6 +160,13 @@ class M68kFrameLowering : public TargetFrameLowering {
/// pointer by a constant value.
void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI,
int64_t NumBytes, bool InEpilogue) const;

protected:
/// Return true if the specified function should have a dedicated frame
/// pointer register. This is true if the function has variable sized
/// allocas, if it needs dynamic stack realignment, if frame pointer
/// elimination is disabled, or if the frame address is taken.
bool hasFPImpl(const MachineFunction &MF) const override;
};
} // namespace llvm

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/MSP430/MSP430FrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ MSP430FrameLowering::MSP430FrameLowering(const MSP430Subtarget &STI)
Align(2)),
STI(STI), TII(*STI.getInstrInfo()), TRI(STI.getRegisterInfo()) {}

bool MSP430FrameLowering::hasFP(const MachineFunction &MF) const {
bool MSP430FrameLowering::hasFPImpl(const MachineFunction &MF) const {
const MachineFrameInfo &MFI = MF.getFrameInfo();

return (MF.getTarget().Options.DisableFramePointerElim(MF) ||
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/MSP430/MSP430FrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MSP430RegisterInfo;

class MSP430FrameLowering : public TargetFrameLowering {
protected:
bool hasFPImpl(const MachineFunction &MF) const override;

public:
MSP430FrameLowering(const MSP430Subtarget &STI);
Expand Down Expand Up @@ -51,7 +52,6 @@ class MSP430FrameLowering : public TargetFrameLowering {
MutableArrayRef<CalleeSavedInfo> CSI,
const TargetRegisterInfo *TRI) const override;

bool hasFP(const MachineFunction &MF) const override;
bool hasReservedCallFrame(const MachineFunction &MF) const override;
void processFunctionBeforeFrameFinalized(MachineFunction &MF,
RegScavenger *RS = nullptr) const override;
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Target/Mips/MipsFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ const MipsFrameLowering *MipsFrameLowering::create(const MipsSubtarget &ST) {
return llvm::createMipsSEFrameLowering(ST);
}

// hasFP - Return true if the specified function should have a dedicated frame
// pointer register. This is true if the function has variable sized allocas,
// if it needs dynamic stack realignment, if frame pointer elimination is
// disabled, or if the frame address is taken.
bool MipsFrameLowering::hasFP(const MachineFunction &MF) const {
// hasFPImpl - Return true if the specified function should have a dedicated
// frame pointer register. This is true if the function has variable sized
// allocas, if it needs dynamic stack realignment, if frame pointer elimination
// is disabled, or if the frame address is taken.
bool MipsFrameLowering::hasFPImpl(const MachineFunction &MF) const {
const MachineFrameInfo &MFI = MF.getFrameInfo();
const TargetRegisterInfo *TRI = STI.getRegisterInfo();

Expand Down
Loading
Loading