14c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar//===- Parsing, selection, and construction of pass pipelines --*- C++ -*--===//
236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//
336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//                     The LLVM Compiler Infrastructure
436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//
536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// This file is distributed under the University of Illinois Open Source
636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// License. See LICENSE.TXT for details.
736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//
836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//===----------------------------------------------------------------------===//
936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines/// \file
1036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines///
114c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar/// Interfaces for registering analysis passes, producing common pass manager
12ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines/// configurations, and parsing of pass pipelines.
1336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines///
1436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//===----------------------------------------------------------------------===//
1536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
164c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar#ifndef LLVM_PASSES_PASSBUILDER_H
174c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar#define LLVM_PASSES_PASSBUILDER_H
1836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
19ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines#include "llvm/Analysis/CGSCCPassManager.h"
20de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar#include "llvm/Analysis/LoopPassManager.h"
21ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines#include "llvm/IR/PassManager.h"
2236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
2336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesnamespace llvm {
24de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainarclass StringRef;
25de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainarclass AAManager;
26ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesclass TargetMachine;
2736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
284c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar/// \brief This class provides access to building LLVM's passes.
2936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines///
30ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines/// It's members provide the baseline state available to passes during their
31ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines/// construction. The \c PassRegistry.def file specifies how to construct all
32ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines/// of the built-in passes, and those may reference these members during
33ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines/// construction.
344c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainarclass PassBuilder {
35ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  TargetMachine *TM;
36ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
37ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinespublic:
38de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// \brief LLVM-provided high-level optimization levels.
39de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  ///
40de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// This enumerates the LLVM-provided high-level optimization levels. Each
41de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// level has a specific goal and rationale.
42de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  enum OptimizationLevel {
43de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// Disable as many optimizations as possible. This doesn't completely
44de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// disable the optimizer in many cases as there are correctness issues
45de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// such as always_inline functions.
46de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    O0,
47de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar
48de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// Optimize quickly without destroying debuggability.
49de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    ///
50de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// FIXME: The current and historical behavior of this level does *not*
51de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// agree with this goal, but we would like to move toward this goal in the
52de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// future.
53de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    ///
54de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// This level is tuned to produce a result from the optimizer as quickly
55de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// as possible and to avoid destroying debuggability. This tends to result
56de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// in a very good development mode where the compiled code will be
57de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// immediately executed as part of testing. As a consequence, where
58de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// possible, we would like to produce efficient-to-execute code, but not
59de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// if it significantly slows down compilation or would prevent even basic
60de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// debugging of the resulting binary.
61de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    ///
62de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// As an example, complex loop transformations such as versioning,
63de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// vectorization, or fusion might not make sense here due to the degree to
64de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// which the executed code would differ from the source code, and the
65de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// potential compile time cost.
66de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    O1,
67de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar
68de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// Optimize for fast execution as much as possible without triggering
69de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// significant incremental compile time or code size growth.
70de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    ///
71de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// The key idea is that optimizations at this level should "pay for
72de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// themselves". So if an optimization increases compile time by 5% or
73de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// increases code size by 5% for a particular benchmark, that benchmark
74de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// should also be one which sees a 5% runtime improvement. If the compile
75de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// time or code size penalties happen on average across a diverse range of
76de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// LLVM users' benchmarks, then the improvements should as well.
77de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    ///
78de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// And no matter what, the compile time needs to not grow superlinearly
79de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// with the size of input to LLVM so that users can control the runtime of
80de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// the optimizer in this mode.
81de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    ///
82de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// This is expected to be a good default optimization level for the vast
83de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// majority of users.
84de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    O2,
85de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar
86de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// Optimize for fast execution as much as possible.
87de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    ///
88de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// This mode is significantly more aggressive in trading off compile time
89de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// and code size to get execution time improvements. The core idea is that
90de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// this mode should include any optimization that helps execution time on
91de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// balance across a diverse collection of benchmarks, even if it increases
92de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// code size or compile time for some benchmarks without corresponding
93de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// improvements to execution time.
94de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    ///
95de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// Despite being willing to trade more compile time off to get improved
96de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// execution time, this mode still tries to avoid superlinear growth in
97de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// order to make even significantly slower compile times at least scale
98de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// reasonably. This does not preclude very substantial constant factor
99de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// costs though.
100de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    O3,
101de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar
102de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// Similar to \c O2 but tries to optimize for small code size instead of
103de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// fast execution without triggering significant incremental execution
104de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// time slowdowns.
105de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    ///
106de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// The logic here is exactly the same as \c O2, but with code size and
107de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// execution time metrics swapped.
108de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    ///
109de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// A consequence of the different core goal is that this should in general
110de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// produce substantially smaller executables that still run in
111de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// a reasonable amount of time.
112de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    Os,
113de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar
114de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// A very specialized mode that will optimize for code size at any and all
115de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// costs.
116de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    ///
117de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// This is useful primarily when there are absolute size limitations and
118de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// any effort taken to reduce the size is worth it regardless of the
119de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// execution time impact. You should expect this level to produce rather
120de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    /// slow, but very small, code.
121de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar    Oz
122de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  };
123de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar
1244c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar  explicit PassBuilder(TargetMachine *TM = nullptr) : TM(TM) {}
125ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
126de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// \brief Cross register the analysis managers through their proxies.
127de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  ///
128de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// This is an interface that can be used to cross register each
129de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  // AnalysisManager with all the others analysis managers.
130de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  void crossRegisterProxies(LoopAnalysisManager &LAM,
131de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar                            FunctionAnalysisManager &FAM,
132de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar                            CGSCCAnalysisManager &CGAM,
133de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar                            ModuleAnalysisManager &MAM);
134de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar
135ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// \brief Registers all available module analysis passes.
136ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///
137ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// This is an interface that can be used to populate a \c
138ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// ModuleAnalysisManager with all registered module analyses. Callers can
139de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// still manually register any additional analyses. Callers can also
140de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// pre-register analyses and this will not override those.
141ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  void registerModuleAnalyses(ModuleAnalysisManager &MAM);
142ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
143ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// \brief Registers all available CGSCC analysis passes.
144ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///
145ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// This is an interface that can be used to populate a \c CGSCCAnalysisManager
146ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// with all registered CGSCC analyses. Callers can still manually register any
147de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// additional analyses. Callers can also pre-register analyses and this will
148de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// not override those.
149ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM);
150ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
151ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// \brief Registers all available function analysis passes.
152ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///
153ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// This is an interface that can be used to populate a \c
154ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// FunctionAnalysisManager with all registered function analyses. Callers can
155de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// still manually register any additional analyses. Callers can also
156de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// pre-register analyses and this will not override those.
157ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  void registerFunctionAnalyses(FunctionAnalysisManager &FAM);
158ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
159de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// \brief Registers all available loop analysis passes.
160de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  ///
161de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// This is an interface that can be used to populate a \c LoopAnalysisManager
162de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// with all registered loop analyses. Callers can still manually register any
163de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// additional analyses.
164de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  void registerLoopAnalyses(LoopAnalysisManager &LAM);
165de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar
166de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// \brief Add a per-module default optimization pipeline to a pass manager.
167de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  ///
168de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// This provides a good default optimization pipeline for per-module
169de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// optimization and code generation without any link-time optimization. It
170de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// typically correspond to frontend "-O[123]" options for optimization
171de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// levels \c O1, \c O2 and \c O3 resp.
172de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  void addPerModuleDefaultPipeline(ModulePassManager &MPM,
173de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar                                   OptimizationLevel Level,
174de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar                                   bool DebugLogging = false);
175de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar
176de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// \brief Add a pre-link, LTO-targeting default optimization pipeline to
177de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// a pass manager.
178de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  ///
179de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// This adds the pre-link optimizations tuned to work well with a later LTO
180de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// run. It works to minimize the IR which needs to be analyzed without
181de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// making irreversible decisions which could be made better during the LTO
182de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// run.
183de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  void addLTOPreLinkDefaultPipeline(ModulePassManager &MPM,
184de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar                                    OptimizationLevel Level,
185de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar                                    bool DebugLogging = false);
186de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar
187de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// \brief Add an LTO default optimization pipeline to a pass manager.
188de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  ///
189de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// This provides a good default optimization pipeline for link-time
190de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// optimization and code generation. It is particularly tuned to fit well
191de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// when IR coming into the LTO phase was first run through \c
192de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// addPreLinkLTODefaultPipeline, and the two coordinate closely.
193de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  void addLTODefaultPipeline(ModulePassManager &MPM, OptimizationLevel Level,
194de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar                             bool DebugLogging = false);
195de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar
196ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// \brief Parse a textual pass pipeline description into a \c ModulePassManager.
197ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///
198ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// The format of the textual pass pipeline description looks something like:
199ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///
200ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///   module(function(instcombine,sroa),dce,cgscc(inliner,function(...)),...)
201ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///
202ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// Pass managers have ()s describing the nest structure of passes. All passes
203ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// are comma separated. As a special shortcut, if the very first pass is not
204ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// a module pass (as a module pass manager is), this will automatically form
205ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// the shortest stack of pass managers that allow inserting that first pass.
206ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// So, assuming function passes 'fpassN', CGSCC passes 'cgpassN', and loop passes
207ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// 'lpassN', all of these are valid:
208ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///
209ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///   fpass1,fpass2,fpass3
210ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///   cgpass1,cgpass2,cgpass3
211ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///   lpass1,lpass2,lpass3
212ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///
213ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// And they are equivalent to the following (resp.):
214ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///
215ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///   module(function(fpass1,fpass2,fpass3))
216ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///   module(cgscc(cgpass1,cgpass2,cgpass3))
217ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///   module(function(loop(lpass1,lpass2,lpass3)))
218ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  ///
219ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// This shortcut is especially useful for debugging and testing small pass
220ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// combinations. Note that these shortcuts don't introduce any other magic. If
221ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// the sequence of passes aren't all the exact same kind of pass, it will be
222ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// an error. You cannot mix different levels implicitly, you must explicitly
223ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  /// form a pass manager in which to nest passes.
224ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  bool parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
225ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines                         bool VerifyEachPass = true, bool DebugLogging = false);
226ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
227de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// Parse a textual alias analysis pipeline into the provided AA manager.
228de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  ///
229de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// The format of the textual AA pipeline is a comma separated list of AA
230de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// pass names:
231de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  ///
232de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  ///   basic-aa,globals-aa,...
233de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  ///
234de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// The AA manager is set up such that the provided alias analyses are tried
235de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// in the order specified. See the \c AAManaager documentation for details
236de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// about the logic used. This routine just provides the textual mapping
237de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// between AA names and the analyses to register with the manager.
238de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  ///
239de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// Returns false if the text cannot be parsed cleanly. The specific state of
240de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// the \p AA manager is unspecified if such an error is encountered and this
241de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  /// returns false.
242de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  bool parseAAPipeline(AAManager &AA, StringRef PipelineText);
243de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar
244ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesprivate:
245de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  bool parseModulePassName(ModulePassManager &MPM, StringRef Name,
246de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar                           bool DebugLogging);
247ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  bool parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name);
248ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  bool parseFunctionPassName(FunctionPassManager &FPM, StringRef Name);
249de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  bool parseLoopPassName(LoopPassManager &LPM, StringRef Name);
250de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  bool parseAAPassName(AAManager &AA, StringRef Name);
251de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar  bool parseLoopPassPipeline(LoopPassManager &LPM, StringRef &PipelineText,
252de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar                             bool VerifyEachPass, bool DebugLogging);
253ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  bool parseFunctionPassPipeline(FunctionPassManager &FPM,
254ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines                                 StringRef &PipelineText, bool VerifyEachPass,
255ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines                                 bool DebugLogging);
256ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  bool parseCGSCCPassPipeline(CGSCCPassManager &CGPM, StringRef &PipelineText,
257ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines                              bool VerifyEachPass, bool DebugLogging);
258ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  bool parseModulePassPipeline(ModulePassManager &MPM, StringRef &PipelineText,
259ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines                               bool VerifyEachPass, bool DebugLogging);
260ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines};
26136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
26236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
26336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#endif
264