blob: 58bd55b92f98ef5e11a4f830a745576731243d68 [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"
George Burgess IVbfa401e2016-07-06 00:26:41 +000027#include "llvm/Analysis/CFLAndersAliasAnalysis.h"
28#include "llvm/Analysis/CFLSteensAliasAnalysis.h"
Chandler Carruth572e3402014-04-21 11:12:00 +000029#include "llvm/Analysis/CGSCCPassManager.h"
Chandler Carruth4c660f72016-03-10 11:24:11 +000030#include "llvm/Analysis/CallGraph.h"
Michael Kupersteinde16b442016-04-18 23:55:01 +000031#include "llvm/Analysis/DemandedBits.h"
Chandler Carruth49c22192016-05-12 22:19:39 +000032#include "llvm/Analysis/DependenceAnalysis.h"
Hongbin Zheng751337f2016-02-25 17:54:15 +000033#include "llvm/Analysis/DominanceFrontier.h"
Chandler Carruth45a9c202016-03-11 09:15:11 +000034#include "llvm/Analysis/GlobalsModRef.h"
Chandler Carruthbf71a342014-02-06 04:37:03 +000035#include "llvm/Analysis/LazyCallGraph.h"
Sean Silva687019f2016-06-13 22:01:25 +000036#include "llvm/Analysis/LazyValueInfo.h"
Xinliang David Li8a021312016-07-02 21:18:40 +000037#include "llvm/Analysis/LoopAccessAnalysis.h"
Chandler Carruthaaf0b4c2015-01-20 10:58:50 +000038#include "llvm/Analysis/LoopInfo.h"
Chandler Carruth61440d22016-03-10 00:55:30 +000039#include "llvm/Analysis/MemoryDependenceAnalysis.h"
Hongbin Zheng3f978402016-02-25 17:54:07 +000040#include "llvm/Analysis/PostDominators.h"
Easwaran Raman019e0bf2016-06-03 22:54:26 +000041#include "llvm/Analysis/ProfileSummaryInfo.h"
Hongbin Zhengbc539772016-02-25 17:54:25 +000042#include "llvm/Analysis/RegionInfo.h"
Chandler Carruth2f1fd162015-08-17 02:08:17 +000043#include "llvm/Analysis/ScalarEvolution.h"
Chandler Carruth2b3d0442016-02-20 04:01:45 +000044#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
Chandler Carruthd6091a02016-02-20 04:03:06 +000045#include "llvm/Analysis/ScopedNoAliasAA.h"
Chandler Carruth8ca43222015-01-15 11:39:46 +000046#include "llvm/Analysis/TargetLibraryInfo.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000047#include "llvm/Analysis/TargetTransformInfo.h"
Chandler Carruthc1dc3842016-02-20 04:04:52 +000048#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
Michael Kuperstein82d5da52016-06-24 20:13:42 +000049#include "llvm/CodeGen/PreISelIntrinsicLowering.h"
Chandler Carruth64764b42015-01-14 10:19:28 +000050#include "llvm/IR/Dominators.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000051#include "llvm/IR/IRPrintingPasses.h"
Chandler Carruth66445382014-01-11 08:16:35 +000052#include "llvm/IR/PassManager.h"
Chandler Carruth4d356312014-01-20 11:34:08 +000053#include "llvm/IR/Verifier.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000054#include "llvm/Support/Debug.h"
Chandler Carruth8b5a74192016-02-28 22:16:03 +000055#include "llvm/Support/Regex.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000056#include "llvm/Target/TargetMachine.h"
Xinliang David Li64dbb292016-06-05 05:12:23 +000057#include "llvm/Transforms/GCOVProfiler.h"
Davide Italiano164b9bc2016-05-05 00:51:09 +000058#include "llvm/Transforms/IPO/ConstantMerge.h"
Sean Silvae3bb4572016-06-12 09:16:39 +000059#include "llvm/Transforms/IPO/DeadArgumentElimination.h"
Davide Italiano344e8382016-05-05 02:37:32 +000060#include "llvm/Transforms/IPO/ElimAvailExtern.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000061#include "llvm/Transforms/IPO/ForceFunctionAttrs.h"
Chandler Carruth9c4ed172016-02-18 11:03:11 +000062#include "llvm/Transforms/IPO/FunctionAttrs.h"
Davide Italiano66228c42016-05-03 19:39:15 +000063#include "llvm/Transforms/IPO/GlobalDCE.h"
Justin Bogner1a075012016-04-26 00:28:01 +000064#include "llvm/Transforms/IPO/GlobalOpt.h"
Chandler Carruth3a040e62015-12-27 08:41:34 +000065#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
Justin Bogner4563a062016-04-26 20:15:52 +000066#include "llvm/Transforms/IPO/Internalize.h"
Easwaran Raman1832bf62016-06-27 16:50:18 +000067#include "llvm/Transforms/IPO/PartialInlining.h"
Davide Italianof54f2f02016-05-05 21:05:36 +000068#include "llvm/Transforms/IPO/SCCP.h"
Justin Bogner21e15372015-10-30 23:28:12 +000069#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
Davide Italianod737dd22016-06-14 21:44:19 +000070#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000071#include "llvm/Transforms/InstCombine/InstCombine.h"
Xinliang David Lie6b89292016-04-18 17:47:38 +000072#include "llvm/Transforms/InstrProfiling.h"
Xinliang David Li8aebf442016-05-06 05:49:19 +000073#include "llvm/Transforms/PGOInstrumentation.h"
Xinliang David Lid38392e2016-05-27 23:20:16 +000074#include "llvm/Transforms/SampleProfile.h"
Justin Bogner19b67992015-10-30 23:13:18 +000075#include "llvm/Transforms/Scalar/ADCE.h"
Sean Silvaa4c2d152016-06-15 06:18:01 +000076#include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h"
Davide Italiano655a1452016-05-25 01:57:04 +000077#include "llvm/Transforms/Scalar/BDCE.h"
Sean Silvab025d372016-07-06 23:26:29 +000078#include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h"
Justin Bogner395c2122016-04-22 19:40:41 +000079#include "llvm/Transforms/Scalar/DCE.h"
Michael Kuperstein071d8302016-07-02 00:16:47 +000080#include "llvm/Transforms/Scalar/ConstantHoisting.h"
Justin Bogner594e07b2016-05-17 21:38:13 +000081#include "llvm/Transforms/Scalar/DeadStoreElimination.h"
Chandler Carruthe8c686a2015-02-01 10:51:23 +000082#include "llvm/Transforms/Scalar/EarlyCSE.h"
Michael Kuperstein83b753d2016-06-24 23:32:02 +000083#include "llvm/Transforms/Scalar/Float2Int.h"
Easwaran Raman019e0bf2016-06-03 22:54:26 +000084#include "llvm/Transforms/Scalar/GVN.h"
Davide Italiano89ab89d2016-06-14 00:49:23 +000085#include "llvm/Transforms/Scalar/GuardWidening.h"
Sanjoy Das4d4339d2016-06-05 18:01:19 +000086#include "llvm/Transforms/Scalar/IndVarSimplify.h"
Sean Silva46590d52016-06-14 00:51:09 +000087#include "llvm/Transforms/Scalar/JumpThreading.h"
Justin Bognerd0d23412016-05-03 22:02:31 +000088#include "llvm/Transforms/Scalar/LoopRotation.h"
Justin Bognerab6a5132016-05-03 21:47:32 +000089#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
Davide Italiano99223442016-05-13 22:52:35 +000090#include "llvm/Transforms/Scalar/LowerAtomic.h"
Chandler Carruth43e590e2015-01-24 11:13:02 +000091#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
Sean Silva6347df02016-06-14 02:44:55 +000092#include "llvm/Transforms/Scalar/MemCpyOptimizer.h"
Davide Italianob49aa5c2016-06-17 19:10:09 +000093#include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
Davide Italiano1021c682016-05-25 23:38:53 +000094#include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
Justin Bognerc2bf63d2016-04-26 23:39:29 +000095#include "llvm/Transforms/Scalar/Reassociate.h"
Davide Italiano98f7e0e2016-05-18 15:18:25 +000096#include "llvm/Transforms/Scalar/SCCP.h"
Chandler Carruth74a8a222016-06-17 07:15:29 +000097#include "llvm/Transforms/Scalar/SLPVectorizer.h"
Chandler Carruth29a18a42015-09-12 09:09:14 +000098#include "llvm/Transforms/Scalar/SROA.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000099#include "llvm/Transforms/Scalar/SimplifyCFG.h"
Justin Bognerb9394902016-04-22 19:54:10 +0000100#include "llvm/Transforms/Scalar/Sink.h"
Sean Silva59fe82f2016-07-06 23:48:41 +0000101#include "llvm/Transforms/Scalar/TailRecursionElimination.h"
Xinliang David Li1eaecef2016-06-15 21:51:30 +0000102#include "llvm/Transforms/Utils/AddDiscriminators.h"
Easwaran Ramane12c4872016-06-09 19:44:46 +0000103#include "llvm/Transforms/Utils/LCSSA.h"
Davide Italianocccf4f02016-06-14 03:22:22 +0000104#include "llvm/Transforms/Utils/Mem2Reg.h"
Geoff Berryb96d3b22016-06-01 21:30:40 +0000105#include "llvm/Transforms/Utils/MemorySSA.h"
Davide Italianocccf4f02016-06-14 03:22:22 +0000106
Chandler Carruth58dde8c2016-02-26 12:17:54 +0000107#include <type_traits>
Chandler Carruth66445382014-01-11 08:16:35 +0000108
109using namespace llvm;
110
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000111static Regex DefaultAliasRegex("^(default|lto-pre-link|lto)<(O[0123sz])>$");
112
Chandler Carruth66445382014-01-11 08:16:35 +0000113namespace {
114
Chandler Carruthd8330982014-01-12 09:34:22 +0000115/// \brief No-op module pass which does nothing.
Chandler Carruth66445382014-01-11 08:16:35 +0000116struct NoOpModulePass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000117 PreservedAnalyses run(Module &M, AnalysisManager<Module> &) {
118 return PreservedAnalyses::all();
119 }
Chandler Carrutha13f27c2014-01-11 11:52:05 +0000120 static StringRef name() { return "NoOpModulePass"; }
Chandler Carruth66445382014-01-11 08:16:35 +0000121};
122
Chandler Carruth0b576b32015-01-06 02:50:06 +0000123/// \brief No-op module analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000124class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
125 friend AnalysisInfoMixin<NoOpModuleAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000126 static char PassID;
127
128public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000129 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000130 Result run(Module &, AnalysisManager<Module> &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000131 static StringRef name() { return "NoOpModuleAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000132};
133
Chandler Carruth572e3402014-04-21 11:12:00 +0000134/// \brief No-op CGSCC pass which does nothing.
135struct NoOpCGSCCPass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000136 PreservedAnalyses run(LazyCallGraph::SCC &C,
137 AnalysisManager<LazyCallGraph::SCC> &) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000138 return PreservedAnalyses::all();
139 }
140 static StringRef name() { return "NoOpCGSCCPass"; }
141};
142
Chandler Carruth0b576b32015-01-06 02:50:06 +0000143/// \brief No-op CGSCC analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000144class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
145 friend AnalysisInfoMixin<NoOpCGSCCAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000146 static char PassID;
147
148public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000149 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000150 Result run(LazyCallGraph::SCC &, AnalysisManager<LazyCallGraph::SCC> &) {
151 return Result();
152 }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000153 static StringRef name() { return "NoOpCGSCCAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000154};
155
Chandler Carruthd8330982014-01-12 09:34:22 +0000156/// \brief No-op function pass which does nothing.
157struct NoOpFunctionPass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000158 PreservedAnalyses run(Function &F, AnalysisManager<Function> &) {
159 return PreservedAnalyses::all();
160 }
Chandler Carruthd8330982014-01-12 09:34:22 +0000161 static StringRef name() { return "NoOpFunctionPass"; }
162};
163
Chandler Carruth0b576b32015-01-06 02:50:06 +0000164/// \brief No-op function analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000165class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
166 friend AnalysisInfoMixin<NoOpFunctionAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000167 static char PassID;
168
169public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000170 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000171 Result run(Function &, AnalysisManager<Function> &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000172 static StringRef name() { return "NoOpFunctionAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000173};
174
Justin Bognereecc3c82016-02-25 07:23:08 +0000175/// \brief No-op loop pass which does nothing.
176struct NoOpLoopPass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000177 PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &) {
178 return PreservedAnalyses::all();
179 }
Justin Bognereecc3c82016-02-25 07:23:08 +0000180 static StringRef name() { return "NoOpLoopPass"; }
181};
182
183/// \brief No-op loop analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000184class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
185 friend AnalysisInfoMixin<NoOpLoopAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000186 static char PassID;
187
188public:
Justin Bognereecc3c82016-02-25 07:23:08 +0000189 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000190 Result run(Loop &, AnalysisManager<Loop> &) { return Result(); }
Justin Bognereecc3c82016-02-25 07:23:08 +0000191 static StringRef name() { return "NoOpLoopAnalysis"; }
Justin Bognereecc3c82016-02-25 07:23:08 +0000192};
193
Chandler Carruthb4faf132016-03-11 10:22:49 +0000194char NoOpModuleAnalysis::PassID;
195char NoOpCGSCCAnalysis::PassID;
196char NoOpFunctionAnalysis::PassID;
197char NoOpLoopAnalysis::PassID;
198
Chandler Carruth66445382014-01-11 08:16:35 +0000199} // End anonymous namespace.
200
Chandler Carruth1ff77242015-03-07 09:02:36 +0000201void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000202#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000203 MAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000204#include "PassRegistry.def"
205}
206
Chandler Carruth1ff77242015-03-07 09:02:36 +0000207void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000208#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000209 CGAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000210#include "PassRegistry.def"
211}
212
Chandler Carruth1ff77242015-03-07 09:02:36 +0000213void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000214#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000215 FAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000216#include "PassRegistry.def"
217}
218
Justin Bognereecc3c82016-02-25 07:23:08 +0000219void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000220#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
Justin Bognereecc3c82016-02-25 07:23:08 +0000221 LAM.registerPass([&] { return CREATE_PASS; });
222#include "PassRegistry.def"
223}
224
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000225void PassBuilder::addPerModuleDefaultPipeline(ModulePassManager &MPM,
226 OptimizationLevel Level,
227 bool DebugLogging) {
228 // FIXME: Finish fleshing this out to match the legacy pipelines.
229 FunctionPassManager EarlyFPM(DebugLogging);
230 EarlyFPM.addPass(SimplifyCFGPass());
231 EarlyFPM.addPass(SROA());
232 EarlyFPM.addPass(EarlyCSEPass());
233 EarlyFPM.addPass(LowerExpectIntrinsicPass());
234
235 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
236}
237
238void PassBuilder::addLTOPreLinkDefaultPipeline(ModulePassManager &MPM,
239 OptimizationLevel Level,
240 bool DebugLogging) {
241 // FIXME: We should use a customized pre-link pipeline!
242 addPerModuleDefaultPipeline(MPM, Level, DebugLogging);
243}
244
245void PassBuilder::addLTODefaultPipeline(ModulePassManager &MPM,
246 OptimizationLevel Level,
247 bool DebugLogging) {
248 // FIXME: Finish fleshing this out to match the legacy LTO pipelines.
249 FunctionPassManager LateFPM(DebugLogging);
250 LateFPM.addPass(InstCombinePass());
251 LateFPM.addPass(SimplifyCFGPass());
252
253 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(LateFPM)));
254}
255
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000256#ifndef NDEBUG
Chandler Carruth66445382014-01-11 08:16:35 +0000257static bool isModulePassName(StringRef Name) {
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000258 // Manually handle aliases for pre-configured pipeline fragments.
259 if (Name.startswith("default") || Name.startswith("lto"))
260 return DefaultAliasRegex.match(Name);
261
Chandler Carruth74a8a222016-06-17 07:15:29 +0000262#define MODULE_PASS(NAME, CREATE_PASS) \
263 if (Name == NAME) \
264 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000265#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000266 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000267 return true;
268#include "PassRegistry.def"
269
Chandler Carruth66445382014-01-11 08:16:35 +0000270 return false;
271}
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000272#endif
Chandler Carruth66445382014-01-11 08:16:35 +0000273
Chandler Carruth572e3402014-04-21 11:12:00 +0000274static bool isCGSCCPassName(StringRef Name) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000275#define CGSCC_PASS(NAME, CREATE_PASS) \
276 if (Name == NAME) \
277 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000278#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000279 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000280 return true;
281#include "PassRegistry.def"
282
Chandler Carruth572e3402014-04-21 11:12:00 +0000283 return false;
284}
285
Chandler Carruthd8330982014-01-12 09:34:22 +0000286static bool isFunctionPassName(StringRef Name) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000287#define FUNCTION_PASS(NAME, CREATE_PASS) \
288 if (Name == NAME) \
289 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000290#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000291 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000292 return true;
293#include "PassRegistry.def"
294
Chandler Carruthd8330982014-01-12 09:34:22 +0000295 return false;
296}
297
Justin Bognereecc3c82016-02-25 07:23:08 +0000298static bool isLoopPassName(StringRef Name) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000299#define LOOP_PASS(NAME, CREATE_PASS) \
300 if (Name == NAME) \
301 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +0000302#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
303 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
304 return true;
305#include "PassRegistry.def"
306
307 return false;
308}
309
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000310bool PassBuilder::parseModulePassName(ModulePassManager &MPM, StringRef Name,
311 bool DebugLogging) {
312 // Manually handle aliases for pre-configured pipeline fragments.
313 if (Name.startswith("default") || Name.startswith("lto")) {
314 SmallVector<StringRef, 3> Matches;
315 if (!DefaultAliasRegex.match(Name, &Matches))
316 return false;
317 assert(Matches.size() == 3 && "Must capture two matched strings!");
318
319 auto L = StringSwitch<OptimizationLevel>(Matches[2])
320 .Case("O0", O0)
321 .Case("O1", O1)
322 .Case("O2", O2)
323 .Case("O3", O3)
324 .Case("Os", Os)
325 .Case("Oz", Oz);
326
327 if (Matches[1] == "default") {
328 addPerModuleDefaultPipeline(MPM, L, DebugLogging);
329 } else if (Matches[1] == "lto-pre-link") {
330 addLTOPreLinkDefaultPipeline(MPM, L, DebugLogging);
331 } else {
332 assert(Matches[1] == "lto" && "Not one of the matched options!");
333 addLTODefaultPipeline(MPM, L, DebugLogging);
334 }
335 return true;
336 }
337
Chandler Carruth58944182014-04-21 08:08:50 +0000338#define MODULE_PASS(NAME, CREATE_PASS) \
339 if (Name == NAME) { \
340 MPM.addPass(CREATE_PASS); \
341 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000342 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000343#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
344 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000345 MPM.addPass(RequireAnalysisPass< \
346 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000347 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000348 } \
349 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000350 MPM.addPass(InvalidateAnalysisPass< \
351 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000352 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000353 }
354#include "PassRegistry.def"
355
Chandler Carruth66445382014-01-11 08:16:35 +0000356 return false;
357}
358
Chandler Carruth1ff77242015-03-07 09:02:36 +0000359bool PassBuilder::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000360#define CGSCC_PASS(NAME, CREATE_PASS) \
361 if (Name == NAME) { \
362 CGPM.addPass(CREATE_PASS); \
363 return true; \
364 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000365#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
366 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000367 CGPM.addPass(RequireAnalysisPass< \
368 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000369 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000370 } \
371 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000372 CGPM.addPass(InvalidateAnalysisPass< \
373 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000374 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000375 }
376#include "PassRegistry.def"
377
Chandler Carruth572e3402014-04-21 11:12:00 +0000378 return false;
379}
380
Chandler Carruth1ff77242015-03-07 09:02:36 +0000381bool PassBuilder::parseFunctionPassName(FunctionPassManager &FPM,
382 StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000383#define FUNCTION_PASS(NAME, CREATE_PASS) \
384 if (Name == NAME) { \
385 FPM.addPass(CREATE_PASS); \
386 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000387 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000388#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
389 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000390 FPM.addPass(RequireAnalysisPass< \
391 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000392 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000393 } \
394 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000395 FPM.addPass(InvalidateAnalysisPass< \
396 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000397 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000398 }
399#include "PassRegistry.def"
400
Chandler Carruthd8330982014-01-12 09:34:22 +0000401 return false;
402}
403
Chandler Carruth74a8a222016-06-17 07:15:29 +0000404bool PassBuilder::parseLoopPassName(LoopPassManager &FPM, StringRef Name) {
Justin Bognereecc3c82016-02-25 07:23:08 +0000405#define LOOP_PASS(NAME, CREATE_PASS) \
406 if (Name == NAME) { \
407 FPM.addPass(CREATE_PASS); \
408 return true; \
409 }
410#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
411 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000412 FPM.addPass(RequireAnalysisPass< \
413 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +0000414 return true; \
415 } \
416 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000417 FPM.addPass(InvalidateAnalysisPass< \
418 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +0000419 return true; \
420 }
421#include "PassRegistry.def"
422
423 return false;
424}
425
Chandler Carruthedf59962016-02-18 09:45:17 +0000426bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
Chandler Carruth45a9c202016-03-11 09:15:11 +0000427#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
428 if (Name == NAME) { \
429 AA.registerModuleAnalysis< \
430 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
431 return true; \
432 }
Chandler Carruthedf59962016-02-18 09:45:17 +0000433#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
434 if (Name == NAME) { \
Chandler Carruth58dde8c2016-02-26 12:17:54 +0000435 AA.registerFunctionAnalysis< \
436 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
Chandler Carruthedf59962016-02-18 09:45:17 +0000437 return true; \
438 }
439#include "PassRegistry.def"
440
441 return false;
442}
443
Justin Bognereecc3c82016-02-25 07:23:08 +0000444bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
445 StringRef &PipelineText,
446 bool VerifyEachPass,
447 bool DebugLogging) {
448 for (;;) {
449 // Parse nested pass managers by recursing.
450 if (PipelineText.startswith("loop(")) {
451 LoopPassManager NestedLPM(DebugLogging);
452
453 // Parse the inner pipeline inte the nested manager.
454 PipelineText = PipelineText.substr(strlen("loop("));
455 if (!parseLoopPassPipeline(NestedLPM, PipelineText, VerifyEachPass,
456 DebugLogging) ||
457 PipelineText.empty())
458 return false;
459 assert(PipelineText[0] == ')');
460 PipelineText = PipelineText.substr(1);
461
462 // Add the nested pass manager with the appropriate adaptor.
463 LPM.addPass(std::move(NestedLPM));
464 } else {
465 // Otherwise try to parse a pass name.
466 size_t End = PipelineText.find_first_of(",)");
467 if (!parseLoopPassName(LPM, PipelineText.substr(0, End)))
468 return false;
469 // TODO: Ideally, we would run a LoopVerifierPass() here in the
470 // VerifyEachPass case, but we don't have such a verifier yet.
471
472 PipelineText = PipelineText.substr(End);
473 }
474
475 if (PipelineText.empty() || PipelineText[0] == ')')
476 return true;
477
478 assert(PipelineText[0] == ',');
479 PipelineText = PipelineText.substr(1);
480 }
481}
482
Chandler Carruth1ff77242015-03-07 09:02:36 +0000483bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
484 StringRef &PipelineText,
485 bool VerifyEachPass,
486 bool DebugLogging) {
Chandler Carruthd8330982014-01-12 09:34:22 +0000487 for (;;) {
488 // Parse nested pass managers by recursing.
489 if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000490 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000491
492 // Parse the inner pipeline inte the nested manager.
493 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000494 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
495 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000496 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000497 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000498 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000499 PipelineText = PipelineText.substr(1);
500
501 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000502 FPM.addPass(std::move(NestedFPM));
Justin Bognereecc3c82016-02-25 07:23:08 +0000503 } else if (PipelineText.startswith("loop(")) {
504 LoopPassManager NestedLPM(DebugLogging);
505
506 // Parse the inner pipeline inte the nested manager.
507 PipelineText = PipelineText.substr(strlen("loop("));
508 if (!parseLoopPassPipeline(NestedLPM, PipelineText, VerifyEachPass,
509 DebugLogging) ||
510 PipelineText.empty())
511 return false;
512 assert(PipelineText[0] == ')');
513 PipelineText = PipelineText.substr(1);
514
515 // Add the nested pass manager with the appropriate adaptor.
516 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(NestedLPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000517 } else {
518 // Otherwise try to parse a pass name.
519 size_t End = PipelineText.find_first_of(",)");
520 if (!parseFunctionPassName(FPM, PipelineText.substr(0, End)))
521 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000522 if (VerifyEachPass)
523 FPM.addPass(VerifierPass());
Chandler Carruthd8330982014-01-12 09:34:22 +0000524
525 PipelineText = PipelineText.substr(End);
526 }
527
528 if (PipelineText.empty() || PipelineText[0] == ')')
529 return true;
530
531 assert(PipelineText[0] == ',');
532 PipelineText = PipelineText.substr(1);
533 }
534}
535
Chandler Carruth1ff77242015-03-07 09:02:36 +0000536bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
537 StringRef &PipelineText,
538 bool VerifyEachPass,
539 bool DebugLogging) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000540 for (;;) {
541 // Parse nested pass managers by recursing.
542 if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000543 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000544
545 // Parse the inner pipeline into the nested manager.
546 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000547 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
548 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000549 PipelineText.empty())
550 return false;
551 assert(PipelineText[0] == ')');
552 PipelineText = PipelineText.substr(1);
553
554 // Add the nested pass manager with the appropriate adaptor.
555 CGPM.addPass(std::move(NestedCGPM));
556 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000557 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000558
559 // Parse the inner pipeline inte the nested manager.
560 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000561 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
562 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000563 PipelineText.empty())
564 return false;
565 assert(PipelineText[0] == ')');
566 PipelineText = PipelineText.substr(1);
567
568 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthdca83402016-06-27 23:26:08 +0000569 CGPM.addPass(
570 createCGSCCToFunctionPassAdaptor(std::move(NestedFPM), DebugLogging));
Chandler Carruth572e3402014-04-21 11:12:00 +0000571 } else {
572 // Otherwise try to parse a pass name.
573 size_t End = PipelineText.find_first_of(",)");
574 if (!parseCGSCCPassName(CGPM, PipelineText.substr(0, End)))
575 return false;
576 // FIXME: No verifier support for CGSCC passes!
577
578 PipelineText = PipelineText.substr(End);
579 }
580
581 if (PipelineText.empty() || PipelineText[0] == ')')
582 return true;
583
584 assert(PipelineText[0] == ',');
585 PipelineText = PipelineText.substr(1);
586 }
587}
588
NAKAMURA Takumia42f5282016-05-16 10:13:37 +0000589void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM,
590 FunctionAnalysisManager &FAM,
591 CGSCCAnalysisManager &CGAM,
592 ModuleAnalysisManager &MAM) {
593 MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
594 MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
595 CGAM.registerPass([&] { return FunctionAnalysisManagerCGSCCProxy(FAM); });
596 CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
597 FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
598 FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
599 FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
600 LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
601}
602
Chandler Carruth1ff77242015-03-07 09:02:36 +0000603bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
604 StringRef &PipelineText,
605 bool VerifyEachPass,
606 bool DebugLogging) {
Chandler Carruth66445382014-01-11 08:16:35 +0000607 for (;;) {
608 // Parse nested pass managers by recursing.
609 if (PipelineText.startswith("module(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000610 ModulePassManager NestedMPM(DebugLogging);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000611
612 // Parse the inner pipeline into the nested manager.
Chandler Carruth66445382014-01-11 08:16:35 +0000613 PipelineText = PipelineText.substr(strlen("module("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000614 if (!parseModulePassPipeline(NestedMPM, PipelineText, VerifyEachPass,
615 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000616 PipelineText.empty())
Chandler Carruth66445382014-01-11 08:16:35 +0000617 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000618 assert(PipelineText[0] == ')');
Chandler Carruth66445382014-01-11 08:16:35 +0000619 PipelineText = PipelineText.substr(1);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000620
621 // Now add the nested manager as a module pass.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000622 MPM.addPass(std::move(NestedMPM));
Chandler Carruth572e3402014-04-21 11:12:00 +0000623 } else if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000624 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000625
626 // Parse the inner pipeline inte the nested manager.
627 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000628 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
629 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000630 PipelineText.empty())
631 return false;
632 assert(PipelineText[0] == ')');
633 PipelineText = PipelineText.substr(1);
634
635 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthdca83402016-06-27 23:26:08 +0000636 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(NestedCGPM),
637 DebugLogging));
Chandler Carruthd8330982014-01-12 09:34:22 +0000638 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000639 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000640
641 // Parse the inner pipeline inte the nested manager.
642 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000643 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
644 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000645 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000646 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000647 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000648 PipelineText = PipelineText.substr(1);
649
650 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000651 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(NestedFPM)));
Chandler Carruth66445382014-01-11 08:16:35 +0000652 } else {
653 // Otherwise try to parse a pass name.
654 size_t End = PipelineText.find_first_of(",)");
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000655 if (!parseModulePassName(MPM, PipelineText.substr(0, End), DebugLogging))
Chandler Carruth66445382014-01-11 08:16:35 +0000656 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000657 if (VerifyEachPass)
658 MPM.addPass(VerifierPass());
Chandler Carruth66445382014-01-11 08:16:35 +0000659
660 PipelineText = PipelineText.substr(End);
661 }
662
663 if (PipelineText.empty() || PipelineText[0] == ')')
664 return true;
665
666 assert(PipelineText[0] == ',');
667 PipelineText = PipelineText.substr(1);
668 }
669}
670
671// Primary pass pipeline description parsing routine.
672// FIXME: Should this routine accept a TargetMachine or require the caller to
673// pre-populate the analysis managers with target-specific stuff?
Chandler Carruth1ff77242015-03-07 09:02:36 +0000674bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
675 StringRef PipelineText, bool VerifyEachPass,
676 bool DebugLogging) {
Chandler Carruthea368f12015-01-06 08:37:58 +0000677 // By default, try to parse the pipeline as-if it were within an implicit
678 // 'module(...)' pass pipeline. If this will parse at all, it needs to
679 // consume the entire string.
Chandler Carruth14a759e2015-01-13 22:42:38 +0000680 if (parseModulePassPipeline(MPM, PipelineText, VerifyEachPass, DebugLogging))
Chandler Carruthea368f12015-01-06 08:37:58 +0000681 return PipelineText.empty();
Chandler Carruth66445382014-01-11 08:16:35 +0000682
Chandler Carruthea368f12015-01-06 08:37:58 +0000683 // This isn't parsable as a module pipeline, look for the end of a pass name
684 // and directly drop down to that layer.
Chandler Carruth6546cb62014-01-12 10:02:02 +0000685 StringRef FirstName =
686 PipelineText.substr(0, PipelineText.find_first_of(",)"));
Chandler Carruthea368f12015-01-06 08:37:58 +0000687 assert(!isModulePassName(FirstName) &&
688 "Already handled all module pipeline options.");
Chandler Carruth66445382014-01-11 08:16:35 +0000689
Chandler Carruthea368f12015-01-06 08:37:58 +0000690 // If this looks like a CGSCC pass, parse the whole thing as a CGSCC
691 // pipeline.
Justin Bognereecc3c82016-02-25 07:23:08 +0000692 if (PipelineText.startswith("cgscc(") || isCGSCCPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000693 CGSCCPassManager CGPM(DebugLogging);
694 if (!parseCGSCCPassPipeline(CGPM, PipelineText, VerifyEachPass,
695 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000696 !PipelineText.empty())
697 return false;
George Burgess IVbfa401e2016-07-06 00:26:41 +0000698 MPM.addPass(
699 createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM), DebugLogging));
Chandler Carruth572e3402014-04-21 11:12:00 +0000700 return true;
701 }
702
Chandler Carruthea368f12015-01-06 08:37:58 +0000703 // Similarly, if this looks like a Function pass, parse the whole thing as
704 // a Function pipelien.
Justin Bognereecc3c82016-02-25 07:23:08 +0000705 if (PipelineText.startswith("function(") || isFunctionPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000706 FunctionPassManager FPM(DebugLogging);
707 if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass,
708 DebugLogging) ||
Chandler Carruth4d356312014-01-20 11:34:08 +0000709 !PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000710 return false;
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000711 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000712 return true;
713 }
Chandler Carruth66445382014-01-11 08:16:35 +0000714
Justin Bognereecc3c82016-02-25 07:23:08 +0000715 // If this looks like a Loop pass, parse the whole thing as a Loop pipeline.
716 if (PipelineText.startswith("loop(") || isLoopPassName(FirstName)) {
717 LoopPassManager LPM(DebugLogging);
718 if (!parseLoopPassPipeline(LPM, PipelineText, VerifyEachPass,
719 DebugLogging) ||
720 !PipelineText.empty())
721 return false;
722 FunctionPassManager FPM(DebugLogging);
723 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM)));
724 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
725 return true;
726 }
727
Chandler Carruth66445382014-01-11 08:16:35 +0000728 return false;
729}
Chandler Carruthedf59962016-02-18 09:45:17 +0000730
731bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) {
732 while (!PipelineText.empty()) {
733 StringRef Name;
734 std::tie(Name, PipelineText) = PipelineText.split(',');
735 if (!parseAAPassName(AA, Name))
736 return false;
737 }
738
739 return true;
740}