LLVM 19.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
20#include "llvm/IR/PassManager.h"
22#include "llvm/Support/Error.h"
29#include <vector>
30
31namespace llvm {
32class StringRef;
33class AAManager;
34class TargetMachine;
35class ModuleSummaryIndex;
36template <typename T> class IntrusiveRefCntPtr;
37namespace vfs {
38class FileSystem;
39} // namespace vfs
40
41/// Tunable parameters for passes in the default pipelines.
43public:
44 /// Constructor sets pipeline tuning defaults based on cl::opts. Each option
45 /// can be set in the PassBuilder when using a LLVM as a library.
47
48 /// Tuning option to set loop interleaving on/off, set based on opt level.
50
51 /// Tuning option to enable/disable loop vectorization, set based on opt
52 /// level.
54
55 /// Tuning option to enable/disable slp loop vectorization, set based on opt
56 /// level.
58
59 /// Tuning option to enable/disable loop unrolling. Its default value is true.
61
62 /// Tuning option to forget all SCEV loops in LoopUnroll. Its default value
63 /// is that of the flag: `-forget-scev-loop-unroll`.
65
66 /// Tuning option to cap the number of calls to retrive clobbering accesses in
67 /// MemorySSA, in LICM.
69
70 /// Tuning option to disable promotion to scalars in LICM with MemorySSA, if
71 /// the number of access is too large.
73
74 /// Tuning option to enable/disable call graph profile. Its default value is
75 /// that of the flag: `-enable-npm-call-graph-profile`.
77
78 // Add LTO pipeline tuning option to enable the unified LTO pipeline.
80
81 /// Tuning option to enable/disable function merging. Its default value is
82 /// false.
84
85 /// Tuning option to override the default inliner threshold.
87
88 // Experimental option to eagerly invalidate more analyses. This has the
89 // potential to decrease max memory usage in exchange for more compile time.
90 // This may affect codegen due to either passes using analyses only when
91 // cached, or invalidating and recalculating an analysis that was
92 // stale/imprecise but still valid. Currently this invalidates all function
93 // analyses after various module->function or cgscc->function adaptors in the
94 // default pipelines.
96};
97
98/// This class provides access to building LLVM's passes.
99///
100/// Its members provide the baseline state available to passes during their
101/// construction. The \c PassRegistry.def file specifies how to construct all
102/// of the built-in passes, and those may reference these members during
103/// construction.
105 TargetMachine *TM;
107 std::optional<PGOOptions> PGOOpt;
109
110public:
111 /// A struct to capture parsed pass pipeline names.
112 ///
113 /// A pipeline is defined as a series of names, each of which may in itself
114 /// recursively contain a nested pipeline. A name is either the name of a pass
115 /// (e.g. "instcombine") or the name of a pipeline type (e.g. "cgscc"). If the
116 /// name is the name of a pass, the InnerPipeline is empty, since passes
117 /// cannot contain inner pipelines. See parsePassPipeline() for a more
118 /// detailed description of the textual pipeline format.
121 std::vector<PipelineElement> InnerPipeline;
122 };
123
124 explicit PassBuilder(TargetMachine *TM = nullptr,
126 std::optional<PGOOptions> PGOOpt = std::nullopt,
127 PassInstrumentationCallbacks *PIC = nullptr);
128
129 /// Cross register the analysis managers through their proxies.
130 ///
131 /// This is an interface that can be used to cross register each
132 /// AnalysisManager with all the others analysis managers.
137
138 /// Registers all available module analysis passes.
139 ///
140 /// This is an interface that can be used to populate a \c
141 /// ModuleAnalysisManager with all registered module analyses. Callers can
142 /// still manually register any additional analyses. Callers can also
143 /// pre-register analyses and this will not override those.
145
146 /// Registers all available CGSCC analysis passes.
147 ///
148 /// This is an interface that can be used to populate a \c CGSCCAnalysisManager
149 /// with all registered CGSCC analyses. Callers can still manually register any
150 /// additional analyses. Callers can also pre-register analyses and this will
151 /// not override those.
153
154 /// Registers all available function analysis passes.
155 ///
156 /// This is an interface that can be used to populate a \c
157 /// FunctionAnalysisManager with all registered function analyses. Callers can
158 /// still manually register any additional analyses. Callers can also
159 /// pre-register analyses and this will not override those.
161
162 /// Registers all available loop analysis passes.
163 ///
164 /// This is an interface that can be used to populate a \c LoopAnalysisManager
165 /// with all registered loop analyses. Callers can still manually register any
166 /// additional analyses.
168
169 /// Registers all available machine function analysis passes.
170 ///
171 /// This is an interface that can be used to populate a \c
172 /// MachineFunctionAnalysisManager with all registered function analyses.
173 /// Callers can still manually register any additional analyses. Callers can
174 /// also pre-register analyses and this will not override those.
176
177 /// Construct the core LLVM function canonicalization and simplification
178 /// pipeline.
179 ///
180 /// This is a long pipeline and uses most of the per-function optimization
181 /// passes in LLVM to canonicalize and simplify the IR. It is suitable to run
182 /// repeatedly over the IR and is not expected to destroy important
183 /// information about the semantics of the IR.
184 ///
185 /// Note that \p Level cannot be `O0` here. The pipelines produced are
186 /// only intended for use when attempting to optimize code. If frontends
187 /// require some transformations for semantic reasons, they should explicitly
188 /// build them.
189 ///
190 /// \p Phase indicates the current ThinLTO phase.
194
195 /// Construct the core LLVM module canonicalization and simplification
196 /// pipeline.
197 ///
198 /// This pipeline focuses on canonicalizing and simplifying the entire module
199 /// of IR. Much like the function simplification pipeline above, it is
200 /// suitable to run repeatedly over the IR and is not expected to destroy
201 /// important information. It does, however, perform inlining and other
202 /// heuristic based simplifications that are not strictly reversible.
203 ///
204 /// Note that \p Level cannot be `O0` here. The pipelines produced are
205 /// only intended for use when attempting to optimize code. If frontends
206 /// require some transformations for semantic reasons, they should explicitly
207 /// build them.
208 ///
209 /// \p Phase indicates the current ThinLTO phase.
212
213 /// Construct the module pipeline that performs inlining as well as
214 /// the inlining-driven cleanups.
217
218 /// Construct the module pipeline that performs inlining with
219 /// module inliner pass.
222
223 /// Construct the core LLVM module optimization pipeline.
224 ///
225 /// This pipeline focuses on optimizing the execution speed of the IR. It
226 /// uses cost modeling and thresholds to balance code growth against runtime
227 /// improvements. It includes vectorization and other information destroying
228 /// transformations. It also cannot generally be run repeatedly on a module
229 /// without potentially seriously regressing either runtime performance of
230 /// the code or serious code size growth.
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.
238 ThinOrFullLTOPhase LTOPhase);
239
240 /// Build a per-module default optimization pipeline.
241 ///
242 /// This provides a good default optimization pipeline for per-module
243 /// optimization and code generation without any link-time optimization. It
244 /// typically correspond to frontend "-O[123]" options for optimization
245 /// levels \c O1, \c O2 and \c O3 resp.
247 bool LTOPreLink = false);
248
249 /// Build a fat object default optimization pipeline.
250 ///
251 /// This builds a pipeline that runs the LTO/ThinLTO pre-link pipeline, and
252 /// emits a section containing the pre-link bitcode along side the object code
253 /// generated in non-LTO compilation.
255 bool ThinLTO, bool EmitSummary);
256
257 /// Build a pre-link, ThinLTO-targeting default optimization pipeline to
258 /// a pass manager.
259 ///
260 /// This adds the pre-link optimizations tuned to prepare a module for
261 /// a ThinLTO run. It works to minimize the IR which needs to be analyzed
262 /// without making irreversible decisions which could be made better during
263 /// the LTO run.
265
266 /// Build an ThinLTO default optimization pipeline to a pass manager.
267 ///
268 /// This provides a good default optimization pipeline for link-time
269 /// optimization and code generation. It is particularly tuned to fit well
270 /// when IR coming into the LTO phase was first run through \c
271 /// addPreLinkLTODefaultPipeline, and the two coordinate closely.
274 const ModuleSummaryIndex *ImportSummary);
275
276 /// Build a pre-link, LTO-targeting default optimization pipeline to a pass
277 /// manager.
278 ///
279 /// This adds the pre-link optimizations tuned to work well with a later LTO
280 /// run. It works to minimize the IR which needs to be analyzed without
281 /// making irreversible decisions which could be made better during the LTO
282 /// run.
284
285 /// Build an LTO default optimization pipeline to a pass manager.
286 ///
287 /// This provides a good default optimization pipeline for link-time
288 /// optimization and code generation. It is particularly tuned to fit well
289 /// when IR coming into the LTO phase was first run through \c
290 /// addPreLinkLTODefaultPipeline, and the two coordinate closely.
292 ModuleSummaryIndex *ExportSummary);
293
294 /// Build an O0 pipeline with the minimal semantically required passes.
295 ///
296 /// This should only be used for non-LTO and LTO pre-link pipelines.
298 bool LTOPreLink = false);
299
300 /// Build the default `AAManager` with the default alias analysis pipeline
301 /// registered.
302 ///
303 /// This also adds target-specific alias analyses registered via
304 /// TargetMachine::registerDefaultAliasAnalyses().
306
307 /// Parse a textual pass pipeline description into a \c
308 /// ModulePassManager.
309 ///
310 /// The format of the textual pass pipeline description looks something like:
311 ///
312 /// module(function(instcombine,sroa),dce,cgscc(inliner,function(...)),...)
313 ///
314 /// Pass managers have ()s describing the nest structure of passes. All passes
315 /// are comma separated. As a special shortcut, if the very first pass is not
316 /// a module pass (as a module pass manager is), this will automatically form
317 /// the shortest stack of pass managers that allow inserting that first pass.
318 /// So, assuming function passes 'fpassN', CGSCC passes 'cgpassN', and loop
319 /// passes 'lpassN', all of these are valid:
320 ///
321 /// fpass1,fpass2,fpass3
322 /// cgpass1,cgpass2,cgpass3
323 /// lpass1,lpass2,lpass3
324 ///
325 /// And they are equivalent to the following (resp.):
326 ///
327 /// module(function(fpass1,fpass2,fpass3))
328 /// module(cgscc(cgpass1,cgpass2,cgpass3))
329 /// module(function(loop(lpass1,lpass2,lpass3)))
330 ///
331 /// This shortcut is especially useful for debugging and testing small pass
332 /// combinations.
333 ///
334 /// The sequence of passes aren't necessarily the exact same kind of pass.
335 /// You can mix different levels implicitly if adaptor passes are defined to
336 /// make them work. For example,
337 ///
338 /// mpass1,fpass1,fpass2,mpass2,lpass1
339 ///
340 /// This pipeline uses only one pass manager: the top-level module manager.
341 /// fpass1,fpass2 and lpass1 are added into the top-level module manager
342 /// using only adaptor passes. No nested function/loop pass managers are
343 /// added. The purpose is to allow easy pass testing when the user
344 /// specifically want the pass to run under a adaptor directly. This is
345 /// preferred when a pipeline is largely of one type, but one or just a few
346 /// passes are of different types(See PassBuilder.cpp for examples).
348
349 /// {{@ Parse a textual pass pipeline description into a specific PassManager
350 ///
351 /// Automatic deduction of an appropriate pass manager stack is not supported.
352 /// For example, to insert a loop pass 'lpass' into a FunctionPassManager,
353 /// this is the valid pipeline text:
354 ///
355 /// function(lpass)
359 /// @}}
360
361 /// Parse a textual MIR pipeline into the provided \c MachineFunctionPass
362 /// manager.
363 /// The format of the textual machine pipeline is a comma separated list of
364 /// machine pass names:
365 ///
366 /// machine-funciton-pass,machine-module-pass,...
367 ///
368 /// There is no need to specify the pass nesting, and this function
369 /// currently cannot handle the pass nesting.
371 StringRef PipelineText);
372
373 /// Parse a textual alias analysis pipeline into the provided AA manager.
374 ///
375 /// The format of the textual AA pipeline is a comma separated list of AA
376 /// pass names:
377 ///
378 /// basic-aa,globals-aa,...
379 ///
380 /// The AA manager is set up such that the provided alias analyses are tried
381 /// in the order specified. See the \c AAManaager documentation for details
382 /// about the logic used. This routine just provides the textual mapping
383 /// between AA names and the analyses to register with the manager.
384 ///
385 /// Returns false if the text cannot be parsed cleanly. The specific state of
386 /// the \p AA manager is unspecified if such an error is encountered and this
387 /// returns false.
388 Error parseAAPipeline(AAManager &AA, StringRef PipelineText);
389
390 /// Print pass names.
392
393 /// Register a callback for a default optimizer pipeline extension
394 /// point
395 ///
396 /// This extension point allows adding passes that perform peephole
397 /// optimizations similar to the instruction combiner. These passes will be
398 /// inserted after each instance of the instruction combiner pass.
400 const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
401 PeepholeEPCallbacks.push_back(C);
402 }
403
404 /// Register a callback for a default optimizer pipeline extension
405 /// point
406 ///
407 /// This extension point allows adding late loop canonicalization and
408 /// simplification passes. This is the last point in the loop optimization
409 /// pipeline before loop deletion. Each pass added
410 /// here must be an instance of LoopPass.
411 /// This is the place to add passes that can remove loops, such as target-
412 /// specific loop idiom recognition.
414 const std::function<void(LoopPassManager &, OptimizationLevel)> &C) {
415 LateLoopOptimizationsEPCallbacks.push_back(C);
416 }
417
418 /// Register a callback for a default optimizer pipeline extension
419 /// point
420 ///
421 /// This extension point allows adding loop passes to the end of the loop
422 /// optimizer.
424 const std::function<void(LoopPassManager &, OptimizationLevel)> &C) {
425 LoopOptimizerEndEPCallbacks.push_back(C);
426 }
427
428 /// Register a callback for a default optimizer pipeline extension
429 /// point
430 ///
431 /// This extension point allows adding optimization passes after most of the
432 /// main optimizations, but before the last cleanup-ish optimizations.
434 const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
435 ScalarOptimizerLateEPCallbacks.push_back(C);
436 }
437
438 /// Register a callback for a default optimizer pipeline extension
439 /// point
440 ///
441 /// This extension point allows adding CallGraphSCC passes at the end of the
442 /// main CallGraphSCC passes and before any function simplification passes run
443 /// by CGPassManager.
445 const std::function<void(CGSCCPassManager &, OptimizationLevel)> &C) {
446 CGSCCOptimizerLateEPCallbacks.push_back(C);
447 }
448
449 /// Register a callback for a default optimizer pipeline extension
450 /// point
451 ///
452 /// This extension point allows adding optimization passes before the
453 /// vectorizer and other highly target specific optimization passes are
454 /// executed.
456 const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
457 VectorizerStartEPCallbacks.push_back(C);
458 }
459
460 /// Register a callback for a default optimizer pipeline extension point.
461 ///
462 /// This extension point allows adding optimization once at the start of the
463 /// pipeline. This does not apply to 'backend' compiles (LTO and ThinLTO
464 /// link-time pipelines).
466 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
467 PipelineStartEPCallbacks.push_back(C);
468 }
469
470 /// Register a callback for a default optimizer pipeline extension point.
471 ///
472 /// This extension point allows adding optimization right after passes that do
473 /// basic simplification of the input IR.
475 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
476 PipelineEarlySimplificationEPCallbacks.push_back(C);
477 }
478
479 /// Register a callback for a default optimizer pipeline extension point
480 ///
481 /// This extension point allows adding optimizations before the function
482 /// optimization pipeline.
484 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
485 OptimizerEarlyEPCallbacks.push_back(C);
486 }
487
488 /// Register a callback for a default optimizer pipeline extension point
489 ///
490 /// This extension point allows adding optimizations at the very end of the
491 /// function optimization pipeline.
493 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
494 OptimizerLastEPCallbacks.push_back(C);
495 }
496
497 /// Register a callback for a default optimizer pipeline extension point
498 ///
499 /// This extension point allows adding optimizations at the start of the full
500 /// LTO pipeline.
502 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
503 FullLinkTimeOptimizationEarlyEPCallbacks.push_back(C);
504 }
505
506 /// Register a callback for a default optimizer pipeline extension point
507 ///
508 /// This extension point allows adding optimizations at the end of the full
509 /// LTO pipeline.
511 const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
512 FullLinkTimeOptimizationLastEPCallbacks.push_back(C);
513 }
514
515 /// Register a callback for parsing an AliasAnalysis Name to populate
516 /// the given AAManager \p AA
518 const std::function<bool(StringRef Name, AAManager &AA)> &C) {
519 AAParsingCallbacks.push_back(C);
520 }
521
522 /// {{@ Register callbacks for analysis registration with this PassBuilder
523 /// instance.
524 /// Callees register their analyses with the given AnalysisManager objects.
526 const std::function<void(CGSCCAnalysisManager &)> &C) {
527 CGSCCAnalysisRegistrationCallbacks.push_back(C);
528 }
530 const std::function<void(FunctionAnalysisManager &)> &C) {
531 FunctionAnalysisRegistrationCallbacks.push_back(C);
532 }
534 const std::function<void(LoopAnalysisManager &)> &C) {
535 LoopAnalysisRegistrationCallbacks.push_back(C);
536 }
538 const std::function<void(ModuleAnalysisManager &)> &C) {
539 ModuleAnalysisRegistrationCallbacks.push_back(C);
540 }
542 const std::function<void(MachineFunctionAnalysisManager &)> &C) {
543 MachineFunctionAnalysisRegistrationCallbacks.push_back(C);
544 }
545 /// @}}
546
547 /// {{@ Register pipeline parsing callbacks with this pass builder instance.
548 /// Using these callbacks, callers can parse both a single pass name, as well
549 /// as entire sub-pipelines, and populate the PassManager instance
550 /// accordingly.
552 const std::function<bool(StringRef Name, CGSCCPassManager &,
554 CGSCCPipelineParsingCallbacks.push_back(C);
555 }
557 const std::function<bool(StringRef Name, FunctionPassManager &,
559 FunctionPipelineParsingCallbacks.push_back(C);
560 }
562 const std::function<bool(StringRef Name, LoopPassManager &,
564 LoopPipelineParsingCallbacks.push_back(C);
565 }
567 const std::function<bool(StringRef Name, ModulePassManager &,
569 ModulePipelineParsingCallbacks.push_back(C);
570 }
572 const std::function<bool(StringRef Name, MachineFunctionPassManager &)>
573 &C) {
574 MachinePipelineParsingCallbacks.push_back(C);
575 }
576 /// @}}
577
578 /// Register a callback for a top-level pipeline entry.
579 ///
580 /// If the PassManager type is not given at the top level of the pipeline
581 /// text, this Callback should be used to determine the appropriate stack of
582 /// PassManagers and populate the passed ModulePassManager.
584 const std::function<bool(ModulePassManager &, ArrayRef<PipelineElement>)>
585 &C);
586
587 /// Add PGOInstrumenation passes for O0 only.
588 void addPGOInstrPassesForO0(ModulePassManager &MPM, bool RunProfileGen,
589 bool IsCS, bool AtomicCounterUpdate,
590 std::string ProfileFile,
591 std::string ProfileRemappingFile,
593
594 /// Returns PIC. External libraries can use this to register pass
595 /// instrumentation callbacks.
597 return PIC;
598 }
599
600 // Invoke the callbacks registered for the various extension points.
601 // Custom pipelines should use these to invoke the callbacks registered
602 // by TargetMachines and other clients.
604 OptimizationLevel Level);
606 OptimizationLevel Level);
608 OptimizationLevel Level);
610 OptimizationLevel Level);
612 OptimizationLevel Level);
614 OptimizationLevel Level);
616 OptimizationLevel Level);
618 OptimizationLevel Level);
620 OptimizationLevel Level);
622 OptimizationLevel Level);
624 OptimizationLevel Level);
626 OptimizationLevel Level);
627
628private:
629 // O1 pass pipeline
631 buildO1FunctionSimplificationPipeline(OptimizationLevel Level,
633
634 void addRequiredLTOPreLinkPasses(ModulePassManager &MPM);
635
636 void addVectorPasses(OptimizationLevel Level, FunctionPassManager &FPM,
637 bool IsFullLTO);
638
639 static std::optional<std::vector<PipelineElement>>
640 parsePipelineText(StringRef Text);
641
642 Error parseModulePass(ModulePassManager &MPM, const PipelineElement &E);
643 Error parseCGSCCPass(CGSCCPassManager &CGPM, const PipelineElement &E);
644 Error parseFunctionPass(FunctionPassManager &FPM, const PipelineElement &E);
645 Error parseLoopPass(LoopPassManager &LPM, const PipelineElement &E);
646 Error parseMachinePass(MachineFunctionPassManager &MFPM,
647 const PipelineElement &E);
648 bool parseAAPassName(AAManager &AA, StringRef Name);
649
650 Error parseMachinePassPipeline(MachineFunctionPassManager &MFPM,
652 Error parseLoopPassPipeline(LoopPassManager &LPM,
654 Error parseFunctionPassPipeline(FunctionPassManager &FPM,
656 Error parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
658 Error parseModulePassPipeline(ModulePassManager &MPM,
660
661 // Adds passes to do pre-inlining and related cleanup passes before
662 // profile instrumentation/matching (to enable better context sensitivity),
663 // and for memprof to enable better matching with missing debug frames.
664 void addPreInlinerPasses(ModulePassManager &MPM, OptimizationLevel Level,
665 ThinOrFullLTOPhase LTOPhase);
666
667 void addPGOInstrPasses(ModulePassManager &MPM, OptimizationLevel Level,
668 bool RunProfileGen, bool IsCS,
669 bool AtomicCounterUpdate, std::string ProfileFile,
670 std::string ProfileRemappingFile,
672
673 // Extension Point callbacks
674 SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
675 PeepholeEPCallbacks;
676 SmallVector<std::function<void(LoopPassManager &, OptimizationLevel)>, 2>
677 LateLoopOptimizationsEPCallbacks;
678 SmallVector<std::function<void(LoopPassManager &, OptimizationLevel)>, 2>
679 LoopOptimizerEndEPCallbacks;
680 SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
681 ScalarOptimizerLateEPCallbacks;
682 SmallVector<std::function<void(CGSCCPassManager &, OptimizationLevel)>, 2>
683 CGSCCOptimizerLateEPCallbacks;
684 SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
685 VectorizerStartEPCallbacks;
686 // Module callbacks
687 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
688 OptimizerEarlyEPCallbacks;
689 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
690 OptimizerLastEPCallbacks;
691 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
692 FullLinkTimeOptimizationEarlyEPCallbacks;
693 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
694 FullLinkTimeOptimizationLastEPCallbacks;
695 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
696 PipelineStartEPCallbacks;
697 SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
698 PipelineEarlySimplificationEPCallbacks;
699
700 SmallVector<std::function<void(ModuleAnalysisManager &)>, 2>
701 ModuleAnalysisRegistrationCallbacks;
704 2>
705 ModulePipelineParsingCallbacks;
708 TopLevelPipelineParsingCallbacks;
709 // CGSCC callbacks
710 SmallVector<std::function<void(CGSCCAnalysisManager &)>, 2>
711 CGSCCAnalysisRegistrationCallbacks;
714 2>
715 CGSCCPipelineParsingCallbacks;
716 // Function callbacks
717 SmallVector<std::function<void(FunctionAnalysisManager &)>, 2>
718 FunctionAnalysisRegistrationCallbacks;
721 2>
722 FunctionPipelineParsingCallbacks;
723 // Loop callbacks
724 SmallVector<std::function<void(LoopAnalysisManager &)>, 2>
725 LoopAnalysisRegistrationCallbacks;
726 SmallVector<std::function<bool(StringRef, LoopPassManager &,
728 2>
729 LoopPipelineParsingCallbacks;
730 // AA callbacks
731 SmallVector<std::function<bool(StringRef Name, AAManager &AA)>, 2>
732 AAParsingCallbacks;
733 // Machine pass callbackcs
734 SmallVector<std::function<void(MachineFunctionAnalysisManager &)>, 2>
735 MachineFunctionAnalysisRegistrationCallbacks;
737 MachinePipelineParsingCallbacks;
738};
739
740/// This utility template takes care of adding require<> and invalidate<>
741/// passes for an analysis to a given \c PassManager. It is intended to be used
742/// during parsing of a pass pipeline when parsing a single PipelineName.
743/// When registering a new function analysis FancyAnalysis with the pass
744/// pipeline name "fancy-analysis", a matching ParsePipelineCallback could look
745/// like this:
746///
747/// static bool parseFunctionPipeline(StringRef Name, FunctionPassManager &FPM,
748/// ArrayRef<PipelineElement> P) {
749/// if (parseAnalysisUtilityPasses<FancyAnalysis>("fancy-analysis", Name,
750/// FPM))
751/// return true;
752/// return false;
753/// }
754template <typename AnalysisT, typename IRUnitT, typename AnalysisManagerT,
755 typename... ExtraArgTs>
757 StringRef AnalysisName, StringRef PipelineName,
759 if (!PipelineName.ends_with(">"))
760 return false;
761 // See if this is an invalidate<> pass name
762 if (PipelineName.starts_with("invalidate<")) {
763 PipelineName = PipelineName.substr(11, PipelineName.size() - 12);
764 if (PipelineName != AnalysisName)
765 return false;
767 return true;
768 }
769
770 // See if this is a require<> pass name
771 if (PipelineName.starts_with("require<")) {
772 PipelineName = PipelineName.substr(8, PipelineName.size() - 9);
773 if (PipelineName != AnalysisName)
774 return false;
775 PM.addPass(RequireAnalysisPass<AnalysisT, IRUnitT, AnalysisManagerT,
776 ExtraArgTs...>());
777 return true;
778 }
779
780 return false;
781}
782
783// These are special since they are only for testing purposes.
784
785/// No-op module pass which does nothing.
786struct NoOpModulePass : PassInfoMixin<NoOpModulePass> {
788 return PreservedAnalyses::all();
789 }
790};
791
792/// No-op module analysis.
793class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
795 static AnalysisKey Key;
796
797public:
798 struct Result {};
800};
801
802/// No-op CGSCC pass which does nothing.
803struct NoOpCGSCCPass : PassInfoMixin<NoOpCGSCCPass> {
806 return PreservedAnalyses::all();
807 }
808};
809
810/// No-op CGSCC analysis.
811class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
813 static AnalysisKey Key;
814
815public:
816 struct Result {};
818 return Result();
819 }
820};
821
822/// No-op function pass which does nothing.
823struct NoOpFunctionPass : PassInfoMixin<NoOpFunctionPass> {
825 return PreservedAnalyses::all();
826 }
827};
828
829/// No-op function analysis.
830class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
832 static AnalysisKey Key;
833
834public:
835 struct Result {};
837};
838
839/// No-op loop nest pass which does nothing.
840struct NoOpLoopNestPass : PassInfoMixin<NoOpLoopNestPass> {
843 return PreservedAnalyses::all();
844 }
845};
846
847/// No-op loop pass which does nothing.
848struct NoOpLoopPass : PassInfoMixin<NoOpLoopPass> {
851 return PreservedAnalyses::all();
852 }
853};
854
855/// No-op machine function pass which does nothing.
857 : public MachinePassInfoMixin<NoOpMachineFunctionPass> {
859 return PreservedAnalyses::all();
860 }
861};
862
863/// No-op loop analysis.
864class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
866 static AnalysisKey Key;
867
868public:
869 struct Result {};
871 return Result();
872 }
873};
874}
875
876#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.
#define F(x, y, z)
Definition: MD5.cpp:55
#define G(x, y, z)
Definition: MD5.cpp:56
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:348
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...
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
An SCC of the call graph.
A lazily constructed view of the call graph of a module.
This class represents a loop nest and can be used to query its properties.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:44
An AnalysisManager<MachineFunction> that also exposes IR analysis results.
MachineFunctionPassManager adds/removes below features to/from the base PassManager template instanti...
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...
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
No-op CGSCC analysis.
Definition: PassBuilder.h:811
Result run(LazyCallGraph::SCC &, CGSCCAnalysisManager &, LazyCallGraph &G)
Definition: PassBuilder.h:817
No-op function analysis.
Definition: PassBuilder.h:830
Result run(Function &, FunctionAnalysisManager &)
Definition: PassBuilder.h:836
No-op loop analysis.
Definition: PassBuilder.h:864
Result run(Loop &, LoopAnalysisManager &, LoopStandardAnalysisResults &)
Definition: PassBuilder.h:870
No-op module analysis.
Definition: PassBuilder.h:793
Result run(Module &, ModuleAnalysisManager &)
Definition: PassBuilder.h:799
This class provides access to building LLVM's passes.
Definition: PassBuilder.h:104
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 registerAnalysisRegistrationCallback(const std::function< void(MachineFunctionAnalysisManager &)> &C)
Definition: PassBuilder.h:541
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:474
void invokeVectorizerStartEPCallbacks(FunctionPassManager &FPM, OptimizationLevel Level)
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, ModulePassManager &, ArrayRef< PipelineElement >)> &C)
Definition: PassBuilder.h:566
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:537
void registerPipelineStartEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:465
void invokeScalarOptimizerLateEPCallbacks(FunctionPassManager &FPM, OptimizationLevel Level)
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, LoopPassManager &, ArrayRef< PipelineElement >)> &C)
Definition: PassBuilder.h:561
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
PassInstrumentationCallbacks * getPassInstrumentationCallbacks() const
Returns PIC.
Definition: PassBuilder.h:596
void registerLateLoopOptimizationsEPCallback(const std::function< void(LoopPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:413
void registerLoopOptimizerEndEPCallback(const std::function< void(LoopPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:423
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:517
void registerOptimizerLastEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:492
void registerVectorizerStartEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:455
void registerAnalysisRegistrationCallback(const std::function< void(LoopAnalysisManager &)> &C)
Definition: PassBuilder.h:533
void registerPeepholeEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:399
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:529
void registerScalarOptimizerLateEPCallback(const std::function< void(FunctionPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:433
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:525
void invokePipelineStartEPCallbacks(ModulePassManager &MPM, OptimizationLevel Level)
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, MachineFunctionPassManager &)> &C)
Definition: PassBuilder.h:571
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:444
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:483
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:551
void registerFullLinkTimeOptimizationEarlyEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:501
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:556
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:510
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.
void registerMachineFunctionAnalyses(MachineFunctionAnalysisManager &MFAM)
Registers all available machine function analysis passes.
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:273
Tunable parameters for passes in the default pipelines.
Definition: PassBuilder.h:42
unsigned LicmMssaNoAccForPromotionCap
Tuning option to disable promotion to scalars in LICM with MemorySSA, if the number of access is too ...
Definition: PassBuilder.h:72
bool SLPVectorization
Tuning option to enable/disable slp loop vectorization, set based on opt level.
Definition: PassBuilder.h:57
int InlinerThreshold
Tuning option to override the default inliner threshold.
Definition: PassBuilder.h:86
bool CallGraphProfile
Tuning option to enable/disable call graph profile.
Definition: PassBuilder.h:76
bool MergeFunctions
Tuning option to enable/disable function merging.
Definition: PassBuilder.h:83
bool ForgetAllSCEVInLoopUnroll
Tuning option to forget all SCEV loops in LoopUnroll.
Definition: PassBuilder.h:64
unsigned LicmMssaOptCap
Tuning option to cap the number of calls to retrive clobbering accesses in MemorySSA,...
Definition: PassBuilder.h:68
bool LoopInterleaving
Tuning option to set loop interleaving on/off, set based on opt level.
Definition: PassBuilder.h:49
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:60
bool LoopVectorization
Tuning option to enable/disable loop vectorization, set based on opt level.
Definition: PassBuilder.h:53
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:109
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:115
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
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:567
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:257
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
Definition: StringRef.h:271
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:756
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.
Definition: Pass.h:76
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:114
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:26
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
A no-op pass template which simply forces a specific analysis result to be invalidated.
Definition: PassManager.h:996
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
A CRTP mix-in that provides informational APIs needed for machine passes.
No-op CGSCC pass which does nothing.
Definition: PassBuilder.h:803
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &, LazyCallGraph &, CGSCCUpdateResult &UR)
Definition: PassBuilder.h:804
No-op function pass which does nothing.
Definition: PassBuilder.h:823
PreservedAnalyses run(Function &F, FunctionAnalysisManager &)
Definition: PassBuilder.h:824
No-op loop nest pass which does nothing.
Definition: PassBuilder.h:840
PreservedAnalyses run(LoopNest &L, LoopAnalysisManager &, LoopStandardAnalysisResults &, LPMUpdater &)
Definition: PassBuilder.h:841
No-op loop pass which does nothing.
Definition: PassBuilder.h:848
PreservedAnalyses run(Loop &L, LoopAnalysisManager &, LoopStandardAnalysisResults &, LPMUpdater &)
Definition: PassBuilder.h:849
No-op machine function pass which does nothing.
Definition: PassBuilder.h:857
PreservedAnalyses run(MachineFunction &, MachineFunctionAnalysisManager &)
Definition: PassBuilder.h:858
No-op module pass which does nothing.
Definition: PassBuilder.h:786
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
Definition: PassBuilder.h:787
A struct to capture parsed pass pipeline names.
Definition: PassBuilder.h:119
std::vector< PipelineElement > InnerPipeline
Definition: PassBuilder.h:121
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:91
A utility pass template to force an analysis result to be available.
Definition: PassManager.h:969