blob: dd9e41c44dea64c40fc095b87be131c91ad86e2f [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"
Daniel Jasperaec2fa32016-12-19 08:22:17 +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"
Mehdi Amini27d23792016-09-16 16:56:30 +000027#include "llvm/Analysis/CFGPrinter.h"
George Burgess IVbfa401e2016-07-06 00:26:41 +000028#include "llvm/Analysis/CFLAndersAliasAnalysis.h"
29#include "llvm/Analysis/CFLSteensAliasAnalysis.h"
Chandler Carruth572e3402014-04-21 11:12:00 +000030#include "llvm/Analysis/CGSCCPassManager.h"
Chandler Carruth4c660f72016-03-10 11:24:11 +000031#include "llvm/Analysis/CallGraph.h"
Michael Kupersteinde16b442016-04-18 23:55:01 +000032#include "llvm/Analysis/DemandedBits.h"
Chandler Carruth49c22192016-05-12 22:19:39 +000033#include "llvm/Analysis/DependenceAnalysis.h"
Hongbin Zheng751337f2016-02-25 17:54:15 +000034#include "llvm/Analysis/DominanceFrontier.h"
Chandler Carruth45a9c202016-03-11 09:15:11 +000035#include "llvm/Analysis/GlobalsModRef.h"
Dehao Chen1a444522016-07-16 22:51:33 +000036#include "llvm/Analysis/IVUsers.h"
Chandler Carruthbf71a342014-02-06 04:37:03 +000037#include "llvm/Analysis/LazyCallGraph.h"
Sean Silva687019f2016-06-13 22:01:25 +000038#include "llvm/Analysis/LazyValueInfo.h"
Xinliang David Li8a021312016-07-02 21:18:40 +000039#include "llvm/Analysis/LoopAccessAnalysis.h"
Chandler Carruthaaf0b4c2015-01-20 10:58:50 +000040#include "llvm/Analysis/LoopInfo.h"
Chandler Carruth410eaeb2017-01-11 06:23:21 +000041#include "llvm/Analysis/LoopPassManager.h"
Chandler Carruth61440d22016-03-10 00:55:30 +000042#include "llvm/Analysis/MemoryDependenceAnalysis.h"
Teresa Johnsonf93b2462016-08-12 13:53:02 +000043#include "llvm/Analysis/ModuleSummaryAnalysis.h"
Adam Nemet79ac42a2016-07-18 16:29:21 +000044#include "llvm/Analysis/OptimizationDiagnosticInfo.h"
Hongbin Zheng3f978402016-02-25 17:54:07 +000045#include "llvm/Analysis/PostDominators.h"
Easwaran Raman019e0bf2016-06-03 22:54:26 +000046#include "llvm/Analysis/ProfileSummaryInfo.h"
Hongbin Zhengbc539772016-02-25 17:54:25 +000047#include "llvm/Analysis/RegionInfo.h"
Chandler Carruth2f1fd162015-08-17 02:08:17 +000048#include "llvm/Analysis/ScalarEvolution.h"
Chandler Carruth2b3d0442016-02-20 04:01:45 +000049#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
Chandler Carruthd6091a02016-02-20 04:03:06 +000050#include "llvm/Analysis/ScopedNoAliasAA.h"
Chandler Carruth8ca43222015-01-15 11:39:46 +000051#include "llvm/Analysis/TargetLibraryInfo.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000052#include "llvm/Analysis/TargetTransformInfo.h"
Chandler Carruthc1dc3842016-02-20 04:04:52 +000053#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
Michael Kuperstein82d5da52016-06-24 20:13:42 +000054#include "llvm/CodeGen/PreISelIntrinsicLowering.h"
Wei Mi90d195a2016-07-08 03:32:49 +000055#include "llvm/CodeGen/UnreachableBlockElim.h"
Chandler Carruth64764b42015-01-14 10:19:28 +000056#include "llvm/IR/Dominators.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000057#include "llvm/IR/IRPrintingPasses.h"
Chandler Carruth66445382014-01-11 08:16:35 +000058#include "llvm/IR/PassManager.h"
Chandler Carruth4d356312014-01-20 11:34:08 +000059#include "llvm/IR/Verifier.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000060#include "llvm/Support/Debug.h"
Chandler Carruth8b5a74192016-02-28 22:16:03 +000061#include "llvm/Support/Regex.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000062#include "llvm/Target/TargetMachine.h"
Xinliang David Li64dbb292016-06-05 05:12:23 +000063#include "llvm/Transforms/GCOVProfiler.h"
Chandler Carruth67fc52f2016-08-17 02:56:20 +000064#include "llvm/Transforms/IPO/AlwaysInliner.h"
Davide Italiano164b9bc2016-05-05 00:51:09 +000065#include "llvm/Transforms/IPO/ConstantMerge.h"
Davide Italiano92b933a2016-07-09 03:25:35 +000066#include "llvm/Transforms/IPO/CrossDSOCFI.h"
Sean Silvae3bb4572016-06-12 09:16:39 +000067#include "llvm/Transforms/IPO/DeadArgumentElimination.h"
Davide Italiano344e8382016-05-05 02:37:32 +000068#include "llvm/Transforms/IPO/ElimAvailExtern.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000069#include "llvm/Transforms/IPO/ForceFunctionAttrs.h"
Chandler Carruth9c4ed172016-02-18 11:03:11 +000070#include "llvm/Transforms/IPO/FunctionAttrs.h"
Teresa Johnson21241572016-07-18 21:22:24 +000071#include "llvm/Transforms/IPO/FunctionImport.h"
Davide Italiano66228c42016-05-03 19:39:15 +000072#include "llvm/Transforms/IPO/GlobalDCE.h"
Justin Bogner1a075012016-04-26 00:28:01 +000073#include "llvm/Transforms/IPO/GlobalOpt.h"
Davide Italiano2ae76dd2016-11-21 00:28:23 +000074#include "llvm/Transforms/IPO/GlobalSplit.h"
Chandler Carruth3a040e62015-12-27 08:41:34 +000075#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
Chandler Carruth1d963112016-12-20 03:15:32 +000076#include "llvm/Transforms/IPO/Inliner.h"
Justin Bogner4563a062016-04-26 20:15:52 +000077#include "llvm/Transforms/IPO/Internalize.h"
Davide Italianoe8ae0b52016-07-11 18:10:06 +000078#include "llvm/Transforms/IPO/LowerTypeTests.h"
Easwaran Raman1832bf62016-06-27 16:50:18 +000079#include "llvm/Transforms/IPO/PartialInlining.h"
Davide Italianof54f2f02016-05-05 21:05:36 +000080#include "llvm/Transforms/IPO/SCCP.h"
Justin Bogner21e15372015-10-30 23:28:12 +000081#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
Davide Italianod737dd22016-06-14 21:44:19 +000082#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000083#include "llvm/Transforms/InstCombine/InstCombine.h"
Xinliang David Lie6b89292016-04-18 17:47:38 +000084#include "llvm/Transforms/InstrProfiling.h"
Xinliang David Li8aebf442016-05-06 05:49:19 +000085#include "llvm/Transforms/PGOInstrumentation.h"
Xinliang David Lid38392e2016-05-27 23:20:16 +000086#include "llvm/Transforms/SampleProfile.h"
Justin Bogner19b67992015-10-30 23:13:18 +000087#include "llvm/Transforms/Scalar/ADCE.h"
Sean Silvaa4c2d152016-06-15 06:18:01 +000088#include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h"
Davide Italiano655a1452016-05-25 01:57:04 +000089#include "llvm/Transforms/Scalar/BDCE.h"
Adam Nemet3beef412016-07-18 16:29:17 +000090#include "llvm/Transforms/Scalar/ConstantHoisting.h"
Sean Silvab025d372016-07-06 23:26:29 +000091#include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h"
Justin Bogner395c2122016-04-22 19:40:41 +000092#include "llvm/Transforms/Scalar/DCE.h"
Justin Bogner594e07b2016-05-17 21:38:13 +000093#include "llvm/Transforms/Scalar/DeadStoreElimination.h"
Chandler Carruthe8c686a2015-02-01 10:51:23 +000094#include "llvm/Transforms/Scalar/EarlyCSE.h"
Michael Kuperstein83b753d2016-06-24 23:32:02 +000095#include "llvm/Transforms/Scalar/Float2Int.h"
Easwaran Raman019e0bf2016-06-03 22:54:26 +000096#include "llvm/Transforms/Scalar/GVN.h"
Davide Italiano89ab89d2016-06-14 00:49:23 +000097#include "llvm/Transforms/Scalar/GuardWidening.h"
Sanjoy Das4d4339d2016-06-05 18:01:19 +000098#include "llvm/Transforms/Scalar/IndVarSimplify.h"
Sean Silva46590d52016-06-14 00:51:09 +000099#include "llvm/Transforms/Scalar/JumpThreading.h"
Dehao Chenf400a092016-07-12 22:42:24 +0000100#include "llvm/Transforms/Scalar/LICM.h"
Teresa Johnson1eca6bc2016-08-13 04:11:27 +0000101#include "llvm/Transforms/Scalar/LoopDataPrefetch.h"
Jun Bum Limc837af32016-07-14 18:28:29 +0000102#include "llvm/Transforms/Scalar/LoopDeletion.h"
Adam Nemetb2593f72016-07-18 16:29:27 +0000103#include "llvm/Transforms/Scalar/LoopDistribute.h"
Dehao Chenb9f8e292016-07-12 18:45:51 +0000104#include "llvm/Transforms/Scalar/LoopIdiomRecognize.h"
Dehao Chendcafd5e2016-07-15 16:42:11 +0000105#include "llvm/Transforms/Scalar/LoopInstSimplify.h"
Justin Bognerd0d23412016-05-03 22:02:31 +0000106#include "llvm/Transforms/Scalar/LoopRotation.h"
Justin Bognerab6a5132016-05-03 21:47:32 +0000107#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
Dehao Chen6132ee82016-07-18 21:41:50 +0000108#include "llvm/Transforms/Scalar/LoopStrengthReduce.h"
Sean Silvae3c18a52016-07-19 23:54:23 +0000109#include "llvm/Transforms/Scalar/LoopUnrollPass.h"
Davide Italiano99223442016-05-13 22:52:35 +0000110#include "llvm/Transforms/Scalar/LowerAtomic.h"
Chandler Carruth43e590e2015-01-24 11:13:02 +0000111#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
Michael Kupersteine45d4d92016-07-28 22:08:41 +0000112#include "llvm/Transforms/Scalar/LowerGuardIntrinsic.h"
Sean Silva6347df02016-06-14 02:44:55 +0000113#include "llvm/Transforms/Scalar/MemCpyOptimizer.h"
Davide Italianob49aa5c2016-06-17 19:10:09 +0000114#include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
Wei Mi1cf58f82016-07-21 22:28:52 +0000115#include "llvm/Transforms/Scalar/NaryReassociate.h"
Davide Italianoe05e3302016-12-22 16:35:02 +0000116#include "llvm/Transforms/Scalar/NewGVN.h"
Davide Italiano1021c682016-05-25 23:38:53 +0000117#include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
Justin Bognerc2bf63d2016-04-26 23:39:29 +0000118#include "llvm/Transforms/Scalar/Reassociate.h"
Davide Italiano98f7e0e2016-05-18 15:18:25 +0000119#include "llvm/Transforms/Scalar/SCCP.h"
Chandler Carruth29a18a42015-09-12 09:09:14 +0000120#include "llvm/Transforms/Scalar/SROA.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +0000121#include "llvm/Transforms/Scalar/SimplifyCFG.h"
Justin Bognerb9394902016-04-22 19:54:10 +0000122#include "llvm/Transforms/Scalar/Sink.h"
Michael Kupersteinc4061862016-08-01 21:48:33 +0000123#include "llvm/Transforms/Scalar/SpeculativeExecution.h"
Sean Silva59fe82f2016-07-06 23:48:41 +0000124#include "llvm/Transforms/Scalar/TailRecursionElimination.h"
Xinliang David Li1eaecef2016-06-15 21:51:30 +0000125#include "llvm/Transforms/Utils/AddDiscriminators.h"
Wei Mie04d0ef2016-07-22 18:04:25 +0000126#include "llvm/Transforms/Utils/BreakCriticalEdges.h"
Easwaran Ramane12c4872016-06-09 19:44:46 +0000127#include "llvm/Transforms/Utils/LCSSA.h"
Rong Xu1c0e9b92016-10-18 21:36:27 +0000128#include "llvm/Transforms/Utils/LibCallsShrinkWrap.h"
Davide Italianocd96cfd2016-07-09 03:03:01 +0000129#include "llvm/Transforms/Utils/LoopSimplify.h"
Michael Kuperstein31b83992016-08-12 17:28:27 +0000130#include "llvm/Transforms/Utils/LowerInvoke.h"
Davide Italianocccf4f02016-06-14 03:22:22 +0000131#include "llvm/Transforms/Utils/Mem2Reg.h"
Geoff Berryb96d3b22016-06-01 21:30:40 +0000132#include "llvm/Transforms/Utils/MemorySSA.h"
Mehdi Amini27d23792016-09-16 16:56:30 +0000133#include "llvm/Transforms/Utils/NameAnonGlobals.h"
Davide Italiano16284df2016-07-07 21:14:36 +0000134#include "llvm/Transforms/Utils/SimplifyInstructions.h"
Michael Kuperstein39feb622016-07-25 20:52:00 +0000135#include "llvm/Transforms/Utils/SymbolRewriter.h"
Sean Silvadb90d4d2016-07-09 22:56:50 +0000136#include "llvm/Transforms/Vectorize/LoopVectorize.h"
Sean Silva0dacbd82016-07-09 03:11:29 +0000137#include "llvm/Transforms/Vectorize/SLPVectorizer.h"
Davide Italianocccf4f02016-06-14 03:22:22 +0000138
Chandler Carruth58dde8c2016-02-26 12:17:54 +0000139#include <type_traits>
Chandler Carruth66445382014-01-11 08:16:35 +0000140
141using namespace llvm;
142
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000143static Regex DefaultAliasRegex("^(default|lto-pre-link|lto)<(O[0123sz])>$");
144
Chandler Carruthe3f50642016-12-22 06:59:15 +0000145static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) {
146 switch (Level) {
147 case PassBuilder::O0:
148 case PassBuilder::O1:
149 case PassBuilder::O2:
150 case PassBuilder::O3:
151 return false;
152
153 case PassBuilder::Os:
154 case PassBuilder::Oz:
155 return true;
156 }
157 llvm_unreachable("Invalid optimization level!");
158}
159
Chandler Carruth66445382014-01-11 08:16:35 +0000160namespace {
161
Chandler Carruthd8330982014-01-12 09:34:22 +0000162/// \brief No-op module pass which does nothing.
Chandler Carruth66445382014-01-11 08:16:35 +0000163struct NoOpModulePass {
Sean Silvafd03ac62016-08-09 00:28:38 +0000164 PreservedAnalyses run(Module &M, ModuleAnalysisManager &) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000165 return PreservedAnalyses::all();
166 }
Chandler Carrutha13f27c2014-01-11 11:52:05 +0000167 static StringRef name() { return "NoOpModulePass"; }
Chandler Carruth66445382014-01-11 08:16:35 +0000168};
169
Chandler Carruth0b576b32015-01-06 02:50:06 +0000170/// \brief No-op module analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000171class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
172 friend AnalysisInfoMixin<NoOpModuleAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000173 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000174
175public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000176 struct Result {};
Sean Silvafd03ac62016-08-09 00:28:38 +0000177 Result run(Module &, ModuleAnalysisManager &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000178 static StringRef name() { return "NoOpModuleAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000179};
180
Chandler Carruth572e3402014-04-21 11:12:00 +0000181/// \brief No-op CGSCC pass which does nothing.
182struct NoOpCGSCCPass {
Chandler Carruth88823462016-08-24 09:37:14 +0000183 PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &,
184 LazyCallGraph &, CGSCCUpdateResult &UR) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000185 return PreservedAnalyses::all();
186 }
187 static StringRef name() { return "NoOpCGSCCPass"; }
188};
189
Chandler Carruth0b576b32015-01-06 02:50:06 +0000190/// \brief No-op CGSCC analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000191class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
192 friend AnalysisInfoMixin<NoOpCGSCCAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000193 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000194
195public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000196 struct Result {};
Chandler Carruth88823462016-08-24 09:37:14 +0000197 Result run(LazyCallGraph::SCC &, CGSCCAnalysisManager &, LazyCallGraph &G) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000198 return Result();
199 }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000200 static StringRef name() { return "NoOpCGSCCAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000201};
202
Chandler Carruthd8330982014-01-12 09:34:22 +0000203/// \brief No-op function pass which does nothing.
204struct NoOpFunctionPass {
Sean Silva36e0d012016-08-09 00:28:15 +0000205 PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000206 return PreservedAnalyses::all();
207 }
Chandler Carruthd8330982014-01-12 09:34:22 +0000208 static StringRef name() { return "NoOpFunctionPass"; }
209};
210
Chandler Carruth0b576b32015-01-06 02:50:06 +0000211/// \brief No-op function analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000212class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
213 friend AnalysisInfoMixin<NoOpFunctionAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000214 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000215
216public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000217 struct Result {};
Sean Silva36e0d012016-08-09 00:28:15 +0000218 Result run(Function &, FunctionAnalysisManager &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000219 static StringRef name() { return "NoOpFunctionAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000220};
221
Justin Bognereecc3c82016-02-25 07:23:08 +0000222/// \brief No-op loop pass which does nothing.
223struct NoOpLoopPass {
Chandler Carruth410eaeb2017-01-11 06:23:21 +0000224 PreservedAnalyses run(Loop &L, LoopAnalysisManager &,
225 LoopStandardAnalysisResults &, LPMUpdater &) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000226 return PreservedAnalyses::all();
227 }
Justin Bognereecc3c82016-02-25 07:23:08 +0000228 static StringRef name() { return "NoOpLoopPass"; }
229};
230
231/// \brief No-op loop analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000232class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
233 friend AnalysisInfoMixin<NoOpLoopAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000234 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000235
236public:
Justin Bognereecc3c82016-02-25 07:23:08 +0000237 struct Result {};
Chandler Carruth410eaeb2017-01-11 06:23:21 +0000238 Result run(Loop &, LoopAnalysisManager &, LoopStandardAnalysisResults &) {
239 return Result();
240 }
Justin Bognereecc3c82016-02-25 07:23:08 +0000241 static StringRef name() { return "NoOpLoopAnalysis"; }
Justin Bognereecc3c82016-02-25 07:23:08 +0000242};
243
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000244AnalysisKey NoOpModuleAnalysis::Key;
245AnalysisKey NoOpCGSCCAnalysis::Key;
246AnalysisKey NoOpFunctionAnalysis::Key;
247AnalysisKey NoOpLoopAnalysis::Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000248
Chandler Carruth66445382014-01-11 08:16:35 +0000249} // End anonymous namespace.
250
Chandler Carruth1ff77242015-03-07 09:02:36 +0000251void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000252#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000253 MAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000254#include "PassRegistry.def"
255}
256
Chandler Carruth1ff77242015-03-07 09:02:36 +0000257void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000258#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000259 CGAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000260#include "PassRegistry.def"
261}
262
Chandler Carruth1ff77242015-03-07 09:02:36 +0000263void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000264#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000265 FAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000266#include "PassRegistry.def"
267}
268
Justin Bognereecc3c82016-02-25 07:23:08 +0000269void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000270#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
Justin Bognereecc3c82016-02-25 07:23:08 +0000271 LAM.registerPass([&] { return CREATE_PASS; });
272#include "PassRegistry.def"
273}
274
Chandler Carruthe3f50642016-12-22 06:59:15 +0000275FunctionPassManager
276PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
277 bool DebugLogging) {
278 assert(Level != O0 && "Must request optimizations!");
279 FunctionPassManager FPM(DebugLogging);
280
281 // Form SSA out of local memory accesses after breaking apart aggregates into
282 // scalars.
283 FPM.addPass(SROA());
284
285 // Catch trivial redundancies
286 FPM.addPass(EarlyCSEPass());
287
288 // Speculative execution if the target has divergent branches; otherwise nop.
289 FPM.addPass(SpeculativeExecutionPass());
290
291 // Optimize based on known information about branches, and cleanup afterward.
292 FPM.addPass(JumpThreadingPass());
293 FPM.addPass(CorrelatedValuePropagationPass());
294 FPM.addPass(SimplifyCFGPass());
295 FPM.addPass(InstCombinePass());
296
297 if (!isOptimizingForSize(Level))
298 FPM.addPass(LibCallsShrinkWrapPass());
299
300 FPM.addPass(TailCallElimPass());
301 FPM.addPass(SimplifyCFGPass());
302
303 // Form canonically associated expression trees, and simplify the trees using
304 // basic mathematical properties. For example, this will form (nearly)
305 // minimal multiplication trees.
306 FPM.addPass(ReassociatePass());
307
308 // Add the primary loop simplification pipeline.
309 // FIXME: Currently this is split into two loop pass pipelines because we run
310 // some function passes in between them. These can and should be replaced by
311 // loop pass equivalenst but those aren't ready yet. Specifically,
312 // `SimplifyCFGPass` and `InstCombinePass` are used. We have
313 // `LoopSimplifyCFGPass` which isn't yet powerful enough, and the closest to
314 // the other we have is `LoopInstSimplify`.
315 LoopPassManager LPM1(DebugLogging), LPM2(DebugLogging);
316
Chandler Carruth81c8eda2016-12-27 10:16:46 +0000317 // FIXME: Enable these when the loop pass manager can support enforcing loop
318 // simplified and LCSSA form as well as updating the loop nest after
319 // transformations and we finsih porting the loop passes.
320#if 0
Chandler Carruthe3f50642016-12-22 06:59:15 +0000321 // Rotate Loop - disable header duplication at -Oz
322 LPM1.addPass(LoopRotatePass(Level != Oz));
323 LPM1.addPass(LICMPass());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000324 LPM1.addPass(LoopUnswitchPass(/* OptimizeForSize */ Level != O3));
325 LPM2.addPass(IndVarSimplifyPass());
326 LPM2.addPass(LoopIdiomPass());
327 LPM2.addPass(LoopDeletionPass());
328 LPM2.addPass(SimpleLoopUnrollPass());
329#endif
330 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM1)));
331 FPM.addPass(SimplifyCFGPass());
332 FPM.addPass(InstCombinePass());
333 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2)));
334
335 // Eliminate redundancies.
336 if (Level != O1) {
337 // These passes add substantial compile time so skip them at O1.
338 FPM.addPass(MergedLoadStoreMotionPass());
339 FPM.addPass(GVN());
340 }
341
342 // Specially optimize memory movement as it doesn't look like dataflow in SSA.
343 FPM.addPass(MemCpyOptPass());
344
345 // Sparse conditional constant propagation.
346 // FIXME: It isn't clear why we do this *after* loop passes rather than
347 // before...
348 FPM.addPass(SCCPPass());
349
350 // Delete dead bit computations (instcombine runs after to fold away the dead
351 // computations, and then ADCE will run later to exploit any new DCE
352 // opportunities that creates).
353 FPM.addPass(BDCEPass());
354
355 // Run instcombine after redundancy and dead bit elimination to exploit
356 // opportunities opened up by them.
357 FPM.addPass(InstCombinePass());
358
359 // Re-consider control flow based optimizations after redundancy elimination,
360 // redo DCE, etc.
361 FPM.addPass(JumpThreadingPass());
362 FPM.addPass(CorrelatedValuePropagationPass());
363 FPM.addPass(DSEPass());
Chandler Carruth81c8eda2016-12-27 10:16:46 +0000364 // FIXME: Enable this when the loop pass manager can support enforcing loop
365 // simplified and LCSSA form as well as updating the loop nest after
366 // transformations and we finsih porting the loop passes.
367#if 0
Chandler Carruthe3f50642016-12-22 06:59:15 +0000368 FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass()));
Chandler Carruth81c8eda2016-12-27 10:16:46 +0000369#endif
Chandler Carruthe3f50642016-12-22 06:59:15 +0000370
371 // Finally, do an expensive DCE pass to catch all the dead code exposed by
372 // the simplifications and basic cleanup after all the simplifications.
373 FPM.addPass(ADCEPass());
374 FPM.addPass(SimplifyCFGPass());
375 FPM.addPass(InstCombinePass());
376
377 return FPM;
378}
379
380ModulePassManager
381PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
382 bool DebugLogging) {
383 assert(Level != O0 && "Must request optimizations for the default pipeline!");
384 ModulePassManager MPM(DebugLogging);
385
386 // Force any function attributes we want the rest of the pipeline te observe.
387 MPM.addPass(ForceFunctionAttrsPass());
388
389 // Do basic inference of function attributes from known properties of system
390 // libraries and other oracles.
391 MPM.addPass(InferFunctionAttrsPass());
392
393 // Create an early function pass manager to cleanup the output of the
394 // frontend.
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000395 FunctionPassManager EarlyFPM(DebugLogging);
396 EarlyFPM.addPass(SimplifyCFGPass());
397 EarlyFPM.addPass(SROA());
398 EarlyFPM.addPass(EarlyCSEPass());
399 EarlyFPM.addPass(LowerExpectIntrinsicPass());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000400 EarlyFPM.addPass(GVNHoistPass());
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000401 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000402
403 // Interprocedural constant propagation now that basic cleanup has occured
404 // and prior to optimizing globals.
405 // FIXME: This position in the pipeline hasn't been carefully considered in
406 // years, it should be re-analyzed.
407 MPM.addPass(IPSCCPPass());
408
409 // Optimize globals to try and fold them into constants.
410 MPM.addPass(GlobalOptPass());
411
412 // Promote any localized globals to SSA registers.
413 // FIXME: Should this instead by a run of SROA?
414 // FIXME: We should probably run instcombine and simplify-cfg afterward to
415 // delete control flows that are dead once globals have been folded to
416 // constants.
417 MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
418
419 // Remove any dead arguments exposed by cleanups and constand folding
420 // globals.
421 MPM.addPass(DeadArgumentEliminationPass());
422
423 // Create a small function pass pipeline to cleanup after all the global
424 // optimizations.
425 FunctionPassManager GlobalCleanupPM(DebugLogging);
426 GlobalCleanupPM.addPass(InstCombinePass());
427 GlobalCleanupPM.addPass(SimplifyCFGPass());
428 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
429
430 // FIXME: Enable this when cross-IR-unit analysis invalidation is working.
431#if 0
432 MPM.addPass(RequireAnalysisPass<GlobalsAA>());
433#endif
434
435 // Now begin the main postorder CGSCC pipeline.
436 // FIXME: The current CGSCC pipeline has its origins in the legacy pass
437 // manager and trying to emulate its precise behavior. Much of this doesn't
438 // make a lot of sense and we should revisit the core CGSCC structure.
439 CGSCCPassManager MainCGPipeline(DebugLogging);
440
441 // Note: historically, the PruneEH pass was run first to deduce nounwind and
442 // generally clean up exception handling overhead. It isn't clear this is
443 // valuable as the inliner doesn't currently care whether it is inlining an
444 // invoke or a call.
445
446 // Run the inliner first. The theory is that we are walking bottom-up and so
447 // the callees have already been fully optimized, and we want to inline them
448 // into the callers so that our optimizations can reflect that.
449 // FIXME; Customize the threshold based on optimization level.
450 MainCGPipeline.addPass(InlinerPass());
451
452 // Now deduce any function attributes based in the current code.
453 MainCGPipeline.addPass(PostOrderFunctionAttrsPass());
454
455 // Lastly, add the core function simplification pipeline nested inside the
456 // CGSCC walk.
457 MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
458 buildFunctionSimplificationPipeline(Level, DebugLogging)));
459
460 MPM.addPass(
461 createModuleToPostOrderCGSCCPassAdaptor(std::move(MainCGPipeline)));
462
463 // This ends the canonicalization and simplification phase of the pipeline.
464 // At this point, we expect to have canonical and simple IR which we begin
465 // *optimizing* for efficient execution going forward.
466
467 // Eliminate externally available functions now that inlining is over -- we
468 // won't emit these anyways.
469 MPM.addPass(EliminateAvailableExternallyPass());
470
471 // Do RPO function attribute inference across the module to forward-propagate
472 // attributes where applicable.
473 // FIXME: Is this really an optimization rather than a canonicalization?
474 MPM.addPass(ReversePostOrderFunctionAttrsPass());
475
476 // Recompute GloblasAA here prior to function passes. This is particularly
477 // useful as the above will have inlined, DCE'ed, and function-attr
478 // propagated everything. We should at this point have a reasonably minimal
479 // and richly annotated call graph. By computing aliasing and mod/ref
480 // information for all local globals here, the late loop passes and notably
481 // the vectorizer will be able to use them to help recognize vectorizable
482 // memory operations.
483 // FIXME: Enable this once analysis invalidation is fully supported.
484#if 0
485 MPM.addPass(Require<GlobalsAA>());
486#endif
487
488 FunctionPassManager OptimizePM(DebugLogging);
489 OptimizePM.addPass(Float2IntPass());
490 // FIXME: We need to run some loop optimizations to re-rotate loops after
491 // simplify-cfg and others undo their rotation.
492
493 // Optimize the loop execution. These passes operate on entire loop nests
494 // rather than on each loop in an inside-out manner, and so they are actually
495 // function passes.
496 OptimizePM.addPass(LoopDistributePass());
Chandler Carruthe6352892016-12-28 02:24:55 +0000497#if 0
498 // FIXME: LoopVectorize relies on "requiring" LCSSA which isn't supported in
499 // the new PM.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000500 OptimizePM.addPass(LoopVectorizePass());
Chandler Carruthe6352892016-12-28 02:24:55 +0000501#endif
Chandler Carruthe3f50642016-12-22 06:59:15 +0000502 // FIXME: Need to port Loop Load Elimination and add it here.
503 OptimizePM.addPass(InstCombinePass());
504
505 // Optimize parallel scalar instruction chains into SIMD instructions.
506 OptimizePM.addPass(SLPVectorizerPass());
507
508 // Cleanup after vectorizers.
509 OptimizePM.addPass(SimplifyCFGPass());
510 OptimizePM.addPass(InstCombinePass());
511
512 // Unroll small loops to hide loop backedge latency and saturate any parallel
513 // execution resources of an out-of-order processor.
514 // FIXME: Need to add once loop pass pipeline is available.
515
516 // FIXME: Add the loop sink pass when ported.
517
518 // FIXME: Add cleanup from the loop pass manager when we're forming LCSSA
519 // here.
520
521 // Now that we've vectorized and unrolled loops, we may have more refined
522 // alignment information, try to re-derive it here.
523 OptimizePM.addPass(AlignmentFromAssumptionsPass());
524
525 // ADd the core optimizing pipeline.
526 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM)));
527
528 // Now we need to do some global optimization transforms.
529 // FIXME: It would seem like these should come first in the optimization
530 // pipeline and maybe be the bottom of the canonicalization pipeline? Weird
531 // ordering here.
532 MPM.addPass(GlobalDCEPass());
533 MPM.addPass(ConstantMergePass());
534
535 return MPM;
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000536}
537
Chandler Carruthe3f50642016-12-22 06:59:15 +0000538ModulePassManager
539PassBuilder::buildLTOPreLinkDefaultPipeline(OptimizationLevel Level,
540 bool DebugLogging) {
541 assert(Level != O0 && "Must request optimizations for the default pipeline!");
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000542 // FIXME: We should use a customized pre-link pipeline!
Chandler Carruthe3f50642016-12-22 06:59:15 +0000543 return buildPerModuleDefaultPipeline(Level, DebugLogging);
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000544}
545
Chandler Carruthe3f50642016-12-22 06:59:15 +0000546ModulePassManager PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
547 bool DebugLogging) {
548 assert(Level != O0 && "Must request optimizations for the default pipeline!");
549 ModulePassManager MPM(DebugLogging);
550
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000551 // FIXME: Finish fleshing this out to match the legacy LTO pipelines.
552 FunctionPassManager LateFPM(DebugLogging);
553 LateFPM.addPass(InstCombinePass());
554 LateFPM.addPass(SimplifyCFGPass());
555
556 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(LateFPM)));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000557
558 return MPM;
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000559}
560
Chandler Carruth060ad612016-12-23 20:38:19 +0000561AAManager PassBuilder::buildDefaultAAPipeline() {
562 AAManager AA;
563
564 // The order in which these are registered determines their priority when
565 // being queried.
566
567 // First we register the basic alias analysis that provides the majority of
568 // per-function local AA logic. This is a stateless, on-demand local set of
569 // AA techniques.
570 AA.registerFunctionAnalysis<BasicAA>();
571
572 // Next we query fast, specialized alias analyses that wrap IR-embedded
573 // information about aliasing.
574 AA.registerFunctionAnalysis<ScopedNoAliasAA>();
575 AA.registerFunctionAnalysis<TypeBasedAA>();
576
577 // Add support for querying global aliasing information when available.
Chandler Carruth534d6442016-12-24 05:11:17 +0000578 // Because the `AAManager` is a function analysis and `GlobalsAA` is a module
579 // analysis, all that the `AAManager` can do is query for any *cached*
580 // results from `GlobalsAA` through a readonly proxy..
Chandler Carruth060ad612016-12-23 20:38:19 +0000581#if 0
Chandler Carruth534d6442016-12-24 05:11:17 +0000582 // FIXME: Enable once the invalidation logic supports this. Currently, the
583 // `AAManager` will hold stale references to the module analyses.
Chandler Carruth060ad612016-12-23 20:38:19 +0000584 AA.registerModuleAnalysis<GlobalsAA>();
585#endif
586
587 return AA;
588}
589
Chandler Carruth241bf242016-08-03 07:44:48 +0000590static Optional<int> parseRepeatPassName(StringRef Name) {
591 if (!Name.consume_front("repeat<") || !Name.consume_back(">"))
592 return None;
593 int Count;
594 if (Name.getAsInteger(0, Count) || Count <= 0)
595 return None;
596 return Count;
597}
598
Chandler Carruth05ca5ac2016-12-28 11:07:33 +0000599static Optional<int> parseDevirtPassName(StringRef Name) {
600 if (!Name.consume_front("devirt<") || !Name.consume_back(">"))
601 return None;
602 int Count;
603 if (Name.getAsInteger(0, Count) || Count <= 0)
604 return None;
605 return Count;
606}
607
Chandler Carruth66445382014-01-11 08:16:35 +0000608static bool isModulePassName(StringRef Name) {
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000609 // Manually handle aliases for pre-configured pipeline fragments.
610 if (Name.startswith("default") || Name.startswith("lto"))
611 return DefaultAliasRegex.match(Name);
612
Chandler Carruth6cb2ab22016-08-03 03:21:41 +0000613 // Explicitly handle pass manager names.
614 if (Name == "module")
615 return true;
616 if (Name == "cgscc")
617 return true;
618 if (Name == "function")
619 return true;
620
Chandler Carruth241bf242016-08-03 07:44:48 +0000621 // Explicitly handle custom-parsed pass names.
622 if (parseRepeatPassName(Name))
623 return true;
624
Chandler Carruth74a8a222016-06-17 07:15:29 +0000625#define MODULE_PASS(NAME, CREATE_PASS) \
626 if (Name == NAME) \
627 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000628#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000629 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000630 return true;
631#include "PassRegistry.def"
632
Chandler Carruth66445382014-01-11 08:16:35 +0000633 return false;
634}
635
Chandler Carruth572e3402014-04-21 11:12:00 +0000636static bool isCGSCCPassName(StringRef Name) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +0000637 // Explicitly handle pass manager names.
638 if (Name == "cgscc")
639 return true;
640 if (Name == "function")
641 return true;
642
Chandler Carruth241bf242016-08-03 07:44:48 +0000643 // Explicitly handle custom-parsed pass names.
644 if (parseRepeatPassName(Name))
645 return true;
Chandler Carruth05ca5ac2016-12-28 11:07:33 +0000646 if (parseDevirtPassName(Name))
647 return true;
Chandler Carruth241bf242016-08-03 07:44:48 +0000648
Chandler Carruth74a8a222016-06-17 07:15:29 +0000649#define CGSCC_PASS(NAME, CREATE_PASS) \
650 if (Name == NAME) \
651 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000652#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000653 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000654 return true;
655#include "PassRegistry.def"
656
Chandler Carruth572e3402014-04-21 11:12:00 +0000657 return false;
658}
659
Chandler Carruthd8330982014-01-12 09:34:22 +0000660static bool isFunctionPassName(StringRef Name) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +0000661 // Explicitly handle pass manager names.
662 if (Name == "function")
663 return true;
664 if (Name == "loop")
665 return true;
666
Chandler Carruth241bf242016-08-03 07:44:48 +0000667 // Explicitly handle custom-parsed pass names.
668 if (parseRepeatPassName(Name))
669 return true;
670
Chandler Carruth74a8a222016-06-17 07:15:29 +0000671#define FUNCTION_PASS(NAME, CREATE_PASS) \
672 if (Name == NAME) \
673 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +0000674#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000675 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +0000676 return true;
677#include "PassRegistry.def"
678
Chandler Carruthd8330982014-01-12 09:34:22 +0000679 return false;
680}
681
Justin Bognereecc3c82016-02-25 07:23:08 +0000682static bool isLoopPassName(StringRef Name) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +0000683 // Explicitly handle pass manager names.
684 if (Name == "loop")
685 return true;
686
Chandler Carruth241bf242016-08-03 07:44:48 +0000687 // Explicitly handle custom-parsed pass names.
688 if (parseRepeatPassName(Name))
689 return true;
690
Chandler Carruth74a8a222016-06-17 07:15:29 +0000691#define LOOP_PASS(NAME, CREATE_PASS) \
692 if (Name == NAME) \
693 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +0000694#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
695 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
696 return true;
697#include "PassRegistry.def"
698
699 return false;
700}
701
Chandler Carruth6cb2ab22016-08-03 03:21:41 +0000702Optional<std::vector<PassBuilder::PipelineElement>>
703PassBuilder::parsePipelineText(StringRef Text) {
704 std::vector<PipelineElement> ResultPipeline;
705
706 SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
707 &ResultPipeline};
708 for (;;) {
709 std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
710 size_t Pos = Text.find_first_of(",()");
711 Pipeline.push_back({Text.substr(0, Pos), {}});
712
713 // If we have a single terminating name, we're done.
714 if (Pos == Text.npos)
715 break;
716
717 char Sep = Text[Pos];
718 Text = Text.substr(Pos + 1);
719 if (Sep == ',')
720 // Just a name ending in a comma, continue.
721 continue;
722
723 if (Sep == '(') {
724 // Push the inner pipeline onto the stack to continue processing.
725 PipelineStack.push_back(&Pipeline.back().InnerPipeline);
726 continue;
727 }
728
729 assert(Sep == ')' && "Bogus separator!");
730 // When handling the close parenthesis, we greedily consume them to avoid
731 // empty strings in the pipeline.
732 do {
733 // If we try to pop the outer pipeline we have unbalanced parentheses.
734 if (PipelineStack.size() == 1)
735 return None;
736
737 PipelineStack.pop_back();
738 } while (Text.consume_front(")"));
739
740 // Check if we've finished parsing.
741 if (Text.empty())
742 break;
743
744 // Otherwise, the end of an inner pipeline always has to be followed by
745 // a comma, and then we can continue.
746 if (!Text.consume_front(","))
747 return None;
748 }
749
750 if (PipelineStack.size() > 1)
751 // Unbalanced paretheses.
752 return None;
753
754 assert(PipelineStack.back() == &ResultPipeline &&
755 "Wrong pipeline at the bottom of the stack!");
756 return {std::move(ResultPipeline)};
757}
758
759bool PassBuilder::parseModulePass(ModulePassManager &MPM,
760 const PipelineElement &E, bool VerifyEachPass,
761 bool DebugLogging) {
762 auto &Name = E.Name;
763 auto &InnerPipeline = E.InnerPipeline;
764
765 // First handle complex passes like the pass managers which carry pipelines.
766 if (!InnerPipeline.empty()) {
767 if (Name == "module") {
768 ModulePassManager NestedMPM(DebugLogging);
769 if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
770 DebugLogging))
771 return false;
772 MPM.addPass(std::move(NestedMPM));
773 return true;
774 }
775 if (Name == "cgscc") {
776 CGSCCPassManager CGPM(DebugLogging);
777 if (!parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass,
778 DebugLogging))
779 return false;
780 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM),
781 DebugLogging));
782 return true;
783 }
784 if (Name == "function") {
785 FunctionPassManager FPM(DebugLogging);
786 if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
787 DebugLogging))
788 return false;
789 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
790 return true;
791 }
Chandler Carruth241bf242016-08-03 07:44:48 +0000792 if (auto Count = parseRepeatPassName(Name)) {
793 ModulePassManager NestedMPM(DebugLogging);
794 if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
795 DebugLogging))
796 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +0000797 MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +0000798 return true;
799 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +0000800 // Normal passes can't have pipelines.
801 return false;
802 }
803
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000804 // Manually handle aliases for pre-configured pipeline fragments.
805 if (Name.startswith("default") || Name.startswith("lto")) {
806 SmallVector<StringRef, 3> Matches;
807 if (!DefaultAliasRegex.match(Name, &Matches))
808 return false;
809 assert(Matches.size() == 3 && "Must capture two matched strings!");
810
Jordan Rosef85a95f2016-07-25 18:34:51 +0000811 OptimizationLevel L = StringSwitch<OptimizationLevel>(Matches[2])
812 .Case("O0", O0)
813 .Case("O1", O1)
814 .Case("O2", O2)
815 .Case("O3", O3)
816 .Case("Os", Os)
817 .Case("Oz", Oz);
Chandler Carruthe3f50642016-12-22 06:59:15 +0000818 if (L == O0)
819 // At O0 we do nothing at all!
820 return true;
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000821
822 if (Matches[1] == "default") {
Chandler Carruthe3f50642016-12-22 06:59:15 +0000823 MPM.addPass(buildPerModuleDefaultPipeline(L, DebugLogging));
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000824 } else if (Matches[1] == "lto-pre-link") {
Chandler Carruthe3f50642016-12-22 06:59:15 +0000825 MPM.addPass(buildLTOPreLinkDefaultPipeline(L, DebugLogging));
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000826 } else {
827 assert(Matches[1] == "lto" && "Not one of the matched options!");
Chandler Carruthe3f50642016-12-22 06:59:15 +0000828 MPM.addPass(buildLTODefaultPipeline(L, DebugLogging));
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000829 }
830 return true;
831 }
832
Chandler Carruth6cb2ab22016-08-03 03:21:41 +0000833 // Finally expand the basic registered passes from the .inc file.
Chandler Carruth58944182014-04-21 08:08:50 +0000834#define MODULE_PASS(NAME, CREATE_PASS) \
835 if (Name == NAME) { \
836 MPM.addPass(CREATE_PASS); \
837 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000838 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000839#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
840 if (Name == "require<" NAME ">") { \
Chandler Carruth9b35e6d2016-08-19 18:36:06 +0000841 MPM.addPass( \
842 RequireAnalysisPass< \
843 std::remove_reference<decltype(CREATE_PASS)>::type, Module>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000844 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000845 } \
846 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000847 MPM.addPass(InvalidateAnalysisPass< \
848 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000849 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000850 }
851#include "PassRegistry.def"
852
Chandler Carruth66445382014-01-11 08:16:35 +0000853 return false;
854}
855
Chandler Carruth6cb2ab22016-08-03 03:21:41 +0000856bool PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
857 const PipelineElement &E, bool VerifyEachPass,
858 bool DebugLogging) {
859 auto &Name = E.Name;
860 auto &InnerPipeline = E.InnerPipeline;
861
862 // First handle complex passes like the pass managers which carry pipelines.
863 if (!InnerPipeline.empty()) {
864 if (Name == "cgscc") {
865 CGSCCPassManager NestedCGPM(DebugLogging);
866 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
867 DebugLogging))
868 return false;
869 // Add the nested pass manager with the appropriate adaptor.
870 CGPM.addPass(std::move(NestedCGPM));
871 return true;
872 }
873 if (Name == "function") {
874 FunctionPassManager FPM(DebugLogging);
875 if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
876 DebugLogging))
877 return false;
878 // Add the nested pass manager with the appropriate adaptor.
879 CGPM.addPass(
880 createCGSCCToFunctionPassAdaptor(std::move(FPM), DebugLogging));
881 return true;
882 }
Chandler Carruth241bf242016-08-03 07:44:48 +0000883 if (auto Count = parseRepeatPassName(Name)) {
884 CGSCCPassManager NestedCGPM(DebugLogging);
885 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
886 DebugLogging))
887 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +0000888 CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +0000889 return true;
890 }
Chandler Carruth05ca5ac2016-12-28 11:07:33 +0000891 if (auto MaxRepetitions = parseDevirtPassName(Name)) {
892 CGSCCPassManager NestedCGPM(DebugLogging);
893 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
894 DebugLogging))
895 return false;
896 CGPM.addPass(createDevirtSCCRepeatedPass(std::move(NestedCGPM),
897 *MaxRepetitions, DebugLogging));
898 return true;
899 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +0000900 // Normal passes can't have pipelines.
901 return false;
902 }
903
904 // Now expand the basic registered passes from the .inc file.
Chandler Carruth572e3402014-04-21 11:12:00 +0000905#define CGSCC_PASS(NAME, CREATE_PASS) \
906 if (Name == NAME) { \
907 CGPM.addPass(CREATE_PASS); \
908 return true; \
909 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000910#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
911 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000912 CGPM.addPass(RequireAnalysisPass< \
Chandler Carruth9b35e6d2016-08-19 18:36:06 +0000913 std::remove_reference<decltype(CREATE_PASS)>::type, \
Chandler Carruth88823462016-08-24 09:37:14 +0000914 LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
915 CGSCCUpdateResult &>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000916 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000917 } \
918 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000919 CGPM.addPass(InvalidateAnalysisPass< \
920 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000921 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000922 }
923#include "PassRegistry.def"
924
Chandler Carruth572e3402014-04-21 11:12:00 +0000925 return false;
926}
927
Chandler Carruth6cb2ab22016-08-03 03:21:41 +0000928bool PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
929 const PipelineElement &E,
930 bool VerifyEachPass, bool DebugLogging) {
931 auto &Name = E.Name;
932 auto &InnerPipeline = E.InnerPipeline;
933
934 // First handle complex passes like the pass managers which carry pipelines.
935 if (!InnerPipeline.empty()) {
936 if (Name == "function") {
937 FunctionPassManager NestedFPM(DebugLogging);
938 if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
939 DebugLogging))
940 return false;
941 // Add the nested pass manager with the appropriate adaptor.
942 FPM.addPass(std::move(NestedFPM));
943 return true;
944 }
945 if (Name == "loop") {
946 LoopPassManager LPM(DebugLogging);
947 if (!parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass,
948 DebugLogging))
949 return false;
950 // Add the nested pass manager with the appropriate adaptor.
951 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM)));
952 return true;
953 }
Chandler Carruth241bf242016-08-03 07:44:48 +0000954 if (auto Count = parseRepeatPassName(Name)) {
955 FunctionPassManager NestedFPM(DebugLogging);
956 if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
957 DebugLogging))
958 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +0000959 FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +0000960 return true;
961 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +0000962 // Normal passes can't have pipelines.
963 return false;
964 }
965
966 // Now expand the basic registered passes from the .inc file.
Chandler Carruth58944182014-04-21 08:08:50 +0000967#define FUNCTION_PASS(NAME, CREATE_PASS) \
968 if (Name == NAME) { \
969 FPM.addPass(CREATE_PASS); \
970 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +0000971 }
Chandler Carruth628503e2015-01-06 02:10:51 +0000972#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
973 if (Name == "require<" NAME ">") { \
Chandler Carruth9b35e6d2016-08-19 18:36:06 +0000974 FPM.addPass( \
975 RequireAnalysisPass< \
976 std::remove_reference<decltype(CREATE_PASS)>::type, Function>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +0000977 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000978 } \
979 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +0000980 FPM.addPass(InvalidateAnalysisPass< \
981 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +0000982 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +0000983 }
984#include "PassRegistry.def"
985
Chandler Carruthd8330982014-01-12 09:34:22 +0000986 return false;
987}
988
Chandler Carruthfdc6ba12016-08-03 09:14:03 +0000989bool PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +0000990 bool VerifyEachPass, bool DebugLogging) {
Chandler Carruth241bf242016-08-03 07:44:48 +0000991 StringRef Name = E.Name;
Chandler Carruth6cb2ab22016-08-03 03:21:41 +0000992 auto &InnerPipeline = E.InnerPipeline;
993
994 // First handle complex passes like the pass managers which carry pipelines.
995 if (!InnerPipeline.empty()) {
996 if (Name == "loop") {
997 LoopPassManager NestedLPM(DebugLogging);
998 if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
999 DebugLogging))
1000 return false;
1001 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001002 LPM.addPass(std::move(NestedLPM));
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001003 return true;
1004 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001005 if (auto Count = parseRepeatPassName(Name)) {
1006 LoopPassManager NestedLPM(DebugLogging);
1007 if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
1008 DebugLogging))
1009 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001010 LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001011 return true;
1012 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001013 // Normal passes can't have pipelines.
1014 return false;
1015 }
1016
1017 // Now expand the basic registered passes from the .inc file.
Justin Bognereecc3c82016-02-25 07:23:08 +00001018#define LOOP_PASS(NAME, CREATE_PASS) \
1019 if (Name == NAME) { \
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001020 LPM.addPass(CREATE_PASS); \
Justin Bognereecc3c82016-02-25 07:23:08 +00001021 return true; \
1022 }
1023#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1024 if (Name == "require<" NAME ">") { \
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001025 LPM.addPass(RequireAnalysisPass< \
Chandler Carruth410eaeb2017-01-11 06:23:21 +00001026 std::remove_reference<decltype(CREATE_PASS)>::type, Loop, \
1027 LoopAnalysisManager, LoopStandardAnalysisResults &, \
1028 LPMUpdater &>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +00001029 return true; \
1030 } \
1031 if (Name == "invalidate<" NAME ">") { \
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001032 LPM.addPass(InvalidateAnalysisPass< \
Chandler Carruth470734b2016-02-26 12:30:18 +00001033 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +00001034 return true; \
1035 }
1036#include "PassRegistry.def"
1037
1038 return false;
1039}
1040
Chandler Carruthedf59962016-02-18 09:45:17 +00001041bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
Chandler Carruth45a9c202016-03-11 09:15:11 +00001042#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1043 if (Name == NAME) { \
1044 AA.registerModuleAnalysis< \
1045 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
1046 return true; \
1047 }
Chandler Carruthedf59962016-02-18 09:45:17 +00001048#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1049 if (Name == NAME) { \
Chandler Carruth58dde8c2016-02-26 12:17:54 +00001050 AA.registerFunctionAnalysis< \
1051 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
Chandler Carruthedf59962016-02-18 09:45:17 +00001052 return true; \
1053 }
1054#include "PassRegistry.def"
1055
1056 return false;
1057}
1058
Justin Bognereecc3c82016-02-25 07:23:08 +00001059bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001060 ArrayRef<PipelineElement> Pipeline,
Justin Bognereecc3c82016-02-25 07:23:08 +00001061 bool VerifyEachPass,
1062 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001063 for (const auto &Element : Pipeline) {
1064 if (!parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging))
1065 return false;
1066 // FIXME: No verifier support for Loop passes!
Justin Bognereecc3c82016-02-25 07:23:08 +00001067 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001068 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +00001069}
1070
Chandler Carruth1ff77242015-03-07 09:02:36 +00001071bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001072 ArrayRef<PipelineElement> Pipeline,
Chandler Carruth1ff77242015-03-07 09:02:36 +00001073 bool VerifyEachPass,
1074 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001075 for (const auto &Element : Pipeline) {
1076 if (!parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging))
1077 return false;
1078 if (VerifyEachPass)
1079 FPM.addPass(VerifierPass());
Chandler Carruthd8330982014-01-12 09:34:22 +00001080 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001081 return true;
Chandler Carruthd8330982014-01-12 09:34:22 +00001082}
1083
Chandler Carruth1ff77242015-03-07 09:02:36 +00001084bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001085 ArrayRef<PipelineElement> Pipeline,
Chandler Carruth1ff77242015-03-07 09:02:36 +00001086 bool VerifyEachPass,
1087 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001088 for (const auto &Element : Pipeline) {
1089 if (!parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging))
1090 return false;
1091 // FIXME: No verifier support for CGSCC passes!
Chandler Carruth572e3402014-04-21 11:12:00 +00001092 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001093 return true;
Chandler Carruth572e3402014-04-21 11:12:00 +00001094}
1095
NAKAMURA Takumia42f5282016-05-16 10:13:37 +00001096void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM,
1097 FunctionAnalysisManager &FAM,
1098 CGSCCAnalysisManager &CGAM,
1099 ModuleAnalysisManager &MAM) {
1100 MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
1101 MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
NAKAMURA Takumia42f5282016-05-16 10:13:37 +00001102 CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
1103 FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
1104 FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
1105 FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
1106 LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
1107}
1108
Chandler Carruth1ff77242015-03-07 09:02:36 +00001109bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001110 ArrayRef<PipelineElement> Pipeline,
Chandler Carruth1ff77242015-03-07 09:02:36 +00001111 bool VerifyEachPass,
1112 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001113 for (const auto &Element : Pipeline) {
1114 if (!parseModulePass(MPM, Element, VerifyEachPass, DebugLogging))
1115 return false;
1116 if (VerifyEachPass)
1117 MPM.addPass(VerifierPass());
Chandler Carruth66445382014-01-11 08:16:35 +00001118 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001119 return true;
Chandler Carruth66445382014-01-11 08:16:35 +00001120}
1121
1122// Primary pass pipeline description parsing routine.
1123// FIXME: Should this routine accept a TargetMachine or require the caller to
1124// pre-populate the analysis managers with target-specific stuff?
Chandler Carruth1ff77242015-03-07 09:02:36 +00001125bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
1126 StringRef PipelineText, bool VerifyEachPass,
1127 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001128 auto Pipeline = parsePipelineText(PipelineText);
1129 if (!Pipeline || Pipeline->empty())
1130 return false;
Chandler Carruth66445382014-01-11 08:16:35 +00001131
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001132 // If the first name isn't at the module layer, wrap the pipeline up
1133 // automatically.
1134 StringRef FirstName = Pipeline->front().Name;
Chandler Carruth66445382014-01-11 08:16:35 +00001135
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001136 if (!isModulePassName(FirstName)) {
1137 if (isCGSCCPassName(FirstName))
1138 Pipeline = {{"cgscc", std::move(*Pipeline)}};
1139 else if (isFunctionPassName(FirstName))
1140 Pipeline = {{"function", std::move(*Pipeline)}};
1141 else if (isLoopPassName(FirstName))
1142 Pipeline = {{"function", {{"loop", std::move(*Pipeline)}}}};
1143 else
1144 // Unknown pass name!
Chandler Carruth572e3402014-04-21 11:12:00 +00001145 return false;
Chandler Carruth572e3402014-04-21 11:12:00 +00001146 }
1147
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001148 return parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging);
Chandler Carruth66445382014-01-11 08:16:35 +00001149}
Chandler Carruthedf59962016-02-18 09:45:17 +00001150
1151bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) {
Chandler Carruth060ad612016-12-23 20:38:19 +00001152 // If the pipeline just consists of the word 'default' just replace the AA
1153 // manager with our default one.
1154 if (PipelineText == "default") {
1155 AA = buildDefaultAAPipeline();
1156 return true;
1157 }
1158
Chandler Carruthedf59962016-02-18 09:45:17 +00001159 while (!PipelineText.empty()) {
1160 StringRef Name;
1161 std::tie(Name, PipelineText) = PipelineText.split(',');
1162 if (!parseAAPassName(AA, Name))
1163 return false;
1164 }
1165
1166 return true;
1167}