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