Skip to content

Commit 1c3b10f

Browse files
authored
[AMDGPU] Remove isKernelLDS, add isKernel(const Function &). NFC. (#167300)
Since #142598 isKernelLDS has been a pointless wrapper around isKernel.
1 parent 177e382 commit 1c3b10f

File tree

9 files changed

+29
-33
lines changed

9 files changed

+29
-33
lines changed

llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7724,7 +7724,7 @@ bool AMDGPULegalizerInfo::legalizeIntrinsic(LegalizerHelper &Helper,
77247724
case Intrinsic::amdgcn_make_buffer_rsrc:
77257725
return legalizePointerAsRsrcIntrin(MI, MRI, B);
77267726
case Intrinsic::amdgcn_kernarg_segment_ptr:
7727-
if (!AMDGPU::isKernel(B.getMF().getFunction().getCallingConv())) {
7727+
if (!AMDGPU::isKernel(B.getMF().getFunction())) {
77287728
// This only makes sense to call in a kernel, so just lower to null.
77297729
B.buildConstant(MI.getOperand(0).getReg(), 0);
77307730
MI.eraseFromParent();

llvm/lib/Target/AMDGPU/AMDGPULowerExecSync.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static GlobalVariable *uniquifyGVPerKernel(Module &M, GlobalVariable *GV,
4444
for (Use &U : GV->uses()) {
4545
if (auto *I = dyn_cast<Instruction>(U.getUser())) {
4646
Function *F = I->getFunction();
47-
if (isKernelLDS(F) && F != KF) {
47+
if (isKernel(*F) && F != KF) {
4848
NeedsReplacement = true;
4949
break;
5050
}
@@ -61,7 +61,7 @@ static GlobalVariable *uniquifyGVPerKernel(Module &M, GlobalVariable *GV,
6161
for (Use &U : make_early_inc_range(GV->uses())) {
6262
if (auto *I = dyn_cast<Instruction>(U.getUser())) {
6363
Function *F = I->getFunction();
64-
if (!isKernelLDS(F) || F == KF) {
64+
if (!isKernel(*F) || F == KF) {
6565
U.getUser()->replaceUsesOfWith(GV, NewGV);
6666
}
6767
}
@@ -133,7 +133,7 @@ static bool lowerExecSyncGlobalVariables(
133133
SmallVector<Function *> OrderedKernels;
134134
for (auto &K : LDSUsesInfo.direct_access) {
135135
Function *F = K.first;
136-
assert(isKernelLDS(F));
136+
assert(isKernel(*F));
137137
OrderedKernels.push_back(F);
138138
}
139139
OrderedKernels = sortByName(std::move(OrderedKernels));
@@ -169,7 +169,7 @@ static bool lowerExecSyncGlobalVariables(
169169
}
170170
// Also erase those special LDS variables from indirect_access.
171171
for (auto &K : LDSUsesInfo.indirect_access) {
172-
assert(isKernelLDS(K.first));
172+
assert(isKernel(*K.first));
173173
for (GlobalVariable *GV : K.second) {
174174
if (isNamedBarrier(*GV))
175175
K.second.erase(GV);
@@ -191,7 +191,7 @@ static bool runLowerExecSyncGlobals(Module &M) {
191191
VariableFunctionMap LDSToKernelsThatNeedToAccessItIndirectly;
192192
for (auto &K : LDSUsesInfo.indirect_access) {
193193
Function *F = K.first;
194-
assert(isKernelLDS(F));
194+
assert(isKernel(*F));
195195
for (GlobalVariable *GV : K.second) {
196196
LDSToKernelsThatNeedToAccessItIndirectly[GV].insert(F);
197197
}

llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ class AMDGPULowerModuleLDS {
441441
return KernelSet;
442442

443443
for (Function &Func : M.functions()) {
444-
if (Func.isDeclaration() || !isKernelLDS(&Func))
444+
if (Func.isDeclaration() || !isKernel(Func))
445445
continue;
446446
for (GlobalVariable *GV : LDSUsesInfo.indirect_access[&Func]) {
447447
if (VariableSet.contains(GV)) {
@@ -555,7 +555,7 @@ class AMDGPULowerModuleLDS {
555555
for (Function &Func : M->functions()) {
556556
if (Func.isDeclaration())
557557
continue;
558-
if (!isKernelLDS(&Func))
558+
if (!isKernel(Func))
559559
continue;
560560

561561
if (KernelsThatAllocateTableLDS.contains(&Func) ||
@@ -703,15 +703,15 @@ class AMDGPULowerModuleLDS {
703703
return false;
704704
}
705705
Function *F = I->getFunction();
706-
return !isKernelLDS(F);
706+
return !isKernel(*F);
707707
});
708708

709709
// Replace uses of module scope variable from kernel functions that
710710
// allocate the module scope variable, otherwise leave them unchanged
711711
// Record on each kernel whether the module scope global is used by it
712712

713713
for (Function &Func : M.functions()) {
714-
if (Func.isDeclaration() || !isKernelLDS(&Func))
714+
if (Func.isDeclaration() || !isKernel(Func))
715715
continue;
716716

717717
if (KernelsThatAllocateModuleLDS.contains(&Func)) {
@@ -743,7 +743,7 @@ class AMDGPULowerModuleLDS {
743743

744744
DenseMap<Function *, LDSVariableReplacement> KernelToReplacement;
745745
for (Function &Func : M.functions()) {
746-
if (Func.isDeclaration() || !isKernelLDS(&Func))
746+
if (Func.isDeclaration() || !isKernel(Func))
747747
continue;
748748

749749
DenseSet<GlobalVariable *> KernelUsedVariables;
@@ -828,7 +828,7 @@ class AMDGPULowerModuleLDS {
828828
// semantics. Setting the alignment here allows this IR pass to accurately
829829
// predict the exact constant at which it will be allocated.
830830

831-
assert(isKernelLDS(func));
831+
assert(isKernel(*func));
832832

833833
LLVMContext &Ctx = M.getContext();
834834
const DataLayout &DL = M.getDataLayout();
@@ -878,7 +878,7 @@ class AMDGPULowerModuleLDS {
878878
for (auto &func : OrderedKernels) {
879879

880880
if (KernelsThatIndirectlyAllocateDynamicLDS.contains(func)) {
881-
assert(isKernelLDS(func));
881+
assert(isKernel(*func));
882882
if (!func->hasName()) {
883883
reportFatalUsageError("anonymous kernels cannot use LDS variables");
884884
}
@@ -912,7 +912,7 @@ class AMDGPULowerModuleLDS {
912912
auto *I = dyn_cast<Instruction>(U.getUser());
913913
if (!I)
914914
continue;
915-
if (isKernelLDS(I->getFunction()))
915+
if (isKernel(*I->getFunction()))
916916
continue;
917917

918918
replaceUseWithTableLookup(M, Builder, table, GV, U, nullptr);
@@ -938,7 +938,7 @@ class AMDGPULowerModuleLDS {
938938
VariableFunctionMap LDSToKernelsThatNeedToAccessItIndirectly;
939939
for (auto &K : LDSUsesInfo.indirect_access) {
940940
Function *F = K.first;
941-
assert(isKernelLDS(F));
941+
assert(isKernel(*F));
942942
for (GlobalVariable *GV : K.second) {
943943
LDSToKernelsThatNeedToAccessItIndirectly[GV].insert(F);
944944
}
@@ -1031,7 +1031,7 @@ class AMDGPULowerModuleLDS {
10311031
const DataLayout &DL = M.getDataLayout();
10321032

10331033
for (Function &Func : M.functions()) {
1034-
if (Func.isDeclaration() || !isKernelLDS(&Func))
1034+
if (Func.isDeclaration() || !isKernel(Func))
10351035
continue;
10361036

10371037
// All three of these are optional. The first variable is allocated at

llvm/lib/Target/AMDGPU/AMDGPUMemoryUtils.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void getUsesOfLDSByFunction(const CallGraph &CG, Module &M,
126126
for (User *V : GV.users()) {
127127
if (auto *I = dyn_cast<Instruction>(V)) {
128128
Function *F = I->getFunction();
129-
if (isKernelLDS(F))
129+
if (isKernel(*F))
130130
kernels[F].insert(&GV);
131131
else
132132
Functions[F].insert(&GV);
@@ -135,10 +135,6 @@ void getUsesOfLDSByFunction(const CallGraph &CG, Module &M,
135135
}
136136
}
137137

138-
bool isKernelLDS(const Function *F) {
139-
return AMDGPU::isKernel(F->getCallingConv());
140-
}
141-
142138
LDSUsesInfoTy getTransitiveUsesOfLDS(const CallGraph &CG, Module &M) {
143139

144140
FunctionVariableMap DirectMapKernel;
@@ -148,7 +144,7 @@ LDSUsesInfoTy getTransitiveUsesOfLDS(const CallGraph &CG, Module &M) {
148144
// Collect functions whose address has escaped
149145
DenseSet<Function *> AddressTakenFuncs;
150146
for (Function &F : M.functions()) {
151-
if (!isKernelLDS(&F))
147+
if (!isKernel(F))
152148
if (F.hasAddressTaken(nullptr,
153149
/* IgnoreCallbackUses */ false,
154150
/* IgnoreAssumeLikeCalls */ false,
@@ -180,7 +176,7 @@ LDSUsesInfoTy getTransitiveUsesOfLDS(const CallGraph &CG, Module &M) {
180176
// access all variables accessed by functions whose address escaped
181177
for (Function &F : M.functions()) {
182178
if (!F.isDeclaration() && FunctionMakesUnknownCall(&F)) {
183-
if (!isKernelLDS(&F)) {
179+
if (!isKernel(F)) {
184180
set_union(TransitiveMapFunction[&F],
185181
VariablesReachableThroughFunctionPointer);
186182
}
@@ -190,7 +186,7 @@ LDSUsesInfoTy getTransitiveUsesOfLDS(const CallGraph &CG, Module &M) {
190186
// Direct implementation of collecting all variables reachable from each
191187
// function
192188
for (Function &Func : M.functions()) {
193-
if (Func.isDeclaration() || isKernelLDS(&Func))
189+
if (Func.isDeclaration() || isKernel(Func))
194190
continue;
195191

196192
DenseSet<Function *> seen; // catches cycles
@@ -227,7 +223,7 @@ LDSUsesInfoTy getTransitiveUsesOfLDS(const CallGraph &CG, Module &M) {
227223
FunctionVariableMap IndirectMapKernel;
228224

229225
for (Function &Func : M.functions()) {
230-
if (Func.isDeclaration() || !isKernelLDS(&Func))
226+
if (Func.isDeclaration() || !isKernel(Func))
231227
continue;
232228

233229
for (const CallGraphNode::CallRecord &R : *CG[&Func]) {
@@ -341,7 +337,7 @@ void removeFnAttrFromReachable(CallGraph &CG, Function *KernelRoot,
341337
Function *PotentialCallee =
342338
ExternalCallRecord.second->getFunction();
343339
assert(PotentialCallee);
344-
if (!isKernelLDS(PotentialCallee)) {
340+
if (!isKernel(*PotentialCallee)) {
345341
for (StringRef Attr : FnAttrs)
346342
PotentialCallee->removeFnAttr(Attr);
347343
}

llvm/lib/Target/AMDGPU/AMDGPUMemoryUtils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ void getUsesOfLDSByFunction(const CallGraph &CG, Module &M,
5353
FunctionVariableMap &kernels,
5454
FunctionVariableMap &functions);
5555

56-
bool isKernelLDS(const Function *F);
57-
5856
LDSUsesInfoTy getTransitiveUsesOfLDS(const CallGraph &CG, Module &M);
5957

6058
/// Strip FnAttr attribute from any functions where we may have

llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ bool AMDGPUSubtarget::makeLIDRangeMetadata(Instruction *I) const {
350350
}
351351

352352
unsigned AMDGPUSubtarget::getImplicitArgNumBytes(const Function &F) const {
353-
assert(AMDGPU::isKernel(F.getCallingConv()));
353+
assert(AMDGPU::isKernel(F));
354354

355355
// We don't allocate the segment if we know the implicit arguments weren't
356356
// used, even if the ABI implies we need them.

llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ void AMDGPUSwLowerLDS::getNonKernelsWithLDSArguments(const CallGraph &CG) {
271271
Function *CalledFunc = CallerCGN->getFunction();
272272
if (!CalledFunc || CalledFunc->isDeclaration())
273273
continue;
274-
if (AMDGPU::isKernelLDS(CalledFunc))
274+
if (AMDGPU::isKernel(*CalledFunc))
275275
continue;
276276
for (auto AI = CalledFunc->arg_begin(), E = CalledFunc->arg_end();
277277
AI != E; ++AI) {
@@ -297,7 +297,7 @@ void AMDGPUSwLowerLDS::getUsesOfLDSByNonKernels() {
297297
for (User *V : GV->users()) {
298298
if (auto *I = dyn_cast<Instruction>(V)) {
299299
Function *F = I->getFunction();
300-
if (!isKernelLDS(F) && !F->isDeclaration())
300+
if (!isKernel(*F) && !F->isDeclaration())
301301
FuncLDSAccessInfo.NonKernelToLDSAccessMap[F].insert(GV);
302302
}
303303
}
@@ -1169,7 +1169,7 @@ bool AMDGPUSwLowerLDS::run() {
11691169
if (!F || K.second.empty())
11701170
continue;
11711171

1172-
assert(isKernelLDS(F));
1172+
assert(isKernel(*F));
11731173

11741174
// Only inserts if key isn't already in the map.
11751175
FuncLDSAccessInfo.KernelToLDSParametersMap.insert(

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9819,7 +9819,7 @@ SDValue SITargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
98199819
AMDGPUFunctionArgInfo::IMPLICIT_ARG_PTR);
98209820
}
98219821
case Intrinsic::amdgcn_kernarg_segment_ptr: {
9822-
if (!AMDGPU::isKernel(MF.getFunction().getCallingConv())) {
9822+
if (!AMDGPU::isKernel(MF.getFunction())) {
98239823
// This only makes sense to call in a kernel, so just lower to null.
98249824
return DAG.getConstant(0, DL, VT);
98259825
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,8 @@ constexpr inline bool isKernel(CallingConv::ID CC) {
15141514
}
15151515
}
15161516

1517+
inline bool isKernel(const Function &F) { return isKernel(F.getCallingConv()); }
1518+
15171519
LLVM_READNONE
15181520
constexpr bool canGuaranteeTCO(CallingConv::ID CC) {
15191521
return CC == CallingConv::Fast;

0 commit comments

Comments
 (0)