1 //===- Parsing, selection, and construction of pass pipelines -------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// 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
16 //===----------------------------------------------------------------------===//
18 #include "llvm/Passes/PassBuilder.h"
19 #include "llvm/ADT/StringSwitch.h"
20 #include "llvm/Analysis/AliasAnalysis.h"
21 #include "llvm/Analysis/AliasAnalysisEvaluator.h"
22 #include "llvm/Analysis/AssumptionCache.h"
23 #include "llvm/Analysis/BasicAliasAnalysis.h"
24 #include "llvm/Analysis/BlockFrequencyInfo.h"
25 #include "llvm/Analysis/BlockFrequencyInfoImpl.h"
26 #include "llvm/Analysis/BranchProbabilityInfo.h"
27 #include "llvm/Analysis/CFLAndersAliasAnalysis.h"
28 #include "llvm/Analysis/CFLSteensAliasAnalysis.h"
29 #include "llvm/Analysis/CGSCCPassManager.h"
30 #include "llvm/Analysis/CallGraph.h"
31 #include "llvm/Analysis/DemandedBits.h"
32 #include "llvm/Analysis/DependenceAnalysis.h"
33 #include "llvm/Analysis/DominanceFrontier.h"
34 #include "llvm/Analysis/GlobalsModRef.h"
35 #include "llvm/Analysis/IVUsers.h"
36 #include "llvm/Analysis/LazyCallGraph.h"
37 #include "llvm/Analysis/LazyValueInfo.h"
38 #include "llvm/Analysis/LoopAccessAnalysis.h"
39 #include "llvm/Analysis/LoopInfo.h"
40 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
41 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
42 #include "llvm/Analysis/PostDominators.h"
43 #include "llvm/Analysis/ProfileSummaryInfo.h"
44 #include "llvm/Analysis/RegionInfo.h"
45 #include "llvm/Analysis/ScalarEvolution.h"
46 #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
47 #include "llvm/Analysis/ScopedNoAliasAA.h"
48 #include "llvm/Analysis/TargetLibraryInfo.h"
49 #include "llvm/Analysis/TargetTransformInfo.h"
50 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
51 #include "llvm/CodeGen/PreISelIntrinsicLowering.h"
52 #include "llvm/CodeGen/UnreachableBlockElim.h"
53 #include "llvm/IR/Dominators.h"
54 #include "llvm/IR/IRPrintingPasses.h"
55 #include "llvm/IR/PassManager.h"
56 #include "llvm/IR/Verifier.h"
57 #include "llvm/Support/Debug.h"
58 #include "llvm/Support/Regex.h"
59 #include "llvm/Target/TargetMachine.h"
60 #include "llvm/Transforms/GCOVProfiler.h"
61 #include "llvm/Transforms/IPO/ConstantMerge.h"
62 #include "llvm/Transforms/IPO/CrossDSOCFI.h"
63 #include "llvm/Transforms/IPO/DeadArgumentElimination.h"
64 #include "llvm/Transforms/IPO/ElimAvailExtern.h"
65 #include "llvm/Transforms/IPO/ForceFunctionAttrs.h"
66 #include "llvm/Transforms/IPO/FunctionAttrs.h"
67 #include "llvm/Transforms/IPO/GlobalDCE.h"
68 #include "llvm/Transforms/IPO/GlobalOpt.h"
69 #include "llvm/Transforms/IPO/InferFunctionAttrs.h"
70 #include "llvm/Transforms/IPO/Internalize.h"
71 #include "llvm/Transforms/IPO/LowerTypeTests.h"
72 #include "llvm/Transforms/IPO/PartialInlining.h"
73 #include "llvm/Transforms/IPO/SCCP.h"
74 #include "llvm/Transforms/IPO/StripDeadPrototypes.h"
75 #include "llvm/Transforms/IPO/WholeProgramDevirt.h"
76 #include "llvm/Transforms/InstCombine/InstCombine.h"
77 #include "llvm/Transforms/InstrProfiling.h"
78 #include "llvm/Transforms/PGOInstrumentation.h"
79 #include "llvm/Transforms/SampleProfile.h"
80 #include "llvm/Transforms/Scalar/ADCE.h"
81 #include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h"
82 #include "llvm/Transforms/Scalar/BDCE.h"
83 #include "llvm/Transforms/Scalar/ConstantHoisting.h"
84 #include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h"
85 #include "llvm/Transforms/Scalar/DCE.h"
86 #include "llvm/Transforms/Scalar/DeadStoreElimination.h"
87 #include "llvm/Transforms/Scalar/EarlyCSE.h"
88 #include "llvm/Transforms/Scalar/Float2Int.h"
89 #include "llvm/Transforms/Scalar/GVN.h"
90 #include "llvm/Transforms/Scalar/GuardWidening.h"
91 #include "llvm/Transforms/Scalar/IndVarSimplify.h"
92 #include "llvm/Transforms/Scalar/JumpThreading.h"
93 #include "llvm/Transforms/Scalar/LICM.h"
94 #include "llvm/Transforms/Scalar/LoopDeletion.h"
95 #include "llvm/Transforms/Scalar/LoopDistribute.h"
96 #include "llvm/Transforms/Scalar/LoopIdiomRecognize.h"
97 #include "llvm/Transforms/Scalar/LoopInstSimplify.h"
98 #include "llvm/Transforms/Scalar/LoopRotation.h"
99 #include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
100 #include "llvm/Transforms/Scalar/LowerAtomic.h"
101 #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
102 #include "llvm/Transforms/Scalar/MemCpyOptimizer.h"
103 #include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
104 #include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
105 #include "llvm/Transforms/Scalar/Reassociate.h"
106 #include "llvm/Transforms/Scalar/SCCP.h"
107 #include "llvm/Transforms/Scalar/SROA.h"
108 #include "llvm/Transforms/Scalar/SimplifyCFG.h"
109 #include "llvm/Transforms/Scalar/Sink.h"
110 #include "llvm/Transforms/Scalar/TailRecursionElimination.h"
111 #include "llvm/Transforms/Utils/AddDiscriminators.h"
112 #include "llvm/Transforms/Utils/LCSSA.h"
113 #include "llvm/Transforms/Utils/LoopSimplify.h"
114 #include "llvm/Transforms/Utils/Mem2Reg.h"
115 #include "llvm/Transforms/Utils/MemorySSA.h"
116 #include "llvm/Transforms/Utils/SimplifyInstructions.h"
117 #include "llvm/Transforms/Vectorize/LoopVectorize.h"
118 #include "llvm/Transforms/Vectorize/SLPVectorizer.h"
120 #include <type_traits>
122 using namespace llvm;
124 static Regex DefaultAliasRegex("^(default|lto-pre-link|lto)<(O[0123sz])>$");
128 /// \brief No-op module pass which does nothing.
129 struct NoOpModulePass {
130 PreservedAnalyses run(Module &M, AnalysisManager<Module> &) {
131 return PreservedAnalyses::all();
133 static StringRef name() { return "NoOpModulePass"; }
136 /// \brief No-op module analysis.
137 class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
138 friend AnalysisInfoMixin<NoOpModuleAnalysis>;
143 Result run(Module &, AnalysisManager<Module> &) { return Result(); }
144 static StringRef name() { return "NoOpModuleAnalysis"; }
147 /// \brief No-op CGSCC pass which does nothing.
148 struct NoOpCGSCCPass {
149 PreservedAnalyses run(LazyCallGraph::SCC &C,
150 AnalysisManager<LazyCallGraph::SCC> &) {
151 return PreservedAnalyses::all();
153 static StringRef name() { return "NoOpCGSCCPass"; }
156 /// \brief No-op CGSCC analysis.
157 class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
158 friend AnalysisInfoMixin<NoOpCGSCCAnalysis>;
163 Result run(LazyCallGraph::SCC &, AnalysisManager<LazyCallGraph::SCC> &) {
166 static StringRef name() { return "NoOpCGSCCAnalysis"; }
169 /// \brief No-op function pass which does nothing.
170 struct NoOpFunctionPass {
171 PreservedAnalyses run(Function &F, AnalysisManager<Function> &) {
172 return PreservedAnalyses::all();
174 static StringRef name() { return "NoOpFunctionPass"; }
177 /// \brief No-op function analysis.
178 class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
179 friend AnalysisInfoMixin<NoOpFunctionAnalysis>;
184 Result run(Function &, AnalysisManager<Function> &) { return Result(); }
185 static StringRef name() { return "NoOpFunctionAnalysis"; }
188 /// \brief No-op loop pass which does nothing.
189 struct NoOpLoopPass {
190 PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &) {
191 return PreservedAnalyses::all();
193 static StringRef name() { return "NoOpLoopPass"; }
196 /// \brief No-op loop analysis.
197 class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
198 friend AnalysisInfoMixin<NoOpLoopAnalysis>;
203 Result run(Loop &, AnalysisManager<Loop> &) { return Result(); }
204 static StringRef name() { return "NoOpLoopAnalysis"; }
207 char NoOpModuleAnalysis::PassID;
208 char NoOpCGSCCAnalysis::PassID;
209 char NoOpFunctionAnalysis::PassID;
210 char NoOpLoopAnalysis::PassID;
212 } // End anonymous namespace.
214 void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
215 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
216 MAM.registerPass([&] { return CREATE_PASS; });
217 #include "PassRegistry.def"
220 void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
221 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
222 CGAM.registerPass([&] { return CREATE_PASS; });
223 #include "PassRegistry.def"
226 void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
227 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
228 FAM.registerPass([&] { return CREATE_PASS; });
229 #include "PassRegistry.def"
232 void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) {
233 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
234 LAM.registerPass([&] { return CREATE_PASS; });
235 #include "PassRegistry.def"
238 void PassBuilder::addPerModuleDefaultPipeline(ModulePassManager &MPM,
239 OptimizationLevel Level,
241 // FIXME: Finish fleshing this out to match the legacy pipelines.
242 FunctionPassManager EarlyFPM(DebugLogging);
243 EarlyFPM.addPass(SimplifyCFGPass());
244 EarlyFPM.addPass(SROA());
245 EarlyFPM.addPass(EarlyCSEPass());
246 EarlyFPM.addPass(LowerExpectIntrinsicPass());
248 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
251 void PassBuilder::addLTOPreLinkDefaultPipeline(ModulePassManager &MPM,
252 OptimizationLevel Level,
254 // FIXME: We should use a customized pre-link pipeline!
255 addPerModuleDefaultPipeline(MPM, Level, DebugLogging);
258 void PassBuilder::addLTODefaultPipeline(ModulePassManager &MPM,
259 OptimizationLevel Level,
261 // FIXME: Finish fleshing this out to match the legacy LTO pipelines.
262 FunctionPassManager LateFPM(DebugLogging);
263 LateFPM.addPass(InstCombinePass());
264 LateFPM.addPass(SimplifyCFGPass());
266 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(LateFPM)));
270 static bool isModulePassName(StringRef Name) {
271 // Manually handle aliases for pre-configured pipeline fragments.
272 if (Name.startswith("default") || Name.startswith("lto"))
273 return DefaultAliasRegex.match(Name);
275 #define MODULE_PASS(NAME, CREATE_PASS) \
278 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
279 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
281 #include "PassRegistry.def"
287 static bool isCGSCCPassName(StringRef Name) {
288 #define CGSCC_PASS(NAME, CREATE_PASS) \
291 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
292 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
294 #include "PassRegistry.def"
299 static bool isFunctionPassName(StringRef Name) {
300 #define FUNCTION_PASS(NAME, CREATE_PASS) \
303 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
304 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
306 #include "PassRegistry.def"
311 static bool isLoopPassName(StringRef Name) {
312 #define LOOP_PASS(NAME, CREATE_PASS) \
315 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
316 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
318 #include "PassRegistry.def"
323 bool PassBuilder::parseModulePassName(ModulePassManager &MPM, StringRef Name,
325 // Manually handle aliases for pre-configured pipeline fragments.
326 if (Name.startswith("default") || Name.startswith("lto")) {
327 SmallVector<StringRef, 3> Matches;
328 if (!DefaultAliasRegex.match(Name, &Matches))
330 assert(Matches.size() == 3 && "Must capture two matched strings!");
332 auto L = StringSwitch<OptimizationLevel>(Matches[2])
340 if (Matches[1] == "default") {
341 addPerModuleDefaultPipeline(MPM, L, DebugLogging);
342 } else if (Matches[1] == "lto-pre-link") {
343 addLTOPreLinkDefaultPipeline(MPM, L, DebugLogging);
345 assert(Matches[1] == "lto" && "Not one of the matched options!");
346 addLTODefaultPipeline(MPM, L, DebugLogging);
351 #define MODULE_PASS(NAME, CREATE_PASS) \
352 if (Name == NAME) { \
353 MPM.addPass(CREATE_PASS); \
356 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
357 if (Name == "require<" NAME ">") { \
358 MPM.addPass(RequireAnalysisPass< \
359 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
362 if (Name == "invalidate<" NAME ">") { \
363 MPM.addPass(InvalidateAnalysisPass< \
364 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
367 #include "PassRegistry.def"
372 bool PassBuilder::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
373 #define CGSCC_PASS(NAME, CREATE_PASS) \
374 if (Name == NAME) { \
375 CGPM.addPass(CREATE_PASS); \
378 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
379 if (Name == "require<" NAME ">") { \
380 CGPM.addPass(RequireAnalysisPass< \
381 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
384 if (Name == "invalidate<" NAME ">") { \
385 CGPM.addPass(InvalidateAnalysisPass< \
386 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
389 #include "PassRegistry.def"
394 bool PassBuilder::parseFunctionPassName(FunctionPassManager &FPM,
396 #define FUNCTION_PASS(NAME, CREATE_PASS) \
397 if (Name == NAME) { \
398 FPM.addPass(CREATE_PASS); \
401 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
402 if (Name == "require<" NAME ">") { \
403 FPM.addPass(RequireAnalysisPass< \
404 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
407 if (Name == "invalidate<" NAME ">") { \
408 FPM.addPass(InvalidateAnalysisPass< \
409 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
412 #include "PassRegistry.def"
417 bool PassBuilder::parseLoopPassName(LoopPassManager &FPM, StringRef Name) {
418 #define LOOP_PASS(NAME, CREATE_PASS) \
419 if (Name == NAME) { \
420 FPM.addPass(CREATE_PASS); \
423 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
424 if (Name == "require<" NAME ">") { \
425 FPM.addPass(RequireAnalysisPass< \
426 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
429 if (Name == "invalidate<" NAME ">") { \
430 FPM.addPass(InvalidateAnalysisPass< \
431 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
434 #include "PassRegistry.def"
439 bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
440 #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
441 if (Name == NAME) { \
442 AA.registerModuleAnalysis< \
443 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
446 #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
447 if (Name == NAME) { \
448 AA.registerFunctionAnalysis< \
449 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
452 #include "PassRegistry.def"
457 bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
458 StringRef &PipelineText,
462 // Parse nested pass managers by recursing.
463 if (PipelineText.startswith("loop(")) {
464 LoopPassManager NestedLPM(DebugLogging);
466 // Parse the inner pipeline inte the nested manager.
467 PipelineText = PipelineText.substr(strlen("loop("));
468 if (!parseLoopPassPipeline(NestedLPM, PipelineText, VerifyEachPass,
470 PipelineText.empty())
472 assert(PipelineText[0] == ')');
473 PipelineText = PipelineText.substr(1);
475 // Add the nested pass manager with the appropriate adaptor.
476 LPM.addPass(std::move(NestedLPM));
478 // Otherwise try to parse a pass name.
479 size_t End = PipelineText.find_first_of(",)");
480 if (!parseLoopPassName(LPM, PipelineText.substr(0, End)))
482 // TODO: Ideally, we would run a LoopVerifierPass() here in the
483 // VerifyEachPass case, but we don't have such a verifier yet.
485 PipelineText = PipelineText.substr(End);
488 if (PipelineText.empty() || PipelineText[0] == ')')
491 assert(PipelineText[0] == ',');
492 PipelineText = PipelineText.substr(1);
496 bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
497 StringRef &PipelineText,
501 // Parse nested pass managers by recursing.
502 if (PipelineText.startswith("function(")) {
503 FunctionPassManager NestedFPM(DebugLogging);
505 // Parse the inner pipeline inte the nested manager.
506 PipelineText = PipelineText.substr(strlen("function("));
507 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
509 PipelineText.empty())
511 assert(PipelineText[0] == ')');
512 PipelineText = PipelineText.substr(1);
514 // Add the nested pass manager with the appropriate adaptor.
515 FPM.addPass(std::move(NestedFPM));
516 } else if (PipelineText.startswith("loop(")) {
517 LoopPassManager NestedLPM(DebugLogging);
519 // Parse the inner pipeline inte the nested manager.
520 PipelineText = PipelineText.substr(strlen("loop("));
521 if (!parseLoopPassPipeline(NestedLPM, PipelineText, VerifyEachPass,
523 PipelineText.empty())
525 assert(PipelineText[0] == ')');
526 PipelineText = PipelineText.substr(1);
528 // Add the nested pass manager with the appropriate adaptor.
529 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(NestedLPM)));
531 // Otherwise try to parse a pass name.
532 size_t End = PipelineText.find_first_of(",)");
533 if (!parseFunctionPassName(FPM, PipelineText.substr(0, End)))
536 FPM.addPass(VerifierPass());
538 PipelineText = PipelineText.substr(End);
541 if (PipelineText.empty() || PipelineText[0] == ')')
544 assert(PipelineText[0] == ',');
545 PipelineText = PipelineText.substr(1);
549 bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
550 StringRef &PipelineText,
554 // Parse nested pass managers by recursing.
555 if (PipelineText.startswith("cgscc(")) {
556 CGSCCPassManager NestedCGPM(DebugLogging);
558 // Parse the inner pipeline into the nested manager.
559 PipelineText = PipelineText.substr(strlen("cgscc("));
560 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
562 PipelineText.empty())
564 assert(PipelineText[0] == ')');
565 PipelineText = PipelineText.substr(1);
567 // Add the nested pass manager with the appropriate adaptor.
568 CGPM.addPass(std::move(NestedCGPM));
569 } else if (PipelineText.startswith("function(")) {
570 FunctionPassManager NestedFPM(DebugLogging);
572 // Parse the inner pipeline inte the nested manager.
573 PipelineText = PipelineText.substr(strlen("function("));
574 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
576 PipelineText.empty())
578 assert(PipelineText[0] == ')');
579 PipelineText = PipelineText.substr(1);
581 // Add the nested pass manager with the appropriate adaptor.
583 createCGSCCToFunctionPassAdaptor(std::move(NestedFPM), DebugLogging));
585 // Otherwise try to parse a pass name.
586 size_t End = PipelineText.find_first_of(",)");
587 if (!parseCGSCCPassName(CGPM, PipelineText.substr(0, End)))
589 // FIXME: No verifier support for CGSCC passes!
591 PipelineText = PipelineText.substr(End);
594 if (PipelineText.empty() || PipelineText[0] == ')')
597 assert(PipelineText[0] == ',');
598 PipelineText = PipelineText.substr(1);
602 void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM,
603 FunctionAnalysisManager &FAM,
604 CGSCCAnalysisManager &CGAM,
605 ModuleAnalysisManager &MAM) {
606 MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
607 MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
608 CGAM.registerPass([&] { return FunctionAnalysisManagerCGSCCProxy(FAM); });
609 CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
610 FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
611 FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
612 FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
613 LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
616 bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
617 StringRef &PipelineText,
621 // Parse nested pass managers by recursing.
622 if (PipelineText.startswith("module(")) {
623 ModulePassManager NestedMPM(DebugLogging);
625 // Parse the inner pipeline into the nested manager.
626 PipelineText = PipelineText.substr(strlen("module("));
627 if (!parseModulePassPipeline(NestedMPM, PipelineText, VerifyEachPass,
629 PipelineText.empty())
631 assert(PipelineText[0] == ')');
632 PipelineText = PipelineText.substr(1);
634 // Now add the nested manager as a module pass.
635 MPM.addPass(std::move(NestedMPM));
636 } else if (PipelineText.startswith("cgscc(")) {
637 CGSCCPassManager NestedCGPM(DebugLogging);
639 // Parse the inner pipeline inte the nested manager.
640 PipelineText = PipelineText.substr(strlen("cgscc("));
641 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
643 PipelineText.empty())
645 assert(PipelineText[0] == ')');
646 PipelineText = PipelineText.substr(1);
648 // Add the nested pass manager with the appropriate adaptor.
649 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(NestedCGPM),
651 } else if (PipelineText.startswith("function(")) {
652 FunctionPassManager NestedFPM(DebugLogging);
654 // Parse the inner pipeline inte the nested manager.
655 PipelineText = PipelineText.substr(strlen("function("));
656 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
658 PipelineText.empty())
660 assert(PipelineText[0] == ')');
661 PipelineText = PipelineText.substr(1);
663 // Add the nested pass manager with the appropriate adaptor.
664 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(NestedFPM)));
666 // Otherwise try to parse a pass name.
667 size_t End = PipelineText.find_first_of(",)");
668 if (!parseModulePassName(MPM, PipelineText.substr(0, End), DebugLogging))
671 MPM.addPass(VerifierPass());
673 PipelineText = PipelineText.substr(End);
676 if (PipelineText.empty() || PipelineText[0] == ')')
679 assert(PipelineText[0] == ',');
680 PipelineText = PipelineText.substr(1);
684 // Primary pass pipeline description parsing routine.
685 // FIXME: Should this routine accept a TargetMachine or require the caller to
686 // pre-populate the analysis managers with target-specific stuff?
687 bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
688 StringRef PipelineText, bool VerifyEachPass,
690 // By default, try to parse the pipeline as-if it were within an implicit
691 // 'module(...)' pass pipeline. If this will parse at all, it needs to
692 // consume the entire string.
693 if (parseModulePassPipeline(MPM, PipelineText, VerifyEachPass, DebugLogging))
694 return PipelineText.empty();
696 // This isn't parsable as a module pipeline, look for the end of a pass name
697 // and directly drop down to that layer.
698 StringRef FirstName =
699 PipelineText.substr(0, PipelineText.find_first_of(",)"));
700 assert(!isModulePassName(FirstName) &&
701 "Already handled all module pipeline options.");
703 // If this looks like a CGSCC pass, parse the whole thing as a CGSCC
705 if (PipelineText.startswith("cgscc(") || isCGSCCPassName(FirstName)) {
706 CGSCCPassManager CGPM(DebugLogging);
707 if (!parseCGSCCPassPipeline(CGPM, PipelineText, VerifyEachPass,
709 !PipelineText.empty())
712 createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM), DebugLogging));
716 // Similarly, if this looks like a Function pass, parse the whole thing as
717 // a Function pipelien.
718 if (PipelineText.startswith("function(") || isFunctionPassName(FirstName)) {
719 FunctionPassManager FPM(DebugLogging);
720 if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass,
722 !PipelineText.empty())
724 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
728 // If this looks like a Loop pass, parse the whole thing as a Loop pipeline.
729 if (PipelineText.startswith("loop(") || isLoopPassName(FirstName)) {
730 LoopPassManager LPM(DebugLogging);
731 if (!parseLoopPassPipeline(LPM, PipelineText, VerifyEachPass,
733 !PipelineText.empty())
735 FunctionPassManager FPM(DebugLogging);
736 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM)));
737 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
744 bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) {
745 while (!PipelineText.empty()) {
747 std::tie(Name, PipelineText) = PipelineText.split(',');
748 if (!parseAAPassName(AA, Name))