LLVM  10.0.0svn
PassBuilder.h
Go to the documentation of this file.
1 //===- Parsing, selection, and construction of pass pipelines --*- C++ -*--===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// Interfaces for registering analysis passes, producing common pass manager
11 /// configurations, and parsing of pass pipelines.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_PASSES_PASSBUILDER_H
16 #define LLVM_PASSES_PASSBUILDER_H
17 
18 #include "llvm/ADT/Optional.h"
20 #include "llvm/IR/PassManager.h"
21 #include "llvm/Support/Error.h"
24 #include <vector>
25 
26 namespace llvm {
27 class StringRef;
28 class AAManager;
29 class TargetMachine;
30 class ModuleSummaryIndex;
31 
32 /// A struct capturing PGO tunables.
33 struct PGOOptions {
36  PGOOptions(std::string ProfileFile = "", std::string CSProfileGenFile = "",
37  std::string ProfileRemappingFile = "", PGOAction Action = NoAction,
42  SamplePGOSupport(SamplePGOSupport || Action == SampleUse) {
43  // Note, we do allow ProfileFile.empty() for Action=IRUse LTO can
44  // callback with IRUse action without ProfileFile.
45 
46  // If there is a CSAction, PGOAction cannot be IRInstr or SampleUse.
47  assert(this->CSAction == NoCSAction ||
48  (this->Action != IRInstr && this->Action != SampleUse));
49 
50  // For CSIRInstr, CSProfileGenFile also needs to be nonempty.
51  assert(this->CSAction != CSIRInstr || !this->CSProfileGenFile.empty());
52 
53  // If CSAction is CSIRUse, PGOAction needs to be IRUse as they share
54  // a profile.
55  assert(this->CSAction != CSIRUse || this->Action == IRUse);
56 
57  // If neither Action nor CSAction, SamplePGOSupport needs to be true.
58  assert(this->Action != NoAction || this->CSAction != NoCSAction ||
59  this->SamplePGOSupport);
60  }
61  std::string ProfileFile;
62  std::string CSProfileGenFile;
63  std::string ProfileRemappingFile;
67 };
68 
69 /// Tunable parameters for passes in the default pipelines.
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.
75 
76  /// Tuning option to set loop interleaving on/off. Its default value is that
77  /// of the flag: `-interleave-loops`.
79 
80  /// Tuning option to enable/disable loop vectorization. Its default value is
81  /// that of the flag: `-vectorize-loops`.
83 
84  /// Tuning option to enable/disable slp loop vectorization. Its default value
85  /// is that of the flag: `vectorize-slp`.
87 
88  /// Tuning option to enable/disable loop unrolling. Its default value is true.
90 
91  /// Tuning option to forget all SCEV loops in LoopUnroll. Its default value
92  /// is that of the flag: `-forget-scev-loop-unroll`.
94 
95  /// Tuning option to cap the number of calls to retrive clobbering accesses in
96  /// MemorySSA, in LICM.
97  unsigned LicmMssaOptCap;
98 
99  /// Tuning option to disable promotion to scalars in LICM with MemorySSA, if
100  /// the number of access is too large.
102 };
103 
104 /// This class provides access to building LLVM's passes.
105 ///
106 /// Its members provide the baseline state available to passes during their
107 /// construction. The \c PassRegistry.def file specifies how to construct all
108 /// of the built-in passes, and those may reference these members during
109 /// construction.
110 class PassBuilder {
111  TargetMachine *TM;
113  Optional<PGOOptions> PGOOpt;
115 
116 public:
117  /// A struct to capture parsed pass pipeline names.
118  ///
119  /// A pipeline is defined as a series of names, each of which may in itself
120  /// recursively contain a nested pipeline. A name is either the name of a pass
121  /// (e.g. "instcombine") or the name of a pipeline type (e.g. "cgscc"). If the
122  /// name is the name of a pass, the InnerPipeline is empty, since passes
123  /// cannot contain inner pipelines. See parsePassPipeline() for a more
124  /// detailed description of the textual pipeline format.
127  std::vector<PipelineElement> InnerPipeline;
128  };
129 
130  /// ThinLTO phase.
131  ///
132  /// This enumerates the LLVM ThinLTO optimization phases.
133  enum class ThinLTOPhase {
134  /// No ThinLTO behavior needed.
135  None,
136  /// ThinLTO prelink (summary) phase.
137  PreLink,
138  /// ThinLTO postlink (backend compile) phase.
139  PostLink
140  };
141 
142  /// LLVM-provided high-level optimization levels.
143  ///
144  /// This enumerates the LLVM-provided high-level optimization levels. Each
145  /// level has a specific goal and rationale.
147  /// Disable as many optimizations as possible. This doesn't completely
148  /// disable the optimizer in all cases, for example always_inline functions
149  /// can be required to be inlined for correctness.
150  O0,
151 
152  /// Optimize quickly without destroying debuggability.
153  ///
154  /// FIXME: The current and historical behavior of this level does *not*
155  /// agree with this goal, but we would like to move toward this goal in the
156  /// future.
157  ///
158  /// This level is tuned to produce a result from the optimizer as quickly
159  /// as possible and to avoid destroying debuggability. This tends to result
160  /// in a very good development mode where the compiled code will be
161  /// immediately executed as part of testing. As a consequence, where
162  /// possible, we would like to produce efficient-to-execute code, but not
163  /// if it significantly slows down compilation or would prevent even basic
164  /// debugging of the resulting binary.
165  ///
166  /// As an example, complex loop transformations such as versioning,
167  /// vectorization, or fusion might not make sense here due to the degree to
168  /// which the executed code would differ from the source code, and the
169  /// potential compile time cost.
170  O1,
171 
172  /// Optimize for fast execution as much as possible without triggering
173  /// significant incremental compile time or code size growth.
174  ///
175  /// The key idea is that optimizations at this level should "pay for
176  /// themselves". So if an optimization increases compile time by 5% or
177  /// increases code size by 5% for a particular benchmark, that benchmark
178  /// should also be one which sees a 5% runtime improvement. If the compile
179  /// time or code size penalties happen on average across a diverse range of
180  /// LLVM users' benchmarks, then the improvements should as well.
181  ///
182  /// And no matter what, the compile time needs to not grow superlinearly
183  /// with the size of input to LLVM so that users can control the runtime of
184  /// the optimizer in this mode.
185  ///
186  /// This is expected to be a good default optimization level for the vast
187  /// majority of users.
188  O2,
189 
190  /// Optimize for fast execution as much as possible.
191  ///
192  /// This mode is significantly more aggressive in trading off compile time
193  /// and code size to get execution time improvements. The core idea is that
194  /// this mode should include any optimization that helps execution time on
195  /// balance across a diverse collection of benchmarks, even if it increases
196  /// code size or compile time for some benchmarks without corresponding
197  /// improvements to execution time.
198  ///
199  /// Despite being willing to trade more compile time off to get improved
200  /// execution time, this mode still tries to avoid superlinear growth in
201  /// order to make even significantly slower compile times at least scale
202  /// reasonably. This does not preclude very substantial constant factor
203  /// costs though.
204  O3,
205 
206  /// Similar to \c O2 but tries to optimize for small code size instead of
207  /// fast execution without triggering significant incremental execution
208  /// time slowdowns.
209  ///
210  /// The logic here is exactly the same as \c O2, but with code size and
211  /// execution time metrics swapped.
212  ///
213  /// A consequence of the different core goal is that this should in general
214  /// produce substantially smaller executables that still run in
215  /// a reasonable amount of time.
216  Os,
217 
218  /// A very specialized mode that will optimize for code size at any and all
219  /// costs.
220  ///
221  /// This is useful primarily when there are absolute size limitations and
222  /// any effort taken to reduce the size is worth it regardless of the
223  /// execution time impact. You should expect this level to produce rather
224  /// slow, but very small, code.
225  Oz
226  };
227 
228  explicit PassBuilder(TargetMachine *TM = nullptr,
230  Optional<PGOOptions> PGOOpt = None,
231  PassInstrumentationCallbacks *PIC = nullptr)
232  : TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC) {}
233 
234  /// Cross register the analysis managers through their proxies.
235  ///
236  /// This is an interface that can be used to cross register each
237  /// AnalysisManager with all the others analysis managers.
238  void crossRegisterProxies(LoopAnalysisManager &LAM,
240  CGSCCAnalysisManager &CGAM,
241  ModuleAnalysisManager &MAM);
242 
243  /// Registers all available module analysis passes.
244  ///
245  /// This is an interface that can be used to populate a \c
246  /// ModuleAnalysisManager with all registered module analyses. Callers can
247  /// still manually register any additional analyses. Callers can also
248  /// pre-register analyses and this will not override those.
249  void registerModuleAnalyses(ModuleAnalysisManager &MAM);
250 
251  /// Registers all available CGSCC analysis passes.
252  ///
253  /// This is an interface that can be used to populate a \c CGSCCAnalysisManager
254  /// with all registered CGSCC analyses. Callers can still manually register any
255  /// additional analyses. Callers can also pre-register analyses and this will
256  /// not override those.
257  void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM);
258 
259  /// Registers all available function analysis passes.
260  ///
261  /// This is an interface that can be used to populate a \c
262  /// FunctionAnalysisManager with all registered function analyses. Callers can
263  /// still manually register any additional analyses. Callers can also
264  /// pre-register analyses and this will not override those.
265  void registerFunctionAnalyses(FunctionAnalysisManager &FAM);
266 
267  /// Registers all available loop analysis passes.
268  ///
269  /// This is an interface that can be used to populate a \c LoopAnalysisManager
270  /// with all registered loop analyses. Callers can still manually register any
271  /// additional analyses.
272  void registerLoopAnalyses(LoopAnalysisManager &LAM);
273 
274  /// Construct the core LLVM function canonicalization and simplification
275  /// pipeline.
276  ///
277  /// This is a long pipeline and uses most of the per-function optimization
278  /// passes in LLVM to canonicalize and simplify the IR. It is suitable to run
279  /// repeatedly over the IR and is not expected to destroy important
280  /// information about the semantics of the IR.
281  ///
282  /// Note that \p Level cannot be `O0` here. The pipelines produced are
283  /// only intended for use when attempting to optimize code. If frontends
284  /// require some transformations for semantic reasons, they should explicitly
285  /// build them.
286  ///
287  /// \p Phase indicates the current ThinLTO phase.
289  buildFunctionSimplificationPipeline(OptimizationLevel Level,
291  bool DebugLogging = false);
292 
293  /// Construct the core LLVM module canonicalization and simplification
294  /// pipeline.
295  ///
296  /// This pipeline focuses on canonicalizing and simplifying the entire module
297  /// of IR. Much like the function simplification pipeline above, it is
298  /// suitable to run repeatedly over the IR and is not expected to destroy
299  /// important information. It does, however, perform inlining and other
300  /// heuristic based simplifications that are not strictly reversible.
301  ///
302  /// Note that \p Level cannot be `O0` here. The pipelines produced are
303  /// only intended for use when attempting to optimize code. If frontends
304  /// require some transformations for semantic reasons, they should explicitly
305  /// build them.
306  ///
307  /// \p Phase indicates the current ThinLTO phase.
309  buildModuleSimplificationPipeline(OptimizationLevel Level,
310  ThinLTOPhase Phase,
311  bool DebugLogging = false);
312 
313  /// Construct the core LLVM module optimization pipeline.
314  ///
315  /// This pipeline focuses on optimizing the execution speed of the IR. It
316  /// uses cost modeling and thresholds to balance code growth against runtime
317  /// improvements. It includes vectorization and other information destroying
318  /// transformations. It also cannot generally be run repeatedly on a module
319  /// without potentially seriously regressing either runtime performance of
320  /// the code or serious code size growth.
321  ///
322  /// Note that \p Level cannot be `O0` here. The pipelines produced are
323  /// only intended for use when attempting to optimize code. If frontends
324  /// require some transformations for semantic reasons, they should explicitly
325  /// build them.
326  ModulePassManager buildModuleOptimizationPipeline(OptimizationLevel Level,
327  bool DebugLogging = false,
328  bool LTOPreLink = false);
329 
330  /// Build a per-module default optimization pipeline.
331  ///
332  /// This provides a good default optimization pipeline for per-module
333  /// optimization and code generation without any link-time optimization. It
334  /// typically correspond to frontend "-O[123]" options for optimization
335  /// levels \c O1, \c O2 and \c O3 resp.
336  ///
337  /// Note that \p Level cannot be `O0` here. The pipelines produced are
338  /// only intended for use when attempting to optimize code. If frontends
339  /// require some transformations for semantic reasons, they should explicitly
340  /// build them.
341  ModulePassManager buildPerModuleDefaultPipeline(OptimizationLevel Level,
342  bool DebugLogging = false,
343  bool LTOPreLink = false);
344 
345  /// Build a pre-link, ThinLTO-targeting default optimization pipeline to
346  /// a pass manager.
347  ///
348  /// This adds the pre-link optimizations tuned to prepare a module for
349  /// a ThinLTO run. It works to minimize the IR which needs to be analyzed
350  /// without making irreversible decisions which could be made better during
351  /// the LTO run.
352  ///
353  /// Note that \p Level cannot be `O0` here. The pipelines produced are
354  /// only intended for use when attempting to optimize code. If frontends
355  /// require some transformations for semantic reasons, they should explicitly
356  /// build them.
358  buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level,
359  bool DebugLogging = false);
360 
361  /// Build an ThinLTO default optimization pipeline to a pass manager.
362  ///
363  /// This provides a good default optimization pipeline for link-time
364  /// optimization and code generation. It is particularly tuned to fit well
365  /// when IR coming into the LTO phase was first run through \c
366  /// addPreLinkLTODefaultPipeline, and the two coordinate closely.
367  ///
368  /// Note that \p Level cannot be `O0` here. The pipelines produced are
369  /// only intended for use when attempting to optimize code. If frontends
370  /// require some transformations for semantic reasons, they should explicitly
371  /// build them.
373  buildThinLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging,
374  const ModuleSummaryIndex *ImportSummary);
375 
376  /// Build a pre-link, LTO-targeting default optimization pipeline to a pass
377  /// manager.
378  ///
379  /// This adds the pre-link optimizations tuned to work well with a later LTO
380  /// run. It works to minimize the IR which needs to be analyzed without
381  /// making irreversible decisions which could be made better during the LTO
382  /// run.
383  ///
384  /// Note that \p Level cannot be `O0` here. The pipelines produced are
385  /// only intended for use when attempting to optimize code. If frontends
386  /// require some transformations for semantic reasons, they should explicitly
387  /// build them.
388  ModulePassManager buildLTOPreLinkDefaultPipeline(OptimizationLevel Level,
389  bool DebugLogging = false);
390 
391  /// Build an LTO default optimization pipeline to a pass manager.
392  ///
393  /// This provides a good default optimization pipeline for link-time
394  /// optimization and code generation. It is particularly tuned to fit well
395  /// when IR coming into the LTO phase was first run through \c
396  /// addPreLinkLTODefaultPipeline, and the two coordinate closely.
397  ///
398  /// Note that \p Level cannot be `O0` here. The pipelines produced are
399  /// only intended for use when attempting to optimize code. If frontends
400  /// require some transformations for semantic reasons, they should explicitly
401  /// build them.
402  ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level,
403  bool DebugLogging,
404  ModuleSummaryIndex *ExportSummary);
405 
406  /// Build the default `AAManager` with the default alias analysis pipeline
407  /// registered.
408  AAManager buildDefaultAAPipeline();
409 
410  /// Parse a textual pass pipeline description into a \c
411  /// ModulePassManager.
412  ///
413  /// The format of the textual pass pipeline description looks something like:
414  ///
415  /// module(function(instcombine,sroa),dce,cgscc(inliner,function(...)),...)
416  ///
417  /// Pass managers have ()s describing the nest structure of passes. All passes
418  /// are comma separated. As a special shortcut, if the very first pass is not
419  /// a module pass (as a module pass manager is), this will automatically form
420  /// the shortest stack of pass managers that allow inserting that first pass.
421  /// So, assuming function passes 'fpassN', CGSCC passes 'cgpassN', and loop
422  /// passes 'lpassN', all of these are valid:
423  ///
424  /// fpass1,fpass2,fpass3
425  /// cgpass1,cgpass2,cgpass3
426  /// lpass1,lpass2,lpass3
427  ///
428  /// And they are equivalent to the following (resp.):
429  ///
430  /// module(function(fpass1,fpass2,fpass3))
431  /// module(cgscc(cgpass1,cgpass2,cgpass3))
432  /// module(function(loop(lpass1,lpass2,lpass3)))
433  ///
434  /// This shortcut is especially useful for debugging and testing small pass
435  /// combinations. Note that these shortcuts don't introduce any other magic.
436  /// If the sequence of passes aren't all the exact same kind of pass, it will
437  /// be an error. You cannot mix different levels implicitly, you must
438  /// explicitly form a pass manager in which to nest passes.
439  Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
440  bool VerifyEachPass = true,
441  bool DebugLogging = false);
442 
443  /// {{@ Parse a textual pass pipeline description into a specific PassManager
444  ///
445  /// Automatic deduction of an appropriate pass manager stack is not supported.
446  /// For example, to insert a loop pass 'lpass' into a FunctionPassManager,
447  /// this is the valid pipeline text:
448  ///
449  /// function(lpass)
450  Error parsePassPipeline(CGSCCPassManager &CGPM, StringRef PipelineText,
451  bool VerifyEachPass = true,
452  bool DebugLogging = false);
453  Error parsePassPipeline(FunctionPassManager &FPM, StringRef PipelineText,
454  bool VerifyEachPass = true,
455  bool DebugLogging = false);
456  Error parsePassPipeline(LoopPassManager &LPM, StringRef PipelineText,
457  bool VerifyEachPass = true,
458  bool DebugLogging = false);
459  /// @}}
460 
461  /// Parse a textual alias analysis pipeline into the provided AA manager.
462  ///
463  /// The format of the textual AA pipeline is a comma separated list of AA
464  /// pass names:
465  ///
466  /// basic-aa,globals-aa,...
467  ///
468  /// The AA manager is set up such that the provided alias analyses are tried
469  /// in the order specified. See the \c AAManaager documentation for details
470  /// about the logic used. This routine just provides the textual mapping
471  /// between AA names and the analyses to register with the manager.
472  ///
473  /// Returns false if the text cannot be parsed cleanly. The specific state of
474  /// the \p AA manager is unspecified if such an error is encountered and this
475  /// returns false.
476  Error parseAAPipeline(AAManager &AA, StringRef PipelineText);
477 
478  /// Register a callback for a default optimizer pipeline extension
479  /// point
480  ///
481  /// This extension point allows adding passes that perform peephole
482  /// optimizations similar to the instruction combiner. These passes will be
483  /// inserted after each instance of the instruction combiner pass.
486  PeepholeEPCallbacks.push_back(C);
487  }
488 
489  /// Register a callback for a default optimizer pipeline extension
490  /// point
491  ///
492  /// This extension point allows adding late loop canonicalization and
493  /// simplification passes. This is the last point in the loop optimization
494  /// pipeline before loop deletion. Each pass added
495  /// here must be an instance of LoopPass.
496  /// This is the place to add passes that can remove loops, such as target-
497  /// specific loop idiom recognition.
500  LateLoopOptimizationsEPCallbacks.push_back(C);
501  }
502 
503  /// Register a callback for a default optimizer pipeline extension
504  /// point
505  ///
506  /// This extension point allows adding loop passes to the end of the loop
507  /// optimizer.
510  LoopOptimizerEndEPCallbacks.push_back(C);
511  }
512 
513  /// Register a callback for a default optimizer pipeline extension
514  /// point
515  ///
516  /// This extension point allows adding optimization passes after most of the
517  /// main optimizations, but before the last cleanup-ish optimizations.
520  ScalarOptimizerLateEPCallbacks.push_back(C);
521  }
522 
523  /// Register a callback for a default optimizer pipeline extension
524  /// point
525  ///
526  /// This extension point allows adding CallGraphSCC passes at the end of the
527  /// main CallGraphSCC passes and before any function simplification passes run
528  /// by CGPassManager.
531  CGSCCOptimizerLateEPCallbacks.push_back(C);
532  }
533 
534  /// Register a callback for a default optimizer pipeline extension
535  /// point
536  ///
537  /// This extension point allows adding optimization passes before the
538  /// vectorizer and other highly target specific optimization passes are
539  /// executed.
542  VectorizerStartEPCallbacks.push_back(C);
543  }
544 
545  /// Register a callback for a default optimizer pipeline extension point.
546  ///
547  /// This extension point allows adding optimization once at the start of the
548  /// pipeline. This does not apply to 'backend' compiles (LTO and ThinLTO
549  /// link-time pipelines).
551  const std::function<void(ModulePassManager &)> &C) {
552  PipelineStartEPCallbacks.push_back(C);
553  }
554 
555  /// Register a callback for a default optimizer pipeline extension point
556  ///
557  /// This extension point allows adding optimizations at the very end of the
558  /// function optimization pipeline. A key difference between this and the
559  /// legacy PassManager's OptimizerLast callback is that this extension point
560  /// is not triggered at O0. Extensions to the O0 pipeline should append their
561  /// passes to the end of the overall pipeline.
564  OptimizerLastEPCallbacks.push_back(C);
565  }
566 
567  /// Register a callback for parsing an AliasAnalysis Name to populate
568  /// the given AAManager \p AA
570  const std::function<bool(StringRef Name, AAManager &AA)> &C) {
571  AAParsingCallbacks.push_back(C);
572  }
573 
574  /// {{@ Register callbacks for analysis registration with this PassBuilder
575  /// instance.
576  /// Callees register their analyses with the given AnalysisManager objects.
578  const std::function<void(CGSCCAnalysisManager &)> &C) {
579  CGSCCAnalysisRegistrationCallbacks.push_back(C);
580  }
582  const std::function<void(FunctionAnalysisManager &)> &C) {
583  FunctionAnalysisRegistrationCallbacks.push_back(C);
584  }
586  const std::function<void(LoopAnalysisManager &)> &C) {
587  LoopAnalysisRegistrationCallbacks.push_back(C);
588  }
590  const std::function<void(ModuleAnalysisManager &)> &C) {
591  ModuleAnalysisRegistrationCallbacks.push_back(C);
592  }
593  /// @}}
594 
595  /// {{@ Register pipeline parsing callbacks with this pass builder instance.
596  /// Using these callbacks, callers can parse both a single pass name, as well
597  /// as entire sub-pipelines, and populate the PassManager instance
598  /// accordingly.
602  CGSCCPipelineParsingCallbacks.push_back(C);
603  }
607  FunctionPipelineParsingCallbacks.push_back(C);
608  }
612  LoopPipelineParsingCallbacks.push_back(C);
613  }
617  ModulePipelineParsingCallbacks.push_back(C);
618  }
619  /// @}}
620 
621  /// Register a callback for a top-level pipeline entry.
622  ///
623  /// If the PassManager type is not given at the top level of the pipeline
624  /// text, this Callback should be used to determine the appropriate stack of
625  /// PassManagers and populate the passed ModulePassManager.
628  bool VerifyEachPass, bool DebugLogging)> &C) {
629  TopLevelPipelineParsingCallbacks.push_back(C);
630  }
631 
632 private:
634  parsePipelineText(StringRef Text);
635 
636  Error parseModulePass(ModulePassManager &MPM, const PipelineElement &E,
637  bool VerifyEachPass, bool DebugLogging);
638  Error parseCGSCCPass(CGSCCPassManager &CGPM, const PipelineElement &E,
639  bool VerifyEachPass, bool DebugLogging);
640  Error parseFunctionPass(FunctionPassManager &FPM, const PipelineElement &E,
641  bool VerifyEachPass, bool DebugLogging);
642  Error parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
643  bool VerifyEachPass, bool DebugLogging);
644  bool parseAAPassName(AAManager &AA, StringRef Name);
645 
646  Error parseLoopPassPipeline(LoopPassManager &LPM,
647  ArrayRef<PipelineElement> Pipeline,
648  bool VerifyEachPass, bool DebugLogging);
649  Error parseFunctionPassPipeline(FunctionPassManager &FPM,
650  ArrayRef<PipelineElement> Pipeline,
651  bool VerifyEachPass, bool DebugLogging);
652  Error parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
653  ArrayRef<PipelineElement> Pipeline,
654  bool VerifyEachPass, bool DebugLogging);
655  Error parseModulePassPipeline(ModulePassManager &MPM,
656  ArrayRef<PipelineElement> Pipeline,
657  bool VerifyEachPass, bool DebugLogging);
658 
659  void addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
660  OptimizationLevel Level, bool RunProfileGen, bool IsCS,
661  std::string ProfileFile,
662  std::string ProfileRemappingFile);
663 
664  void invokePeepholeEPCallbacks(FunctionPassManager &, OptimizationLevel);
665 
666  // Extension Point callbacks
668  PeepholeEPCallbacks;
670  LateLoopOptimizationsEPCallbacks;
672  LoopOptimizerEndEPCallbacks;
674  ScalarOptimizerLateEPCallbacks;
676  CGSCCOptimizerLateEPCallbacks;
678  VectorizerStartEPCallbacks;
680  OptimizerLastEPCallbacks;
681  // Module callbacks
683  PipelineStartEPCallbacks;
685  ModuleAnalysisRegistrationCallbacks;
688  2>
689  ModulePipelineParsingCallbacks;
691  bool VerifyEachPass, bool DebugLogging)>,
692  2>
693  TopLevelPipelineParsingCallbacks;
694  // CGSCC callbacks
696  CGSCCAnalysisRegistrationCallbacks;
699  2>
700  CGSCCPipelineParsingCallbacks;
701  // Function callbacks
703  FunctionAnalysisRegistrationCallbacks;
706  2>
707  FunctionPipelineParsingCallbacks;
708  // Loop callbacks
710  LoopAnalysisRegistrationCallbacks;
713  2>
714  LoopPipelineParsingCallbacks;
715  // AA callbacks
717  AAParsingCallbacks;
718 };
719 
720 /// This utility template takes care of adding require<> and invalidate<>
721 /// passes for an analysis to a given \c PassManager. It is intended to be used
722 /// during parsing of a pass pipeline when parsing a single PipelineName.
723 /// When registering a new function analysis FancyAnalysis with the pass
724 /// pipeline name "fancy-analysis", a matching ParsePipelineCallback could look
725 /// like this:
726 ///
727 /// static bool parseFunctionPipeline(StringRef Name, FunctionPassManager &FPM,
728 /// ArrayRef<PipelineElement> P) {
729 /// if (parseAnalysisUtilityPasses<FancyAnalysis>("fancy-analysis", Name,
730 /// FPM))
731 /// return true;
732 /// return false;
733 /// }
734 template <typename AnalysisT, typename IRUnitT, typename AnalysisManagerT,
735  typename... ExtraArgTs>
737  StringRef AnalysisName, StringRef PipelineName,
739  if (!PipelineName.endswith(">"))
740  return false;
741  // See if this is an invalidate<> pass name
742  if (PipelineName.startswith("invalidate<")) {
743  PipelineName = PipelineName.substr(11, PipelineName.size() - 12);
744  if (PipelineName != AnalysisName)
745  return false;
747  return true;
748  }
749 
750  // See if this is a require<> pass name
751  if (PipelineName.startswith("require<")) {
752  PipelineName = PipelineName.substr(8, PipelineName.size() - 9);
753  if (PipelineName != AnalysisName)
754  return false;
755  PM.addPass(RequireAnalysisPass<AnalysisT, IRUnitT, AnalysisManagerT,
756  ExtraArgTs...>());
757  return true;
758  }
759 
760  return false;
761 }
762 }
763 
764 #endif
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, CGSCCPassManager &, ArrayRef< PipelineElement >)> &C)
{{@ Register pipeline parsing callbacks with this pass builder instance.
Definition: PassBuilder.h:599
uint64_t CallInst * C
bool LoopVectorization
Tuning option to enable/disable loop vectorization.
Definition: PassBuilder.h:82
LLVM_NODISCARD bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
Definition: StringRef.h:267
PGOOptions(std::string ProfileFile="", std::string CSProfileGenFile="", std::string ProfileRemappingFile="", PGOAction Action=NoAction, CSPGOAction CSAction=NoCSAction, bool SamplePGOSupport=false)
Definition: PassBuilder.h:36
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This header provides classes for managing a pipeline of passes over loops in LLVM IR...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:256
CSPGOAction CSAction
Definition: PassBuilder.h:65
OptimizationLevel
LLVM-provided high-level optimization levels.
Definition: PassBuilder.h:146
A utility pass template to force an analysis result to be available.
Definition: PassManager.h:1355
PassBuilder(TargetMachine *TM=nullptr, PipelineTuningOptions PTO=PipelineTuningOptions(), Optional< PGOOptions > PGOOpt=None, PassInstrumentationCallbacks *PIC=nullptr)
Definition: PassBuilder.h:228
Tunable parameters for passes in the default pipelines.
Definition: PassBuilder.h:70
PGOAction Action
Definition: PassBuilder.h:64
std::string ProfileFile
Definition: PassBuilder.h:61
Similar to O2 but tries to optimize for small code size instead of fast execution without triggering ...
Definition: PassBuilder.h:216
This class provides access to building LLVM&#39;s passes.
Definition: PassBuilder.h:110
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, ModulePassManager &, ArrayRef< PipelineElement >)> &C)
Definition: PassBuilder.h:614
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:578
void registerLoopOptimizerEndEPCallback(const std::function< void(LoopPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:508
void registerAnalysisRegistrationCallback(const std::function< void(ModuleAnalysisManager &)> &C)
Definition: PassBuilder.h:589
falkor hwpf fix Falkor HW Prefetch Fix Late Phase
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:130
std::string ProfileRemappingFile
Definition: PassBuilder.h:63
Class to hold module path string table and global value map, and encapsulate methods for operating on...
void registerLateLoopOptimizationsEPCallback(const std::function< void(LoopPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:498
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, FunctionPassManager &, ArrayRef< PipelineElement >)> &C)
Definition: PassBuilder.h:604
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void registerPipelineStartEPCallback(const std::function< void(ModulePassManager &)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:550
Disable as many optimizations as possible.
Definition: PassBuilder.h:150
A manager for alias analyses.
void registerVectorizerStartEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:540
bool ForgetAllSCEVInLoopUnroll
Tuning option to forget all SCEV loops in LoopUnroll.
Definition: PassBuilder.h:93
ThinLTOPhase
ThinLTO phase.
Definition: PassBuilder.h:133
Optimize for fast execution as much as possible.
Definition: PassBuilder.h:204
void registerParseAACallback(const std::function< bool(StringRef Name, AAManager &AA)> &C)
Register a callback for parsing an AliasAnalysis Name to populate the given AAManager AA...
Definition: PassBuilder.h:569
void registerAnalysisRegistrationCallback(const std::function< void(FunctionAnalysisManager &)> &C)
Definition: PassBuilder.h:581
bool LoopInterleaving
Tuning option to set loop interleaving on/off.
Definition: PassBuilder.h:78
void registerOptimizerLastEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:562
bool parseAnalysisUtilityPasses(StringRef AnalysisName, StringRef PipelineName, PassManager< IRUnitT, AnalysisManagerT, ExtraArgTs... > &PM)
This utility template takes care of adding require<> and invalidate<> passes for an analysis to a giv...
Definition: PassBuilder.h:736
std::string CSProfileGenFile
Definition: PassBuilder.h:62
A struct to capture parsed pass pipeline names.
Definition: PassBuilder.h:125
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
Optimize for fast execution as much as possible without triggering significant incremental compile ti...
Definition: PassBuilder.h:188
std::vector< PipelineElement > InnerPipeline
Definition: PassBuilder.h:127
unsigned LicmMssaOptCap
Tuning option to cap the number of calls to retrive clobbering accesses in MemorySSA, in LICM.
Definition: PassBuilder.h:97
void registerPeepholeEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:484
bool LoopUnrolling
Tuning option to enable/disable loop unrolling. Its default value is true.
Definition: PassBuilder.h:89
Manages a sequence of passes over a particular unit of IR.
Definition: PassManager.h:464
A struct capturing PGO tunables.
Definition: PassBuilder.h:33
unsigned LicmMssaNoAccForPromotionCap
Tuning option to disable promotion to scalars in LICM with MemorySSA, if the number of access is too ...
Definition: PassBuilder.h:101
A no-op pass template which simply forces a specific analysis result to be invalidated.
Definition: PassManager.h:1376
This header provides classes for managing passes over SCCs of the call graph.
void registerParseTopLevelPipelineCallback(const std::function< bool(ModulePassManager &, ArrayRef< PipelineElement >, bool VerifyEachPass, bool DebugLogging)> &C)
Register a callback for a top-level pipeline entry.
Definition: PassBuilder.h:626
void registerAnalysisRegistrationCallback(const std::function< void(CGSCCAnalysisManager &)> &C)
{{@ Register callbacks for analysis registration with this PassBuilder instance.
Definition: PassBuilder.h:577
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Optimize quickly without destroying debuggability.
Definition: PassBuilder.h:170
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
void registerCGSCCOptimizerLateEPCallback(const std::function< void(CGSCCPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:529
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
A container for analyses that lazily runs them and caches their results.
void addPass(PassT Pass)
Definition: PassManager.h:548
void registerAnalysisRegistrationCallback(const std::function< void(LoopAnalysisManager &)> &C)
Definition: PassBuilder.h:585
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, LoopPassManager &, ArrayRef< PipelineElement >)> &C)
Definition: PassBuilder.h:609
This header defines various interfaces for pass management in LLVM.
bool SLPVectorization
Tuning option to enable/disable slp loop vectorization.
Definition: PassBuilder.h:86
void registerScalarOptimizerLateEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:518