LLVM  9.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 CSAction 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 /// This class provides access to building LLVM's passes.
70 ///
71 /// Its members provide the baseline state available to passes during their
72 /// construction. The \c PassRegistry.def file specifies how to construct all
73 /// of the built-in passes, and those may reference these members during
74 /// construction.
75 class PassBuilder {
77  Optional<PGOOptions> PGOOpt;
79 
80 public:
81  /// A struct to capture parsed pass pipeline names.
82  ///
83  /// A pipeline is defined as a series of names, each of which may in itself
84  /// recursively contain a nested pipeline. A name is either the name of a pass
85  /// (e.g. "instcombine") or the name of a pipeline type (e.g. "cgscc"). If the
86  /// name is the name of a pass, the InnerPipeline is empty, since passes
87  /// cannot contain inner pipelines. See parsePassPipeline() for a more
88  /// detailed description of the textual pipeline format.
89  struct PipelineElement {
91  std::vector<PipelineElement> InnerPipeline;
92  };
93 
94  /// ThinLTO phase.
95  ///
96  /// This enumerates the LLVM ThinLTO optimization phases.
97  enum class ThinLTOPhase {
98  /// No ThinLTO behavior needed.
99  None,
100  // ThinLTO prelink (summary) phase.
101  PreLink,
102  // ThinLTO postlink (backend compile) phase.
103  PostLink
104  };
105 
106  /// LLVM-provided high-level optimization levels.
107  ///
108  /// This enumerates the LLVM-provided high-level optimization levels. Each
109  /// level has a specific goal and rationale.
111  /// Disable as many optimizations as possible. This doesn't completely
112  /// disable the optimizer in all cases, for example always_inline functions
113  /// can be required to be inlined for correctness.
114  O0,
115 
116  /// Optimize quickly without destroying debuggability.
117  ///
118  /// FIXME: The current and historical behavior of this level does *not*
119  /// agree with this goal, but we would like to move toward this goal in the
120  /// future.
121  ///
122  /// This level is tuned to produce a result from the optimizer as quickly
123  /// as possible and to avoid destroying debuggability. This tends to result
124  /// in a very good development mode where the compiled code will be
125  /// immediately executed as part of testing. As a consequence, where
126  /// possible, we would like to produce efficient-to-execute code, but not
127  /// if it significantly slows down compilation or would prevent even basic
128  /// debugging of the resulting binary.
129  ///
130  /// As an example, complex loop transformations such as versioning,
131  /// vectorization, or fusion might not make sense here due to the degree to
132  /// which the executed code would differ from the source code, and the
133  /// potential compile time cost.
134  O1,
135 
136  /// Optimize for fast execution as much as possible without triggering
137  /// significant incremental compile time or code size growth.
138  ///
139  /// The key idea is that optimizations at this level should "pay for
140  /// themselves". So if an optimization increases compile time by 5% or
141  /// increases code size by 5% for a particular benchmark, that benchmark
142  /// should also be one which sees a 5% runtime improvement. If the compile
143  /// time or code size penalties happen on average across a diverse range of
144  /// LLVM users' benchmarks, then the improvements should as well.
145  ///
146  /// And no matter what, the compile time needs to not grow superlinearly
147  /// with the size of input to LLVM so that users can control the runtime of
148  /// the optimizer in this mode.
149  ///
150  /// This is expected to be a good default optimization level for the vast
151  /// majority of users.
152  O2,
153 
154  /// Optimize for fast execution as much as possible.
155  ///
156  /// This mode is significantly more aggressive in trading off compile time
157  /// and code size to get execution time improvements. The core idea is that
158  /// this mode should include any optimization that helps execution time on
159  /// balance across a diverse collection of benchmarks, even if it increases
160  /// code size or compile time for some benchmarks without corresponding
161  /// improvements to execution time.
162  ///
163  /// Despite being willing to trade more compile time off to get improved
164  /// execution time, this mode still tries to avoid superlinear growth in
165  /// order to make even significantly slower compile times at least scale
166  /// reasonably. This does not preclude very substantial constant factor
167  /// costs though.
168  O3,
169 
170  /// Similar to \c O2 but tries to optimize for small code size instead of
171  /// fast execution without triggering significant incremental execution
172  /// time slowdowns.
173  ///
174  /// The logic here is exactly the same as \c O2, but with code size and
175  /// execution time metrics swapped.
176  ///
177  /// A consequence of the different core goal is that this should in general
178  /// produce substantially smaller executables that still run in
179  /// a reasonable amount of time.
180  Os,
181 
182  /// A very specialized mode that will optimize for code size at any and all
183  /// costs.
184  ///
185  /// This is useful primarily when there are absolute size limitations and
186  /// any effort taken to reduce the size is worth it regardless of the
187  /// execution time impact. You should expect this level to produce rather
188  /// slow, but very small, code.
189  Oz
190  };
191 
192  explicit PassBuilder(TargetMachine *TM = nullptr,
193  Optional<PGOOptions> PGOOpt = None,
194  PassInstrumentationCallbacks *PIC = nullptr)
195  : TM(TM), PGOOpt(PGOOpt), PIC(PIC) {}
196 
197  /// Cross register the analysis managers through their proxies.
198  ///
199  /// This is an interface that can be used to cross register each
200  // AnalysisManager with all the others analysis managers.
201  void crossRegisterProxies(LoopAnalysisManager &LAM,
203  CGSCCAnalysisManager &CGAM,
204  ModuleAnalysisManager &MAM);
205 
206  /// Registers all available module analysis passes.
207  ///
208  /// This is an interface that can be used to populate a \c
209  /// ModuleAnalysisManager with all registered module analyses. Callers can
210  /// still manually register any additional analyses. Callers can also
211  /// pre-register analyses and this will not override those.
212  void registerModuleAnalyses(ModuleAnalysisManager &MAM);
213 
214  /// Registers all available CGSCC analysis passes.
215  ///
216  /// This is an interface that can be used to populate a \c CGSCCAnalysisManager
217  /// with all registered CGSCC analyses. Callers can still manually register any
218  /// additional analyses. Callers can also pre-register analyses and this will
219  /// not override those.
220  void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM);
221 
222  /// Registers all available function analysis passes.
223  ///
224  /// This is an interface that can be used to populate a \c
225  /// FunctionAnalysisManager with all registered function analyses. Callers can
226  /// still manually register any additional analyses. Callers can also
227  /// pre-register analyses and this will not override those.
228  void registerFunctionAnalyses(FunctionAnalysisManager &FAM);
229 
230  /// Registers all available loop analysis passes.
231  ///
232  /// This is an interface that can be used to populate a \c LoopAnalysisManager
233  /// with all registered loop analyses. Callers can still manually register any
234  /// additional analyses.
235  void registerLoopAnalyses(LoopAnalysisManager &LAM);
236 
237  /// Construct the core LLVM function canonicalization and simplification
238  /// pipeline.
239  ///
240  /// This is a long pipeline and uses most of the per-function optimization
241  /// passes in LLVM to canonicalize and simplify the IR. It is suitable to run
242  /// repeatedly over the IR and is not expected to destroy important
243  /// information about the semantics of the IR.
244  ///
245  /// Note that \p Level cannot be `O0` here. The pipelines produced are
246  /// only intended for use when attempting to optimize code. If frontends
247  /// require some transformations for semantic reasons, they should explicitly
248  /// build them.
249  ///
250  /// \p Phase indicates the current ThinLTO phase.
252  buildFunctionSimplificationPipeline(OptimizationLevel Level,
254  bool DebugLogging = false);
255 
256  /// Construct the core LLVM module canonicalization and simplification
257  /// pipeline.
258  ///
259  /// This pipeline focuses on canonicalizing and simplifying the entire module
260  /// of IR. Much like the function simplification pipeline above, it is
261  /// suitable to run repeatedly over the IR and is not expected to destroy
262  /// important information. It does, however, perform inlining and other
263  /// heuristic based simplifications that are not strictly reversible.
264  ///
265  /// Note that \p Level cannot be `O0` here. The pipelines produced are
266  /// only intended for use when attempting to optimize code. If frontends
267  /// require some transformations for semantic reasons, they should explicitly
268  /// build them.
269  ///
270  /// \p Phase indicates the current ThinLTO phase.
272  buildModuleSimplificationPipeline(OptimizationLevel Level,
273  ThinLTOPhase Phase,
274  bool DebugLogging = false);
275 
276  /// Construct the core LLVM module optimization pipeline.
277  ///
278  /// This pipeline focuses on optimizing the execution speed of the IR. It
279  /// uses cost modeling and thresholds to balance code growth against runtime
280  /// improvements. It includes vectorization and other information destroying
281  /// transformations. It also cannot generally be run repeatedly on a module
282  /// without potentially seriously regressing either runtime performance of
283  /// the code or serious code size growth.
284  ///
285  /// Note that \p Level cannot be `O0` here. The pipelines produced are
286  /// only intended for use when attempting to optimize code. If frontends
287  /// require some transformations for semantic reasons, they should explicitly
288  /// build them.
289  ModulePassManager buildModuleOptimizationPipeline(OptimizationLevel Level,
290  bool DebugLogging = false,
291  bool LTOPreLink = false);
292 
293  /// Build a per-module default optimization pipeline.
294  ///
295  /// This provides a good default optimization pipeline for per-module
296  /// optimization and code generation without any link-time optimization. It
297  /// typically correspond to frontend "-O[123]" options for optimization
298  /// levels \c O1, \c O2 and \c O3 resp.
299  ///
300  /// Note that \p Level cannot be `O0` here. The pipelines produced are
301  /// only intended for use when attempting to optimize code. If frontends
302  /// require some transformations for semantic reasons, they should explicitly
303  /// build them.
304  ModulePassManager buildPerModuleDefaultPipeline(OptimizationLevel Level,
305  bool DebugLogging = false,
306  bool LTOPreLink = false);
307 
308  /// Build a pre-link, ThinLTO-targeting default optimization pipeline to
309  /// a pass manager.
310  ///
311  /// This adds the pre-link optimizations tuned to prepare a module for
312  /// a ThinLTO run. It works to minimize the IR which needs to be analyzed
313  /// without making irreversible decisions which could be made better during
314  /// the LTO run.
315  ///
316  /// Note that \p Level cannot be `O0` here. The pipelines produced are
317  /// only intended for use when attempting to optimize code. If frontends
318  /// require some transformations for semantic reasons, they should explicitly
319  /// build them.
321  buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level,
322  bool DebugLogging = false);
323 
324  /// Build an ThinLTO default optimization pipeline to a pass manager.
325  ///
326  /// This provides a good default optimization pipeline for link-time
327  /// optimization and code generation. It is particularly tuned to fit well
328  /// when IR coming into the LTO phase was first run through \c
329  /// addPreLinkLTODefaultPipeline, and the two coordinate closely.
330  ///
331  /// Note that \p Level cannot be `O0` here. The pipelines produced are
332  /// only intended for use when attempting to optimize code. If frontends
333  /// require some transformations for semantic reasons, they should explicitly
334  /// build them.
336  buildThinLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging,
337  const ModuleSummaryIndex *ImportSummary);
338 
339  /// Build a pre-link, LTO-targeting default optimization pipeline to a pass
340  /// manager.
341  ///
342  /// This adds the pre-link optimizations tuned to work well with a later LTO
343  /// run. It works to minimize the IR which needs to be analyzed without
344  /// making irreversible decisions which could be made better during the LTO
345  /// run.
346  ///
347  /// Note that \p Level cannot be `O0` here. The pipelines produced are
348  /// only intended for use when attempting to optimize code. If frontends
349  /// require some transformations for semantic reasons, they should explicitly
350  /// build them.
351  ModulePassManager buildLTOPreLinkDefaultPipeline(OptimizationLevel Level,
352  bool DebugLogging = false);
353 
354  /// Build an LTO default optimization pipeline to a pass manager.
355  ///
356  /// This provides a good default optimization pipeline for link-time
357  /// optimization and code generation. It is particularly tuned to fit well
358  /// when IR coming into the LTO phase was first run through \c
359  /// addPreLinkLTODefaultPipeline, and the two coordinate closely.
360  ///
361  /// Note that \p Level cannot be `O0` here. The pipelines produced are
362  /// only intended for use when attempting to optimize code. If frontends
363  /// require some transformations for semantic reasons, they should explicitly
364  /// build them.
365  ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level,
366  bool DebugLogging,
367  ModuleSummaryIndex *ExportSummary);
368 
369  /// Build the default `AAManager` with the default alias analysis pipeline
370  /// registered.
371  AAManager buildDefaultAAPipeline();
372 
373  /// Parse a textual pass pipeline description into a \c
374  /// ModulePassManager.
375  ///
376  /// The format of the textual pass pipeline description looks something like:
377  ///
378  /// module(function(instcombine,sroa),dce,cgscc(inliner,function(...)),...)
379  ///
380  /// Pass managers have ()s describing the nest structure of passes. All passes
381  /// are comma separated. As a special shortcut, if the very first pass is not
382  /// a module pass (as a module pass manager is), this will automatically form
383  /// the shortest stack of pass managers that allow inserting that first pass.
384  /// So, assuming function passes 'fpassN', CGSCC passes 'cgpassN', and loop
385  /// passes 'lpassN', all of these are valid:
386  ///
387  /// fpass1,fpass2,fpass3
388  /// cgpass1,cgpass2,cgpass3
389  /// lpass1,lpass2,lpass3
390  ///
391  /// And they are equivalent to the following (resp.):
392  ///
393  /// module(function(fpass1,fpass2,fpass3))
394  /// module(cgscc(cgpass1,cgpass2,cgpass3))
395  /// module(function(loop(lpass1,lpass2,lpass3)))
396  ///
397  /// This shortcut is especially useful for debugging and testing small pass
398  /// combinations. Note that these shortcuts don't introduce any other magic.
399  /// If the sequence of passes aren't all the exact same kind of pass, it will
400  /// be an error. You cannot mix different levels implicitly, you must
401  /// explicitly form a pass manager in which to nest passes.
402  Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
403  bool VerifyEachPass = true,
404  bool DebugLogging = false);
405 
406  /// {{@ Parse a textual pass pipeline description into a specific PassManager
407  ///
408  /// Automatic deduction of an appropriate pass manager stack is not supported.
409  /// For example, to insert a loop pass 'lpass' into a FunctinoPassManager,
410  /// this is the valid pipeline text:
411  ///
412  /// function(lpass)
413  Error parsePassPipeline(CGSCCPassManager &CGPM, StringRef PipelineText,
414  bool VerifyEachPass = true,
415  bool DebugLogging = false);
416  Error parsePassPipeline(FunctionPassManager &FPM, StringRef PipelineText,
417  bool VerifyEachPass = true,
418  bool DebugLogging = false);
419  Error parsePassPipeline(LoopPassManager &LPM, StringRef PipelineText,
420  bool VerifyEachPass = true,
421  bool DebugLogging = false);
422  /// @}}
423 
424  /// Parse a textual alias analysis pipeline into the provided AA manager.
425  ///
426  /// The format of the textual AA pipeline is a comma separated list of AA
427  /// pass names:
428  ///
429  /// basic-aa,globals-aa,...
430  ///
431  /// The AA manager is set up such that the provided alias analyses are tried
432  /// in the order specified. See the \c AAManaager documentation for details
433  /// about the logic used. This routine just provides the textual mapping
434  /// between AA names and the analyses to register with the manager.
435  ///
436  /// Returns false if the text cannot be parsed cleanly. The specific state of
437  /// the \p AA manager is unspecified if such an error is encountered and this
438  /// returns false.
439  Error parseAAPipeline(AAManager &AA, StringRef PipelineText);
440 
441  /// Register a callback for a default optimizer pipeline extension
442  /// point
443  ///
444  /// This extension point allows adding passes that perform peephole
445  /// optimizations similar to the instruction combiner. These passes will be
446  /// inserted after each instance of the instruction combiner pass.
449  PeepholeEPCallbacks.push_back(C);
450  }
451 
452  /// Register a callback for a default optimizer pipeline extension
453  /// point
454  ///
455  /// This extension point allows adding late loop canonicalization and
456  /// simplification passes. This is the last point in the loop optimization
457  /// pipeline before loop deletion. Each pass added
458  /// here must be an instance of LoopPass.
459  /// This is the place to add passes that can remove loops, such as target-
460  /// specific loop idiom recognition.
463  LateLoopOptimizationsEPCallbacks.push_back(C);
464  }
465 
466  /// Register a callback for a default optimizer pipeline extension
467  /// point
468  ///
469  /// This extension point allows adding loop passes to the end of the loop
470  /// optimizer.
473  LoopOptimizerEndEPCallbacks.push_back(C);
474  }
475 
476  /// Register a callback for a default optimizer pipeline extension
477  /// point
478  ///
479  /// This extension point allows adding optimization passes after most of the
480  /// main optimizations, but before the last cleanup-ish optimizations.
483  ScalarOptimizerLateEPCallbacks.push_back(C);
484  }
485 
486  /// Register a callback for a default optimizer pipeline extension
487  /// point
488  ///
489  /// This extension point allows adding CallGraphSCC passes at the end of the
490  /// main CallGraphSCC passes and before any function simplification passes run
491  /// by CGPassManager.
494  CGSCCOptimizerLateEPCallbacks.push_back(C);
495  }
496 
497  /// Register a callback for a default optimizer pipeline extension
498  /// point
499  ///
500  /// This extension point allows adding optimization passes before the
501  /// vectorizer and other highly target specific optimization passes are
502  /// executed.
505  VectorizerStartEPCallbacks.push_back(C);
506  }
507 
508  /// Register a callback for a default optimizer pipeline extension point.
509  ///
510  /// This extension point allows adding optimization once at the start of the
511  /// pipeline. This does not apply to 'backend' compiles (LTO and ThinLTO
512  /// link-time pipelines).
514  const std::function<void(ModulePassManager &)> &C) {
515  PipelineStartEPCallbacks.push_back(C);
516  }
517 
518  /// Register a callback for a default optimizer pipeline extension point
519  ///
520  /// This extension point allows adding optimizations at the very end of the
521  /// function optimization pipeline. A key difference between this and the
522  /// legacy PassManager's OptimizerLast callback is that this extension point
523  /// is not triggered at O0. Extensions to the O0 pipeline should append their
524  /// passes to the end of the overall pipeline.
527  OptimizerLastEPCallbacks.push_back(C);
528  }
529 
530  /// Register a callback for parsing an AliasAnalysis Name to populate
531  /// the given AAManager \p AA
533  const std::function<bool(StringRef Name, AAManager &AA)> &C) {
534  AAParsingCallbacks.push_back(C);
535  }
536 
537  /// {{@ Register callbacks for analysis registration with this PassBuilder
538  /// instance.
539  /// Callees register their analyses with the given AnalysisManager objects.
541  const std::function<void(CGSCCAnalysisManager &)> &C) {
542  CGSCCAnalysisRegistrationCallbacks.push_back(C);
543  }
545  const std::function<void(FunctionAnalysisManager &)> &C) {
546  FunctionAnalysisRegistrationCallbacks.push_back(C);
547  }
549  const std::function<void(LoopAnalysisManager &)> &C) {
550  LoopAnalysisRegistrationCallbacks.push_back(C);
551  }
553  const std::function<void(ModuleAnalysisManager &)> &C) {
554  ModuleAnalysisRegistrationCallbacks.push_back(C);
555  }
556  /// @}}
557 
558  /// {{@ Register pipeline parsing callbacks with this pass builder instance.
559  /// Using these callbacks, callers can parse both a single pass name, as well
560  /// as entire sub-pipelines, and populate the PassManager instance
561  /// accordingly.
565  CGSCCPipelineParsingCallbacks.push_back(C);
566  }
570  FunctionPipelineParsingCallbacks.push_back(C);
571  }
575  LoopPipelineParsingCallbacks.push_back(C);
576  }
580  ModulePipelineParsingCallbacks.push_back(C);
581  }
582  /// @}}
583 
584  /// Register a callback for a top-level pipeline entry.
585  ///
586  /// If the PassManager type is not given at the top level of the pipeline
587  /// text, this Callback should be used to determine the appropriate stack of
588  /// PassManagers and populate the passed ModulePassManager.
591  bool VerifyEachPass, bool DebugLogging)> &C) {
592  TopLevelPipelineParsingCallbacks.push_back(C);
593  }
594 
595 private:
597  parsePipelineText(StringRef Text);
598 
599  Error parseModulePass(ModulePassManager &MPM, const PipelineElement &E,
600  bool VerifyEachPass, bool DebugLogging);
601  Error parseCGSCCPass(CGSCCPassManager &CGPM, const PipelineElement &E,
602  bool VerifyEachPass, bool DebugLogging);
603  Error parseFunctionPass(FunctionPassManager &FPM, const PipelineElement &E,
604  bool VerifyEachPass, bool DebugLogging);
605  Error parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
606  bool VerifyEachPass, bool DebugLogging);
607  bool parseAAPassName(AAManager &AA, StringRef Name);
608 
609  Error parseLoopPassPipeline(LoopPassManager &LPM,
610  ArrayRef<PipelineElement> Pipeline,
611  bool VerifyEachPass, bool DebugLogging);
612  Error parseFunctionPassPipeline(FunctionPassManager &FPM,
613  ArrayRef<PipelineElement> Pipeline,
614  bool VerifyEachPass, bool DebugLogging);
615  Error parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
616  ArrayRef<PipelineElement> Pipeline,
617  bool VerifyEachPass, bool DebugLogging);
618  Error parseModulePassPipeline(ModulePassManager &MPM,
619  ArrayRef<PipelineElement> Pipeline,
620  bool VerifyEachPass, bool DebugLogging);
621 
622  void addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
623  OptimizationLevel Level, bool RunProfileGen, bool IsCS,
624  std::string ProfileFile,
625  std::string ProfileRemappingFile);
626 
627  void invokePeepholeEPCallbacks(FunctionPassManager &, OptimizationLevel);
628 
629  // Extension Point callbacks
631  PeepholeEPCallbacks;
633  LateLoopOptimizationsEPCallbacks;
635  LoopOptimizerEndEPCallbacks;
637  ScalarOptimizerLateEPCallbacks;
639  CGSCCOptimizerLateEPCallbacks;
641  VectorizerStartEPCallbacks;
643  OptimizerLastEPCallbacks;
644  // Module callbacks
646  PipelineStartEPCallbacks;
648  ModuleAnalysisRegistrationCallbacks;
651  2>
652  ModulePipelineParsingCallbacks;
654  bool VerifyEachPass, bool DebugLogging)>,
655  2>
656  TopLevelPipelineParsingCallbacks;
657  // CGSCC callbacks
659  CGSCCAnalysisRegistrationCallbacks;
662  2>
663  CGSCCPipelineParsingCallbacks;
664  // Function callbacks
666  FunctionAnalysisRegistrationCallbacks;
669  2>
670  FunctionPipelineParsingCallbacks;
671  // Loop callbacks
673  LoopAnalysisRegistrationCallbacks;
676  2>
677  LoopPipelineParsingCallbacks;
678  // AA callbacks
680  AAParsingCallbacks;
681 };
682 
683 /// This utility template takes care of adding require<> and invalidate<>
684 /// passes for an analysis to a given \c PassManager. It is intended to be used
685 /// during parsing of a pass pipeline when parsing a single PipelineName.
686 /// When registering a new function analysis FancyAnalysis with the pass
687 /// pipeline name "fancy-analysis", a matching ParsePipelineCallback could look
688 /// like this:
689 ///
690 /// static bool parseFunctionPipeline(StringRef Name, FunctionPassManager &FPM,
691 /// ArrayRef<PipelineElement> P) {
692 /// if (parseAnalysisUtilityPasses<FancyAnalysis>("fancy-analysis", Name,
693 /// FPM))
694 /// return true;
695 /// return false;
696 /// }
697 template <typename AnalysisT, typename IRUnitT, typename AnalysisManagerT,
698  typename... ExtraArgTs>
700  StringRef AnalysisName, StringRef PipelineName,
702  if (!PipelineName.endswith(">"))
703  return false;
704  // See if this is an invalidate<> pass name
705  if (PipelineName.startswith("invalidate<")) {
706  PipelineName = PipelineName.substr(11, PipelineName.size() - 12);
707  if (PipelineName != AnalysisName)
708  return false;
710  return true;
711  }
712 
713  // See if this is a require<> pass name
714  if (PipelineName.startswith("require<")) {
715  PipelineName = PipelineName.substr(8, PipelineName.size() - 9);
716  if (PipelineName != AnalysisName)
717  return false;
718  PM.addPass(RequireAnalysisPass<AnalysisT, IRUnitT, AnalysisManagerT,
719  ExtraArgTs...>());
720  return true;
721  }
722 
723  return false;
724 }
725 }
726 
727 #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:562
uint64_t CallInst * C
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:110
A utility pass template to force an analysis result to be available.
Definition: PassManager.h:1348
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:180
This class provides access to building LLVM&#39;s passes.
Definition: PassBuilder.h:75
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, ModulePassManager &, ArrayRef< PipelineElement >)> &C)
Definition: PassBuilder.h:577
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:471
void registerAnalysisRegistrationCallback(const std::function< void(ModuleAnalysisManager &)> &C)
Definition: PassBuilder.h:552
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:461
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, FunctionPassManager &, ArrayRef< PipelineElement >)> &C)
Definition: PassBuilder.h:567
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:513
Disable as many optimizations as possible.
Definition: PassBuilder.h:114
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:503
ThinLTOPhase
ThinLTO phase.
Definition: PassBuilder.h:97
Optimize for fast execution as much as possible.
Definition: PassBuilder.h:168
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:532
void registerAnalysisRegistrationCallback(const std::function< void(FunctionAnalysisManager &)> &C)
Definition: PassBuilder.h:544
PassBuilder(TargetMachine *TM=nullptr, Optional< PGOOptions > PGOOpt=None, PassInstrumentationCallbacks *PIC=nullptr)
Definition: PassBuilder.h:192
void registerOptimizerLastEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:525
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:699
std::string CSProfileGenFile
Definition: PassBuilder.h:62
A struct to capture parsed pass pipeline names.
Definition: PassBuilder.h:89
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:841
Optimize for fast execution as much as possible without triggering significant incremental compile ti...
Definition: PassBuilder.h:152
std::vector< PipelineElement > InnerPipeline
Definition: PassBuilder.h:91
void registerPeepholeEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:447
Manages a sequence of passes over a particular unit of IR.
Definition: PassManager.h:457
A struct capturing PGO tunables.
Definition: PassBuilder.h:33
A no-op pass template which simply forces a specific analysis result to be invalidated.
Definition: PassManager.h:1369
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:589
void registerAnalysisRegistrationCallback(const std::function< void(CGSCCAnalysisManager &)> &C)
{{@ Register callbacks for analysis registration with this PassBuilder instance.
Definition: PassBuilder.h:540
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Optimize quickly without destroying debuggability.
Definition: PassBuilder.h:134
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:492
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:541
void registerAnalysisRegistrationCallback(const std::function< void(LoopAnalysisManager &)> &C)
Definition: PassBuilder.h:548
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, LoopPassManager &, ArrayRef< PipelineElement >)> &C)
Definition: PassBuilder.h:572
This header defines various interfaces for pass management in LLVM.
void registerScalarOptimizerLateEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:481