[llvm] r358763 - [NewPassManager] Adding pass tuning options: loop vectorize.
Alina Sbirlea via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 19 09:11:59 PDT 2019
Author: asbirlea
Date: Fri Apr 19 09:11:59 2019
New Revision: 358763
URL: http://llvm.org/viewvc/llvm-project?rev=358763&view=rev
Log:
[NewPassManager] Adding pass tuning options: loop vectorize.
Summary:
Trying to add the plumbing necessary to add tuning options to the new pass manager.
Testing with the flags for loop vectorize.
Reviewers: chandlerc
Subscribers: sanjoy, mehdi_amini, jlebar, steven_wu, dexonsmith, dang, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59723
Modified:
llvm/trunk/include/llvm/Passes/PassBuilder.h
llvm/trunk/include/llvm/Transforms/Vectorize.h
llvm/trunk/include/llvm/Transforms/Vectorize/LoopVectorize.h
llvm/trunk/lib/LTO/LTOBackend.cpp
llvm/trunk/lib/Passes/PassBuilder.cpp
llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp
llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/trunk/tools/opt/NewPMDriver.cpp
llvm/trunk/unittests/IR/PassBuilderCallbacksTest.cpp
Modified: llvm/trunk/include/llvm/Passes/PassBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Passes/PassBuilder.h?rev=358763&r1=358762&r2=358763&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Passes/PassBuilder.h (original)
+++ llvm/trunk/include/llvm/Passes/PassBuilder.h Fri Apr 19 09:11:59 2019
@@ -66,6 +66,22 @@ struct PGOOptions {
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 @@ struct PGOOptions {
/// construction.
class PassBuilder {
TargetMachine *TM;
+ PipelineTuningOptions PTO;
Optional<PGOOptions> PGOOpt;
PassInstrumentationCallbacks *PIC;
@@ -190,9 +207,10 @@ public:
};
explicit PassBuilder(TargetMachine *TM = nullptr,
+ PipelineTuningOptions PTO = PipelineTuningOptions(),
Optional<PGOOptions> 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.
///
Modified: llvm/trunk/include/llvm/Transforms/Vectorize.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Vectorize.h?rev=358763&r1=358762&r2=358763&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Vectorize.h (original)
+++ llvm/trunk/include/llvm/Transforms/Vectorize.h Fri Apr 19 09:11:59 2019
@@ -109,8 +109,9 @@ struct VectorizeConfig {
//
// LoopVectorize - Create a loop vectorization pass.
//
-Pass *createLoopVectorizePass(bool InterleaveOnlyWhenForced = false,
- bool VectorizeOnlyWhenForced = false);
+Pass *createLoopVectorizePass();
+Pass *createLoopVectorizePass(bool InterleaveOnlyWhenForced,
+ bool VectorizeOnlyWhenForced);
//===----------------------------------------------------------------------===//
//
Modified: llvm/trunk/include/llvm/Transforms/Vectorize/LoopVectorize.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Vectorize/LoopVectorize.h?rev=358763&r1=358762&r2=358763&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Vectorize/LoopVectorize.h (original)
+++ llvm/trunk/include/llvm/Transforms/Vectorize/LoopVectorize.h Fri Apr 19 09:11:59 2019
@@ -76,6 +76,9 @@ class ScalarEvolution;
class TargetLibraryInfo;
class TargetTransformInfo;
+extern cl::opt<bool> EnableLoopInterleaving;
+extern cl::opt<bool> EnableLoopVectorization;
+
struct LoopVectorizeOptions {
/// If false, consider all loops for interleaving.
/// If true, only loops that explicitly request interleaving are considered.
@@ -85,8 +88,21 @@ struct LoopVectorizeOptions {
/// If true, only loops that explicitly request vectorization are considered.
bool VectorizeOnlyWhenForced;
+ /// 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 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).
LoopVectorizeOptions()
: InterleaveOnlyWhenForced(false), VectorizeOnlyWhenForced(false) {}
+ LoopVectorizeOptions(bool InterleaveOnlyWhenForced,
+ bool VectorizeOnlyWhenForced)
+ : InterleaveOnlyWhenForced(InterleaveOnlyWhenForced),
+ VectorizeOnlyWhenForced(VectorizeOnlyWhenForced) {}
LoopVectorizeOptions &setInterleaveOnlyWhenForced(bool Value) {
InterleaveOnlyWhenForced = Value;
Modified: llvm/trunk/lib/LTO/LTOBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOBackend.cpp?rev=358763&r1=358762&r2=358763&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOBackend.cpp (original)
+++ llvm/trunk/lib/LTO/LTOBackend.cpp Fri Apr 19 09:11:59 2019
@@ -164,7 +164,7 @@ static void runNewPMPasses(Config &Conf,
PGOOptions::IRUse, PGOOptions::CSIRUse);
}
- PassBuilder PB(TM, PGOOpt);
+ PassBuilder PB(TM, PipelineTuningOptions(), PGOOpt);
AAManager AA;
// Parse a custom AA pipeline if asked to.
Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=358763&r1=358762&r2=358763&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Fri Apr 19 09:11:59 2019
@@ -215,6 +215,11 @@ static cl::opt<bool>
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<bool> EnableHotColdSplit;
extern cl::opt<bool> EnableOrderFileInstrumentation;
@@ -857,7 +862,8 @@ ModulePassManager PassBuilder::buildModu
OptimizePM.addPass(LoopDistributePass());
// Now run the core loop vectorizer.
- OptimizePM.addPass(LoopVectorizePass());
+ OptimizePM.addPass(LoopVectorizePass(
+ LoopVectorizeOptions(!PTO.LoopInterleaving, !PTO.LoopVectorization)));
// Eliminate loads by forwarding stores from the previous iteration to loads
// of the current iteration.
Modified: llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp?rev=358763&r1=358762&r2=358763&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp Fri Apr 19 09:11:59 2019
@@ -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;
@@ -49,10 +50,6 @@ static cl::opt<bool>
cl::ZeroOrMore, cl::desc("Run Partial inlinining pass"));
static cl::opt<bool>
- RunLoopVectorization("vectorize-loops", cl::Hidden,
- cl::desc("Run the Loop vectorization passes"));
-
-static cl::opt<bool>
RunSLPVectorization("vectorize-slp", cl::Hidden,
cl::desc("Run the SLP vectorization passes"));
@@ -167,7 +164,10 @@ PassManagerBuilder::PassManagerBuilder()
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;
Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=358763&r1=358762&r2=358763&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Fri Apr 19 09:11:59 2019
@@ -277,6 +277,13 @@ static cl::opt<bool> VPlanBuildStressTes
"out right after the build (stress test the VPlan H-CFG construction "
"in the VPlan-native vectorization path)."));
+cl::opt<bool> llvm::EnableLoopInterleaving(
+ "interleave-loops", cl::init(true), cl::Hidden,
+ cl::desc("Enable loop interleaving in Loop vectorization passes"));
+cl::opt<bool> llvm::EnableLoopVectorization(
+ "vectorize-loops", cl::init(false), cl::Hidden,
+ cl::desc("Run the Loop vectorization passes"));
+
/// 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.
@@ -6063,6 +6070,8 @@ INITIALIZE_PASS_END(LoopVectorize, LV_NA
namespace llvm {
+Pass *createLoopVectorizePass() { return new LoopVectorize(); }
+
Pass *createLoopVectorizePass(bool InterleaveOnlyWhenForced,
bool VectorizeOnlyWhenForced) {
return new LoopVectorize(InterleaveOnlyWhenForced, VectorizeOnlyWhenForced);
Modified: llvm/trunk/tools/opt/NewPMDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/NewPMDriver.cpp?rev=358763&r1=358762&r2=358763&view=diff
==============================================================================
--- llvm/trunk/tools/opt/NewPMDriver.cpp (original)
+++ llvm/trunk/tools/opt/NewPMDriver.cpp Fri Apr 19 09:11:59 2019
@@ -261,7 +261,7 @@ bool llvm::runPassPipeline(StringRef Arg
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
Modified: llvm/trunk/unittests/IR/PassBuilderCallbacksTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/PassBuilderCallbacksTest.cpp?rev=358763&r1=358762&r2=358763&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/PassBuilderCallbacksTest.cpp (original)
+++ llvm/trunk/unittests/IR/PassBuilderCallbacksTest.cpp Fri Apr 19 09:11:59 2019
@@ -414,7 +414,8 @@ protected:
"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.
More information about the llvm-commits
mailing list