LLVM  3.7.0
PassBuilder.h
Go to the documentation of this file.
1 //===- Parsing, selection, and construction of pass pipelines --*- C++ -*--===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 ///
11 /// Interfaces for registering analysis passes, producing common pass manager
12 /// configurations, and parsing of pass pipelines.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_PASSES_PASSBUILDER_H
17 #define LLVM_PASSES_PASSBUILDER_H
18 
19 #include "llvm/ADT/StringRef.h"
21 #include "llvm/IR/PassManager.h"
22 
23 namespace llvm {
24 class TargetMachine;
25 
26 /// \brief This class provides access to building LLVM's passes.
27 ///
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
31 /// construction.
32 class PassBuilder {
33  TargetMachine *TM;
34 
35 public:
36  explicit PassBuilder(TargetMachine *TM = nullptr) : TM(TM) {}
37 
38  /// \brief Registers all available module analysis passes.
39  ///
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.
44 
45  /// \brief Registers all available CGSCC analysis passes.
46  ///
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.
51 
52  /// \brief Registers all available function analysis passes.
53  ///
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.
58 
59  /// \brief Parse a textual pass pipeline description into a \c ModulePassManager.
60  ///
61  /// The format of the textual pass pipeline description looks something like:
62  ///
63  /// module(function(instcombine,sroa),dce,cgscc(inliner,function(...)),...)
64  ///
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:
71  ///
72  /// fpass1,fpass2,fpass3
73  /// cgpass1,cgpass2,cgpass3
74  /// lpass1,lpass2,lpass3
75  ///
76  /// And they are equivalent to the following (resp.):
77  ///
78  /// module(function(fpass1,fpass2,fpass3))
79  /// module(cgscc(cgpass1,cgpass2,cgpass3))
80  /// module(function(loop(lpass1,lpass2,lpass3)))
81  ///
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);
89 
90 private:
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,
96  bool DebugLogging);
97  bool parseCGSCCPassPipeline(CGSCCPassManager &CGPM, StringRef &PipelineText,
98  bool VerifyEachPass, bool DebugLogging);
99  bool parseModulePassPipeline(ModulePassManager &MPM, StringRef &PipelineText,
100  bool VerifyEachPass, bool DebugLogging);
101 };
102 
103 }
104 
105 #endif
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
Definition: PassBuilder.cpp:98
PassBuilder(TargetMachine *TM=nullptr)
Definition: PassBuilder.h:36
This class provides access to building LLVM's passes.
Definition: PassBuilder.h:32
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
bool parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText, bool VerifyEachPass=true, bool DebugLogging=false)
Parse a textual pass pipeline description into a ModulePassManager.
Manages a sequence of passes over units of IR.
Definition: PassManager.h:180
This header provides classes for managing passes over SCCs of the call graph.
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
Primary interface to the complete machine description for the target machine.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
A generic analysis pass manager with lazy running and caching of results.
This header defines various interfaces for pass management in LLVM.