llvm.org GIT mirror llvm / a837603
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358763 91177308-0d34-0410-b5e6-96231b3b80d8 Alina Sbirlea 3 months ago
9 changed file(s) with 63 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
6565 bool SamplePGOSupport;
6666 };
6767
68 /// Tunable parameters for passes in the default pipelines.
69 class PipelineTuningOptions {
70 public:
71 /// Constructor sets pipeline tuning defaults based on cl::opts. Each option
72 /// can be set in the PassBuilder when using a LLVM as a library.
73 PipelineTuningOptions();
74
75 /// Tuning option to set loop interleaving on/off. Its default value is that
76 /// of the flag: `-interleave-loops`.
77 bool LoopInterleaving;
78
79 /// Tuning option to enable/disable loop vectorization. Its default value is
80 /// that of the flag: `-vectorize-loops`.
81 bool LoopVectorization;
82 };
83
6884 /// This class provides access to building LLVM's passes.
6985 ///
7086 /// Its members provide the baseline state available to passes during their
7389 /// construction.
7490 class PassBuilder {
7591 TargetMachine *TM;
92 PipelineTuningOptions PTO;
7693 Optional PGOOpt;
7794 PassInstrumentationCallbacks *PIC;
7895
189206 };
190207
191208 explicit PassBuilder(TargetMachine *TM = nullptr,
209 PipelineTuningOptions PTO = PipelineTuningOptions(),
192210 Optional PGOOpt = None,
193211 PassInstrumentationCallbacks *PIC = nullptr)
194 : TM(TM), PGOOpt(PGOOpt), PIC(PIC) {}
212 : TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC) {}
195213
196214 /// Cross register the analysis managers through their proxies.
197215 ///
7575 class TargetLibraryInfo;
7676 class TargetTransformInfo;
7777
78 extern cl::opt EnableLoopInterleaving;
79 extern cl::opt EnableLoopVectorization;
80
7881 struct LoopVectorizeOptions {
7982 /// If false, consider all loops for interleaving.
8083 /// If true, only loops that explicitly request interleaving are considered.
8487 /// If true, only loops that explicitly request vectorization are considered.
8588 bool VectorizeOnlyWhenForced;
8689
90 /// The current defaults when creating the pass with no arguments are:
91 /// EnableLoopInterleaving = true and EnableLoopVectorization = true. This
92 /// means that interleaving default is consistent with the cl::opt flag, while
93 /// vectorization is not.
94 /// FIXME: The default for EnableLoopVectorization in the cl::opt should be
95 /// set to true, and the corresponding change to account for this be made in
96 /// opt.cpp. The initializations below will become:
97 /// InterleaveOnlyWhenForced(!EnableLoopInterleaving)
98 /// VectorizeOnlyWhenForced(!EnableLoopVectorization).
8799 LoopVectorizeOptions()
88100 : InterleaveOnlyWhenForced(false), VectorizeOnlyWhenForced(false) {}
101 LoopVectorizeOptions(bool InterleaveOnlyWhenForced,
102 bool VectorizeOnlyWhenForced)
103 : InterleaveOnlyWhenForced(InterleaveOnlyWhenForced),
104 VectorizeOnlyWhenForced(VectorizeOnlyWhenForced) {}
89105
90106 LoopVectorizeOptions &setInterleaveOnlyWhenForced(bool Value) {
91107 InterleaveOnlyWhenForced = Value;
108108 //
109109 // LoopVectorize - Create a loop vectorization pass.
110110 //
111 Pass *createLoopVectorizePass(bool InterleaveOnlyWhenForced = false,
112 bool VectorizeOnlyWhenForced = false);
111 Pass *createLoopVectorizePass();
112 Pass *createLoopVectorizePass(bool InterleaveOnlyWhenForced,
113 bool VectorizeOnlyWhenForced);
113114
114115 //===----------------------------------------------------------------------===//
115116 //
163163 PGOOptions::IRUse, PGOOptions::CSIRUse);
164164 }
165165
166 PassBuilder PB(TM, PGOOpt);
166 PassBuilder PB(TM, PipelineTuningOptions(), PGOOpt);
167167 AAManager AA;
168168
169169 // Parse a custom AA pipeline if asked to.
214214 EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden,
215215 cl::desc("Enable control height reduction optimization (CHR)"));
216216
217 PipelineTuningOptions::PipelineTuningOptions() {
218 LoopInterleaving = EnableLoopInterleaving;
219 LoopVectorization = EnableLoopVectorization;
220 }
221
217222 extern cl::opt EnableHotColdSplit;
218223 extern cl::opt EnableOrderFileInstrumentation;
219224
856861 OptimizePM.addPass(LoopDistributePass());
857862
858863 // Now run the core loop vectorizer.
859 OptimizePM.addPass(LoopVectorizePass());
864 OptimizePM.addPass(LoopVectorizePass(
865 LoopVectorizeOptions(!PTO.LoopInterleaving, !PTO.LoopVectorization)));
860866
861867 // Eliminate loads by forwarding stores from the previous iteration to loads
862868 // of the current iteration.
4040 #include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h"
4141 #include "llvm/Transforms/Utils.h"
4242 #include "llvm/Transforms/Vectorize.h"
43 #include "llvm/Transforms/Vectorize/LoopVectorize.h"
4344
4445 using namespace llvm;
4546
4647 static cl::opt
4748 RunPartialInlining("enable-partial-inlining", cl::init(false), cl::Hidden,
4849 cl::ZeroOrMore, cl::desc("Run Partial inlinining pass"));
49
50 static cl::opt
51 RunLoopVectorization("vectorize-loops", cl::Hidden,
52 cl::desc("Run the Loop vectorization passes"));
5350
5451 static cl::opt
5552 RunSLPVectorization("vectorize-slp", cl::Hidden,
166163 Inliner = nullptr;
167164 DisableUnrollLoops = false;
168165 SLPVectorize = RunSLPVectorization;
169 LoopVectorize = RunLoopVectorization;
166 LoopVectorize = EnableLoopVectorization;
167 // FIXME: Add: LoopsInterleaved = EnableLoopInterleaving;
168 // Replace usage of DisableUnrollLoops with LoopsInterleaved when creating
169 // the LoopVectorize pass, to be consistent with the new pass manager.
170170 RerollLoops = RunLoopRerolling;
171171 NewGVN = RunNewGVN;
172172 DisableGVNLoadPRE = false;
276276 "out right after the build (stress test the VPlan H-CFG construction "
277277 "in the VPlan-native vectorization path)."));
278278
279 cl::opt llvm::EnableLoopInterleaving(
280 "interleave-loops", cl::init(true), cl::Hidden,
281 cl::desc("Enable loop interleaving in Loop vectorization passes"));
282 cl::opt llvm::EnableLoopVectorization(
283 "vectorize-loops", cl::init(false), cl::Hidden,
284 cl::desc("Run the Loop vectorization passes"));
285
279286 /// A helper function for converting Scalar types to vector types.
280287 /// If the incoming type is void, we return void. If the VF is 1, we return
281288 /// the scalar type.
60626069
60636070 namespace llvm {
60646071
6072 Pass *createLoopVectorizePass() { return new LoopVectorize(); }
6073
60656074 Pass *createLoopVectorizePass(bool InterleaveOnlyWhenForced,
60666075 bool VectorizeOnlyWhenForced) {
60676076 return new LoopVectorize(InterleaveOnlyWhenForced, VectorizeOnlyWhenForced);
260260 StandardInstrumentations SI;
261261 SI.registerCallbacks(PIC);
262262
263 PassBuilder PB(TM, P, &PIC);
263 PassBuilder PB(TM, PipelineTuningOptions(), P, &PIC);
264264 registerEPCallbacks(PB, VerifyEachPass, DebugPM);
265265
266266 // Load requested pass plugins and let them register pass builder callbacks
413413 "exit:\n"
414414 " ret void\n"
415415 "}\n")),
416 CallbacksHandle(), PB(nullptr, None, &CallbacksHandle.Callbacks),
416 CallbacksHandle(),
417 PB(nullptr, PipelineTuningOptions(), None, &CallbacksHandle.Callbacks),
417418 PM(true), LAM(true), FAM(true), CGAM(true), AM(true) {
418419
419420 /// Register a callback for analysis registration.