Skip to content

Commit 84692ce

Browse files
committed
[AMDGPU] Remove duplicated/confusing helpers. NFCI
Move canGuaranteeTCO and mayTailCallThisCC into AMDGPUBaseInfo instead of keeping two copies for DAG/Global ISel. Also remove isKernelCC, which doesn't agree with isKernel and doesn't seem very useful.
1 parent c9968f4 commit 84692ce

File tree

6 files changed

+22
-48
lines changed

6 files changed

+22
-48
lines changed

llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,22 +1090,6 @@ bool AMDGPUCallLowering::areCalleeOutgoingArgsTailCallable(
10901090
return parametersInCSRMatch(MRI, CallerPreservedMask, OutLocs, OutArgs);
10911091
}
10921092

1093-
/// Return true if the calling convention is one that we can guarantee TCO for.
1094-
static bool canGuaranteeTCO(CallingConv::ID CC) {
1095-
return CC == CallingConv::Fast;
1096-
}
1097-
1098-
/// Return true if we might ever do TCO for calls with this calling convention.
1099-
static bool mayTailCallThisCC(CallingConv::ID CC) {
1100-
switch (CC) {
1101-
case CallingConv::C:
1102-
case CallingConv::AMDGPU_Gfx:
1103-
return true;
1104-
default:
1105-
return canGuaranteeTCO(CC);
1106-
}
1107-
}
1108-
11091093
bool AMDGPUCallLowering::isEligibleForTailCallOptimization(
11101094
MachineIRBuilder &B, CallLoweringInfo &Info,
11111095
SmallVectorImpl<ArgInfo> &InArgs, SmallVectorImpl<ArgInfo> &OutArgs) const {
@@ -1130,7 +1114,7 @@ bool AMDGPUCallLowering::isEligibleForTailCallOptimization(
11301114
if (!CallerPreserved)
11311115
return false;
11321116

1133-
if (!mayTailCallThisCC(CalleeCC)) {
1117+
if (!AMDGPU::mayTailCallThisCC(CalleeCC)) {
11341118
LLVM_DEBUG(dbgs() << "... Calling convention cannot be tail called.\n");
11351119
return false;
11361120
}
@@ -1145,7 +1129,8 @@ bool AMDGPUCallLowering::isEligibleForTailCallOptimization(
11451129

11461130
// If we have -tailcallopt, then we're done.
11471131
if (MF.getTarget().Options.GuaranteedTailCallOpt)
1148-
return canGuaranteeTCO(CalleeCC) && CalleeCC == CallerF.getCallingConv();
1132+
return AMDGPU::canGuaranteeTCO(CalleeCC) &&
1133+
CalleeCC == CallerF.getCallingConv();
11491134

11501135
// Verify that the incoming and outgoing arguments from the callee are
11511136
// safe to tail call.

llvm/lib/Target/AMDGPU/AMDGPUMemoryUtils.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,6 @@ void getUsesOfLDSByFunction(const CallGraph &CG, Module &M,
125125
}
126126

127127
bool isKernelLDS(const Function *F) {
128-
// Some weirdness here. AMDGPU::isKernelCC does not call into
129-
// AMDGPU::isKernel with the calling conv, it instead calls into
130-
// isModuleEntryFunction which returns true for more calling conventions
131-
// than AMDGPU::isKernel does. There's a FIXME on AMDGPU::isKernel.
132-
// There's also a test that checks that the LDS lowering does not hit on
133-
// a graphics shader, denoted amdgpu_ps, so stay with the limited case.
134-
// Putting LDS in the name of the function to draw attention to this.
135128
return AMDGPU::isKernel(F->getCallingConv());
136129
}
137130

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,9 @@ bool AMDGPUTargetMachine::isNoopAddrSpaceCast(unsigned SrcAS,
978978

979979
unsigned AMDGPUTargetMachine::getAssumedAddrSpace(const Value *V) const {
980980
if (auto *Arg = dyn_cast<Argument>(V);
981-
Arg && AMDGPU::isKernelCC(Arg->getParent()) && !Arg->hasByRefAttr())
981+
Arg &&
982+
AMDGPU::isModuleEntryFunctionCC(Arg->getParent()->getCallingConv()) &&
983+
!Arg->hasByRefAttr())
982984
return AMDGPUAS::GLOBAL_ADDRESS;
983985

984986
const auto *LD = dyn_cast<LoadInst>(V);

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3574,21 +3574,6 @@ void SITargetLowering::passSpecialInputs(
35743574
}
35753575
}
35763576

3577-
static bool canGuaranteeTCO(CallingConv::ID CC) {
3578-
return CC == CallingConv::Fast;
3579-
}
3580-
3581-
/// Return true if we might ever do TCO for calls with this calling convention.
3582-
static bool mayTailCallThisCC(CallingConv::ID CC) {
3583-
switch (CC) {
3584-
case CallingConv::C:
3585-
case CallingConv::AMDGPU_Gfx:
3586-
return true;
3587-
default:
3588-
return canGuaranteeTCO(CC);
3589-
}
3590-
}
3591-
35923577
bool SITargetLowering::isEligibleForTailCallOptimization(
35933578
SDValue Callee, CallingConv::ID CalleeCC, bool IsVarArg,
35943579
const SmallVectorImpl<ISD::OutputArg> &Outs,
@@ -3597,7 +3582,7 @@ bool SITargetLowering::isEligibleForTailCallOptimization(
35973582
if (AMDGPU::isChainCC(CalleeCC))
35983583
return true;
35993584

3600-
if (!mayTailCallThisCC(CalleeCC))
3585+
if (!AMDGPU::mayTailCallThisCC(CalleeCC))
36013586
return false;
36023587

36033588
// For a divergent call target, we need to do a waterfall loop over the
@@ -3619,7 +3604,7 @@ bool SITargetLowering::isEligibleForTailCallOptimization(
36193604
bool CCMatch = CallerCC == CalleeCC;
36203605

36213606
if (DAG.getTarget().Options.GuaranteedTailCallOpt) {
3622-
if (canGuaranteeTCO(CalleeCC) && CCMatch)
3607+
if (AMDGPU::canGuaranteeTCO(CalleeCC) && CCMatch)
36233608
return true;
36243609
return false;
36253610
}

llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,8 +2185,16 @@ bool isChainCC(CallingConv::ID CC) {
21852185
}
21862186
}
21872187

2188-
bool isKernelCC(const Function *Func) {
2189-
return AMDGPU::isModuleEntryFunctionCC(Func->getCallingConv());
2188+
bool canGuaranteeTCO(CallingConv::ID CC) { return CC == CallingConv::Fast; }
2189+
2190+
bool mayTailCallThisCC(CallingConv::ID CC) {
2191+
switch (CC) {
2192+
case CallingConv::C:
2193+
case CallingConv::AMDGPU_Gfx:
2194+
return true;
2195+
default:
2196+
return canGuaranteeTCO(CC);
2197+
}
21902198
}
21912199

21922200
bool hasXNACK(const MCSubtargetInfo &STI) {

llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,9 +1329,6 @@ bool isModuleEntryFunctionCC(CallingConv::ID CC);
13291329
LLVM_READNONE
13301330
bool isChainCC(CallingConv::ID CC);
13311331

1332-
bool isKernelCC(const Function *Func);
1333-
1334-
// FIXME: Remove this when calling conventions cleaned up
13351332
LLVM_READNONE
13361333
inline bool isKernel(CallingConv::ID CC) {
13371334
switch (CC) {
@@ -1343,6 +1340,10 @@ inline bool isKernel(CallingConv::ID CC) {
13431340
}
13441341
}
13451342

1343+
/// Return true if we might ever do TCO for calls with this calling convention.
1344+
bool mayTailCallThisCC(CallingConv::ID CC);
1345+
bool canGuaranteeTCO(CallingConv::ID CC);
1346+
13461347
bool hasXNACK(const MCSubtargetInfo &STI);
13471348
bool hasSRAMECC(const MCSubtargetInfo &STI);
13481349
bool hasMIMG_R128(const MCSubtargetInfo &STI);

0 commit comments

Comments
 (0)