[llvm] [AMDGPU] Introduce isBottomOfStack helper. NFC (PR #74288)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 4 00:31:38 PST 2023
https://github.com/rovka created https://github.com/llvm/llvm-project/pull/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.
>From ee3b574ff9c76431cd6012c46f0fbafcdb4d2666 Mon Sep 17 00:00:00 2001
From: Diana Picus <Diana-Magda.Picus at amd.com>
Date: Mon, 13 Nov 2023 15:06:06 +0100
Subject: [PATCH] [AMDGPU] Introduce isBottomOfStack helper. NFC
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.
---
llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.h | 5 +++++
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp | 2 +-
llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp | 8 ++++----
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.h b/llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.h
index 06d4a6c0d0274..25c0b4953ab7f 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.h
@@ -90,6 +90,11 @@ class AMDGPUMachineFunction : public MachineFunctionInfo {
bool isChainFunction() const { return IsChainFunction; }
+ // The stack is empty upon entry to this function.
+ bool isBottomOfStack() const {
+ return isEntryFunction() || isChainFunction();
+ }
+
bool hasNoSignedZerosFPMath() const {
return NoSignedZerosFPMath;
}
diff --git a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
index 7645c6da03388..f8eb67199f623 100644
--- a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
@@ -519,7 +519,7 @@ int SIMachineFunctionInfo::getScavengeFI(MachineFrameInfo &MFI,
const SIRegisterInfo &TRI) {
if (ScavengeFI)
return *ScavengeFI;
- if (isEntryFunction() || isChainFunction()) {
+ if (isBottomOfStack()) {
ScavengeFI = MFI.CreateFixedObject(
TRI.getSpillSize(AMDGPU::SGPR_32RegClass), 0, false);
} else {
diff --git a/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp b/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
index abb7c41e3385a..877188f33befe 100644
--- a/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
@@ -503,7 +503,7 @@ Register SIRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
// functions, but never actually want to reference it when accessing our own
// frame. If we need a frame pointer we use it, but otherwise we can just use
// an immediate "0" which we represent by returning NoRegister.
- if (FuncInfo->isEntryFunction() || FuncInfo->isChainFunction()) {
+ if (FuncInfo->isBottomOfStack()) {
return TFI->hasFP(MF) ? FuncInfo->getFrameOffsetReg() : Register();
}
return TFI->hasFP(MF) ? FuncInfo->getFrameOffsetReg()
@@ -738,7 +738,7 @@ bool SIRegisterInfo::shouldRealignStack(const MachineFunction &MF) const {
// FIXME: Should be able to specify the entry frame alignment per calling
// convention instead.
- if (Info->isEntryFunction() || Info->isChainFunction())
+ if (Info->isBottomOfStack())
return false;
return TargetRegisterInfo::shouldRealignStack(MF);
@@ -1649,7 +1649,7 @@ void SIRegisterInfo::buildSpillLoadStore(
if (UseVGPROffset && ScratchOffsetReg) {
MIB.addReg(ScratchOffsetReg);
} else {
- assert(FuncInfo->isEntryFunction() || FuncInfo->isChainFunction());
+ assert(FuncInfo->isBottomOfStack());
MIB.addImm(0);
}
}
@@ -2424,7 +2424,7 @@ bool SIRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator MI,
bool IsMUBUF = TII->isMUBUF(*MI);
- if (!IsMUBUF && !MFI->isEntryFunction() && !MFI->isChainFunction()) {
+ if (!IsMUBUF && !MFI->isBottomOfStack()) {
// Convert to a swizzled stack address by scaling by the wave size.
// In an entry function/kernel the offset is already swizzled.
bool IsSALU = isSGPRClass(TII->getOpRegClass(*MI, FIOperandNum));
More information about the llvm-commits
mailing list