blob: 1f638e7683078cc53726b8db60cf80726cca71cb [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
Davide Italianobe1b6a92017-06-03 23:18:29 +0000167static cl::opt<bool> EnableGVNSink(
168 "enable-npm-gvn-sink", cl::init(false), cl::Hidden,
169 cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"));
170
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000171static Regex DefaultAliasRegex(
172 "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$");
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000173
Chandler Carruthe3f50642016-12-22 06:59:15 +0000174static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) {
175 switch (Level) {
176 case PassBuilder::O0:
177 case PassBuilder::O1:
178 case PassBuilder::O2:
179 case PassBuilder::O3:
180 return false;
181
182 case PassBuilder::Os:
183 case PassBuilder::Oz:
184 return true;
185 }
186 llvm_unreachable("Invalid optimization level!");
187}
188
Chandler Carruth66445382014-01-11 08:16:35 +0000189namespace {
190
Chandler Carruthd8330982014-01-12 09:34:22 +0000191/// \brief No-op module pass which does nothing.
Chandler Carruth66445382014-01-11 08:16:35 +0000192struct NoOpModulePass {
Sean Silvafd03ac62016-08-09 00:28:38 +0000193 PreservedAnalyses run(Module &M, ModuleAnalysisManager &) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000194 return PreservedAnalyses::all();
195 }
Chandler Carrutha13f27c2014-01-11 11:52:05 +0000196 static StringRef name() { return "NoOpModulePass"; }
Chandler Carruth66445382014-01-11 08:16:35 +0000197};
198
Chandler Carruth0b576b32015-01-06 02:50:06 +0000199/// \brief No-op module analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000200class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
201 friend AnalysisInfoMixin<NoOpModuleAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000202 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000203
204public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000205 struct Result {};
Sean Silvafd03ac62016-08-09 00:28:38 +0000206 Result run(Module &, ModuleAnalysisManager &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000207 static StringRef name() { return "NoOpModuleAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000208};
209
Chandler Carruth572e3402014-04-21 11:12:00 +0000210/// \brief No-op CGSCC pass which does nothing.
211struct NoOpCGSCCPass {
Chandler Carruth88823462016-08-24 09:37:14 +0000212 PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &,
213 LazyCallGraph &, CGSCCUpdateResult &UR) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000214 return PreservedAnalyses::all();
215 }
216 static StringRef name() { return "NoOpCGSCCPass"; }
217};
218
Chandler Carruth0b576b32015-01-06 02:50:06 +0000219/// \brief No-op CGSCC analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000220class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
221 friend AnalysisInfoMixin<NoOpCGSCCAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000222 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000223
224public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000225 struct Result {};
Chandler Carruth88823462016-08-24 09:37:14 +0000226 Result run(LazyCallGraph::SCC &, CGSCCAnalysisManager &, LazyCallGraph &G) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000227 return Result();
228 }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000229 static StringRef name() { return "NoOpCGSCCAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000230};
231
Chandler Carruthd8330982014-01-12 09:34:22 +0000232/// \brief No-op function pass which does nothing.
233struct NoOpFunctionPass {
Sean Silva36e0d012016-08-09 00:28:15 +0000234 PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000235 return PreservedAnalyses::all();
236 }
Chandler Carruthd8330982014-01-12 09:34:22 +0000237 static StringRef name() { return "NoOpFunctionPass"; }
238};
239
Chandler Carruth0b576b32015-01-06 02:50:06 +0000240/// \brief No-op function analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000241class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
242 friend AnalysisInfoMixin<NoOpFunctionAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000243 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000244
245public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000246 struct Result {};
Sean Silva36e0d012016-08-09 00:28:15 +0000247 Result run(Function &, FunctionAnalysisManager &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000248 static StringRef name() { return "NoOpFunctionAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000249};
250
Justin Bognereecc3c82016-02-25 07:23:08 +0000251/// \brief No-op loop pass which does nothing.
252struct NoOpLoopPass {
Chandler Carruth410eaeb2017-01-11 06:23:21 +0000253 PreservedAnalyses run(Loop &L, LoopAnalysisManager &,
254 LoopStandardAnalysisResults &, LPMUpdater &) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000255 return PreservedAnalyses::all();
256 }
Justin Bognereecc3c82016-02-25 07:23:08 +0000257 static StringRef name() { return "NoOpLoopPass"; }
258};
259
260/// \brief No-op loop analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000261class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
262 friend AnalysisInfoMixin<NoOpLoopAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000263 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000264
265public:
Justin Bognereecc3c82016-02-25 07:23:08 +0000266 struct Result {};
Chandler Carruth410eaeb2017-01-11 06:23:21 +0000267 Result run(Loop &, LoopAnalysisManager &, LoopStandardAnalysisResults &) {
268 return Result();
269 }
Justin Bognereecc3c82016-02-25 07:23:08 +0000270 static StringRef name() { return "NoOpLoopAnalysis"; }
Justin Bognereecc3c82016-02-25 07:23:08 +0000271};
272
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000273AnalysisKey NoOpModuleAnalysis::Key;
274AnalysisKey NoOpCGSCCAnalysis::Key;
275AnalysisKey NoOpFunctionAnalysis::Key;
276AnalysisKey NoOpLoopAnalysis::Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000277
Chandler Carruth66445382014-01-11 08:16:35 +0000278} // End anonymous namespace.
279
Chandler Carruth1ff77242015-03-07 09:02:36 +0000280void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000281#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000282 MAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000283#include "PassRegistry.def"
284}
285
Chandler Carruth1ff77242015-03-07 09:02:36 +0000286void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000287#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000288 CGAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000289#include "PassRegistry.def"
290}
291
Chandler Carruth1ff77242015-03-07 09:02:36 +0000292void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000293#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000294 FAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000295#include "PassRegistry.def"
296}
297
Justin Bognereecc3c82016-02-25 07:23:08 +0000298void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000299#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
Justin Bognereecc3c82016-02-25 07:23:08 +0000300 LAM.registerPass([&] { return CREATE_PASS; });
301#include "PassRegistry.def"
302}
303
Chandler Carruthe3f50642016-12-22 06:59:15 +0000304FunctionPassManager
305PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
306 bool DebugLogging) {
307 assert(Level != O0 && "Must request optimizations!");
308 FunctionPassManager FPM(DebugLogging);
309
310 // Form SSA out of local memory accesses after breaking apart aggregates into
311 // scalars.
312 FPM.addPass(SROA());
313
314 // Catch trivial redundancies
315 FPM.addPass(EarlyCSEPass());
316
Davide Italianoc3688312017-06-01 23:08:14 +0000317 // Hoisting of scalars and load expressions.
318 if (EnableGVNHoist)
319 FPM.addPass(GVNHoistPass());
320
Davide Italianobe1b6a92017-06-03 23:18:29 +0000321 // Global value numbering based sinking.
322 if (EnableGVNSink) {
323 FPM.addPass(GVNSinkPass());
324 FPM.addPass(SimplifyCFGPass());
325 }
326
Chandler Carruthe3f50642016-12-22 06:59:15 +0000327 // Speculative execution if the target has divergent branches; otherwise nop.
328 FPM.addPass(SpeculativeExecutionPass());
329
330 // Optimize based on known information about branches, and cleanup afterward.
331 FPM.addPass(JumpThreadingPass());
332 FPM.addPass(CorrelatedValuePropagationPass());
333 FPM.addPass(SimplifyCFGPass());
334 FPM.addPass(InstCombinePass());
335
336 if (!isOptimizingForSize(Level))
337 FPM.addPass(LibCallsShrinkWrapPass());
338
339 FPM.addPass(TailCallElimPass());
340 FPM.addPass(SimplifyCFGPass());
341
342 // Form canonically associated expression trees, and simplify the trees using
343 // basic mathematical properties. For example, this will form (nearly)
344 // minimal multiplication trees.
345 FPM.addPass(ReassociatePass());
346
347 // Add the primary loop simplification pipeline.
348 // FIXME: Currently this is split into two loop pass pipelines because we run
349 // some function passes in between them. These can and should be replaced by
350 // loop pass equivalenst but those aren't ready yet. Specifically,
351 // `SimplifyCFGPass` and `InstCombinePass` are used. We have
352 // `LoopSimplifyCFGPass` which isn't yet powerful enough, and the closest to
353 // the other we have is `LoopInstSimplify`.
354 LoopPassManager LPM1(DebugLogging), LPM2(DebugLogging);
355
356 // Rotate Loop - disable header duplication at -Oz
357 LPM1.addPass(LoopRotatePass(Level != Oz));
358 LPM1.addPass(LICMPass());
Chandler Carruth86248d52017-05-26 01:24:11 +0000359 LPM1.addPass(SimpleLoopUnswitchPass());
Chandler Carruth79b733b2017-01-26 23:21:17 +0000360 LPM2.addPass(IndVarSimplifyPass());
361 LPM2.addPass(LoopIdiomRecognizePass());
362 LPM2.addPass(LoopDeletionPass());
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000363 // FIXME: The old pass manager has a hack to disable loop unrolling during
364 // ThinLTO when using sample PGO. Need to either fix it or port some
365 // workaround.
Dehao Chen7d230322017-02-18 03:46:51 +0000366 LPM2.addPass(LoopUnrollPass::createFull(Level));
Chandler Carruth79b733b2017-01-26 23:21:17 +0000367
Chandler Carruth0ede22e2017-02-09 23:54:57 +0000368 // We provide the opt remark emitter pass for LICM to use. We only need to do
369 // this once as it is immutable.
370 FPM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000371 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM1)));
372 FPM.addPass(SimplifyCFGPass());
373 FPM.addPass(InstCombinePass());
374 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2)));
375
376 // Eliminate redundancies.
377 if (Level != O1) {
378 // These passes add substantial compile time so skip them at O1.
379 FPM.addPass(MergedLoadStoreMotionPass());
Davide Italiano8a09b8e2017-05-22 23:41:40 +0000380 if (RunNewGVN)
381 FPM.addPass(NewGVNPass());
382 else
383 FPM.addPass(GVN());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000384 }
385
386 // Specially optimize memory movement as it doesn't look like dataflow in SSA.
387 FPM.addPass(MemCpyOptPass());
388
389 // Sparse conditional constant propagation.
390 // FIXME: It isn't clear why we do this *after* loop passes rather than
391 // before...
392 FPM.addPass(SCCPPass());
393
394 // Delete dead bit computations (instcombine runs after to fold away the dead
395 // computations, and then ADCE will run later to exploit any new DCE
396 // opportunities that creates).
397 FPM.addPass(BDCEPass());
398
399 // Run instcombine after redundancy and dead bit elimination to exploit
400 // opportunities opened up by them.
401 FPM.addPass(InstCombinePass());
402
403 // Re-consider control flow based optimizations after redundancy elimination,
404 // redo DCE, etc.
405 FPM.addPass(JumpThreadingPass());
406 FPM.addPass(CorrelatedValuePropagationPass());
407 FPM.addPass(DSEPass());
408 FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass()));
409
410 // Finally, do an expensive DCE pass to catch all the dead code exposed by
411 // the simplifications and basic cleanup after all the simplifications.
412 FPM.addPass(ADCEPass());
413 FPM.addPass(SimplifyCFGPass());
414 FPM.addPass(InstCombinePass());
415
416 return FPM;
417}
418
Davide Italiano513dfaa2017-02-13 15:26:22 +0000419static void addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
420 PassBuilder::OptimizationLevel Level,
421 bool RunProfileGen, std::string ProfileGenFile,
422 std::string ProfileUseFile) {
423 // Generally running simplification passes and the inliner with an high
424 // threshold results in smaller executables, but there may be cases where
425 // the size grows, so let's be conservative here and skip this simplification
426 // at -Os/Oz.
427 if (!isOptimizingForSize(Level)) {
428 InlineParams IP;
429
430 // In the old pass manager, this is a cl::opt. Should still this be one?
431 IP.DefaultThreshold = 75;
432
433 // FIXME: The hint threshold has the same value used by the regular inliner.
434 // This should probably be lowered after performance testing.
435 // FIXME: this comment is cargo culted from the old pass manager, revisit).
436 IP.HintThreshold = 325;
437
438 CGSCCPassManager CGPipeline(DebugLogging);
439
440 CGPipeline.addPass(InlinerPass(IP));
441
442 FunctionPassManager FPM;
443 FPM.addPass(SROA());
444 FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies.
445 FPM.addPass(SimplifyCFGPass()); // Merge & remove basic blocks.
446 FPM.addPass(InstCombinePass()); // Combine silly sequences.
447
448 // FIXME: Here the old pass manager inserts peephole extensions.
449 // Add them when they're supported.
450 CGPipeline.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
451
452 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPipeline)));
453 }
454
Chandler Carruthf4d62c42017-05-25 07:15:09 +0000455 // Delete anything that is now dead to make sure that we don't instrument
456 // dead code. Instrumentation can end up keeping dead code around and
457 // dramatically increase code size.
458 MPM.addPass(GlobalDCEPass());
459
Davide Italiano513dfaa2017-02-13 15:26:22 +0000460 if (RunProfileGen) {
461 MPM.addPass(PGOInstrumentationGen());
462
463 // Add the profile lowering pass.
464 InstrProfOptions Options;
465 if (!ProfileGenFile.empty())
466 Options.InstrProfileOutput = ProfileGenFile;
467 MPM.addPass(InstrProfiling(Options));
468 }
469
470 if (!ProfileUseFile.empty())
471 MPM.addPass(PGOInstrumentationUse(ProfileUseFile));
472}
473
Chandler Carruthe3f50642016-12-22 06:59:15 +0000474ModulePassManager
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000475PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
476 bool DebugLogging) {
Chandler Carruthe3f50642016-12-22 06:59:15 +0000477 ModulePassManager MPM(DebugLogging);
478
Chandler Carruthe3f50642016-12-22 06:59:15 +0000479 // Do basic inference of function attributes from known properties of system
480 // libraries and other oracles.
481 MPM.addPass(InferFunctionAttrsPass());
482
483 // Create an early function pass manager to cleanup the output of the
484 // frontend.
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000485 FunctionPassManager EarlyFPM(DebugLogging);
486 EarlyFPM.addPass(SimplifyCFGPass());
487 EarlyFPM.addPass(SROA());
488 EarlyFPM.addPass(EarlyCSEPass());
489 EarlyFPM.addPass(LowerExpectIntrinsicPass());
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000490 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000491
492 // Interprocedural constant propagation now that basic cleanup has occured
493 // and prior to optimizing globals.
494 // FIXME: This position in the pipeline hasn't been carefully considered in
495 // years, it should be re-analyzed.
496 MPM.addPass(IPSCCPPass());
497
498 // Optimize globals to try and fold them into constants.
499 MPM.addPass(GlobalOptPass());
500
501 // Promote any localized globals to SSA registers.
502 // FIXME: Should this instead by a run of SROA?
503 // FIXME: We should probably run instcombine and simplify-cfg afterward to
504 // delete control flows that are dead once globals have been folded to
505 // constants.
506 MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
507
508 // Remove any dead arguments exposed by cleanups and constand folding
509 // globals.
510 MPM.addPass(DeadArgumentEliminationPass());
511
512 // Create a small function pass pipeline to cleanup after all the global
513 // optimizations.
514 FunctionPassManager GlobalCleanupPM(DebugLogging);
515 GlobalCleanupPM.addPass(InstCombinePass());
516 GlobalCleanupPM.addPass(SimplifyCFGPass());
517 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
518
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000519 // Add all the requested passes for PGO, if requested.
Davide Italiano513dfaa2017-02-13 15:26:22 +0000520 if (PGOOpt) {
Dehao Chencc75d242017-02-23 22:15:18 +0000521 assert(PGOOpt->RunProfileGen || PGOOpt->SamplePGO ||
522 !PGOOpt->ProfileUseFile.empty());
Davide Italiano513dfaa2017-02-13 15:26:22 +0000523 addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
524 PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
Davide Italiano513dfaa2017-02-13 15:26:22 +0000525
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000526 // Indirect call promotion that promotes intra-module targes only.
527 MPM.addPass(PGOIndirectCallPromotion(false, PGOOpt && PGOOpt->SamplePGO));
528 }
Davide Italiano513dfaa2017-02-13 15:26:22 +0000529
Chandler Carruthe87fc8c2017-02-12 05:34:04 +0000530 // Require the GlobalsAA analysis for the module so we can query it within
531 // the CGSCC pipeline.
532 MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000533
Easwaran Raman5e6f9bd2017-05-04 16:58:45 +0000534 // Require the ProfileSummaryAnalysis for the module so we can query it within
535 // the inliner pass.
536 MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
537
Chandler Carruthe3f50642016-12-22 06:59:15 +0000538 // Now begin the main postorder CGSCC pipeline.
539 // FIXME: The current CGSCC pipeline has its origins in the legacy pass
540 // manager and trying to emulate its precise behavior. Much of this doesn't
541 // make a lot of sense and we should revisit the core CGSCC structure.
542 CGSCCPassManager MainCGPipeline(DebugLogging);
543
544 // Note: historically, the PruneEH pass was run first to deduce nounwind and
545 // generally clean up exception handling overhead. It isn't clear this is
546 // valuable as the inliner doesn't currently care whether it is inlining an
547 // invoke or a call.
548
549 // Run the inliner first. The theory is that we are walking bottom-up and so
550 // the callees have already been fully optimized, and we want to inline them
551 // into the callers so that our optimizations can reflect that.
552 // FIXME; Customize the threshold based on optimization level.
553 MainCGPipeline.addPass(InlinerPass());
554
555 // Now deduce any function attributes based in the current code.
556 MainCGPipeline.addPass(PostOrderFunctionAttrsPass());
557
Chandler Carruth0ede22e2017-02-09 23:54:57 +0000558 // When at O3 add argument promotion to the pass pipeline.
559 // FIXME: It isn't at all clear why this should be limited to O3.
560 if (Level == O3)
561 MainCGPipeline.addPass(ArgumentPromotionPass());
562
Chandler Carruthe3f50642016-12-22 06:59:15 +0000563 // Lastly, add the core function simplification pipeline nested inside the
564 // CGSCC walk.
565 MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
566 buildFunctionSimplificationPipeline(Level, DebugLogging)));
567
Chandler Carruth719ffe12017-02-12 05:38:04 +0000568 // We wrap the CGSCC pipeline in a devirtualization repeater. This will try
569 // to detect when we devirtualize indirect calls and iterate the SCC passes
570 // in that case to try and catch knock-on inlining or function attrs
571 // opportunities. Then we add it to the module pipeline by walking the SCCs
572 // in postorder (or bottom-up).
Chandler Carruthe3f50642016-12-22 06:59:15 +0000573 MPM.addPass(
Chandler Carruth719ffe12017-02-12 05:38:04 +0000574 createModuleToPostOrderCGSCCPassAdaptor(createDevirtSCCRepeatedPass(
575 std::move(MainCGPipeline), MaxDevirtIterations, DebugLogging)));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000576
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000577 return MPM;
578}
579
580ModulePassManager
581PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
582 bool DebugLogging) {
583 ModulePassManager MPM(DebugLogging);
584
585 // Optimize globals now that the module is fully simplified.
586 MPM.addPass(GlobalOptPass());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000587
Xinliang David Li126157c2017-05-22 16:41:57 +0000588 // Run partial inlining pass to partially inline functions that have
589 // large bodies.
590 if (RunPartialInlining)
591 MPM.addPass(PartialInlinerPass());
592
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000593 // Remove avail extern fns and globals definitions since we aren't compiling
594 // an object file for later LTO. For LTO we want to preserve these so they
595 // are eligible for inlining at link-time. Note if they are unreferenced they
596 // will be removed by GlobalDCE later, so this only impacts referenced
597 // available externally globals. Eventually they will be suppressed during
598 // codegen, but eliminating here enables more opportunity for GlobalDCE as it
599 // may make globals referenced by available external functions dead and saves
600 // running remaining passes on the eliminated functions.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000601 MPM.addPass(EliminateAvailableExternallyPass());
602
603 // Do RPO function attribute inference across the module to forward-propagate
604 // attributes where applicable.
605 // FIXME: Is this really an optimization rather than a canonicalization?
606 MPM.addPass(ReversePostOrderFunctionAttrsPass());
607
Chandler Carruthe87fc8c2017-02-12 05:34:04 +0000608 // Re-require GloblasAA here prior to function passes. This is particularly
Chandler Carruthe3f50642016-12-22 06:59:15 +0000609 // useful as the above will have inlined, DCE'ed, and function-attr
610 // propagated everything. We should at this point have a reasonably minimal
611 // and richly annotated call graph. By computing aliasing and mod/ref
612 // information for all local globals here, the late loop passes and notably
613 // the vectorizer will be able to use them to help recognize vectorizable
614 // memory operations.
Chandler Carruthe87fc8c2017-02-12 05:34:04 +0000615 MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000616
617 FunctionPassManager OptimizePM(DebugLogging);
618 OptimizePM.addPass(Float2IntPass());
619 // FIXME: We need to run some loop optimizations to re-rotate loops after
620 // simplify-cfg and others undo their rotation.
621
622 // Optimize the loop execution. These passes operate on entire loop nests
623 // rather than on each loop in an inside-out manner, and so they are actually
624 // function passes.
Chandler Carrutha95ff382017-01-27 00:50:21 +0000625
626 // First rotate loops that may have been un-rotated by prior passes.
627 OptimizePM.addPass(createFunctionToLoopPassAdaptor(LoopRotatePass()));
628
629 // Distribute loops to allow partial vectorization. I.e. isolate dependences
630 // into separate loop that would otherwise inhibit vectorization. This is
631 // currently only performed for loops marked with the metadata
632 // llvm.loop.distribute=true or when -enable-loop-distribute is specified.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000633 OptimizePM.addPass(LoopDistributePass());
Chandler Carrutha95ff382017-01-27 00:50:21 +0000634
635 // Now run the core loop vectorizer.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000636 OptimizePM.addPass(LoopVectorizePass());
Chandler Carrutha95ff382017-01-27 00:50:21 +0000637
Chandler Carruthbaabda92017-01-27 01:32:26 +0000638 // Eliminate loads by forwarding stores from the previous iteration to loads
639 // of the current iteration.
640 OptimizePM.addPass(LoopLoadEliminationPass());
Chandler Carrutha95ff382017-01-27 00:50:21 +0000641
642 // Cleanup after the loop optimization passes.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000643 OptimizePM.addPass(InstCombinePass());
644
Chandler Carrutha95ff382017-01-27 00:50:21 +0000645
646 // Now that we've formed fast to execute loop structures, we do further
647 // optimizations. These are run afterward as they might block doing complex
648 // analyses and transforms such as what are needed for loop vectorization.
649
Chandler Carruthe3f50642016-12-22 06:59:15 +0000650 // Optimize parallel scalar instruction chains into SIMD instructions.
651 OptimizePM.addPass(SLPVectorizerPass());
652
Chandler Carrutha95ff382017-01-27 00:50:21 +0000653 // Cleanup after all of the vectorizers.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000654 OptimizePM.addPass(SimplifyCFGPass());
655 OptimizePM.addPass(InstCombinePass());
656
657 // Unroll small loops to hide loop backedge latency and saturate any parallel
Chandler Carrutha95ff382017-01-27 00:50:21 +0000658 // execution resources of an out-of-order processor. We also then need to
659 // clean up redundancies and loop invariant code.
660 // FIXME: It would be really good to use a loop-integrated instruction
661 // combiner for cleanup here so that the unrolling and LICM can be pipelined
662 // across the loop nests.
Dehao Chen7d230322017-02-18 03:46:51 +0000663 OptimizePM.addPass(createFunctionToLoopPassAdaptor(LoopUnrollPass::create(Level)));
Chandler Carrutha95ff382017-01-27 00:50:21 +0000664 OptimizePM.addPass(InstCombinePass());
Chandler Carruth0ede22e2017-02-09 23:54:57 +0000665 OptimizePM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
Chandler Carrutha95ff382017-01-27 00:50:21 +0000666 OptimizePM.addPass(createFunctionToLoopPassAdaptor(LICMPass()));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000667
668 // Now that we've vectorized and unrolled loops, we may have more refined
669 // alignment information, try to re-derive it here.
670 OptimizePM.addPass(AlignmentFromAssumptionsPass());
671
Chandler Carrutha95ff382017-01-27 00:50:21 +0000672 // LoopSink pass sinks instructions hoisted by LICM, which serves as a
673 // canonicalization pass that enables other optimizations. As a result,
674 // LoopSink pass needs to be a very late IR pass to avoid undoing LICM
675 // result too early.
676 OptimizePM.addPass(LoopSinkPass());
677
678 // And finally clean up LCSSA form before generating code.
679 OptimizePM.addPass(InstSimplifierPass());
680
Filipe Cabecinhas92dc3482017-04-26 12:02:41 +0000681 // LoopSink (and other loop passes since the last simplifyCFG) might have
682 // resulted in single-entry-single-exit or empty blocks. Clean up the CFG.
683 OptimizePM.addPass(SimplifyCFGPass());
684
Chandler Carrutha95ff382017-01-27 00:50:21 +0000685 // Add the core optimizing pipeline.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000686 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM)));
687
688 // Now we need to do some global optimization transforms.
689 // FIXME: It would seem like these should come first in the optimization
690 // pipeline and maybe be the bottom of the canonicalization pipeline? Weird
691 // ordering here.
692 MPM.addPass(GlobalDCEPass());
693 MPM.addPass(ConstantMergePass());
694
695 return MPM;
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000696}
697
Chandler Carruthe3f50642016-12-22 06:59:15 +0000698ModulePassManager
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000699PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
700 bool DebugLogging) {
701 assert(Level != O0 && "Must request optimizations for the default pipeline!");
702
703 ModulePassManager MPM(DebugLogging);
704
705 // Force any function attributes we want the rest of the pipeline to observe.
706 MPM.addPass(ForceFunctionAttrsPass());
707
708 // Add the core simplification pipeline.
709 MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging));
710
711 // Now add the optimization pipeline.
712 MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
713
714 return MPM;
715}
716
717ModulePassManager
718PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level,
719 bool DebugLogging) {
720 assert(Level != O0 && "Must request optimizations for the default pipeline!");
721
722 ModulePassManager MPM(DebugLogging);
723
724 // Force any function attributes we want the rest of the pipeline to observe.
725 MPM.addPass(ForceFunctionAttrsPass());
726
727 // If we are planning to perform ThinLTO later, we don't bloat the code with
728 // unrolling/vectorization/... now. Just simplify the module as much as we
729 // can.
730 MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging));
731
732 // Run partial inlining pass to partially inline functions that have
733 // large bodies.
734 // FIXME: It isn't clear whether this is really the right place to run this
735 // in ThinLTO. Because there is another canonicalization and simplification
736 // phase that will run after the thin link, running this here ends up with
737 // less information than will be available later and it may grow functions in
738 // ways that aren't beneficial.
739 if (RunPartialInlining)
740 MPM.addPass(PartialInlinerPass());
741
742 // Reduce the size of the IR as much as possible.
743 MPM.addPass(GlobalOptPass());
744
745 // Rename anon globals to be able to export them in the summary.
746 MPM.addPass(NameAnonGlobalPass());
747
748 return MPM;
749}
750
751ModulePassManager
752PassBuilder::buildThinLTODefaultPipeline(OptimizationLevel Level,
753 bool DebugLogging) {
754 // FIXME: The summary index is not hooked in the new pass manager yet.
755 // When it's going to be hooked, enable WholeProgramDevirt and LowerTypeTest
756 // here.
757
758 ModulePassManager MPM(DebugLogging);
759
760 // Force any function attributes we want the rest of the pipeline to observe.
761 MPM.addPass(ForceFunctionAttrsPass());
762
763 // During the ThinLTO backend phase we perform early indirect call promotion
764 // here, before globalopt. Otherwise imported available_externally functions
765 // look unreferenced and are removed.
766 MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
767 PGOOpt && PGOOpt->SamplePGO &&
768 !PGOOpt->ProfileUseFile.empty()));
769
770 // Add the core simplification pipeline.
771 MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging));
772
773 // Now add the optimization pipeline.
774 MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
775
776 return MPM;
777}
778
779ModulePassManager
Chandler Carruthe3f50642016-12-22 06:59:15 +0000780PassBuilder::buildLTOPreLinkDefaultPipeline(OptimizationLevel Level,
781 bool DebugLogging) {
782 assert(Level != O0 && "Must request optimizations for the default pipeline!");
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000783 // FIXME: We should use a customized pre-link pipeline!
Chandler Carruthe3f50642016-12-22 06:59:15 +0000784 return buildPerModuleDefaultPipeline(Level, DebugLogging);
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000785}
786
Chandler Carruthe3f50642016-12-22 06:59:15 +0000787ModulePassManager PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
788 bool DebugLogging) {
789 assert(Level != O0 && "Must request optimizations for the default pipeline!");
790 ModulePassManager MPM(DebugLogging);
791
Davide Italiano089a9122017-01-24 00:57:39 +0000792 // Remove unused virtual tables to improve the quality of code generated by
793 // whole-program devirtualization and bitset lowering.
794 MPM.addPass(GlobalDCEPass());
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000795
Davide Italiano089a9122017-01-24 00:57:39 +0000796 // Force any function attributes we want the rest of the pipeline to observe.
797 MPM.addPass(ForceFunctionAttrsPass());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000798
Davide Italiano089a9122017-01-24 00:57:39 +0000799 // Do basic inference of function attributes from known properties of system
800 // libraries and other oracles.
801 MPM.addPass(InferFunctionAttrsPass());
802
803 if (Level > 1) {
804 // Indirect call promotion. This should promote all the targets that are
805 // left by the earlier promotion pass that promotes intra-module targets.
806 // This two-step promotion is to save the compile time. For LTO, it should
807 // produce the same result as if we only do promotion here.
Dehao Chencc75d242017-02-23 22:15:18 +0000808 MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
809 PGOOpt && PGOOpt->SamplePGO));
Davide Italiano089a9122017-01-24 00:57:39 +0000810
811 // Propagate constants at call sites into the functions they call. This
812 // opens opportunities for globalopt (and inlining) by substituting function
813 // pointers passed as arguments to direct uses of functions.
814 MPM.addPass(IPSCCPPass());
815 }
816
817 // Now deduce any function attributes based in the current code.
818 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
819 PostOrderFunctionAttrsPass()));
820
821 // Do RPO function attribute inference across the module to forward-propagate
822 // attributes where applicable.
823 // FIXME: Is this really an optimization rather than a canonicalization?
824 MPM.addPass(ReversePostOrderFunctionAttrsPass());
825
826 // Use inragne annotations on GEP indices to split globals where beneficial.
827 MPM.addPass(GlobalSplitPass());
828
829 // Run whole program optimization of virtual call when the list of callees
830 // is fixed.
831 MPM.addPass(WholeProgramDevirtPass());
832
833 // Stop here at -O1.
834 if (Level == 1)
835 return MPM;
836
837 // Optimize globals to try and fold them into constants.
838 MPM.addPass(GlobalOptPass());
839
840 // Promote any localized globals to SSA registers.
841 MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
842
843 // Linking modules together can lead to duplicate global constant, only
844 // keep one copy of each constant.
845 MPM.addPass(ConstantMergePass());
846
847 // Remove unused arguments from functions.
848 MPM.addPass(DeadArgumentEliminationPass());
849
850 // Reduce the code after globalopt and ipsccp. Both can open up significant
851 // simplification opportunities, and both can propagate functions through
852 // function pointers. When this happens, we often have to resolve varargs
853 // calls, etc, so let instcombine do this.
854 // FIXME: add peephole extensions here as the legacy PM does.
855 MPM.addPass(createModuleToFunctionPassAdaptor(InstCombinePass()));
856
857 // Note: historically, the PruneEH pass was run first to deduce nounwind and
858 // generally clean up exception handling overhead. It isn't clear this is
859 // valuable as the inliner doesn't currently care whether it is inlining an
860 // invoke or a call.
861 // Run the inliner now.
862 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(InlinerPass()));
863
864 // Optimize globals again after we ran the inliner.
865 MPM.addPass(GlobalOptPass());
866
867 // Garbage collect dead functions.
868 // FIXME: Add ArgumentPromotion pass after once it's ported.
869 MPM.addPass(GlobalDCEPass());
870
871 FunctionPassManager FPM(DebugLogging);
872
873 // The IPO Passes may leave cruft around. Clean up after them.
874 // FIXME: add peephole extensions here as the legacy PM does.
875 FPM.addPass(InstCombinePass());
876 FPM.addPass(JumpThreadingPass());
877
878 // Break up allocas
879 FPM.addPass(SROA());
880
881 // Run a few AA driver optimizations here and now to cleanup the code.
882 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
883
884 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
885 PostOrderFunctionAttrsPass()));
886 // FIXME: here we run IP alias analysis in the legacy PM.
887
888 FunctionPassManager MainFPM;
889
890 // FIXME: once we fix LoopPass Manager, add LICM here.
891 // FIXME: once we provide support for enabling MLSM, add it here.
892 // FIXME: once we provide support for enabling NewGVN, add it here.
Davide Italiano8a09b8e2017-05-22 23:41:40 +0000893 if (RunNewGVN)
894 MainFPM.addPass(NewGVNPass());
895 else
896 MainFPM.addPass(GVN());
Davide Italiano089a9122017-01-24 00:57:39 +0000897
898 // Remove dead memcpy()'s.
899 MainFPM.addPass(MemCpyOptPass());
900
901 // Nuke dead stores.
902 MainFPM.addPass(DSEPass());
903
904 // FIXME: at this point, we run a bunch of loop passes:
905 // indVarSimplify, loopDeletion, loopInterchange, loopUnrool,
906 // loopVectorize. Enable them once the remaining issue with LPM
907 // are sorted out.
908
909 MainFPM.addPass(InstCombinePass());
910 MainFPM.addPass(SimplifyCFGPass());
911 MainFPM.addPass(SCCPPass());
912 MainFPM.addPass(InstCombinePass());
913 MainFPM.addPass(BDCEPass());
914
915 // FIXME: We may want to run SLPVectorizer here.
916 // After vectorization, assume intrinsics may tell us more
917 // about pointer alignments.
918#if 0
919 MainFPM.add(AlignmentFromAssumptionsPass());
920#endif
921
922 // FIXME: Conditionally run LoadCombine here, after it's ported
923 // (in case we still have this pass, given its questionable usefulness).
924
925 // FIXME: add peephole extensions to the PM here.
926 MainFPM.addPass(InstCombinePass());
927 MainFPM.addPass(JumpThreadingPass());
928 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(MainFPM)));
929
930 // Create a function that performs CFI checks for cross-DSO calls with
931 // targets in the current module.
932 MPM.addPass(CrossDSOCFIPass());
933
934 // Lower type metadata and the type.test intrinsic. This pass supports
935 // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs
936 // to be run at link time if CFI is enabled. This pass does nothing if
937 // CFI is disabled.
938 // Enable once we add support for the summary in the new PM.
939#if 0
Peter Collingbourne857aba42017-02-09 21:45:01 +0000940 MPM.addPass(LowerTypeTestsPass(Summary ? PassSummaryAction::Export :
941 PassSummaryAction::None,
Davide Italiano089a9122017-01-24 00:57:39 +0000942 Summary));
943#endif
944
945 // Add late LTO optimization passes.
946 // Delete basic blocks, which optimization passes may have killed.
947 MPM.addPass(createModuleToFunctionPassAdaptor(SimplifyCFGPass()));
948
949 // Drop bodies of available eternally objects to improve GlobalDCE.
950 MPM.addPass(EliminateAvailableExternallyPass());
951
952 // Now that we have optimized the program, discard unreachable functions.
953 MPM.addPass(GlobalDCEPass());
954
955 // FIXME: Enable MergeFuncs, conditionally, after ported, maybe.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000956 return MPM;
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000957}
958
Chandler Carruth060ad612016-12-23 20:38:19 +0000959AAManager PassBuilder::buildDefaultAAPipeline() {
960 AAManager AA;
961
962 // The order in which these are registered determines their priority when
963 // being queried.
964
965 // First we register the basic alias analysis that provides the majority of
966 // per-function local AA logic. This is a stateless, on-demand local set of
967 // AA techniques.
968 AA.registerFunctionAnalysis<BasicAA>();
969
970 // Next we query fast, specialized alias analyses that wrap IR-embedded
971 // information about aliasing.
972 AA.registerFunctionAnalysis<ScopedNoAliasAA>();
973 AA.registerFunctionAnalysis<TypeBasedAA>();
974
975 // Add support for querying global aliasing information when available.
Chandler Carruth534d6442016-12-24 05:11:17 +0000976 // Because the `AAManager` is a function analysis and `GlobalsAA` is a module
977 // analysis, all that the `AAManager` can do is query for any *cached*
Chandler Carruthe87fc8c2017-02-12 05:34:04 +0000978 // results from `GlobalsAA` through a readonly proxy.
Chandler Carruth060ad612016-12-23 20:38:19 +0000979 AA.registerModuleAnalysis<GlobalsAA>();
Chandler Carruth060ad612016-12-23 20:38:19 +0000980
981 return AA;
982}
983
Chandler Carruth241bf242016-08-03 07:44:48 +0000984static Optional<int> parseRepeatPassName(StringRef Name) {
985 if (!Name.consume_front("repeat<") || !Name.consume_back(">"))
986 return None;
987 int Count;
988 if (Name.getAsInteger(0, Count) || Count <= 0)
989 return None;
990 return Count;
991}
992
Chandler Carruth05ca5ac2016-12-28 11:07:33 +0000993static Optional<int> parseDevirtPassName(StringRef Name) {
994 if (!Name.consume_front("devirt<") || !Name.consume_back(">"))
995 return None;
996 int Count;
997 if (Name.getAsInteger(0, Count) || Count <= 0)
998 return None;
999 return Count;
1000}
1001
Chandler Carruth8b3be4e2017-06-01 11:39:39 +00001002/// Tests whether a pass name starts with a valid prefix for a default pipeline
1003/// alias.
1004static bool startsWithDefaultPipelineAliasPrefix(StringRef Name) {
1005 return Name.startswith("default") || Name.startswith("thinlto") ||
1006 Name.startswith("lto");
1007}
1008
Chandler Carruth66445382014-01-11 08:16:35 +00001009static bool isModulePassName(StringRef Name) {
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001010 // Manually handle aliases for pre-configured pipeline fragments.
Chandler Carruth8b3be4e2017-06-01 11:39:39 +00001011 if (startsWithDefaultPipelineAliasPrefix(Name))
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001012 return DefaultAliasRegex.match(Name);
1013
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001014 // Explicitly handle pass manager names.
1015 if (Name == "module")
1016 return true;
1017 if (Name == "cgscc")
1018 return true;
1019 if (Name == "function")
1020 return true;
1021
Chandler Carruth241bf242016-08-03 07:44:48 +00001022 // Explicitly handle custom-parsed pass names.
1023 if (parseRepeatPassName(Name))
1024 return true;
1025
Chandler Carruth74a8a222016-06-17 07:15:29 +00001026#define MODULE_PASS(NAME, CREATE_PASS) \
1027 if (Name == NAME) \
1028 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +00001029#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001030 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +00001031 return true;
1032#include "PassRegistry.def"
1033
Chandler Carruth66445382014-01-11 08:16:35 +00001034 return false;
1035}
1036
Chandler Carruth572e3402014-04-21 11:12:00 +00001037static bool isCGSCCPassName(StringRef Name) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001038 // Explicitly handle pass manager names.
1039 if (Name == "cgscc")
1040 return true;
1041 if (Name == "function")
1042 return true;
1043
Chandler Carruth241bf242016-08-03 07:44:48 +00001044 // Explicitly handle custom-parsed pass names.
1045 if (parseRepeatPassName(Name))
1046 return true;
Chandler Carruth05ca5ac2016-12-28 11:07:33 +00001047 if (parseDevirtPassName(Name))
1048 return true;
Chandler Carruth241bf242016-08-03 07:44:48 +00001049
Chandler Carruth74a8a222016-06-17 07:15:29 +00001050#define CGSCC_PASS(NAME, CREATE_PASS) \
1051 if (Name == NAME) \
1052 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +00001053#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001054 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +00001055 return true;
1056#include "PassRegistry.def"
1057
Chandler Carruth572e3402014-04-21 11:12:00 +00001058 return false;
1059}
1060
Chandler Carruthd8330982014-01-12 09:34:22 +00001061static bool isFunctionPassName(StringRef Name) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001062 // Explicitly handle pass manager names.
1063 if (Name == "function")
1064 return true;
1065 if (Name == "loop")
1066 return true;
1067
Chandler Carruth241bf242016-08-03 07:44:48 +00001068 // Explicitly handle custom-parsed pass names.
1069 if (parseRepeatPassName(Name))
1070 return true;
1071
Chandler Carruth74a8a222016-06-17 07:15:29 +00001072#define FUNCTION_PASS(NAME, CREATE_PASS) \
1073 if (Name == NAME) \
1074 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +00001075#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001076 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +00001077 return true;
1078#include "PassRegistry.def"
1079
Chandler Carruthd8330982014-01-12 09:34:22 +00001080 return false;
1081}
1082
Justin Bognereecc3c82016-02-25 07:23:08 +00001083static bool isLoopPassName(StringRef Name) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001084 // Explicitly handle pass manager names.
1085 if (Name == "loop")
1086 return true;
1087
Chandler Carruth241bf242016-08-03 07:44:48 +00001088 // Explicitly handle custom-parsed pass names.
1089 if (parseRepeatPassName(Name))
1090 return true;
1091
Chandler Carruth74a8a222016-06-17 07:15:29 +00001092#define LOOP_PASS(NAME, CREATE_PASS) \
1093 if (Name == NAME) \
1094 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +00001095#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1096 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1097 return true;
1098#include "PassRegistry.def"
1099
1100 return false;
1101}
1102
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001103Optional<std::vector<PassBuilder::PipelineElement>>
1104PassBuilder::parsePipelineText(StringRef Text) {
1105 std::vector<PipelineElement> ResultPipeline;
1106
1107 SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
1108 &ResultPipeline};
1109 for (;;) {
1110 std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
1111 size_t Pos = Text.find_first_of(",()");
1112 Pipeline.push_back({Text.substr(0, Pos), {}});
1113
1114 // If we have a single terminating name, we're done.
1115 if (Pos == Text.npos)
1116 break;
1117
1118 char Sep = Text[Pos];
1119 Text = Text.substr(Pos + 1);
1120 if (Sep == ',')
1121 // Just a name ending in a comma, continue.
1122 continue;
1123
1124 if (Sep == '(') {
1125 // Push the inner pipeline onto the stack to continue processing.
1126 PipelineStack.push_back(&Pipeline.back().InnerPipeline);
1127 continue;
1128 }
1129
1130 assert(Sep == ')' && "Bogus separator!");
1131 // When handling the close parenthesis, we greedily consume them to avoid
1132 // empty strings in the pipeline.
1133 do {
1134 // If we try to pop the outer pipeline we have unbalanced parentheses.
1135 if (PipelineStack.size() == 1)
1136 return None;
1137
1138 PipelineStack.pop_back();
1139 } while (Text.consume_front(")"));
1140
1141 // Check if we've finished parsing.
1142 if (Text.empty())
1143 break;
1144
1145 // Otherwise, the end of an inner pipeline always has to be followed by
1146 // a comma, and then we can continue.
1147 if (!Text.consume_front(","))
1148 return None;
1149 }
1150
1151 if (PipelineStack.size() > 1)
1152 // Unbalanced paretheses.
1153 return None;
1154
1155 assert(PipelineStack.back() == &ResultPipeline &&
1156 "Wrong pipeline at the bottom of the stack!");
1157 return {std::move(ResultPipeline)};
1158}
1159
1160bool PassBuilder::parseModulePass(ModulePassManager &MPM,
1161 const PipelineElement &E, bool VerifyEachPass,
1162 bool DebugLogging) {
1163 auto &Name = E.Name;
1164 auto &InnerPipeline = E.InnerPipeline;
1165
1166 // First handle complex passes like the pass managers which carry pipelines.
1167 if (!InnerPipeline.empty()) {
1168 if (Name == "module") {
1169 ModulePassManager NestedMPM(DebugLogging);
1170 if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
1171 DebugLogging))
1172 return false;
1173 MPM.addPass(std::move(NestedMPM));
1174 return true;
1175 }
1176 if (Name == "cgscc") {
1177 CGSCCPassManager CGPM(DebugLogging);
1178 if (!parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass,
1179 DebugLogging))
1180 return false;
1181 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM),
1182 DebugLogging));
1183 return true;
1184 }
1185 if (Name == "function") {
1186 FunctionPassManager FPM(DebugLogging);
1187 if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
1188 DebugLogging))
1189 return false;
1190 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1191 return true;
1192 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001193 if (auto Count = parseRepeatPassName(Name)) {
1194 ModulePassManager NestedMPM(DebugLogging);
1195 if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
1196 DebugLogging))
1197 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001198 MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001199 return true;
1200 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001201 // Normal passes can't have pipelines.
1202 return false;
1203 }
1204
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001205 // Manually handle aliases for pre-configured pipeline fragments.
Chandler Carruth8b3be4e2017-06-01 11:39:39 +00001206 if (startsWithDefaultPipelineAliasPrefix(Name)) {
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001207 SmallVector<StringRef, 3> Matches;
1208 if (!DefaultAliasRegex.match(Name, &Matches))
1209 return false;
1210 assert(Matches.size() == 3 && "Must capture two matched strings!");
1211
Jordan Rosef85a95f2016-07-25 18:34:51 +00001212 OptimizationLevel L = StringSwitch<OptimizationLevel>(Matches[2])
1213 .Case("O0", O0)
1214 .Case("O1", O1)
1215 .Case("O2", O2)
1216 .Case("O3", O3)
1217 .Case("Os", Os)
1218 .Case("Oz", Oz);
Chandler Carruthe3f50642016-12-22 06:59:15 +00001219 if (L == O0)
1220 // At O0 we do nothing at all!
1221 return true;
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001222
1223 if (Matches[1] == "default") {
Chandler Carruthe3f50642016-12-22 06:59:15 +00001224 MPM.addPass(buildPerModuleDefaultPipeline(L, DebugLogging));
Chandler Carruth8b3be4e2017-06-01 11:39:39 +00001225 } else if (Matches[1] == "thinlto-pre-link") {
1226 MPM.addPass(buildThinLTOPreLinkDefaultPipeline(L, DebugLogging));
1227 } else if (Matches[1] == "thinlto") {
1228 MPM.addPass(buildThinLTODefaultPipeline(L, DebugLogging));
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001229 } else if (Matches[1] == "lto-pre-link") {
Chandler Carruthe3f50642016-12-22 06:59:15 +00001230 MPM.addPass(buildLTOPreLinkDefaultPipeline(L, DebugLogging));
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001231 } else {
1232 assert(Matches[1] == "lto" && "Not one of the matched options!");
Chandler Carruthe3f50642016-12-22 06:59:15 +00001233 MPM.addPass(buildLTODefaultPipeline(L, DebugLogging));
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001234 }
1235 return true;
1236 }
1237
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001238 // Finally expand the basic registered passes from the .inc file.
Chandler Carruth58944182014-04-21 08:08:50 +00001239#define MODULE_PASS(NAME, CREATE_PASS) \
1240 if (Name == NAME) { \
1241 MPM.addPass(CREATE_PASS); \
1242 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +00001243 }
Chandler Carruth628503e2015-01-06 02:10:51 +00001244#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1245 if (Name == "require<" NAME ">") { \
Chandler Carruth9b35e6d2016-08-19 18:36:06 +00001246 MPM.addPass( \
1247 RequireAnalysisPass< \
1248 std::remove_reference<decltype(CREATE_PASS)>::type, Module>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +00001249 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001250 } \
1251 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001252 MPM.addPass(InvalidateAnalysisPass< \
1253 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001254 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +00001255 }
1256#include "PassRegistry.def"
1257
Chandler Carruth66445382014-01-11 08:16:35 +00001258 return false;
1259}
1260
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001261bool PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
1262 const PipelineElement &E, bool VerifyEachPass,
1263 bool DebugLogging) {
1264 auto &Name = E.Name;
1265 auto &InnerPipeline = E.InnerPipeline;
1266
1267 // First handle complex passes like the pass managers which carry pipelines.
1268 if (!InnerPipeline.empty()) {
1269 if (Name == "cgscc") {
1270 CGSCCPassManager NestedCGPM(DebugLogging);
1271 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1272 DebugLogging))
1273 return false;
1274 // Add the nested pass manager with the appropriate adaptor.
1275 CGPM.addPass(std::move(NestedCGPM));
1276 return true;
1277 }
1278 if (Name == "function") {
1279 FunctionPassManager FPM(DebugLogging);
1280 if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
1281 DebugLogging))
1282 return false;
1283 // Add the nested pass manager with the appropriate adaptor.
1284 CGPM.addPass(
1285 createCGSCCToFunctionPassAdaptor(std::move(FPM), DebugLogging));
1286 return true;
1287 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001288 if (auto Count = parseRepeatPassName(Name)) {
1289 CGSCCPassManager NestedCGPM(DebugLogging);
1290 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1291 DebugLogging))
1292 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001293 CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001294 return true;
1295 }
Chandler Carruth05ca5ac2016-12-28 11:07:33 +00001296 if (auto MaxRepetitions = parseDevirtPassName(Name)) {
1297 CGSCCPassManager NestedCGPM(DebugLogging);
1298 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1299 DebugLogging))
1300 return false;
1301 CGPM.addPass(createDevirtSCCRepeatedPass(std::move(NestedCGPM),
1302 *MaxRepetitions, DebugLogging));
1303 return true;
1304 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001305 // Normal passes can't have pipelines.
1306 return false;
1307 }
1308
1309 // Now expand the basic registered passes from the .inc file.
Chandler Carruth572e3402014-04-21 11:12:00 +00001310#define CGSCC_PASS(NAME, CREATE_PASS) \
1311 if (Name == NAME) { \
1312 CGPM.addPass(CREATE_PASS); \
1313 return true; \
1314 }
Chandler Carruth628503e2015-01-06 02:10:51 +00001315#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1316 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001317 CGPM.addPass(RequireAnalysisPass< \
Chandler Carruth9b35e6d2016-08-19 18:36:06 +00001318 std::remove_reference<decltype(CREATE_PASS)>::type, \
Chandler Carruth88823462016-08-24 09:37:14 +00001319 LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
1320 CGSCCUpdateResult &>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +00001321 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001322 } \
1323 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001324 CGPM.addPass(InvalidateAnalysisPass< \
1325 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001326 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +00001327 }
1328#include "PassRegistry.def"
1329
Chandler Carruth572e3402014-04-21 11:12:00 +00001330 return false;
1331}
1332
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001333bool PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
1334 const PipelineElement &E,
1335 bool VerifyEachPass, bool DebugLogging) {
1336 auto &Name = E.Name;
1337 auto &InnerPipeline = E.InnerPipeline;
1338
1339 // First handle complex passes like the pass managers which carry pipelines.
1340 if (!InnerPipeline.empty()) {
1341 if (Name == "function") {
1342 FunctionPassManager NestedFPM(DebugLogging);
1343 if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
1344 DebugLogging))
1345 return false;
1346 // Add the nested pass manager with the appropriate adaptor.
1347 FPM.addPass(std::move(NestedFPM));
1348 return true;
1349 }
1350 if (Name == "loop") {
1351 LoopPassManager LPM(DebugLogging);
1352 if (!parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass,
1353 DebugLogging))
1354 return false;
1355 // Add the nested pass manager with the appropriate adaptor.
1356 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM)));
1357 return true;
1358 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001359 if (auto Count = parseRepeatPassName(Name)) {
1360 FunctionPassManager NestedFPM(DebugLogging);
1361 if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
1362 DebugLogging))
1363 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001364 FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001365 return true;
1366 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001367 // Normal passes can't have pipelines.
1368 return false;
1369 }
1370
1371 // Now expand the basic registered passes from the .inc file.
Chandler Carruth58944182014-04-21 08:08:50 +00001372#define FUNCTION_PASS(NAME, CREATE_PASS) \
1373 if (Name == NAME) { \
1374 FPM.addPass(CREATE_PASS); \
1375 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +00001376 }
Chandler Carruth628503e2015-01-06 02:10:51 +00001377#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1378 if (Name == "require<" NAME ">") { \
Chandler Carruth9b35e6d2016-08-19 18:36:06 +00001379 FPM.addPass( \
1380 RequireAnalysisPass< \
1381 std::remove_reference<decltype(CREATE_PASS)>::type, Function>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +00001382 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001383 } \
1384 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001385 FPM.addPass(InvalidateAnalysisPass< \
1386 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001387 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +00001388 }
1389#include "PassRegistry.def"
1390
Chandler Carruthd8330982014-01-12 09:34:22 +00001391 return false;
1392}
1393
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001394bool PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001395 bool VerifyEachPass, bool DebugLogging) {
Chandler Carruth241bf242016-08-03 07:44:48 +00001396 StringRef Name = E.Name;
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001397 auto &InnerPipeline = E.InnerPipeline;
1398
1399 // First handle complex passes like the pass managers which carry pipelines.
1400 if (!InnerPipeline.empty()) {
1401 if (Name == "loop") {
1402 LoopPassManager NestedLPM(DebugLogging);
1403 if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
1404 DebugLogging))
1405 return false;
1406 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001407 LPM.addPass(std::move(NestedLPM));
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001408 return true;
1409 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001410 if (auto Count = parseRepeatPassName(Name)) {
1411 LoopPassManager NestedLPM(DebugLogging);
1412 if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
1413 DebugLogging))
1414 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001415 LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001416 return true;
1417 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001418 // Normal passes can't have pipelines.
1419 return false;
1420 }
1421
1422 // Now expand the basic registered passes from the .inc file.
Justin Bognereecc3c82016-02-25 07:23:08 +00001423#define LOOP_PASS(NAME, CREATE_PASS) \
1424 if (Name == NAME) { \
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001425 LPM.addPass(CREATE_PASS); \
Justin Bognereecc3c82016-02-25 07:23:08 +00001426 return true; \
1427 }
1428#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1429 if (Name == "require<" NAME ">") { \
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001430 LPM.addPass(RequireAnalysisPass< \
Chandler Carruth410eaeb2017-01-11 06:23:21 +00001431 std::remove_reference<decltype(CREATE_PASS)>::type, Loop, \
1432 LoopAnalysisManager, LoopStandardAnalysisResults &, \
1433 LPMUpdater &>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +00001434 return true; \
1435 } \
1436 if (Name == "invalidate<" NAME ">") { \
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001437 LPM.addPass(InvalidateAnalysisPass< \
Chandler Carruth470734b2016-02-26 12:30:18 +00001438 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +00001439 return true; \
1440 }
1441#include "PassRegistry.def"
1442
1443 return false;
1444}
1445
Chandler Carruthedf59962016-02-18 09:45:17 +00001446bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
Chandler Carruth45a9c202016-03-11 09:15:11 +00001447#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1448 if (Name == NAME) { \
1449 AA.registerModuleAnalysis< \
1450 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
1451 return true; \
1452 }
Chandler Carruthedf59962016-02-18 09:45:17 +00001453#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1454 if (Name == NAME) { \
Chandler Carruth58dde8c2016-02-26 12:17:54 +00001455 AA.registerFunctionAnalysis< \
1456 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
Chandler Carruthedf59962016-02-18 09:45:17 +00001457 return true; \
1458 }
1459#include "PassRegistry.def"
1460
1461 return false;
1462}
1463
Justin Bognereecc3c82016-02-25 07:23:08 +00001464bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001465 ArrayRef<PipelineElement> Pipeline,
Justin Bognereecc3c82016-02-25 07:23:08 +00001466 bool VerifyEachPass,
1467 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001468 for (const auto &Element : Pipeline) {
1469 if (!parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging))
1470 return false;
1471 // FIXME: No verifier support for Loop passes!
Justin Bognereecc3c82016-02-25 07:23:08 +00001472 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001473 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +00001474}
1475
Chandler Carruth1ff77242015-03-07 09:02:36 +00001476bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001477 ArrayRef<PipelineElement> Pipeline,
Chandler Carruth1ff77242015-03-07 09:02:36 +00001478 bool VerifyEachPass,
1479 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001480 for (const auto &Element : Pipeline) {
1481 if (!parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging))
1482 return false;
1483 if (VerifyEachPass)
1484 FPM.addPass(VerifierPass());
Chandler Carruthd8330982014-01-12 09:34:22 +00001485 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001486 return true;
Chandler Carruthd8330982014-01-12 09:34:22 +00001487}
1488
Chandler Carruth1ff77242015-03-07 09:02:36 +00001489bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001490 ArrayRef<PipelineElement> Pipeline,
Chandler Carruth1ff77242015-03-07 09:02:36 +00001491 bool VerifyEachPass,
1492 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001493 for (const auto &Element : Pipeline) {
1494 if (!parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging))
1495 return false;
1496 // FIXME: No verifier support for CGSCC passes!
Chandler Carruth572e3402014-04-21 11:12:00 +00001497 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001498 return true;
Chandler Carruth572e3402014-04-21 11:12:00 +00001499}
1500
NAKAMURA Takumia42f5282016-05-16 10:13:37 +00001501void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM,
1502 FunctionAnalysisManager &FAM,
1503 CGSCCAnalysisManager &CGAM,
1504 ModuleAnalysisManager &MAM) {
1505 MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
1506 MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
NAKAMURA Takumia42f5282016-05-16 10:13:37 +00001507 CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
1508 FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
1509 FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
1510 FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
1511 LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
1512}
1513
Chandler Carruth1ff77242015-03-07 09:02:36 +00001514bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001515 ArrayRef<PipelineElement> Pipeline,
Chandler Carruth1ff77242015-03-07 09:02:36 +00001516 bool VerifyEachPass,
1517 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001518 for (const auto &Element : Pipeline) {
1519 if (!parseModulePass(MPM, Element, VerifyEachPass, DebugLogging))
1520 return false;
1521 if (VerifyEachPass)
1522 MPM.addPass(VerifierPass());
Chandler Carruth66445382014-01-11 08:16:35 +00001523 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001524 return true;
Chandler Carruth66445382014-01-11 08:16:35 +00001525}
1526
1527// Primary pass pipeline description parsing routine.
1528// FIXME: Should this routine accept a TargetMachine or require the caller to
1529// pre-populate the analysis managers with target-specific stuff?
Chandler Carruth1ff77242015-03-07 09:02:36 +00001530bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
1531 StringRef PipelineText, bool VerifyEachPass,
1532 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001533 auto Pipeline = parsePipelineText(PipelineText);
1534 if (!Pipeline || Pipeline->empty())
1535 return false;
Chandler Carruth66445382014-01-11 08:16:35 +00001536
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001537 // If the first name isn't at the module layer, wrap the pipeline up
1538 // automatically.
1539 StringRef FirstName = Pipeline->front().Name;
Chandler Carruth66445382014-01-11 08:16:35 +00001540
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001541 if (!isModulePassName(FirstName)) {
1542 if (isCGSCCPassName(FirstName))
1543 Pipeline = {{"cgscc", std::move(*Pipeline)}};
1544 else if (isFunctionPassName(FirstName))
1545 Pipeline = {{"function", std::move(*Pipeline)}};
1546 else if (isLoopPassName(FirstName))
1547 Pipeline = {{"function", {{"loop", std::move(*Pipeline)}}}};
1548 else
1549 // Unknown pass name!
Chandler Carruth572e3402014-04-21 11:12:00 +00001550 return false;
Chandler Carruth572e3402014-04-21 11:12:00 +00001551 }
1552
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001553 return parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging);
Chandler Carruth66445382014-01-11 08:16:35 +00001554}
Chandler Carruthedf59962016-02-18 09:45:17 +00001555
1556bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) {
Chandler Carruth060ad612016-12-23 20:38:19 +00001557 // If the pipeline just consists of the word 'default' just replace the AA
1558 // manager with our default one.
1559 if (PipelineText == "default") {
1560 AA = buildDefaultAAPipeline();
1561 return true;
1562 }
1563
Chandler Carruthedf59962016-02-18 09:45:17 +00001564 while (!PipelineText.empty()) {
1565 StringRef Name;
1566 std::tie(Name, PipelineText) = PipelineText.split(',');
1567 if (!parseAAPassName(AA, Name))
1568 return false;
1569 }
1570
1571 return true;
1572}