LLVM 17.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 /// Tuning option to enable/disable function merging. Its default value is
78 /// false.
80
81 /// Tuning option to override the default inliner threshold.
83
84 // Experimental option to eagerly invalidate more analyses. This has the
85 // potential to decrease max memory usage in exchange for more compile time.
86 // This may affect codegen due to either passes using analyses only when
87 // cached, or invalidating and recalculating an analysis that was
88 // stale/imprecise but still valid. Currently this invalidates all function
89 // analyses after various module->function or cgscc->function adaptors in the
90 // default pipelines.
92};
93
94/// This class provides access to building LLVM's passes.
95///
96/// Its members provide the baseline state available to passes during their
97/// construction. The \c PassRegistry.def file specifies how to construct all
98/// of the built-in passes, and those may reference these members during
99/// construction.
101 TargetMachine *TM;
103 std::optional<PGOOptions> PGOOpt;
105
106public:
107 /// A struct to capture parsed pass pipeline names.
108 ///
109 /// A pipeline is defined as a series of names, each of which may in itself
110 /// recursively contain a nested pipeline. A name is either the name of a pass
111 /// (e.g. "instcombine") or the name of a pipeline type (e.g. "cgscc"). If the
112 /// name is the name of a pass, the InnerPipeline is empty, since passes
113 /// cannot contain inner pipelines. See parsePassPipeline() for a more
114 /// detailed description of the textual pipeline format.
117 std::vector<PipelineElement> InnerPipeline;
118 };
119
120 explicit PassBuilder(TargetMachine *TM = nullptr,
122 std::optional<PGOOptions> PGOOpt = std::nullopt,
123 PassInstrumentationCallbacks *PIC = nullptr);
124
125 /// Cross register the analysis managers through their proxies.
126 ///
127 /// This is an interface that can be used to cross register each
128 /// AnalysisManager with all the others analysis managers.
133
134 /// Registers all available module analysis passes.
135 ///
136 /// This is an interface that can be used to populate a \c
137 /// ModuleAnalysisManager with all registered module analyses. Callers can
138 /// still manually register any additional analyses. Callers can also
139 /// pre-register analyses and this will not override those.
141
142 /// Registers all available CGSCC analysis passes.
143 ///
144 /// This is an interface that can be used to populate a \c CGSCCAnalysisManager
145 /// with all registered CGSCC analyses. Callers can still manually register any
146 /// additional analyses. Callers can also pre-register analyses and this will
147 /// not override those.
149
150 /// Registers all available function analysis passes.
151 ///
152 /// This is an interface that can be used to populate a \c
153 /// FunctionAnalysisManager with all registered function analyses. Callers can
154 /// still manually register any additional analyses. Callers can also
155 /// pre-register analyses and this will not override those.
157
158 /// Registers all available loop analysis passes.
159 ///
160 /// This is an interface that can be used to populate a \c LoopAnalysisManager
161 /// with all registered loop analyses. Callers can still manually register any
162 /// additional analyses.
164
165 /// Construct the core LLVM function canonicalization and simplification
166 /// pipeline.
167 ///
168 /// This is a long pipeline and uses most of the per-function optimization
169 /// passes in LLVM to canonicalize and simplify the IR. It is suitable to run
170 /// repeatedly over the IR and is not expected to destroy important
171 /// information about the semantics of the IR.
172 ///
173 /// Note that \p Level cannot be `O0` here. The pipelines produced are
174 /// only intended for use when attempting to optimize code. If frontends
175 /// require some transformations for semantic reasons, they should explicitly
176 /// build them.
177 ///
178 /// \p Phase indicates the current ThinLTO phase.
182
183 /// Construct the core LLVM module canonicalization and simplification
184 /// pipeline.
185 ///
186 /// This pipeline focuses on canonicalizing and simplifying the entire module
187 /// of IR. Much like the function simplification pipeline above, it is
188 /// suitable to run repeatedly over the IR and is not expected to destroy
189 /// important information. It does, however, perform inlining and other
190 /// heuristic based simplifications that are not strictly reversible.
191 ///
192 /// Note that \p Level cannot be `O0` here. The pipelines produced are
193 /// only intended for use when attempting to optimize code. If frontends
194 /// require some transformations for semantic reasons, they should explicitly
195 /// build them.
196 ///
197 /// \p Phase indicates the current ThinLTO phase.
200
201 /// Construct the module pipeline that performs inlining as well as
202 /// the inlining-driven cleanups.
205
206 /// Construct the module pipeline that performs inlining with
207 /// module inliner pass.
210
211 /// Construct the core LLVM module optimization pipeline.
212 ///
213 /// This pipeline focuses on optimizing the execution speed of the IR. It
214 /// uses cost modeling and thresholds to balance code growth against runtime
215 /// improvements. It includes vectorization and other information destroying
216 /// transformations. It also cannot generally be run repeatedly on a module
217 /// without potentially seriously regressing either runtime performance of
218 /// the code or serious code size growth.
219 ///
220 /// Note that \p Level cannot be `O0` here. The pipelines produced are
221 /// only intended for use when attempting to optimize code. If frontends
222 /// require some transformations for semantic reasons, they should explicitly
223 /// build them.
226 ThinOrFullLTOPhase LTOPhase);
227
228 /// Build a per-module default optimization pipeline.
229 ///
230 /// This provides a good default optimization pipeline for per-module
231 /// optimization and code generation without any link-time optimization. It
232 /// typically correspond to frontend "-O[123]" options for optimization
233 /// levels \c O1, \c O2 and \c O3 resp.
234 ///
235 /// Note that \p Level cannot be `O0` here. The pipelines produced are
236 /// only intended for use when attempting to optimize code. If frontends
237 /// require some transformations for semantic reasons, they should explicitly
238 /// build them.
240 bool LTOPreLink = false);
241
242 /// Build a pre-link, ThinLTO-targeting default optimization pipeline to
243 /// a pass manager.
244 ///
245 /// This adds the pre-link optimizations tuned to prepare a module for
246 /// a ThinLTO run. It works to minimize the IR which needs to be analyzed
247 /// without making irreversible decisions which could be made better during
248 /// the LTO run.
249 ///
250 /// Note that \p Level cannot be `O0` here. The pipelines produced are
251 /// only intended for use when attempting to optimize code. If frontends
252 /// require some transformations for semantic reasons, they should explicitly
253 /// build them.
255
256 /// Build an ThinLTO default optimization pipeline to a pass manager.
257 ///
258 /// This provides a good default optimization pipeline for link-time
259 /// optimization and code generation. It is particularly tuned to fit well
260 /// when IR coming into the LTO phase was first run through \c
261 /// addPreLinkLTODefaultPipeline, and the two coordinate closely.
264 const ModuleSummaryIndex *ImportSummary);
265
266 /// Build a pre-link, LTO-targeting default optimization pipeline to a pass
267 /// manager.
268 ///
269 /// This adds the pre-link optimizations tuned to work well with a later LTO
270 /// run. It works to minimize the IR which needs to be analyzed without
271 /// making irreversible decisions which could be made better during the LTO
272 /// run.
274
275 /// Build an LTO default optimization pipeline to a pass manager.
276 ///
277 /// This provides a good default optimization pipeline for link-time
278 /// optimization and code generation. It is particularly tuned to fit well
279 /// when IR coming into the LTO phase was first run through \c
280 /// addPreLinkLTODefaultPipeline, and the two coordinate closely.
282 ModuleSummaryIndex *ExportSummary);
283
284 /// Build an O0 pipeline with the minimal semantically required passes.
285 ///
286 /// This should only be used for non-LTO and LTO pre-link pipelines.
288 bool LTOPreLink = false);
289
290 /// Build the default `AAManager` with the default alias analysis pipeline
291 /// registered.
292 ///
293 /// This also adds target-specific alias analyses registered via
294 /// TargetMachine::registerDefaultAliasAnalyses().
296
297 /// Parse a textual pass pipeline description into a \c
298 /// ModulePassManager.
299 ///
300 /// The format of the textual pass pipeline description looks something like:
301 ///
302 /// module(function(instcombine,sroa),dce,cgscc(inliner,function(...)),...)
303 ///
304 /// Pass managers have ()s describing the nest structure of passes. All passes
305 /// are comma separated. As a special shortcut, if the very first pass is not
306 /// a module pass (as a module pass manager is), this will automatically form
307 /// the shortest stack of pass managers that allow inserting that first pass.
308 /// So, assuming function passes 'fpassN', CGSCC passes 'cgpassN', and loop
309 /// passes 'lpassN', all of these are valid:
310 ///
311 /// fpass1,fpass2,fpass3
312 /// cgpass1,cgpass2,cgpass3
313 /// lpass1,lpass2,lpass3
314 ///
315 /// And they are equivalent to the following (resp.):
316 ///
317 /// module(function(fpass1,fpass2,fpass3))
318 /// module(cgscc(cgpass1,cgpass2,cgpass3))
319 /// module(function(loop(lpass1,lpass2,lpass3)))
320 ///
321 /// This shortcut is especially useful for debugging and testing small pass
322 /// combinations.
323 ///
324 /// The sequence of passes aren't necessarily the exact same kind of pass.
325 /// You can mix different levels implicitly if adaptor passes are defined to
326 /// make them work. For example,
327 ///
328 /// mpass1,fpass1,fpass2,mpass2,lpass1
329 ///
330 /// This pipeline uses only one pass manager: the top-level module manager.
331 /// fpass1,fpass2 and lpass1 are added into the the top-level module manager
332 /// using only adaptor passes. No nested function/loop pass managers are
333 /// added. The purpose is to allow easy pass testing when the user
334 /// specifically want the pass to run under a adaptor directly. This is
335 /// preferred when a pipeline is largely of one type, but one or just a few
336 /// passes are of different types(See PassBuilder.cpp for examples).
338
339 /// {{@ Parse a textual pass pipeline description into a specific PassManager
340 ///
341 /// Automatic deduction of an appropriate pass manager stack is not supported.
342 /// For example, to insert a loop pass 'lpass' into a FunctionPassManager,
343 /// this is the valid pipeline text:
344 ///
345 /// function(lpass)
349 /// @}}
350
351 /// Parse a textual alias analysis pipeline into the provided AA manager.
352 ///
353 /// The format of the textual AA pipeline is a comma separated list of AA
354 /// pass names:
355 ///
356 /// basic-aa,globals-aa,...
357 ///
358 /// The AA manager is set up such that the provided alias analyses are tried
359 /// in the order specified. See the \c AAManaager documentation for details
360 /// about the logic used. This routine just provides the textual mapping
361 /// between AA names and the analyses to register with the manager.
362 ///
363 /// Returns false if the text cannot be parsed cleanly. The specific state of
364 /// the \p AA manager is unspecified if such an error is encountered and this
365 /// returns false.
366 Error parseAAPipeline(AAManager &AA, StringRef PipelineText);
367
368 /// Print pass names.
370
371 /// Register a callback for a default optimizer pipeline extension
372 /// point
373 ///
374 /// This extension point allows adding passes that perform peephole
375 /// optimizations similar to the instruction combiner. These passes will be
376 /// inserted after each instance of the instruction combiner pass.
378 const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
379 PeepholeEPCallbacks.push_back(C);
380 }
381
382 /// Register a callback for a default optimizer pipeline extension
383 /// point
384 ///
385 /// This extension point allows adding late loop canonicalization and
386 /// simplification passes. This is the last point in the loop optimization
387 /// pipeline before loop deletion. Each pass added
388 /// here must be an instance of LoopPass.
389 /// This is the place to add passes that can remove loops, such as target-
390 /// specific loop idiom recognition.
392 const std::function<void(LoopPassManager &, OptimizationLevel)> &C) {
393 LateLoopOptimizationsEPCallbacks.push_back(C);
394 }
395
396 /// Register a callback for a default optimizer pipeline extension
397 /// point
398 ///
399 /// This extension point allows adding loop passes to the end of the loop
400 /// optimizer.
402 const std::function<void(LoopPassManager &, OptimizationLevel)> &C) {
403 LoopOptimizerEndEPCallbacks.push_back(C);
404 }
405
406 /// Register a callback for a default optimizer pipeline extension
407 /// point
408 ///
409 /// This extension point allows adding optimization passes after most of the
410 /// main optimizations, but before the last cleanup-ish optimizations.
412 const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
413 ScalarOptimizerLateEPCallbacks.push_back(C);
414 }
415
416 /// Register a callback for a default optimizer pipeline extension
417 /// point
418 ///
419 /// This extension point allows adding CallGraphSCC passes at the end of the
420 /// main CallGraphSCC passes and before any function simplification passes run
421 /// by CGPassManager.
423 const std::function<void(CGSCCPassManager &, OptimizationLevel)> &C) {
424 CGSCCOptimizerLateEPCallbacks.push_back(C);
425 }
426
427 /// Register a callback for a default optimizer pipeline extension
428 /// point
429 ///
430 /// This extension point allows adding optimization passes before the
431 /// vectorizer and other highly target specific optimization passes are
432 /// executed.
434 const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
435 VectorizerStartEPCallbacks.push_back(C);
436 }
437
438 /// Register a callback for a default optimizer pipeline extension point.
439 ///
440 /// This extension point allows adding optimization once at the start of the
441 /// pipeline. This does not apply to 'backend' compiles (LTO and ThinLTO
442 /// link-time pipelines).
444 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
445 PipelineStartEPCallbacks.push_back(C);
446 }
447
448 /// Register a callback for a default optimizer pipeline extension point.
449 ///
450 /// This extension point allows adding optimization right after passes that do
451 /// basic simplification of the input IR.
453 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
454 PipelineEarlySimplificationEPCallbacks.push_back(C);
455 }
456
457 /// Register a callback for a default optimizer pipeline extension point
458 ///
459 /// This extension point allows adding optimizations before the function
460 /// optimization pipeline.
462 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
463 OptimizerEarlyEPCallbacks.push_back(C);
464 }
465
466 /// Register a callback for a default optimizer pipeline extension point
467 ///
468 /// This extension point allows adding optimizations at the very end of the
469 /// function optimization pipeline.
471 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
472 OptimizerLastEPCallbacks.push_back(C);
473 }
474
475 /// Register a callback for a default optimizer pipeline extension point
476 ///
477 /// This extension point allows adding optimizations at the start of the full
478 /// LTO pipeline.
480 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
481 FullLinkTimeOptimizationEarlyEPCallbacks.push_back(C);
482 }
483
484 /// Register a callback for a default optimizer pipeline extension point
485 ///
486 /// This extension point allows adding optimizations at the end of the full
487 /// LTO pipeline.
489 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
490 FullLinkTimeOptimizationLastEPCallbacks.push_back(C);
491 }
492
493 /// Register a callback for parsing an AliasAnalysis Name to populate
494 /// the given AAManager \p AA
496 const std::function<bool(StringRef Name, AAManager &AA)> &C) {
497 AAParsingCallbacks.push_back(C);
498 }
499
500 /// {{@ Register callbacks for analysis registration with this PassBuilder
501 /// instance.
502 /// Callees register their analyses with the given AnalysisManager objects.
504 const std::function<void(CGSCCAnalysisManager &)> &C) {
505 CGSCCAnalysisRegistrationCallbacks.push_back(C);
506 }
508 const std::function<void(FunctionAnalysisManager &)> &C) {
509 FunctionAnalysisRegistrationCallbacks.push_back(C);
510 }
512 const std::function<void(LoopAnalysisManager &)> &C) {
513 LoopAnalysisRegistrationCallbacks.push_back(C);
514 }
516 const std::function<void(ModuleAnalysisManager &)> &C) {
517 ModuleAnalysisRegistrationCallbacks.push_back(C);
518 }
519 /// @}}
520
521 /// {{@ Register pipeline parsing callbacks with this pass builder instance.
522 /// Using these callbacks, callers can parse both a single pass name, as well
523 /// as entire sub-pipelines, and populate the PassManager instance
524 /// accordingly.
526 const std::function<bool(StringRef Name, CGSCCPassManager &,
528 CGSCCPipelineParsingCallbacks.push_back(C);
529 }
531 const std::function<bool(StringRef Name, FunctionPassManager &,
533 FunctionPipelineParsingCallbacks.push_back(C);
534 }
536 const std::function<bool(StringRef Name, LoopPassManager &,
538 LoopPipelineParsingCallbacks.push_back(C);
539 }
541 const std::function<bool(StringRef Name, ModulePassManager &,
543 ModulePipelineParsingCallbacks.push_back(C);
544 }
545 /// @}}
546
547 /// Register a callback for a top-level pipeline entry.
548 ///
549 /// If the PassManager type is not given at the top level of the pipeline
550 /// text, this Callback should be used to determine the appropriate stack of
551 /// PassManagers and populate the passed ModulePassManager.
553 const std::function<bool(ModulePassManager &, ArrayRef<PipelineElement>)>
554 &C);
555
556 /// Add PGOInstrumenation passes for O0 only.
557 void addPGOInstrPassesForO0(ModulePassManager &MPM, bool RunProfileGen,
558 bool IsCS, std::string ProfileFile,
559 std::string ProfileRemappingFile,
561
562 /// Returns PIC. External libraries can use this to register pass
563 /// instrumentation callbacks.
565 return PIC;
566 }
567
568private:
569 // O1 pass pipeline
571 buildO1FunctionSimplificationPipeline(OptimizationLevel Level,
573
574 void addRequiredLTOPreLinkPasses(ModulePassManager &MPM);
575
576 void addVectorPasses(OptimizationLevel Level, FunctionPassManager &FPM,
577 bool IsFullLTO);
578
579 static std::optional<std::vector<PipelineElement>>
580 parsePipelineText(StringRef Text);
581
582 Error parseModulePass(ModulePassManager &MPM, const PipelineElement &E);
583 Error parseCGSCCPass(CGSCCPassManager &CGPM, const PipelineElement &E);
584 Error parseFunctionPass(FunctionPassManager &FPM, const PipelineElement &E);
585 Error parseLoopPass(LoopPassManager &LPM, const PipelineElement &E);
586 bool parseAAPassName(AAManager &AA, StringRef Name);
587
588 Error parseLoopPassPipeline(LoopPassManager &LPM,
590 Error parseFunctionPassPipeline(FunctionPassManager &FPM,
592 Error parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
594 Error parseModulePassPipeline(ModulePassManager &MPM,
596
597 void addPGOInstrPasses(ModulePassManager &MPM, OptimizationLevel Level,
598 bool RunProfileGen, bool IsCS, std::string ProfileFile,
599 std::string ProfileRemappingFile,
600 ThinOrFullLTOPhase LTOPhase,
602 void invokePeepholeEPCallbacks(FunctionPassManager &, OptimizationLevel);
603
604 // Extension Point callbacks
605 SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
606 PeepholeEPCallbacks;
607 SmallVector<std::function<void(LoopPassManager &, OptimizationLevel)>, 2>
608 LateLoopOptimizationsEPCallbacks;
609 SmallVector<std::function<void(LoopPassManager &, OptimizationLevel)>, 2>
610 LoopOptimizerEndEPCallbacks;
611 SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
612 ScalarOptimizerLateEPCallbacks;
613 SmallVector<std::function<void(CGSCCPassManager &, OptimizationLevel)>, 2>
614 CGSCCOptimizerLateEPCallbacks;
615 SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
616 VectorizerStartEPCallbacks;
617 // Module callbacks
618 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
619 OptimizerEarlyEPCallbacks;
620 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
621 OptimizerLastEPCallbacks;
622 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
623 FullLinkTimeOptimizationEarlyEPCallbacks;
624 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
625 FullLinkTimeOptimizationLastEPCallbacks;
626 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
627 PipelineStartEPCallbacks;
628 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
629 PipelineEarlySimplificationEPCallbacks;
630
631 SmallVector<std::function<void(ModuleAnalysisManager &)>, 2>
632 ModuleAnalysisRegistrationCallbacks;
635 2>
636 ModulePipelineParsingCallbacks;
639 TopLevelPipelineParsingCallbacks;
640 // CGSCC callbacks
641 SmallVector<std::function<void(CGSCCAnalysisManager &)>, 2>
642 CGSCCAnalysisRegistrationCallbacks;
645 2>
646 CGSCCPipelineParsingCallbacks;
647 // Function callbacks
648 SmallVector<std::function<void(FunctionAnalysisManager &)>, 2>
649 FunctionAnalysisRegistrationCallbacks;
652 2>
653 FunctionPipelineParsingCallbacks;
654 // Loop callbacks
655 SmallVector<std::function<void(LoopAnalysisManager &)>, 2>
656 LoopAnalysisRegistrationCallbacks;
657 SmallVector<std::function<bool(StringRef, LoopPassManager &,
659 2>
660 LoopPipelineParsingCallbacks;
661 // AA callbacks
662 SmallVector<std::function<bool(StringRef Name, AAManager &AA)>, 2>
663 AAParsingCallbacks;
664};
665
666/// This utility template takes care of adding require<> and invalidate<>
667/// passes for an analysis to a given \c PassManager. It is intended to be used
668/// during parsing of a pass pipeline when parsing a single PipelineName.
669/// When registering a new function analysis FancyAnalysis with the pass
670/// pipeline name "fancy-analysis", a matching ParsePipelineCallback could look
671/// like this:
672///
673/// static bool parseFunctionPipeline(StringRef Name, FunctionPassManager &FPM,
674/// ArrayRef<PipelineElement> P) {
675/// if (parseAnalysisUtilityPasses<FancyAnalysis>("fancy-analysis", Name,
676/// FPM))
677/// return true;
678/// return false;
679/// }
680template <typename AnalysisT, typename IRUnitT, typename AnalysisManagerT,
681 typename... ExtraArgTs>
683 StringRef AnalysisName, StringRef PipelineName,
685 if (!PipelineName.endswith(">"))
686 return false;
687 // See if this is an invalidate<> pass name
688 if (PipelineName.startswith("invalidate<")) {
689 PipelineName = PipelineName.substr(11, PipelineName.size() - 12);
690 if (PipelineName != AnalysisName)
691 return false;
693 return true;
694 }
695
696 // See if this is a require<> pass name
697 if (PipelineName.startswith("require<")) {
698 PipelineName = PipelineName.substr(8, PipelineName.size() - 9);
699 if (PipelineName != AnalysisName)
700 return false;
701 PM.addPass(RequireAnalysisPass<AnalysisT, IRUnitT, AnalysisManagerT,
702 ExtraArgTs...>());
703 return true;
704 }
705
706 return false;
707}
708}
709
710#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
@ Text
Definition: TextStubV5.cpp:112
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:156
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
Module pass, wrapping the inliner pass.
Definition: Inliner.h:67
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:100
ModulePassManager buildO0DefaultPipeline(OptimizationLevel Level, bool LTOPreLink=false)
Build an O0 pipeline with the minimal semantically required passes.
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 registerPipelineEarlySimplificationEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:452
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, ModulePassManager &, ArrayRef< PipelineElement >)> &C)
Definition: PassBuilder.h:540
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.
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:515
void registerPipelineStartEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:443
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, LoopPassManager &, ArrayRef< PipelineElement >)> &C)
Definition: PassBuilder.h:535
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
PassInstrumentationCallbacks * getPassInstrumentationCallbacks() const
Returns PIC.
Definition: PassBuilder.h:564
void registerLateLoopOptimizationsEPCallback(const std::function< void(LoopPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:391
void registerLoopOptimizerEndEPCallback(const std::function< void(LoopPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:401
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:495
void registerOptimizerLastEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:470
void registerVectorizerStartEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:433
void registerAnalysisRegistrationCallback(const std::function< void(LoopAnalysisManager &)> &C)
Definition: PassBuilder.h:511
void registerPeepholeEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:377
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:507
void registerScalarOptimizerLateEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:411
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:503
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:422
Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText)
Parse a textual pass pipeline description into a ModulePassManager.
void registerOptimizerEarlyEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:461
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:525
void registerFullLinkTimeOptimizationEarlyEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:479
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, FunctionPassManager &, ArrayRef< PipelineElement >)> &C)
Definition: PassBuilder.h:530
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
void addPGOInstrPassesForO0(ModulePassManager &MPM, bool RunProfileGen, bool IsCS, std::string ProfileFile, std::string ProfileRemappingFile, IntrusiveRefCntPtr< vfs::FileSystem > FS)
Add PGOInstrumenation passes for O0 only.
void registerFullLinkTimeOptimizationLastEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:488
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
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.
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:82
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:79
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:558
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:277
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:682
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.
Definition: Pass.h:73
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:115
std::vector< PipelineElement > InnerPipeline
Definition: PassBuilder.h:117
A utility pass template to force an analysis result to be available.
Definition: PassManager.h:1245