[PM] Refactor the analysis registration and pass pipeline parsing to
[oota-llvm.git] / tools / opt / Passes.h
1 //===- Passes.h - Utilities for manipulating all passes ---------*- 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 passes, producing common pass manager
12 /// configurations, and parsing of pass pipelines.
13 ///
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_TOOLS_OPT_PASSES_H
17 #define LLVM_TOOLS_OPT_PASSES_H
18
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Analysis/CGSCCPassManager.h"
21 #include "llvm/IR/PassManager.h"
22
23 namespace llvm {
24
25 /// \brief This class provides access to all of LLVM's passes.
26 ///
27 /// It's members provide the baseline state available to passes during their
28 /// construction. The \c PassRegistry.def file specifies how to construct all
29 /// of the built-in passes, and those may reference these members during
30 /// construction.
31 class Passes {
32 public:
33   /// \brief Registers all available module analysis passes.
34   ///
35   /// This is an interface that can be used to populate a \c
36   /// ModuleAnalysisManager with all registered module analyses. Callers can
37   /// still manually register any additional analyses.
38   void registerModuleAnalyses(ModuleAnalysisManager &MAM);
39
40   /// \brief Registers all available CGSCC analysis passes.
41   ///
42   /// This is an interface that can be used to populate a \c CGSCCAnalysisManager
43   /// with all registered CGSCC analyses. Callers can still manually register any
44   /// additional analyses.
45   void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM);
46
47   /// \brief Registers all available function analysis passes.
48   ///
49   /// This is an interface that can be used to populate a \c
50   /// FunctionAnalysisManager with all registered function analyses. Callers can
51   /// still manually register any additional analyses.
52   void registerFunctionAnalyses(FunctionAnalysisManager &FAM);
53
54   /// \brief Parse a textual pass pipeline description into a \c ModulePassManager.
55   ///
56   /// The format of the textual pass pipeline description looks something like:
57   ///
58   ///   module(function(instcombine,sroa),dce,cgscc(inliner,function(...)),...)
59   ///
60   /// Pass managers have ()s describing the nest structure of passes. All passes
61   /// are comma separated. As a special shortcut, if the very first pass is not
62   /// a module pass (as a module pass manager is), this will automatically form
63   /// the shortest stack of pass managers that allow inserting that first pass.
64   /// So, assuming function passes 'fpassN', CGSCC passes 'cgpassN', and loop passes
65   /// 'lpassN', all of these are valid:
66   ///
67   ///   fpass1,fpass2,fpass3
68   ///   cgpass1,cgpass2,cgpass3
69   ///   lpass1,lpass2,lpass3
70   ///
71   /// And they are equivalent to the following (resp.):
72   ///
73   ///   module(function(fpass1,fpass2,fpass3))
74   ///   module(cgscc(cgpass1,cgpass2,cgpass3))
75   ///   module(function(loop(lpass1,lpass2,lpass3)))
76   ///
77   /// This shortcut is especially useful for debugging and testing small pass
78   /// combinations. Note that these shortcuts don't introduce any other magic. If
79   /// the sequence of passes aren't all the exact same kind of pass, it will be
80   /// an error. You cannot mix different levels implicitly, you must explicitly
81   /// form a pass manager in which to nest passes.
82   bool parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
83                          bool VerifyEachPass = true, bool DebugLogging = false);
84
85 private:
86   bool parseModulePassName(ModulePassManager &MPM, StringRef Name);
87   bool parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name);
88   bool parseFunctionPassName(FunctionPassManager &FPM, StringRef Name);
89   bool parseFunctionPassPipeline(FunctionPassManager &FPM,
90                                  StringRef &PipelineText, bool VerifyEachPass,
91                                  bool DebugLogging);
92   bool parseCGSCCPassPipeline(CGSCCPassManager &CGPM, StringRef &PipelineText,
93                               bool VerifyEachPass, bool DebugLogging);
94   bool parseModulePassPipeline(ModulePassManager &MPM, StringRef &PipelineText,
95                                bool VerifyEachPass, bool DebugLogging);
96 };
97
98 }
99
100 #endif