Skip to content

Commit 4c2fbd6

Browse files
[DAE][SYCL] - Removed DAE from standard optimization pipeline
We cannot run DAE in ESIMD cntext since the pointers to SPIR kernel functions are saved in !genx.kernels metadata. Because of that I removed DAE pass from the standard pipeline and put it in the place that is specific for SYCL passes and guarded it under a new temporary option: '-fenable-sycl-dae'. This option is only used until other parts of the solution are not in place.
1 parent 9fdb269 commit 4c2fbd6

File tree

9 files changed

+13
-5
lines changed

9 files changed

+13
-5
lines changed

clang/include/clang/Basic/LangOptions.def

+1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ LANGOPT(SYCLUnnamedLambda , 1, 0, "Allow unnamed lambda SYCL kernels")
251251
LANGOPT(SYCLVersion , 32, 0, "Version of the SYCL standard used")
252252
LANGOPT(DeclareSPIRVBuiltins, 1, 0, "Declare SPIR-V builtin functions")
253253
LANGOPT(SYCLExplicitSIMD , 1, 0, "SYCL compilation with explicit SIMD extension")
254+
LANGOPT(EnableDAEInSpirKernels , 1, 0, "Enable Dead Argument Elimination in SPIR kernels")
254255

255256
LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")
256257

clang/include/clang/Driver/Options.td

+2
Original file line numberDiff line numberDiff line change
@@ -4456,6 +4456,8 @@ def fsycl_allow_func_ptr : Flag<["-"], "fsycl-allow-func-ptr">,
44564456
def fno_sycl_allow_func_ptr : Flag<["-"], "fno-sycl-allow-func-ptr">;
44574457
def fsycl_enable_optimizations: Flag<["-"], "fsycl-enable-optimizations">,
44584458
HelpText<"Experimental flag enabling standard optimization in the front-end.">;
4459+
def fenable_sycl_dae : Flag<["-"], "fenable-sycl-dae">,
4460+
HelpText<"Enable Dead Argument Elimination in SPIR kernels">;
44594461

44604462
} // let Flags = [CC1Option]
44614463

clang/lib/CodeGen/BackendUtil.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,15 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
918918
if (LangOpts.SYCLIsDevice && CodeGenOpts.DisableLLVMPasses)
919919
PerModulePasses.add(createDeadCodeEliminationPass());
920920

921+
// Eliminate dead arguments from SPIR kernels in SYCL environment.
922+
// 1. Run DAE when LLVM optimizations are applied as well.
923+
// 2. We cannot run DAE for ESIMD since the pointers to SPIR kernel
924+
// functions are saved in !genx.kernels metadata.
925+
// 3. DAE pass temporary guarded under option.
926+
if (LangOpts.SYCLIsDevice && !CodeGenOpts.DisableLLVMPasses &&
927+
!LangOpts.SYCLExplicitSIMD && LangOpts.EnableDAEInSpirKernels)
928+
PerModulePasses.add(createDeadArgEliminationSYCLPass());
929+
921930
if (LangOpts.SYCLIsDevice && LangOpts.SYCLExplicitSIMD)
922931
PerModulePasses.add(createGenXSPIRVWriterAdaptorPass());
923932

clang/lib/Frontend/CompilerInvocation.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2596,6 +2596,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
25962596
}
25972597
}
25982598
Opts.SYCLExplicitSIMD = Args.hasArg(options::OPT_fsycl_esimd);
2599+
Opts.EnableDAEInSpirKernels = Args.hasArg(options::OPT_fenable_sycl_dae);
25992600
}
26002601

26012602
Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header);

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,6 @@ void PassManagerBuilder::populateModulePassManager(
680680
if (RunInliner) {
681681
MPM.add(createGlobalOptimizerPass());
682682
MPM.add(createGlobalDCEPass());
683-
MPM.add(createDeadArgEliminationSYCLPass());
684683
}
685684

686685
// If we are planning to perform ThinLTO later, let's not bloat the code with

llvm/test/Other/opt-O2-pipeline.ll

-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@
193193
; CHECK-NEXT: Branch Probability Analysis
194194
; CHECK-NEXT: Block Frequency Analysis
195195
; CHECK-NEXT: Dead Global Elimination
196-
; CHECK-NEXT: Dead Argument Elimination for SPIR kernels in SYCL environment
197196
; CHECK-NEXT: CallGraph Construction
198197
; CHECK-NEXT: Globals Alias Analysis
199198
; CHECK-NEXT: FunctionPass Manager

llvm/test/Other/opt-O3-pipeline-enable-matrix.ll

-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@
198198
; CHECK-NEXT: Branch Probability Analysis
199199
; CHECK-NEXT: Block Frequency Analysis
200200
; CHECK-NEXT: Dead Global Elimination
201-
; CHECK-NEXT: Dead Argument Elimination for SPIR kernels in SYCL environment
202201
; CHECK-NEXT: CallGraph Construction
203202
; CHECK-NEXT: Globals Alias Analysis
204203
; CHECK-NEXT: FunctionPass Manager

llvm/test/Other/opt-O3-pipeline.ll

-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@
198198
; CHECK-NEXT: Branch Probability Analysis
199199
; CHECK-NEXT: Block Frequency Analysis
200200
; CHECK-NEXT: Dead Global Elimination
201-
; CHECK-NEXT: Dead Argument Elimination for SPIR kernels in SYCL environment
202201
; CHECK-NEXT: CallGraph Construction
203202
; CHECK-NEXT: Globals Alias Analysis
204203
; CHECK-NEXT: FunctionPass Manager

llvm/test/Other/opt-Os-pipeline.ll

-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@
179179
; CHECK-NEXT: Branch Probability Analysis
180180
; CHECK-NEXT: Block Frequency Analysis
181181
; CHECK-NEXT: Dead Global Elimination
182-
; CHECK-NEXT: Dead Argument Elimination for SPIR kernels in SYCL environment
183182
; CHECK-NEXT: CallGraph Construction
184183
; CHECK-NEXT: Globals Alias Analysis
185184
; CHECK-NEXT: FunctionPass Manager

0 commit comments

Comments
 (0)