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`. + bool LoopInterleaving; + + /// Tuning option to enable/disable loop vectorization. Its default value is + /// that of the flag: `-vectorize-loops`. + bool LoopVectorization; +}; + /// 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.h =================================================================== --- include/llvm/Transforms/Vectorize.h +++ include/llvm/Transforms/Vectorize.h @@ -109,8 +109,9 @@ // // LoopVectorize - Create a loop vectorization pass. // -Pass *createLoopVectorizePass(bool InterleaveOnlyWhenForced = false, - bool VectorizeOnlyWhenForced = false); +Pass *createLoopVectorizePass(); +Pass *createLoopVectorizePass(bool InterleaveOnlyWhenForced, + bool VectorizeOnlyWhenForced); //===----------------------------------------------------------------------===// // Index: include/llvm/Transforms/Vectorize/LoopVectorize.h =================================================================== --- include/llvm/Transforms/Vectorize/LoopVectorize.h +++ include/llvm/Transforms/Vectorize/LoopVectorize.h @@ -75,8 +75,13 @@ class TargetLibraryInfo; class TargetTransformInfo; +extern cl::opt EnableLoopInterleaving; +extern cl::opt EnableLoopVectorization; + /// The LoopVectorize Pass. struct LoopVectorizePass : public PassInfoMixin { + LoopVectorizePass(); + LoopVectorizePass(bool IOWF, bool 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 @@ -212,6 +212,11 @@ EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden, cl::desc("Enable control height reduction optimization (CHR)")); +PipelineTuningOptions::PipelineTuningOptions() { + LoopInterleaving = EnableLoopInterleaving; + LoopVectorization = EnableLoopVectorization; +} + extern cl::opt EnableHotColdSplit; extern cl::opt EnableOrderFileInstrumentation; @@ -847,7 +852,8 @@ OptimizePM.addPass(LoopDistributePass()); // Now run the core loop vectorizer. - OptimizePM.addPass(LoopVectorizePass()); + OptimizePM.addPass( + LoopVectorizePass(!PTO.LoopInterleaving, !PTO.LoopVectorization)); // Eliminate loads by forwarding stores from the previous iteration to loads // of the current iteration. Index: lib/Transforms/IPO/PassManagerBuilder.cpp =================================================================== --- lib/Transforms/IPO/PassManagerBuilder.cpp +++ lib/Transforms/IPO/PassManagerBuilder.cpp @@ -41,6 +41,7 @@ #include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h" #include "llvm/Transforms/Utils.h" #include "llvm/Transforms/Vectorize.h" +#include "llvm/Transforms/Vectorize/LoopVectorize.h" using namespace llvm; @@ -48,10 +49,6 @@ RunPartialInlining("enable-partial-inlining", cl::init(false), cl::Hidden, cl::ZeroOrMore, cl::desc("Run Partial inlinining pass")); -static cl::opt - RunLoopVectorization("vectorize-loops", cl::Hidden, - cl::desc("Run the Loop vectorization passes")); - static cl::opt RunSLPVectorization("vectorize-slp", cl::Hidden, cl::desc("Run the SLP vectorization passes")); @@ -171,7 +168,10 @@ Inliner = nullptr; DisableUnrollLoops = false; SLPVectorize = RunSLPVectorization; - LoopVectorize = RunLoopVectorization; + LoopVectorize = EnableLoopVectorization; + // FIXME: Add: LoopsInterleaved = EnableLoopInterleaving; + // Replace usage of DisableUnrollLoops with LoopsInterleaved when creating + // the LoopVectorize pass, to be consistent with the new pass manager. RerollLoops = RunLoopRerolling; NewGVN = RunNewGVN; DisableGVNLoadPRE = false; Index: lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- lib/Transforms/Vectorize/LoopVectorize.cpp +++ lib/Transforms/Vectorize/LoopVectorize.cpp @@ -275,6 +275,27 @@ "out right after the build (stress test the VPlan H-CFG construction " "in the VPlan-native vectorization path).")); +cl::opt llvm::EnableLoopInterleaving( + "interleave-loops", cl::init(true), cl::Hidden, + cl::desc("Enable loop interleaving in Loop vectorization passes")); +cl::opt llvm::EnableLoopVectorization( + "vectorize-loops", cl::init(false), cl::Hidden, + cl::desc("Run the Loop vectorization passes")); + +LoopVectorizePass::LoopVectorizePass() + // The current defaults when creating the pass with no arguments are: + // EnableLoopInterleaving = true and EnableLoopVectorization = true. + // This means that interleaving default is consistent with the cl::opt flag, + // while vectorization is not. + // FIXME: The default for EnableLoopVectorization in the above cl::opt + // should be set to true, and the corresponding change to account for this + // be made in opt.cpp. The initializations below will become: + // InterleaveOnlyWhenForced(!EnableLoopInterleaving) + // VectorizeOnlyWhenForced(!EnableLoopVectorization). + : InterleaveOnlyWhenForced(false), VectorizeOnlyWhenForced(false) {} +LoopVectorizePass::LoopVectorizePass(bool IOWF, bool VOWF) + : InterleaveOnlyWhenForced(IOWF), VectorizeOnlyWhenForced(VOWF) {} + /// A helper function for converting Scalar types to vector types. /// If the incoming type is void, we return void. If the VF is 1, we return /// the scalar type. @@ -6058,6 +6079,8 @@ namespace llvm { +Pass *createLoopVectorizePass() { return new LoopVectorize(); } + Pass *createLoopVectorizePass(bool InterleaveOnlyWhenForced, bool VectorizeOnlyWhenForced) { return new LoopVectorize(InterleaveOnlyWhenForced, VectorizeOnlyWhenForced); 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.