Index: include/llvm/Passes/PassBuilder.h =================================================================== --- include/llvm/Passes/PassBuilder.h +++ include/llvm/Passes/PassBuilder.h @@ -66,6 +66,22 @@ bool SamplePGOSupport; }; +/// Tunable parameters for passes in the default pipelines. +class PipelineTuningOptions { +public: + /// Constructor sets pipeline tuning defaults based on cl::opts. Each option + /// can be set in the PassBuilder when using a LLVM as a library. + PipelineTuningOptions(); + + /// Tuning option to set loop interleaving on/off. Its default value is that + /// of the flag: `-interleave-loops-npm`. + bool InterleaveLoops; + + /// Tuning option to enable/disable loop vectorization. Its default value is + /// that of the flag: `-vectorize-loops-npm`. + bool LoopVectorize; +}; + /// This class provides access to building LLVM's passes. /// /// Its members provide the baseline state available to passes during their @@ -74,6 +90,7 @@ /// construction. class PassBuilder { TargetMachine *TM; + PipelineTuningOptions PTO; Optional PGOOpt; PassInstrumentationCallbacks *PIC; @@ -190,9 +207,10 @@ }; explicit PassBuilder(TargetMachine *TM = nullptr, + PipelineTuningOptions PTO = PipelineTuningOptions(), Optional PGOOpt = None, PassInstrumentationCallbacks *PIC = nullptr) - : TM(TM), PGOOpt(PGOOpt), PIC(PIC) {} + : TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC) {} /// Cross register the analysis managers through their proxies. /// Index: include/llvm/Transforms/Vectorize/LoopVectorize.h =================================================================== --- include/llvm/Transforms/Vectorize/LoopVectorize.h +++ include/llvm/Transforms/Vectorize/LoopVectorize.h @@ -77,6 +77,8 @@ /// The LoopVectorize Pass. struct LoopVectorizePass : public PassInfoMixin { + LoopVectorizePass(bool IOWF = false, bool VOWF = false) + : InterleaveOnlyWhenForced(IOWF), VectorizeOnlyWhenForced(VOWF) {} /// If false, consider all loops for interleaving. /// If true, only loops that explicitly request interleaving are considered. bool InterleaveOnlyWhenForced = false; Index: lib/LTO/LTOBackend.cpp =================================================================== --- lib/LTO/LTOBackend.cpp +++ lib/LTO/LTOBackend.cpp @@ -164,7 +164,7 @@ PGOOptions::IRUse, PGOOptions::CSIRUse); } - PassBuilder PB(TM, PGOOpt); + PassBuilder PB(TM, PipelineTuningOptions(), PGOOpt); AAManager AA; // Parse a custom AA pipeline if asked to. Index: lib/Passes/PassBuilder.cpp =================================================================== --- lib/Passes/PassBuilder.cpp +++ lib/Passes/PassBuilder.cpp @@ -211,6 +211,18 @@ EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden, cl::desc("Enable control height reduction optimization (CHR)")); +static cl::opt + RunLoopVectorizationNPM("vectorize-loops-npm", cl::init(true), cl::Hidden, + cl::desc("Run the Loop vectorization passes")); +static cl::opt + SetLoopsInterleavedNPM("interleave-loops-npm", cl::init(true), cl::Hidden, + cl::desc("Run the Loop vectorization passes")); + +PipelineTuningOptions::PipelineTuningOptions() { + InterleaveLoops = SetLoopsInterleavedNPM; + LoopVectorize = RunLoopVectorizationNPM; +} + extern cl::opt EnableHotColdSplit; extern cl::opt EnableOrderFileInstrumentation; @@ -846,7 +858,8 @@ OptimizePM.addPass(LoopDistributePass()); // Now run the core loop vectorizer. - OptimizePM.addPass(LoopVectorizePass()); + OptimizePM.addPass( + LoopVectorizePass(!PTO.InterleaveLoops, !PTO.LoopVectorize)); // Eliminate loads by forwarding stores from the previous iteration to loads // of the current iteration. Index: tools/opt/NewPMDriver.cpp =================================================================== --- tools/opt/NewPMDriver.cpp +++ tools/opt/NewPMDriver.cpp @@ -261,7 +261,7 @@ StandardInstrumentations SI; SI.registerCallbacks(PIC); - PassBuilder PB(TM, P, &PIC); + PassBuilder PB(TM, PipelineTuningOptions(), P, &PIC); registerEPCallbacks(PB, VerifyEachPass, DebugPM); // Load requested pass plugins and let them register pass builder callbacks Index: unittests/IR/PassBuilderCallbacksTest.cpp =================================================================== --- unittests/IR/PassBuilderCallbacksTest.cpp +++ unittests/IR/PassBuilderCallbacksTest.cpp @@ -414,7 +414,8 @@ "exit:\n" " ret void\n" "}\n")), - CallbacksHandle(), PB(nullptr, None, &CallbacksHandle.Callbacks), + CallbacksHandle(), + PB(nullptr, PipelineTuningOptions(), None, &CallbacksHandle.Callbacks), PM(true), LAM(true), FAM(true), CGAM(true), AM(true) { /// Register a callback for analysis registration.