diff --git a/llvm/include/llvm/Transforms/Scalar/Scalarizer.h b/llvm/include/llvm/Transforms/Scalar/Scalarizer.h --- a/llvm/include/llvm/Transforms/Scalar/Scalarizer.h +++ b/llvm/include/llvm/Transforms/Scalar/Scalarizer.h @@ -17,6 +17,7 @@ #ifndef LLVM_TRANSFORMS_SCALAR_SCALARIZER_H #define LLVM_TRANSFORMS_SCALAR_SCALARIZER_H +#include "llvm/ADT/Optional.h" #include "llvm/IR/PassManager.h" namespace llvm { @@ -24,9 +25,25 @@ class Function; class FunctionPass; +struct ScalarizerPassOptions { + // For these optional booleans, the default value None lets the implementation + // pick a default value based on corresponding command-line options defined in + // Scalarizer.cpp. Setting a non-default value here allows to override that, + // which is useful when creating a ScalarizerPass from another pass. + llvm::Optional ScalarizeVariableInsertExtract; + llvm::Optional ScalarizeLoadStore; +}; + class ScalarizerPass : public PassInfoMixin { + ScalarizerPassOptions options; + public: PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); + + void setScalarizeVariableInsertExtract(bool value) { + options.ScalarizeVariableInsertExtract = value; + } + void setScalarizeLoadStore(bool value) { options.ScalarizeLoadStore = value; } }; /// Create a legacy pass manager instance of the Scalarizer pass diff --git a/llvm/lib/Transforms/Scalar/Scalarizer.cpp b/llvm/lib/Transforms/Scalar/Scalarizer.cpp --- a/llvm/lib/Transforms/Scalar/Scalarizer.cpp +++ b/llvm/lib/Transforms/Scalar/Scalarizer.cpp @@ -50,7 +50,7 @@ #define DEBUG_TYPE "scalarizer" -static cl::opt ScalarizeVariableInsertExtract( +static cl::opt ClScalarizeVariableInsertExtract( "scalarize-variable-insert-extract", cl::init(true), cl::Hidden, cl::desc("Allow the scalarizer pass to scalarize " "insertelement/extractelement with variable index")); @@ -58,9 +58,9 @@ // This is disabled by default because having separate loads and stores // makes it more likely that the -combiner-alias-analysis limits will be // reached. -static cl::opt - ScalarizeLoadStore("scalarize-load-store", cl::init(false), cl::Hidden, - cl::desc("Allow the scalarizer pass to scalarize loads and store")); +static cl::opt ClScalarizeLoadStore( + "scalarize-load-store", cl::init(false), cl::Hidden, + cl::desc("Allow the scalarizer pass to scalarize loads and store")); namespace { @@ -188,9 +188,11 @@ class ScalarizerVisitor : public InstVisitor { public: - ScalarizerVisitor(unsigned ParallelLoopAccessMDKind, DominatorTree *DT) - : ParallelLoopAccessMDKind(ParallelLoopAccessMDKind), DT(DT) { - } + ScalarizerVisitor(unsigned ParallelLoopAccessMDKind, DominatorTree *DT, + ScalarizerPassOptions options) + : ParallelLoopAccessMDKind(ParallelLoopAccessMDKind), DT(DT), + ScalarizeVariableInsertExtract(options.ScalarizeVariableInsertExtract.getValueOr(ClScalarizeVariableInsertExtract)), + ScalarizeLoadStore(options.ScalarizeLoadStore.getValueOr(ClScalarizeLoadStore)) {} bool visit(Function &F); @@ -235,6 +237,9 @@ unsigned ParallelLoopAccessMDKind; DominatorTree *DT; + + const bool ScalarizeVariableInsertExtract; + const bool ScalarizeLoadStore; }; class ScalarizerLegacyPass : public FunctionPass { @@ -334,7 +339,7 @@ unsigned ParallelLoopAccessMDKind = M.getContext().getMDKindID("llvm.mem.parallel_loop_access"); DominatorTree *DT = &getAnalysis().getDomTree(); - ScalarizerVisitor Impl(ParallelLoopAccessMDKind, DT); + ScalarizerVisitor Impl(ParallelLoopAccessMDKind, DT, ScalarizerPassOptions()); return Impl.visit(F); } @@ -983,7 +988,7 @@ unsigned ParallelLoopAccessMDKind = M.getContext().getMDKindID("llvm.mem.parallel_loop_access"); DominatorTree *DT = &AM.getResult(F); - ScalarizerVisitor Impl(ParallelLoopAccessMDKind, DT); + ScalarizerVisitor Impl(ParallelLoopAccessMDKind, DT, options); bool Changed = Impl.visit(F); PreservedAnalyses PA; PA.preserve();