Skip to content

Commit 1f02be2

Browse files
authored
[AMDGPU] Enable "amdgpu-sw-lower-lds" pass in pipeline. (#89206)
This PR enables "amdgpu-sw-lower-lds" pass in the pipeline. Also introduces "amdgpu-enable-sw-lower-lds" cmd line flag to enbale/disable the pass.
1 parent 533e6bb commit 1f02be2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ static cl::opt<bool> EnableScalarIRPasses(
338338
cl::init(true),
339339
cl::Hidden);
340340

341+
static cl::opt<bool>
342+
EnableSwLowerLDS("amdgpu-enable-sw-lower-lds",
343+
cl::desc("Enable lowering of lds to global memory pass "
344+
"and asan instrument resulting IR."),
345+
cl::init(true), cl::Hidden);
346+
341347
static cl::opt<bool, true> EnableLowerModuleLDS(
342348
"amdgpu-enable-lower-module-lds", cl::desc("Enable lower module lds pass"),
343349
cl::location(AMDGPUTargetMachine::EnableLowerModuleLDS), cl::init(true),
@@ -759,6 +765,8 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
759765
// We want to support the -lto-partitions=N option as "best effort".
760766
// For that, we need to lower LDS earlier in the pipeline before the
761767
// module is partitioned for codegen.
768+
if (EnableSwLowerLDS)
769+
PM.addPass(AMDGPUSwLowerLDSPass(*this));
762770
if (EnableLowerModuleLDS)
763771
PM.addPass(AMDGPULowerModuleLDSPass(*this));
764772

@@ -1068,6 +1076,10 @@ void AMDGPUPassConfig::addIRPasses() {
10681076
// Replace OpenCL enqueued block function pointers with global variables.
10691077
addPass(createAMDGPUOpenCLEnqueuedBlockLoweringPass());
10701078

1079+
// Lower LDS accesses to global memory pass if address sanitizer is enabled.
1080+
if (EnableSwLowerLDS)
1081+
addPass(createAMDGPUSwLowerLDSLegacyPass(&TM));
1082+
10711083
// Runs before PromoteAlloca so the latter can account for function uses
10721084
if (EnableLowerModuleLDS) {
10731085
addPass(createAMDGPULowerModuleLDSLegacyPass(&TM));

llvm/test/CodeGen/AMDGPU/llc-pipeline.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
; GCN-O0-NEXT: Basic Alias Analysis (stateless AA impl)
4040
; GCN-O0-NEXT: Function Alias Analysis Results
4141
; GCN-O0-NEXT: Lower OpenCL enqueued blocks
42+
; GCN-O0-NEXT: AMDGPU Software lowering of LDS
4243
; GCN-O0-NEXT: Lower uses of LDS variables from non-kernel functions
4344
; GCN-O0-NEXT: FunctionPass Manager
4445
; GCN-O0-NEXT: Expand Atomic instructions
@@ -185,6 +186,7 @@
185186
; GCN-O1-NEXT: Basic Alias Analysis (stateless AA impl)
186187
; GCN-O1-NEXT: Function Alias Analysis Results
187188
; GCN-O1-NEXT: Lower OpenCL enqueued blocks
189+
; GCN-O1-NEXT: AMDGPU Software lowering of LDS
188190
; GCN-O1-NEXT: Lower uses of LDS variables from non-kernel functions
189191
; GCN-O1-NEXT: FunctionPass Manager
190192
; GCN-O1-NEXT: Infer address spaces
@@ -460,6 +462,7 @@
460462
; GCN-O1-OPTS-NEXT: Basic Alias Analysis (stateless AA impl)
461463
; GCN-O1-OPTS-NEXT: Function Alias Analysis Results
462464
; GCN-O1-OPTS-NEXT: Lower OpenCL enqueued blocks
465+
; GCN-O1-OPTS-NEXT: AMDGPU Software lowering of LDS
463466
; GCN-O1-OPTS-NEXT: Lower uses of LDS variables from non-kernel functions
464467
; GCN-O1-OPTS-NEXT: FunctionPass Manager
465468
; GCN-O1-OPTS-NEXT: Infer address spaces
@@ -765,6 +768,7 @@
765768
; GCN-O2-NEXT: Basic Alias Analysis (stateless AA impl)
766769
; GCN-O2-NEXT: Function Alias Analysis Results
767770
; GCN-O2-NEXT: Lower OpenCL enqueued blocks
771+
; GCN-O2-NEXT: AMDGPU Software lowering of LDS
768772
; GCN-O2-NEXT: Lower uses of LDS variables from non-kernel functions
769773
; GCN-O2-NEXT: FunctionPass Manager
770774
; GCN-O2-NEXT: Infer address spaces
@@ -1074,6 +1078,7 @@
10741078
; GCN-O3-NEXT: Basic Alias Analysis (stateless AA impl)
10751079
; GCN-O3-NEXT: Function Alias Analysis Results
10761080
; GCN-O3-NEXT: Lower OpenCL enqueued blocks
1081+
; GCN-O3-NEXT: AMDGPU Software lowering of LDS
10771082
; GCN-O3-NEXT: Lower uses of LDS variables from non-kernel functions
10781083
; GCN-O3-NEXT: FunctionPass Manager
10791084
; GCN-O3-NEXT: Infer address spaces

0 commit comments

Comments
 (0)