Skip to content

Commit ba38c92

Browse files
cdevadasSterling-Augustine
authored andcommitted
[AMDGPU] Merge the conditions used for deciding CS spills for amdgpu_cs_chain[_preserve] (llvm#109911)
Multiple conditions exist to decide whether callee save spills/restores are required for amdgpu_cs_chain or amdgpu_cs_chain_preserve calling conventions. This patch consolidates them all and moves to a single place.
1 parent e54ae3c commit ba38c92

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

llvm/lib/Target/AMDGPU/SIFrameLowering.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,20 +1342,10 @@ void SIFrameLowering::processFunctionBeforeFrameFinalized(
13421342
SIMachineFunctionInfo *FuncInfo = MF.getInfo<SIMachineFunctionInfo>();
13431343

13441344
// Allocate spill slots for WWM reserved VGPRs.
1345-
// For chain functions, we only need to do this if we have calls to
1346-
// llvm.amdgcn.cs.chain (otherwise there's no one to save them for, since
1347-
// chain functions do not return) and the function did not contain a call to
1348-
// llvm.amdgcn.init.whole.wave (since in that case there are no inactive lanes
1349-
// when entering the function).
1350-
bool IsChainWithoutRestores =
1351-
FuncInfo->isChainFunction() &&
1352-
(!MF.getFrameInfo().hasTailCall() || FuncInfo->hasInitWholeWave());
1353-
if (!FuncInfo->isEntryFunction() && !IsChainWithoutRestores) {
1354-
for (Register Reg : FuncInfo->getWWMReservedRegs()) {
1355-
const TargetRegisterClass *RC = TRI->getPhysRegBaseClass(Reg);
1356-
FuncInfo->allocateWWMSpill(MF, Reg, TRI->getSpillSize(*RC),
1357-
TRI->getSpillAlign(*RC));
1358-
}
1345+
for (Register Reg : FuncInfo->getWWMReservedRegs()) {
1346+
const TargetRegisterClass *RC = TRI->getPhysRegBaseClass(Reg);
1347+
FuncInfo->allocateWWMSpill(MF, Reg, TRI->getSpillSize(*RC),
1348+
TRI->getSpillAlign(*RC));
13591349
}
13601350

13611351
const bool SpillVGPRToAGPR = ST.hasMAIInsts() && FuncInfo->hasSpilledVGPRs()

llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,14 @@ void SIMachineFunctionInfo::allocateWWMSpill(MachineFunction &MF, Register VGPR,
287287
// amdgpu_cs_chain_preserve calling convention and this is a scratch register.
288288
// We never need to allocate a spill for these because we don't even need to
289289
// restore the inactive lanes for them (they're scratchier than the usual
290-
// scratch registers).
291-
if (isChainFunction() && SIRegisterInfo::isChainScratchRegister(VGPR))
290+
// scratch registers). We only need to do this if we have calls to
291+
// llvm.amdgcn.cs.chain (otherwise there's no one to save them for, since
292+
// chain functions do not return) and the function did not contain a call to
293+
// llvm.amdgcn.init.whole.wave (since in that case there are no inactive lanes
294+
// when entering the function).
295+
if (isChainFunction() &&
296+
(SIRegisterInfo::isChainScratchRegister(VGPR) ||
297+
!MF.getFrameInfo().hasTailCall() || hasInitWholeWave()))
292298
return;
293299

294300
WWMSpills.insert(std::make_pair(

0 commit comments

Comments
 (0)