Skip to content

Commit b92b555

Browse files
committed
[AMDGPU] Move removeNoLdsKernelIdFromReachable from amdgpu-lower-module-lds pass to AMDGPUMemoryUtils
1 parent 4e67582 commit b92b555

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,49 @@ LDSUsesInfoTy getTransitiveUsesOfLDS(CallGraph const &CG, Module &M) {
241241
return {std::move(direct_map_kernel), std::move(indirect_map_kernel)};
242242
}
243243

244+
void removeFnAttrFromReachable(CallGraph &CG, Function *KernelRoot,
245+
StringRef FnAttr) {
246+
KernelRoot->removeFnAttr(FnAttr);
247+
248+
SmallVector<Function *> Tmp({CG[KernelRoot]->getFunction()});
249+
if (!Tmp.back())
250+
return;
251+
252+
SmallPtrSet<Function *, 8> Visited;
253+
bool SeenUnknownCall = false;
254+
255+
do {
256+
Function *F = Tmp.pop_back_val();
257+
258+
for (auto &N : *CG[F]) {
259+
if (!N.second)
260+
continue;
261+
262+
Function *Callee = N.second->getFunction();
263+
if (!Callee) {
264+
if (!SeenUnknownCall) {
265+
SeenUnknownCall = true;
266+
267+
// If we see any indirect calls, assume nothing about potential
268+
// targets.
269+
// TODO: This could be refined to possible LDS global users.
270+
for (auto &N : *CG.getExternalCallingNode()) {
271+
Function *PotentialCallee = N.second->getFunction();
272+
if (!isKernelLDS(PotentialCallee))
273+
PotentialCallee->removeFnAttr(FnAttr);
274+
}
275+
276+
continue;
277+
}
278+
}
279+
280+
Callee->removeFnAttr(FnAttr);
281+
if (Visited.insert(Callee).second)
282+
Tmp.push_back(Callee);
283+
}
284+
} while (!Tmp.empty());
285+
}
286+
244287
bool isReallyAClobber(const Value *Ptr, MemoryDef *Def, AAResults *AA) {
245288
Instruction *DefInst = Def->getMemoryInst();
246289

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ bool isKernelLDS(const Function *F);
5151

5252
LDSUsesInfoTy getTransitiveUsesOfLDS(CallGraph const &CG, Module &M);
5353

54+
/// Strip FnAttr attribute from any functions where we may have
55+
/// introduced its use.
56+
void removeFnAttrFromReachable(CallGraph &CG, Function *KernelRoot,
57+
StringRef FnAttr);
58+
5459
/// Given a \p Def clobbering a load from \p Ptr according to the MSSA check
5560
/// if this is actually a memory update or an artificial clobber to facilitate
5661
/// ordering constraints.

0 commit comments

Comments
 (0)