blob: 5ebe98361d0cf6ac758475e7fad0953a7b259e06 [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"
Justin Bogner395c2122016-04-22 19:40:41 +000078#include "llvm/Transforms/Scalar/DCE.h"
Michael Kuperstein071d8302016-07-02 00:16:47 +000079#include "llvm/Transforms/Scalar/ConstantHoisting.h"
Justin Bogner594e07b2016-05-17 21:38:13 +000080#include "llvm/Transforms/Scalar/DeadStoreElimination.h"
Chandler Carruthe8c686a2015-02-01 10:51:23 +000081#include "llvm/Transforms/Scalar/EarlyCSE.h"
Michael Kuperstein83b753d2016-06-24 23:32:02 +000082#include "llvm/Transforms/Scalar/Float2Int.h"
Easwaran Raman019e0bf2016-06-03 22:54:26 +000083#include "llvm/Transforms/Scalar/GVN.h"
Davide Italiano89ab89d2016-06-14 00:49:23 +000084#include "llvm/Transforms/Scalar/GuardWidening.h"
Sanjoy Das4d4339d2016-06-05 18:01:19 +000085#include "llvm/Transforms/Scalar/IndVarSimplify.h"
Sean Silva46590d52016-06-14 00:51:09 +000086#include "llvm/Transforms/Scalar/JumpThreading.h"
Justin Bognerd0d23412016-05-03 22:02:31 +000087#include "llvm/Transforms/Scalar/LoopRotation.h"
Justin Bognerab6a5132016-05-03 21:47:32 +000088#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
Davide Italiano99223442016-05-13 22:52:35 +000089#include "llvm/Transforms/Scalar/LowerAtomic.h"
Chandler Carruth43e590e2015-01-24 11:13:02 +000090#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
Sean Silva6347df02016-06-14 02:44:55 +000091#include "llvm/Transforms/Scalar/MemCpyOptimizer.h"
Davide Italianob49aa5c2016-06-17 19:10:09 +000092#include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
Davide Italiano1021c682016-05-25 23:38:53 +000093#include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
Justin Bognerc2bf63d2016-04-26 23:39:29 +000094#include "llvm/Transforms/Scalar/Reassociate.h"
Davide Italiano98f7e0e2016-05-18 15:18:25 +000095#include "llvm/Transforms/Scalar/SCCP.h"
Chandler Carruth74a8a222016-06-17 07:15:29 +000096#include "llvm/Transforms/Scalar/SLPVectorizer.h"
Chandler Carruth29a18a42015-09-12 09:09:14 +000097#include "llvm/Transforms/Scalar/SROA.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000098#include "llvm/Transforms/Scalar/SimplifyCFG.h"
Justin Bognerb9394902016-04-22 19:54:10 +000099#include "llvm/Transforms/Scalar/Sink.h"
Xinliang David Li1eaecef2016-06-15 21:51:30 +0000100#include "llvm/Transforms/Utils/AddDiscriminators.h"
Easwaran Ramane12c4872016-06-09 19:44:46 +0000101#include "llvm/Transforms/Utils/LCSSA.h"
Davide Italianocccf4f02016-06-14 03:22:22 +0000102#include "llvm/Transforms/Utils/Mem2Reg.h"
Geoff Berryb96d3b22016-06-01 21:30:40 +0000103#include "llvm/Transforms/Utils/MemorySSA.h"
Davide Italianocccf4f02016-06-14 03:22:22 +0000104
Chandler Carruth58dde8c2016-02-26 12:17:54 +0000105#include <type_traits>
Chandler Carruth66445382014-01-11 08:16:35 +0000106
107using namespace llvm;
108
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000109static Regex DefaultAliasRegex("^(default|lto-pre-link|lto)<(O[0123sz])>$");
110
Chandler Carruth66445382014-01-11 08:16:35 +0000111namespace {
112
Chandler Carruthd8330982014-01-12 09:34:22 +0000113/// \brief No-op module pass which does nothing.
Chandler Carruth66445382014-01-11 08:16:35 +0000114struct NoOpModulePass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000115 PreservedAnalyses run(Module &M, AnalysisManager<Module> &) {
116 return PreservedAnalyses::all();
117 }
Chandler Carrutha13f27c2014-01-11 11:52:05 +0000118 static StringRef name() { return "NoOpModulePass"; }
Chandler Carruth66445382014-01-11 08:16:35 +0000119};
120
Chandler Carruth0b576b32015-01-06 02:50:06 +0000121/// \brief No-op module analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000122class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
123 friend AnalysisInfoMixin<NoOpModuleAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000124 static char PassID;
125
126public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000127 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000128 Result run(Module &, AnalysisManager<Module> &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000129 static StringRef name() { return "NoOpModuleAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000130};
131
Chandler Carruth572e3402014-04-21 11:12:00 +0000132/// \brief No-op CGSCC pass which does nothing.
133struct NoOpCGSCCPass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000134 PreservedAnalyses run(LazyCallGraph::SCC &C,
135 AnalysisManager<LazyCallGraph::SCC> &) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000136 return PreservedAnalyses::all();
137 }
138 static StringRef name() { return "NoOpCGSCCPass"; }
139};
140
Chandler Carruth0b576b32015-01-06 02:50:06 +0000141/// \brief No-op CGSCC analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000142class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
143 friend AnalysisInfoMixin<NoOpCGSCCAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000144 static char PassID;
145
146public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000147 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000148 Result run(LazyCallGraph::SCC &, AnalysisManager<LazyCallGraph::SCC> &) {
149 return Result();
150 }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000151 static StringRef name() { return "NoOpCGSCCAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000152};
153
Chandler Carruthd8330982014-01-12 09:34:22 +0000154/// \brief No-op function pass which does nothing.
155struct NoOpFunctionPass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000156 PreservedAnalyses run(Function &F, AnalysisManager<Function> &) {
157 return PreservedAnalyses::all();
158 }
Chandler Carruthd8330982014-01-12 09:34:22 +0000159 static StringRef name() { return "NoOpFunctionPass"; }
160};
161
Chandler Carruth0b576b32015-01-06 02:50:06 +0000162/// \brief No-op function analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000163class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
164 friend AnalysisInfoMixin<NoOpFunctionAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000165 static char PassID;
166
167public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000168 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000169 Result run(Function &, AnalysisManager<Function> &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000170 static StringRef name() { return "NoOpFunctionAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000171};
172
Justin Bognereecc3c82016-02-25 07:23:08 +0000173/// \brief No-op loop pass which does nothing.
174struct NoOpLoopPass {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000175 PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &) {
176 return PreservedAnalyses::all();
177 }
Justin Bognereecc3c82016-02-25 07:23:08 +0000178 static StringRef name() { return "NoOpLoopPass"; }
179};
180
181/// \brief No-op loop analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000182class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
183 friend AnalysisInfoMixin<NoOpLoopAnalysis>;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000184 static char PassID;
185
186public:
Justin Bognereecc3c82016-02-25 07:23:08 +0000187 struct Result {};
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000188 Result run(Loop &, AnalysisManager<Loop> &) { return Result(); }
Justin Bognereecc3c82016-02-25 07:23:08 +0000189 static StringRef name() { return "NoOpLoopAnalysis"; }
Justin Bognereecc3c82016-02-25 07:23:08 +0000190};
191
Chandler Carruthb4faf132016-03-11 10:22:49 +0000192char NoOpModuleAnalysis::PassID;
193char NoOpCGSCCAnalysis::PassID;
194char NoOpFunctionAnalysis::PassID;
195char NoOpLoopAnalysis::PassID;
196
Chandler Carruth66445382014-01-11 08:16:35 +0000197} // End anonymous namespace.
198
Chandler Carruth1ff77242015-03-07 09:02:36 +0000199void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000200#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000201 MAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000202#include "PassRegistry.def"
203}
204
Chandler Carruth1ff77242015-03-07 09:02:36 +0000205void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000206#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000207 CGAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000208#include "PassRegistry.def"
209}
210
Chandler Carruth1ff77242015-03-07 09:02:36 +0000211void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000212#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000213 FAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000214#include "PassRegistry.def"
215}
216
Justin Bognereecc3c82016-02-25 07:23:08 +0000217void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000218#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
Justin Bognereecc3c82016-02-25 07:23:08 +0000219 LAM.registerPass([&] { return CREATE_PASS; });
220#include "PassRegistry.def"
221}
222
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000223void PassBuilder::addPerModuleDefaultPipeline(ModulePassManager &MPM,
224 OptimizationLevel Level,
225 bool DebugLogging) {
226 // FIXME: Finish fleshing this out to match the legacy pipelines.
227 FunctionPassManager EarlyFPM(DebugLogging);
228 EarlyFPM.addPass(SimplifyCFGPass());
229 EarlyFPM.addPass(SROA());
230 EarlyFPM.addPass(EarlyCSEPass());
231 EarlyFPM.addPass(LowerExpectIntrinsicPass());
232
233 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
234}
235
236void PassBuilder::addLTOPreLinkDefaultPipeline(ModulePassManager &MPM,
237 OptimizationLevel Level,
238 bool DebugLogging) {
239 // FIXME: We should use a customized pre-link pipeline!
240 addPerModuleDefaultPipeline(MPM, Level, DebugLogging);
241}
242
243void PassBuilder::addLTODefaultPipeline(ModulePassManager &MPM,
244 OptimizationLevel Level,
245 bool DebugLogging) {
246 // FIXME: Finish fleshing this out to match the legacy LTO pipelines.
247 FunctionPassManager LateFPM(DebugLogging);
248 LateFPM.addPass(InstCombinePass());
249 LateFPM.addPass(SimplifyCFGPass());
250
251 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(LateFPM)));
252}
253
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000254#ifndef NDEBUG
Chandler Carruth66445382014-01-11 08:16:35 +0000255static bool isModulePassName(StringRef Name) {
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000256 // Manually handle aliases for pre-configured pipeline fragments.
257 if (Name.startswith("default") || Name.startswith("lto"))
258 return DefaultAliasRegex.match(Name);
259
Chandler Carruth74a8a222016-06-17 07:15:29 +0000260#define MODULE_PASS(NAME, CREATE_PASS) \
261 if (Name == NAME) \
262 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000263#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000264 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000265 return true;
266#include "PassRegistry.def"
267
Chandler Carruth66445382014-01-11 08:16:35 +0000268 return false;
269}
Chandler Carruth9d2e58f2015-01-06 09:10:47 +0000270#endif
Chandler Carruth66445382014-01-11 08:16:35 +0000271
Chandler Carruth572e3402014-04-21 11:12:00 +0000272static bool isCGSCCPassName(StringRef Name) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000273#define CGSCC_PASS(NAME, CREATE_PASS) \
274 if (Name == NAME) \
275 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000276#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000277 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000278 return true;
279#include "PassRegistry.def"
280
Chandler Carruth572e3402014-04-21 11:12:00 +0000281 return false;
282}
283
Chandler Carruthd8330982014-01-12 09:34:22 +0000284static bool isFunctionPassName(StringRef Name) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000285#define FUNCTION_PASS(NAME, CREATE_PASS) \
286 if (Name == NAME) \
287 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000288#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000289 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000290 return true;
291#include "PassRegistry.def"
292
Chandler Carruthd8330982014-01-12 09:34:22 +0000293 return false;
294}
295
Justin Bognereecc3c82016-02-25 07:23:08 +0000296static bool isLoopPassName(StringRef Name) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000297#define LOOP_PASS(NAME, CREATE_PASS) \
298 if (Name == NAME) \
299 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +0000300#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
301 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
302 return true;
303#include "PassRegistry.def"
304
305 return false;
306}
307
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000308bool PassBuilder::parseModulePassName(ModulePassManager &MPM, StringRef Name,
309 bool DebugLogging) {
310 // Manually handle aliases for pre-configured pipeline fragments.
311 if (Name.startswith("default") || Name.startswith("lto")) {
312 SmallVector<StringRef, 3> Matches;
313 if (!DefaultAliasRegex.match(Name, &Matches))
314 return false;
315 assert(Matches.size() == 3 && "Must capture two matched strings!");
316
317 auto L = StringSwitch<OptimizationLevel>(Matches[2])
318 .Case("O0", O0)
319 .Case("O1", O1)
320 .Case("O2", O2)
321 .Case("O3", O3)
322 .Case("Os", Os)
323 .Case("Oz", Oz);
324
325 if (Matches[1] == "default") {
326 addPerModuleDefaultPipeline(MPM, L, DebugLogging);
327 } else if (Matches[1] == "lto-pre-link") {
328 addLTOPreLinkDefaultPipeline(MPM, L, DebugLogging);
329 } else {
330 assert(Matches[1] == "lto" && "Not one of the matched options!");
331 addLTODefaultPipeline(MPM, L, DebugLogging);
332 }
333 return true;
334 }
335
Chandler Carruth58944182014-04-21 08:08:50 +0000336#define MODULE_PASS(NAME, CREATE_PASS) \
337 if (Name == NAME) { \
338 MPM.addPass(CREATE_PASS); \
339 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000340 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000341#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
342 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000343 MPM.addPass(RequireAnalysisPass< \
344 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000345 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000346 } \
347 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000348 MPM.addPass(InvalidateAnalysisPass< \
349 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000350 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000351 }
352#include "PassRegistry.def"
353
Chandler Carruth66445382014-01-11 08:16:35 +0000354 return false;
355}
356
Chandler Carruth1ff77242015-03-07 09:02:36 +0000357bool PassBuilder::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000358#define CGSCC_PASS(NAME, CREATE_PASS) \
359 if (Name == NAME) { \
360 CGPM.addPass(CREATE_PASS); \
361 return true; \
362 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000363#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
364 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000365 CGPM.addPass(RequireAnalysisPass< \
366 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000367 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000368 } \
369 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000370 CGPM.addPass(InvalidateAnalysisPass< \
371 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000372 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000373 }
374#include "PassRegistry.def"
375
Chandler Carruth572e3402014-04-21 11:12:00 +0000376 return false;
377}
378
Chandler Carruth1ff77242015-03-07 09:02:36 +0000379bool PassBuilder::parseFunctionPassName(FunctionPassManager &FPM,
380 StringRef Name) {
Chandler Carruth58944182014-04-21 08:08:50 +0000381#define FUNCTION_PASS(NAME, CREATE_PASS) \
382 if (Name == NAME) { \
383 FPM.addPass(CREATE_PASS); \
384 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000385 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000386#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
387 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000388 FPM.addPass(RequireAnalysisPass< \
389 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000390 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000391 } \
392 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000393 FPM.addPass(InvalidateAnalysisPass< \
394 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000395 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000396 }
397#include "PassRegistry.def"
398
Chandler Carruthd8330982014-01-12 09:34:22 +0000399 return false;
400}
401
Chandler Carruth74a8a222016-06-17 07:15:29 +0000402bool PassBuilder::parseLoopPassName(LoopPassManager &FPM, StringRef Name) {
Justin Bognereecc3c82016-02-25 07:23:08 +0000403#define LOOP_PASS(NAME, CREATE_PASS) \
404 if (Name == NAME) { \
405 FPM.addPass(CREATE_PASS); \
406 return true; \
407 }
408#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
409 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000410 FPM.addPass(RequireAnalysisPass< \
411 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +0000412 return true; \
413 } \
414 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000415 FPM.addPass(InvalidateAnalysisPass< \
416 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +0000417 return true; \
418 }
419#include "PassRegistry.def"
420
421 return false;
422}
423
Chandler Carruthedf59962016-02-18 09:45:17 +0000424bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
Chandler Carruth45a9c202016-03-11 09:15:11 +0000425#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
426 if (Name == NAME) { \
427 AA.registerModuleAnalysis< \
428 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
429 return true; \
430 }
Chandler Carruthedf59962016-02-18 09:45:17 +0000431#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
432 if (Name == NAME) { \
Chandler Carruth58dde8c2016-02-26 12:17:54 +0000433 AA.registerFunctionAnalysis< \
434 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
Chandler Carruthedf59962016-02-18 09:45:17 +0000435 return true; \
436 }
437#include "PassRegistry.def"
438
439 return false;
440}
441
Justin Bognereecc3c82016-02-25 07:23:08 +0000442bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
443 StringRef &PipelineText,
444 bool VerifyEachPass,
445 bool DebugLogging) {
446 for (;;) {
447 // Parse nested pass managers by recursing.
448 if (PipelineText.startswith("loop(")) {
449 LoopPassManager NestedLPM(DebugLogging);
450
451 // Parse the inner pipeline inte the nested manager.
452 PipelineText = PipelineText.substr(strlen("loop("));
453 if (!parseLoopPassPipeline(NestedLPM, PipelineText, VerifyEachPass,
454 DebugLogging) ||
455 PipelineText.empty())
456 return false;
457 assert(PipelineText[0] == ')');
458 PipelineText = PipelineText.substr(1);
459
460 // Add the nested pass manager with the appropriate adaptor.
461 LPM.addPass(std::move(NestedLPM));
462 } else {
463 // Otherwise try to parse a pass name.
464 size_t End = PipelineText.find_first_of(",)");
465 if (!parseLoopPassName(LPM, PipelineText.substr(0, End)))
466 return false;
467 // TODO: Ideally, we would run a LoopVerifierPass() here in the
468 // VerifyEachPass case, but we don't have such a verifier yet.
469
470 PipelineText = PipelineText.substr(End);
471 }
472
473 if (PipelineText.empty() || PipelineText[0] == ')')
474 return true;
475
476 assert(PipelineText[0] == ',');
477 PipelineText = PipelineText.substr(1);
478 }
479}
480
Chandler Carruth1ff77242015-03-07 09:02:36 +0000481bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
482 StringRef &PipelineText,
483 bool VerifyEachPass,
484 bool DebugLogging) {
Chandler Carruthd8330982014-01-12 09:34:22 +0000485 for (;;) {
486 // Parse nested pass managers by recursing.
487 if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000488 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000489
490 // Parse the inner pipeline inte the nested manager.
491 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000492 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
493 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000494 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000495 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000496 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000497 PipelineText = PipelineText.substr(1);
498
499 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000500 FPM.addPass(std::move(NestedFPM));
Justin Bognereecc3c82016-02-25 07:23:08 +0000501 } else if (PipelineText.startswith("loop(")) {
502 LoopPassManager NestedLPM(DebugLogging);
503
504 // Parse the inner pipeline inte the nested manager.
505 PipelineText = PipelineText.substr(strlen("loop("));
506 if (!parseLoopPassPipeline(NestedLPM, PipelineText, VerifyEachPass,
507 DebugLogging) ||
508 PipelineText.empty())
509 return false;
510 assert(PipelineText[0] == ')');
511 PipelineText = PipelineText.substr(1);
512
513 // Add the nested pass manager with the appropriate adaptor.
514 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(NestedLPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000515 } else {
516 // Otherwise try to parse a pass name.
517 size_t End = PipelineText.find_first_of(",)");
518 if (!parseFunctionPassName(FPM, PipelineText.substr(0, End)))
519 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000520 if (VerifyEachPass)
521 FPM.addPass(VerifierPass());
Chandler Carruthd8330982014-01-12 09:34:22 +0000522
523 PipelineText = PipelineText.substr(End);
524 }
525
526 if (PipelineText.empty() || PipelineText[0] == ')')
527 return true;
528
529 assert(PipelineText[0] == ',');
530 PipelineText = PipelineText.substr(1);
531 }
532}
533
Chandler Carruth1ff77242015-03-07 09:02:36 +0000534bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
535 StringRef &PipelineText,
536 bool VerifyEachPass,
537 bool DebugLogging) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000538 for (;;) {
539 // Parse nested pass managers by recursing.
540 if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000541 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000542
543 // Parse the inner pipeline into the nested manager.
544 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000545 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
546 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000547 PipelineText.empty())
548 return false;
549 assert(PipelineText[0] == ')');
550 PipelineText = PipelineText.substr(1);
551
552 // Add the nested pass manager with the appropriate adaptor.
553 CGPM.addPass(std::move(NestedCGPM));
554 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000555 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000556
557 // Parse the inner pipeline inte the nested manager.
558 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000559 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
560 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000561 PipelineText.empty())
562 return false;
563 assert(PipelineText[0] == ')');
564 PipelineText = PipelineText.substr(1);
565
566 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthdca83402016-06-27 23:26:08 +0000567 CGPM.addPass(
568 createCGSCCToFunctionPassAdaptor(std::move(NestedFPM), DebugLogging));
Chandler Carruth572e3402014-04-21 11:12:00 +0000569 } else {
570 // Otherwise try to parse a pass name.
571 size_t End = PipelineText.find_first_of(",)");
572 if (!parseCGSCCPassName(CGPM, PipelineText.substr(0, End)))
573 return false;
574 // FIXME: No verifier support for CGSCC passes!
575
576 PipelineText = PipelineText.substr(End);
577 }
578
579 if (PipelineText.empty() || PipelineText[0] == ')')
580 return true;
581
582 assert(PipelineText[0] == ',');
583 PipelineText = PipelineText.substr(1);
584 }
585}
586
NAKAMURA Takumia42f5282016-05-16 10:13:37 +0000587void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM,
588 FunctionAnalysisManager &FAM,
589 CGSCCAnalysisManager &CGAM,
590 ModuleAnalysisManager &MAM) {
591 MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
592 MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
593 CGAM.registerPass([&] { return FunctionAnalysisManagerCGSCCProxy(FAM); });
594 CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
595 FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
596 FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
597 FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
598 LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
599}
600
Chandler Carruth1ff77242015-03-07 09:02:36 +0000601bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
602 StringRef &PipelineText,
603 bool VerifyEachPass,
604 bool DebugLogging) {
Chandler Carruth66445382014-01-11 08:16:35 +0000605 for (;;) {
606 // Parse nested pass managers by recursing.
607 if (PipelineText.startswith("module(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000608 ModulePassManager NestedMPM(DebugLogging);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000609
610 // Parse the inner pipeline into the nested manager.
Chandler Carruth66445382014-01-11 08:16:35 +0000611 PipelineText = PipelineText.substr(strlen("module("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000612 if (!parseModulePassPipeline(NestedMPM, PipelineText, VerifyEachPass,
613 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000614 PipelineText.empty())
Chandler Carruth66445382014-01-11 08:16:35 +0000615 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000616 assert(PipelineText[0] == ')');
Chandler Carruth66445382014-01-11 08:16:35 +0000617 PipelineText = PipelineText.substr(1);
Chandler Carruth258dbb32014-01-11 12:06:47 +0000618
619 // Now add the nested manager as a module pass.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000620 MPM.addPass(std::move(NestedMPM));
Chandler Carruth572e3402014-04-21 11:12:00 +0000621 } else if (PipelineText.startswith("cgscc(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000622 CGSCCPassManager NestedCGPM(DebugLogging);
Chandler Carruth572e3402014-04-21 11:12:00 +0000623
624 // Parse the inner pipeline inte the nested manager.
625 PipelineText = PipelineText.substr(strlen("cgscc("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000626 if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass,
627 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000628 PipelineText.empty())
629 return false;
630 assert(PipelineText[0] == ')');
631 PipelineText = PipelineText.substr(1);
632
633 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthdca83402016-06-27 23:26:08 +0000634 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(NestedCGPM),
635 DebugLogging));
Chandler Carruthd8330982014-01-12 09:34:22 +0000636 } else if (PipelineText.startswith("function(")) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000637 FunctionPassManager NestedFPM(DebugLogging);
Chandler Carruthd8330982014-01-12 09:34:22 +0000638
639 // Parse the inner pipeline inte the nested manager.
640 PipelineText = PipelineText.substr(strlen("function("));
Chandler Carruth14a759e2015-01-13 22:42:38 +0000641 if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
642 DebugLogging) ||
Chandler Carruth6546cb62014-01-12 10:02:02 +0000643 PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000644 return false;
Chandler Carruth6546cb62014-01-12 10:02:02 +0000645 assert(PipelineText[0] == ')');
Chandler Carruthd8330982014-01-12 09:34:22 +0000646 PipelineText = PipelineText.substr(1);
647
648 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000649 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(NestedFPM)));
Chandler Carruth66445382014-01-11 08:16:35 +0000650 } else {
651 // Otherwise try to parse a pass name.
652 size_t End = PipelineText.find_first_of(",)");
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000653 if (!parseModulePassName(MPM, PipelineText.substr(0, End), DebugLogging))
Chandler Carruth66445382014-01-11 08:16:35 +0000654 return false;
Chandler Carruth4d356312014-01-20 11:34:08 +0000655 if (VerifyEachPass)
656 MPM.addPass(VerifierPass());
Chandler Carruth66445382014-01-11 08:16:35 +0000657
658 PipelineText = PipelineText.substr(End);
659 }
660
661 if (PipelineText.empty() || PipelineText[0] == ')')
662 return true;
663
664 assert(PipelineText[0] == ',');
665 PipelineText = PipelineText.substr(1);
666 }
667}
668
669// Primary pass pipeline description parsing routine.
670// FIXME: Should this routine accept a TargetMachine or require the caller to
671// pre-populate the analysis managers with target-specific stuff?
Chandler Carruth1ff77242015-03-07 09:02:36 +0000672bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
673 StringRef PipelineText, bool VerifyEachPass,
674 bool DebugLogging) {
Chandler Carruthea368f12015-01-06 08:37:58 +0000675 // By default, try to parse the pipeline as-if it were within an implicit
676 // 'module(...)' pass pipeline. If this will parse at all, it needs to
677 // consume the entire string.
Chandler Carruth14a759e2015-01-13 22:42:38 +0000678 if (parseModulePassPipeline(MPM, PipelineText, VerifyEachPass, DebugLogging))
Chandler Carruthea368f12015-01-06 08:37:58 +0000679 return PipelineText.empty();
Chandler Carruth66445382014-01-11 08:16:35 +0000680
Chandler Carruthea368f12015-01-06 08:37:58 +0000681 // This isn't parsable as a module pipeline, look for the end of a pass name
682 // and directly drop down to that layer.
Chandler Carruth6546cb62014-01-12 10:02:02 +0000683 StringRef FirstName =
684 PipelineText.substr(0, PipelineText.find_first_of(",)"));
Chandler Carruthea368f12015-01-06 08:37:58 +0000685 assert(!isModulePassName(FirstName) &&
686 "Already handled all module pipeline options.");
Chandler Carruth66445382014-01-11 08:16:35 +0000687
Chandler Carruthea368f12015-01-06 08:37:58 +0000688 // If this looks like a CGSCC pass, parse the whole thing as a CGSCC
689 // pipeline.
Justin Bognereecc3c82016-02-25 07:23:08 +0000690 if (PipelineText.startswith("cgscc(") || isCGSCCPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000691 CGSCCPassManager CGPM(DebugLogging);
692 if (!parseCGSCCPassPipeline(CGPM, PipelineText, VerifyEachPass,
693 DebugLogging) ||
Chandler Carruth572e3402014-04-21 11:12:00 +0000694 !PipelineText.empty())
695 return false;
George Burgess IVbfa401e2016-07-06 00:26:41 +0000696 MPM.addPass(
697 createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM), DebugLogging));
Chandler Carruth572e3402014-04-21 11:12:00 +0000698 return true;
699 }
700
Chandler Carruthea368f12015-01-06 08:37:58 +0000701 // Similarly, if this looks like a Function pass, parse the whole thing as
702 // a Function pipelien.
Justin Bognereecc3c82016-02-25 07:23:08 +0000703 if (PipelineText.startswith("function(") || isFunctionPassName(FirstName)) {
Chandler Carruth14a759e2015-01-13 22:42:38 +0000704 FunctionPassManager FPM(DebugLogging);
705 if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass,
706 DebugLogging) ||
Chandler Carruth4d356312014-01-20 11:34:08 +0000707 !PipelineText.empty())
Chandler Carruthd8330982014-01-12 09:34:22 +0000708 return false;
Chandler Carruthc3f3da32014-03-09 11:49:53 +0000709 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
Chandler Carruthd8330982014-01-12 09:34:22 +0000710 return true;
711 }
Chandler Carruth66445382014-01-11 08:16:35 +0000712
Justin Bognereecc3c82016-02-25 07:23:08 +0000713 // If this looks like a Loop pass, parse the whole thing as a Loop pipeline.
714 if (PipelineText.startswith("loop(") || isLoopPassName(FirstName)) {
715 LoopPassManager LPM(DebugLogging);
716 if (!parseLoopPassPipeline(LPM, PipelineText, VerifyEachPass,
717 DebugLogging) ||
718 !PipelineText.empty())
719 return false;
720 FunctionPassManager FPM(DebugLogging);
721 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM)));
722 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
723 return true;
724 }
725
Chandler Carruth66445382014-01-11 08:16:35 +0000726 return false;
727}
Chandler Carruthedf59962016-02-18 09:45:17 +0000728
729bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) {
730 while (!PipelineText.empty()) {
731 StringRef Name;
732 std::tie(Name, PipelineText) = PipelineText.split(',');
733 if (!parseAAPassName(AA, Name))
734 return false;
735 }
736
737 return true;
738}