blob: b24c615f85ff54f2257058f2db648c250f2c8b55 [file] [log] [blame]
Chandler Carruth1ff77242015-03-07 09:02:36 +00001//===- Parsing, selection, and construction of pass pipelines -------------===//
Chandler Carruth66445382014-01-11 08:16:35 +00002//
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///
Chandler Carruth1ff77242015-03-07 09:02:36 +000011/// This file provides the implementation of the PassBuilder based on our
12/// static pass registry as well as related functionality. It also provides
13/// helpers to aid in analyzing, debugging, and testing passes and pass
14/// pipelines.
Chandler Carruth66445382014-01-11 08:16:35 +000015///
16//===----------------------------------------------------------------------===//
17
Chandler Carruth1ff77242015-03-07 09:02:36 +000018#include "llvm/Passes/PassBuilder.h"
Chandler Carruthdf8b2232015-01-22 21:53:09 +000019#include "llvm/Analysis/AssumptionCache.h"
Chandler Carruth572e3402014-04-21 11:12:00 +000020#include "llvm/Analysis/CGSCCPassManager.h"
Chandler Carruthbf71a342014-02-06 04:37:03 +000021#include "llvm/Analysis/LazyCallGraph.h"
Chandler Carruthaaf0b4c2015-01-20 10:58:50 +000022#include "llvm/Analysis/LoopInfo.h"
Chandler Carruth2f1fd162015-08-17 02:08:17 +000023#include "llvm/Analysis/ScalarEvolution.h"
Chandler Carruth8ca43222015-01-15 11:39:46 +000024#include "llvm/Analysis/TargetLibraryInfo.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000025#include "llvm/Analysis/TargetTransformInfo.h"
Chandler Carruth64764b42015-01-14 10:19:28 +000026#include "llvm/IR/Dominators.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000027#include "llvm/IR/IRPrintingPasses.h"
Chandler Carruth66445382014-01-11 08:16:35 +000028#include "llvm/IR/PassManager.h"
Chandler Carruth4d356312014-01-20 11:34:08 +000029#include "llvm/IR/Verifier.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000030#include "llvm/Support/Debug.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000031#include "llvm/Target/TargetMachine.h"
Chandler Carruth83ba2692015-01-24 04:19:17 +000032#include "llvm/Transforms/InstCombine/InstCombine.h"
Justin Bogner21e15372015-10-30 23:28:12 +000033#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
Justin Bogner19b67992015-10-30 23:13:18 +000034#include "llvm/Transforms/Scalar/ADCE.h"
Chandler Carruthe8c686a2015-02-01 10:51:23 +000035#include "llvm/Transforms/Scalar/EarlyCSE.h"
Chandler Carruth43e590e2015-01-24 11:13:02 +000036#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
Chandler Carruthfdffd872015-02-01 11:34:21 +000037#include "llvm/Transforms/Scalar/SimplifyCFG.h"
Chandler Carruth29a18a42015-09-12 09:09:14 +000038#include "llvm/Transforms/Scalar/SROA.h"
Chandler Carruth66445382014-01-11 08:16:35 +000039
40using namespace llvm;
41
42namespace {
43
Chandler Carruthd8330982014-01-12 09:34:22 +000044/// \brief No-op module pass which does nothing.
Chandler Carruth66445382014-01-11 08:16:35 +000045struct NoOpModulePass {
Chandler Carruthd174ce42015-01-05 02:47:05 +000046 PreservedAnalyses run(Module &M) { return PreservedAnalyses::all(); }
Chandler Carrutha13f27c2014-01-11 11:52:05 +000047 static StringRef name() { return "NoOpModulePass"; }
Chandler Carruth66445382014-01-11 08:16:35 +000048};
49
Chandler Carruth0b576b32015-01-06 02:50:06 +000050/// \brief No-op module analysis.
51struct NoOpModuleAnalysis {
52 struct Result {};
53 Result run(Module &) { return Result(); }
54 static StringRef name() { return "NoOpModuleAnalysis"; }
55 static void *ID() { return (void *)&PassID; }
56private:
57 static char PassID;
58};
59
60char NoOpModuleAnalysis::PassID;
61
Chandler Carruth572e3402014-04-21 11:12:00 +000062/// \brief No-op CGSCC pass which does nothing.
63struct NoOpCGSCCPass {
Chandler Carruthd174ce42015-01-05 02:47:05 +000064 PreservedAnalyses run(LazyCallGraph::SCC &C) {
Chandler Carruth572e3402014-04-21 11:12:00 +000065 return PreservedAnalyses::all();
66 }
67 static StringRef name() { return "NoOpCGSCCPass"; }
68};
69
Chandler Carruth0b576b32015-01-06 02:50:06 +000070/// \brief No-op CGSCC analysis.
71struct NoOpCGSCCAnalysis {
72 struct Result {};
73 Result run(LazyCallGraph::SCC &) { return Result(); }
74 static StringRef name() { return "NoOpCGSCCAnalysis"; }
75 static void *ID() { return (void *)&PassID; }
76private:
77 static char PassID;
78};
79
80char NoOpCGSCCAnalysis::PassID;
81
Chandler Carruthd8330982014-01-12 09:34:22 +000082/// \brief No-op function pass which does nothing.
83struct NoOpFunctionPass {
Chandler Carruthd174ce42015-01-05 02:47:05 +000084 PreservedAnalyses run(Function &F) { return PreservedAnalyses::all(); }
Chandler Carruthd8330982014-01-12 09:34:22 +000085 static StringRef name() { return "NoOpFunctionPass"; }
86};
87
Chandler Carruth0b576b32015-01-06 02:50:06 +000088/// \brief No-op function analysis.
89struct NoOpFunctionAnalysis {
90 struct Result {};
91 Result run(Function &) { return Result(); }
92 static StringRef name() { return "NoOpFunctionAnalysis"; }
93 static void *ID() { return (void *)&PassID; }
94private:
95 static char PassID;
96};
97
98char NoOpFunctionAnalysis::PassID;
99
Chandler Carruth66445382014-01-11 08:16:35 +0000100} // End anonymous namespace.
101
Chandler Carruth1ff77242015-03-07 09:02:36 +0000102void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
Chandler Carruthb70f6732015-01-06 02:21:37 +0000103#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
104 MAM.registerPass(CREATE_PASS);
105#include "PassRegistry.def"
106}
107
Chandler Carruth1ff77242015-03-07 09:02:36 +0000108void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
Chandler Carruthb70f6732015-01-06 02:21:37 +0000109#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
110 CGAM.registerPass(CREATE_PASS);
111#include "PassRegistry.def"
112}
113
Chandler Carruth1ff77242015-03-07 09:02:36 +0000114void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
Chandler Carruthb70f6732015-01-06 02:21:37 +0000115#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
116 FAM.registerPass(CREATE_PASS);
117#include "PassRegistry.def"
118}
119
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000120#ifndef NDEBUG
Chandler Carruth66445382014-01-11 08:16:35 +0000121static bool isModulePassName(StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000122#define MODULE_PASS(NAME, CREATE_PASS) if (Name == NAME) return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000123#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000124 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000125 return true;
126#include "PassRegistry.def"
127
Chandler Carruth66445382014-01-11 08:16:35 +0000128 return false;
129}
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000130#endif
Chandler Carruth66445382014-01-11 08:16:35 +0000131
Chandler Carruth572e3402014-04-21 11:12:00 +0000132static bool isCGSCCPassName(StringRef Name) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000133#define CGSCC_PASS(NAME, CREATE_PASS) if (Name == NAME) return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000134#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000135 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000136 return true;
137#include "PassRegistry.def"
138
Chandler Carruth572e3402014-04-21 11:12:00 +0000139 return false;
140}
141
Chandler Carruthd8330982014-01-12 09:34:22 +0000142static bool isFunctionPassName(StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000143#define FUNCTION_PASS(NAME, CREATE_PASS) if (Name == NAME) return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000144#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000145 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000146 return true;
147#include "PassRegistry.def"
148
Chandler Carruthd8330982014-01-12 09:34:22 +0000149 return false;
150}
151
Chandler Carruth1ff77242015-03-07 09:02:36 +0000152bool PassBuilder::parseModulePassName(ModulePassManager &MPM, StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000153#define MODULE_PASS(NAME, CREATE_PASS) \
154 if (Name == NAME) { \
155 MPM.addPass(CREATE_PASS); \
156 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000157 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000158#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
159 if (Name == "require<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000160 MPM.addPass(RequireAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000161 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000162 } \
163 if (Name == "invalidate<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000164 MPM.addPass(InvalidateAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000165 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000166 }
167#include "PassRegistry.def"
168
Chandler Carruth66445382014-01-11 08:16:35 +0000169 return false;
170}
171
Chandler Carruth1ff77242015-03-07 09:02:36 +0000172bool PassBuilder::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000173#define CGSCC_PASS(NAME, CREATE_PASS) \
174 if (Name == NAME) { \
175 CGPM.addPass(CREATE_PASS); \
176 return true; \
177 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000178#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
179 if (Name == "require<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000180 CGPM.addPass(RequireAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000181 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000182 } \
183 if (Name == "invalidate<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000184 CGPM.addPass(InvalidateAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000185 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000186 }
187#include "PassRegistry.def"
188
Chandler Carruth572e3402014-04-21 11:12:00 +0000189 return false;
190}
191
Chandler Carruth1ff77242015-03-07 09:02:36 +0000192bool PassBuilder::parseFunctionPassName(FunctionPassManager &FPM,
193 StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000194#define FUNCTION_PASS(NAME, CREATE_PASS) \
195 if (Name == NAME) { \
196 FPM.addPass(CREATE_PASS); \
197 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000198 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000199#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
200 if (Name == "require<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000201 FPM.addPass(RequireAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000202 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000203 } \
204 if (Name == "invalidate<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000205 FPM.addPass(InvalidateAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000206 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000207 }
208#include "PassRegistry.def"
209
Chandler Carruthd8330982014-01-12 09:34:22 +0000210 return false;
211}
212
Chandler Carruth1ff77242015-03-07 09:02:36 +0000213bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
214 StringRef &PipelineText,
215 bool VerifyEachPass,
216 bool DebugLogging) {
Chandler Carruthd8330982014-01-12 09:34:22 +0000217 for (;;) {
218 // Parse nested pass managers by recursing.
219 if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000220 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000221
222 // Parse the inner pipeline inte the nested manager.
223 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000224 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
225 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000226 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000227 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000228 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000229 PipelineText = PipelineText.substr(1);
230
231 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000232 FPM.addPass(std::move(NestedFPM));
Chandler Carruthd8330982014-01-12 09:34:22 +0000233 } else {
234 // Otherwise try to parse a pass name.
235 size_t End = PipelineText.find_first_of(",)");
236 if (!parseFunctionPassName(FPM, PipelineText.substr(0, End)))
237 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000238 if (VerifyEachPass)
239 FPM.addPass(VerifierPass());
Chandler Carruthd8330982014-01-12 09:34:22 +0000240
241 PipelineText = PipelineText.substr(End);
242 }
243
244 if (PipelineText.empty() || PipelineText[0] == ')')
245 return true;
246
247 assert(PipelineText[0] == ',');
248 PipelineText = PipelineText.substr(1);
249 }
250}
251
Chandler Carruth1ff77242015-03-07 09:02:36 +0000252bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
253 StringRef &PipelineText,
254 bool VerifyEachPass,
255 bool DebugLogging) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000256 for (;;) {
257 // Parse nested pass managers by recursing.
258 if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000259 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000260
261 // Parse the inner pipeline into the nested manager.
262 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000263 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
264 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000265 PipelineText.empty())
266 return false;
267 assert(PipelineText[0] == ')');
268 PipelineText = PipelineText.substr(1);
269
270 // Add the nested pass manager with the appropriate adaptor.
271 CGPM.addPass(std::move(NestedCGPM));
272 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000273 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000274
275 // Parse the inner pipeline inte the nested manager.
276 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000277 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
278 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000279 PipelineText.empty())
280 return false;
281 assert(PipelineText[0] == ')');
282 PipelineText = PipelineText.substr(1);
283
284 // Add the nested pass manager with the appropriate adaptor.
285 CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(NestedFPM)));
286 } else {
287 // Otherwise try to parse a pass name.
288 size_t End = PipelineText.find_first_of(",)");
289 if (!parseCGSCCPassName(CGPM, PipelineText.substr(0, End)))
290 return false;
291 // FIXME: No verifier support for CGSCC passes!
292
293 PipelineText = PipelineText.substr(End);
294 }
295
296 if (PipelineText.empty() || PipelineText[0] == ')')
297 return true;
298
299 assert(PipelineText[0] == ',');
300 PipelineText = PipelineText.substr(1);
301 }
302}
303
Chandler Carruth1ff77242015-03-07 09:02:36 +0000304bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
305 StringRef &PipelineText,
306 bool VerifyEachPass,
307 bool DebugLogging) {
Chandler Carruth66445382014-01-11 08:16:35 +0000308 for (;;) {
309 // Parse nested pass managers by recursing.
310 if (PipelineText.startswith("module(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000311 ModulePassManager NestedMPM(DebugLogging);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000312
313 // Parse the inner pipeline into the nested manager.
Chandler Carruth66445382014-01-11 08:16:35 +0000314 PipelineText = PipelineText.substr(strlen("module("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000315 if (!parseModulePassPipeline(NestedMPM, PipelineText, VerifyEachPass,
316 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000317 PipelineText.empty())
Chandler Carruth66445382014-01-11 08:16:35 +0000318 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000319 assert(PipelineText[0] == ')');
Chandler Carruth66445382014-01-11 08:16:35 +0000320 PipelineText = PipelineText.substr(1);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000321
322 // Now add the nested manager as a module pass.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000323 MPM.addPass(std::move(NestedMPM));
Chandler Carruth572e3402014-04-21 11:12:00 +0000324 } else if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000325 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000326
327 // Parse the inner pipeline inte the nested manager.
328 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000329 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
330 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000331 PipelineText.empty())
332 return false;
333 assert(PipelineText[0] == ')');
334 PipelineText = PipelineText.substr(1);
335
336 // Add the nested pass manager with the appropriate adaptor.
337 MPM.addPass(
338 createModuleToPostOrderCGSCCPassAdaptor(std::move(NestedCGPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000339 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000340 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000341
342 // Parse the inner pipeline inte the nested manager.
343 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000344 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
345 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000346 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000347 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000348 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000349 PipelineText = PipelineText.substr(1);
350
351 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000352 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(NestedFPM)));
Chandler Carruth66445382014-01-11 08:16:35 +0000353 } else {
354 // Otherwise try to parse a pass name.
355 size_t End = PipelineText.find_first_of(",)");
356 if (!parseModulePassName(MPM, PipelineText.substr(0, End)))
357 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000358 if (VerifyEachPass)
359 MPM.addPass(VerifierPass());
Chandler Carruth66445382014-01-11 08:16:35 +0000360
361 PipelineText = PipelineText.substr(End);
362 }
363
364 if (PipelineText.empty() || PipelineText[0] == ')')
365 return true;
366
367 assert(PipelineText[0] == ',');
368 PipelineText = PipelineText.substr(1);
369 }
370}
371
372// Primary pass pipeline description parsing routine.
373// FIXME: Should this routine accept a TargetMachine or require the caller to
374// pre-populate the analysis managers with target-specific stuff?
Chandler Carruth1ff77242015-03-07 09:02:36 +0000375bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
376 StringRef PipelineText, bool VerifyEachPass,
377 bool DebugLogging) {
Chandler Carruthea368f12015-01-06 08:37:58 +0000378 // By default, try to parse the pipeline as-if it were within an implicit
379 // 'module(...)' pass pipeline. If this will parse at all, it needs to
380 // consume the entire string.
Chandler Carruth14a759e2015-01-13 22:42:38 +0000381 if (parseModulePassPipeline(MPM, PipelineText, VerifyEachPass, DebugLogging))
Chandler Carruthea368f12015-01-06 08:37:58 +0000382 return PipelineText.empty();
Chandler Carruth66445382014-01-11 08:16:35 +0000383
Chandler Carruthea368f12015-01-06 08:37:58 +0000384 // This isn't parsable as a module pipeline, look for the end of a pass name
385 // and directly drop down to that layer.
Chandler Carruth6546cb62014-01-12 10:02:02 +0000386 StringRef FirstName =
387 PipelineText.substr(0, PipelineText.find_first_of(",)"));
Chandler Carruthea368f12015-01-06 08:37:58 +0000388 assert(!isModulePassName(FirstName) &&
389 "Already handled all module pipeline options.");
Chandler Carruth66445382014-01-11 08:16:35 +0000390
Chandler Carruthea368f12015-01-06 08:37:58 +0000391 // If this looks like a CGSCC pass, parse the whole thing as a CGSCC
392 // pipeline.
Chandler Carruth572e3402014-04-21 11:12:00 +0000393 if (isCGSCCPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000394 CGSCCPassManager CGPM(DebugLogging);
395 if (!parseCGSCCPassPipeline(CGPM, PipelineText, VerifyEachPass,
396 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000397 !PipelineText.empty())
398 return false;
399 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
400 return true;
401 }
402
Chandler Carruthea368f12015-01-06 08:37:58 +0000403 // Similarly, if this looks like a Function pass, parse the whole thing as
404 // a Function pipelien.
Chandler Carruthd8330982014-01-12 09:34:22 +0000405 if (isFunctionPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000406 FunctionPassManager FPM(DebugLogging);
407 if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass,
408 DebugLogging) ||
Chandler Carruth4d356312014-01-20 11:34:08 +0000409 !PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000410 return false;
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000411 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000412 return true;
413 }
Chandler Carruth66445382014-01-11 08:16:35 +0000414
415 return false;
416}