Skip to content

Commit 5835996

Browse files
committed
[AMDGPU] Let LowerModuleLDS run twice on the same module
See llvm#81491 Split from llvm#75333
1 parent 855bac2 commit 5835996

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,18 @@ class AMDGPULowerModuleLDS {
327327
return convertUsersOfConstantsToInstructions(LDSGlobals);
328328
}
329329

330+
std::optional<bool> HasAbsoluteGVs;
331+
330332
public:
331333
AMDGPULowerModuleLDS(const AMDGPUTargetMachine &TM_) : TM(TM_) {}
332334

333335
using FunctionVariableMap = DenseMap<Function *, DenseSet<GlobalVariable *>>;
334336

335337
using VariableFunctionMap = DenseMap<GlobalVariable *, DenseSet<Function *>>;
336338

337-
static void getUsesOfLDSByFunction(CallGraph const &CG, Module &M,
338-
FunctionVariableMap &kernels,
339-
FunctionVariableMap &functions) {
339+
void getUsesOfLDSByFunction(CallGraph const &CG, Module &M,
340+
FunctionVariableMap &kernels,
341+
FunctionVariableMap &functions) {
340342

341343
// Get uses from the current function, excluding uses by called functions
342344
// Two output variables to avoid walking the globals list twice
@@ -345,10 +347,18 @@ class AMDGPULowerModuleLDS {
345347
continue;
346348
}
347349

348-
if (GV.isAbsoluteSymbolRef()) {
349-
report_fatal_error(
350-
"LDS variables with absolute addresses are unimplemented.");
351-
}
350+
// Check if the module is consistent: either all GVs are absolute (happens
351+
// when we run the pass more than once), or none are.
352+
if (HasAbsoluteGVs.has_value()) {
353+
if (*HasAbsoluteGVs != GV.isAbsoluteSymbolRef()) {
354+
report_fatal_error(
355+
"Module cannot mix absolute and non-absolute LDS GVs");
356+
}
357+
} else
358+
HasAbsoluteGVs = GV.isAbsoluteSymbolRef();
359+
360+
if (GV.isAbsoluteSymbolRef())
361+
continue;
352362

353363
for (User *V : GV.users()) {
354364
if (auto *I = dyn_cast<Instruction>(V)) {
@@ -368,7 +378,7 @@ class AMDGPULowerModuleLDS {
368378
FunctionVariableMap indirect_access;
369379
};
370380

371-
static LDSUsesInfoTy getTransitiveUsesOfLDS(CallGraph const &CG, Module &M) {
381+
LDSUsesInfoTy getTransitiveUsesOfLDS(CallGraph const &CG, Module &M) {
372382

373383
FunctionVariableMap direct_map_kernel;
374384
FunctionVariableMap direct_map_function;

llvm/test/CodeGen/AMDGPU/lds-reject-absolute-addresses.ll renamed to llvm/test/CodeGen/AMDGPU/lds-reject-mixed-absolute-addresses.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
; RUN: not --crash opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds < %s 2>&1 | FileCheck %s
33

44
@var1 = addrspace(3) global i32 undef, !absolute_symbol !0
5+
@var2 = addrspace(3) global i32 undef
56

6-
; CHECK: LLVM ERROR: LDS variables with absolute addresses are unimplemented.
7+
; CHECK: Module cannot mix absolute and non-absolute LDS GVs
78
define amdgpu_kernel void @kern() {
89
%val0 = load i32, ptr addrspace(3) @var1
910
%val1 = add i32 %val0, 4
@@ -12,4 +13,3 @@ define amdgpu_kernel void @kern() {
1213
}
1314

1415
!0 = !{i32 0, i32 1}
15-
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds %s -o %t.ll
2+
; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds %t.ll -o -
3+
; RUN: diff -ub %t.ll %t.second.ll -I ".*ModuleID.*"
4+
5+
; Check AMDGPULowerModuleLDS can run more than once on the same module, and that
6+
; the second run is a no-op.
7+
8+
@lds = internal unnamed_addr addrspace(3) global i32 undef, align 4
9+
10+
define amdgpu_kernel void @test() {
11+
entry:
12+
store i32 1, ptr addrspace(3) @lds
13+
ret void
14+
}

0 commit comments

Comments
 (0)