Skip to content

Commit 0499a2f

Browse files
committed
[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 llvm-svn: 358763
1 parent 51873d3 commit 0499a2f

File tree

9 files changed

+63
-12
lines changed

9 files changed

+63
-12
lines changed

llvm/include/llvm/Passes/PassBuilder.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ struct PGOOptions {
6666
bool SamplePGOSupport;
6767
};
6868

69+
/// Tunable parameters for passes in the default pipelines.
70+
class PipelineTuningOptions {
71+
public:
72+
/// Constructor sets pipeline tuning defaults based on cl::opts. Each option
73+
/// can be set in the PassBuilder when using a LLVM as a library.
74+
PipelineTuningOptions();
75+
76+
/// Tuning option to set loop interleaving on/off. Its default value is that
77+
/// of the flag: `-interleave-loops`.
78+
bool LoopInterleaving;
79+
80+
/// Tuning option to enable/disable loop vectorization. Its default value is
81+
/// that of the flag: `-vectorize-loops`.
82+
bool LoopVectorization;
83+
};
84+
6985
/// This class provides access to building LLVM's passes.
7086
///
7187
/// Its members provide the baseline state available to passes during their
@@ -74,6 +90,7 @@ struct PGOOptions {
7490
/// construction.
7591
class PassBuilder {
7692
TargetMachine *TM;
93+
PipelineTuningOptions PTO;
7794
Optional<PGOOptions> PGOOpt;
7895
PassInstrumentationCallbacks *PIC;
7996

@@ -190,9 +207,10 @@ class PassBuilder {
190207
};
191208

192209
explicit PassBuilder(TargetMachine *TM = nullptr,
210+
PipelineTuningOptions PTO = PipelineTuningOptions(),
193211
Optional<PGOOptions> PGOOpt = None,
194212
PassInstrumentationCallbacks *PIC = nullptr)
195-
: TM(TM), PGOOpt(PGOOpt), PIC(PIC) {}
213+
: TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC) {}
196214

197215
/// Cross register the analysis managers through their proxies.
198216
///

llvm/include/llvm/Transforms/Vectorize.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ struct VectorizeConfig {
109109
//
110110
// LoopVectorize - Create a loop vectorization pass.
111111
//
112-
Pass *createLoopVectorizePass(bool InterleaveOnlyWhenForced = false,
113-
bool VectorizeOnlyWhenForced = false);
112+
Pass *createLoopVectorizePass();
113+
Pass *createLoopVectorizePass(bool InterleaveOnlyWhenForced,
114+
bool VectorizeOnlyWhenForced);
114115

115116
//===----------------------------------------------------------------------===//
116117
//

llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class ScalarEvolution;
7676
class TargetLibraryInfo;
7777
class TargetTransformInfo;
7878

79+
extern cl::opt<bool> EnableLoopInterleaving;
80+
extern cl::opt<bool> EnableLoopVectorization;
81+
7982
struct LoopVectorizeOptions {
8083
/// If false, consider all loops for interleaving.
8184
/// If true, only loops that explicitly request interleaving are considered.
@@ -85,8 +88,21 @@ struct LoopVectorizeOptions {
8588
/// If true, only loops that explicitly request vectorization are considered.
8689
bool VectorizeOnlyWhenForced;
8790

91+
/// The current defaults when creating the pass with no arguments are:
92+
/// EnableLoopInterleaving = true and EnableLoopVectorization = true. This
93+
/// means that interleaving default is consistent with the cl::opt flag, while
94+
/// vectorization is not.
95+
/// FIXME: The default for EnableLoopVectorization in the cl::opt should be
96+
/// set to true, and the corresponding change to account for this be made in
97+
/// opt.cpp. The initializations below will become:
98+
/// InterleaveOnlyWhenForced(!EnableLoopInterleaving)
99+
/// VectorizeOnlyWhenForced(!EnableLoopVectorization).
88100
LoopVectorizeOptions()
89101
: InterleaveOnlyWhenForced(false), VectorizeOnlyWhenForced(false) {}
102+
LoopVectorizeOptions(bool InterleaveOnlyWhenForced,
103+
bool VectorizeOnlyWhenForced)
104+
: InterleaveOnlyWhenForced(InterleaveOnlyWhenForced),
105+
VectorizeOnlyWhenForced(VectorizeOnlyWhenForced) {}
90106

91107
LoopVectorizeOptions &setInterleaveOnlyWhenForced(bool Value) {
92108
InterleaveOnlyWhenForced = Value;

llvm/lib/LTO/LTOBackend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static void runNewPMPasses(Config &Conf, Module &Mod, TargetMachine *TM,
164164
PGOOptions::IRUse, PGOOptions::CSIRUse);
165165
}
166166

167-
PassBuilder PB(TM, PGOOpt);
167+
PassBuilder PB(TM, PipelineTuningOptions(), PGOOpt);
168168
AAManager AA;
169169

170170
// Parse a custom AA pipeline if asked to.

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ static cl::opt<bool>
215215
EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden,
216216
cl::desc("Enable control height reduction optimization (CHR)"));
217217

218+
PipelineTuningOptions::PipelineTuningOptions() {
219+
LoopInterleaving = EnableLoopInterleaving;
220+
LoopVectorization = EnableLoopVectorization;
221+
}
222+
218223
extern cl::opt<bool> EnableHotColdSplit;
219224
extern cl::opt<bool> EnableOrderFileInstrumentation;
220225

@@ -857,7 +862,8 @@ ModulePassManager PassBuilder::buildModuleOptimizationPipeline(
857862
OptimizePM.addPass(LoopDistributePass());
858863

859864
// Now run the core loop vectorizer.
860-
OptimizePM.addPass(LoopVectorizePass());
865+
OptimizePM.addPass(LoopVectorizePass(
866+
LoopVectorizeOptions(!PTO.LoopInterleaving, !PTO.LoopVectorization)));
861867

862868
// Eliminate loads by forwarding stores from the previous iteration to loads
863869
// of the current iteration.

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,14 @@
4141
#include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h"
4242
#include "llvm/Transforms/Utils.h"
4343
#include "llvm/Transforms/Vectorize.h"
44+
#include "llvm/Transforms/Vectorize/LoopVectorize.h"
4445

4546
using namespace llvm;
4647

4748
static cl::opt<bool>
4849
RunPartialInlining("enable-partial-inlining", cl::init(false), cl::Hidden,
4950
cl::ZeroOrMore, cl::desc("Run Partial inlinining pass"));
5051

51-
static cl::opt<bool>
52-
RunLoopVectorization("vectorize-loops", cl::Hidden,
53-
cl::desc("Run the Loop vectorization passes"));
54-
5552
static cl::opt<bool>
5653
RunSLPVectorization("vectorize-slp", cl::Hidden,
5754
cl::desc("Run the SLP vectorization passes"));
@@ -167,7 +164,10 @@ PassManagerBuilder::PassManagerBuilder() {
167164
Inliner = nullptr;
168165
DisableUnrollLoops = false;
169166
SLPVectorize = RunSLPVectorization;
170-
LoopVectorize = RunLoopVectorization;
167+
LoopVectorize = EnableLoopVectorization;
168+
// FIXME: Add: LoopsInterleaved = EnableLoopInterleaving;
169+
// Replace usage of DisableUnrollLoops with LoopsInterleaved when creating
170+
// the LoopVectorize pass, to be consistent with the new pass manager.
171171
RerollLoops = RunLoopRerolling;
172172
NewGVN = RunNewGVN;
173173
DisableGVNLoadPRE = false;

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ static cl::opt<bool> VPlanBuildStressTest(
277277
"out right after the build (stress test the VPlan H-CFG construction "
278278
"in the VPlan-native vectorization path)."));
279279

280+
cl::opt<bool> llvm::EnableLoopInterleaving(
281+
"interleave-loops", cl::init(true), cl::Hidden,
282+
cl::desc("Enable loop interleaving in Loop vectorization passes"));
283+
cl::opt<bool> llvm::EnableLoopVectorization(
284+
"vectorize-loops", cl::init(false), cl::Hidden,
285+
cl::desc("Run the Loop vectorization passes"));
286+
280287
/// A helper function for converting Scalar types to vector types.
281288
/// If the incoming type is void, we return void. If the VF is 1, we return
282289
/// the scalar type.
@@ -6063,6 +6070,8 @@ INITIALIZE_PASS_END(LoopVectorize, LV_NAME, lv_name, false, false)
60636070

60646071
namespace llvm {
60656072

6073+
Pass *createLoopVectorizePass() { return new LoopVectorize(); }
6074+
60666075
Pass *createLoopVectorizePass(bool InterleaveOnlyWhenForced,
60676076
bool VectorizeOnlyWhenForced) {
60686077
return new LoopVectorize(InterleaveOnlyWhenForced, VectorizeOnlyWhenForced);

llvm/tools/opt/NewPMDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
261261
StandardInstrumentations SI;
262262
SI.registerCallbacks(PIC);
263263

264-
PassBuilder PB(TM, P, &PIC);
264+
PassBuilder PB(TM, PipelineTuningOptions(), P, &PIC);
265265
registerEPCallbacks(PB, VerifyEachPass, DebugPM);
266266

267267
// Load requested pass plugins and let them register pass builder callbacks

llvm/unittests/IR/PassBuilderCallbacksTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ class PassBuilderCallbacksTest<PassManager<
414414
"exit:\n"
415415
" ret void\n"
416416
"}\n")),
417-
CallbacksHandle(), PB(nullptr, None, &CallbacksHandle.Callbacks),
417+
CallbacksHandle(),
418+
PB(nullptr, PipelineTuningOptions(), None, &CallbacksHandle.Callbacks),
418419
PM(true), LAM(true), FAM(true), CGAM(true), AM(true) {
419420

420421
/// Register a callback for analysis registration.

0 commit comments

Comments
 (0)