Index: llvm/trunk/include/llvm/Transforms/Vectorize/LoopVectorize.h =================================================================== --- llvm/trunk/include/llvm/Transforms/Vectorize/LoopVectorize.h +++ llvm/trunk/include/llvm/Transforms/Vectorize/LoopVectorize.h @@ -76,15 +76,42 @@ class TargetLibraryInfo; class TargetTransformInfo; +struct LoopVectorizeOptions { + /// If false, consider all loops for interleaving. + /// If true, only loops that explicitly request interleaving are considered. + bool InterleaveOnlyWhenForced; + + /// If false, consider all loops for vectorization. + /// If true, only loops that explicitly request vectorization are considered. + bool VectorizeOnlyWhenForced; + + LoopVectorizeOptions() + : InterleaveOnlyWhenForced(false), VectorizeOnlyWhenForced(false) {} + + LoopVectorizeOptions &setInterleaveOnlyWhenForced(bool Value) { + InterleaveOnlyWhenForced = Value; + return *this; + } + + LoopVectorizeOptions &setVectorizeOnlyWhenForced(bool Value) { + VectorizeOnlyWhenForced = Value; + return *this; + } +}; + /// The LoopVectorize Pass. struct LoopVectorizePass : public PassInfoMixin { /// If false, consider all loops for interleaving. /// If true, only loops that explicitly request interleaving are considered. - bool InterleaveOnlyWhenForced = false; + bool InterleaveOnlyWhenForced; /// If false, consider all loops for vectorization. /// If true, only loops that explicitly request vectorization are considered. - bool VectorizeOnlyWhenForced = false; + bool VectorizeOnlyWhenForced; + + LoopVectorizePass(LoopVectorizeOptions Opts = {}) + : InterleaveOnlyWhenForced(Opts.InterleaveOnlyWhenForced), + VectorizeOnlyWhenForced(Opts.VectorizeOnlyWhenForced) {} ScalarEvolution *SE; LoopInfo *LI; Index: llvm/trunk/lib/Passes/PassBuilder.cpp =================================================================== --- llvm/trunk/lib/Passes/PassBuilder.cpp +++ llvm/trunk/lib/Passes/PassBuilder.cpp @@ -1469,6 +1469,27 @@ return Result; } +/// Parser of parameters for LoopVectorize pass. +Expected parseLoopVectorizeOptions(StringRef Params) { + LoopVectorizeOptions Opts; + while (!Params.empty()) { + StringRef ParamName; + std::tie(ParamName, Params) = Params.split(';'); + + bool Enable = !ParamName.consume_front("no-"); + if (ParamName == "interleave-forced-only") { + Opts.setInterleaveOnlyWhenForced(Enable); + } else if (ParamName == "vectorize-forced-only") { + Opts.setVectorizeOnlyWhenForced(Enable); + } else { + return make_error( + formatv("invalid LoopVectorize parameter '{0}' ", ParamName).str(), + inconvertibleErrorCode()); + } + } + return Opts; +} + } // namespace /// Tests whether a pass name starts with a valid prefix for a default pipeline Index: llvm/trunk/lib/Passes/PassRegistry.def =================================================================== --- llvm/trunk/lib/Passes/PassRegistry.def +++ llvm/trunk/lib/Passes/PassRegistry.def @@ -199,7 +199,6 @@ FUNCTION_PASS("loop-load-elim", LoopLoadEliminationPass()) FUNCTION_PASS("loop-fuse", LoopFusePass()) FUNCTION_PASS("loop-distribute", LoopDistributePass()) -FUNCTION_PASS("loop-vectorize", LoopVectorizePass()) FUNCTION_PASS("pgo-memop-opt", PGOMemOPSizeOpt()) FUNCTION_PASS("print", PrintFunctionPass(dbgs())) FUNCTION_PASS("print", AssumptionPrinterPass(dbgs())) @@ -258,6 +257,11 @@ return SimplifyCFGPass(Opts); }, parseSimplifyCFGOptions) +FUNCTION_PASS_WITH_PARAMS("loop-vectorize", + [](LoopVectorizeOptions Opts) { + return LoopVectorizePass(Opts); + }, + parseLoopVectorizeOptions) #undef FUNCTION_PASS_WITH_PARAMS #ifndef LOOP_ANALYSIS