Skip to content

Commit 624f12d

Browse files
[amdgpu] Drop lowering of LDS used by global variables
Approximately revert D103431. LDS variables are allocated at kernel launch and deallocated at kernel exit. The address is therefore kernel execution dependent. Global variables are initialized by values written to .data, which can't be done for a LDS variable as there is no kernel running, or by a global constructor. Initializing the global to the address of some LDS allocated by a global constructor is possible but indistinguishable from undef. Assigning the address of a LDS variable to a global should be a sema error. It isn't for openmp, haven't checked other languages. Failing that it could be set to undef, perhaps in this pass. Reviewed By: rampitec Differential Revision: https://reviews.llvm.org/D115413
1 parent 87fe070 commit 624f12d

File tree

6 files changed

+4
-321
lines changed

6 files changed

+4
-321
lines changed

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

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,6 @@ void replaceConstantUsesInFunction(ConstantExpr *C, const Function *F) {
6262
}
6363
}
6464

65-
bool hasUserInstruction(const GlobalValue *GV) {
66-
SmallPtrSet<const User *, 8> Visited;
67-
SmallVector<const User *, 16> Stack(GV->users());
68-
69-
while (!Stack.empty()) {
70-
const User *U = Stack.pop_back_val();
71-
72-
if (!Visited.insert(U).second)
73-
continue;
74-
75-
if (isa<Instruction>(U))
76-
return true;
77-
78-
append_range(Stack, U->users());
79-
}
80-
81-
return false;
82-
}
83-
84-
/// \returns true if an LDS global requires lowering to a module LDS structure
85-
/// if \p F is not given. If \p F is given it must be a kernel and function
86-
/// \returns true if an LDS global is directly used from that kernel and it
87-
/// is safe to replace its uses with a kernel LDS structure member.
8865
static bool shouldLowerLDSToStruct(const GlobalVariable &GV,
8966
const Function *F) {
9067
// We are not interested in kernel LDS lowering for module LDS itself.
@@ -94,23 +71,17 @@ static bool shouldLowerLDSToStruct(const GlobalVariable &GV,
9471
bool Ret = false;
9572
SmallPtrSet<const User *, 8> Visited;
9673
SmallVector<const User *, 16> Stack(GV.users());
97-
SmallPtrSet<const GlobalValue *, 8> GlobalUsers;
9874

9975
assert(!F || isKernelCC(F));
10076

10177
while (!Stack.empty()) {
10278
const User *V = Stack.pop_back_val();
10379
Visited.insert(V);
10480

105-
if (auto *G = dyn_cast<GlobalValue>(V)) {
106-
StringRef GName = G->getName();
107-
if (F && GName != "llvm.used" && GName != "llvm.compiler.used") {
108-
// For kernel LDS lowering, if G is not a compiler.used list, then we
109-
// cannot lower the lds GV since we cannot replace the use of GV within
110-
// G.
111-
return false;
112-
}
113-
GlobalUsers.insert(G);
81+
if (isa<GlobalValue>(V)) {
82+
// This use of the LDS variable is the initializer of a global variable.
83+
// This is ill formed. The address of an LDS variable is kernel dependent
84+
// and unknown until runtime. It can't be written to a global variable.
11485
continue;
11586
}
11687

@@ -132,15 +103,6 @@ static bool shouldLowerLDSToStruct(const GlobalVariable &GV,
132103
append_range(Stack, V->users());
133104
}
134105

135-
if (!F && !Ret) {
136-
// For module LDS lowering, we have not yet decided if we should lower GV or
137-
// not. Explore all global users of GV, and check if atleast one of these
138-
// global users appear as an use within an instruction (possibly nested use
139-
// via constant expression), if so, then conservately lower LDS.
140-
for (auto *G : GlobalUsers)
141-
Ret |= hasUserInstruction(G);
142-
}
143-
144106
return Ret;
145107
}
146108

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ bool isKernelCC(const Function *Func);
2626

2727
Align getAlign(DataLayout const &DL, const GlobalVariable *GV);
2828

29-
/// \returns true if a given global variable \p GV (or its global users) appear
30-
/// as an use within some instruction (either from kernel or from non-kernel).
31-
bool hasUserInstruction(const GlobalValue *GV);
32-
3329
std::vector<GlobalVariable *> findVariablesToLower(Module &M,
3430
const Function *F = nullptr);
3531

llvm/test/CodeGen/AMDGPU/lower-kernel-lds-global-uses.ll

Lines changed: 0 additions & 55 deletions
This file was deleted.

llvm/test/CodeGen/AMDGPU/lower-module-lds-global-alias.ll

Lines changed: 0 additions & 93 deletions
This file was deleted.

llvm/test/CodeGen/AMDGPU/lower-module-lds-global-uses.ll

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)