blob: ba7132050e9bdbc963aae138d48c1ce70141aed8 [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 Carruth8ca43222015-01-15 11:39:46 +000023#include "llvm/Analysis/TargetLibraryInfo.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000024#include "llvm/Analysis/TargetTransformInfo.h"
Chandler Carruth64764b42015-01-14 10:19:28 +000025#include "llvm/IR/Dominators.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000026#include "llvm/IR/IRPrintingPasses.h"
Chandler Carruth66445382014-01-11 08:16:35 +000027#include "llvm/IR/PassManager.h"
Chandler Carruth4d356312014-01-20 11:34:08 +000028#include "llvm/IR/Verifier.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000029#include "llvm/Support/Debug.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000030#include "llvm/Target/TargetMachine.h"
Chandler Carruth83ba2692015-01-24 04:19:17 +000031#include "llvm/Transforms/InstCombine/InstCombine.h"
Chandler Carruthe8c686a2015-02-01 10:51:23 +000032#include "llvm/Transforms/Scalar/EarlyCSE.h"
Chandler Carruth43e590e2015-01-24 11:13:02 +000033#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
Chandler Carruthfdffd872015-02-01 11:34:21 +000034#include "llvm/Transforms/Scalar/SimplifyCFG.h"
Chandler Carruth66445382014-01-11 08:16:35 +000035
36using namespace llvm;
37
38namespace {
39
Chandler Carruthd8330982014-01-12 09:34:22 +000040/// \brief No-op module pass which does nothing.
Chandler Carruth66445382014-01-11 08:16:35 +000041struct NoOpModulePass {
Chandler Carruthd174ce42015-01-05 02:47:05 +000042 PreservedAnalyses run(Module &M) { return PreservedAnalyses::all(); }
Chandler Carrutha13f27c2014-01-11 11:52:05 +000043 static StringRef name() { return "NoOpModulePass"; }
Chandler Carruth66445382014-01-11 08:16:35 +000044};
45
Chandler Carruth0b576b32015-01-06 02:50:06 +000046/// \brief No-op module analysis.
47struct NoOpModuleAnalysis {
48 struct Result {};
49 Result run(Module &) { return Result(); }
50 static StringRef name() { return "NoOpModuleAnalysis"; }
51 static void *ID() { return (void *)&PassID; }
52private:
53 static char PassID;
54};
55
56char NoOpModuleAnalysis::PassID;
57
Chandler Carruth572e3402014-04-21 11:12:00 +000058/// \brief No-op CGSCC pass which does nothing.
59struct NoOpCGSCCPass {
Chandler Carruthd174ce42015-01-05 02:47:05 +000060 PreservedAnalyses run(LazyCallGraph::SCC &C) {
Chandler Carruth572e3402014-04-21 11:12:00 +000061 return PreservedAnalyses::all();
62 }
63 static StringRef name() { return "NoOpCGSCCPass"; }
64};
65
Chandler Carruth0b576b32015-01-06 02:50:06 +000066/// \brief No-op CGSCC analysis.
67struct NoOpCGSCCAnalysis {
68 struct Result {};
69 Result run(LazyCallGraph::SCC &) { return Result(); }
70 static StringRef name() { return "NoOpCGSCCAnalysis"; }
71 static void *ID() { return (void *)&PassID; }
72private:
73 static char PassID;
74};
75
76char NoOpCGSCCAnalysis::PassID;
77
Chandler Carruthd8330982014-01-12 09:34:22 +000078/// \brief No-op function pass which does nothing.
79struct NoOpFunctionPass {
Chandler Carruthd174ce42015-01-05 02:47:05 +000080 PreservedAnalyses run(Function &F) { return PreservedAnalyses::all(); }
Chandler Carruthd8330982014-01-12 09:34:22 +000081 static StringRef name() { return "NoOpFunctionPass"; }
82};
83
Chandler Carruth0b576b32015-01-06 02:50:06 +000084/// \brief No-op function analysis.
85struct NoOpFunctionAnalysis {
86 struct Result {};
87 Result run(Function &) { return Result(); }
88 static StringRef name() { return "NoOpFunctionAnalysis"; }
89 static void *ID() { return (void *)&PassID; }
90private:
91 static char PassID;
92};
93
94char NoOpFunctionAnalysis::PassID;
95
Chandler Carruth66445382014-01-11 08:16:35 +000096} // End anonymous namespace.
97
Chandler Carruth1ff77242015-03-07 09:02:36 +000098void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
Chandler Carruthb70f6732015-01-06 02:21:37 +000099#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
100 MAM.registerPass(CREATE_PASS);
101#include "PassRegistry.def"
102}
103
Chandler Carruth1ff77242015-03-07 09:02:36 +0000104void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
Chandler Carruthb70f6732015-01-06 02:21:37 +0000105#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
106 CGAM.registerPass(CREATE_PASS);
107#include "PassRegistry.def"
108}
109
Chandler Carruth1ff77242015-03-07 09:02:36 +0000110void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
Chandler Carruthb70f6732015-01-06 02:21:37 +0000111#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
112 FAM.registerPass(CREATE_PASS);
113#include "PassRegistry.def"
114}
115
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000116#ifndef NDEBUG
Chandler Carruth66445382014-01-11 08:16:35 +0000117static bool isModulePassName(StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000118#define MODULE_PASS(NAME, CREATE_PASS) if (Name == NAME) return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000119#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000120 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000121 return true;
122#include "PassRegistry.def"
123
Chandler Carruth66445382014-01-11 08:16:35 +0000124 return false;
125}
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000126#endif
Chandler Carruth66445382014-01-11 08:16:35 +0000127
Chandler Carruth572e3402014-04-21 11:12:00 +0000128static bool isCGSCCPassName(StringRef Name) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000129#define CGSCC_PASS(NAME, CREATE_PASS) if (Name == NAME) return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000130#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000131 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000132 return true;
133#include "PassRegistry.def"
134
Chandler Carruth572e3402014-04-21 11:12:00 +0000135 return false;
136}
137
Chandler Carruthd8330982014-01-12 09:34:22 +0000138static bool isFunctionPassName(StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000139#define FUNCTION_PASS(NAME, CREATE_PASS) if (Name == NAME) return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000140#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000141 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000142 return true;
143#include "PassRegistry.def"
144
Chandler Carruthd8330982014-01-12 09:34:22 +0000145 return false;
146}
147
Chandler Carruth1ff77242015-03-07 09:02:36 +0000148bool PassBuilder::parseModulePassName(ModulePassManager &MPM, StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000149#define MODULE_PASS(NAME, CREATE_PASS) \
150 if (Name == NAME) { \
151 MPM.addPass(CREATE_PASS); \
152 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000153 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000154#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
155 if (Name == "require<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000156 MPM.addPass(RequireAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000157 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000158 } \
159 if (Name == "invalidate<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000160 MPM.addPass(InvalidateAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000161 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000162 }
163#include "PassRegistry.def"
164
Chandler Carruth66445382014-01-11 08:16:35 +0000165 return false;
166}
167
Chandler Carruth1ff77242015-03-07 09:02:36 +0000168bool PassBuilder::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000169#define CGSCC_PASS(NAME, CREATE_PASS) \
170 if (Name == NAME) { \
171 CGPM.addPass(CREATE_PASS); \
172 return true; \
173 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000174#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
175 if (Name == "require<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000176 CGPM.addPass(RequireAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000177 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000178 } \
179 if (Name == "invalidate<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000180 CGPM.addPass(InvalidateAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000181 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000182 }
183#include "PassRegistry.def"
184
Chandler Carruth572e3402014-04-21 11:12:00 +0000185 return false;
186}
187
Chandler Carruth1ff77242015-03-07 09:02:36 +0000188bool PassBuilder::parseFunctionPassName(FunctionPassManager &FPM,
189 StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000190#define FUNCTION_PASS(NAME, CREATE_PASS) \
191 if (Name == NAME) { \
192 FPM.addPass(CREATE_PASS); \
193 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000194 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000195#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
196 if (Name == "require<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000197 FPM.addPass(RequireAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000198 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000199 } \
200 if (Name == "invalidate<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000201 FPM.addPass(InvalidateAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000202 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000203 }
204#include "PassRegistry.def"
205
Chandler Carruthd8330982014-01-12 09:34:22 +0000206 return false;
207}
208
Chandler Carruth1ff77242015-03-07 09:02:36 +0000209bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
210 StringRef &PipelineText,
211 bool VerifyEachPass,
212 bool DebugLogging) {
Chandler Carruthd8330982014-01-12 09:34:22 +0000213 for (;;) {
214 // Parse nested pass managers by recursing.
215 if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000216 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000217
218 // Parse the inner pipeline inte the nested manager.
219 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000220 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
221 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000222 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000223 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000224 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000225 PipelineText = PipelineText.substr(1);
226
227 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000228 FPM.addPass(std::move(NestedFPM));
Chandler Carruthd8330982014-01-12 09:34:22 +0000229 } else {
230 // Otherwise try to parse a pass name.
231 size_t End = PipelineText.find_first_of(",)");
232 if (!parseFunctionPassName(FPM, PipelineText.substr(0, End)))
233 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000234 if (VerifyEachPass)
235 FPM.addPass(VerifierPass());
Chandler Carruthd8330982014-01-12 09:34:22 +0000236
237 PipelineText = PipelineText.substr(End);
238 }
239
240 if (PipelineText.empty() || PipelineText[0] == ')')
241 return true;
242
243 assert(PipelineText[0] == ',');
244 PipelineText = PipelineText.substr(1);
245 }
246}
247
Chandler Carruth1ff77242015-03-07 09:02:36 +0000248bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
249 StringRef &PipelineText,
250 bool VerifyEachPass,
251 bool DebugLogging) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000252 for (;;) {
253 // Parse nested pass managers by recursing.
254 if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000255 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000256
257 // Parse the inner pipeline into the nested manager.
258 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000259 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
260 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000261 PipelineText.empty())
262 return false;
263 assert(PipelineText[0] == ')');
264 PipelineText = PipelineText.substr(1);
265
266 // Add the nested pass manager with the appropriate adaptor.
267 CGPM.addPass(std::move(NestedCGPM));
268 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000269 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000270
271 // Parse the inner pipeline inte the nested manager.
272 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000273 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
274 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000275 PipelineText.empty())
276 return false;
277 assert(PipelineText[0] == ')');
278 PipelineText = PipelineText.substr(1);
279
280 // Add the nested pass manager with the appropriate adaptor.
281 CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(NestedFPM)));
282 } else {
283 // Otherwise try to parse a pass name.
284 size_t End = PipelineText.find_first_of(",)");
285 if (!parseCGSCCPassName(CGPM, PipelineText.substr(0, End)))
286 return false;
287 // FIXME: No verifier support for CGSCC passes!
288
289 PipelineText = PipelineText.substr(End);
290 }
291
292 if (PipelineText.empty() || PipelineText[0] == ')')
293 return true;
294
295 assert(PipelineText[0] == ',');
296 PipelineText = PipelineText.substr(1);
297 }
298}
299
Chandler Carruth1ff77242015-03-07 09:02:36 +0000300bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
301 StringRef &PipelineText,
302 bool VerifyEachPass,
303 bool DebugLogging) {
Chandler Carruth66445382014-01-11 08:16:35 +0000304 for (;;) {
305 // Parse nested pass managers by recursing.
306 if (PipelineText.startswith("module(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000307 ModulePassManager NestedMPM(DebugLogging);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000308
309 // Parse the inner pipeline into the nested manager.
Chandler Carruth66445382014-01-11 08:16:35 +0000310 PipelineText = PipelineText.substr(strlen("module("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000311 if (!parseModulePassPipeline(NestedMPM, PipelineText, VerifyEachPass,
312 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000313 PipelineText.empty())
Chandler Carruth66445382014-01-11 08:16:35 +0000314 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000315 assert(PipelineText[0] == ')');
Chandler Carruth66445382014-01-11 08:16:35 +0000316 PipelineText = PipelineText.substr(1);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000317
318 // Now add the nested manager as a module pass.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000319 MPM.addPass(std::move(NestedMPM));
Chandler Carruth572e3402014-04-21 11:12:00 +0000320 } else if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000321 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000322
323 // Parse the inner pipeline inte the nested manager.
324 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000325 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
326 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000327 PipelineText.empty())
328 return false;
329 assert(PipelineText[0] == ')');
330 PipelineText = PipelineText.substr(1);
331
332 // Add the nested pass manager with the appropriate adaptor.
333 MPM.addPass(
334 createModuleToPostOrderCGSCCPassAdaptor(std::move(NestedCGPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000335 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000336 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000337
338 // Parse the inner pipeline inte the nested manager.
339 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000340 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
341 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000342 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000343 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000344 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000345 PipelineText = PipelineText.substr(1);
346
347 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000348 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(NestedFPM)));
Chandler Carruth66445382014-01-11 08:16:35 +0000349 } else {
350 // Otherwise try to parse a pass name.
351 size_t End = PipelineText.find_first_of(",)");
352 if (!parseModulePassName(MPM, PipelineText.substr(0, End)))
353 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000354 if (VerifyEachPass)
355 MPM.addPass(VerifierPass());
Chandler Carruth66445382014-01-11 08:16:35 +0000356
357 PipelineText = PipelineText.substr(End);
358 }
359
360 if (PipelineText.empty() || PipelineText[0] == ')')
361 return true;
362
363 assert(PipelineText[0] == ',');
364 PipelineText = PipelineText.substr(1);
365 }
366}
367
368// Primary pass pipeline description parsing routine.
369// FIXME: Should this routine accept a TargetMachine or require the caller to
370// pre-populate the analysis managers with target-specific stuff?
Chandler Carruth1ff77242015-03-07 09:02:36 +0000371bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
372 StringRef PipelineText, bool VerifyEachPass,
373 bool DebugLogging) {
Chandler Carruthea368f12015-01-06 08:37:58 +0000374 // By default, try to parse the pipeline as-if it were within an implicit
375 // 'module(...)' pass pipeline. If this will parse at all, it needs to
376 // consume the entire string.
Chandler Carruth14a759e2015-01-13 22:42:38 +0000377 if (parseModulePassPipeline(MPM, PipelineText, VerifyEachPass, DebugLogging))
Chandler Carruthea368f12015-01-06 08:37:58 +0000378 return PipelineText.empty();
Chandler Carruth66445382014-01-11 08:16:35 +0000379
Chandler Carruthea368f12015-01-06 08:37:58 +0000380 // This isn't parsable as a module pipeline, look for the end of a pass name
381 // and directly drop down to that layer.
Chandler Carruth6546cb62014-01-12 10:02:02 +0000382 StringRef FirstName =
383 PipelineText.substr(0, PipelineText.find_first_of(",)"));
Chandler Carruthea368f12015-01-06 08:37:58 +0000384 assert(!isModulePassName(FirstName) &&
385 "Already handled all module pipeline options.");
Chandler Carruth66445382014-01-11 08:16:35 +0000386
Chandler Carruthea368f12015-01-06 08:37:58 +0000387 // If this looks like a CGSCC pass, parse the whole thing as a CGSCC
388 // pipeline.
Chandler Carruth572e3402014-04-21 11:12:00 +0000389 if (isCGSCCPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000390 CGSCCPassManager CGPM(DebugLogging);
391 if (!parseCGSCCPassPipeline(CGPM, PipelineText, VerifyEachPass,
392 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000393 !PipelineText.empty())
394 return false;
395 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
396 return true;
397 }
398
Chandler Carruthea368f12015-01-06 08:37:58 +0000399 // Similarly, if this looks like a Function pass, parse the whole thing as
400 // a Function pipelien.
Chandler Carruthd8330982014-01-12 09:34:22 +0000401 if (isFunctionPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000402 FunctionPassManager FPM(DebugLogging);
403 if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass,
404 DebugLogging) ||
Chandler Carruth4d356312014-01-20 11:34:08 +0000405 !PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000406 return false;
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000407 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000408 return true;
409 }
Chandler Carruth66445382014-01-11 08:16:35 +0000410
411 return false;
412}