blob: eb81e58b9b0e6c0a6563eca1e8373bb7510ff31e [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 Carruth61440d22016-03-10 00:55:30 +000041#include "llvm/Analysis/MemoryDependenceAnalysis.h"
Daniel Berlin554dcd82017-04-11 20:06:36 +000042#include "llvm/Analysis/MemorySSA.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"
Chandler Carruthaddcda42017-02-09 23:46:27 +000065#include "llvm/Transforms/IPO/ArgumentPromotion.h"
Davide Italiano164b9bc2016-05-05 00:51:09 +000066#include "llvm/Transforms/IPO/ConstantMerge.h"
Davide Italiano92b933a2016-07-09 03:25:35 +000067#include "llvm/Transforms/IPO/CrossDSOCFI.h"
Sean Silvae3bb4572016-06-12 09:16:39 +000068#include "llvm/Transforms/IPO/DeadArgumentElimination.h"
Davide Italiano344e8382016-05-05 02:37:32 +000069#include "llvm/Transforms/IPO/ElimAvailExtern.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000070#include "llvm/Transforms/IPO/ForceFunctionAttrs.h"
Chandler Carruth9c4ed172016-02-18 11:03:11 +000071#include "llvm/Transforms/IPO/FunctionAttrs.h"
Teresa Johnson21241572016-07-18 21:22:24 +000072#include "llvm/Transforms/IPO/FunctionImport.h"
Davide Italiano66228c42016-05-03 19:39:15 +000073#include "llvm/Transforms/IPO/GlobalDCE.h"
Justin Bogner1a075012016-04-26 00:28:01 +000074#include "llvm/Transforms/IPO/GlobalOpt.h"
Davide Italiano2ae76dd2016-11-21 00:28:23 +000075#include "llvm/Transforms/IPO/GlobalSplit.h"
Chandler Carruth3a040e62015-12-27 08:41:34 +000076#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
Chandler Carruth1d963112016-12-20 03:15:32 +000077#include "llvm/Transforms/IPO/Inliner.h"
Justin Bogner4563a062016-04-26 20:15:52 +000078#include "llvm/Transforms/IPO/Internalize.h"
Davide Italianoe8ae0b52016-07-11 18:10:06 +000079#include "llvm/Transforms/IPO/LowerTypeTests.h"
Easwaran Raman1832bf62016-06-27 16:50:18 +000080#include "llvm/Transforms/IPO/PartialInlining.h"
Davide Italianof54f2f02016-05-05 21:05:36 +000081#include "llvm/Transforms/IPO/SCCP.h"
Justin Bogner21e15372015-10-30 23:28:12 +000082#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
Davide Italianod737dd22016-06-14 21:44:19 +000083#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000084#include "llvm/Transforms/InstCombine/InstCombine.h"
Xinliang David Lie6b89292016-04-18 17:47:38 +000085#include "llvm/Transforms/InstrProfiling.h"
Xinliang David Li8aebf442016-05-06 05:49:19 +000086#include "llvm/Transforms/PGOInstrumentation.h"
Xinliang David Lid38392e2016-05-27 23:20:16 +000087#include "llvm/Transforms/SampleProfile.h"
Justin Bogner19b67992015-10-30 23:13:18 +000088#include "llvm/Transforms/Scalar/ADCE.h"
Sean Silvaa4c2d152016-06-15 06:18:01 +000089#include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h"
Davide Italiano655a1452016-05-25 01:57:04 +000090#include "llvm/Transforms/Scalar/BDCE.h"
Adam Nemet3beef412016-07-18 16:29:17 +000091#include "llvm/Transforms/Scalar/ConstantHoisting.h"
Sean Silvab025d372016-07-06 23:26:29 +000092#include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h"
Justin Bogner395c2122016-04-22 19:40:41 +000093#include "llvm/Transforms/Scalar/DCE.h"
Justin Bogner594e07b2016-05-17 21:38:13 +000094#include "llvm/Transforms/Scalar/DeadStoreElimination.h"
Chandler Carruthe8c686a2015-02-01 10:51:23 +000095#include "llvm/Transforms/Scalar/EarlyCSE.h"
Michael Kuperstein83b753d2016-06-24 23:32:02 +000096#include "llvm/Transforms/Scalar/Float2Int.h"
Easwaran Raman019e0bf2016-06-03 22:54:26 +000097#include "llvm/Transforms/Scalar/GVN.h"
Davide Italiano89ab89d2016-06-14 00:49:23 +000098#include "llvm/Transforms/Scalar/GuardWidening.h"
Chandler Carruth3bab7e12017-01-11 09:43:56 +000099#include "llvm/Transforms/Scalar/IVUsersPrinter.h"
Sanjoy Das4d4339d2016-06-05 18:01:19 +0000100#include "llvm/Transforms/Scalar/IndVarSimplify.h"
Sean Silva46590d52016-06-14 00:51:09 +0000101#include "llvm/Transforms/Scalar/JumpThreading.h"
Dehao Chenf400a092016-07-12 22:42:24 +0000102#include "llvm/Transforms/Scalar/LICM.h"
Chandler Carruth3bab7e12017-01-11 09:43:56 +0000103#include "llvm/Transforms/Scalar/LoopAccessAnalysisPrinter.h"
Teresa Johnson1eca6bc2016-08-13 04:11:27 +0000104#include "llvm/Transforms/Scalar/LoopDataPrefetch.h"
Jun Bum Limc837af32016-07-14 18:28:29 +0000105#include "llvm/Transforms/Scalar/LoopDeletion.h"
Adam Nemetb2593f72016-07-18 16:29:27 +0000106#include "llvm/Transforms/Scalar/LoopDistribute.h"
Dehao Chenb9f8e292016-07-12 18:45:51 +0000107#include "llvm/Transforms/Scalar/LoopIdiomRecognize.h"
Dehao Chendcafd5e2016-07-15 16:42:11 +0000108#include "llvm/Transforms/Scalar/LoopInstSimplify.h"
Chandler Carruthbaabda92017-01-27 01:32:26 +0000109#include "llvm/Transforms/Scalar/LoopLoadElimination.h"
Chandler Carruth3bab7e12017-01-11 09:43:56 +0000110#include "llvm/Transforms/Scalar/LoopPassManager.h"
Artur Pilipenko8fb3d572017-01-25 16:00:44 +0000111#include "llvm/Transforms/Scalar/LoopPredication.h"
Justin Bognerd0d23412016-05-03 22:02:31 +0000112#include "llvm/Transforms/Scalar/LoopRotation.h"
Justin Bognerab6a5132016-05-03 21:47:32 +0000113#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
Chandler Carruthe9b18e32017-01-20 08:42:19 +0000114#include "llvm/Transforms/Scalar/LoopSink.h"
Dehao Chen6132ee82016-07-18 21:41:50 +0000115#include "llvm/Transforms/Scalar/LoopStrengthReduce.h"
Sean Silvae3c18a52016-07-19 23:54:23 +0000116#include "llvm/Transforms/Scalar/LoopUnrollPass.h"
Davide Italiano99223442016-05-13 22:52:35 +0000117#include "llvm/Transforms/Scalar/LowerAtomic.h"
Chandler Carruth43e590e2015-01-24 11:13:02 +0000118#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
Michael Kupersteine45d4d92016-07-28 22:08:41 +0000119#include "llvm/Transforms/Scalar/LowerGuardIntrinsic.h"
Sean Silva6347df02016-06-14 02:44:55 +0000120#include "llvm/Transforms/Scalar/MemCpyOptimizer.h"
Davide Italianob49aa5c2016-06-17 19:10:09 +0000121#include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
Wei Mi1cf58f82016-07-21 22:28:52 +0000122#include "llvm/Transforms/Scalar/NaryReassociate.h"
Davide Italianoe05e3302016-12-22 16:35:02 +0000123#include "llvm/Transforms/Scalar/NewGVN.h"
Davide Italiano1021c682016-05-25 23:38:53 +0000124#include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
Justin Bognerc2bf63d2016-04-26 23:39:29 +0000125#include "llvm/Transforms/Scalar/Reassociate.h"
Davide Italiano98f7e0e2016-05-18 15:18:25 +0000126#include "llvm/Transforms/Scalar/SCCP.h"
Chandler Carruth29a18a42015-09-12 09:09:14 +0000127#include "llvm/Transforms/Scalar/SROA.h"
Chandler Carruth1353f9a2017-04-27 18:45:20 +0000128#include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +0000129#include "llvm/Transforms/Scalar/SimplifyCFG.h"
Justin Bognerb9394902016-04-22 19:54:10 +0000130#include "llvm/Transforms/Scalar/Sink.h"
Michael Kupersteinc4061862016-08-01 21:48:33 +0000131#include "llvm/Transforms/Scalar/SpeculativeExecution.h"
Sean Silva59fe82f2016-07-06 23:48:41 +0000132#include "llvm/Transforms/Scalar/TailRecursionElimination.h"
Xinliang David Li1eaecef2016-06-15 21:51:30 +0000133#include "llvm/Transforms/Utils/AddDiscriminators.h"
Wei Mie04d0ef2016-07-22 18:04:25 +0000134#include "llvm/Transforms/Utils/BreakCriticalEdges.h"
Easwaran Ramane12c4872016-06-09 19:44:46 +0000135#include "llvm/Transforms/Utils/LCSSA.h"
Rong Xu1c0e9b92016-10-18 21:36:27 +0000136#include "llvm/Transforms/Utils/LibCallsShrinkWrap.h"
Davide Italianocd96cfd2016-07-09 03:03:01 +0000137#include "llvm/Transforms/Utils/LoopSimplify.h"
Michael Kuperstein31b83992016-08-12 17:28:27 +0000138#include "llvm/Transforms/Utils/LowerInvoke.h"
Davide Italianocccf4f02016-06-14 03:22:22 +0000139#include "llvm/Transforms/Utils/Mem2Reg.h"
Mehdi Amini27d23792016-09-16 16:56:30 +0000140#include "llvm/Transforms/Utils/NameAnonGlobals.h"
Daniel Berlin439042b2017-02-07 21:10:46 +0000141#include "llvm/Transforms/Utils/PredicateInfo.h"
Davide Italiano16284df2016-07-07 21:14:36 +0000142#include "llvm/Transforms/Utils/SimplifyInstructions.h"
Michael Kuperstein39feb622016-07-25 20:52:00 +0000143#include "llvm/Transforms/Utils/SymbolRewriter.h"
Sean Silvadb90d4d2016-07-09 22:56:50 +0000144#include "llvm/Transforms/Vectorize/LoopVectorize.h"
Sean Silva0dacbd82016-07-09 03:11:29 +0000145#include "llvm/Transforms/Vectorize/SLPVectorizer.h"
Davide Italianocccf4f02016-06-14 03:22:22 +0000146
Chandler Carruth58dde8c2016-02-26 12:17:54 +0000147#include <type_traits>
Chandler Carruth66445382014-01-11 08:16:35 +0000148
149using namespace llvm;
150
Chandler Carruth719ffe12017-02-12 05:38:04 +0000151static cl::opt<unsigned> MaxDevirtIterations("pm-max-devirt-iterations",
152 cl::ReallyHidden, cl::init(4));
Xinliang David Li126157c2017-05-22 16:41:57 +0000153static cl::opt<bool>
154 RunPartialInlining("enable-npm-partial-inlining", cl::init(false),
155 cl::Hidden, cl::ZeroOrMore,
156 cl::desc("Run Partial inlinining pass"));
Chandler Carruth719ffe12017-02-12 05:38:04 +0000157
Davide Italiano8a09b8e2017-05-22 23:41:40 +0000158static cl::opt<bool>
Davide Italiano8e7d11a2017-05-22 23:47:11 +0000159 RunNewGVN("enable-npm-newgvn", cl::init(false),
Davide Italiano8a09b8e2017-05-22 23:41:40 +0000160 cl::Hidden, cl::ZeroOrMore,
161 cl::desc("Run NewGVN instead of GVN"));
162
Chandler Carruthc246a4c2017-04-27 00:28:03 +0000163static cl::opt<bool> EnableGVNHoist(
164 "enable-npm-gvn-hoist", cl::init(false), cl::Hidden,
165 cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"));
166
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000167static Regex DefaultAliasRegex(
168 "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$");
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000169
Chandler Carruthe3f50642016-12-22 06:59:15 +0000170static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) {
171 switch (Level) {
172 case PassBuilder::O0:
173 case PassBuilder::O1:
174 case PassBuilder::O2:
175 case PassBuilder::O3:
176 return false;
177
178 case PassBuilder::Os:
179 case PassBuilder::Oz:
180 return true;
181 }
182 llvm_unreachable("Invalid optimization level!");
183}
184
Chandler Carruth66445382014-01-11 08:16:35 +0000185namespace {
186
Chandler Carruthd8330982014-01-12 09:34:22 +0000187/// \brief No-op module pass which does nothing.
Chandler Carruth66445382014-01-11 08:16:35 +0000188struct NoOpModulePass {
Sean Silvafd03ac62016-08-09 00:28:38 +0000189 PreservedAnalyses run(Module &M, ModuleAnalysisManager &) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000190 return PreservedAnalyses::all();
191 }
Chandler Carrutha13f27c2014-01-11 11:52:05 +0000192 static StringRef name() { return "NoOpModulePass"; }
Chandler Carruth66445382014-01-11 08:16:35 +0000193};
194
Chandler Carruth0b576b32015-01-06 02:50:06 +0000195/// \brief No-op module analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000196class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
197 friend AnalysisInfoMixin<NoOpModuleAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000198 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000199
200public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000201 struct Result {};
Sean Silvafd03ac62016-08-09 00:28:38 +0000202 Result run(Module &, ModuleAnalysisManager &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000203 static StringRef name() { return "NoOpModuleAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000204};
205
Chandler Carruth572e3402014-04-21 11:12:00 +0000206/// \brief No-op CGSCC pass which does nothing.
207struct NoOpCGSCCPass {
Chandler Carruth88823462016-08-24 09:37:14 +0000208 PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &,
209 LazyCallGraph &, CGSCCUpdateResult &UR) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000210 return PreservedAnalyses::all();
211 }
212 static StringRef name() { return "NoOpCGSCCPass"; }
213};
214
Chandler Carruth0b576b32015-01-06 02:50:06 +0000215/// \brief No-op CGSCC analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000216class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
217 friend AnalysisInfoMixin<NoOpCGSCCAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000218 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000219
220public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000221 struct Result {};
Chandler Carruth88823462016-08-24 09:37:14 +0000222 Result run(LazyCallGraph::SCC &, CGSCCAnalysisManager &, LazyCallGraph &G) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000223 return Result();
224 }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000225 static StringRef name() { return "NoOpCGSCCAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000226};
227
Chandler Carruthd8330982014-01-12 09:34:22 +0000228/// \brief No-op function pass which does nothing.
229struct NoOpFunctionPass {
Sean Silva36e0d012016-08-09 00:28:15 +0000230 PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000231 return PreservedAnalyses::all();
232 }
Chandler Carruthd8330982014-01-12 09:34:22 +0000233 static StringRef name() { return "NoOpFunctionPass"; }
234};
235
Chandler Carruth0b576b32015-01-06 02:50:06 +0000236/// \brief No-op function analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000237class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
238 friend AnalysisInfoMixin<NoOpFunctionAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000239 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000240
241public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000242 struct Result {};
Sean Silva36e0d012016-08-09 00:28:15 +0000243 Result run(Function &, FunctionAnalysisManager &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000244 static StringRef name() { return "NoOpFunctionAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000245};
246
Justin Bognereecc3c82016-02-25 07:23:08 +0000247/// \brief No-op loop pass which does nothing.
248struct NoOpLoopPass {
Chandler Carruth410eaeb2017-01-11 06:23:21 +0000249 PreservedAnalyses run(Loop &L, LoopAnalysisManager &,
250 LoopStandardAnalysisResults &, LPMUpdater &) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000251 return PreservedAnalyses::all();
252 }
Justin Bognereecc3c82016-02-25 07:23:08 +0000253 static StringRef name() { return "NoOpLoopPass"; }
254};
255
256/// \brief No-op loop analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000257class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
258 friend AnalysisInfoMixin<NoOpLoopAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000259 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000260
261public:
Justin Bognereecc3c82016-02-25 07:23:08 +0000262 struct Result {};
Chandler Carruth410eaeb2017-01-11 06:23:21 +0000263 Result run(Loop &, LoopAnalysisManager &, LoopStandardAnalysisResults &) {
264 return Result();
265 }
Justin Bognereecc3c82016-02-25 07:23:08 +0000266 static StringRef name() { return "NoOpLoopAnalysis"; }
Justin Bognereecc3c82016-02-25 07:23:08 +0000267};
268
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000269AnalysisKey NoOpModuleAnalysis::Key;
270AnalysisKey NoOpCGSCCAnalysis::Key;
271AnalysisKey NoOpFunctionAnalysis::Key;
272AnalysisKey NoOpLoopAnalysis::Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000273
Chandler Carruth66445382014-01-11 08:16:35 +0000274} // End anonymous namespace.
275
Chandler Carruth1ff77242015-03-07 09:02:36 +0000276void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000277#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000278 MAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000279#include "PassRegistry.def"
280}
281
Chandler Carruth1ff77242015-03-07 09:02:36 +0000282void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000283#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000284 CGAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000285#include "PassRegistry.def"
286}
287
Chandler Carruth1ff77242015-03-07 09:02:36 +0000288void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000289#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000290 FAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000291#include "PassRegistry.def"
292}
293
Justin Bognereecc3c82016-02-25 07:23:08 +0000294void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000295#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
Justin Bognereecc3c82016-02-25 07:23:08 +0000296 LAM.registerPass([&] { return CREATE_PASS; });
297#include "PassRegistry.def"
298}
299
Chandler Carruthe3f50642016-12-22 06:59:15 +0000300FunctionPassManager
301PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
302 bool DebugLogging) {
303 assert(Level != O0 && "Must request optimizations!");
304 FunctionPassManager FPM(DebugLogging);
305
306 // Form SSA out of local memory accesses after breaking apart aggregates into
307 // scalars.
308 FPM.addPass(SROA());
309
310 // Catch trivial redundancies
311 FPM.addPass(EarlyCSEPass());
312
313 // Speculative execution if the target has divergent branches; otherwise nop.
314 FPM.addPass(SpeculativeExecutionPass());
315
316 // Optimize based on known information about branches, and cleanup afterward.
317 FPM.addPass(JumpThreadingPass());
318 FPM.addPass(CorrelatedValuePropagationPass());
319 FPM.addPass(SimplifyCFGPass());
320 FPM.addPass(InstCombinePass());
321
322 if (!isOptimizingForSize(Level))
323 FPM.addPass(LibCallsShrinkWrapPass());
324
325 FPM.addPass(TailCallElimPass());
326 FPM.addPass(SimplifyCFGPass());
327
328 // Form canonically associated expression trees, and simplify the trees using
329 // basic mathematical properties. For example, this will form (nearly)
330 // minimal multiplication trees.
331 FPM.addPass(ReassociatePass());
332
333 // Add the primary loop simplification pipeline.
334 // FIXME: Currently this is split into two loop pass pipelines because we run
335 // some function passes in between them. These can and should be replaced by
336 // loop pass equivalenst but those aren't ready yet. Specifically,
337 // `SimplifyCFGPass` and `InstCombinePass` are used. We have
338 // `LoopSimplifyCFGPass` which isn't yet powerful enough, and the closest to
339 // the other we have is `LoopInstSimplify`.
340 LoopPassManager LPM1(DebugLogging), LPM2(DebugLogging);
341
342 // Rotate Loop - disable header duplication at -Oz
343 LPM1.addPass(LoopRotatePass(Level != Oz));
344 LPM1.addPass(LICMPass());
Chandler Carruth86248d52017-05-26 01:24:11 +0000345 LPM1.addPass(SimpleLoopUnswitchPass());
Chandler Carruth79b733b2017-01-26 23:21:17 +0000346 LPM2.addPass(IndVarSimplifyPass());
347 LPM2.addPass(LoopIdiomRecognizePass());
348 LPM2.addPass(LoopDeletionPass());
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000349 // FIXME: The old pass manager has a hack to disable loop unrolling during
350 // ThinLTO when using sample PGO. Need to either fix it or port some
351 // workaround.
Dehao Chen7d230322017-02-18 03:46:51 +0000352 LPM2.addPass(LoopUnrollPass::createFull(Level));
Chandler Carruth79b733b2017-01-26 23:21:17 +0000353
Chandler Carruth0ede22e2017-02-09 23:54:57 +0000354 // We provide the opt remark emitter pass for LICM to use. We only need to do
355 // this once as it is immutable.
356 FPM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000357 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM1)));
358 FPM.addPass(SimplifyCFGPass());
359 FPM.addPass(InstCombinePass());
360 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2)));
361
362 // Eliminate redundancies.
363 if (Level != O1) {
364 // These passes add substantial compile time so skip them at O1.
365 FPM.addPass(MergedLoadStoreMotionPass());
Davide Italiano8a09b8e2017-05-22 23:41:40 +0000366 if (RunNewGVN)
367 FPM.addPass(NewGVNPass());
368 else
369 FPM.addPass(GVN());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000370 }
371
372 // Specially optimize memory movement as it doesn't look like dataflow in SSA.
373 FPM.addPass(MemCpyOptPass());
374
375 // Sparse conditional constant propagation.
376 // FIXME: It isn't clear why we do this *after* loop passes rather than
377 // before...
378 FPM.addPass(SCCPPass());
379
380 // Delete dead bit computations (instcombine runs after to fold away the dead
381 // computations, and then ADCE will run later to exploit any new DCE
382 // opportunities that creates).
383 FPM.addPass(BDCEPass());
384
385 // Run instcombine after redundancy and dead bit elimination to exploit
386 // opportunities opened up by them.
387 FPM.addPass(InstCombinePass());
388
389 // Re-consider control flow based optimizations after redundancy elimination,
390 // redo DCE, etc.
391 FPM.addPass(JumpThreadingPass());
392 FPM.addPass(CorrelatedValuePropagationPass());
393 FPM.addPass(DSEPass());
394 FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass()));
395
396 // Finally, do an expensive DCE pass to catch all the dead code exposed by
397 // the simplifications and basic cleanup after all the simplifications.
398 FPM.addPass(ADCEPass());
399 FPM.addPass(SimplifyCFGPass());
400 FPM.addPass(InstCombinePass());
401
402 return FPM;
403}
404
Davide Italiano513dfaa2017-02-13 15:26:22 +0000405static void addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
406 PassBuilder::OptimizationLevel Level,
407 bool RunProfileGen, std::string ProfileGenFile,
408 std::string ProfileUseFile) {
409 // Generally running simplification passes and the inliner with an high
410 // threshold results in smaller executables, but there may be cases where
411 // the size grows, so let's be conservative here and skip this simplification
412 // at -Os/Oz.
413 if (!isOptimizingForSize(Level)) {
414 InlineParams IP;
415
416 // In the old pass manager, this is a cl::opt. Should still this be one?
417 IP.DefaultThreshold = 75;
418
419 // FIXME: The hint threshold has the same value used by the regular inliner.
420 // This should probably be lowered after performance testing.
421 // FIXME: this comment is cargo culted from the old pass manager, revisit).
422 IP.HintThreshold = 325;
423
424 CGSCCPassManager CGPipeline(DebugLogging);
425
426 CGPipeline.addPass(InlinerPass(IP));
427
428 FunctionPassManager FPM;
429 FPM.addPass(SROA());
430 FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies.
431 FPM.addPass(SimplifyCFGPass()); // Merge & remove basic blocks.
432 FPM.addPass(InstCombinePass()); // Combine silly sequences.
433
434 // FIXME: Here the old pass manager inserts peephole extensions.
435 // Add them when they're supported.
436 CGPipeline.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
437
438 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPipeline)));
439 }
440
Chandler Carruthf4d62c42017-05-25 07:15:09 +0000441 // Delete anything that is now dead to make sure that we don't instrument
442 // dead code. Instrumentation can end up keeping dead code around and
443 // dramatically increase code size.
444 MPM.addPass(GlobalDCEPass());
445
Davide Italiano513dfaa2017-02-13 15:26:22 +0000446 if (RunProfileGen) {
447 MPM.addPass(PGOInstrumentationGen());
448
449 // Add the profile lowering pass.
450 InstrProfOptions Options;
451 if (!ProfileGenFile.empty())
452 Options.InstrProfileOutput = ProfileGenFile;
453 MPM.addPass(InstrProfiling(Options));
454 }
455
456 if (!ProfileUseFile.empty())
457 MPM.addPass(PGOInstrumentationUse(ProfileUseFile));
458}
459
Chandler Carruthe3f50642016-12-22 06:59:15 +0000460ModulePassManager
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000461PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
462 bool DebugLogging) {
Chandler Carruthe3f50642016-12-22 06:59:15 +0000463 ModulePassManager MPM(DebugLogging);
464
Chandler Carruthe3f50642016-12-22 06:59:15 +0000465 // Do basic inference of function attributes from known properties of system
466 // libraries and other oracles.
467 MPM.addPass(InferFunctionAttrsPass());
468
469 // Create an early function pass manager to cleanup the output of the
470 // frontend.
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000471 FunctionPassManager EarlyFPM(DebugLogging);
472 EarlyFPM.addPass(SimplifyCFGPass());
473 EarlyFPM.addPass(SROA());
474 EarlyFPM.addPass(EarlyCSEPass());
475 EarlyFPM.addPass(LowerExpectIntrinsicPass());
Chandler Carruthc246a4c2017-04-27 00:28:03 +0000476 if (EnableGVNHoist)
477 EarlyFPM.addPass(GVNHoistPass());
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000478 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000479
480 // Interprocedural constant propagation now that basic cleanup has occured
481 // and prior to optimizing globals.
482 // FIXME: This position in the pipeline hasn't been carefully considered in
483 // years, it should be re-analyzed.
484 MPM.addPass(IPSCCPPass());
485
486 // Optimize globals to try and fold them into constants.
487 MPM.addPass(GlobalOptPass());
488
489 // Promote any localized globals to SSA registers.
490 // FIXME: Should this instead by a run of SROA?
491 // FIXME: We should probably run instcombine and simplify-cfg afterward to
492 // delete control flows that are dead once globals have been folded to
493 // constants.
494 MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
495
496 // Remove any dead arguments exposed by cleanups and constand folding
497 // globals.
498 MPM.addPass(DeadArgumentEliminationPass());
499
500 // Create a small function pass pipeline to cleanup after all the global
501 // optimizations.
502 FunctionPassManager GlobalCleanupPM(DebugLogging);
503 GlobalCleanupPM.addPass(InstCombinePass());
504 GlobalCleanupPM.addPass(SimplifyCFGPass());
505 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
506
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000507 // Add all the requested passes for PGO, if requested.
Davide Italiano513dfaa2017-02-13 15:26:22 +0000508 if (PGOOpt) {
Dehao Chencc75d242017-02-23 22:15:18 +0000509 assert(PGOOpt->RunProfileGen || PGOOpt->SamplePGO ||
510 !PGOOpt->ProfileUseFile.empty());
Davide Italiano513dfaa2017-02-13 15:26:22 +0000511 addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
512 PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
Davide Italiano513dfaa2017-02-13 15:26:22 +0000513
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000514 // Indirect call promotion that promotes intra-module targes only.
515 MPM.addPass(PGOIndirectCallPromotion(false, PGOOpt && PGOOpt->SamplePGO));
516 }
Davide Italiano513dfaa2017-02-13 15:26:22 +0000517
Chandler Carruthe87fc8c2017-02-12 05:34:04 +0000518 // Require the GlobalsAA analysis for the module so we can query it within
519 // the CGSCC pipeline.
520 MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000521
Easwaran Raman5e6f9bd2017-05-04 16:58:45 +0000522 // Require the ProfileSummaryAnalysis for the module so we can query it within
523 // the inliner pass.
524 MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
525
Chandler Carruthe3f50642016-12-22 06:59:15 +0000526 // Now begin the main postorder CGSCC pipeline.
527 // FIXME: The current CGSCC pipeline has its origins in the legacy pass
528 // manager and trying to emulate its precise behavior. Much of this doesn't
529 // make a lot of sense and we should revisit the core CGSCC structure.
530 CGSCCPassManager MainCGPipeline(DebugLogging);
531
532 // Note: historically, the PruneEH pass was run first to deduce nounwind and
533 // generally clean up exception handling overhead. It isn't clear this is
534 // valuable as the inliner doesn't currently care whether it is inlining an
535 // invoke or a call.
536
537 // Run the inliner first. The theory is that we are walking bottom-up and so
538 // the callees have already been fully optimized, and we want to inline them
539 // into the callers so that our optimizations can reflect that.
540 // FIXME; Customize the threshold based on optimization level.
541 MainCGPipeline.addPass(InlinerPass());
542
543 // Now deduce any function attributes based in the current code.
544 MainCGPipeline.addPass(PostOrderFunctionAttrsPass());
545
Chandler Carruth0ede22e2017-02-09 23:54:57 +0000546 // When at O3 add argument promotion to the pass pipeline.
547 // FIXME: It isn't at all clear why this should be limited to O3.
548 if (Level == O3)
549 MainCGPipeline.addPass(ArgumentPromotionPass());
550
Chandler Carruthe3f50642016-12-22 06:59:15 +0000551 // Lastly, add the core function simplification pipeline nested inside the
552 // CGSCC walk.
553 MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
554 buildFunctionSimplificationPipeline(Level, DebugLogging)));
555
Chandler Carruth719ffe12017-02-12 05:38:04 +0000556 // We wrap the CGSCC pipeline in a devirtualization repeater. This will try
557 // to detect when we devirtualize indirect calls and iterate the SCC passes
558 // in that case to try and catch knock-on inlining or function attrs
559 // opportunities. Then we add it to the module pipeline by walking the SCCs
560 // in postorder (or bottom-up).
Chandler Carruthe3f50642016-12-22 06:59:15 +0000561 MPM.addPass(
Chandler Carruth719ffe12017-02-12 05:38:04 +0000562 createModuleToPostOrderCGSCCPassAdaptor(createDevirtSCCRepeatedPass(
563 std::move(MainCGPipeline), MaxDevirtIterations, DebugLogging)));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000564
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000565 return MPM;
566}
567
568ModulePassManager
569PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
570 bool DebugLogging) {
571 ModulePassManager MPM(DebugLogging);
572
573 // Optimize globals now that the module is fully simplified.
574 MPM.addPass(GlobalOptPass());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000575
Xinliang David Li126157c2017-05-22 16:41:57 +0000576 // Run partial inlining pass to partially inline functions that have
577 // large bodies.
578 if (RunPartialInlining)
579 MPM.addPass(PartialInlinerPass());
580
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000581 // Remove avail extern fns and globals definitions since we aren't compiling
582 // an object file for later LTO. For LTO we want to preserve these so they
583 // are eligible for inlining at link-time. Note if they are unreferenced they
584 // will be removed by GlobalDCE later, so this only impacts referenced
585 // available externally globals. Eventually they will be suppressed during
586 // codegen, but eliminating here enables more opportunity for GlobalDCE as it
587 // may make globals referenced by available external functions dead and saves
588 // running remaining passes on the eliminated functions.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000589 MPM.addPass(EliminateAvailableExternallyPass());
590
591 // Do RPO function attribute inference across the module to forward-propagate
592 // attributes where applicable.
593 // FIXME: Is this really an optimization rather than a canonicalization?
594 MPM.addPass(ReversePostOrderFunctionAttrsPass());
595
Chandler Carruthe87fc8c2017-02-12 05:34:04 +0000596 // Re-require GloblasAA here prior to function passes. This is particularly
Chandler Carruthe3f50642016-12-22 06:59:15 +0000597 // useful as the above will have inlined, DCE'ed, and function-attr
598 // propagated everything. We should at this point have a reasonably minimal
599 // and richly annotated call graph. By computing aliasing and mod/ref
600 // information for all local globals here, the late loop passes and notably
601 // the vectorizer will be able to use them to help recognize vectorizable
602 // memory operations.
Chandler Carruthe87fc8c2017-02-12 05:34:04 +0000603 MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000604
605 FunctionPassManager OptimizePM(DebugLogging);
606 OptimizePM.addPass(Float2IntPass());
607 // FIXME: We need to run some loop optimizations to re-rotate loops after
608 // simplify-cfg and others undo their rotation.
609
610 // Optimize the loop execution. These passes operate on entire loop nests
611 // rather than on each loop in an inside-out manner, and so they are actually
612 // function passes.
Chandler Carrutha95ff382017-01-27 00:50:21 +0000613
614 // First rotate loops that may have been un-rotated by prior passes.
615 OptimizePM.addPass(createFunctionToLoopPassAdaptor(LoopRotatePass()));
616
617 // Distribute loops to allow partial vectorization. I.e. isolate dependences
618 // into separate loop that would otherwise inhibit vectorization. This is
619 // currently only performed for loops marked with the metadata
620 // llvm.loop.distribute=true or when -enable-loop-distribute is specified.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000621 OptimizePM.addPass(LoopDistributePass());
Chandler Carrutha95ff382017-01-27 00:50:21 +0000622
623 // Now run the core loop vectorizer.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000624 OptimizePM.addPass(LoopVectorizePass());
Chandler Carrutha95ff382017-01-27 00:50:21 +0000625
Chandler Carruthbaabda92017-01-27 01:32:26 +0000626 // Eliminate loads by forwarding stores from the previous iteration to loads
627 // of the current iteration.
628 OptimizePM.addPass(LoopLoadEliminationPass());
Chandler Carrutha95ff382017-01-27 00:50:21 +0000629
630 // Cleanup after the loop optimization passes.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000631 OptimizePM.addPass(InstCombinePass());
632
Chandler Carrutha95ff382017-01-27 00:50:21 +0000633
634 // Now that we've formed fast to execute loop structures, we do further
635 // optimizations. These are run afterward as they might block doing complex
636 // analyses and transforms such as what are needed for loop vectorization.
637
Chandler Carruthe3f50642016-12-22 06:59:15 +0000638 // Optimize parallel scalar instruction chains into SIMD instructions.
639 OptimizePM.addPass(SLPVectorizerPass());
640
Chandler Carrutha95ff382017-01-27 00:50:21 +0000641 // Cleanup after all of the vectorizers.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000642 OptimizePM.addPass(SimplifyCFGPass());
643 OptimizePM.addPass(InstCombinePass());
644
645 // Unroll small loops to hide loop backedge latency and saturate any parallel
Chandler Carrutha95ff382017-01-27 00:50:21 +0000646 // execution resources of an out-of-order processor. We also then need to
647 // clean up redundancies and loop invariant code.
648 // FIXME: It would be really good to use a loop-integrated instruction
649 // combiner for cleanup here so that the unrolling and LICM can be pipelined
650 // across the loop nests.
Dehao Chen7d230322017-02-18 03:46:51 +0000651 OptimizePM.addPass(createFunctionToLoopPassAdaptor(LoopUnrollPass::create(Level)));
Chandler Carrutha95ff382017-01-27 00:50:21 +0000652 OptimizePM.addPass(InstCombinePass());
Chandler Carruth0ede22e2017-02-09 23:54:57 +0000653 OptimizePM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
Chandler Carrutha95ff382017-01-27 00:50:21 +0000654 OptimizePM.addPass(createFunctionToLoopPassAdaptor(LICMPass()));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000655
656 // Now that we've vectorized and unrolled loops, we may have more refined
657 // alignment information, try to re-derive it here.
658 OptimizePM.addPass(AlignmentFromAssumptionsPass());
659
Chandler Carrutha95ff382017-01-27 00:50:21 +0000660 // LoopSink pass sinks instructions hoisted by LICM, which serves as a
661 // canonicalization pass that enables other optimizations. As a result,
662 // LoopSink pass needs to be a very late IR pass to avoid undoing LICM
663 // result too early.
664 OptimizePM.addPass(LoopSinkPass());
665
666 // And finally clean up LCSSA form before generating code.
667 OptimizePM.addPass(InstSimplifierPass());
668
Filipe Cabecinhas92dc3482017-04-26 12:02:41 +0000669 // LoopSink (and other loop passes since the last simplifyCFG) might have
670 // resulted in single-entry-single-exit or empty blocks. Clean up the CFG.
671 OptimizePM.addPass(SimplifyCFGPass());
672
Chandler Carrutha95ff382017-01-27 00:50:21 +0000673 // Add the core optimizing pipeline.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000674 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM)));
675
676 // Now we need to do some global optimization transforms.
677 // FIXME: It would seem like these should come first in the optimization
678 // pipeline and maybe be the bottom of the canonicalization pipeline? Weird
679 // ordering here.
680 MPM.addPass(GlobalDCEPass());
681 MPM.addPass(ConstantMergePass());
682
683 return MPM;
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000684}
685
Chandler Carruthe3f50642016-12-22 06:59:15 +0000686ModulePassManager
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000687PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
688 bool DebugLogging) {
689 assert(Level != O0 && "Must request optimizations for the default pipeline!");
690
691 ModulePassManager MPM(DebugLogging);
692
693 // Force any function attributes we want the rest of the pipeline to observe.
694 MPM.addPass(ForceFunctionAttrsPass());
695
696 // Add the core simplification pipeline.
697 MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging));
698
699 // Now add the optimization pipeline.
700 MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
701
702 return MPM;
703}
704
705ModulePassManager
706PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level,
707 bool DebugLogging) {
708 assert(Level != O0 && "Must request optimizations for the default pipeline!");
709
710 ModulePassManager MPM(DebugLogging);
711
712 // Force any function attributes we want the rest of the pipeline to observe.
713 MPM.addPass(ForceFunctionAttrsPass());
714
715 // If we are planning to perform ThinLTO later, we don't bloat the code with
716 // unrolling/vectorization/... now. Just simplify the module as much as we
717 // can.
718 MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging));
719
720 // Run partial inlining pass to partially inline functions that have
721 // large bodies.
722 // FIXME: It isn't clear whether this is really the right place to run this
723 // in ThinLTO. Because there is another canonicalization and simplification
724 // phase that will run after the thin link, running this here ends up with
725 // less information than will be available later and it may grow functions in
726 // ways that aren't beneficial.
727 if (RunPartialInlining)
728 MPM.addPass(PartialInlinerPass());
729
730 // Reduce the size of the IR as much as possible.
731 MPM.addPass(GlobalOptPass());
732
733 // Rename anon globals to be able to export them in the summary.
734 MPM.addPass(NameAnonGlobalPass());
735
736 return MPM;
737}
738
739ModulePassManager
740PassBuilder::buildThinLTODefaultPipeline(OptimizationLevel Level,
741 bool DebugLogging) {
742 // FIXME: The summary index is not hooked in the new pass manager yet.
743 // When it's going to be hooked, enable WholeProgramDevirt and LowerTypeTest
744 // here.
745
746 ModulePassManager MPM(DebugLogging);
747
748 // Force any function attributes we want the rest of the pipeline to observe.
749 MPM.addPass(ForceFunctionAttrsPass());
750
751 // During the ThinLTO backend phase we perform early indirect call promotion
752 // here, before globalopt. Otherwise imported available_externally functions
753 // look unreferenced and are removed.
754 MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
755 PGOOpt && PGOOpt->SamplePGO &&
756 !PGOOpt->ProfileUseFile.empty()));
757
758 // Add the core simplification pipeline.
759 MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging));
760
761 // Now add the optimization pipeline.
762 MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
763
764 return MPM;
765}
766
767ModulePassManager
Chandler Carruthe3f50642016-12-22 06:59:15 +0000768PassBuilder::buildLTOPreLinkDefaultPipeline(OptimizationLevel Level,
769 bool DebugLogging) {
770 assert(Level != O0 && "Must request optimizations for the default pipeline!");
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000771 // FIXME: We should use a customized pre-link pipeline!
Chandler Carruthe3f50642016-12-22 06:59:15 +0000772 return buildPerModuleDefaultPipeline(Level, DebugLogging);
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000773}
774
Chandler Carruthe3f50642016-12-22 06:59:15 +0000775ModulePassManager PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
776 bool DebugLogging) {
777 assert(Level != O0 && "Must request optimizations for the default pipeline!");
778 ModulePassManager MPM(DebugLogging);
779
Davide Italiano089a9122017-01-24 00:57:39 +0000780 // Remove unused virtual tables to improve the quality of code generated by
781 // whole-program devirtualization and bitset lowering.
782 MPM.addPass(GlobalDCEPass());
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000783
Davide Italiano089a9122017-01-24 00:57:39 +0000784 // Force any function attributes we want the rest of the pipeline to observe.
785 MPM.addPass(ForceFunctionAttrsPass());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000786
Davide Italiano089a9122017-01-24 00:57:39 +0000787 // Do basic inference of function attributes from known properties of system
788 // libraries and other oracles.
789 MPM.addPass(InferFunctionAttrsPass());
790
791 if (Level > 1) {
792 // Indirect call promotion. This should promote all the targets that are
793 // left by the earlier promotion pass that promotes intra-module targets.
794 // This two-step promotion is to save the compile time. For LTO, it should
795 // produce the same result as if we only do promotion here.
Dehao Chencc75d242017-02-23 22:15:18 +0000796 MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
797 PGOOpt && PGOOpt->SamplePGO));
Davide Italiano089a9122017-01-24 00:57:39 +0000798
799 // Propagate constants at call sites into the functions they call. This
800 // opens opportunities for globalopt (and inlining) by substituting function
801 // pointers passed as arguments to direct uses of functions.
802 MPM.addPass(IPSCCPPass());
803 }
804
805 // Now deduce any function attributes based in the current code.
806 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
807 PostOrderFunctionAttrsPass()));
808
809 // Do RPO function attribute inference across the module to forward-propagate
810 // attributes where applicable.
811 // FIXME: Is this really an optimization rather than a canonicalization?
812 MPM.addPass(ReversePostOrderFunctionAttrsPass());
813
814 // Use inragne annotations on GEP indices to split globals where beneficial.
815 MPM.addPass(GlobalSplitPass());
816
817 // Run whole program optimization of virtual call when the list of callees
818 // is fixed.
819 MPM.addPass(WholeProgramDevirtPass());
820
821 // Stop here at -O1.
822 if (Level == 1)
823 return MPM;
824
825 // Optimize globals to try and fold them into constants.
826 MPM.addPass(GlobalOptPass());
827
828 // Promote any localized globals to SSA registers.
829 MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
830
831 // Linking modules together can lead to duplicate global constant, only
832 // keep one copy of each constant.
833 MPM.addPass(ConstantMergePass());
834
835 // Remove unused arguments from functions.
836 MPM.addPass(DeadArgumentEliminationPass());
837
838 // Reduce the code after globalopt and ipsccp. Both can open up significant
839 // simplification opportunities, and both can propagate functions through
840 // function pointers. When this happens, we often have to resolve varargs
841 // calls, etc, so let instcombine do this.
842 // FIXME: add peephole extensions here as the legacy PM does.
843 MPM.addPass(createModuleToFunctionPassAdaptor(InstCombinePass()));
844
845 // Note: historically, the PruneEH pass was run first to deduce nounwind and
846 // generally clean up exception handling overhead. It isn't clear this is
847 // valuable as the inliner doesn't currently care whether it is inlining an
848 // invoke or a call.
849 // Run the inliner now.
850 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(InlinerPass()));
851
852 // Optimize globals again after we ran the inliner.
853 MPM.addPass(GlobalOptPass());
854
855 // Garbage collect dead functions.
856 // FIXME: Add ArgumentPromotion pass after once it's ported.
857 MPM.addPass(GlobalDCEPass());
858
859 FunctionPassManager FPM(DebugLogging);
860
861 // The IPO Passes may leave cruft around. Clean up after them.
862 // FIXME: add peephole extensions here as the legacy PM does.
863 FPM.addPass(InstCombinePass());
864 FPM.addPass(JumpThreadingPass());
865
866 // Break up allocas
867 FPM.addPass(SROA());
868
869 // Run a few AA driver optimizations here and now to cleanup the code.
870 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
871
872 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
873 PostOrderFunctionAttrsPass()));
874 // FIXME: here we run IP alias analysis in the legacy PM.
875
876 FunctionPassManager MainFPM;
877
878 // FIXME: once we fix LoopPass Manager, add LICM here.
879 // FIXME: once we provide support for enabling MLSM, add it here.
880 // FIXME: once we provide support for enabling NewGVN, add it here.
Davide Italiano8a09b8e2017-05-22 23:41:40 +0000881 if (RunNewGVN)
882 MainFPM.addPass(NewGVNPass());
883 else
884 MainFPM.addPass(GVN());
Davide Italiano089a9122017-01-24 00:57:39 +0000885
886 // Remove dead memcpy()'s.
887 MainFPM.addPass(MemCpyOptPass());
888
889 // Nuke dead stores.
890 MainFPM.addPass(DSEPass());
891
892 // FIXME: at this point, we run a bunch of loop passes:
893 // indVarSimplify, loopDeletion, loopInterchange, loopUnrool,
894 // loopVectorize. Enable them once the remaining issue with LPM
895 // are sorted out.
896
897 MainFPM.addPass(InstCombinePass());
898 MainFPM.addPass(SimplifyCFGPass());
899 MainFPM.addPass(SCCPPass());
900 MainFPM.addPass(InstCombinePass());
901 MainFPM.addPass(BDCEPass());
902
903 // FIXME: We may want to run SLPVectorizer here.
904 // After vectorization, assume intrinsics may tell us more
905 // about pointer alignments.
906#if 0
907 MainFPM.add(AlignmentFromAssumptionsPass());
908#endif
909
910 // FIXME: Conditionally run LoadCombine here, after it's ported
911 // (in case we still have this pass, given its questionable usefulness).
912
913 // FIXME: add peephole extensions to the PM here.
914 MainFPM.addPass(InstCombinePass());
915 MainFPM.addPass(JumpThreadingPass());
916 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(MainFPM)));
917
918 // Create a function that performs CFI checks for cross-DSO calls with
919 // targets in the current module.
920 MPM.addPass(CrossDSOCFIPass());
921
922 // Lower type metadata and the type.test intrinsic. This pass supports
923 // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs
924 // to be run at link time if CFI is enabled. This pass does nothing if
925 // CFI is disabled.
926 // Enable once we add support for the summary in the new PM.
927#if 0
Peter Collingbourne857aba42017-02-09 21:45:01 +0000928 MPM.addPass(LowerTypeTestsPass(Summary ? PassSummaryAction::Export :
929 PassSummaryAction::None,
Davide Italiano089a9122017-01-24 00:57:39 +0000930 Summary));
931#endif
932
933 // Add late LTO optimization passes.
934 // Delete basic blocks, which optimization passes may have killed.
935 MPM.addPass(createModuleToFunctionPassAdaptor(SimplifyCFGPass()));
936
937 // Drop bodies of available eternally objects to improve GlobalDCE.
938 MPM.addPass(EliminateAvailableExternallyPass());
939
940 // Now that we have optimized the program, discard unreachable functions.
941 MPM.addPass(GlobalDCEPass());
942
943 // FIXME: Enable MergeFuncs, conditionally, after ported, maybe.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000944 return MPM;
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000945}
946
Chandler Carruth060ad612016-12-23 20:38:19 +0000947AAManager PassBuilder::buildDefaultAAPipeline() {
948 AAManager AA;
949
950 // The order in which these are registered determines their priority when
951 // being queried.
952
953 // First we register the basic alias analysis that provides the majority of
954 // per-function local AA logic. This is a stateless, on-demand local set of
955 // AA techniques.
956 AA.registerFunctionAnalysis<BasicAA>();
957
958 // Next we query fast, specialized alias analyses that wrap IR-embedded
959 // information about aliasing.
960 AA.registerFunctionAnalysis<ScopedNoAliasAA>();
961 AA.registerFunctionAnalysis<TypeBasedAA>();
962
963 // Add support for querying global aliasing information when available.
Chandler Carruth534d6442016-12-24 05:11:17 +0000964 // Because the `AAManager` is a function analysis and `GlobalsAA` is a module
965 // analysis, all that the `AAManager` can do is query for any *cached*
Chandler Carruthe87fc8c2017-02-12 05:34:04 +0000966 // results from `GlobalsAA` through a readonly proxy.
Chandler Carruth060ad612016-12-23 20:38:19 +0000967 AA.registerModuleAnalysis<GlobalsAA>();
Chandler Carruth060ad612016-12-23 20:38:19 +0000968
969 return AA;
970}
971
Chandler Carruth241bf242016-08-03 07:44:48 +0000972static Optional<int> parseRepeatPassName(StringRef Name) {
973 if (!Name.consume_front("repeat<") || !Name.consume_back(">"))
974 return None;
975 int Count;
976 if (Name.getAsInteger(0, Count) || Count <= 0)
977 return None;
978 return Count;
979}
980
Chandler Carruth05ca5ac2016-12-28 11:07:33 +0000981static Optional<int> parseDevirtPassName(StringRef Name) {
982 if (!Name.consume_front("devirt<") || !Name.consume_back(">"))
983 return None;
984 int Count;
985 if (Name.getAsInteger(0, Count) || Count <= 0)
986 return None;
987 return Count;
988}
989
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000990/// Tests whether a pass name starts with a valid prefix for a default pipeline
991/// alias.
992static bool startsWithDefaultPipelineAliasPrefix(StringRef Name) {
993 return Name.startswith("default") || Name.startswith("thinlto") ||
994 Name.startswith("lto");
995}
996
Chandler Carruth66445382014-01-11 08:16:35 +0000997static bool isModulePassName(StringRef Name) {
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000998 // Manually handle aliases for pre-configured pipeline fragments.
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000999 if (startsWithDefaultPipelineAliasPrefix(Name))
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001000 return DefaultAliasRegex.match(Name);
1001
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001002 // Explicitly handle pass manager names.
1003 if (Name == "module")
1004 return true;
1005 if (Name == "cgscc")
1006 return true;
1007 if (Name == "function")
1008 return true;
1009
Chandler Carruth241bf242016-08-03 07:44:48 +00001010 // Explicitly handle custom-parsed pass names.
1011 if (parseRepeatPassName(Name))
1012 return true;
1013
Chandler Carruth74a8a222016-06-17 07:15:29 +00001014#define MODULE_PASS(NAME, CREATE_PASS) \
1015 if (Name == NAME) \
1016 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +00001017#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001018 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +00001019 return true;
1020#include "PassRegistry.def"
1021
Chandler Carruth66445382014-01-11 08:16:35 +00001022 return false;
1023}
1024
Chandler Carruth572e3402014-04-21 11:12:00 +00001025static bool isCGSCCPassName(StringRef Name) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001026 // Explicitly handle pass manager names.
1027 if (Name == "cgscc")
1028 return true;
1029 if (Name == "function")
1030 return true;
1031
Chandler Carruth241bf242016-08-03 07:44:48 +00001032 // Explicitly handle custom-parsed pass names.
1033 if (parseRepeatPassName(Name))
1034 return true;
Chandler Carruth05ca5ac2016-12-28 11:07:33 +00001035 if (parseDevirtPassName(Name))
1036 return true;
Chandler Carruth241bf242016-08-03 07:44:48 +00001037
Chandler Carruth74a8a222016-06-17 07:15:29 +00001038#define CGSCC_PASS(NAME, CREATE_PASS) \
1039 if (Name == NAME) \
1040 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +00001041#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001042 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +00001043 return true;
1044#include "PassRegistry.def"
1045
Chandler Carruth572e3402014-04-21 11:12:00 +00001046 return false;
1047}
1048
Chandler Carruthd8330982014-01-12 09:34:22 +00001049static bool isFunctionPassName(StringRef Name) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001050 // Explicitly handle pass manager names.
1051 if (Name == "function")
1052 return true;
1053 if (Name == "loop")
1054 return true;
1055
Chandler Carruth241bf242016-08-03 07:44:48 +00001056 // Explicitly handle custom-parsed pass names.
1057 if (parseRepeatPassName(Name))
1058 return true;
1059
Chandler Carruth74a8a222016-06-17 07:15:29 +00001060#define FUNCTION_PASS(NAME, CREATE_PASS) \
1061 if (Name == NAME) \
1062 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +00001063#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001064 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +00001065 return true;
1066#include "PassRegistry.def"
1067
Chandler Carruthd8330982014-01-12 09:34:22 +00001068 return false;
1069}
1070
Justin Bognereecc3c82016-02-25 07:23:08 +00001071static bool isLoopPassName(StringRef Name) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001072 // Explicitly handle pass manager names.
1073 if (Name == "loop")
1074 return true;
1075
Chandler Carruth241bf242016-08-03 07:44:48 +00001076 // Explicitly handle custom-parsed pass names.
1077 if (parseRepeatPassName(Name))
1078 return true;
1079
Chandler Carruth74a8a222016-06-17 07:15:29 +00001080#define LOOP_PASS(NAME, CREATE_PASS) \
1081 if (Name == NAME) \
1082 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +00001083#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1084 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1085 return true;
1086#include "PassRegistry.def"
1087
1088 return false;
1089}
1090
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001091Optional<std::vector<PassBuilder::PipelineElement>>
1092PassBuilder::parsePipelineText(StringRef Text) {
1093 std::vector<PipelineElement> ResultPipeline;
1094
1095 SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
1096 &ResultPipeline};
1097 for (;;) {
1098 std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
1099 size_t Pos = Text.find_first_of(",()");
1100 Pipeline.push_back({Text.substr(0, Pos), {}});
1101
1102 // If we have a single terminating name, we're done.
1103 if (Pos == Text.npos)
1104 break;
1105
1106 char Sep = Text[Pos];
1107 Text = Text.substr(Pos + 1);
1108 if (Sep == ',')
1109 // Just a name ending in a comma, continue.
1110 continue;
1111
1112 if (Sep == '(') {
1113 // Push the inner pipeline onto the stack to continue processing.
1114 PipelineStack.push_back(&Pipeline.back().InnerPipeline);
1115 continue;
1116 }
1117
1118 assert(Sep == ')' && "Bogus separator!");
1119 // When handling the close parenthesis, we greedily consume them to avoid
1120 // empty strings in the pipeline.
1121 do {
1122 // If we try to pop the outer pipeline we have unbalanced parentheses.
1123 if (PipelineStack.size() == 1)
1124 return None;
1125
1126 PipelineStack.pop_back();
1127 } while (Text.consume_front(")"));
1128
1129 // Check if we've finished parsing.
1130 if (Text.empty())
1131 break;
1132
1133 // Otherwise, the end of an inner pipeline always has to be followed by
1134 // a comma, and then we can continue.
1135 if (!Text.consume_front(","))
1136 return None;
1137 }
1138
1139 if (PipelineStack.size() > 1)
1140 // Unbalanced paretheses.
1141 return None;
1142
1143 assert(PipelineStack.back() == &ResultPipeline &&
1144 "Wrong pipeline at the bottom of the stack!");
1145 return {std::move(ResultPipeline)};
1146}
1147
1148bool PassBuilder::parseModulePass(ModulePassManager &MPM,
1149 const PipelineElement &E, bool VerifyEachPass,
1150 bool DebugLogging) {
1151 auto &Name = E.Name;
1152 auto &InnerPipeline = E.InnerPipeline;
1153
1154 // First handle complex passes like the pass managers which carry pipelines.
1155 if (!InnerPipeline.empty()) {
1156 if (Name == "module") {
1157 ModulePassManager NestedMPM(DebugLogging);
1158 if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
1159 DebugLogging))
1160 return false;
1161 MPM.addPass(std::move(NestedMPM));
1162 return true;
1163 }
1164 if (Name == "cgscc") {
1165 CGSCCPassManager CGPM(DebugLogging);
1166 if (!parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass,
1167 DebugLogging))
1168 return false;
1169 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM),
1170 DebugLogging));
1171 return true;
1172 }
1173 if (Name == "function") {
1174 FunctionPassManager FPM(DebugLogging);
1175 if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
1176 DebugLogging))
1177 return false;
1178 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1179 return true;
1180 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001181 if (auto Count = parseRepeatPassName(Name)) {
1182 ModulePassManager NestedMPM(DebugLogging);
1183 if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
1184 DebugLogging))
1185 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001186 MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001187 return true;
1188 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001189 // Normal passes can't have pipelines.
1190 return false;
1191 }
1192
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001193 // Manually handle aliases for pre-configured pipeline fragments.
Chandler Carruth8b3be4e2017-06-01 11:39:39 +00001194 if (startsWithDefaultPipelineAliasPrefix(Name)) {
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001195 SmallVector<StringRef, 3> Matches;
1196 if (!DefaultAliasRegex.match(Name, &Matches))
1197 return false;
1198 assert(Matches.size() == 3 && "Must capture two matched strings!");
1199
Jordan Rosef85a95f2016-07-25 18:34:51 +00001200 OptimizationLevel L = StringSwitch<OptimizationLevel>(Matches[2])
1201 .Case("O0", O0)
1202 .Case("O1", O1)
1203 .Case("O2", O2)
1204 .Case("O3", O3)
1205 .Case("Os", Os)
1206 .Case("Oz", Oz);
Chandler Carruthe3f50642016-12-22 06:59:15 +00001207 if (L == O0)
1208 // At O0 we do nothing at all!
1209 return true;
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001210
1211 if (Matches[1] == "default") {
Chandler Carruthe3f50642016-12-22 06:59:15 +00001212 MPM.addPass(buildPerModuleDefaultPipeline(L, DebugLogging));
Chandler Carruth8b3be4e2017-06-01 11:39:39 +00001213 } else if (Matches[1] == "thinlto-pre-link") {
1214 MPM.addPass(buildThinLTOPreLinkDefaultPipeline(L, DebugLogging));
1215 } else if (Matches[1] == "thinlto") {
1216 MPM.addPass(buildThinLTODefaultPipeline(L, DebugLogging));
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001217 } else if (Matches[1] == "lto-pre-link") {
Chandler Carruthe3f50642016-12-22 06:59:15 +00001218 MPM.addPass(buildLTOPreLinkDefaultPipeline(L, DebugLogging));
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001219 } else {
1220 assert(Matches[1] == "lto" && "Not one of the matched options!");
Chandler Carruthe3f50642016-12-22 06:59:15 +00001221 MPM.addPass(buildLTODefaultPipeline(L, DebugLogging));
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001222 }
1223 return true;
1224 }
1225
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001226 // Finally expand the basic registered passes from the .inc file.
Chandler Carruth58944182014-04-21 08:08:50 +00001227#define MODULE_PASS(NAME, CREATE_PASS) \
1228 if (Name == NAME) { \
1229 MPM.addPass(CREATE_PASS); \
1230 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +00001231 }
Chandler Carruth628503e2015-01-06 02:10:51 +00001232#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1233 if (Name == "require<" NAME ">") { \
Chandler Carruth9b35e6d2016-08-19 18:36:06 +00001234 MPM.addPass( \
1235 RequireAnalysisPass< \
1236 std::remove_reference<decltype(CREATE_PASS)>::type, Module>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +00001237 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001238 } \
1239 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001240 MPM.addPass(InvalidateAnalysisPass< \
1241 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001242 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +00001243 }
1244#include "PassRegistry.def"
1245
Chandler Carruth66445382014-01-11 08:16:35 +00001246 return false;
1247}
1248
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001249bool PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
1250 const PipelineElement &E, bool VerifyEachPass,
1251 bool DebugLogging) {
1252 auto &Name = E.Name;
1253 auto &InnerPipeline = E.InnerPipeline;
1254
1255 // First handle complex passes like the pass managers which carry pipelines.
1256 if (!InnerPipeline.empty()) {
1257 if (Name == "cgscc") {
1258 CGSCCPassManager NestedCGPM(DebugLogging);
1259 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1260 DebugLogging))
1261 return false;
1262 // Add the nested pass manager with the appropriate adaptor.
1263 CGPM.addPass(std::move(NestedCGPM));
1264 return true;
1265 }
1266 if (Name == "function") {
1267 FunctionPassManager FPM(DebugLogging);
1268 if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
1269 DebugLogging))
1270 return false;
1271 // Add the nested pass manager with the appropriate adaptor.
1272 CGPM.addPass(
1273 createCGSCCToFunctionPassAdaptor(std::move(FPM), DebugLogging));
1274 return true;
1275 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001276 if (auto Count = parseRepeatPassName(Name)) {
1277 CGSCCPassManager NestedCGPM(DebugLogging);
1278 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1279 DebugLogging))
1280 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001281 CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001282 return true;
1283 }
Chandler Carruth05ca5ac2016-12-28 11:07:33 +00001284 if (auto MaxRepetitions = parseDevirtPassName(Name)) {
1285 CGSCCPassManager NestedCGPM(DebugLogging);
1286 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1287 DebugLogging))
1288 return false;
1289 CGPM.addPass(createDevirtSCCRepeatedPass(std::move(NestedCGPM),
1290 *MaxRepetitions, DebugLogging));
1291 return true;
1292 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001293 // Normal passes can't have pipelines.
1294 return false;
1295 }
1296
1297 // Now expand the basic registered passes from the .inc file.
Chandler Carruth572e3402014-04-21 11:12:00 +00001298#define CGSCC_PASS(NAME, CREATE_PASS) \
1299 if (Name == NAME) { \
1300 CGPM.addPass(CREATE_PASS); \
1301 return true; \
1302 }
Chandler Carruth628503e2015-01-06 02:10:51 +00001303#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1304 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001305 CGPM.addPass(RequireAnalysisPass< \
Chandler Carruth9b35e6d2016-08-19 18:36:06 +00001306 std::remove_reference<decltype(CREATE_PASS)>::type, \
Chandler Carruth88823462016-08-24 09:37:14 +00001307 LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
1308 CGSCCUpdateResult &>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +00001309 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001310 } \
1311 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001312 CGPM.addPass(InvalidateAnalysisPass< \
1313 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001314 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +00001315 }
1316#include "PassRegistry.def"
1317
Chandler Carruth572e3402014-04-21 11:12:00 +00001318 return false;
1319}
1320
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001321bool PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
1322 const PipelineElement &E,
1323 bool VerifyEachPass, bool DebugLogging) {
1324 auto &Name = E.Name;
1325 auto &InnerPipeline = E.InnerPipeline;
1326
1327 // First handle complex passes like the pass managers which carry pipelines.
1328 if (!InnerPipeline.empty()) {
1329 if (Name == "function") {
1330 FunctionPassManager NestedFPM(DebugLogging);
1331 if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
1332 DebugLogging))
1333 return false;
1334 // Add the nested pass manager with the appropriate adaptor.
1335 FPM.addPass(std::move(NestedFPM));
1336 return true;
1337 }
1338 if (Name == "loop") {
1339 LoopPassManager LPM(DebugLogging);
1340 if (!parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass,
1341 DebugLogging))
1342 return false;
1343 // Add the nested pass manager with the appropriate adaptor.
1344 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM)));
1345 return true;
1346 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001347 if (auto Count = parseRepeatPassName(Name)) {
1348 FunctionPassManager NestedFPM(DebugLogging);
1349 if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
1350 DebugLogging))
1351 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001352 FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001353 return true;
1354 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001355 // Normal passes can't have pipelines.
1356 return false;
1357 }
1358
1359 // Now expand the basic registered passes from the .inc file.
Chandler Carruth58944182014-04-21 08:08:50 +00001360#define FUNCTION_PASS(NAME, CREATE_PASS) \
1361 if (Name == NAME) { \
1362 FPM.addPass(CREATE_PASS); \
1363 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +00001364 }
Chandler Carruth628503e2015-01-06 02:10:51 +00001365#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1366 if (Name == "require<" NAME ">") { \
Chandler Carruth9b35e6d2016-08-19 18:36:06 +00001367 FPM.addPass( \
1368 RequireAnalysisPass< \
1369 std::remove_reference<decltype(CREATE_PASS)>::type, Function>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +00001370 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001371 } \
1372 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001373 FPM.addPass(InvalidateAnalysisPass< \
1374 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001375 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +00001376 }
1377#include "PassRegistry.def"
1378
Chandler Carruthd8330982014-01-12 09:34:22 +00001379 return false;
1380}
1381
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001382bool PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001383 bool VerifyEachPass, bool DebugLogging) {
Chandler Carruth241bf242016-08-03 07:44:48 +00001384 StringRef Name = E.Name;
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001385 auto &InnerPipeline = E.InnerPipeline;
1386
1387 // First handle complex passes like the pass managers which carry pipelines.
1388 if (!InnerPipeline.empty()) {
1389 if (Name == "loop") {
1390 LoopPassManager NestedLPM(DebugLogging);
1391 if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
1392 DebugLogging))
1393 return false;
1394 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001395 LPM.addPass(std::move(NestedLPM));
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001396 return true;
1397 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001398 if (auto Count = parseRepeatPassName(Name)) {
1399 LoopPassManager NestedLPM(DebugLogging);
1400 if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
1401 DebugLogging))
1402 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001403 LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001404 return true;
1405 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001406 // Normal passes can't have pipelines.
1407 return false;
1408 }
1409
1410 // Now expand the basic registered passes from the .inc file.
Justin Bognereecc3c82016-02-25 07:23:08 +00001411#define LOOP_PASS(NAME, CREATE_PASS) \
1412 if (Name == NAME) { \
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001413 LPM.addPass(CREATE_PASS); \
Justin Bognereecc3c82016-02-25 07:23:08 +00001414 return true; \
1415 }
1416#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1417 if (Name == "require<" NAME ">") { \
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001418 LPM.addPass(RequireAnalysisPass< \
Chandler Carruth410eaeb2017-01-11 06:23:21 +00001419 std::remove_reference<decltype(CREATE_PASS)>::type, Loop, \
1420 LoopAnalysisManager, LoopStandardAnalysisResults &, \
1421 LPMUpdater &>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +00001422 return true; \
1423 } \
1424 if (Name == "invalidate<" NAME ">") { \
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001425 LPM.addPass(InvalidateAnalysisPass< \
Chandler Carruth470734b2016-02-26 12:30:18 +00001426 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +00001427 return true; \
1428 }
1429#include "PassRegistry.def"
1430
1431 return false;
1432}
1433
Chandler Carruthedf59962016-02-18 09:45:17 +00001434bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
Chandler Carruth45a9c202016-03-11 09:15:11 +00001435#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1436 if (Name == NAME) { \
1437 AA.registerModuleAnalysis< \
1438 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
1439 return true; \
1440 }
Chandler Carruthedf59962016-02-18 09:45:17 +00001441#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1442 if (Name == NAME) { \
Chandler Carruth58dde8c2016-02-26 12:17:54 +00001443 AA.registerFunctionAnalysis< \
1444 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
Chandler Carruthedf59962016-02-18 09:45:17 +00001445 return true; \
1446 }
1447#include "PassRegistry.def"
1448
1449 return false;
1450}
1451
Justin Bognereecc3c82016-02-25 07:23:08 +00001452bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001453 ArrayRef<PipelineElement> Pipeline,
Justin Bognereecc3c82016-02-25 07:23:08 +00001454 bool VerifyEachPass,
1455 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001456 for (const auto &Element : Pipeline) {
1457 if (!parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging))
1458 return false;
1459 // FIXME: No verifier support for Loop passes!
Justin Bognereecc3c82016-02-25 07:23:08 +00001460 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001461 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +00001462}
1463
Chandler Carruth1ff77242015-03-07 09:02:36 +00001464bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001465 ArrayRef<PipelineElement> Pipeline,
Chandler Carruth1ff77242015-03-07 09:02:36 +00001466 bool VerifyEachPass,
1467 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001468 for (const auto &Element : Pipeline) {
1469 if (!parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging))
1470 return false;
1471 if (VerifyEachPass)
1472 FPM.addPass(VerifierPass());
Chandler Carruthd8330982014-01-12 09:34:22 +00001473 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001474 return true;
Chandler Carruthd8330982014-01-12 09:34:22 +00001475}
1476
Chandler Carruth1ff77242015-03-07 09:02:36 +00001477bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001478 ArrayRef<PipelineElement> Pipeline,
Chandler Carruth1ff77242015-03-07 09:02:36 +00001479 bool VerifyEachPass,
1480 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001481 for (const auto &Element : Pipeline) {
1482 if (!parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging))
1483 return false;
1484 // FIXME: No verifier support for CGSCC passes!
Chandler Carruth572e3402014-04-21 11:12:00 +00001485 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001486 return true;
Chandler Carruth572e3402014-04-21 11:12:00 +00001487}
1488
NAKAMURA Takumia42f5282016-05-16 10:13:37 +00001489void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM,
1490 FunctionAnalysisManager &FAM,
1491 CGSCCAnalysisManager &CGAM,
1492 ModuleAnalysisManager &MAM) {
1493 MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
1494 MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
NAKAMURA Takumia42f5282016-05-16 10:13:37 +00001495 CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
1496 FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
1497 FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
1498 FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
1499 LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
1500}
1501
Chandler Carruth1ff77242015-03-07 09:02:36 +00001502bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001503 ArrayRef<PipelineElement> Pipeline,
Chandler Carruth1ff77242015-03-07 09:02:36 +00001504 bool VerifyEachPass,
1505 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001506 for (const auto &Element : Pipeline) {
1507 if (!parseModulePass(MPM, Element, VerifyEachPass, DebugLogging))
1508 return false;
1509 if (VerifyEachPass)
1510 MPM.addPass(VerifierPass());
Chandler Carruth66445382014-01-11 08:16:35 +00001511 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001512 return true;
Chandler Carruth66445382014-01-11 08:16:35 +00001513}
1514
1515// Primary pass pipeline description parsing routine.
1516// FIXME: Should this routine accept a TargetMachine or require the caller to
1517// pre-populate the analysis managers with target-specific stuff?
Chandler Carruth1ff77242015-03-07 09:02:36 +00001518bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
1519 StringRef PipelineText, bool VerifyEachPass,
1520 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001521 auto Pipeline = parsePipelineText(PipelineText);
1522 if (!Pipeline || Pipeline->empty())
1523 return false;
Chandler Carruth66445382014-01-11 08:16:35 +00001524
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001525 // If the first name isn't at the module layer, wrap the pipeline up
1526 // automatically.
1527 StringRef FirstName = Pipeline->front().Name;
Chandler Carruth66445382014-01-11 08:16:35 +00001528
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001529 if (!isModulePassName(FirstName)) {
1530 if (isCGSCCPassName(FirstName))
1531 Pipeline = {{"cgscc", std::move(*Pipeline)}};
1532 else if (isFunctionPassName(FirstName))
1533 Pipeline = {{"function", std::move(*Pipeline)}};
1534 else if (isLoopPassName(FirstName))
1535 Pipeline = {{"function", {{"loop", std::move(*Pipeline)}}}};
1536 else
1537 // Unknown pass name!
Chandler Carruth572e3402014-04-21 11:12:00 +00001538 return false;
Chandler Carruth572e3402014-04-21 11:12:00 +00001539 }
1540
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001541 return parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging);
Chandler Carruth66445382014-01-11 08:16:35 +00001542}
Chandler Carruthedf59962016-02-18 09:45:17 +00001543
1544bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) {
Chandler Carruth060ad612016-12-23 20:38:19 +00001545 // If the pipeline just consists of the word 'default' just replace the AA
1546 // manager with our default one.
1547 if (PipelineText == "default") {
1548 AA = buildDefaultAAPipeline();
1549 return true;
1550 }
1551
Chandler Carruthedf59962016-02-18 09:45:17 +00001552 while (!PipelineText.empty()) {
1553 StringRef Name;
1554 std::tie(Name, PipelineText) = PipelineText.split(',');
1555 if (!parseAAPassName(AA, Name))
1556 return false;
1557 }
1558
1559 return true;
1560}