blob: c372b5a378a1b5c5cbe3151d7da69b2a3044dbe1 [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"
Davide Italianof54f2f02016-05-05 21:05:36 +000065#include "llvm/Transforms/IPO/SCCP.h"
Justin Bogner21e15372015-10-30 23:28:12 +000066#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
Davide Italianod737dd22016-06-14 21:44:19 +000067#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000068#include "llvm/Transforms/InstCombine/InstCombine.h"
Xinliang David Lie6b89292016-04-18 17:47:38 +000069#include "llvm/Transforms/InstrProfiling.h"
Xinliang David Li8aebf442016-05-06 05:49:19 +000070#include "llvm/Transforms/PGOInstrumentation.h"
Xinliang David Lid38392e2016-05-27 23:20:16 +000071#include "llvm/Transforms/SampleProfile.h"
Justin Bogner19b67992015-10-30 23:13:18 +000072#include "llvm/Transforms/Scalar/ADCE.h"
Sean Silvaa4c2d152016-06-15 06:18:01 +000073#include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h"
Davide Italiano655a1452016-05-25 01:57:04 +000074#include "llvm/Transforms/Scalar/BDCE.h"
Justin Bogner395c2122016-04-22 19:40:41 +000075#include "llvm/Transforms/Scalar/DCE.h"
Justin Bogner594e07b2016-05-17 21:38:13 +000076#include "llvm/Transforms/Scalar/DeadStoreElimination.h"
Chandler Carruthe8c686a2015-02-01 10:51:23 +000077#include "llvm/Transforms/Scalar/EarlyCSE.h"
Easwaran Raman019e0bf2016-06-03 22:54:26 +000078#include "llvm/Transforms/Scalar/GVN.h"
Davide Italiano89ab89d2016-06-14 00:49:23 +000079#include "llvm/Transforms/Scalar/GuardWidening.h"
Sanjoy Das4d4339d2016-06-05 18:01:19 +000080#include "llvm/Transforms/Scalar/IndVarSimplify.h"
Sean Silva46590d52016-06-14 00:51:09 +000081#include "llvm/Transforms/Scalar/JumpThreading.h"
Justin Bognerd0d23412016-05-03 22:02:31 +000082#include "llvm/Transforms/Scalar/LoopRotation.h"
Justin Bognerab6a5132016-05-03 21:47:32 +000083#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
Davide Italiano99223442016-05-13 22:52:35 +000084#include "llvm/Transforms/Scalar/LowerAtomic.h"
Chandler Carruth43e590e2015-01-24 11:13:02 +000085#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
Sean Silva6347df02016-06-14 02:44:55 +000086#include "llvm/Transforms/Scalar/MemCpyOptimizer.h"
Davide Italianob49aa5c2016-06-17 19:10:09 +000087#include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
Davide Italiano1021c682016-05-25 23:38:53 +000088#include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
Justin Bognerc2bf63d2016-04-26 23:39:29 +000089#include "llvm/Transforms/Scalar/Reassociate.h"
Davide Italiano98f7e0e2016-05-18 15:18:25 +000090#include "llvm/Transforms/Scalar/SCCP.h"
Chandler Carruth74a8a222016-06-17 07:15:29 +000091#include "llvm/Transforms/Scalar/SLPVectorizer.h"
Chandler Carruth29a18a42015-09-12 09:09:14 +000092#include "llvm/Transforms/Scalar/SROA.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000093#include "llvm/Transforms/Scalar/SimplifyCFG.h"
Justin Bognerb9394902016-04-22 19:54:10 +000094#include "llvm/Transforms/Scalar/Sink.h"
Xinliang David Li1eaecef2016-06-15 21:51:30 +000095#include "llvm/Transforms/Utils/AddDiscriminators.h"
Easwaran Ramane12c4872016-06-09 19:44:46 +000096#include "llvm/Transforms/Utils/LCSSA.h"
Davide Italianocccf4f02016-06-14 03:22:22 +000097#include "llvm/Transforms/Utils/Mem2Reg.h"
Geoff Berryb96d3b22016-06-01 21:30:40 +000098#include "llvm/Transforms/Utils/MemorySSA.h"
Davide Italianocccf4f02016-06-14 03:22:22 +000099
Chandler Carruth58dde8c2016-02-26 12:17:54 +0000100#include <type_traits>
Chandler Carruth66445382014-01-11 08:16:35 +0000101
102using namespace llvm;
103
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000104static Regex DefaultAliasRegex("^(default|lto-pre-link|lto)<(O[0123sz])>$");
105
Chandler Carruth66445382014-01-11 08:16:35 +0000106namespace {
107
Chandler Carruthd8330982014-01-12 09:34:22 +0000108/// \brief No-op module pass which does nothing.
Chandler Carruth66445382014-01-11 08:16:35 +0000109struct NoOpModulePass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000110 PreservedAnalyses run(Module &M, AnalysisManager<Module> &) {
111 return PreservedAnalyses::all();
112 }
Chandler Carrutha13f27c2014-01-11 11:52:05 +0000113 static StringRef name() { return "NoOpModulePass"; }
Chandler Carruth66445382014-01-11 08:16:35 +0000114};
115
Chandler Carruth0b576b32015-01-06 02:50:06 +0000116/// \brief No-op module analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000117class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
118 friend AnalysisInfoMixin<NoOpModuleAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000119 static char PassID;
120
121public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000122 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000123 Result run(Module &, AnalysisManager<Module> &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000124 static StringRef name() { return "NoOpModuleAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000125};
126
Chandler Carruth572e3402014-04-21 11:12:00 +0000127/// \brief No-op CGSCC pass which does nothing.
128struct NoOpCGSCCPass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000129 PreservedAnalyses run(LazyCallGraph::SCC &C,
130 AnalysisManager<LazyCallGraph::SCC> &) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000131 return PreservedAnalyses::all();
132 }
133 static StringRef name() { return "NoOpCGSCCPass"; }
134};
135
Chandler Carruth0b576b32015-01-06 02:50:06 +0000136/// \brief No-op CGSCC analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000137class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
138 friend AnalysisInfoMixin<NoOpCGSCCAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000139 static char PassID;
140
141public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000142 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000143 Result run(LazyCallGraph::SCC &, AnalysisManager<LazyCallGraph::SCC> &) {
144 return Result();
145 }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000146 static StringRef name() { return "NoOpCGSCCAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000147};
148
Chandler Carruthd8330982014-01-12 09:34:22 +0000149/// \brief No-op function pass which does nothing.
150struct NoOpFunctionPass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000151 PreservedAnalyses run(Function &F, AnalysisManager<Function> &) {
152 return PreservedAnalyses::all();
153 }
Chandler Carruthd8330982014-01-12 09:34:22 +0000154 static StringRef name() { return "NoOpFunctionPass"; }
155};
156
Chandler Carruth0b576b32015-01-06 02:50:06 +0000157/// \brief No-op function analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000158class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
159 friend AnalysisInfoMixin<NoOpFunctionAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000160 static char PassID;
161
162public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000163 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000164 Result run(Function &, AnalysisManager<Function> &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000165 static StringRef name() { return "NoOpFunctionAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000166};
167
Justin Bognereecc3c82016-02-25 07:23:08 +0000168/// \brief No-op loop pass which does nothing.
169struct NoOpLoopPass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000170 PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &) {
171 return PreservedAnalyses::all();
172 }
Justin Bognereecc3c82016-02-25 07:23:08 +0000173 static StringRef name() { return "NoOpLoopPass"; }
174};
175
176/// \brief No-op loop analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000177class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
178 friend AnalysisInfoMixin<NoOpLoopAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000179 static char PassID;
180
181public:
Justin Bognereecc3c82016-02-25 07:23:08 +0000182 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000183 Result run(Loop &, AnalysisManager<Loop> &) { return Result(); }
Justin Bognereecc3c82016-02-25 07:23:08 +0000184 static StringRef name() { return "NoOpLoopAnalysis"; }
Justin Bognereecc3c82016-02-25 07:23:08 +0000185};
186
Chandler Carruthb4faf132016-03-11 10:22:49 +0000187char NoOpModuleAnalysis::PassID;
188char NoOpCGSCCAnalysis::PassID;
189char NoOpFunctionAnalysis::PassID;
190char NoOpLoopAnalysis::PassID;
191
Chandler Carruth66445382014-01-11 08:16:35 +0000192} // End anonymous namespace.
193
Chandler Carruth1ff77242015-03-07 09:02:36 +0000194void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000195#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000196 MAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000197#include "PassRegistry.def"
198}
199
Chandler Carruth1ff77242015-03-07 09:02:36 +0000200void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000201#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000202 CGAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000203#include "PassRegistry.def"
204}
205
Chandler Carruth1ff77242015-03-07 09:02:36 +0000206void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000207#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000208 FAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000209#include "PassRegistry.def"
210}
211
Justin Bognereecc3c82016-02-25 07:23:08 +0000212void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000213#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
Justin Bognereecc3c82016-02-25 07:23:08 +0000214 LAM.registerPass([&] { return CREATE_PASS; });
215#include "PassRegistry.def"
216}
217
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000218void PassBuilder::addPerModuleDefaultPipeline(ModulePassManager &MPM,
219 OptimizationLevel Level,
220 bool DebugLogging) {
221 // FIXME: Finish fleshing this out to match the legacy pipelines.
222 FunctionPassManager EarlyFPM(DebugLogging);
223 EarlyFPM.addPass(SimplifyCFGPass());
224 EarlyFPM.addPass(SROA());
225 EarlyFPM.addPass(EarlyCSEPass());
226 EarlyFPM.addPass(LowerExpectIntrinsicPass());
227
228 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
229}
230
231void PassBuilder::addLTOPreLinkDefaultPipeline(ModulePassManager &MPM,
232 OptimizationLevel Level,
233 bool DebugLogging) {
234 // FIXME: We should use a customized pre-link pipeline!
235 addPerModuleDefaultPipeline(MPM, Level, DebugLogging);
236}
237
238void PassBuilder::addLTODefaultPipeline(ModulePassManager &MPM,
239 OptimizationLevel Level,
240 bool DebugLogging) {
241 // FIXME: Finish fleshing this out to match the legacy LTO pipelines.
242 FunctionPassManager LateFPM(DebugLogging);
243 LateFPM.addPass(InstCombinePass());
244 LateFPM.addPass(SimplifyCFGPass());
245
246 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(LateFPM)));
247}
248
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000249#ifndef NDEBUG
Chandler Carruth66445382014-01-11 08:16:35 +0000250static bool isModulePassName(StringRef Name) {
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000251 // Manually handle aliases for pre-configured pipeline fragments.
252 if (Name.startswith("default") || Name.startswith("lto"))
253 return DefaultAliasRegex.match(Name);
254
Chandler Carruth74a8a222016-06-17 07:15:29 +0000255#define MODULE_PASS(NAME, CREATE_PASS) \
256 if (Name == NAME) \
257 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000258#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000259 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000260 return true;
261#include "PassRegistry.def"
262
Chandler Carruth66445382014-01-11 08:16:35 +0000263 return false;
264}
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000265#endif
Chandler Carruth66445382014-01-11 08:16:35 +0000266
Chandler Carruth572e3402014-04-21 11:12:00 +0000267static bool isCGSCCPassName(StringRef Name) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000268#define CGSCC_PASS(NAME, CREATE_PASS) \
269 if (Name == NAME) \
270 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000271#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000272 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000273 return true;
274#include "PassRegistry.def"
275
Chandler Carruth572e3402014-04-21 11:12:00 +0000276 return false;
277}
278
Chandler Carruthd8330982014-01-12 09:34:22 +0000279static bool isFunctionPassName(StringRef Name) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000280#define FUNCTION_PASS(NAME, CREATE_PASS) \
281 if (Name == NAME) \
282 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000283#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000284 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000285 return true;
286#include "PassRegistry.def"
287
Chandler Carruthd8330982014-01-12 09:34:22 +0000288 return false;
289}
290
Justin Bognereecc3c82016-02-25 07:23:08 +0000291static bool isLoopPassName(StringRef Name) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000292#define LOOP_PASS(NAME, CREATE_PASS) \
293 if (Name == NAME) \
294 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +0000295#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
296 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
297 return true;
298#include "PassRegistry.def"
299
300 return false;
301}
302
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000303bool PassBuilder::parseModulePassName(ModulePassManager &MPM, StringRef Name,
304 bool DebugLogging) {
305 // Manually handle aliases for pre-configured pipeline fragments.
306 if (Name.startswith("default") || Name.startswith("lto")) {
307 SmallVector<StringRef, 3> Matches;
308 if (!DefaultAliasRegex.match(Name, &Matches))
309 return false;
310 assert(Matches.size() == 3 && "Must capture two matched strings!");
311
312 auto L = StringSwitch<OptimizationLevel>(Matches[2])
313 .Case("O0", O0)
314 .Case("O1", O1)
315 .Case("O2", O2)
316 .Case("O3", O3)
317 .Case("Os", Os)
318 .Case("Oz", Oz);
319
320 if (Matches[1] == "default") {
321 addPerModuleDefaultPipeline(MPM, L, DebugLogging);
322 } else if (Matches[1] == "lto-pre-link") {
323 addLTOPreLinkDefaultPipeline(MPM, L, DebugLogging);
324 } else {
325 assert(Matches[1] == "lto" && "Not one of the matched options!");
326 addLTODefaultPipeline(MPM, L, DebugLogging);
327 }
328 return true;
329 }
330
Chandler Carruth58944182014-04-21 08:08:50 +0000331#define MODULE_PASS(NAME, CREATE_PASS) \
332 if (Name == NAME) { \
333 MPM.addPass(CREATE_PASS); \
334 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000335 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000336#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
337 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000338 MPM.addPass(RequireAnalysisPass< \
339 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000340 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000341 } \
342 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000343 MPM.addPass(InvalidateAnalysisPass< \
344 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000345 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000346 }
347#include "PassRegistry.def"
348
Chandler Carruth66445382014-01-11 08:16:35 +0000349 return false;
350}
351
Chandler Carruth1ff77242015-03-07 09:02:36 +0000352bool PassBuilder::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000353#define CGSCC_PASS(NAME, CREATE_PASS) \
354 if (Name == NAME) { \
355 CGPM.addPass(CREATE_PASS); \
356 return true; \
357 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000358#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
359 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000360 CGPM.addPass(RequireAnalysisPass< \
361 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000362 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000363 } \
364 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000365 CGPM.addPass(InvalidateAnalysisPass< \
366 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000367 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000368 }
369#include "PassRegistry.def"
370
Chandler Carruth572e3402014-04-21 11:12:00 +0000371 return false;
372}
373
Chandler Carruth1ff77242015-03-07 09:02:36 +0000374bool PassBuilder::parseFunctionPassName(FunctionPassManager &FPM,
375 StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000376#define FUNCTION_PASS(NAME, CREATE_PASS) \
377 if (Name == NAME) { \
378 FPM.addPass(CREATE_PASS); \
379 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000380 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000381#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
382 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000383 FPM.addPass(RequireAnalysisPass< \
384 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000385 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000386 } \
387 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000388 FPM.addPass(InvalidateAnalysisPass< \
389 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000390 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000391 }
392#include "PassRegistry.def"
393
Chandler Carruthd8330982014-01-12 09:34:22 +0000394 return false;
395}
396
Chandler Carruth74a8a222016-06-17 07:15:29 +0000397bool PassBuilder::parseLoopPassName(LoopPassManager &FPM, StringRef Name) {
Justin Bognereecc3c82016-02-25 07:23:08 +0000398#define LOOP_PASS(NAME, CREATE_PASS) \
399 if (Name == NAME) { \
400 FPM.addPass(CREATE_PASS); \
401 return true; \
402 }
403#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
404 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000405 FPM.addPass(RequireAnalysisPass< \
406 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +0000407 return true; \
408 } \
409 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000410 FPM.addPass(InvalidateAnalysisPass< \
411 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +0000412 return true; \
413 }
414#include "PassRegistry.def"
415
416 return false;
417}
418
Chandler Carruthedf59962016-02-18 09:45:17 +0000419bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
Chandler Carruth45a9c202016-03-11 09:15:11 +0000420#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
421 if (Name == NAME) { \
422 AA.registerModuleAnalysis< \
423 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
424 return true; \
425 }
Chandler Carruthedf59962016-02-18 09:45:17 +0000426#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
427 if (Name == NAME) { \
Chandler Carruth58dde8c2016-02-26 12:17:54 +0000428 AA.registerFunctionAnalysis< \
429 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
Chandler Carruthedf59962016-02-18 09:45:17 +0000430 return true; \
431 }
432#include "PassRegistry.def"
433
434 return false;
435}
436
Justin Bognereecc3c82016-02-25 07:23:08 +0000437bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
438 StringRef &PipelineText,
439 bool VerifyEachPass,
440 bool DebugLogging) {
441 for (;;) {
442 // Parse nested pass managers by recursing.
443 if (PipelineText.startswith("loop(")) {
444 LoopPassManager NestedLPM(DebugLogging);
445
446 // Parse the inner pipeline inte the nested manager.
447 PipelineText = PipelineText.substr(strlen("loop("));
448 if (!parseLoopPassPipeline(NestedLPM, PipelineText, VerifyEachPass,
449 DebugLogging) ||
450 PipelineText.empty())
451 return false;
452 assert(PipelineText[0] == ')');
453 PipelineText = PipelineText.substr(1);
454
455 // Add the nested pass manager with the appropriate adaptor.
456 LPM.addPass(std::move(NestedLPM));
457 } else {
458 // Otherwise try to parse a pass name.
459 size_t End = PipelineText.find_first_of(",)");
460 if (!parseLoopPassName(LPM, PipelineText.substr(0, End)))
461 return false;
462 // TODO: Ideally, we would run a LoopVerifierPass() here in the
463 // VerifyEachPass case, but we don't have such a verifier yet.
464
465 PipelineText = PipelineText.substr(End);
466 }
467
468 if (PipelineText.empty() || PipelineText[0] == ')')
469 return true;
470
471 assert(PipelineText[0] == ',');
472 PipelineText = PipelineText.substr(1);
473 }
474}
475
Chandler Carruth1ff77242015-03-07 09:02:36 +0000476bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
477 StringRef &PipelineText,
478 bool VerifyEachPass,
479 bool DebugLogging) {
Chandler Carruthd8330982014-01-12 09:34:22 +0000480 for (;;) {
481 // Parse nested pass managers by recursing.
482 if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000483 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000484
485 // Parse the inner pipeline inte the nested manager.
486 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000487 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
488 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000489 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000490 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000491 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000492 PipelineText = PipelineText.substr(1);
493
494 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000495 FPM.addPass(std::move(NestedFPM));
Justin Bognereecc3c82016-02-25 07:23:08 +0000496 } else if (PipelineText.startswith("loop(")) {
497 LoopPassManager NestedLPM(DebugLogging);
498
499 // Parse the inner pipeline inte the nested manager.
500 PipelineText = PipelineText.substr(strlen("loop("));
501 if (!parseLoopPassPipeline(NestedLPM, PipelineText, VerifyEachPass,
502 DebugLogging) ||
503 PipelineText.empty())
504 return false;
505 assert(PipelineText[0] == ')');
506 PipelineText = PipelineText.substr(1);
507
508 // Add the nested pass manager with the appropriate adaptor.
509 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(NestedLPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000510 } else {
511 // Otherwise try to parse a pass name.
512 size_t End = PipelineText.find_first_of(",)");
513 if (!parseFunctionPassName(FPM, PipelineText.substr(0, End)))
514 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000515 if (VerifyEachPass)
516 FPM.addPass(VerifierPass());
Chandler Carruthd8330982014-01-12 09:34:22 +0000517
518 PipelineText = PipelineText.substr(End);
519 }
520
521 if (PipelineText.empty() || PipelineText[0] == ')')
522 return true;
523
524 assert(PipelineText[0] == ',');
525 PipelineText = PipelineText.substr(1);
526 }
527}
528
Chandler Carruth1ff77242015-03-07 09:02:36 +0000529bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
530 StringRef &PipelineText,
531 bool VerifyEachPass,
532 bool DebugLogging) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000533 for (;;) {
534 // Parse nested pass managers by recursing.
535 if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000536 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000537
538 // Parse the inner pipeline into the nested manager.
539 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000540 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
541 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000542 PipelineText.empty())
543 return false;
544 assert(PipelineText[0] == ')');
545 PipelineText = PipelineText.substr(1);
546
547 // Add the nested pass manager with the appropriate adaptor.
548 CGPM.addPass(std::move(NestedCGPM));
549 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000550 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000551
552 // Parse the inner pipeline inte the nested manager.
553 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000554 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
555 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000556 PipelineText.empty())
557 return false;
558 assert(PipelineText[0] == ')');
559 PipelineText = PipelineText.substr(1);
560
561 // Add the nested pass manager with the appropriate adaptor.
562 CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(NestedFPM)));
563 } else {
564 // Otherwise try to parse a pass name.
565 size_t End = PipelineText.find_first_of(",)");
566 if (!parseCGSCCPassName(CGPM, PipelineText.substr(0, End)))
567 return false;
568 // FIXME: No verifier support for CGSCC passes!
569
570 PipelineText = PipelineText.substr(End);
571 }
572
573 if (PipelineText.empty() || PipelineText[0] == ')')
574 return true;
575
576 assert(PipelineText[0] == ',');
577 PipelineText = PipelineText.substr(1);
578 }
579}
580
NAKAMURA Takumia42f5282016-05-16 10:13:37 +0000581void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM,
582 FunctionAnalysisManager &FAM,
583 CGSCCAnalysisManager &CGAM,
584 ModuleAnalysisManager &MAM) {
585 MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
586 MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
587 CGAM.registerPass([&] { return FunctionAnalysisManagerCGSCCProxy(FAM); });
588 CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
589 FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
590 FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
591 FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
592 LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
593}
594
Chandler Carruth1ff77242015-03-07 09:02:36 +0000595bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
596 StringRef &PipelineText,
597 bool VerifyEachPass,
598 bool DebugLogging) {
Chandler Carruth66445382014-01-11 08:16:35 +0000599 for (;;) {
600 // Parse nested pass managers by recursing.
601 if (PipelineText.startswith("module(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000602 ModulePassManager NestedMPM(DebugLogging);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000603
604 // Parse the inner pipeline into the nested manager.
Chandler Carruth66445382014-01-11 08:16:35 +0000605 PipelineText = PipelineText.substr(strlen("module("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000606 if (!parseModulePassPipeline(NestedMPM, PipelineText, VerifyEachPass,
607 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000608 PipelineText.empty())
Chandler Carruth66445382014-01-11 08:16:35 +0000609 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000610 assert(PipelineText[0] == ')');
Chandler Carruth66445382014-01-11 08:16:35 +0000611 PipelineText = PipelineText.substr(1);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000612
613 // Now add the nested manager as a module pass.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000614 MPM.addPass(std::move(NestedMPM));
Chandler Carruth572e3402014-04-21 11:12:00 +0000615 } else if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000616 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000617
618 // Parse the inner pipeline inte the nested manager.
619 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000620 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
621 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000622 PipelineText.empty())
623 return false;
624 assert(PipelineText[0] == ')');
625 PipelineText = PipelineText.substr(1);
626
627 // Add the nested pass manager with the appropriate adaptor.
628 MPM.addPass(
629 createModuleToPostOrderCGSCCPassAdaptor(std::move(NestedCGPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000630 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000631 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000632
633 // Parse the inner pipeline inte the nested manager.
634 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000635 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
636 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000637 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000638 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000639 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000640 PipelineText = PipelineText.substr(1);
641
642 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000643 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(NestedFPM)));
Chandler Carruth66445382014-01-11 08:16:35 +0000644 } else {
645 // Otherwise try to parse a pass name.
646 size_t End = PipelineText.find_first_of(",)");
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000647 if (!parseModulePassName(MPM, PipelineText.substr(0, End), DebugLogging))
Chandler Carruth66445382014-01-11 08:16:35 +0000648 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000649 if (VerifyEachPass)
650 MPM.addPass(VerifierPass());
Chandler Carruth66445382014-01-11 08:16:35 +0000651
652 PipelineText = PipelineText.substr(End);
653 }
654
655 if (PipelineText.empty() || PipelineText[0] == ')')
656 return true;
657
658 assert(PipelineText[0] == ',');
659 PipelineText = PipelineText.substr(1);
660 }
661}
662
663// Primary pass pipeline description parsing routine.
664// FIXME: Should this routine accept a TargetMachine or require the caller to
665// pre-populate the analysis managers with target-specific stuff?
Chandler Carruth1ff77242015-03-07 09:02:36 +0000666bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
667 StringRef PipelineText, bool VerifyEachPass,
668 bool DebugLogging) {
Chandler Carruthea368f12015-01-06 08:37:58 +0000669 // By default, try to parse the pipeline as-if it were within an implicit
670 // 'module(...)' pass pipeline. If this will parse at all, it needs to
671 // consume the entire string.
Chandler Carruth14a759e2015-01-13 22:42:38 +0000672 if (parseModulePassPipeline(MPM, PipelineText, VerifyEachPass, DebugLogging))
Chandler Carruthea368f12015-01-06 08:37:58 +0000673 return PipelineText.empty();
Chandler Carruth66445382014-01-11 08:16:35 +0000674
Chandler Carruthea368f12015-01-06 08:37:58 +0000675 // This isn't parsable as a module pipeline, look for the end of a pass name
676 // and directly drop down to that layer.
Chandler Carruth6546cb62014-01-12 10:02:02 +0000677 StringRef FirstName =
678 PipelineText.substr(0, PipelineText.find_first_of(",)"));
Chandler Carruthea368f12015-01-06 08:37:58 +0000679 assert(!isModulePassName(FirstName) &&
680 "Already handled all module pipeline options.");
Chandler Carruth66445382014-01-11 08:16:35 +0000681
Chandler Carruthea368f12015-01-06 08:37:58 +0000682 // If this looks like a CGSCC pass, parse the whole thing as a CGSCC
683 // pipeline.
Justin Bognereecc3c82016-02-25 07:23:08 +0000684 if (PipelineText.startswith("cgscc(") || isCGSCCPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000685 CGSCCPassManager CGPM(DebugLogging);
686 if (!parseCGSCCPassPipeline(CGPM, PipelineText, VerifyEachPass,
687 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000688 !PipelineText.empty())
689 return false;
690 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
691 return true;
692 }
693
Chandler Carruthea368f12015-01-06 08:37:58 +0000694 // Similarly, if this looks like a Function pass, parse the whole thing as
695 // a Function pipelien.
Justin Bognereecc3c82016-02-25 07:23:08 +0000696 if (PipelineText.startswith("function(") || isFunctionPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000697 FunctionPassManager FPM(DebugLogging);
698 if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass,
699 DebugLogging) ||
Chandler Carruth4d356312014-01-20 11:34:08 +0000700 !PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000701 return false;
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000702 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000703 return true;
704 }
Chandler Carruth66445382014-01-11 08:16:35 +0000705
Justin Bognereecc3c82016-02-25 07:23:08 +0000706 // If this looks like a Loop pass, parse the whole thing as a Loop pipeline.
707 if (PipelineText.startswith("loop(") || isLoopPassName(FirstName)) {
708 LoopPassManager LPM(DebugLogging);
709 if (!parseLoopPassPipeline(LPM, PipelineText, VerifyEachPass,
710 DebugLogging) ||
711 !PipelineText.empty())
712 return false;
713 FunctionPassManager FPM(DebugLogging);
714 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM)));
715 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
716 return true;
717 }
718
Chandler Carruth66445382014-01-11 08:16:35 +0000719 return false;
720}
Chandler Carruthedf59962016-02-18 09:45:17 +0000721
722bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) {
723 while (!PipelineText.empty()) {
724 StringRef Name;
725 std::tie(Name, PipelineText) = PipelineText.split(',');
726 if (!parseAAPassName(AA, Name))
727 return false;
728 }
729
730 return true;
731}