1 //===- Parsing, selection, and construction of pass pipelines --*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// Interfaces for registering analysis passes, producing common pass manager
12 /// configurations, and parsing of pass pipelines.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_PASSES_PASSBUILDER_H
17 #define LLVM_PASSES_PASSBUILDER_H
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Analysis/CGSCCPassManager.h"
21 #include "llvm/IR/PassManager.h"
26 /// \brief This class provides access to building LLVM's passes.
28 /// It's members provide the baseline state available to passes during their
29 /// construction. The \c PassRegistry.def file specifies how to construct all
30 /// of the built-in passes, and those may reference these members during
36 explicit PassBuilder(TargetMachine *TM = nullptr) : TM(TM) {}
38 /// \brief Registers all available module analysis passes.
40 /// This is an interface that can be used to populate a \c
41 /// ModuleAnalysisManager with all registered module analyses. Callers can
42 /// still manually register any additional analyses.
43 void registerModuleAnalyses(ModuleAnalysisManager &MAM);
45 /// \brief Registers all available CGSCC analysis passes.
47 /// This is an interface that can be used to populate a \c CGSCCAnalysisManager
48 /// with all registered CGSCC analyses. Callers can still manually register any
49 /// additional analyses.
50 void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM);
52 /// \brief Registers all available function analysis passes.
54 /// This is an interface that can be used to populate a \c
55 /// FunctionAnalysisManager with all registered function analyses. Callers can
56 /// still manually register any additional analyses.
57 void registerFunctionAnalyses(FunctionAnalysisManager &FAM);
59 /// \brief Parse a textual pass pipeline description into a \c ModulePassManager.
61 /// The format of the textual pass pipeline description looks something like:
63 /// module(function(instcombine,sroa),dce,cgscc(inliner,function(...)),...)
65 /// Pass managers have ()s describing the nest structure of passes. All passes
66 /// are comma separated. As a special shortcut, if the very first pass is not
67 /// a module pass (as a module pass manager is), this will automatically form
68 /// the shortest stack of pass managers that allow inserting that first pass.
69 /// So, assuming function passes 'fpassN', CGSCC passes 'cgpassN', and loop passes
70 /// 'lpassN', all of these are valid:
72 /// fpass1,fpass2,fpass3
73 /// cgpass1,cgpass2,cgpass3
74 /// lpass1,lpass2,lpass3
76 /// And they are equivalent to the following (resp.):
78 /// module(function(fpass1,fpass2,fpass3))
79 /// module(cgscc(cgpass1,cgpass2,cgpass3))
80 /// module(function(loop(lpass1,lpass2,lpass3)))
82 /// This shortcut is especially useful for debugging and testing small pass
83 /// combinations. Note that these shortcuts don't introduce any other magic. If
84 /// the sequence of passes aren't all the exact same kind of pass, it will be
85 /// an error. You cannot mix different levels implicitly, you must explicitly
86 /// form a pass manager in which to nest passes.
87 bool parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
88 bool VerifyEachPass = true, bool DebugLogging = false);
91 bool parseModulePassName(ModulePassManager &MPM, StringRef Name);
92 bool parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name);
93 bool parseFunctionPassName(FunctionPassManager &FPM, StringRef Name);
94 bool parseFunctionPassPipeline(FunctionPassManager &FPM,
95 StringRef &PipelineText, bool VerifyEachPass,
97 bool parseCGSCCPassPipeline(CGSCCPassManager &CGPM, StringRef &PipelineText,
98 bool VerifyEachPass, bool DebugLogging);
99 bool parseModulePassPipeline(ModulePassManager &MPM, StringRef &PipelineText,
100 bool VerifyEachPass, bool DebugLogging);