blob: fe9e4cffcbd8f208299a6e1b588f9c6ecc2ff357 [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"
Xinliang David Li8a021312016-07-02 21:18:40 +000036#include "llvm/Analysis/LoopAccessAnalysis.h"
Chandler Carruthaaf0b4c2015-01-20 10:58:50 +000037#include "llvm/Analysis/LoopInfo.h"
Chandler Carruth61440d22016-03-10 00:55:30 +000038#include "llvm/Analysis/MemoryDependenceAnalysis.h"
Hongbin Zheng3f978402016-02-25 17:54:07 +000039#include "llvm/Analysis/PostDominators.h"
Easwaran Raman019e0bf2016-06-03 22:54:26 +000040#include "llvm/Analysis/ProfileSummaryInfo.h"
Hongbin Zhengbc539772016-02-25 17:54:25 +000041#include "llvm/Analysis/RegionInfo.h"
Chandler Carruth2f1fd162015-08-17 02:08:17 +000042#include "llvm/Analysis/ScalarEvolution.h"
Chandler Carruth2b3d0442016-02-20 04:01:45 +000043#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
Chandler Carruthd6091a02016-02-20 04:03:06 +000044#include "llvm/Analysis/ScopedNoAliasAA.h"
Chandler Carruth8ca43222015-01-15 11:39:46 +000045#include "llvm/Analysis/TargetLibraryInfo.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000046#include "llvm/Analysis/TargetTransformInfo.h"
Chandler Carruthc1dc3842016-02-20 04:04:52 +000047#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
Michael Kuperstein82d5da52016-06-24 20:13:42 +000048#include "llvm/CodeGen/PreISelIntrinsicLowering.h"
Chandler Carruth64764b42015-01-14 10:19:28 +000049#include "llvm/IR/Dominators.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000050#include "llvm/IR/IRPrintingPasses.h"
Chandler Carruth66445382014-01-11 08:16:35 +000051#include "llvm/IR/PassManager.h"
Chandler Carruth4d356312014-01-20 11:34:08 +000052#include "llvm/IR/Verifier.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000053#include "llvm/Support/Debug.h"
Chandler Carruth8b5a74192016-02-28 22:16:03 +000054#include "llvm/Support/Regex.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000055#include "llvm/Target/TargetMachine.h"
Xinliang David Li64dbb292016-06-05 05:12:23 +000056#include "llvm/Transforms/GCOVProfiler.h"
Davide Italiano164b9bc2016-05-05 00:51:09 +000057#include "llvm/Transforms/IPO/ConstantMerge.h"
Sean Silvae3bb4572016-06-12 09:16:39 +000058#include "llvm/Transforms/IPO/DeadArgumentElimination.h"
Davide Italiano344e8382016-05-05 02:37:32 +000059#include "llvm/Transforms/IPO/ElimAvailExtern.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000060#include "llvm/Transforms/IPO/ForceFunctionAttrs.h"
Chandler Carruth9c4ed172016-02-18 11:03:11 +000061#include "llvm/Transforms/IPO/FunctionAttrs.h"
Davide Italiano66228c42016-05-03 19:39:15 +000062#include "llvm/Transforms/IPO/GlobalDCE.h"
Justin Bogner1a075012016-04-26 00:28:01 +000063#include "llvm/Transforms/IPO/GlobalOpt.h"
Chandler Carruth3a040e62015-12-27 08:41:34 +000064#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
Justin Bogner4563a062016-04-26 20:15:52 +000065#include "llvm/Transforms/IPO/Internalize.h"
Easwaran Raman1832bf62016-06-27 16:50:18 +000066#include "llvm/Transforms/IPO/PartialInlining.h"
Davide Italianof54f2f02016-05-05 21:05:36 +000067#include "llvm/Transforms/IPO/SCCP.h"
Justin Bogner21e15372015-10-30 23:28:12 +000068#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
Davide Italianod737dd22016-06-14 21:44:19 +000069#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000070#include "llvm/Transforms/InstCombine/InstCombine.h"
Xinliang David Lie6b89292016-04-18 17:47:38 +000071#include "llvm/Transforms/InstrProfiling.h"
Xinliang David Li8aebf442016-05-06 05:49:19 +000072#include "llvm/Transforms/PGOInstrumentation.h"
Xinliang David Lid38392e2016-05-27 23:20:16 +000073#include "llvm/Transforms/SampleProfile.h"
Justin Bogner19b67992015-10-30 23:13:18 +000074#include "llvm/Transforms/Scalar/ADCE.h"
Sean Silvaa4c2d152016-06-15 06:18:01 +000075#include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h"
Davide Italiano655a1452016-05-25 01:57:04 +000076#include "llvm/Transforms/Scalar/BDCE.h"
Justin Bogner395c2122016-04-22 19:40:41 +000077#include "llvm/Transforms/Scalar/DCE.h"
Michael Kuperstein071d8302016-07-02 00:16:47 +000078#include "llvm/Transforms/Scalar/ConstantHoisting.h"
Justin Bogner594e07b2016-05-17 21:38:13 +000079#include "llvm/Transforms/Scalar/DeadStoreElimination.h"
Chandler Carruthe8c686a2015-02-01 10:51:23 +000080#include "llvm/Transforms/Scalar/EarlyCSE.h"
Michael Kuperstein83b753d2016-06-24 23:32:02 +000081#include "llvm/Transforms/Scalar/Float2Int.h"
Easwaran Raman019e0bf2016-06-03 22:54:26 +000082#include "llvm/Transforms/Scalar/GVN.h"
Davide Italiano89ab89d2016-06-14 00:49:23 +000083#include "llvm/Transforms/Scalar/GuardWidening.h"
Sanjoy Das4d4339d2016-06-05 18:01:19 +000084#include "llvm/Transforms/Scalar/IndVarSimplify.h"
Sean Silva46590d52016-06-14 00:51:09 +000085#include "llvm/Transforms/Scalar/JumpThreading.h"
Justin Bognerd0d23412016-05-03 22:02:31 +000086#include "llvm/Transforms/Scalar/LoopRotation.h"
Justin Bognerab6a5132016-05-03 21:47:32 +000087#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
Davide Italiano99223442016-05-13 22:52:35 +000088#include "llvm/Transforms/Scalar/LowerAtomic.h"
Chandler Carruth43e590e2015-01-24 11:13:02 +000089#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
Sean Silva6347df02016-06-14 02:44:55 +000090#include "llvm/Transforms/Scalar/MemCpyOptimizer.h"
Davide Italianob49aa5c2016-06-17 19:10:09 +000091#include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
Davide Italiano1021c682016-05-25 23:38:53 +000092#include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
Justin Bognerc2bf63d2016-04-26 23:39:29 +000093#include "llvm/Transforms/Scalar/Reassociate.h"
Davide Italiano98f7e0e2016-05-18 15:18:25 +000094#include "llvm/Transforms/Scalar/SCCP.h"
Chandler Carruth74a8a222016-06-17 07:15:29 +000095#include "llvm/Transforms/Scalar/SLPVectorizer.h"
Chandler Carruth29a18a42015-09-12 09:09:14 +000096#include "llvm/Transforms/Scalar/SROA.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000097#include "llvm/Transforms/Scalar/SimplifyCFG.h"
Justin Bognerb9394902016-04-22 19:54:10 +000098#include "llvm/Transforms/Scalar/Sink.h"
Xinliang David Li1eaecef2016-06-15 21:51:30 +000099#include "llvm/Transforms/Utils/AddDiscriminators.h"
Easwaran Ramane12c4872016-06-09 19:44:46 +0000100#include "llvm/Transforms/Utils/LCSSA.h"
Davide Italianocccf4f02016-06-14 03:22:22 +0000101#include "llvm/Transforms/Utils/Mem2Reg.h"
Geoff Berryb96d3b22016-06-01 21:30:40 +0000102#include "llvm/Transforms/Utils/MemorySSA.h"
Davide Italianocccf4f02016-06-14 03:22:22 +0000103
Chandler Carruth58dde8c2016-02-26 12:17:54 +0000104#include <type_traits>
Chandler Carruth66445382014-01-11 08:16:35 +0000105
106using namespace llvm;
107
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000108static Regex DefaultAliasRegex("^(default|lto-pre-link|lto)<(O[0123sz])>$");
109
Chandler Carruth66445382014-01-11 08:16:35 +0000110namespace {
111
Chandler Carruthd8330982014-01-12 09:34:22 +0000112/// \brief No-op module pass which does nothing.
Chandler Carruth66445382014-01-11 08:16:35 +0000113struct NoOpModulePass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000114 PreservedAnalyses run(Module &M, AnalysisManager<Module> &) {
115 return PreservedAnalyses::all();
116 }
Chandler Carrutha13f27c2014-01-11 11:52:05 +0000117 static StringRef name() { return "NoOpModulePass"; }
Chandler Carruth66445382014-01-11 08:16:35 +0000118};
119
Chandler Carruth0b576b32015-01-06 02:50:06 +0000120/// \brief No-op module analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000121class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
122 friend AnalysisInfoMixin<NoOpModuleAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000123 static char PassID;
124
125public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000126 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000127 Result run(Module &, AnalysisManager<Module> &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000128 static StringRef name() { return "NoOpModuleAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000129};
130
Chandler Carruth572e3402014-04-21 11:12:00 +0000131/// \brief No-op CGSCC pass which does nothing.
132struct NoOpCGSCCPass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000133 PreservedAnalyses run(LazyCallGraph::SCC &C,
134 AnalysisManager<LazyCallGraph::SCC> &) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000135 return PreservedAnalyses::all();
136 }
137 static StringRef name() { return "NoOpCGSCCPass"; }
138};
139
Chandler Carruth0b576b32015-01-06 02:50:06 +0000140/// \brief No-op CGSCC analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000141class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
142 friend AnalysisInfoMixin<NoOpCGSCCAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000143 static char PassID;
144
145public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000146 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000147 Result run(LazyCallGraph::SCC &, AnalysisManager<LazyCallGraph::SCC> &) {
148 return Result();
149 }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000150 static StringRef name() { return "NoOpCGSCCAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000151};
152
Chandler Carruthd8330982014-01-12 09:34:22 +0000153/// \brief No-op function pass which does nothing.
154struct NoOpFunctionPass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000155 PreservedAnalyses run(Function &F, AnalysisManager<Function> &) {
156 return PreservedAnalyses::all();
157 }
Chandler Carruthd8330982014-01-12 09:34:22 +0000158 static StringRef name() { return "NoOpFunctionPass"; }
159};
160
Chandler Carruth0b576b32015-01-06 02:50:06 +0000161/// \brief No-op function analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000162class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
163 friend AnalysisInfoMixin<NoOpFunctionAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000164 static char PassID;
165
166public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000167 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000168 Result run(Function &, AnalysisManager<Function> &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000169 static StringRef name() { return "NoOpFunctionAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000170};
171
Justin Bognereecc3c82016-02-25 07:23:08 +0000172/// \brief No-op loop pass which does nothing.
173struct NoOpLoopPass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000174 PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &) {
175 return PreservedAnalyses::all();
176 }
Justin Bognereecc3c82016-02-25 07:23:08 +0000177 static StringRef name() { return "NoOpLoopPass"; }
178};
179
180/// \brief No-op loop analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000181class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
182 friend AnalysisInfoMixin<NoOpLoopAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000183 static char PassID;
184
185public:
Justin Bognereecc3c82016-02-25 07:23:08 +0000186 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000187 Result run(Loop &, AnalysisManager<Loop> &) { return Result(); }
Justin Bognereecc3c82016-02-25 07:23:08 +0000188 static StringRef name() { return "NoOpLoopAnalysis"; }
Justin Bognereecc3c82016-02-25 07:23:08 +0000189};
190
Chandler Carruthb4faf132016-03-11 10:22:49 +0000191char NoOpModuleAnalysis::PassID;
192char NoOpCGSCCAnalysis::PassID;
193char NoOpFunctionAnalysis::PassID;
194char NoOpLoopAnalysis::PassID;
195
Chandler Carruth66445382014-01-11 08:16:35 +0000196} // End anonymous namespace.
197
Chandler Carruth1ff77242015-03-07 09:02:36 +0000198void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000199#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000200 MAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000201#include "PassRegistry.def"
202}
203
Chandler Carruth1ff77242015-03-07 09:02:36 +0000204void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000205#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000206 CGAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000207#include "PassRegistry.def"
208}
209
Chandler Carruth1ff77242015-03-07 09:02:36 +0000210void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000211#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000212 FAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000213#include "PassRegistry.def"
214}
215
Justin Bognereecc3c82016-02-25 07:23:08 +0000216void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000217#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
Justin Bognereecc3c82016-02-25 07:23:08 +0000218 LAM.registerPass([&] { return CREATE_PASS; });
219#include "PassRegistry.def"
220}
221
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000222void PassBuilder::addPerModuleDefaultPipeline(ModulePassManager &MPM,
223 OptimizationLevel Level,
224 bool DebugLogging) {
225 // FIXME: Finish fleshing this out to match the legacy pipelines.
226 FunctionPassManager EarlyFPM(DebugLogging);
227 EarlyFPM.addPass(SimplifyCFGPass());
228 EarlyFPM.addPass(SROA());
229 EarlyFPM.addPass(EarlyCSEPass());
230 EarlyFPM.addPass(LowerExpectIntrinsicPass());
231
232 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
233}
234
235void PassBuilder::addLTOPreLinkDefaultPipeline(ModulePassManager &MPM,
236 OptimizationLevel Level,
237 bool DebugLogging) {
238 // FIXME: We should use a customized pre-link pipeline!
239 addPerModuleDefaultPipeline(MPM, Level, DebugLogging);
240}
241
242void PassBuilder::addLTODefaultPipeline(ModulePassManager &MPM,
243 OptimizationLevel Level,
244 bool DebugLogging) {
245 // FIXME: Finish fleshing this out to match the legacy LTO pipelines.
246 FunctionPassManager LateFPM(DebugLogging);
247 LateFPM.addPass(InstCombinePass());
248 LateFPM.addPass(SimplifyCFGPass());
249
250 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(LateFPM)));
251}
252
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000253#ifndef NDEBUG
Chandler Carruth66445382014-01-11 08:16:35 +0000254static bool isModulePassName(StringRef Name) {
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000255 // Manually handle aliases for pre-configured pipeline fragments.
256 if (Name.startswith("default") || Name.startswith("lto"))
257 return DefaultAliasRegex.match(Name);
258
Chandler Carruth74a8a222016-06-17 07:15:29 +0000259#define MODULE_PASS(NAME, CREATE_PASS) \
260 if (Name == NAME) \
261 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000262#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000263 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000264 return true;
265#include "PassRegistry.def"
266
Chandler Carruth66445382014-01-11 08:16:35 +0000267 return false;
268}
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000269#endif
Chandler Carruth66445382014-01-11 08:16:35 +0000270
Chandler Carruth572e3402014-04-21 11:12:00 +0000271static bool isCGSCCPassName(StringRef Name) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000272#define CGSCC_PASS(NAME, CREATE_PASS) \
273 if (Name == NAME) \
274 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000275#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000276 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000277 return true;
278#include "PassRegistry.def"
279
Chandler Carruth572e3402014-04-21 11:12:00 +0000280 return false;
281}
282
Chandler Carruthd8330982014-01-12 09:34:22 +0000283static bool isFunctionPassName(StringRef Name) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000284#define FUNCTION_PASS(NAME, CREATE_PASS) \
285 if (Name == NAME) \
286 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000287#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000288 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000289 return true;
290#include "PassRegistry.def"
291
Chandler Carruthd8330982014-01-12 09:34:22 +0000292 return false;
293}
294
Justin Bognereecc3c82016-02-25 07:23:08 +0000295static bool isLoopPassName(StringRef Name) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000296#define LOOP_PASS(NAME, CREATE_PASS) \
297 if (Name == NAME) \
298 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +0000299#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
300 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
301 return true;
302#include "PassRegistry.def"
303
304 return false;
305}
306
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000307bool PassBuilder::parseModulePassName(ModulePassManager &MPM, StringRef Name,
308 bool DebugLogging) {
309 // Manually handle aliases for pre-configured pipeline fragments.
310 if (Name.startswith("default") || Name.startswith("lto")) {
311 SmallVector<StringRef, 3> Matches;
312 if (!DefaultAliasRegex.match(Name, &Matches))
313 return false;
314 assert(Matches.size() == 3 && "Must capture two matched strings!");
315
316 auto L = StringSwitch<OptimizationLevel>(Matches[2])
317 .Case("O0", O0)
318 .Case("O1", O1)
319 .Case("O2", O2)
320 .Case("O3", O3)
321 .Case("Os", Os)
322 .Case("Oz", Oz);
323
324 if (Matches[1] == "default") {
325 addPerModuleDefaultPipeline(MPM, L, DebugLogging);
326 } else if (Matches[1] == "lto-pre-link") {
327 addLTOPreLinkDefaultPipeline(MPM, L, DebugLogging);
328 } else {
329 assert(Matches[1] == "lto" && "Not one of the matched options!");
330 addLTODefaultPipeline(MPM, L, DebugLogging);
331 }
332 return true;
333 }
334
Chandler Carruth58944182014-04-21 08:08:50 +0000335#define MODULE_PASS(NAME, CREATE_PASS) \
336 if (Name == NAME) { \
337 MPM.addPass(CREATE_PASS); \
338 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000339 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000340#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
341 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000342 MPM.addPass(RequireAnalysisPass< \
343 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000344 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000345 } \
346 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000347 MPM.addPass(InvalidateAnalysisPass< \
348 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000349 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000350 }
351#include "PassRegistry.def"
352
Chandler Carruth66445382014-01-11 08:16:35 +0000353 return false;
354}
355
Chandler Carruth1ff77242015-03-07 09:02:36 +0000356bool PassBuilder::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000357#define CGSCC_PASS(NAME, CREATE_PASS) \
358 if (Name == NAME) { \
359 CGPM.addPass(CREATE_PASS); \
360 return true; \
361 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000362#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
363 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000364 CGPM.addPass(RequireAnalysisPass< \
365 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000366 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000367 } \
368 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000369 CGPM.addPass(InvalidateAnalysisPass< \
370 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000371 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000372 }
373#include "PassRegistry.def"
374
Chandler Carruth572e3402014-04-21 11:12:00 +0000375 return false;
376}
377
Chandler Carruth1ff77242015-03-07 09:02:36 +0000378bool PassBuilder::parseFunctionPassName(FunctionPassManager &FPM,
379 StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000380#define FUNCTION_PASS(NAME, CREATE_PASS) \
381 if (Name == NAME) { \
382 FPM.addPass(CREATE_PASS); \
383 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000384 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000385#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
386 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000387 FPM.addPass(RequireAnalysisPass< \
388 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000389 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000390 } \
391 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000392 FPM.addPass(InvalidateAnalysisPass< \
393 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000394 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000395 }
396#include "PassRegistry.def"
397
Chandler Carruthd8330982014-01-12 09:34:22 +0000398 return false;
399}
400
Chandler Carruth74a8a222016-06-17 07:15:29 +0000401bool PassBuilder::parseLoopPassName(LoopPassManager &FPM, StringRef Name) {
Justin Bognereecc3c82016-02-25 07:23:08 +0000402#define LOOP_PASS(NAME, CREATE_PASS) \
403 if (Name == NAME) { \
404 FPM.addPass(CREATE_PASS); \
405 return true; \
406 }
407#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
408 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000409 FPM.addPass(RequireAnalysisPass< \
410 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +0000411 return true; \
412 } \
413 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000414 FPM.addPass(InvalidateAnalysisPass< \
415 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +0000416 return true; \
417 }
418#include "PassRegistry.def"
419
420 return false;
421}
422
Chandler Carruthedf59962016-02-18 09:45:17 +0000423bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
Chandler Carruth45a9c202016-03-11 09:15:11 +0000424#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
425 if (Name == NAME) { \
426 AA.registerModuleAnalysis< \
427 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
428 return true; \
429 }
Chandler Carruthedf59962016-02-18 09:45:17 +0000430#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
431 if (Name == NAME) { \
Chandler Carruth58dde8c2016-02-26 12:17:54 +0000432 AA.registerFunctionAnalysis< \
433 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
Chandler Carruthedf59962016-02-18 09:45:17 +0000434 return true; \
435 }
436#include "PassRegistry.def"
437
438 return false;
439}
440
Justin Bognereecc3c82016-02-25 07:23:08 +0000441bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
442 StringRef &PipelineText,
443 bool VerifyEachPass,
444 bool DebugLogging) {
445 for (;;) {
446 // Parse nested pass managers by recursing.
447 if (PipelineText.startswith("loop(")) {
448 LoopPassManager NestedLPM(DebugLogging);
449
450 // Parse the inner pipeline inte the nested manager.
451 PipelineText = PipelineText.substr(strlen("loop("));
452 if (!parseLoopPassPipeline(NestedLPM, PipelineText, VerifyEachPass,
453 DebugLogging) ||
454 PipelineText.empty())
455 return false;
456 assert(PipelineText[0] == ')');
457 PipelineText = PipelineText.substr(1);
458
459 // Add the nested pass manager with the appropriate adaptor.
460 LPM.addPass(std::move(NestedLPM));
461 } else {
462 // Otherwise try to parse a pass name.
463 size_t End = PipelineText.find_first_of(",)");
464 if (!parseLoopPassName(LPM, PipelineText.substr(0, End)))
465 return false;
466 // TODO: Ideally, we would run a LoopVerifierPass() here in the
467 // VerifyEachPass case, but we don't have such a verifier yet.
468
469 PipelineText = PipelineText.substr(End);
470 }
471
472 if (PipelineText.empty() || PipelineText[0] == ')')
473 return true;
474
475 assert(PipelineText[0] == ',');
476 PipelineText = PipelineText.substr(1);
477 }
478}
479
Chandler Carruth1ff77242015-03-07 09:02:36 +0000480bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
481 StringRef &PipelineText,
482 bool VerifyEachPass,
483 bool DebugLogging) {
Chandler Carruthd8330982014-01-12 09:34:22 +0000484 for (;;) {
485 // Parse nested pass managers by recursing.
486 if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000487 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000488
489 // Parse the inner pipeline inte the nested manager.
490 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000491 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
492 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000493 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000494 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000495 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000496 PipelineText = PipelineText.substr(1);
497
498 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000499 FPM.addPass(std::move(NestedFPM));
Justin Bognereecc3c82016-02-25 07:23:08 +0000500 } else if (PipelineText.startswith("loop(")) {
501 LoopPassManager NestedLPM(DebugLogging);
502
503 // Parse the inner pipeline inte the nested manager.
504 PipelineText = PipelineText.substr(strlen("loop("));
505 if (!parseLoopPassPipeline(NestedLPM, PipelineText, VerifyEachPass,
506 DebugLogging) ||
507 PipelineText.empty())
508 return false;
509 assert(PipelineText[0] == ')');
510 PipelineText = PipelineText.substr(1);
511
512 // Add the nested pass manager with the appropriate adaptor.
513 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(NestedLPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000514 } else {
515 // Otherwise try to parse a pass name.
516 size_t End = PipelineText.find_first_of(",)");
517 if (!parseFunctionPassName(FPM, PipelineText.substr(0, End)))
518 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000519 if (VerifyEachPass)
520 FPM.addPass(VerifierPass());
Chandler Carruthd8330982014-01-12 09:34:22 +0000521
522 PipelineText = PipelineText.substr(End);
523 }
524
525 if (PipelineText.empty() || PipelineText[0] == ')')
526 return true;
527
528 assert(PipelineText[0] == ',');
529 PipelineText = PipelineText.substr(1);
530 }
531}
532
Chandler Carruth1ff77242015-03-07 09:02:36 +0000533bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
534 StringRef &PipelineText,
535 bool VerifyEachPass,
536 bool DebugLogging) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000537 for (;;) {
538 // Parse nested pass managers by recursing.
539 if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000540 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000541
542 // Parse the inner pipeline into the nested manager.
543 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000544 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
545 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000546 PipelineText.empty())
547 return false;
548 assert(PipelineText[0] == ')');
549 PipelineText = PipelineText.substr(1);
550
551 // Add the nested pass manager with the appropriate adaptor.
552 CGPM.addPass(std::move(NestedCGPM));
553 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000554 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000555
556 // Parse the inner pipeline inte the nested manager.
557 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000558 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
559 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000560 PipelineText.empty())
561 return false;
562 assert(PipelineText[0] == ')');
563 PipelineText = PipelineText.substr(1);
564
565 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthdca83402016-06-27 23:26:08 +0000566 CGPM.addPass(
567 createCGSCCToFunctionPassAdaptor(std::move(NestedFPM), DebugLogging));
Chandler Carruth572e3402014-04-21 11:12:00 +0000568 } else {
569 // Otherwise try to parse a pass name.
570 size_t End = PipelineText.find_first_of(",)");
571 if (!parseCGSCCPassName(CGPM, PipelineText.substr(0, End)))
572 return false;
573 // FIXME: No verifier support for CGSCC passes!
574
575 PipelineText = PipelineText.substr(End);
576 }
577
578 if (PipelineText.empty() || PipelineText[0] == ')')
579 return true;
580
581 assert(PipelineText[0] == ',');
582 PipelineText = PipelineText.substr(1);
583 }
584}
585
NAKAMURA Takumia42f5282016-05-16 10:13:37 +0000586void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM,
587 FunctionAnalysisManager &FAM,
588 CGSCCAnalysisManager &CGAM,
589 ModuleAnalysisManager &MAM) {
590 MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
591 MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
592 CGAM.registerPass([&] { return FunctionAnalysisManagerCGSCCProxy(FAM); });
593 CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
594 FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
595 FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
596 FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
597 LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
598}
599
Chandler Carruth1ff77242015-03-07 09:02:36 +0000600bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
601 StringRef &PipelineText,
602 bool VerifyEachPass,
603 bool DebugLogging) {
Chandler Carruth66445382014-01-11 08:16:35 +0000604 for (;;) {
605 // Parse nested pass managers by recursing.
606 if (PipelineText.startswith("module(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000607 ModulePassManager NestedMPM(DebugLogging);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000608
609 // Parse the inner pipeline into the nested manager.
Chandler Carruth66445382014-01-11 08:16:35 +0000610 PipelineText = PipelineText.substr(strlen("module("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000611 if (!parseModulePassPipeline(NestedMPM, PipelineText, VerifyEachPass,
612 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000613 PipelineText.empty())
Chandler Carruth66445382014-01-11 08:16:35 +0000614 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000615 assert(PipelineText[0] == ')');
Chandler Carruth66445382014-01-11 08:16:35 +0000616 PipelineText = PipelineText.substr(1);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000617
618 // Now add the nested manager as a module pass.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000619 MPM.addPass(std::move(NestedMPM));
Chandler Carruth572e3402014-04-21 11:12:00 +0000620 } else if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000621 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000622
623 // Parse the inner pipeline inte the nested manager.
624 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000625 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
626 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000627 PipelineText.empty())
628 return false;
629 assert(PipelineText[0] == ')');
630 PipelineText = PipelineText.substr(1);
631
632 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthdca83402016-06-27 23:26:08 +0000633 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(NestedCGPM),
634 DebugLogging));
Chandler Carruthd8330982014-01-12 09:34:22 +0000635 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000636 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000637
638 // Parse the inner pipeline inte the nested manager.
639 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000640 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
641 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000642 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000643 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000644 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000645 PipelineText = PipelineText.substr(1);
646
647 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000648 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(NestedFPM)));
Chandler Carruth66445382014-01-11 08:16:35 +0000649 } else {
650 // Otherwise try to parse a pass name.
651 size_t End = PipelineText.find_first_of(",)");
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000652 if (!parseModulePassName(MPM, PipelineText.substr(0, End), DebugLogging))
Chandler Carruth66445382014-01-11 08:16:35 +0000653 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000654 if (VerifyEachPass)
655 MPM.addPass(VerifierPass());
Chandler Carruth66445382014-01-11 08:16:35 +0000656
657 PipelineText = PipelineText.substr(End);
658 }
659
660 if (PipelineText.empty() || PipelineText[0] == ')')
661 return true;
662
663 assert(PipelineText[0] == ',');
664 PipelineText = PipelineText.substr(1);
665 }
666}
667
668// Primary pass pipeline description parsing routine.
669// FIXME: Should this routine accept a TargetMachine or require the caller to
670// pre-populate the analysis managers with target-specific stuff?
Chandler Carruth1ff77242015-03-07 09:02:36 +0000671bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
672 StringRef PipelineText, bool VerifyEachPass,
673 bool DebugLogging) {
Chandler Carruthea368f12015-01-06 08:37:58 +0000674 // By default, try to parse the pipeline as-if it were within an implicit
675 // 'module(...)' pass pipeline. If this will parse at all, it needs to
676 // consume the entire string.
Chandler Carruth14a759e2015-01-13 22:42:38 +0000677 if (parseModulePassPipeline(MPM, PipelineText, VerifyEachPass, DebugLogging))
Chandler Carruthea368f12015-01-06 08:37:58 +0000678 return PipelineText.empty();
Chandler Carruth66445382014-01-11 08:16:35 +0000679
Chandler Carruthea368f12015-01-06 08:37:58 +0000680 // This isn't parsable as a module pipeline, look for the end of a pass name
681 // and directly drop down to that layer.
Chandler Carruth6546cb62014-01-12 10:02:02 +0000682 StringRef FirstName =
683 PipelineText.substr(0, PipelineText.find_first_of(",)"));
Chandler Carruthea368f12015-01-06 08:37:58 +0000684 assert(!isModulePassName(FirstName) &&
685 "Already handled all module pipeline options.");
Chandler Carruth66445382014-01-11 08:16:35 +0000686
Chandler Carruthea368f12015-01-06 08:37:58 +0000687 // If this looks like a CGSCC pass, parse the whole thing as a CGSCC
688 // pipeline.
Justin Bognereecc3c82016-02-25 07:23:08 +0000689 if (PipelineText.startswith("cgscc(") || isCGSCCPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000690 CGSCCPassManager CGPM(DebugLogging);
691 if (!parseCGSCCPassPipeline(CGPM, PipelineText, VerifyEachPass,
692 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000693 !PipelineText.empty())
694 return false;
Chandler Carruthdca83402016-06-27 23:26:08 +0000695 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM), DebugLogging));
Chandler Carruth572e3402014-04-21 11:12:00 +0000696 return true;
697 }
698
Chandler Carruthea368f12015-01-06 08:37:58 +0000699 // Similarly, if this looks like a Function pass, parse the whole thing as
700 // a Function pipelien.
Justin Bognereecc3c82016-02-25 07:23:08 +0000701 if (PipelineText.startswith("function(") || isFunctionPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000702 FunctionPassManager FPM(DebugLogging);
703 if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass,
704 DebugLogging) ||
Chandler Carruth4d356312014-01-20 11:34:08 +0000705 !PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000706 return false;
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000707 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000708 return true;
709 }
Chandler Carruth66445382014-01-11 08:16:35 +0000710
Justin Bognereecc3c82016-02-25 07:23:08 +0000711 // If this looks like a Loop pass, parse the whole thing as a Loop pipeline.
712 if (PipelineText.startswith("loop(") || isLoopPassName(FirstName)) {
713 LoopPassManager LPM(DebugLogging);
714 if (!parseLoopPassPipeline(LPM, PipelineText, VerifyEachPass,
715 DebugLogging) ||
716 !PipelineText.empty())
717 return false;
718 FunctionPassManager FPM(DebugLogging);
719 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM)));
720 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
721 return true;
722 }
723
Chandler Carruth66445382014-01-11 08:16:35 +0000724 return false;
725}
Chandler Carruthedf59962016-02-18 09:45:17 +0000726
727bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) {
728 while (!PipelineText.empty()) {
729 StringRef Name;
730 std::tie(Name, PipelineText) = PipelineText.split(',');
731 if (!parseAAPassName(AA, Name))
732 return false;
733 }
734
735 return true;
736}