LLVM 18.0.0git
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
19#include "llvm/IR/PassManager.h"
21#include "llvm/Support/Error.h"
28#include <vector>
29
30namespace llvm {
31class StringRef;
32class AAManager;
33class TargetMachine;
34class ModuleSummaryIndex;
35template <typename T> class IntrusiveRefCntPtr;
36namespace vfs {
37class FileSystem;
38} // namespace vfs
39
40/// Tunable parameters for passes in the default pipelines.
42public:
43 /// Constructor sets pipeline tuning defaults based on cl::opts. Each option
44 /// can be set in the PassBuilder when using a LLVM as a library.
46
47 /// Tuning option to set loop interleaving on/off, set based on opt level.
49
50 /// Tuning option to enable/disable loop vectorization, set based on opt
51 /// level.
53
54 /// Tuning option to enable/disable slp loop vectorization, set based on opt
55 /// level.
57
58 /// Tuning option to enable/disable loop unrolling. Its default value is true.
60
61 /// Tuning option to forget all SCEV loops in LoopUnroll. Its default value
62 /// is that of the flag: `-forget-scev-loop-unroll`.
64
65 /// Tuning option to cap the number of calls to retrive clobbering accesses in
66 /// MemorySSA, in LICM.
68
69 /// Tuning option to disable promotion to scalars in LICM with MemorySSA, if
70 /// the number of access is too large.
72
73 /// Tuning option to enable/disable call graph profile. Its default value is
74 /// that of the flag: `-enable-npm-call-graph-profile`.
76
77 // Add LTO pipeline tuning option to enable the unified LTO pipeline.
79
80 /// Tuning option to enable/disable function merging. Its default value is
81 /// false.
83
84 /// Tuning option to override the default inliner threshold.
86
87 // Experimental option to eagerly invalidate more analyses. This has the
88 // potential to decrease max memory usage in exchange for more compile time.
89 // This may affect codegen due to either passes using analyses only when
90 // cached, or invalidating and recalculating an analysis that was
91 // stale/imprecise but still valid. Currently this invalidates all function
92 // analyses after various module->function or cgscc->function adaptors in the
93 // default pipelines.
95};
96
97/// This class provides access to building LLVM's passes.
98///
99/// Its members provide the baseline state available to passes during their
100/// construction. The \c PassRegistry.def file specifies how to construct all
101/// of the built-in passes, and those may reference these members during
102/// construction.
104 TargetMachine *TM;
106 std::optional<PGOOptions> PGOOpt;
108
109public:
110 /// A struct to capture parsed pass pipeline names.
111 ///
112 /// A pipeline is defined as a series of names, each of which may in itself
113 /// recursively contain a nested pipeline. A name is either the name of a pass
114 /// (e.g. "instcombine") or the name of a pipeline type (e.g. "cgscc"). If the
115 /// name is the name of a pass, the InnerPipeline is empty, since passes
116 /// cannot contain inner pipelines. See parsePassPipeline() for a more
117 /// detailed description of the textual pipeline format.
120 std::vector<PipelineElement> InnerPipeline;
121 };
122
123 explicit PassBuilder(TargetMachine *TM = nullptr,
125 std::optional<PGOOptions> PGOOpt = std::nullopt,
126 PassInstrumentationCallbacks *PIC = nullptr);
127
128 /// Cross register the analysis managers through their proxies.
129 ///
130 /// This is an interface that can be used to cross register each
131 /// AnalysisManager with all the others analysis managers.
136
137 /// Registers all available module analysis passes.
138 ///
139 /// This is an interface that can be used to populate a \c
140 /// ModuleAnalysisManager with all registered module analyses. Callers can
141 /// still manually register any additional analyses. Callers can also
142 /// pre-register analyses and this will not override those.
144
145 /// Registers all available CGSCC analysis passes.
146 ///
147 /// This is an interface that can be used to populate a \c CGSCCAnalysisManager
148 /// with all registered CGSCC analyses. Callers can still manually register any
149 /// additional analyses. Callers can also pre-register analyses and this will
150 /// not override those.
152
153 /// Registers all available function analysis passes.
154 ///
155 /// This is an interface that can be used to populate a \c
156 /// FunctionAnalysisManager with all registered function analyses. Callers can
157 /// still manually register any additional analyses. Callers can also
158 /// pre-register analyses and this will not override those.
160
161 /// Registers all available loop analysis passes.
162 ///
163 /// This is an interface that can be used to populate a \c LoopAnalysisManager
164 /// with all registered loop analyses. Callers can still manually register any
165 /// additional analyses.
167
168 /// Construct the core LLVM function canonicalization and simplification
169 /// pipeline.
170 ///
171 /// This is a long pipeline and uses most of the per-function optimization
172 /// passes in LLVM to canonicalize and simplify the IR. It is suitable to run
173 /// repeatedly over the IR and is not expected to destroy important
174 /// information about the semantics of the IR.
175 ///
176 /// Note that \p Level cannot be `O0` here. The pipelines produced are
177 /// only intended for use when attempting to optimize code. If frontends
178 /// require some transformations for semantic reasons, they should explicitly
179 /// build them.
180 ///
181 /// \p Phase indicates the current ThinLTO phase.
185
186 /// Construct the core LLVM module canonicalization and simplification
187 /// pipeline.
188 ///
189 /// This pipeline focuses on canonicalizing and simplifying the entire module
190 /// of IR. Much like the function simplification pipeline above, it is
191 /// suitable to run repeatedly over the IR and is not expected to destroy
192 /// important information. It does, however, perform inlining and other
193 /// heuristic based simplifications that are not strictly reversible.
194 ///
195 /// Note that \p Level cannot be `O0` here. The pipelines produced are
196 /// only intended for use when attempting to optimize code. If frontends
197 /// require some transformations for semantic reasons, they should explicitly
198 /// build them.
199 ///
200 /// \p Phase indicates the current ThinLTO phase.
203
204 /// Construct the module pipeline that performs inlining as well as
205 /// the inlining-driven cleanups.
208
209 /// Construct the module pipeline that performs inlining with
210 /// module inliner pass.
213
214 /// Construct the core LLVM module optimization pipeline.
215 ///
216 /// This pipeline focuses on optimizing the execution speed of the IR. It
217 /// uses cost modeling and thresholds to balance code growth against runtime
218 /// improvements. It includes vectorization and other information destroying
219 /// transformations. It also cannot generally be run repeatedly on a module
220 /// without potentially seriously regressing either runtime performance of
221 /// the code or serious code size growth.
222 ///
223 /// Note that \p Level cannot be `O0` here. The pipelines produced are
224 /// only intended for use when attempting to optimize code. If frontends
225 /// require some transformations for semantic reasons, they should explicitly
226 /// build them.
229 ThinOrFullLTOPhase LTOPhase);
230
231 /// Build a per-module default optimization pipeline.
232 ///
233 /// This provides a good default optimization pipeline for per-module
234 /// optimization and code generation without any link-time optimization. It
235 /// typically correspond to frontend "-O[123]" options for optimization
236 /// levels \c O1, \c O2 and \c O3 resp.
238 bool LTOPreLink = false);
239
240 /// Build a fat object default optimization pipeline.
241 ///
242 /// This builds a pipeline that runs the LTO/ThinLTO pre-link pipeline, and
243 /// emits a section containing the pre-link bitcode along side the object code
244 /// generated by running the PerModuleDefaultPipeline, used when compiling
245 /// without LTO. It clones the module and runs the LTO/non-LTO pipelines
246 /// separately to avoid any inconsistencies with an ad-hoc pipeline that tries
247 /// to approximate the PerModuleDefaultPipeline from the pre-link LTO
248 /// pipelines.
250 bool ThinLTO, bool EmitSummary);
251
252 /// Build a pre-link, ThinLTO-targeting default optimization pipeline to
253 /// a pass manager.
254 ///
255 /// This adds the pre-link optimizations tuned to prepare a module for
256 /// a ThinLTO run. It works to minimize the IR which needs to be analyzed
257 /// without making irreversible decisions which could be made better during
258 /// the LTO run.
260
261 /// Build an ThinLTO default optimization pipeline to a pass manager.
262 ///
263 /// This provides a good default optimization pipeline for link-time
264 /// optimization and code generation. It is particularly tuned to fit well
265 /// when IR coming into the LTO phase was first run through \c
266 /// addPreLinkLTODefaultPipeline, and the two coordinate closely.
269 const ModuleSummaryIndex *ImportSummary);
270
271 /// Build a pre-link, LTO-targeting default optimization pipeline to a pass
272 /// manager.
273 ///
274 /// This adds the pre-link optimizations tuned to work well with a later LTO
275 /// run. It works to minimize the IR which needs to be analyzed without
276 /// making irreversible decisions which could be made better during the LTO
277 /// run.
279
280 /// Build an LTO default optimization pipeline to a pass manager.
281 ///
282 /// This provides a good default optimization pipeline for link-time
283 /// optimization and code generation. It is particularly tuned to fit well
284 /// when IR coming into the LTO phase was first run through \c
285 /// addPreLinkLTODefaultPipeline, and the two coordinate closely.
287 ModuleSummaryIndex *ExportSummary);
288
289 /// Build an O0 pipeline with the minimal semantically required passes.
290 ///
291 /// This should only be used for non-LTO and LTO pre-link pipelines.
293 bool LTOPreLink = false);
294
295 /// Build the default `AAManager` with the default alias analysis pipeline
296 /// registered.
297 ///
298 /// This also adds target-specific alias analyses registered via
299 /// TargetMachine::registerDefaultAliasAnalyses().
301
302 /// Parse a textual pass pipeline description into a \c
303 /// ModulePassManager.
304 ///
305 /// The format of the textual pass pipeline description looks something like:
306 ///
307 /// module(function(instcombine,sroa),dce,cgscc(inliner,function(...)),...)
308 ///
309 /// Pass managers have ()s describing the nest structure of passes. All passes
310 /// are comma separated. As a special shortcut, if the very first pass is not
311 /// a module pass (as a module pass manager is), this will automatically form
312 /// the shortest stack of pass managers that allow inserting that first pass.
313 /// So, assuming function passes 'fpassN', CGSCC passes 'cgpassN', and loop
314 /// passes 'lpassN', all of these are valid:
315 ///
316 /// fpass1,fpass2,fpass3
317 /// cgpass1,cgpass2,cgpass3
318 /// lpass1,lpass2,lpass3
319 ///
320 /// And they are equivalent to the following (resp.):
321 ///
322 /// module(function(fpass1,fpass2,fpass3))
323 /// module(cgscc(cgpass1,cgpass2,cgpass3))
324 /// module(function(loop(lpass1,lpass2,lpass3)))
325 ///
326 /// This shortcut is especially useful for debugging and testing small pass
327 /// combinations.
328 ///
329 /// The sequence of passes aren't necessarily the exact same kind of pass.
330 /// You can mix different levels implicitly if adaptor passes are defined to
331 /// make them work. For example,
332 ///
333 /// mpass1,fpass1,fpass2,mpass2,lpass1
334 ///
335 /// This pipeline uses only one pass manager: the top-level module manager.
336 /// fpass1,fpass2 and lpass1 are added into the top-level module manager
337 /// using only adaptor passes. No nested function/loop pass managers are
338 /// added. The purpose is to allow easy pass testing when the user
339 /// specifically want the pass to run under a adaptor directly. This is
340 /// preferred when a pipeline is largely of one type, but one or just a few
341 /// passes are of different types(See PassBuilder.cpp for examples).
343
344 /// {{@ Parse a textual pass pipeline description into a specific PassManager
345 ///
346 /// Automatic deduction of an appropriate pass manager stack is not supported.
347 /// For example, to insert a loop pass 'lpass' into a FunctionPassManager,
348 /// this is the valid pipeline text:
349 ///
350 /// function(lpass)
354 /// @}}
355
356 /// Parse a textual alias analysis pipeline into the provided AA manager.
357 ///
358 /// The format of the textual AA pipeline is a comma separated list of AA
359 /// pass names:
360 ///
361 /// basic-aa,globals-aa,...
362 ///
363 /// The AA manager is set up such that the provided alias analyses are tried
364 /// in the order specified. See the \c AAManaager documentation for details
365 /// about the logic used. This routine just provides the textual mapping
366 /// between AA names and the analyses to register with the manager.
367 ///
368 /// Returns false if the text cannot be parsed cleanly. The specific state of
369 /// the \p AA manager is unspecified if such an error is encountered and this
370 /// returns false.
371 Error parseAAPipeline(AAManager &AA, StringRef PipelineText);
372
373 /// Print pass names.
375
376 /// Register a callback for a default optimizer pipeline extension
377 /// point
378 ///
379 /// This extension point allows adding passes that perform peephole
380 /// optimizations similar to the instruction combiner. These passes will be
381 /// inserted after each instance of the instruction combiner pass.
383 const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
384 PeepholeEPCallbacks.push_back(C);
385 }
386
387 /// Register a callback for a default optimizer pipeline extension
388 /// point
389 ///
390 /// This extension point allows adding late loop canonicalization and
391 /// simplification passes. This is the last point in the loop optimization
392 /// pipeline before loop deletion. Each pass added
393 /// here must be an instance of LoopPass.
394 /// This is the place to add passes that can remove loops, such as target-
395 /// specific loop idiom recognition.
397 const std::function<void(LoopPassManager &, OptimizationLevel)> &C) {
398 LateLoopOptimizationsEPCallbacks.push_back(C);
399 }
400
401 /// Register a callback for a default optimizer pipeline extension
402 /// point
403 ///
404 /// This extension point allows adding loop passes to the end of the loop
405 /// optimizer.
407 const std::function<void(LoopPassManager &, OptimizationLevel)> &C) {
408 LoopOptimizerEndEPCallbacks.push_back(C);
409 }
410
411 /// Register a callback for a default optimizer pipeline extension
412 /// point
413 ///
414 /// This extension point allows adding optimization passes after most of the
415 /// main optimizations, but before the last cleanup-ish optimizations.
417 const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
418 ScalarOptimizerLateEPCallbacks.push_back(C);
419 }
420
421 /// Register a callback for a default optimizer pipeline extension
422 /// point
423 ///
424 /// This extension point allows adding CallGraphSCC passes at the end of the
425 /// main CallGraphSCC passes and before any function simplification passes run
426 /// by CGPassManager.
428 const std::function<void(CGSCCPassManager &, OptimizationLevel)> &C) {
429 CGSCCOptimizerLateEPCallbacks.push_back(C);
430 }
431
432 /// Register a callback for a default optimizer pipeline extension
433 /// point
434 ///
435 /// This extension point allows adding optimization passes before the
436 /// vectorizer and other highly target specific optimization passes are
437 /// executed.
439 const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
440 VectorizerStartEPCallbacks.push_back(C);
441 }
442
443 /// Register a callback for a default optimizer pipeline extension point.
444 ///
445 /// This extension point allows adding optimization once at the start of the
446 /// pipeline. This does not apply to 'backend' compiles (LTO and ThinLTO
447 /// link-time pipelines).
449 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
450 PipelineStartEPCallbacks.push_back(C);
451 }
452
453 /// Register a callback for a default optimizer pipeline extension point.
454 ///
455 /// This extension point allows adding optimization right after passes that do
456 /// basic simplification of the input IR.
458 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
459 PipelineEarlySimplificationEPCallbacks.push_back(C);
460 }
461
462 /// Register a callback for a default optimizer pipeline extension point
463 ///
464 /// This extension point allows adding optimizations before the function
465 /// optimization pipeline.
467 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
468 OptimizerEarlyEPCallbacks.push_back(C);
469 }
470
471 /// Register a callback for a default optimizer pipeline extension point
472 ///
473 /// This extension point allows adding optimizations at the very end of the
474 /// function optimization pipeline.
476 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
477 OptimizerLastEPCallbacks.push_back(C);
478 }
479
480 /// Register a callback for a default optimizer pipeline extension point
481 ///
482 /// This extension point allows adding optimizations at the start of the full
483 /// LTO pipeline.
485 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
486 FullLinkTimeOptimizationEarlyEPCallbacks.push_back(C);
487 }
488
489 /// Register a callback for a default optimizer pipeline extension point
490 ///
491 /// This extension point allows adding optimizations at the end of the full
492 /// LTO pipeline.
494 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
495 FullLinkTimeOptimizationLastEPCallbacks.push_back(C);
496 }
497
498 /// Register a callback for parsing an AliasAnalysis Name to populate
499 /// the given AAManager \p AA
501 const std::function<bool(StringRef Name, AAManager &AA)> &C) {
502 AAParsingCallbacks.push_back(C);
503 }
504
505 /// {{@ Register callbacks for analysis registration with this PassBuilder
506 /// instance.
507 /// Callees register their analyses with the given AnalysisManager objects.
509 const std::function<void(CGSCCAnalysisManager &)> &C) {
510 CGSCCAnalysisRegistrationCallbacks.push_back(C);
511 }
513 const std::function<void(FunctionAnalysisManager &)> &C) {
514 FunctionAnalysisRegistrationCallbacks.push_back(C);
515 }
517 const std::function<void(LoopAnalysisManager &)> &C) {
518 LoopAnalysisRegistrationCallbacks.push_back(C);
519 }
521 const std::function<void(ModuleAnalysisManager &)> &C) {
522 ModuleAnalysisRegistrationCallbacks.push_back(C);
523 }
524 /// @}}
525
526 /// {{@ Register pipeline parsing callbacks with this pass builder instance.
527 /// Using these callbacks, callers can parse both a single pass name, as well
528 /// as entire sub-pipelines, and populate the PassManager instance
529 /// accordingly.
531 const std::function<bool(StringRef Name, CGSCCPassManager &,
533 CGSCCPipelineParsingCallbacks.push_back(C);
534 }
536 const std::function<bool(StringRef Name, FunctionPassManager &,
538 FunctionPipelineParsingCallbacks.push_back(C);
539 }
541 const std::function<bool(StringRef Name, LoopPassManager &,
543 LoopPipelineParsingCallbacks.push_back(C);
544 }
546 const std::function<bool(StringRef Name, ModulePassManager &,
548 ModulePipelineParsingCallbacks.push_back(C);
549 }
550 /// @}}
551
552 /// Register a callback for a top-level pipeline entry.
553 ///
554 /// If the PassManager type is not given at the top level of the pipeline
555 /// text, this Callback should be used to determine the appropriate stack of
556 /// PassManagers and populate the passed ModulePassManager.
558 const std::function<bool(ModulePassManager &, ArrayRef<PipelineElement>)>
559 &C);
560
561 /// Add PGOInstrumenation passes for O0 only.
562 void addPGOInstrPassesForO0(ModulePassManager &MPM, bool RunProfileGen,
563 bool IsCS, bool AtomicCounterUpdate,
564 std::string ProfileFile,
565 std::string ProfileRemappingFile,
567
568 /// Returns PIC. External libraries can use this to register pass
569 /// instrumentation callbacks.
571 return PIC;
572 }
573
574 // Invoke the callbacks registered for the various extension points.
575 // Custom pipelines should use these to invoke the callbacks registered
576 // by TargetMachines and other clients.
578 OptimizationLevel Level);
580 OptimizationLevel Level);
582 OptimizationLevel Level);
584 OptimizationLevel Level);
586 OptimizationLevel Level);
588 OptimizationLevel Level);
590 OptimizationLevel Level);
592 OptimizationLevel Level);
594 OptimizationLevel Level);
596 OptimizationLevel Level);
598 OptimizationLevel Level);
600 OptimizationLevel Level);
601
602private:
603 // O1 pass pipeline
605 buildO1FunctionSimplificationPipeline(OptimizationLevel Level,
607
608 void addRequiredLTOPreLinkPasses(ModulePassManager &MPM);
609
610 void addVectorPasses(OptimizationLevel Level, FunctionPassManager &FPM,
611 bool IsFullLTO);
612
613 static std::optional<std::vector<PipelineElement>>
614 parsePipelineText(StringRef Text);
615
616 Error parseModulePass(ModulePassManager &MPM, const PipelineElement &E);
617 Error parseCGSCCPass(CGSCCPassManager &CGPM, const PipelineElement &E);
618 Error parseFunctionPass(FunctionPassManager &FPM, const PipelineElement &E);
619 Error parseLoopPass(LoopPassManager &LPM, const PipelineElement &E);
620 bool parseAAPassName(AAManager &AA, StringRef Name);
621
622 Error parseLoopPassPipeline(LoopPassManager &LPM,
624 Error parseFunctionPassPipeline(FunctionPassManager &FPM,
626 Error parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
628 Error parseModulePassPipeline(ModulePassManager &MPM,
630
631 void addPGOInstrPasses(ModulePassManager &MPM, OptimizationLevel Level,
632 bool RunProfileGen, bool IsCS,
633 bool AtomicCounterUpdate, std::string ProfileFile,
634 std::string ProfileRemappingFile,
635 ThinOrFullLTOPhase LTOPhase,
637
638 // Extension Point callbacks
639 SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
640 PeepholeEPCallbacks;
641 SmallVector<std::function<void(LoopPassManager &, OptimizationLevel)>, 2>
642 LateLoopOptimizationsEPCallbacks;
643 SmallVector<std::function<void(LoopPassManager &, OptimizationLevel)>, 2>
644 LoopOptimizerEndEPCallbacks;
645 SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
646 ScalarOptimizerLateEPCallbacks;
647 SmallVector<std::function<void(CGSCCPassManager &, OptimizationLevel)>, 2>
648 CGSCCOptimizerLateEPCallbacks;
649 SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
650 VectorizerStartEPCallbacks;
651 // Module callbacks
652 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
653 OptimizerEarlyEPCallbacks;
654 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
655 OptimizerLastEPCallbacks;
656 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
657 FullLinkTimeOptimizationEarlyEPCallbacks;
658 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
659 FullLinkTimeOptimizationLastEPCallbacks;
660 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
661 PipelineStartEPCallbacks;
662 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
663 PipelineEarlySimplificationEPCallbacks;
664
665 SmallVector<std::function<void(ModuleAnalysisManager &)>, 2>
666 ModuleAnalysisRegistrationCallbacks;
669 2>
670 ModulePipelineParsingCallbacks;
673 TopLevelPipelineParsingCallbacks;
674 // CGSCC callbacks
675 SmallVector<std::function<void(CGSCCAnalysisManager &)>, 2>
676 CGSCCAnalysisRegistrationCallbacks;
679 2>
680 CGSCCPipelineParsingCallbacks;
681 // Function callbacks
682 SmallVector<std::function<void(FunctionAnalysisManager &)>, 2>
683 FunctionAnalysisRegistrationCallbacks;
686 2>
687 FunctionPipelineParsingCallbacks;
688 // Loop callbacks
689 SmallVector<std::function<void(LoopAnalysisManager &)>, 2>
690 LoopAnalysisRegistrationCallbacks;
691 SmallVector<std::function<bool(StringRef, LoopPassManager &,
693 2>
694 LoopPipelineParsingCallbacks;
695 // AA callbacks
696 SmallVector<std::function<bool(StringRef Name, AAManager &AA)>, 2>
697 AAParsingCallbacks;
698};
699
700/// This utility template takes care of adding require<> and invalidate<>
701/// passes for an analysis to a given \c PassManager. It is intended to be used
702/// during parsing of a pass pipeline when parsing a single PipelineName.
703/// When registering a new function analysis FancyAnalysis with the pass
704/// pipeline name "fancy-analysis", a matching ParsePipelineCallback could look
705/// like this:
706///
707/// static bool parseFunctionPipeline(StringRef Name, FunctionPassManager &FPM,
708/// ArrayRef<PipelineElement> P) {
709/// if (parseAnalysisUtilityPasses<FancyAnalysis>("fancy-analysis", Name,
710/// FPM))
711/// return true;
712/// return false;
713/// }
714template <typename AnalysisT, typename IRUnitT, typename AnalysisManagerT,
715 typename... ExtraArgTs>
717 StringRef AnalysisName, StringRef PipelineName,
719 if (!PipelineName.endswith(">"))
720 return false;
721 // See if this is an invalidate<> pass name
722 if (PipelineName.startswith("invalidate<")) {
723 PipelineName = PipelineName.substr(11, PipelineName.size() - 12);
724 if (PipelineName != AnalysisName)
725 return false;
727 return true;
728 }
729
730 // See if this is a require<> pass name
731 if (PipelineName.startswith("require<")) {
732 PipelineName = PipelineName.substr(8, PipelineName.size() - 9);
733 if (PipelineName != AnalysisName)
734 return false;
735 PM.addPass(RequireAnalysisPass<AnalysisT, IRUnitT, AnalysisManagerT,
736 ExtraArgTs...>());
737 return true;
738 }
739
740 return false;
741}
742}
743
744#endif
aarch64 falkor hwpf fix Falkor HW Prefetch Fix Late Phase
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This header provides classes for managing passes over SCCs of the call graph.
std::string Name
This header provides classes for managing a pipeline of passes over loops in LLVM IR.
This header enumerates the LLVM-provided high-level optimization levels.
Define option tunables for PGO.
CGSCCAnalysisManager CGAM
ModulePassManager MPM
LoopAnalysisManager LAM
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
PassInstrumentationCallbacks PIC
This header defines various interfaces for pass management in LLVM.
raw_pwrite_stream & OS
A manager for alias analyses.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
Module pass, wrapping the inliner pass.
Definition: Inliner.h:62
Class to hold module path string table and global value map, and encapsulate methods for operating on...
This class provides access to building LLVM's passes.
Definition: PassBuilder.h:103
ModulePassManager buildO0DefaultPipeline(OptimizationLevel Level, bool LTOPreLink=false)
Build an O0 pipeline with the minimal semantically required passes.
void invokeFullLinkTimeOptimizationLastEPCallbacks(ModulePassManager &MPM, OptimizationLevel Level)
ModuleInlinerWrapperPass buildInlinerPipeline(OptimizationLevel Level, ThinOrFullLTOPhase Phase)
Construct the module pipeline that performs inlining as well as the inlining-driven cleanups.
void printPassNames(raw_ostream &OS)
Print pass names.
void invokeOptimizerLastEPCallbacks(ModulePassManager &MPM, OptimizationLevel Level)
void registerPipelineEarlySimplificationEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:457
void invokeVectorizerStartEPCallbacks(FunctionPassManager &FPM, OptimizationLevel Level)
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, ModulePassManager &, ArrayRef< PipelineElement >)> &C)
Definition: PassBuilder.h:545
AAManager buildDefaultAAPipeline()
Build the default AAManager with the default alias analysis pipeline registered.
Error parseAAPipeline(AAManager &AA, StringRef PipelineText)
Parse a textual alias analysis pipeline into the provided AA manager.
void invokeCGSCCOptimizerLateEPCallbacks(CGSCCPassManager &CGPM, OptimizationLevel Level)
ModulePassManager buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level)
Build a pre-link, ThinLTO-targeting default optimization pipeline to a pass manager.
void registerAnalysisRegistrationCallback(const std::function< void(ModuleAnalysisManager &)> &C)
Definition: PassBuilder.h:520
void registerPipelineStartEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:448
void invokeScalarOptimizerLateEPCallbacks(FunctionPassManager &FPM, OptimizationLevel Level)
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, LoopPassManager &, ArrayRef< PipelineElement >)> &C)
Definition: PassBuilder.h:540
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
PassInstrumentationCallbacks * getPassInstrumentationCallbacks() const
Returns PIC.
Definition: PassBuilder.h:570
void registerLateLoopOptimizationsEPCallback(const std::function< void(LoopPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:396
void registerLoopOptimizerEndEPCallback(const std::function< void(LoopPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:406
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:500
void registerOptimizerLastEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:475
void registerVectorizerStartEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:438
void registerAnalysisRegistrationCallback(const std::function< void(LoopAnalysisManager &)> &C)
Definition: PassBuilder.h:516
void registerPeepholeEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:382
void crossRegisterProxies(LoopAnalysisManager &LAM, FunctionAnalysisManager &FAM, CGSCCAnalysisManager &CGAM, ModuleAnalysisManager &MAM)
Cross register the analysis managers through their proxies.
void registerAnalysisRegistrationCallback(const std::function< void(FunctionAnalysisManager &)> &C)
Definition: PassBuilder.h:512
void registerScalarOptimizerLateEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:416
ModulePassManager buildPerModuleDefaultPipeline(OptimizationLevel Level, bool LTOPreLink=false)
Build a per-module default optimization pipeline.
void registerAnalysisRegistrationCallback(const std::function< void(CGSCCAnalysisManager &)> &C)
{{@ Register callbacks for analysis registration with this PassBuilder instance.
Definition: PassBuilder.h:508
void invokePipelineStartEPCallbacks(ModulePassManager &MPM, OptimizationLevel Level)
FunctionPassManager buildFunctionSimplificationPipeline(OptimizationLevel Level, ThinOrFullLTOPhase Phase)
Construct the core LLVM function canonicalization and simplification pipeline.
void registerCGSCCOptimizerLateEPCallback(const std::function< void(CGSCCPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:427
void invokePeepholeEPCallbacks(FunctionPassManager &FPM, OptimizationLevel Level)
Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText)
Parse a textual pass pipeline description into a ModulePassManager.
void invokeLoopOptimizerEndEPCallbacks(LoopPassManager &LPM, OptimizationLevel Level)
void registerOptimizerEarlyEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:466
ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level, ModuleSummaryIndex *ExportSummary)
Build an LTO default optimization pipeline to a pass manager.
ModulePassManager buildModuleInlinerPipeline(OptimizationLevel Level, ThinOrFullLTOPhase Phase)
Construct the module pipeline that performs inlining with module inliner pass.
ModulePassManager buildThinLTODefaultPipeline(OptimizationLevel Level, const ModuleSummaryIndex *ImportSummary)
Build an ThinLTO default optimization pipeline to a pass manager.
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, CGSCCPassManager &, ArrayRef< PipelineElement >)> &C)
{{@ Register pipeline parsing callbacks with this pass builder instance.
Definition: PassBuilder.h:530
void registerFullLinkTimeOptimizationEarlyEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:484
void invokeLateLoopOptimizationsEPCallbacks(LoopPassManager &LPM, OptimizationLevel Level)
void invokeOptimizerEarlyEPCallbacks(ModulePassManager &MPM, OptimizationLevel Level)
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, FunctionPassManager &, ArrayRef< PipelineElement >)> &C)
Definition: PassBuilder.h:535
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
void invokePipelineEarlySimplificationEPCallbacks(ModulePassManager &MPM, OptimizationLevel Level)
void registerFullLinkTimeOptimizationLastEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:493
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
void invokeFullLinkTimeOptimizationEarlyEPCallbacks(ModulePassManager &MPM, OptimizationLevel Level)
ModulePassManager buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO, bool EmitSummary)
Build a fat object default optimization pipeline.
ModulePassManager buildModuleSimplificationPipeline(OptimizationLevel Level, ThinOrFullLTOPhase Phase)
Construct the core LLVM module canonicalization and simplification pipeline.
ModulePassManager buildModuleOptimizationPipeline(OptimizationLevel Level, ThinOrFullLTOPhase LTOPhase)
Construct the core LLVM module optimization pipeline.
void registerParseTopLevelPipelineCallback(const std::function< bool(ModulePassManager &, ArrayRef< PipelineElement >)> &C)
Register a callback for a top-level pipeline entry.
void addPGOInstrPassesForO0(ModulePassManager &MPM, bool RunProfileGen, bool IsCS, bool AtomicCounterUpdate, std::string ProfileFile, std::string ProfileRemappingFile, IntrusiveRefCntPtr< vfs::FileSystem > FS)
Add PGOInstrumenation passes for O0 only.
ModulePassManager buildLTOPreLinkDefaultPipeline(OptimizationLevel Level)
Build a pre-link, LTO-targeting default optimization pipeline to a pass manager.
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
Definition: PassManager.h:544
Tunable parameters for passes in the default pipelines.
Definition: PassBuilder.h:41
unsigned LicmMssaNoAccForPromotionCap
Tuning option to disable promotion to scalars in LICM with MemorySSA, if the number of access is too ...
Definition: PassBuilder.h:71
bool SLPVectorization
Tuning option to enable/disable slp loop vectorization, set based on opt level.
Definition: PassBuilder.h:56
int InlinerThreshold
Tuning option to override the default inliner threshold.
Definition: PassBuilder.h:85
bool CallGraphProfile
Tuning option to enable/disable call graph profile.
Definition: PassBuilder.h:75
bool MergeFunctions
Tuning option to enable/disable function merging.
Definition: PassBuilder.h:82
bool ForgetAllSCEVInLoopUnroll
Tuning option to forget all SCEV loops in LoopUnroll.
Definition: PassBuilder.h:63
unsigned LicmMssaOptCap
Tuning option to cap the number of calls to retrive clobbering accesses in MemorySSA,...
Definition: PassBuilder.h:67
bool LoopInterleaving
Tuning option to set loop interleaving on/off, set based on opt level.
Definition: PassBuilder.h:48
PipelineTuningOptions()
Constructor sets pipeline tuning defaults based on cl::opts.
bool LoopUnrolling
Tuning option to enable/disable loop unrolling. Its default value is true.
Definition: PassBuilder.h:59
bool LoopVectorization
Tuning option to enable/disable loop vectorization, set based on opt level.
Definition: PassBuilder.h:52
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:575
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
bool startswith(StringRef Prefix) const
Definition: StringRef.h:261
bool endswith(StringRef Suffix) const
Definition: StringRef.h:280
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:78
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:716
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.
Definition: Pass.h:76
A no-op pass template which simply forces a specific analysis result to be invalidated.
Definition: PassManager.h:1272
A struct to capture parsed pass pipeline names.
Definition: PassBuilder.h:118
std::vector< PipelineElement > InnerPipeline
Definition: PassBuilder.h:120
A utility pass template to force an analysis result to be available.
Definition: PassManager.h:1245