blob: e5ad5c06644b368649c71b231a5ce22ea3894e40 [file] [log] [blame]
Chandler Carruth66445382014-01-11 08:16:35 +00001//===- Passes.cpp - Parsing, selection, and running of passes -------------===//
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/// This file provides the infrastructure to parse and build a custom pass
12/// manager based on a commandline flag. It also provides helpers to aid in
13/// analyzing, debugging, and testing pass structures.
14///
15//===----------------------------------------------------------------------===//
16
17#include "Passes.h"
Chandler Carruthdf8b2232015-01-22 21:53:09 +000018#include "llvm/Analysis/AssumptionCache.h"
Chandler Carruth572e3402014-04-21 11:12:00 +000019#include "llvm/Analysis/CGSCCPassManager.h"
Chandler Carruthbf71a342014-02-06 04:37:03 +000020#include "llvm/Analysis/LazyCallGraph.h"
Chandler Carruthaaf0b4c2015-01-20 10:58:50 +000021#include "llvm/Analysis/LoopInfo.h"
Chandler Carruth8ca43222015-01-15 11:39:46 +000022#include "llvm/Analysis/TargetLibraryInfo.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000023#include "llvm/Analysis/TargetTransformInfo.h"
Chandler Carruth64764b42015-01-14 10:19:28 +000024#include "llvm/IR/Dominators.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000025#include "llvm/IR/IRPrintingPasses.h"
Chandler Carruth66445382014-01-11 08:16:35 +000026#include "llvm/IR/PassManager.h"
Chandler Carruth4d356312014-01-20 11:34:08 +000027#include "llvm/IR/Verifier.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000028#include "llvm/Support/Debug.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000029#include "llvm/Target/TargetMachine.h"
Chandler Carruth83ba2692015-01-24 04:19:17 +000030#include "llvm/Transforms/InstCombine/InstCombine.h"
Chandler Carruthe8c686a2015-02-01 10:51:23 +000031#include "llvm/Transforms/Scalar/EarlyCSE.h"
Chandler Carruth43e590e2015-01-24 11:13:02 +000032#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
Chandler Carruthfdffd872015-02-01 11:34:21 +000033#include "llvm/Transforms/Scalar/SimplifyCFG.h"
Chandler Carruth66445382014-01-11 08:16:35 +000034
35using namespace llvm;
36
37namespace {
38
Chandler Carruthd8330982014-01-12 09:34:22 +000039/// \brief No-op module pass which does nothing.
Chandler Carruth66445382014-01-11 08:16:35 +000040struct NoOpModulePass {
Chandler Carruthd174ce42015-01-05 02:47:05 +000041 PreservedAnalyses run(Module &M) { return PreservedAnalyses::all(); }
Chandler Carrutha13f27c2014-01-11 11:52:05 +000042 static StringRef name() { return "NoOpModulePass"; }
Chandler Carruth66445382014-01-11 08:16:35 +000043};
44
Chandler Carruth0b576b32015-01-06 02:50:06 +000045/// \brief No-op module analysis.
46struct NoOpModuleAnalysis {
47 struct Result {};
48 Result run(Module &) { return Result(); }
49 static StringRef name() { return "NoOpModuleAnalysis"; }
50 static void *ID() { return (void *)&PassID; }
51private:
52 static char PassID;
53};
54
55char NoOpModuleAnalysis::PassID;
56
Chandler Carruth572e3402014-04-21 11:12:00 +000057/// \brief No-op CGSCC pass which does nothing.
58struct NoOpCGSCCPass {
Chandler Carruthd174ce42015-01-05 02:47:05 +000059 PreservedAnalyses run(LazyCallGraph::SCC &C) {
Chandler Carruth572e3402014-04-21 11:12:00 +000060 return PreservedAnalyses::all();
61 }
62 static StringRef name() { return "NoOpCGSCCPass"; }
63};
64
Chandler Carruth0b576b32015-01-06 02:50:06 +000065/// \brief No-op CGSCC analysis.
66struct NoOpCGSCCAnalysis {
67 struct Result {};
68 Result run(LazyCallGraph::SCC &) { return Result(); }
69 static StringRef name() { return "NoOpCGSCCAnalysis"; }
70 static void *ID() { return (void *)&PassID; }
71private:
72 static char PassID;
73};
74
75char NoOpCGSCCAnalysis::PassID;
76
Chandler Carruthd8330982014-01-12 09:34:22 +000077/// \brief No-op function pass which does nothing.
78struct NoOpFunctionPass {
Chandler Carruthd174ce42015-01-05 02:47:05 +000079 PreservedAnalyses run(Function &F) { return PreservedAnalyses::all(); }
Chandler Carruthd8330982014-01-12 09:34:22 +000080 static StringRef name() { return "NoOpFunctionPass"; }
81};
82
Chandler Carruth0b576b32015-01-06 02:50:06 +000083/// \brief No-op function analysis.
84struct NoOpFunctionAnalysis {
85 struct Result {};
86 Result run(Function &) { return Result(); }
87 static StringRef name() { return "NoOpFunctionAnalysis"; }
88 static void *ID() { return (void *)&PassID; }
89private:
90 static char PassID;
91};
92
93char NoOpFunctionAnalysis::PassID;
94
Chandler Carruth66445382014-01-11 08:16:35 +000095} // End anonymous namespace.
96
Chandler Carruth2dc92e92015-02-01 07:40:05 +000097void Passes::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
Chandler Carruthb70f6732015-01-06 02:21:37 +000098#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
99 MAM.registerPass(CREATE_PASS);
100#include "PassRegistry.def"
101}
102
Chandler Carruth2dc92e92015-02-01 07:40:05 +0000103void Passes::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
Chandler Carruthb70f6732015-01-06 02:21:37 +0000104#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
105 CGAM.registerPass(CREATE_PASS);
106#include "PassRegistry.def"
107}
108
Chandler Carruth2dc92e92015-02-01 07:40:05 +0000109void Passes::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
Chandler Carruthb70f6732015-01-06 02:21:37 +0000110#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
111 FAM.registerPass(CREATE_PASS);
112#include "PassRegistry.def"
113}
114
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000115#ifndef NDEBUG
Chandler Carruth66445382014-01-11 08:16:35 +0000116static bool isModulePassName(StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000117#define MODULE_PASS(NAME, CREATE_PASS) if (Name == NAME) return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000118#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000119 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000120 return true;
121#include "PassRegistry.def"
122
Chandler Carruth66445382014-01-11 08:16:35 +0000123 return false;
124}
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000125#endif
Chandler Carruth66445382014-01-11 08:16:35 +0000126
Chandler Carruth572e3402014-04-21 11:12:00 +0000127static bool isCGSCCPassName(StringRef Name) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000128#define CGSCC_PASS(NAME, CREATE_PASS) if (Name == NAME) return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000129#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000130 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000131 return true;
132#include "PassRegistry.def"
133
Chandler Carruth572e3402014-04-21 11:12:00 +0000134 return false;
135}
136
Chandler Carruthd8330982014-01-12 09:34:22 +0000137static bool isFunctionPassName(StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000138#define FUNCTION_PASS(NAME, CREATE_PASS) if (Name == NAME) return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000139#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000140 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000141 return true;
142#include "PassRegistry.def"
143
Chandler Carruthd8330982014-01-12 09:34:22 +0000144 return false;
145}
146
Chandler Carruth2dc92e92015-02-01 07:40:05 +0000147bool Passes::parseModulePassName(ModulePassManager &MPM, StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000148#define MODULE_PASS(NAME, CREATE_PASS) \
149 if (Name == NAME) { \
150 MPM.addPass(CREATE_PASS); \
151 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000152 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000153#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
154 if (Name == "require<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000155 MPM.addPass(RequireAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000156 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000157 } \
158 if (Name == "invalidate<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000159 MPM.addPass(InvalidateAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000160 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000161 }
162#include "PassRegistry.def"
163
Chandler Carruth66445382014-01-11 08:16:35 +0000164 return false;
165}
166
Chandler Carruth2dc92e92015-02-01 07:40:05 +0000167bool Passes::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000168#define CGSCC_PASS(NAME, CREATE_PASS) \
169 if (Name == NAME) { \
170 CGPM.addPass(CREATE_PASS); \
171 return true; \
172 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000173#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
174 if (Name == "require<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000175 CGPM.addPass(RequireAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000176 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000177 } \
178 if (Name == "invalidate<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000179 CGPM.addPass(InvalidateAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000180 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000181 }
182#include "PassRegistry.def"
183
Chandler Carruth572e3402014-04-21 11:12:00 +0000184 return false;
185}
186
Chandler Carruth2dc92e92015-02-01 07:40:05 +0000187bool Passes::parseFunctionPassName(FunctionPassManager &FPM, StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000188#define FUNCTION_PASS(NAME, CREATE_PASS) \
189 if (Name == NAME) { \
190 FPM.addPass(CREATE_PASS); \
191 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000192 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000193#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
194 if (Name == "require<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000195 FPM.addPass(RequireAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000196 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000197 } \
198 if (Name == "invalidate<" NAME ">") { \
Chandler Carruthe5b0a9c2015-01-07 11:14:51 +0000199 FPM.addPass(InvalidateAnalysisPass<decltype(CREATE_PASS)>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000200 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000201 }
202#include "PassRegistry.def"
203
Chandler Carruthd8330982014-01-12 09:34:22 +0000204 return false;
205}
206
Chandler Carruth2dc92e92015-02-01 07:40:05 +0000207bool Passes::parseFunctionPassPipeline(FunctionPassManager &FPM,
208 StringRef &PipelineText,
209 bool VerifyEachPass, bool DebugLogging) {
Chandler Carruthd8330982014-01-12 09:34:22 +0000210 for (;;) {
211 // Parse nested pass managers by recursing.
212 if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000213 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000214
215 // Parse the inner pipeline inte the nested manager.
216 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000217 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
218 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000219 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000220 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000221 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000222 PipelineText = PipelineText.substr(1);
223
224 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000225 FPM.addPass(std::move(NestedFPM));
Chandler Carruthd8330982014-01-12 09:34:22 +0000226 } else {
227 // Otherwise try to parse a pass name.
228 size_t End = PipelineText.find_first_of(",)");
229 if (!parseFunctionPassName(FPM, PipelineText.substr(0, End)))
230 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000231 if (VerifyEachPass)
232 FPM.addPass(VerifierPass());
Chandler Carruthd8330982014-01-12 09:34:22 +0000233
234 PipelineText = PipelineText.substr(End);
235 }
236
237 if (PipelineText.empty() || PipelineText[0] == ')')
238 return true;
239
240 assert(PipelineText[0] == ',');
241 PipelineText = PipelineText.substr(1);
242 }
243}
244
Chandler Carruth2dc92e92015-02-01 07:40:05 +0000245bool Passes::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
246 StringRef &PipelineText,
247 bool VerifyEachPass, bool DebugLogging) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000248 for (;;) {
249 // Parse nested pass managers by recursing.
250 if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000251 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000252
253 // Parse the inner pipeline into the nested manager.
254 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000255 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
256 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000257 PipelineText.empty())
258 return false;
259 assert(PipelineText[0] == ')');
260 PipelineText = PipelineText.substr(1);
261
262 // Add the nested pass manager with the appropriate adaptor.
263 CGPM.addPass(std::move(NestedCGPM));
264 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000265 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000266
267 // Parse the inner pipeline inte the nested manager.
268 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000269 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
270 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000271 PipelineText.empty())
272 return false;
273 assert(PipelineText[0] == ')');
274 PipelineText = PipelineText.substr(1);
275
276 // Add the nested pass manager with the appropriate adaptor.
277 CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(NestedFPM)));
278 } else {
279 // Otherwise try to parse a pass name.
280 size_t End = PipelineText.find_first_of(",)");
281 if (!parseCGSCCPassName(CGPM, PipelineText.substr(0, End)))
282 return false;
283 // FIXME: No verifier support for CGSCC passes!
284
285 PipelineText = PipelineText.substr(End);
286 }
287
288 if (PipelineText.empty() || PipelineText[0] == ')')
289 return true;
290
291 assert(PipelineText[0] == ',');
292 PipelineText = PipelineText.substr(1);
293 }
294}
295
Chandler Carruth2dc92e92015-02-01 07:40:05 +0000296bool Passes::parseModulePassPipeline(ModulePassManager &MPM,
297 StringRef &PipelineText,
298 bool VerifyEachPass, bool DebugLogging) {
Chandler Carruth66445382014-01-11 08:16:35 +0000299 for (;;) {
300 // Parse nested pass managers by recursing.
301 if (PipelineText.startswith("module(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000302 ModulePassManager NestedMPM(DebugLogging);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000303
304 // Parse the inner pipeline into the nested manager.
Chandler Carruth66445382014-01-11 08:16:35 +0000305 PipelineText = PipelineText.substr(strlen("module("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000306 if (!parseModulePassPipeline(NestedMPM, PipelineText, VerifyEachPass,
307 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000308 PipelineText.empty())
Chandler Carruth66445382014-01-11 08:16:35 +0000309 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000310 assert(PipelineText[0] == ')');
Chandler Carruth66445382014-01-11 08:16:35 +0000311 PipelineText = PipelineText.substr(1);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000312
313 // Now add the nested manager as a module pass.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000314 MPM.addPass(std::move(NestedMPM));
Chandler Carruth572e3402014-04-21 11:12:00 +0000315 } else if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000316 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000317
318 // Parse the inner pipeline inte the nested manager.
319 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000320 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
321 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000322 PipelineText.empty())
323 return false;
324 assert(PipelineText[0] == ')');
325 PipelineText = PipelineText.substr(1);
326
327 // Add the nested pass manager with the appropriate adaptor.
328 MPM.addPass(
329 createModuleToPostOrderCGSCCPassAdaptor(std::move(NestedCGPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000330 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000331 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000332
333 // Parse the inner pipeline inte the nested manager.
334 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000335 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
336 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000337 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000338 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000339 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000340 PipelineText = PipelineText.substr(1);
341
342 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000343 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(NestedFPM)));
Chandler Carruth66445382014-01-11 08:16:35 +0000344 } else {
345 // Otherwise try to parse a pass name.
346 size_t End = PipelineText.find_first_of(",)");
347 if (!parseModulePassName(MPM, PipelineText.substr(0, End)))
348 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000349 if (VerifyEachPass)
350 MPM.addPass(VerifierPass());
Chandler Carruth66445382014-01-11 08:16:35 +0000351
352 PipelineText = PipelineText.substr(End);
353 }
354
355 if (PipelineText.empty() || PipelineText[0] == ')')
356 return true;
357
358 assert(PipelineText[0] == ',');
359 PipelineText = PipelineText.substr(1);
360 }
361}
362
363// Primary pass pipeline description parsing routine.
364// FIXME: Should this routine accept a TargetMachine or require the caller to
365// pre-populate the analysis managers with target-specific stuff?
Chandler Carruth2dc92e92015-02-01 07:40:05 +0000366bool Passes::parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
367 bool VerifyEachPass, bool DebugLogging) {
Chandler Carruthea368f12015-01-06 08:37:58 +0000368 // By default, try to parse the pipeline as-if it were within an implicit
369 // 'module(...)' pass pipeline. If this will parse at all, it needs to
370 // consume the entire string.
Chandler Carruth14a759e2015-01-13 22:42:38 +0000371 if (parseModulePassPipeline(MPM, PipelineText, VerifyEachPass, DebugLogging))
Chandler Carruthea368f12015-01-06 08:37:58 +0000372 return PipelineText.empty();
Chandler Carruth66445382014-01-11 08:16:35 +0000373
Chandler Carruthea368f12015-01-06 08:37:58 +0000374 // This isn't parsable as a module pipeline, look for the end of a pass name
375 // and directly drop down to that layer.
Chandler Carruth6546cb62014-01-12 10:02:02 +0000376 StringRef FirstName =
377 PipelineText.substr(0, PipelineText.find_first_of(",)"));
Chandler Carruthea368f12015-01-06 08:37:58 +0000378 assert(!isModulePassName(FirstName) &&
379 "Already handled all module pipeline options.");
Chandler Carruth66445382014-01-11 08:16:35 +0000380
Chandler Carruthea368f12015-01-06 08:37:58 +0000381 // If this looks like a CGSCC pass, parse the whole thing as a CGSCC
382 // pipeline.
Chandler Carruth572e3402014-04-21 11:12:00 +0000383 if (isCGSCCPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000384 CGSCCPassManager CGPM(DebugLogging);
385 if (!parseCGSCCPassPipeline(CGPM, PipelineText, VerifyEachPass,
386 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000387 !PipelineText.empty())
388 return false;
389 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
390 return true;
391 }
392
Chandler Carruthea368f12015-01-06 08:37:58 +0000393 // Similarly, if this looks like a Function pass, parse the whole thing as
394 // a Function pipelien.
Chandler Carruthd8330982014-01-12 09:34:22 +0000395 if (isFunctionPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000396 FunctionPassManager FPM(DebugLogging);
397 if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass,
398 DebugLogging) ||
Chandler Carruth4d356312014-01-20 11:34:08 +0000399 !PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000400 return false;
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000401 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000402 return true;
403 }
Chandler Carruth66445382014-01-11 08:16:35 +0000404
405 return false;
406}