Skip to content

Commit 97a3150

Browse files
authored
[SYCL] Enable standard optimization pipeline for SYCL device compiler (#2049)
1 parent 57a63b0 commit 97a3150

File tree

1 file changed

+16
-54
lines changed

1 file changed

+16
-54
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include "llvm/Passes/StandardInstrumentations.h"
4343
#include "llvm/Support/BuryPointer.h"
4444
#include "llvm/Support/CommandLine.h"
45-
#include "llvm/Support/Debug.h"
4645
#include "llvm/Support/MemoryBuffer.h"
4746
#include "llvm/Support/PrettyStackTrace.h"
4847
#include "llvm/Support/TargetRegistry.h"
@@ -82,11 +81,6 @@
8281
#include "llvm/Transforms/Utils/SymbolRewriter.h"
8382
#include "llvm/Transforms/Utils/UniqueInternalLinkageNames.h"
8483
#include <memory>
85-
86-
namespace SPIRV {
87-
extern llvm::cl::opt<bool> SPIRVNoDerefAttr;
88-
}
89-
9084
using namespace clang;
9185
using namespace llvm;
9286

@@ -622,54 +616,22 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
622616
CodeGenOpts.PrepareForThinLTO));
623617
}
624618

625-
// FIXME: This code is a workaround for a number of problems with optimized
626-
// SYCL code for the SPIR target. This change trying to balance between doing
627-
// too few and too many optimizations. The current approach is to disable as
628-
// much as possible just to keep the compiler functional. Eventually we can
629-
// consider allowing -On option to configure the optimization set for the FE
630-
// device compiler as well, but before that we must fix all the functional and
631-
// performance issues caused by LLVM transformantions.
632-
// E.g. LLVM optimizations make use of llvm intrinsics, instructions, data
633-
// types, etc., which are not supported by the SPIR-V translator (current
634-
// "back-end" for SYCL device compiler).
635-
// NOTE: We use "normal" inliner (i.e. from O2/O3), but limit the rest of
636-
// optimization pipeline. Inliner is a must for enabling size reduction
637-
// optimizations.
638-
if (LangOpts.SYCLIsDevice && TargetTriple.isSPIR()) {
639-
PMBuilder.OptLevel = 1;
640-
PMBuilder.SizeLevel = 2;
641-
PMBuilder.SLPVectorize = false;
642-
PMBuilder.LoopVectorize = false;
643-
PMBuilder.DivergentTarget = true;
644-
PMBuilder.DisableGVNLoadPRE = true;
645-
PMBuilder.ForgetAllSCEVInLoopUnroll = true;
646-
647-
PMBuilder.DisableUnrollLoops = true;
648-
// Loop interleaving in the loop vectorizer has historically been set to be
649-
// enabled when loop unrolling is enabled.
650-
PMBuilder.LoopsInterleaved = false;
651-
PMBuilder.MergeFunctions = false;
652-
PMBuilder.PrepareForThinLTO = false;
653-
PMBuilder.PrepareForLTO = false;
654-
PMBuilder.RerollLoops = false;
655-
} else {
656-
PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel;
657-
PMBuilder.SizeLevel = CodeGenOpts.OptimizeSize;
658-
PMBuilder.SLPVectorize = CodeGenOpts.VectorizeSLP;
659-
PMBuilder.LoopVectorize = CodeGenOpts.VectorizeLoop;
660-
// Only enable CGProfilePass when using integrated assembler, since
661-
// non-integrated assemblers don't recognize .cgprofile section.
662-
PMBuilder.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;
663-
664-
PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops;
665-
// Loop interleaving in the loop vectorizer has historically been set to be
666-
// enabled when loop unrolling is enabled.
667-
PMBuilder.LoopsInterleaved = CodeGenOpts.UnrollLoops;
668-
PMBuilder.MergeFunctions = CodeGenOpts.MergeFunctions;
669-
PMBuilder.PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO;
670-
PMBuilder.PrepareForLTO = CodeGenOpts.PrepareForLTO;
671-
PMBuilder.RerollLoops = CodeGenOpts.RerollLoops;
672-
}
619+
PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel;
620+
PMBuilder.SizeLevel = CodeGenOpts.OptimizeSize;
621+
PMBuilder.SLPVectorize = CodeGenOpts.VectorizeSLP;
622+
PMBuilder.LoopVectorize = CodeGenOpts.VectorizeLoop;
623+
// Only enable CGProfilePass when using integrated assembler, since
624+
// non-integrated assemblers don't recognize .cgprofile section.
625+
PMBuilder.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;
626+
627+
PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops;
628+
// Loop interleaving in the loop vectorizer has historically been set to be
629+
// enabled when loop unrolling is enabled.
630+
PMBuilder.LoopsInterleaved = CodeGenOpts.UnrollLoops;
631+
PMBuilder.MergeFunctions = CodeGenOpts.MergeFunctions;
632+
PMBuilder.PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO;
633+
PMBuilder.PrepareForLTO = CodeGenOpts.PrepareForLTO;
634+
PMBuilder.RerollLoops = CodeGenOpts.RerollLoops;
673635

674636
MPM.add(new TargetLibraryInfoWrapperPass(*TLII));
675637

0 commit comments

Comments
 (0)