blob: 362bd13d03d3a713c6072fef4f4910e56dc5b05f [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 Carruth8b5a74192016-02-28 22:16:03 +000019#include "llvm/ADT/StringSwitch.h"
Chandler Carruth6f5770b102016-02-13 23:32:00 +000020#include "llvm/Analysis/AliasAnalysis.h"
Chandler Carruth4f846a52016-02-20 03:46:03 +000021#include "llvm/Analysis/AliasAnalysisEvaluator.h"
Chandler Carruthdf8b2232015-01-22 21:53:09 +000022#include "llvm/Analysis/AssumptionCache.h"
Chandler Carruthbece8d52016-02-13 23:46:24 +000023#include "llvm/Analysis/BasicAliasAnalysis.h"
Xinliang David Li28a93272016-05-05 21:13:27 +000024#include "llvm/Analysis/BlockFrequencyInfo.h"
25#include "llvm/Analysis/BlockFrequencyInfoImpl.h"
Xinliang David Li6e5dd412016-05-05 02:59:57 +000026#include "llvm/Analysis/BranchProbabilityInfo.h"
Chandler Carruth342c6712016-02-20 03:52:02 +000027#include "llvm/Analysis/CFLAliasAnalysis.h"
Chandler Carruth572e3402014-04-21 11:12:00 +000028#include "llvm/Analysis/CGSCCPassManager.h"
Chandler Carruth4c660f72016-03-10 11:24:11 +000029#include "llvm/Analysis/CallGraph.h"
Michael Kupersteinde16b442016-04-18 23:55:01 +000030#include "llvm/Analysis/DemandedBits.h"
Chandler Carruth49c22192016-05-12 22:19:39 +000031#include "llvm/Analysis/DependenceAnalysis.h"
Hongbin Zheng751337f2016-02-25 17:54:15 +000032#include "llvm/Analysis/DominanceFrontier.h"
Chandler Carruth45a9c202016-03-11 09:15:11 +000033#include "llvm/Analysis/GlobalsModRef.h"
Chandler Carruthbf71a342014-02-06 04:37:03 +000034#include "llvm/Analysis/LazyCallGraph.h"
Sean Silva687019f2016-06-13 22:01:25 +000035#include "llvm/Analysis/LazyValueInfo.h"
Chandler Carruthaaf0b4c2015-01-20 10:58:50 +000036#include "llvm/Analysis/LoopInfo.h"
Chandler Carruth61440d22016-03-10 00:55:30 +000037#include "llvm/Analysis/MemoryDependenceAnalysis.h"
Hongbin Zheng3f978402016-02-25 17:54:07 +000038#include "llvm/Analysis/PostDominators.h"
Easwaran Raman019e0bf2016-06-03 22:54:26 +000039#include "llvm/Analysis/ProfileSummaryInfo.h"
Hongbin Zhengbc539772016-02-25 17:54:25 +000040#include "llvm/Analysis/RegionInfo.h"
Chandler Carruth2f1fd162015-08-17 02:08:17 +000041#include "llvm/Analysis/ScalarEvolution.h"
Chandler Carruth2b3d0442016-02-20 04:01:45 +000042#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
Chandler Carruthd6091a02016-02-20 04:03:06 +000043#include "llvm/Analysis/ScopedNoAliasAA.h"
Chandler Carruth8ca43222015-01-15 11:39:46 +000044#include "llvm/Analysis/TargetLibraryInfo.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000045#include "llvm/Analysis/TargetTransformInfo.h"
Chandler Carruthc1dc3842016-02-20 04:04:52 +000046#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
Michael Kuperstein82d5da52016-06-24 20:13:42 +000047#include "llvm/CodeGen/PreISelIntrinsicLowering.h"
Chandler Carruth64764b42015-01-14 10:19:28 +000048#include "llvm/IR/Dominators.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000049#include "llvm/IR/IRPrintingPasses.h"
Chandler Carruth66445382014-01-11 08:16:35 +000050#include "llvm/IR/PassManager.h"
Chandler Carruth4d356312014-01-20 11:34:08 +000051#include "llvm/IR/Verifier.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000052#include "llvm/Support/Debug.h"
Chandler Carruth8b5a74192016-02-28 22:16:03 +000053#include "llvm/Support/Regex.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000054#include "llvm/Target/TargetMachine.h"
Xinliang David Li64dbb292016-06-05 05:12:23 +000055#include "llvm/Transforms/GCOVProfiler.h"
Davide Italiano164b9bc2016-05-05 00:51:09 +000056#include "llvm/Transforms/IPO/ConstantMerge.h"
Sean Silvae3bb4572016-06-12 09:16:39 +000057#include "llvm/Transforms/IPO/DeadArgumentElimination.h"
Davide Italiano344e8382016-05-05 02:37:32 +000058#include "llvm/Transforms/IPO/ElimAvailExtern.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000059#include "llvm/Transforms/IPO/ForceFunctionAttrs.h"
Chandler Carruth9c4ed172016-02-18 11:03:11 +000060#include "llvm/Transforms/IPO/FunctionAttrs.h"
Davide Italiano66228c42016-05-03 19:39:15 +000061#include "llvm/Transforms/IPO/GlobalDCE.h"
Justin Bogner1a075012016-04-26 00:28:01 +000062#include "llvm/Transforms/IPO/GlobalOpt.h"
Chandler Carruth3a040e62015-12-27 08:41:34 +000063#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
Justin Bogner4563a062016-04-26 20:15:52 +000064#include "llvm/Transforms/IPO/Internalize.h"
Easwaran Raman1832bf62016-06-27 16:50:18 +000065#include "llvm/Transforms/IPO/PartialInlining.h"
Davide Italianof54f2f02016-05-05 21:05:36 +000066#include "llvm/Transforms/IPO/SCCP.h"
Justin Bogner21e15372015-10-30 23:28:12 +000067#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
Davide Italianod737dd22016-06-14 21:44:19 +000068#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000069#include "llvm/Transforms/InstCombine/InstCombine.h"
Xinliang David Lie6b89292016-04-18 17:47:38 +000070#include "llvm/Transforms/InstrProfiling.h"
Xinliang David Li8aebf442016-05-06 05:49:19 +000071#include "llvm/Transforms/PGOInstrumentation.h"
Xinliang David Lid38392e2016-05-27 23:20:16 +000072#include "llvm/Transforms/SampleProfile.h"
Justin Bogner19b67992015-10-30 23:13:18 +000073#include "llvm/Transforms/Scalar/ADCE.h"
Sean Silvaa4c2d152016-06-15 06:18:01 +000074#include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h"
Davide Italiano655a1452016-05-25 01:57:04 +000075#include "llvm/Transforms/Scalar/BDCE.h"
Justin Bogner395c2122016-04-22 19:40:41 +000076#include "llvm/Transforms/Scalar/DCE.h"
Justin Bogner594e07b2016-05-17 21:38:13 +000077#include "llvm/Transforms/Scalar/DeadStoreElimination.h"
Chandler Carruthe8c686a2015-02-01 10:51:23 +000078#include "llvm/Transforms/Scalar/EarlyCSE.h"
Michael Kuperstein83b753d2016-06-24 23:32:02 +000079#include "llvm/Transforms/Scalar/Float2Int.h"
Easwaran Raman019e0bf2016-06-03 22:54:26 +000080#include "llvm/Transforms/Scalar/GVN.h"
Davide Italiano89ab89d2016-06-14 00:49:23 +000081#include "llvm/Transforms/Scalar/GuardWidening.h"
Sanjoy Das4d4339d2016-06-05 18:01:19 +000082#include "llvm/Transforms/Scalar/IndVarSimplify.h"
Sean Silva46590d52016-06-14 00:51:09 +000083#include "llvm/Transforms/Scalar/JumpThreading.h"
Justin Bognerd0d23412016-05-03 22:02:31 +000084#include "llvm/Transforms/Scalar/LoopRotation.h"
Justin Bognerab6a5132016-05-03 21:47:32 +000085#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
Davide Italiano99223442016-05-13 22:52:35 +000086#include "llvm/Transforms/Scalar/LowerAtomic.h"
Chandler Carruth43e590e2015-01-24 11:13:02 +000087#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
Sean Silva6347df02016-06-14 02:44:55 +000088#include "llvm/Transforms/Scalar/MemCpyOptimizer.h"
Davide Italianob49aa5c2016-06-17 19:10:09 +000089#include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
Davide Italiano1021c682016-05-25 23:38:53 +000090#include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
Justin Bognerc2bf63d2016-04-26 23:39:29 +000091#include "llvm/Transforms/Scalar/Reassociate.h"
Davide Italiano98f7e0e2016-05-18 15:18:25 +000092#include "llvm/Transforms/Scalar/SCCP.h"
Chandler Carruth74a8a222016-06-17 07:15:29 +000093#include "llvm/Transforms/Scalar/SLPVectorizer.h"
Chandler Carruth29a18a42015-09-12 09:09:14 +000094#include "llvm/Transforms/Scalar/SROA.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000095#include "llvm/Transforms/Scalar/SimplifyCFG.h"
Justin Bognerb9394902016-04-22 19:54:10 +000096#include "llvm/Transforms/Scalar/Sink.h"
Xinliang David Li1eaecef2016-06-15 21:51:30 +000097#include "llvm/Transforms/Utils/AddDiscriminators.h"
Easwaran Ramane12c4872016-06-09 19:44:46 +000098#include "llvm/Transforms/Utils/LCSSA.h"
Davide Italianocccf4f02016-06-14 03:22:22 +000099#include "llvm/Transforms/Utils/Mem2Reg.h"
Geoff Berryb96d3b22016-06-01 21:30:40 +0000100#include "llvm/Transforms/Utils/MemorySSA.h"
Davide Italianocccf4f02016-06-14 03:22:22 +0000101
Chandler Carruth58dde8c2016-02-26 12:17:54 +0000102#include <type_traits>
Chandler Carruth66445382014-01-11 08:16:35 +0000103
104using namespace llvm;
105
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000106static Regex DefaultAliasRegex("^(default|lto-pre-link|lto)<(O[0123sz])>$");
107
Chandler Carruth66445382014-01-11 08:16:35 +0000108namespace {
109
Chandler Carruthd8330982014-01-12 09:34:22 +0000110/// \brief No-op module pass which does nothing.
Chandler Carruth66445382014-01-11 08:16:35 +0000111struct NoOpModulePass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000112 PreservedAnalyses run(Module &M, AnalysisManager<Module> &) {
113 return PreservedAnalyses::all();
114 }
Chandler Carrutha13f27c2014-01-11 11:52:05 +0000115 static StringRef name() { return "NoOpModulePass"; }
Chandler Carruth66445382014-01-11 08:16:35 +0000116};
117
Chandler Carruth0b576b32015-01-06 02:50:06 +0000118/// \brief No-op module analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000119class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
120 friend AnalysisInfoMixin<NoOpModuleAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000121 static char PassID;
122
123public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000124 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000125 Result run(Module &, AnalysisManager<Module> &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000126 static StringRef name() { return "NoOpModuleAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000127};
128
Chandler Carruth572e3402014-04-21 11:12:00 +0000129/// \brief No-op CGSCC pass which does nothing.
130struct NoOpCGSCCPass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000131 PreservedAnalyses run(LazyCallGraph::SCC &C,
132 AnalysisManager<LazyCallGraph::SCC> &) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000133 return PreservedAnalyses::all();
134 }
135 static StringRef name() { return "NoOpCGSCCPass"; }
136};
137
Chandler Carruth0b576b32015-01-06 02:50:06 +0000138/// \brief No-op CGSCC analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000139class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
140 friend AnalysisInfoMixin<NoOpCGSCCAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000141 static char PassID;
142
143public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000144 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000145 Result run(LazyCallGraph::SCC &, AnalysisManager<LazyCallGraph::SCC> &) {
146 return Result();
147 }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000148 static StringRef name() { return "NoOpCGSCCAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000149};
150
Chandler Carruthd8330982014-01-12 09:34:22 +0000151/// \brief No-op function pass which does nothing.
152struct NoOpFunctionPass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000153 PreservedAnalyses run(Function &F, AnalysisManager<Function> &) {
154 return PreservedAnalyses::all();
155 }
Chandler Carruthd8330982014-01-12 09:34:22 +0000156 static StringRef name() { return "NoOpFunctionPass"; }
157};
158
Chandler Carruth0b576b32015-01-06 02:50:06 +0000159/// \brief No-op function analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000160class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
161 friend AnalysisInfoMixin<NoOpFunctionAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000162 static char PassID;
163
164public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000165 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000166 Result run(Function &, AnalysisManager<Function> &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000167 static StringRef name() { return "NoOpFunctionAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000168};
169
Justin Bognereecc3c82016-02-25 07:23:08 +0000170/// \brief No-op loop pass which does nothing.
171struct NoOpLoopPass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000172 PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &) {
173 return PreservedAnalyses::all();
174 }
Justin Bognereecc3c82016-02-25 07:23:08 +0000175 static StringRef name() { return "NoOpLoopPass"; }
176};
177
178/// \brief No-op loop analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000179class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
180 friend AnalysisInfoMixin<NoOpLoopAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000181 static char PassID;
182
183public:
Justin Bognereecc3c82016-02-25 07:23:08 +0000184 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000185 Result run(Loop &, AnalysisManager<Loop> &) { return Result(); }
Justin Bognereecc3c82016-02-25 07:23:08 +0000186 static StringRef name() { return "NoOpLoopAnalysis"; }
Justin Bognereecc3c82016-02-25 07:23:08 +0000187};
188
Chandler Carruthb4faf132016-03-11 10:22:49 +0000189char NoOpModuleAnalysis::PassID;
190char NoOpCGSCCAnalysis::PassID;
191char NoOpFunctionAnalysis::PassID;
192char NoOpLoopAnalysis::PassID;
193
Chandler Carruth66445382014-01-11 08:16:35 +0000194} // End anonymous namespace.
195
Chandler Carruth1ff77242015-03-07 09:02:36 +0000196void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000197#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000198 MAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000199#include "PassRegistry.def"
200}
201
Chandler Carruth1ff77242015-03-07 09:02:36 +0000202void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000203#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000204 CGAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000205#include "PassRegistry.def"
206}
207
Chandler Carruth1ff77242015-03-07 09:02:36 +0000208void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000209#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000210 FAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000211#include "PassRegistry.def"
212}
213
Justin Bognereecc3c82016-02-25 07:23:08 +0000214void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000215#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
Justin Bognereecc3c82016-02-25 07:23:08 +0000216 LAM.registerPass([&] { return CREATE_PASS; });
217#include "PassRegistry.def"
218}
219
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000220void PassBuilder::addPerModuleDefaultPipeline(ModulePassManager &MPM,
221 OptimizationLevel Level,
222 bool DebugLogging) {
223 // FIXME: Finish fleshing this out to match the legacy pipelines.
224 FunctionPassManager EarlyFPM(DebugLogging);
225 EarlyFPM.addPass(SimplifyCFGPass());
226 EarlyFPM.addPass(SROA());
227 EarlyFPM.addPass(EarlyCSEPass());
228 EarlyFPM.addPass(LowerExpectIntrinsicPass());
229
230 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
231}
232
233void PassBuilder::addLTOPreLinkDefaultPipeline(ModulePassManager &MPM,
234 OptimizationLevel Level,
235 bool DebugLogging) {
236 // FIXME: We should use a customized pre-link pipeline!
237 addPerModuleDefaultPipeline(MPM, Level, DebugLogging);
238}
239
240void PassBuilder::addLTODefaultPipeline(ModulePassManager &MPM,
241 OptimizationLevel Level,
242 bool DebugLogging) {
243 // FIXME: Finish fleshing this out to match the legacy LTO pipelines.
244 FunctionPassManager LateFPM(DebugLogging);
245 LateFPM.addPass(InstCombinePass());
246 LateFPM.addPass(SimplifyCFGPass());
247
248 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(LateFPM)));
249}
250
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000251#ifndef NDEBUG
Chandler Carruth66445382014-01-11 08:16:35 +0000252static bool isModulePassName(StringRef Name) {
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000253 // Manually handle aliases for pre-configured pipeline fragments.
254 if (Name.startswith("default") || Name.startswith("lto"))
255 return DefaultAliasRegex.match(Name);
256
Chandler Carruth74a8a222016-06-17 07:15:29 +0000257#define MODULE_PASS(NAME, CREATE_PASS) \
258 if (Name == NAME) \
259 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000260#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000261 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000262 return true;
263#include "PassRegistry.def"
264
Chandler Carruth66445382014-01-11 08:16:35 +0000265 return false;
266}
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000267#endif
Chandler Carruth66445382014-01-11 08:16:35 +0000268
Chandler Carruth572e3402014-04-21 11:12:00 +0000269static bool isCGSCCPassName(StringRef Name) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000270#define CGSCC_PASS(NAME, CREATE_PASS) \
271 if (Name == NAME) \
272 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000273#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000274 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000275 return true;
276#include "PassRegistry.def"
277
Chandler Carruth572e3402014-04-21 11:12:00 +0000278 return false;
279}
280
Chandler Carruthd8330982014-01-12 09:34:22 +0000281static bool isFunctionPassName(StringRef Name) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000282#define FUNCTION_PASS(NAME, CREATE_PASS) \
283 if (Name == NAME) \
284 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000285#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000286 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000287 return true;
288#include "PassRegistry.def"
289
Chandler Carruthd8330982014-01-12 09:34:22 +0000290 return false;
291}
292
Justin Bognereecc3c82016-02-25 07:23:08 +0000293static bool isLoopPassName(StringRef Name) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000294#define LOOP_PASS(NAME, CREATE_PASS) \
295 if (Name == NAME) \
296 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +0000297#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
298 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
299 return true;
300#include "PassRegistry.def"
301
302 return false;
303}
304
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000305bool PassBuilder::parseModulePassName(ModulePassManager &MPM, StringRef Name,
306 bool DebugLogging) {
307 // Manually handle aliases for pre-configured pipeline fragments.
308 if (Name.startswith("default") || Name.startswith("lto")) {
309 SmallVector<StringRef, 3> Matches;
310 if (!DefaultAliasRegex.match(Name, &Matches))
311 return false;
312 assert(Matches.size() == 3 && "Must capture two matched strings!");
313
314 auto L = StringSwitch<OptimizationLevel>(Matches[2])
315 .Case("O0", O0)
316 .Case("O1", O1)
317 .Case("O2", O2)
318 .Case("O3", O3)
319 .Case("Os", Os)
320 .Case("Oz", Oz);
321
322 if (Matches[1] == "default") {
323 addPerModuleDefaultPipeline(MPM, L, DebugLogging);
324 } else if (Matches[1] == "lto-pre-link") {
325 addLTOPreLinkDefaultPipeline(MPM, L, DebugLogging);
326 } else {
327 assert(Matches[1] == "lto" && "Not one of the matched options!");
328 addLTODefaultPipeline(MPM, L, DebugLogging);
329 }
330 return true;
331 }
332
Chandler Carruth58944182014-04-21 08:08:50 +0000333#define MODULE_PASS(NAME, CREATE_PASS) \
334 if (Name == NAME) { \
335 MPM.addPass(CREATE_PASS); \
336 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000337 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000338#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
339 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000340 MPM.addPass(RequireAnalysisPass< \
341 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000342 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000343 } \
344 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000345 MPM.addPass(InvalidateAnalysisPass< \
346 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000347 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000348 }
349#include "PassRegistry.def"
350
Chandler Carruth66445382014-01-11 08:16:35 +0000351 return false;
352}
353
Chandler Carruth1ff77242015-03-07 09:02:36 +0000354bool PassBuilder::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000355#define CGSCC_PASS(NAME, CREATE_PASS) \
356 if (Name == NAME) { \
357 CGPM.addPass(CREATE_PASS); \
358 return true; \
359 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000360#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
361 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000362 CGPM.addPass(RequireAnalysisPass< \
363 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000364 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000365 } \
366 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000367 CGPM.addPass(InvalidateAnalysisPass< \
368 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000369 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000370 }
371#include "PassRegistry.def"
372
Chandler Carruth572e3402014-04-21 11:12:00 +0000373 return false;
374}
375
Chandler Carruth1ff77242015-03-07 09:02:36 +0000376bool PassBuilder::parseFunctionPassName(FunctionPassManager &FPM,
377 StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000378#define FUNCTION_PASS(NAME, CREATE_PASS) \
379 if (Name == NAME) { \
380 FPM.addPass(CREATE_PASS); \
381 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000382 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000383#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
384 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000385 FPM.addPass(RequireAnalysisPass< \
386 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000387 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000388 } \
389 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000390 FPM.addPass(InvalidateAnalysisPass< \
391 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000392 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000393 }
394#include "PassRegistry.def"
395
Chandler Carruthd8330982014-01-12 09:34:22 +0000396 return false;
397}
398
Chandler Carruth74a8a222016-06-17 07:15:29 +0000399bool PassBuilder::parseLoopPassName(LoopPassManager &FPM, StringRef Name) {
Justin Bognereecc3c82016-02-25 07:23:08 +0000400#define LOOP_PASS(NAME, CREATE_PASS) \
401 if (Name == NAME) { \
402 FPM.addPass(CREATE_PASS); \
403 return true; \
404 }
405#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
406 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000407 FPM.addPass(RequireAnalysisPass< \
408 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +0000409 return true; \
410 } \
411 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000412 FPM.addPass(InvalidateAnalysisPass< \
413 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +0000414 return true; \
415 }
416#include "PassRegistry.def"
417
418 return false;
419}
420
Chandler Carruthedf59962016-02-18 09:45:17 +0000421bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
Chandler Carruth45a9c202016-03-11 09:15:11 +0000422#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
423 if (Name == NAME) { \
424 AA.registerModuleAnalysis< \
425 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
426 return true; \
427 }
Chandler Carruthedf59962016-02-18 09:45:17 +0000428#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
429 if (Name == NAME) { \
Chandler Carruth58dde8c2016-02-26 12:17:54 +0000430 AA.registerFunctionAnalysis< \
431 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
Chandler Carruthedf59962016-02-18 09:45:17 +0000432 return true; \
433 }
434#include "PassRegistry.def"
435
436 return false;
437}
438
Justin Bognereecc3c82016-02-25 07:23:08 +0000439bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
440 StringRef &PipelineText,
441 bool VerifyEachPass,
442 bool DebugLogging) {
443 for (;;) {
444 // Parse nested pass managers by recursing.
445 if (PipelineText.startswith("loop(")) {
446 LoopPassManager NestedLPM(DebugLogging);
447
448 // Parse the inner pipeline inte the nested manager.
449 PipelineText = PipelineText.substr(strlen("loop("));
450 if (!parseLoopPassPipeline(NestedLPM, PipelineText, VerifyEachPass,
451 DebugLogging) ||
452 PipelineText.empty())
453 return false;
454 assert(PipelineText[0] == ')');
455 PipelineText = PipelineText.substr(1);
456
457 // Add the nested pass manager with the appropriate adaptor.
458 LPM.addPass(std::move(NestedLPM));
459 } else {
460 // Otherwise try to parse a pass name.
461 size_t End = PipelineText.find_first_of(",)");
462 if (!parseLoopPassName(LPM, PipelineText.substr(0, End)))
463 return false;
464 // TODO: Ideally, we would run a LoopVerifierPass() here in the
465 // VerifyEachPass case, but we don't have such a verifier yet.
466
467 PipelineText = PipelineText.substr(End);
468 }
469
470 if (PipelineText.empty() || PipelineText[0] == ')')
471 return true;
472
473 assert(PipelineText[0] == ',');
474 PipelineText = PipelineText.substr(1);
475 }
476}
477
Chandler Carruth1ff77242015-03-07 09:02:36 +0000478bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
479 StringRef &PipelineText,
480 bool VerifyEachPass,
481 bool DebugLogging) {
Chandler Carruthd8330982014-01-12 09:34:22 +0000482 for (;;) {
483 // Parse nested pass managers by recursing.
484 if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000485 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000486
487 // Parse the inner pipeline inte the nested manager.
488 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000489 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
490 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000491 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000492 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000493 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000494 PipelineText = PipelineText.substr(1);
495
496 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000497 FPM.addPass(std::move(NestedFPM));
Justin Bognereecc3c82016-02-25 07:23:08 +0000498 } else if (PipelineText.startswith("loop(")) {
499 LoopPassManager NestedLPM(DebugLogging);
500
501 // Parse the inner pipeline inte the nested manager.
502 PipelineText = PipelineText.substr(strlen("loop("));
503 if (!parseLoopPassPipeline(NestedLPM, PipelineText, VerifyEachPass,
504 DebugLogging) ||
505 PipelineText.empty())
506 return false;
507 assert(PipelineText[0] == ')');
508 PipelineText = PipelineText.substr(1);
509
510 // Add the nested pass manager with the appropriate adaptor.
511 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(NestedLPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000512 } else {
513 // Otherwise try to parse a pass name.
514 size_t End = PipelineText.find_first_of(",)");
515 if (!parseFunctionPassName(FPM, PipelineText.substr(0, End)))
516 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000517 if (VerifyEachPass)
518 FPM.addPass(VerifierPass());
Chandler Carruthd8330982014-01-12 09:34:22 +0000519
520 PipelineText = PipelineText.substr(End);
521 }
522
523 if (PipelineText.empty() || PipelineText[0] == ')')
524 return true;
525
526 assert(PipelineText[0] == ',');
527 PipelineText = PipelineText.substr(1);
528 }
529}
530
Chandler Carruth1ff77242015-03-07 09:02:36 +0000531bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
532 StringRef &PipelineText,
533 bool VerifyEachPass,
534 bool DebugLogging) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000535 for (;;) {
536 // Parse nested pass managers by recursing.
537 if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000538 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000539
540 // Parse the inner pipeline into the nested manager.
541 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000542 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
543 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000544 PipelineText.empty())
545 return false;
546 assert(PipelineText[0] == ')');
547 PipelineText = PipelineText.substr(1);
548
549 // Add the nested pass manager with the appropriate adaptor.
550 CGPM.addPass(std::move(NestedCGPM));
551 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000552 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000553
554 // Parse the inner pipeline inte the nested manager.
555 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000556 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
557 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000558 PipelineText.empty())
559 return false;
560 assert(PipelineText[0] == ')');
561 PipelineText = PipelineText.substr(1);
562
563 // Add the nested pass manager with the appropriate adaptor.
564 CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(NestedFPM)));
565 } else {
566 // Otherwise try to parse a pass name.
567 size_t End = PipelineText.find_first_of(",)");
568 if (!parseCGSCCPassName(CGPM, PipelineText.substr(0, End)))
569 return false;
570 // FIXME: No verifier support for CGSCC passes!
571
572 PipelineText = PipelineText.substr(End);
573 }
574
575 if (PipelineText.empty() || PipelineText[0] == ')')
576 return true;
577
578 assert(PipelineText[0] == ',');
579 PipelineText = PipelineText.substr(1);
580 }
581}
582
NAKAMURA Takumia42f5282016-05-16 10:13:37 +0000583void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM,
584 FunctionAnalysisManager &FAM,
585 CGSCCAnalysisManager &CGAM,
586 ModuleAnalysisManager &MAM) {
587 MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
588 MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
589 CGAM.registerPass([&] { return FunctionAnalysisManagerCGSCCProxy(FAM); });
590 CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
591 FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
592 FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
593 FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
594 LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
595}
596
Chandler Carruth1ff77242015-03-07 09:02:36 +0000597bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
598 StringRef &PipelineText,
599 bool VerifyEachPass,
600 bool DebugLogging) {
Chandler Carruth66445382014-01-11 08:16:35 +0000601 for (;;) {
602 // Parse nested pass managers by recursing.
603 if (PipelineText.startswith("module(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000604 ModulePassManager NestedMPM(DebugLogging);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000605
606 // Parse the inner pipeline into the nested manager.
Chandler Carruth66445382014-01-11 08:16:35 +0000607 PipelineText = PipelineText.substr(strlen("module("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000608 if (!parseModulePassPipeline(NestedMPM, PipelineText, VerifyEachPass,
609 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000610 PipelineText.empty())
Chandler Carruth66445382014-01-11 08:16:35 +0000611 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000612 assert(PipelineText[0] == ')');
Chandler Carruth66445382014-01-11 08:16:35 +0000613 PipelineText = PipelineText.substr(1);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000614
615 // Now add the nested manager as a module pass.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000616 MPM.addPass(std::move(NestedMPM));
Chandler Carruth572e3402014-04-21 11:12:00 +0000617 } else if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000618 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000619
620 // Parse the inner pipeline inte the nested manager.
621 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000622 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
623 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000624 PipelineText.empty())
625 return false;
626 assert(PipelineText[0] == ')');
627 PipelineText = PipelineText.substr(1);
628
629 // Add the nested pass manager with the appropriate adaptor.
630 MPM.addPass(
631 createModuleToPostOrderCGSCCPassAdaptor(std::move(NestedCGPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000632 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000633 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000634
635 // Parse the inner pipeline inte the nested manager.
636 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000637 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
638 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000639 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000640 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000641 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000642 PipelineText = PipelineText.substr(1);
643
644 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000645 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(NestedFPM)));
Chandler Carruth66445382014-01-11 08:16:35 +0000646 } else {
647 // Otherwise try to parse a pass name.
648 size_t End = PipelineText.find_first_of(",)");
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000649 if (!parseModulePassName(MPM, PipelineText.substr(0, End), DebugLogging))
Chandler Carruth66445382014-01-11 08:16:35 +0000650 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000651 if (VerifyEachPass)
652 MPM.addPass(VerifierPass());
Chandler Carruth66445382014-01-11 08:16:35 +0000653
654 PipelineText = PipelineText.substr(End);
655 }
656
657 if (PipelineText.empty() || PipelineText[0] == ')')
658 return true;
659
660 assert(PipelineText[0] == ',');
661 PipelineText = PipelineText.substr(1);
662 }
663}
664
665// Primary pass pipeline description parsing routine.
666// FIXME: Should this routine accept a TargetMachine or require the caller to
667// pre-populate the analysis managers with target-specific stuff?
Chandler Carruth1ff77242015-03-07 09:02:36 +0000668bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
669 StringRef PipelineText, bool VerifyEachPass,
670 bool DebugLogging) {
Chandler Carruthea368f12015-01-06 08:37:58 +0000671 // By default, try to parse the pipeline as-if it were within an implicit
672 // 'module(...)' pass pipeline. If this will parse at all, it needs to
673 // consume the entire string.
Chandler Carruth14a759e2015-01-13 22:42:38 +0000674 if (parseModulePassPipeline(MPM, PipelineText, VerifyEachPass, DebugLogging))
Chandler Carruthea368f12015-01-06 08:37:58 +0000675 return PipelineText.empty();
Chandler Carruth66445382014-01-11 08:16:35 +0000676
Chandler Carruthea368f12015-01-06 08:37:58 +0000677 // This isn't parsable as a module pipeline, look for the end of a pass name
678 // and directly drop down to that layer.
Chandler Carruth6546cb62014-01-12 10:02:02 +0000679 StringRef FirstName =
680 PipelineText.substr(0, PipelineText.find_first_of(",)"));
Chandler Carruthea368f12015-01-06 08:37:58 +0000681 assert(!isModulePassName(FirstName) &&
682 "Already handled all module pipeline options.");
Chandler Carruth66445382014-01-11 08:16:35 +0000683
Chandler Carruthea368f12015-01-06 08:37:58 +0000684 // If this looks like a CGSCC pass, parse the whole thing as a CGSCC
685 // pipeline.
Justin Bognereecc3c82016-02-25 07:23:08 +0000686 if (PipelineText.startswith("cgscc(") || isCGSCCPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000687 CGSCCPassManager CGPM(DebugLogging);
688 if (!parseCGSCCPassPipeline(CGPM, PipelineText, VerifyEachPass,
689 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000690 !PipelineText.empty())
691 return false;
692 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
693 return true;
694 }
695
Chandler Carruthea368f12015-01-06 08:37:58 +0000696 // Similarly, if this looks like a Function pass, parse the whole thing as
697 // a Function pipelien.
Justin Bognereecc3c82016-02-25 07:23:08 +0000698 if (PipelineText.startswith("function(") || isFunctionPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000699 FunctionPassManager FPM(DebugLogging);
700 if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass,
701 DebugLogging) ||
Chandler Carruth4d356312014-01-20 11:34:08 +0000702 !PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000703 return false;
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000704 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000705 return true;
706 }
Chandler Carruth66445382014-01-11 08:16:35 +0000707
Justin Bognereecc3c82016-02-25 07:23:08 +0000708 // If this looks like a Loop pass, parse the whole thing as a Loop pipeline.
709 if (PipelineText.startswith("loop(") || isLoopPassName(FirstName)) {
710 LoopPassManager LPM(DebugLogging);
711 if (!parseLoopPassPipeline(LPM, PipelineText, VerifyEachPass,
712 DebugLogging) ||
713 !PipelineText.empty())
714 return false;
715 FunctionPassManager FPM(DebugLogging);
716 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM)));
717 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
718 return true;
719 }
720
Chandler Carruth66445382014-01-11 08:16:35 +0000721 return false;
722}
Chandler Carruthedf59962016-02-18 09:45:17 +0000723
724bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) {
725 while (!PipelineText.empty()) {
726 StringRef Name;
727 std::tie(Name, PipelineText) = PipelineText.split(',');
728 if (!parseAAPassName(AA, Name))
729 return false;
730 }
731
732 return true;
733}