Skip to content

[SYCL] Enable standard optimization pipeline for SYCL device compiler #2049

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

Merged
merged 1 commit into from
Jul 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 16 additions & 54 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "llvm/Passes/StandardInstrumentations.h"
#include "llvm/Support/BuryPointer.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/TargetRegistry.h"
Expand Down Expand Up @@ -82,11 +81,6 @@
#include "llvm/Transforms/Utils/SymbolRewriter.h"
#include "llvm/Transforms/Utils/UniqueInternalLinkageNames.h"
#include <memory>

namespace SPIRV {
extern llvm::cl::opt<bool> SPIRVNoDerefAttr;
}

using namespace clang;
using namespace llvm;

Expand Down Expand Up @@ -622,54 +616,22 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
CodeGenOpts.PrepareForThinLTO));
}

// 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;
// Only enable CGProfilePass when using integrated assembler, since
// non-integrated assemblers don't recognize .cgprofile section.
PMBuilder.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;

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;
}
PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel;
PMBuilder.SizeLevel = CodeGenOpts.OptimizeSize;
PMBuilder.SLPVectorize = CodeGenOpts.VectorizeSLP;
PMBuilder.LoopVectorize = CodeGenOpts.VectorizeLoop;
// Only enable CGProfilePass when using integrated assembler, since
// non-integrated assemblers don't recognize .cgprofile section.
PMBuilder.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;

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));

Expand Down