blob: 17c60348633c13d6bc98321f0d066efc75343efb [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
Davide Italianoc3688312017-06-01 23:08:14 +0000313 // Hoisting of scalars and load expressions.
314 if (EnableGVNHoist)
315 FPM.addPass(GVNHoistPass());
316
Chandler Carruthe3f50642016-12-22 06:59:15 +0000317 // Speculative execution if the target has divergent branches; otherwise nop.
318 FPM.addPass(SpeculativeExecutionPass());
319
320 // Optimize based on known information about branches, and cleanup afterward.
321 FPM.addPass(JumpThreadingPass());
322 FPM.addPass(CorrelatedValuePropagationPass());
323 FPM.addPass(SimplifyCFGPass());
324 FPM.addPass(InstCombinePass());
325
326 if (!isOptimizingForSize(Level))
327 FPM.addPass(LibCallsShrinkWrapPass());
328
329 FPM.addPass(TailCallElimPass());
330 FPM.addPass(SimplifyCFGPass());
331
332 // Form canonically associated expression trees, and simplify the trees using
333 // basic mathematical properties. For example, this will form (nearly)
334 // minimal multiplication trees.
335 FPM.addPass(ReassociatePass());
336
337 // Add the primary loop simplification pipeline.
338 // FIXME: Currently this is split into two loop pass pipelines because we run
339 // some function passes in between them. These can and should be replaced by
340 // loop pass equivalenst but those aren't ready yet. Specifically,
341 // `SimplifyCFGPass` and `InstCombinePass` are used. We have
342 // `LoopSimplifyCFGPass` which isn't yet powerful enough, and the closest to
343 // the other we have is `LoopInstSimplify`.
344 LoopPassManager LPM1(DebugLogging), LPM2(DebugLogging);
345
346 // Rotate Loop - disable header duplication at -Oz
347 LPM1.addPass(LoopRotatePass(Level != Oz));
348 LPM1.addPass(LICMPass());
Chandler Carruth86248d52017-05-26 01:24:11 +0000349 LPM1.addPass(SimpleLoopUnswitchPass());
Chandler Carruth79b733b2017-01-26 23:21:17 +0000350 LPM2.addPass(IndVarSimplifyPass());
351 LPM2.addPass(LoopIdiomRecognizePass());
352 LPM2.addPass(LoopDeletionPass());
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000353 // FIXME: The old pass manager has a hack to disable loop unrolling during
354 // ThinLTO when using sample PGO. Need to either fix it or port some
355 // workaround.
Dehao Chen7d230322017-02-18 03:46:51 +0000356 LPM2.addPass(LoopUnrollPass::createFull(Level));
Chandler Carruth79b733b2017-01-26 23:21:17 +0000357
Chandler Carruth0ede22e2017-02-09 23:54:57 +0000358 // We provide the opt remark emitter pass for LICM to use. We only need to do
359 // this once as it is immutable.
360 FPM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000361 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM1)));
362 FPM.addPass(SimplifyCFGPass());
363 FPM.addPass(InstCombinePass());
364 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2)));
365
366 // Eliminate redundancies.
367 if (Level != O1) {
368 // These passes add substantial compile time so skip them at O1.
369 FPM.addPass(MergedLoadStoreMotionPass());
Davide Italiano8a09b8e2017-05-22 23:41:40 +0000370 if (RunNewGVN)
371 FPM.addPass(NewGVNPass());
372 else
373 FPM.addPass(GVN());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000374 }
375
376 // Specially optimize memory movement as it doesn't look like dataflow in SSA.
377 FPM.addPass(MemCpyOptPass());
378
379 // Sparse conditional constant propagation.
380 // FIXME: It isn't clear why we do this *after* loop passes rather than
381 // before...
382 FPM.addPass(SCCPPass());
383
384 // Delete dead bit computations (instcombine runs after to fold away the dead
385 // computations, and then ADCE will run later to exploit any new DCE
386 // opportunities that creates).
387 FPM.addPass(BDCEPass());
388
389 // Run instcombine after redundancy and dead bit elimination to exploit
390 // opportunities opened up by them.
391 FPM.addPass(InstCombinePass());
392
393 // Re-consider control flow based optimizations after redundancy elimination,
394 // redo DCE, etc.
395 FPM.addPass(JumpThreadingPass());
396 FPM.addPass(CorrelatedValuePropagationPass());
397 FPM.addPass(DSEPass());
398 FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass()));
399
400 // Finally, do an expensive DCE pass to catch all the dead code exposed by
401 // the simplifications and basic cleanup after all the simplifications.
402 FPM.addPass(ADCEPass());
403 FPM.addPass(SimplifyCFGPass());
404 FPM.addPass(InstCombinePass());
405
406 return FPM;
407}
408
Davide Italiano513dfaa2017-02-13 15:26:22 +0000409static void addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
410 PassBuilder::OptimizationLevel Level,
411 bool RunProfileGen, std::string ProfileGenFile,
412 std::string ProfileUseFile) {
413 // Generally running simplification passes and the inliner with an high
414 // threshold results in smaller executables, but there may be cases where
415 // the size grows, so let's be conservative here and skip this simplification
416 // at -Os/Oz.
417 if (!isOptimizingForSize(Level)) {
418 InlineParams IP;
419
420 // In the old pass manager, this is a cl::opt. Should still this be one?
421 IP.DefaultThreshold = 75;
422
423 // FIXME: The hint threshold has the same value used by the regular inliner.
424 // This should probably be lowered after performance testing.
425 // FIXME: this comment is cargo culted from the old pass manager, revisit).
426 IP.HintThreshold = 325;
427
428 CGSCCPassManager CGPipeline(DebugLogging);
429
430 CGPipeline.addPass(InlinerPass(IP));
431
432 FunctionPassManager FPM;
433 FPM.addPass(SROA());
434 FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies.
435 FPM.addPass(SimplifyCFGPass()); // Merge & remove basic blocks.
436 FPM.addPass(InstCombinePass()); // Combine silly sequences.
437
438 // FIXME: Here the old pass manager inserts peephole extensions.
439 // Add them when they're supported.
440 CGPipeline.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
441
442 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPipeline)));
443 }
444
Chandler Carruthf4d62c42017-05-25 07:15:09 +0000445 // Delete anything that is now dead to make sure that we don't instrument
446 // dead code. Instrumentation can end up keeping dead code around and
447 // dramatically increase code size.
448 MPM.addPass(GlobalDCEPass());
449
Davide Italiano513dfaa2017-02-13 15:26:22 +0000450 if (RunProfileGen) {
451 MPM.addPass(PGOInstrumentationGen());
452
453 // Add the profile lowering pass.
454 InstrProfOptions Options;
455 if (!ProfileGenFile.empty())
456 Options.InstrProfileOutput = ProfileGenFile;
457 MPM.addPass(InstrProfiling(Options));
458 }
459
460 if (!ProfileUseFile.empty())
461 MPM.addPass(PGOInstrumentationUse(ProfileUseFile));
462}
463
Chandler Carruthe3f50642016-12-22 06:59:15 +0000464ModulePassManager
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000465PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
466 bool DebugLogging) {
Chandler Carruthe3f50642016-12-22 06:59:15 +0000467 ModulePassManager MPM(DebugLogging);
468
Chandler Carruthe3f50642016-12-22 06:59:15 +0000469 // Do basic inference of function attributes from known properties of system
470 // libraries and other oracles.
471 MPM.addPass(InferFunctionAttrsPass());
472
473 // Create an early function pass manager to cleanup the output of the
474 // frontend.
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000475 FunctionPassManager EarlyFPM(DebugLogging);
476 EarlyFPM.addPass(SimplifyCFGPass());
477 EarlyFPM.addPass(SROA());
478 EarlyFPM.addPass(EarlyCSEPass());
479 EarlyFPM.addPass(LowerExpectIntrinsicPass());
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000480 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000481
482 // Interprocedural constant propagation now that basic cleanup has occured
483 // and prior to optimizing globals.
484 // FIXME: This position in the pipeline hasn't been carefully considered in
485 // years, it should be re-analyzed.
486 MPM.addPass(IPSCCPPass());
487
488 // Optimize globals to try and fold them into constants.
489 MPM.addPass(GlobalOptPass());
490
491 // Promote any localized globals to SSA registers.
492 // FIXME: Should this instead by a run of SROA?
493 // FIXME: We should probably run instcombine and simplify-cfg afterward to
494 // delete control flows that are dead once globals have been folded to
495 // constants.
496 MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
497
498 // Remove any dead arguments exposed by cleanups and constand folding
499 // globals.
500 MPM.addPass(DeadArgumentEliminationPass());
501
502 // Create a small function pass pipeline to cleanup after all the global
503 // optimizations.
504 FunctionPassManager GlobalCleanupPM(DebugLogging);
505 GlobalCleanupPM.addPass(InstCombinePass());
506 GlobalCleanupPM.addPass(SimplifyCFGPass());
507 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
508
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000509 // Add all the requested passes for PGO, if requested.
Davide Italiano513dfaa2017-02-13 15:26:22 +0000510 if (PGOOpt) {
Dehao Chencc75d242017-02-23 22:15:18 +0000511 assert(PGOOpt->RunProfileGen || PGOOpt->SamplePGO ||
512 !PGOOpt->ProfileUseFile.empty());
Davide Italiano513dfaa2017-02-13 15:26:22 +0000513 addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
514 PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
Davide Italiano513dfaa2017-02-13 15:26:22 +0000515
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000516 // Indirect call promotion that promotes intra-module targes only.
517 MPM.addPass(PGOIndirectCallPromotion(false, PGOOpt && PGOOpt->SamplePGO));
518 }
Davide Italiano513dfaa2017-02-13 15:26:22 +0000519
Chandler Carruthe87fc8c2017-02-12 05:34:04 +0000520 // Require the GlobalsAA analysis for the module so we can query it within
521 // the CGSCC pipeline.
522 MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000523
Easwaran Raman5e6f9bd2017-05-04 16:58:45 +0000524 // Require the ProfileSummaryAnalysis for the module so we can query it within
525 // the inliner pass.
526 MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
527
Chandler Carruthe3f50642016-12-22 06:59:15 +0000528 // Now begin the main postorder CGSCC pipeline.
529 // FIXME: The current CGSCC pipeline has its origins in the legacy pass
530 // manager and trying to emulate its precise behavior. Much of this doesn't
531 // make a lot of sense and we should revisit the core CGSCC structure.
532 CGSCCPassManager MainCGPipeline(DebugLogging);
533
534 // Note: historically, the PruneEH pass was run first to deduce nounwind and
535 // generally clean up exception handling overhead. It isn't clear this is
536 // valuable as the inliner doesn't currently care whether it is inlining an
537 // invoke or a call.
538
539 // Run the inliner first. The theory is that we are walking bottom-up and so
540 // the callees have already been fully optimized, and we want to inline them
541 // into the callers so that our optimizations can reflect that.
542 // FIXME; Customize the threshold based on optimization level.
543 MainCGPipeline.addPass(InlinerPass());
544
545 // Now deduce any function attributes based in the current code.
546 MainCGPipeline.addPass(PostOrderFunctionAttrsPass());
547
Chandler Carruth0ede22e2017-02-09 23:54:57 +0000548 // When at O3 add argument promotion to the pass pipeline.
549 // FIXME: It isn't at all clear why this should be limited to O3.
550 if (Level == O3)
551 MainCGPipeline.addPass(ArgumentPromotionPass());
552
Chandler Carruthe3f50642016-12-22 06:59:15 +0000553 // Lastly, add the core function simplification pipeline nested inside the
554 // CGSCC walk.
555 MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
556 buildFunctionSimplificationPipeline(Level, DebugLogging)));
557
Chandler Carruth719ffe12017-02-12 05:38:04 +0000558 // We wrap the CGSCC pipeline in a devirtualization repeater. This will try
559 // to detect when we devirtualize indirect calls and iterate the SCC passes
560 // in that case to try and catch knock-on inlining or function attrs
561 // opportunities. Then we add it to the module pipeline by walking the SCCs
562 // in postorder (or bottom-up).
Chandler Carruthe3f50642016-12-22 06:59:15 +0000563 MPM.addPass(
Chandler Carruth719ffe12017-02-12 05:38:04 +0000564 createModuleToPostOrderCGSCCPassAdaptor(createDevirtSCCRepeatedPass(
565 std::move(MainCGPipeline), MaxDevirtIterations, DebugLogging)));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000566
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000567 return MPM;
568}
569
570ModulePassManager
571PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
572 bool DebugLogging) {
573 ModulePassManager MPM(DebugLogging);
574
575 // Optimize globals now that the module is fully simplified.
576 MPM.addPass(GlobalOptPass());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000577
Xinliang David Li126157c2017-05-22 16:41:57 +0000578 // Run partial inlining pass to partially inline functions that have
579 // large bodies.
580 if (RunPartialInlining)
581 MPM.addPass(PartialInlinerPass());
582
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000583 // Remove avail extern fns and globals definitions since we aren't compiling
584 // an object file for later LTO. For LTO we want to preserve these so they
585 // are eligible for inlining at link-time. Note if they are unreferenced they
586 // will be removed by GlobalDCE later, so this only impacts referenced
587 // available externally globals. Eventually they will be suppressed during
588 // codegen, but eliminating here enables more opportunity for GlobalDCE as it
589 // may make globals referenced by available external functions dead and saves
590 // running remaining passes on the eliminated functions.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000591 MPM.addPass(EliminateAvailableExternallyPass());
592
593 // Do RPO function attribute inference across the module to forward-propagate
594 // attributes where applicable.
595 // FIXME: Is this really an optimization rather than a canonicalization?
596 MPM.addPass(ReversePostOrderFunctionAttrsPass());
597
Chandler Carruthe87fc8c2017-02-12 05:34:04 +0000598 // Re-require GloblasAA here prior to function passes. This is particularly
Chandler Carruthe3f50642016-12-22 06:59:15 +0000599 // useful as the above will have inlined, DCE'ed, and function-attr
600 // propagated everything. We should at this point have a reasonably minimal
601 // and richly annotated call graph. By computing aliasing and mod/ref
602 // information for all local globals here, the late loop passes and notably
603 // the vectorizer will be able to use them to help recognize vectorizable
604 // memory operations.
Chandler Carruthe87fc8c2017-02-12 05:34:04 +0000605 MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000606
607 FunctionPassManager OptimizePM(DebugLogging);
608 OptimizePM.addPass(Float2IntPass());
609 // FIXME: We need to run some loop optimizations to re-rotate loops after
610 // simplify-cfg and others undo their rotation.
611
612 // Optimize the loop execution. These passes operate on entire loop nests
613 // rather than on each loop in an inside-out manner, and so they are actually
614 // function passes.
Chandler Carrutha95ff382017-01-27 00:50:21 +0000615
616 // First rotate loops that may have been un-rotated by prior passes.
617 OptimizePM.addPass(createFunctionToLoopPassAdaptor(LoopRotatePass()));
618
619 // Distribute loops to allow partial vectorization. I.e. isolate dependences
620 // into separate loop that would otherwise inhibit vectorization. This is
621 // currently only performed for loops marked with the metadata
622 // llvm.loop.distribute=true or when -enable-loop-distribute is specified.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000623 OptimizePM.addPass(LoopDistributePass());
Chandler Carrutha95ff382017-01-27 00:50:21 +0000624
625 // Now run the core loop vectorizer.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000626 OptimizePM.addPass(LoopVectorizePass());
Chandler Carrutha95ff382017-01-27 00:50:21 +0000627
Chandler Carruthbaabda92017-01-27 01:32:26 +0000628 // Eliminate loads by forwarding stores from the previous iteration to loads
629 // of the current iteration.
630 OptimizePM.addPass(LoopLoadEliminationPass());
Chandler Carrutha95ff382017-01-27 00:50:21 +0000631
632 // Cleanup after the loop optimization passes.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000633 OptimizePM.addPass(InstCombinePass());
634
Chandler Carrutha95ff382017-01-27 00:50:21 +0000635
636 // Now that we've formed fast to execute loop structures, we do further
637 // optimizations. These are run afterward as they might block doing complex
638 // analyses and transforms such as what are needed for loop vectorization.
639
Chandler Carruthe3f50642016-12-22 06:59:15 +0000640 // Optimize parallel scalar instruction chains into SIMD instructions.
641 OptimizePM.addPass(SLPVectorizerPass());
642
Chandler Carrutha95ff382017-01-27 00:50:21 +0000643 // Cleanup after all of the vectorizers.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000644 OptimizePM.addPass(SimplifyCFGPass());
645 OptimizePM.addPass(InstCombinePass());
646
647 // Unroll small loops to hide loop backedge latency and saturate any parallel
Chandler Carrutha95ff382017-01-27 00:50:21 +0000648 // execution resources of an out-of-order processor. We also then need to
649 // clean up redundancies and loop invariant code.
650 // FIXME: It would be really good to use a loop-integrated instruction
651 // combiner for cleanup here so that the unrolling and LICM can be pipelined
652 // across the loop nests.
Dehao Chen7d230322017-02-18 03:46:51 +0000653 OptimizePM.addPass(createFunctionToLoopPassAdaptor(LoopUnrollPass::create(Level)));
Chandler Carrutha95ff382017-01-27 00:50:21 +0000654 OptimizePM.addPass(InstCombinePass());
Chandler Carruth0ede22e2017-02-09 23:54:57 +0000655 OptimizePM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
Chandler Carrutha95ff382017-01-27 00:50:21 +0000656 OptimizePM.addPass(createFunctionToLoopPassAdaptor(LICMPass()));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000657
658 // Now that we've vectorized and unrolled loops, we may have more refined
659 // alignment information, try to re-derive it here.
660 OptimizePM.addPass(AlignmentFromAssumptionsPass());
661
Chandler Carrutha95ff382017-01-27 00:50:21 +0000662 // LoopSink pass sinks instructions hoisted by LICM, which serves as a
663 // canonicalization pass that enables other optimizations. As a result,
664 // LoopSink pass needs to be a very late IR pass to avoid undoing LICM
665 // result too early.
666 OptimizePM.addPass(LoopSinkPass());
667
668 // And finally clean up LCSSA form before generating code.
669 OptimizePM.addPass(InstSimplifierPass());
670
Filipe Cabecinhas92dc3482017-04-26 12:02:41 +0000671 // LoopSink (and other loop passes since the last simplifyCFG) might have
672 // resulted in single-entry-single-exit or empty blocks. Clean up the CFG.
673 OptimizePM.addPass(SimplifyCFGPass());
674
Chandler Carrutha95ff382017-01-27 00:50:21 +0000675 // Add the core optimizing pipeline.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000676 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM)));
677
678 // Now we need to do some global optimization transforms.
679 // FIXME: It would seem like these should come first in the optimization
680 // pipeline and maybe be the bottom of the canonicalization pipeline? Weird
681 // ordering here.
682 MPM.addPass(GlobalDCEPass());
683 MPM.addPass(ConstantMergePass());
684
685 return MPM;
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000686}
687
Chandler Carruthe3f50642016-12-22 06:59:15 +0000688ModulePassManager
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000689PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
690 bool DebugLogging) {
691 assert(Level != O0 && "Must request optimizations for the default pipeline!");
692
693 ModulePassManager MPM(DebugLogging);
694
695 // Force any function attributes we want the rest of the pipeline to observe.
696 MPM.addPass(ForceFunctionAttrsPass());
697
698 // Add the core simplification pipeline.
699 MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging));
700
701 // Now add the optimization pipeline.
702 MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
703
704 return MPM;
705}
706
707ModulePassManager
708PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level,
709 bool DebugLogging) {
710 assert(Level != O0 && "Must request optimizations for the default pipeline!");
711
712 ModulePassManager MPM(DebugLogging);
713
714 // Force any function attributes we want the rest of the pipeline to observe.
715 MPM.addPass(ForceFunctionAttrsPass());
716
717 // If we are planning to perform ThinLTO later, we don't bloat the code with
718 // unrolling/vectorization/... now. Just simplify the module as much as we
719 // can.
720 MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging));
721
722 // Run partial inlining pass to partially inline functions that have
723 // large bodies.
724 // FIXME: It isn't clear whether this is really the right place to run this
725 // in ThinLTO. Because there is another canonicalization and simplification
726 // phase that will run after the thin link, running this here ends up with
727 // less information than will be available later and it may grow functions in
728 // ways that aren't beneficial.
729 if (RunPartialInlining)
730 MPM.addPass(PartialInlinerPass());
731
732 // Reduce the size of the IR as much as possible.
733 MPM.addPass(GlobalOptPass());
734
735 // Rename anon globals to be able to export them in the summary.
736 MPM.addPass(NameAnonGlobalPass());
737
738 return MPM;
739}
740
741ModulePassManager
742PassBuilder::buildThinLTODefaultPipeline(OptimizationLevel Level,
743 bool DebugLogging) {
744 // FIXME: The summary index is not hooked in the new pass manager yet.
745 // When it's going to be hooked, enable WholeProgramDevirt and LowerTypeTest
746 // here.
747
748 ModulePassManager MPM(DebugLogging);
749
750 // Force any function attributes we want the rest of the pipeline to observe.
751 MPM.addPass(ForceFunctionAttrsPass());
752
753 // During the ThinLTO backend phase we perform early indirect call promotion
754 // here, before globalopt. Otherwise imported available_externally functions
755 // look unreferenced and are removed.
756 MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
757 PGOOpt && PGOOpt->SamplePGO &&
758 !PGOOpt->ProfileUseFile.empty()));
759
760 // Add the core simplification pipeline.
761 MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging));
762
763 // Now add the optimization pipeline.
764 MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
765
766 return MPM;
767}
768
769ModulePassManager
Chandler Carruthe3f50642016-12-22 06:59:15 +0000770PassBuilder::buildLTOPreLinkDefaultPipeline(OptimizationLevel Level,
771 bool DebugLogging) {
772 assert(Level != O0 && "Must request optimizations for the default pipeline!");
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000773 // FIXME: We should use a customized pre-link pipeline!
Chandler Carruthe3f50642016-12-22 06:59:15 +0000774 return buildPerModuleDefaultPipeline(Level, DebugLogging);
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000775}
776
Chandler Carruthe3f50642016-12-22 06:59:15 +0000777ModulePassManager PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
778 bool DebugLogging) {
779 assert(Level != O0 && "Must request optimizations for the default pipeline!");
780 ModulePassManager MPM(DebugLogging);
781
Davide Italiano089a9122017-01-24 00:57:39 +0000782 // Remove unused virtual tables to improve the quality of code generated by
783 // whole-program devirtualization and bitset lowering.
784 MPM.addPass(GlobalDCEPass());
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000785
Davide Italiano089a9122017-01-24 00:57:39 +0000786 // Force any function attributes we want the rest of the pipeline to observe.
787 MPM.addPass(ForceFunctionAttrsPass());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000788
Davide Italiano089a9122017-01-24 00:57:39 +0000789 // Do basic inference of function attributes from known properties of system
790 // libraries and other oracles.
791 MPM.addPass(InferFunctionAttrsPass());
792
793 if (Level > 1) {
794 // Indirect call promotion. This should promote all the targets that are
795 // left by the earlier promotion pass that promotes intra-module targets.
796 // This two-step promotion is to save the compile time. For LTO, it should
797 // produce the same result as if we only do promotion here.
Dehao Chencc75d242017-02-23 22:15:18 +0000798 MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
799 PGOOpt && PGOOpt->SamplePGO));
Davide Italiano089a9122017-01-24 00:57:39 +0000800
801 // Propagate constants at call sites into the functions they call. This
802 // opens opportunities for globalopt (and inlining) by substituting function
803 // pointers passed as arguments to direct uses of functions.
804 MPM.addPass(IPSCCPPass());
805 }
806
807 // Now deduce any function attributes based in the current code.
808 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
809 PostOrderFunctionAttrsPass()));
810
811 // Do RPO function attribute inference across the module to forward-propagate
812 // attributes where applicable.
813 // FIXME: Is this really an optimization rather than a canonicalization?
814 MPM.addPass(ReversePostOrderFunctionAttrsPass());
815
816 // Use inragne annotations on GEP indices to split globals where beneficial.
817 MPM.addPass(GlobalSplitPass());
818
819 // Run whole program optimization of virtual call when the list of callees
820 // is fixed.
821 MPM.addPass(WholeProgramDevirtPass());
822
823 // Stop here at -O1.
824 if (Level == 1)
825 return MPM;
826
827 // Optimize globals to try and fold them into constants.
828 MPM.addPass(GlobalOptPass());
829
830 // Promote any localized globals to SSA registers.
831 MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
832
833 // Linking modules together can lead to duplicate global constant, only
834 // keep one copy of each constant.
835 MPM.addPass(ConstantMergePass());
836
837 // Remove unused arguments from functions.
838 MPM.addPass(DeadArgumentEliminationPass());
839
840 // Reduce the code after globalopt and ipsccp. Both can open up significant
841 // simplification opportunities, and both can propagate functions through
842 // function pointers. When this happens, we often have to resolve varargs
843 // calls, etc, so let instcombine do this.
844 // FIXME: add peephole extensions here as the legacy PM does.
845 MPM.addPass(createModuleToFunctionPassAdaptor(InstCombinePass()));
846
847 // Note: historically, the PruneEH pass was run first to deduce nounwind and
848 // generally clean up exception handling overhead. It isn't clear this is
849 // valuable as the inliner doesn't currently care whether it is inlining an
850 // invoke or a call.
851 // Run the inliner now.
852 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(InlinerPass()));
853
854 // Optimize globals again after we ran the inliner.
855 MPM.addPass(GlobalOptPass());
856
857 // Garbage collect dead functions.
858 // FIXME: Add ArgumentPromotion pass after once it's ported.
859 MPM.addPass(GlobalDCEPass());
860
861 FunctionPassManager FPM(DebugLogging);
862
863 // The IPO Passes may leave cruft around. Clean up after them.
864 // FIXME: add peephole extensions here as the legacy PM does.
865 FPM.addPass(InstCombinePass());
866 FPM.addPass(JumpThreadingPass());
867
868 // Break up allocas
869 FPM.addPass(SROA());
870
871 // Run a few AA driver optimizations here and now to cleanup the code.
872 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
873
874 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
875 PostOrderFunctionAttrsPass()));
876 // FIXME: here we run IP alias analysis in the legacy PM.
877
878 FunctionPassManager MainFPM;
879
880 // FIXME: once we fix LoopPass Manager, add LICM here.
881 // FIXME: once we provide support for enabling MLSM, add it here.
882 // FIXME: once we provide support for enabling NewGVN, add it here.
Davide Italiano8a09b8e2017-05-22 23:41:40 +0000883 if (RunNewGVN)
884 MainFPM.addPass(NewGVNPass());
885 else
886 MainFPM.addPass(GVN());
Davide Italiano089a9122017-01-24 00:57:39 +0000887
888 // Remove dead memcpy()'s.
889 MainFPM.addPass(MemCpyOptPass());
890
891 // Nuke dead stores.
892 MainFPM.addPass(DSEPass());
893
894 // FIXME: at this point, we run a bunch of loop passes:
895 // indVarSimplify, loopDeletion, loopInterchange, loopUnrool,
896 // loopVectorize. Enable them once the remaining issue with LPM
897 // are sorted out.
898
899 MainFPM.addPass(InstCombinePass());
900 MainFPM.addPass(SimplifyCFGPass());
901 MainFPM.addPass(SCCPPass());
902 MainFPM.addPass(InstCombinePass());
903 MainFPM.addPass(BDCEPass());
904
905 // FIXME: We may want to run SLPVectorizer here.
906 // After vectorization, assume intrinsics may tell us more
907 // about pointer alignments.
908#if 0
909 MainFPM.add(AlignmentFromAssumptionsPass());
910#endif
911
912 // FIXME: Conditionally run LoadCombine here, after it's ported
913 // (in case we still have this pass, given its questionable usefulness).
914
915 // FIXME: add peephole extensions to the PM here.
916 MainFPM.addPass(InstCombinePass());
917 MainFPM.addPass(JumpThreadingPass());
918 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(MainFPM)));
919
920 // Create a function that performs CFI checks for cross-DSO calls with
921 // targets in the current module.
922 MPM.addPass(CrossDSOCFIPass());
923
924 // Lower type metadata and the type.test intrinsic. This pass supports
925 // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs
926 // to be run at link time if CFI is enabled. This pass does nothing if
927 // CFI is disabled.
928 // Enable once we add support for the summary in the new PM.
929#if 0
Peter Collingbourne857aba42017-02-09 21:45:01 +0000930 MPM.addPass(LowerTypeTestsPass(Summary ? PassSummaryAction::Export :
931 PassSummaryAction::None,
Davide Italiano089a9122017-01-24 00:57:39 +0000932 Summary));
933#endif
934
935 // Add late LTO optimization passes.
936 // Delete basic blocks, which optimization passes may have killed.
937 MPM.addPass(createModuleToFunctionPassAdaptor(SimplifyCFGPass()));
938
939 // Drop bodies of available eternally objects to improve GlobalDCE.
940 MPM.addPass(EliminateAvailableExternallyPass());
941
942 // Now that we have optimized the program, discard unreachable functions.
943 MPM.addPass(GlobalDCEPass());
944
945 // FIXME: Enable MergeFuncs, conditionally, after ported, maybe.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000946 return MPM;
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000947}
948
Chandler Carruth060ad612016-12-23 20:38:19 +0000949AAManager PassBuilder::buildDefaultAAPipeline() {
950 AAManager AA;
951
952 // The order in which these are registered determines their priority when
953 // being queried.
954
955 // First we register the basic alias analysis that provides the majority of
956 // per-function local AA logic. This is a stateless, on-demand local set of
957 // AA techniques.
958 AA.registerFunctionAnalysis<BasicAA>();
959
960 // Next we query fast, specialized alias analyses that wrap IR-embedded
961 // information about aliasing.
962 AA.registerFunctionAnalysis<ScopedNoAliasAA>();
963 AA.registerFunctionAnalysis<TypeBasedAA>();
964
965 // Add support for querying global aliasing information when available.
Chandler Carruth534d6442016-12-24 05:11:17 +0000966 // Because the `AAManager` is a function analysis and `GlobalsAA` is a module
967 // analysis, all that the `AAManager` can do is query for any *cached*
Chandler Carruthe87fc8c2017-02-12 05:34:04 +0000968 // results from `GlobalsAA` through a readonly proxy.
Chandler Carruth060ad612016-12-23 20:38:19 +0000969 AA.registerModuleAnalysis<GlobalsAA>();
Chandler Carruth060ad612016-12-23 20:38:19 +0000970
971 return AA;
972}
973
Chandler Carruth241bf242016-08-03 07:44:48 +0000974static Optional<int> parseRepeatPassName(StringRef Name) {
975 if (!Name.consume_front("repeat<") || !Name.consume_back(">"))
976 return None;
977 int Count;
978 if (Name.getAsInteger(0, Count) || Count <= 0)
979 return None;
980 return Count;
981}
982
Chandler Carruth05ca5ac2016-12-28 11:07:33 +0000983static Optional<int> parseDevirtPassName(StringRef Name) {
984 if (!Name.consume_front("devirt<") || !Name.consume_back(">"))
985 return None;
986 int Count;
987 if (Name.getAsInteger(0, Count) || Count <= 0)
988 return None;
989 return Count;
990}
991
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000992/// Tests whether a pass name starts with a valid prefix for a default pipeline
993/// alias.
994static bool startsWithDefaultPipelineAliasPrefix(StringRef Name) {
995 return Name.startswith("default") || Name.startswith("thinlto") ||
996 Name.startswith("lto");
997}
998
Chandler Carruth66445382014-01-11 08:16:35 +0000999static bool isModulePassName(StringRef Name) {
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001000 // Manually handle aliases for pre-configured pipeline fragments.
Chandler Carruth8b3be4e2017-06-01 11:39:39 +00001001 if (startsWithDefaultPipelineAliasPrefix(Name))
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001002 return DefaultAliasRegex.match(Name);
1003
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001004 // Explicitly handle pass manager names.
1005 if (Name == "module")
1006 return true;
1007 if (Name == "cgscc")
1008 return true;
1009 if (Name == "function")
1010 return true;
1011
Chandler Carruth241bf242016-08-03 07:44:48 +00001012 // Explicitly handle custom-parsed pass names.
1013 if (parseRepeatPassName(Name))
1014 return true;
1015
Chandler Carruth74a8a222016-06-17 07:15:29 +00001016#define MODULE_PASS(NAME, CREATE_PASS) \
1017 if (Name == NAME) \
1018 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +00001019#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001020 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +00001021 return true;
1022#include "PassRegistry.def"
1023
Chandler Carruth66445382014-01-11 08:16:35 +00001024 return false;
1025}
1026
Chandler Carruth572e3402014-04-21 11:12:00 +00001027static bool isCGSCCPassName(StringRef Name) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001028 // Explicitly handle pass manager names.
1029 if (Name == "cgscc")
1030 return true;
1031 if (Name == "function")
1032 return true;
1033
Chandler Carruth241bf242016-08-03 07:44:48 +00001034 // Explicitly handle custom-parsed pass names.
1035 if (parseRepeatPassName(Name))
1036 return true;
Chandler Carruth05ca5ac2016-12-28 11:07:33 +00001037 if (parseDevirtPassName(Name))
1038 return true;
Chandler Carruth241bf242016-08-03 07:44:48 +00001039
Chandler Carruth74a8a222016-06-17 07:15:29 +00001040#define CGSCC_PASS(NAME, CREATE_PASS) \
1041 if (Name == NAME) \
1042 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +00001043#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001044 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +00001045 return true;
1046#include "PassRegistry.def"
1047
Chandler Carruth572e3402014-04-21 11:12:00 +00001048 return false;
1049}
1050
Chandler Carruthd8330982014-01-12 09:34:22 +00001051static bool isFunctionPassName(StringRef Name) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001052 // Explicitly handle pass manager names.
1053 if (Name == "function")
1054 return true;
1055 if (Name == "loop")
1056 return true;
1057
Chandler Carruth241bf242016-08-03 07:44:48 +00001058 // Explicitly handle custom-parsed pass names.
1059 if (parseRepeatPassName(Name))
1060 return true;
1061
Chandler Carruth74a8a222016-06-17 07:15:29 +00001062#define FUNCTION_PASS(NAME, CREATE_PASS) \
1063 if (Name == NAME) \
1064 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +00001065#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001066 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +00001067 return true;
1068#include "PassRegistry.def"
1069
Chandler Carruthd8330982014-01-12 09:34:22 +00001070 return false;
1071}
1072
Justin Bognereecc3c82016-02-25 07:23:08 +00001073static bool isLoopPassName(StringRef Name) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001074 // Explicitly handle pass manager names.
1075 if (Name == "loop")
1076 return true;
1077
Chandler Carruth241bf242016-08-03 07:44:48 +00001078 // Explicitly handle custom-parsed pass names.
1079 if (parseRepeatPassName(Name))
1080 return true;
1081
Chandler Carruth74a8a222016-06-17 07:15:29 +00001082#define LOOP_PASS(NAME, CREATE_PASS) \
1083 if (Name == NAME) \
1084 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +00001085#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1086 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1087 return true;
1088#include "PassRegistry.def"
1089
1090 return false;
1091}
1092
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001093Optional<std::vector<PassBuilder::PipelineElement>>
1094PassBuilder::parsePipelineText(StringRef Text) {
1095 std::vector<PipelineElement> ResultPipeline;
1096
1097 SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
1098 &ResultPipeline};
1099 for (;;) {
1100 std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
1101 size_t Pos = Text.find_first_of(",()");
1102 Pipeline.push_back({Text.substr(0, Pos), {}});
1103
1104 // If we have a single terminating name, we're done.
1105 if (Pos == Text.npos)
1106 break;
1107
1108 char Sep = Text[Pos];
1109 Text = Text.substr(Pos + 1);
1110 if (Sep == ',')
1111 // Just a name ending in a comma, continue.
1112 continue;
1113
1114 if (Sep == '(') {
1115 // Push the inner pipeline onto the stack to continue processing.
1116 PipelineStack.push_back(&Pipeline.back().InnerPipeline);
1117 continue;
1118 }
1119
1120 assert(Sep == ')' && "Bogus separator!");
1121 // When handling the close parenthesis, we greedily consume them to avoid
1122 // empty strings in the pipeline.
1123 do {
1124 // If we try to pop the outer pipeline we have unbalanced parentheses.
1125 if (PipelineStack.size() == 1)
1126 return None;
1127
1128 PipelineStack.pop_back();
1129 } while (Text.consume_front(")"));
1130
1131 // Check if we've finished parsing.
1132 if (Text.empty())
1133 break;
1134
1135 // Otherwise, the end of an inner pipeline always has to be followed by
1136 // a comma, and then we can continue.
1137 if (!Text.consume_front(","))
1138 return None;
1139 }
1140
1141 if (PipelineStack.size() > 1)
1142 // Unbalanced paretheses.
1143 return None;
1144
1145 assert(PipelineStack.back() == &ResultPipeline &&
1146 "Wrong pipeline at the bottom of the stack!");
1147 return {std::move(ResultPipeline)};
1148}
1149
1150bool PassBuilder::parseModulePass(ModulePassManager &MPM,
1151 const PipelineElement &E, bool VerifyEachPass,
1152 bool DebugLogging) {
1153 auto &Name = E.Name;
1154 auto &InnerPipeline = E.InnerPipeline;
1155
1156 // First handle complex passes like the pass managers which carry pipelines.
1157 if (!InnerPipeline.empty()) {
1158 if (Name == "module") {
1159 ModulePassManager NestedMPM(DebugLogging);
1160 if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
1161 DebugLogging))
1162 return false;
1163 MPM.addPass(std::move(NestedMPM));
1164 return true;
1165 }
1166 if (Name == "cgscc") {
1167 CGSCCPassManager CGPM(DebugLogging);
1168 if (!parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass,
1169 DebugLogging))
1170 return false;
1171 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM),
1172 DebugLogging));
1173 return true;
1174 }
1175 if (Name == "function") {
1176 FunctionPassManager FPM(DebugLogging);
1177 if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
1178 DebugLogging))
1179 return false;
1180 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1181 return true;
1182 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001183 if (auto Count = parseRepeatPassName(Name)) {
1184 ModulePassManager NestedMPM(DebugLogging);
1185 if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
1186 DebugLogging))
1187 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001188 MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001189 return true;
1190 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001191 // Normal passes can't have pipelines.
1192 return false;
1193 }
1194
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001195 // Manually handle aliases for pre-configured pipeline fragments.
Chandler Carruth8b3be4e2017-06-01 11:39:39 +00001196 if (startsWithDefaultPipelineAliasPrefix(Name)) {
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001197 SmallVector<StringRef, 3> Matches;
1198 if (!DefaultAliasRegex.match(Name, &Matches))
1199 return false;
1200 assert(Matches.size() == 3 && "Must capture two matched strings!");
1201
Jordan Rosef85a95f2016-07-25 18:34:51 +00001202 OptimizationLevel L = StringSwitch<OptimizationLevel>(Matches[2])
1203 .Case("O0", O0)
1204 .Case("O1", O1)
1205 .Case("O2", O2)
1206 .Case("O3", O3)
1207 .Case("Os", Os)
1208 .Case("Oz", Oz);
Chandler Carruthe3f50642016-12-22 06:59:15 +00001209 if (L == O0)
1210 // At O0 we do nothing at all!
1211 return true;
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001212
1213 if (Matches[1] == "default") {
Chandler Carruthe3f50642016-12-22 06:59:15 +00001214 MPM.addPass(buildPerModuleDefaultPipeline(L, DebugLogging));
Chandler Carruth8b3be4e2017-06-01 11:39:39 +00001215 } else if (Matches[1] == "thinlto-pre-link") {
1216 MPM.addPass(buildThinLTOPreLinkDefaultPipeline(L, DebugLogging));
1217 } else if (Matches[1] == "thinlto") {
1218 MPM.addPass(buildThinLTODefaultPipeline(L, DebugLogging));
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001219 } else if (Matches[1] == "lto-pre-link") {
Chandler Carruthe3f50642016-12-22 06:59:15 +00001220 MPM.addPass(buildLTOPreLinkDefaultPipeline(L, DebugLogging));
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001221 } else {
1222 assert(Matches[1] == "lto" && "Not one of the matched options!");
Chandler Carruthe3f50642016-12-22 06:59:15 +00001223 MPM.addPass(buildLTODefaultPipeline(L, DebugLogging));
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001224 }
1225 return true;
1226 }
1227
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001228 // Finally expand the basic registered passes from the .inc file.
Chandler Carruth58944182014-04-21 08:08:50 +00001229#define MODULE_PASS(NAME, CREATE_PASS) \
1230 if (Name == NAME) { \
1231 MPM.addPass(CREATE_PASS); \
1232 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +00001233 }
Chandler Carruth628503e2015-01-06 02:10:51 +00001234#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1235 if (Name == "require<" NAME ">") { \
Chandler Carruth9b35e6d2016-08-19 18:36:06 +00001236 MPM.addPass( \
1237 RequireAnalysisPass< \
1238 std::remove_reference<decltype(CREATE_PASS)>::type, Module>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +00001239 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001240 } \
1241 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001242 MPM.addPass(InvalidateAnalysisPass< \
1243 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001244 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +00001245 }
1246#include "PassRegistry.def"
1247
Chandler Carruth66445382014-01-11 08:16:35 +00001248 return false;
1249}
1250
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001251bool PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
1252 const PipelineElement &E, bool VerifyEachPass,
1253 bool DebugLogging) {
1254 auto &Name = E.Name;
1255 auto &InnerPipeline = E.InnerPipeline;
1256
1257 // First handle complex passes like the pass managers which carry pipelines.
1258 if (!InnerPipeline.empty()) {
1259 if (Name == "cgscc") {
1260 CGSCCPassManager NestedCGPM(DebugLogging);
1261 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1262 DebugLogging))
1263 return false;
1264 // Add the nested pass manager with the appropriate adaptor.
1265 CGPM.addPass(std::move(NestedCGPM));
1266 return true;
1267 }
1268 if (Name == "function") {
1269 FunctionPassManager FPM(DebugLogging);
1270 if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
1271 DebugLogging))
1272 return false;
1273 // Add the nested pass manager with the appropriate adaptor.
1274 CGPM.addPass(
1275 createCGSCCToFunctionPassAdaptor(std::move(FPM), DebugLogging));
1276 return true;
1277 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001278 if (auto Count = parseRepeatPassName(Name)) {
1279 CGSCCPassManager NestedCGPM(DebugLogging);
1280 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1281 DebugLogging))
1282 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001283 CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001284 return true;
1285 }
Chandler Carruth05ca5ac2016-12-28 11:07:33 +00001286 if (auto MaxRepetitions = parseDevirtPassName(Name)) {
1287 CGSCCPassManager NestedCGPM(DebugLogging);
1288 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1289 DebugLogging))
1290 return false;
1291 CGPM.addPass(createDevirtSCCRepeatedPass(std::move(NestedCGPM),
1292 *MaxRepetitions, DebugLogging));
1293 return true;
1294 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001295 // Normal passes can't have pipelines.
1296 return false;
1297 }
1298
1299 // Now expand the basic registered passes from the .inc file.
Chandler Carruth572e3402014-04-21 11:12:00 +00001300#define CGSCC_PASS(NAME, CREATE_PASS) \
1301 if (Name == NAME) { \
1302 CGPM.addPass(CREATE_PASS); \
1303 return true; \
1304 }
Chandler Carruth628503e2015-01-06 02:10:51 +00001305#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1306 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001307 CGPM.addPass(RequireAnalysisPass< \
Chandler Carruth9b35e6d2016-08-19 18:36:06 +00001308 std::remove_reference<decltype(CREATE_PASS)>::type, \
Chandler Carruth88823462016-08-24 09:37:14 +00001309 LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
1310 CGSCCUpdateResult &>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +00001311 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001312 } \
1313 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001314 CGPM.addPass(InvalidateAnalysisPass< \
1315 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001316 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +00001317 }
1318#include "PassRegistry.def"
1319
Chandler Carruth572e3402014-04-21 11:12:00 +00001320 return false;
1321}
1322
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001323bool PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
1324 const PipelineElement &E,
1325 bool VerifyEachPass, bool DebugLogging) {
1326 auto &Name = E.Name;
1327 auto &InnerPipeline = E.InnerPipeline;
1328
1329 // First handle complex passes like the pass managers which carry pipelines.
1330 if (!InnerPipeline.empty()) {
1331 if (Name == "function") {
1332 FunctionPassManager NestedFPM(DebugLogging);
1333 if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
1334 DebugLogging))
1335 return false;
1336 // Add the nested pass manager with the appropriate adaptor.
1337 FPM.addPass(std::move(NestedFPM));
1338 return true;
1339 }
1340 if (Name == "loop") {
1341 LoopPassManager LPM(DebugLogging);
1342 if (!parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass,
1343 DebugLogging))
1344 return false;
1345 // Add the nested pass manager with the appropriate adaptor.
1346 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM)));
1347 return true;
1348 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001349 if (auto Count = parseRepeatPassName(Name)) {
1350 FunctionPassManager NestedFPM(DebugLogging);
1351 if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
1352 DebugLogging))
1353 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001354 FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001355 return true;
1356 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001357 // Normal passes can't have pipelines.
1358 return false;
1359 }
1360
1361 // Now expand the basic registered passes from the .inc file.
Chandler Carruth58944182014-04-21 08:08:50 +00001362#define FUNCTION_PASS(NAME, CREATE_PASS) \
1363 if (Name == NAME) { \
1364 FPM.addPass(CREATE_PASS); \
1365 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +00001366 }
Chandler Carruth628503e2015-01-06 02:10:51 +00001367#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1368 if (Name == "require<" NAME ">") { \
Chandler Carruth9b35e6d2016-08-19 18:36:06 +00001369 FPM.addPass( \
1370 RequireAnalysisPass< \
1371 std::remove_reference<decltype(CREATE_PASS)>::type, Function>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +00001372 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001373 } \
1374 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001375 FPM.addPass(InvalidateAnalysisPass< \
1376 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001377 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +00001378 }
1379#include "PassRegistry.def"
1380
Chandler Carruthd8330982014-01-12 09:34:22 +00001381 return false;
1382}
1383
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001384bool PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001385 bool VerifyEachPass, bool DebugLogging) {
Chandler Carruth241bf242016-08-03 07:44:48 +00001386 StringRef Name = E.Name;
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001387 auto &InnerPipeline = E.InnerPipeline;
1388
1389 // First handle complex passes like the pass managers which carry pipelines.
1390 if (!InnerPipeline.empty()) {
1391 if (Name == "loop") {
1392 LoopPassManager NestedLPM(DebugLogging);
1393 if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
1394 DebugLogging))
1395 return false;
1396 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001397 LPM.addPass(std::move(NestedLPM));
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001398 return true;
1399 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001400 if (auto Count = parseRepeatPassName(Name)) {
1401 LoopPassManager NestedLPM(DebugLogging);
1402 if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
1403 DebugLogging))
1404 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001405 LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001406 return true;
1407 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001408 // Normal passes can't have pipelines.
1409 return false;
1410 }
1411
1412 // Now expand the basic registered passes from the .inc file.
Justin Bognereecc3c82016-02-25 07:23:08 +00001413#define LOOP_PASS(NAME, CREATE_PASS) \
1414 if (Name == NAME) { \
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001415 LPM.addPass(CREATE_PASS); \
Justin Bognereecc3c82016-02-25 07:23:08 +00001416 return true; \
1417 }
1418#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1419 if (Name == "require<" NAME ">") { \
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001420 LPM.addPass(RequireAnalysisPass< \
Chandler Carruth410eaeb2017-01-11 06:23:21 +00001421 std::remove_reference<decltype(CREATE_PASS)>::type, Loop, \
1422 LoopAnalysisManager, LoopStandardAnalysisResults &, \
1423 LPMUpdater &>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +00001424 return true; \
1425 } \
1426 if (Name == "invalidate<" NAME ">") { \
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001427 LPM.addPass(InvalidateAnalysisPass< \
Chandler Carruth470734b2016-02-26 12:30:18 +00001428 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +00001429 return true; \
1430 }
1431#include "PassRegistry.def"
1432
1433 return false;
1434}
1435
Chandler Carruthedf59962016-02-18 09:45:17 +00001436bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
Chandler Carruth45a9c202016-03-11 09:15:11 +00001437#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1438 if (Name == NAME) { \
1439 AA.registerModuleAnalysis< \
1440 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
1441 return true; \
1442 }
Chandler Carruthedf59962016-02-18 09:45:17 +00001443#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1444 if (Name == NAME) { \
Chandler Carruth58dde8c2016-02-26 12:17:54 +00001445 AA.registerFunctionAnalysis< \
1446 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
Chandler Carruthedf59962016-02-18 09:45:17 +00001447 return true; \
1448 }
1449#include "PassRegistry.def"
1450
1451 return false;
1452}
1453
Justin Bognereecc3c82016-02-25 07:23:08 +00001454bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001455 ArrayRef<PipelineElement> Pipeline,
Justin Bognereecc3c82016-02-25 07:23:08 +00001456 bool VerifyEachPass,
1457 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001458 for (const auto &Element : Pipeline) {
1459 if (!parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging))
1460 return false;
1461 // FIXME: No verifier support for Loop passes!
Justin Bognereecc3c82016-02-25 07:23:08 +00001462 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001463 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +00001464}
1465
Chandler Carruth1ff77242015-03-07 09:02:36 +00001466bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001467 ArrayRef<PipelineElement> Pipeline,
Chandler Carruth1ff77242015-03-07 09:02:36 +00001468 bool VerifyEachPass,
1469 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001470 for (const auto &Element : Pipeline) {
1471 if (!parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging))
1472 return false;
1473 if (VerifyEachPass)
1474 FPM.addPass(VerifierPass());
Chandler Carruthd8330982014-01-12 09:34:22 +00001475 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001476 return true;
Chandler Carruthd8330982014-01-12 09:34:22 +00001477}
1478
Chandler Carruth1ff77242015-03-07 09:02:36 +00001479bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001480 ArrayRef<PipelineElement> Pipeline,
Chandler Carruth1ff77242015-03-07 09:02:36 +00001481 bool VerifyEachPass,
1482 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001483 for (const auto &Element : Pipeline) {
1484 if (!parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging))
1485 return false;
1486 // FIXME: No verifier support for CGSCC passes!
Chandler Carruth572e3402014-04-21 11:12:00 +00001487 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001488 return true;
Chandler Carruth572e3402014-04-21 11:12:00 +00001489}
1490
NAKAMURA Takumia42f5282016-05-16 10:13:37 +00001491void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM,
1492 FunctionAnalysisManager &FAM,
1493 CGSCCAnalysisManager &CGAM,
1494 ModuleAnalysisManager &MAM) {
1495 MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
1496 MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
NAKAMURA Takumia42f5282016-05-16 10:13:37 +00001497 CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
1498 FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
1499 FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
1500 FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
1501 LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
1502}
1503
Chandler Carruth1ff77242015-03-07 09:02:36 +00001504bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001505 ArrayRef<PipelineElement> Pipeline,
Chandler Carruth1ff77242015-03-07 09:02:36 +00001506 bool VerifyEachPass,
1507 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001508 for (const auto &Element : Pipeline) {
1509 if (!parseModulePass(MPM, Element, VerifyEachPass, DebugLogging))
1510 return false;
1511 if (VerifyEachPass)
1512 MPM.addPass(VerifierPass());
Chandler Carruth66445382014-01-11 08:16:35 +00001513 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001514 return true;
Chandler Carruth66445382014-01-11 08:16:35 +00001515}
1516
1517// Primary pass pipeline description parsing routine.
1518// FIXME: Should this routine accept a TargetMachine or require the caller to
1519// pre-populate the analysis managers with target-specific stuff?
Chandler Carruth1ff77242015-03-07 09:02:36 +00001520bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
1521 StringRef PipelineText, bool VerifyEachPass,
1522 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001523 auto Pipeline = parsePipelineText(PipelineText);
1524 if (!Pipeline || Pipeline->empty())
1525 return false;
Chandler Carruth66445382014-01-11 08:16:35 +00001526
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001527 // If the first name isn't at the module layer, wrap the pipeline up
1528 // automatically.
1529 StringRef FirstName = Pipeline->front().Name;
Chandler Carruth66445382014-01-11 08:16:35 +00001530
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001531 if (!isModulePassName(FirstName)) {
1532 if (isCGSCCPassName(FirstName))
1533 Pipeline = {{"cgscc", std::move(*Pipeline)}};
1534 else if (isFunctionPassName(FirstName))
1535 Pipeline = {{"function", std::move(*Pipeline)}};
1536 else if (isLoopPassName(FirstName))
1537 Pipeline = {{"function", {{"loop", std::move(*Pipeline)}}}};
1538 else
1539 // Unknown pass name!
Chandler Carruth572e3402014-04-21 11:12:00 +00001540 return false;
Chandler Carruth572e3402014-04-21 11:12:00 +00001541 }
1542
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001543 return parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging);
Chandler Carruth66445382014-01-11 08:16:35 +00001544}
Chandler Carruthedf59962016-02-18 09:45:17 +00001545
1546bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) {
Chandler Carruth060ad612016-12-23 20:38:19 +00001547 // If the pipeline just consists of the word 'default' just replace the AA
1548 // manager with our default one.
1549 if (PipelineText == "default") {
1550 AA = buildDefaultAAPipeline();
1551 return true;
1552 }
1553
Chandler Carruthedf59962016-02-18 09:45:17 +00001554 while (!PipelineText.empty()) {
1555 StringRef Name;
1556 std::tie(Name, PipelineText) = PipelineText.split(',');
1557 if (!parseAAPassName(AA, Name))
1558 return false;
1559 }
1560
1561 return true;
1562}