Skip to content

Commit 40d802a

Browse files
authored
[AMDGPU] Introduce isBottomOfStack helper. NFC (#74288)
Introduce a helper to check if a function is at the bottom of the stack, i.e. if it's an entry function or a chain function. This was suggested in #71913.
1 parent bb4484d commit 40d802a

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ class AMDGPUMachineFunction : public MachineFunctionInfo {
9090

9191
bool isChainFunction() const { return IsChainFunction; }
9292

93+
// The stack is empty upon entry to this function.
94+
bool isBottomOfStack() const {
95+
return isEntryFunction() || isChainFunction();
96+
}
97+
9398
bool hasNoSignedZerosFPMath() const {
9499
return NoSignedZerosFPMath;
95100
}

llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ int SIMachineFunctionInfo::getScavengeFI(MachineFrameInfo &MFI,
519519
const SIRegisterInfo &TRI) {
520520
if (ScavengeFI)
521521
return *ScavengeFI;
522-
if (isEntryFunction() || isChainFunction()) {
522+
if (isBottomOfStack()) {
523523
ScavengeFI = MFI.CreateFixedObject(
524524
TRI.getSpillSize(AMDGPU::SGPR_32RegClass), 0, false);
525525
} else {

llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ Register SIRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
503503
// functions, but never actually want to reference it when accessing our own
504504
// frame. If we need a frame pointer we use it, but otherwise we can just use
505505
// an immediate "0" which we represent by returning NoRegister.
506-
if (FuncInfo->isEntryFunction() || FuncInfo->isChainFunction()) {
506+
if (FuncInfo->isBottomOfStack()) {
507507
return TFI->hasFP(MF) ? FuncInfo->getFrameOffsetReg() : Register();
508508
}
509509
return TFI->hasFP(MF) ? FuncInfo->getFrameOffsetReg()
@@ -738,7 +738,7 @@ bool SIRegisterInfo::shouldRealignStack(const MachineFunction &MF) const {
738738

739739
// FIXME: Should be able to specify the entry frame alignment per calling
740740
// convention instead.
741-
if (Info->isEntryFunction() || Info->isChainFunction())
741+
if (Info->isBottomOfStack())
742742
return false;
743743

744744
return TargetRegisterInfo::shouldRealignStack(MF);
@@ -1649,7 +1649,7 @@ void SIRegisterInfo::buildSpillLoadStore(
16491649
if (UseVGPROffset && ScratchOffsetReg) {
16501650
MIB.addReg(ScratchOffsetReg);
16511651
} else {
1652-
assert(FuncInfo->isEntryFunction() || FuncInfo->isChainFunction());
1652+
assert(FuncInfo->isBottomOfStack());
16531653
MIB.addImm(0);
16541654
}
16551655
}
@@ -2424,7 +2424,7 @@ bool SIRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator MI,
24242424

24252425
bool IsMUBUF = TII->isMUBUF(*MI);
24262426

2427-
if (!IsMUBUF && !MFI->isEntryFunction() && !MFI->isChainFunction()) {
2427+
if (!IsMUBUF && !MFI->isBottomOfStack()) {
24282428
// Convert to a swizzled stack address by scaling by the wave size.
24292429
// In an entry function/kernel the offset is already swizzled.
24302430
bool IsSALU = isSGPRClass(TII->getOpRegClass(*MI, FIOperandNum));

0 commit comments

Comments
 (0)