-
Notifications
You must be signed in to change notification settings - Fork 779
[SYCL][Experimental] Reduce the set of optimizations for SYCL device #1550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
32c3c2a
9be423e
716d023
810327a
5a41ab2
7c8bf8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -599,19 +599,51 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM, | |
CodeGenOpts.PrepareForThinLTO)); | ||
} | ||
|
||
PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel; | ||
PMBuilder.SizeLevel = CodeGenOpts.OptimizeSize; | ||
PMBuilder.SLPVectorize = CodeGenOpts.VectorizeSLP; | ||
PMBuilder.LoopVectorize = CodeGenOpts.VectorizeLoop; | ||
|
||
PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops; | ||
// Loop interleaving in the loop vectorizer has historically been set to be | ||
// enabled when loop unrolling is enabled. | ||
PMBuilder.LoopsInterleaved = CodeGenOpts.UnrollLoops; | ||
PMBuilder.MergeFunctions = CodeGenOpts.MergeFunctions; | ||
PMBuilder.PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO; | ||
PMBuilder.PrepareForLTO = CodeGenOpts.PrepareForLTO; | ||
PMBuilder.RerollLoops = CodeGenOpts.RerollLoops; | ||
// FIXME: This code is a workaround for a number of problems with optimized | ||
// SYCL code for the SPIR target. This change trying to balance between doing | ||
// too few and too many optimizations. The current approach is to disable as | ||
// much as possible just to keep the compiler functional. Eventually we can | ||
// consider allowing -On option to configure the optimization set for the FE | ||
// device compiler as well, but before that we must fix all the functional and | ||
// performance issues caused by LLVM transformantions. | ||
// E.g. LLVM optimizations make use of llvm intrinsics, instructions, data | ||
// types, etc., which are not supported by the SPIR-V translator (current | ||
// "back-end" for SYCL device compiler). | ||
// NOTE: We use "normal" inliner (i.e. from O2/O3), but limit the rest of | ||
// optimization pipeline. Inliner is a must for enabling size reduction | ||
// optimizations. | ||
if (LangOpts.SYCLIsDevice && TargetTriple.isSPIR()) { | ||
PMBuilder.OptLevel = 1; | ||
PMBuilder.SizeLevel = 2; | ||
PMBuilder.SLPVectorize = false; | ||
PMBuilder.LoopVectorize = false; | ||
PMBuilder.DivergentTarget = true; | ||
PMBuilder.DisableGVNLoadPRE = true; | ||
PMBuilder.ForgetAllSCEVInLoopUnroll = true; | ||
|
||
PMBuilder.DisableUnrollLoops = true; | ||
// Loop interleaving in the loop vectorizer has historically been set to be | ||
// enabled when loop unrolling is enabled. | ||
PMBuilder.LoopsInterleaved = false; | ||
PMBuilder.MergeFunctions = false; | ||
PMBuilder.PrepareForThinLTO = false; | ||
PMBuilder.PrepareForLTO = false; | ||
PMBuilder.RerollLoops = false; | ||
} else { | ||
PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel; | ||
PMBuilder.SizeLevel = CodeGenOpts.OptimizeSize; | ||
PMBuilder.SLPVectorize = CodeGenOpts.VectorizeSLP; | ||
PMBuilder.LoopVectorize = CodeGenOpts.VectorizeLoop; | ||
|
||
PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops; | ||
// Loop interleaving in the loop vectorizer has historically been set to be | ||
// enabled when loop unrolling is enabled. | ||
PMBuilder.LoopsInterleaved = CodeGenOpts.UnrollLoops; | ||
PMBuilder.MergeFunctions = CodeGenOpts.MergeFunctions; | ||
PMBuilder.PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO; | ||
PMBuilder.PrepareForLTO = CodeGenOpts.PrepareForLTO; | ||
PMBuilder.RerollLoops = CodeGenOpts.RerollLoops; | ||
} | ||
|
||
MPM.add(new TargetLibraryInfoWrapperPass(*TLII)); | ||
|
||
|
@@ -865,14 +897,15 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action, | |
|
||
std::unique_ptr<llvm::ToolOutputFile> ThinLinkOS, DwoOS; | ||
|
||
// Clean-up SYCL device code if LLVM passes are disabled | ||
if (LangOpts.SYCLIsDevice && CodeGenOpts.DisableLLVMPasses) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More a suggestion for upstreaming purposes: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is just a refactoring of existing functionality. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it was more informative. As you refactored it, this was highlighted, but that's clearly out of scope. |
||
PerModulePasses.add(createDeadCodeEliminationPass()); | ||
|
||
switch (Action) { | ||
case Backend_EmitNothing: | ||
break; | ||
|
||
case Backend_EmitBC: | ||
if (LangOpts.SYCLIsDevice) { | ||
PerModulePasses.add(createDeadCodeEliminationPass()); | ||
} | ||
if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) { | ||
if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) { | ||
ThinLinkOS = openOutputFile(CodeGenOpts.ThinLinkBitcodeFile); | ||
|
@@ -1346,9 +1379,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( | |
break; | ||
|
||
case Backend_EmitBC: | ||
if (LangOpts.SYCLIsDevice) { | ||
CodeGenPasses.add(createDeadCodeEliminationPass()); | ||
} | ||
if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) { | ||
if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) { | ||
ThinLinkOS = openOutputFile(CodeGenOpts.ThinLinkBitcodeFile); | ||
|
Uh oh!
There was an error while loading. Please reload this page.