blob: dc085d543561ea311c51e043841fb66fc685607a [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"
Xinliang David Li6e5dd412016-05-05 02:59:57 +000025#include "llvm/Analysis/BranchProbabilityInfo.h"
Mehdi Amini27d23792016-09-16 16:56:30 +000026#include "llvm/Analysis/CFGPrinter.h"
George Burgess IVbfa401e2016-07-06 00:26:41 +000027#include "llvm/Analysis/CFLAndersAliasAnalysis.h"
28#include "llvm/Analysis/CFLSteensAliasAnalysis.h"
Chandler Carruth572e3402014-04-21 11:12:00 +000029#include "llvm/Analysis/CGSCCPassManager.h"
Chandler Carruth4c660f72016-03-10 11:24:11 +000030#include "llvm/Analysis/CallGraph.h"
Michael Kupersteinde16b442016-04-18 23:55:01 +000031#include "llvm/Analysis/DemandedBits.h"
Chandler Carruth49c22192016-05-12 22:19:39 +000032#include "llvm/Analysis/DependenceAnalysis.h"
Hongbin Zheng751337f2016-02-25 17:54:15 +000033#include "llvm/Analysis/DominanceFrontier.h"
Chandler Carruth45a9c202016-03-11 09:15:11 +000034#include "llvm/Analysis/GlobalsModRef.h"
Dehao Chen1a444522016-07-16 22:51:33 +000035#include "llvm/Analysis/IVUsers.h"
Chandler Carruthbf71a342014-02-06 04:37:03 +000036#include "llvm/Analysis/LazyCallGraph.h"
Sean Silva687019f2016-06-13 22:01:25 +000037#include "llvm/Analysis/LazyValueInfo.h"
Xinliang David Li8a021312016-07-02 21:18:40 +000038#include "llvm/Analysis/LoopAccessAnalysis.h"
Chandler Carruthaaf0b4c2015-01-20 10:58:50 +000039#include "llvm/Analysis/LoopInfo.h"
Chandler Carruth61440d22016-03-10 00:55:30 +000040#include "llvm/Analysis/MemoryDependenceAnalysis.h"
Daniel Berlin554dcd82017-04-11 20:06:36 +000041#include "llvm/Analysis/MemorySSA.h"
Teresa Johnsonf93b2462016-08-12 13:53:02 +000042#include "llvm/Analysis/ModuleSummaryAnalysis.h"
Adam Nemet0965da22017-10-09 23:19:02 +000043#include "llvm/Analysis/OptimizationRemarkEmitter.h"
Hongbin Zheng3f978402016-02-25 17:54:07 +000044#include "llvm/Analysis/PostDominators.h"
Easwaran Raman019e0bf2016-06-03 22:54:26 +000045#include "llvm/Analysis/ProfileSummaryInfo.h"
Hongbin Zhengbc539772016-02-25 17:54:25 +000046#include "llvm/Analysis/RegionInfo.h"
Chandler Carruth2f1fd162015-08-17 02:08:17 +000047#include "llvm/Analysis/ScalarEvolution.h"
Chandler Carruth2b3d0442016-02-20 04:01:45 +000048#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
Chandler Carruthd6091a02016-02-20 04:03:06 +000049#include "llvm/Analysis/ScopedNoAliasAA.h"
Chandler Carruth8ca43222015-01-15 11:39:46 +000050#include "llvm/Analysis/TargetLibraryInfo.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000051#include "llvm/Analysis/TargetTransformInfo.h"
Chandler Carruthc1dc3842016-02-20 04:04:52 +000052#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
Michael Kuperstein82d5da52016-06-24 20:13:42 +000053#include "llvm/CodeGen/PreISelIntrinsicLowering.h"
Wei Mi90d195a2016-07-08 03:32:49 +000054#include "llvm/CodeGen/UnreachableBlockElim.h"
Chandler Carruth64764b42015-01-14 10:19:28 +000055#include "llvm/IR/Dominators.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000056#include "llvm/IR/IRPrintingPasses.h"
Chandler Carruth66445382014-01-11 08:16:35 +000057#include "llvm/IR/PassManager.h"
Chandler Carruth4d356312014-01-20 11:34:08 +000058#include "llvm/IR/Verifier.h"
Chandler Carruth52eef882014-01-12 12:15:39 +000059#include "llvm/Support/Debug.h"
Chandler Carruth8b5a74192016-02-28 22:16:03 +000060#include "llvm/Support/Regex.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000061#include "llvm/Target/TargetMachine.h"
Amjad Aboudf1f57a32018-01-25 12:06:32 +000062#include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.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"
Matthew Simpsoncb585582017-10-25 13:40:08 +000066#include "llvm/Transforms/IPO/CalledValuePropagation.h"
Davide Italiano164b9bc2016-05-05 00:51:09 +000067#include "llvm/Transforms/IPO/ConstantMerge.h"
Davide Italiano92b933a2016-07-09 03:25:35 +000068#include "llvm/Transforms/IPO/CrossDSOCFI.h"
Sean Silvae3bb4572016-06-12 09:16:39 +000069#include "llvm/Transforms/IPO/DeadArgumentElimination.h"
Davide Italiano344e8382016-05-05 02:37:32 +000070#include "llvm/Transforms/IPO/ElimAvailExtern.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000071#include "llvm/Transforms/IPO/ForceFunctionAttrs.h"
Chandler Carruth9c4ed172016-02-18 11:03:11 +000072#include "llvm/Transforms/IPO/FunctionAttrs.h"
Teresa Johnson21241572016-07-18 21:22:24 +000073#include "llvm/Transforms/IPO/FunctionImport.h"
Davide Italiano66228c42016-05-03 19:39:15 +000074#include "llvm/Transforms/IPO/GlobalDCE.h"
Justin Bogner1a075012016-04-26 00:28:01 +000075#include "llvm/Transforms/IPO/GlobalOpt.h"
Davide Italiano2ae76dd2016-11-21 00:28:23 +000076#include "llvm/Transforms/IPO/GlobalSplit.h"
Chandler Carruth3a040e62015-12-27 08:41:34 +000077#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
Chandler Carruth1d963112016-12-20 03:15:32 +000078#include "llvm/Transforms/IPO/Inliner.h"
Justin Bogner4563a062016-04-26 20:15:52 +000079#include "llvm/Transforms/IPO/Internalize.h"
Davide Italianoe8ae0b52016-07-11 18:10:06 +000080#include "llvm/Transforms/IPO/LowerTypeTests.h"
Easwaran Raman1832bf62016-06-27 16:50:18 +000081#include "llvm/Transforms/IPO/PartialInlining.h"
Davide Italianof54f2f02016-05-05 21:05:36 +000082#include "llvm/Transforms/IPO/SCCP.h"
Justin Bogner21e15372015-10-30 23:28:12 +000083#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
Easwaran Ramanbdf20262018-01-09 19:39:35 +000084#include "llvm/Transforms/IPO/SyntheticCountsPropagation.h"
Davide Italianod737dd22016-06-14 21:44:19 +000085#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000086#include "llvm/Transforms/InstCombine/InstCombine.h"
Xinliang David Lie6b89292016-04-18 17:47:38 +000087#include "llvm/Transforms/InstrProfiling.h"
Chandler Carruth00a301d2017-11-14 01:30:04 +000088#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
Xinliang David Li8aebf442016-05-06 05:49:19 +000089#include "llvm/Transforms/PGOInstrumentation.h"
Xinliang David Lid38392e2016-05-27 23:20:16 +000090#include "llvm/Transforms/SampleProfile.h"
Justin Bogner19b67992015-10-30 23:13:18 +000091#include "llvm/Transforms/Scalar/ADCE.h"
Sean Silvaa4c2d152016-06-15 06:18:01 +000092#include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h"
Davide Italiano655a1452016-05-25 01:57:04 +000093#include "llvm/Transforms/Scalar/BDCE.h"
Jun Bum Lim0c990072017-11-03 20:41:16 +000094#include "llvm/Transforms/Scalar/CallSiteSplitting.h"
Adam Nemet3beef412016-07-18 16:29:17 +000095#include "llvm/Transforms/Scalar/ConstantHoisting.h"
Sean Silvab025d372016-07-06 23:26:29 +000096#include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h"
Justin Bogner395c2122016-04-22 19:40:41 +000097#include "llvm/Transforms/Scalar/DCE.h"
Justin Bogner594e07b2016-05-17 21:38:13 +000098#include "llvm/Transforms/Scalar/DeadStoreElimination.h"
Sanjay Patel6fd43912017-09-09 13:38:18 +000099#include "llvm/Transforms/Scalar/DivRemPairs.h"
Chandler Carruthe8c686a2015-02-01 10:51:23 +0000100#include "llvm/Transforms/Scalar/EarlyCSE.h"
Michael Kuperstein83b753d2016-06-24 23:32:02 +0000101#include "llvm/Transforms/Scalar/Float2Int.h"
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000102#include "llvm/Transforms/Scalar/GVN.h"
Davide Italiano89ab89d2016-06-14 00:49:23 +0000103#include "llvm/Transforms/Scalar/GuardWidening.h"
Chandler Carruth3bab7e12017-01-11 09:43:56 +0000104#include "llvm/Transforms/Scalar/IVUsersPrinter.h"
Sanjoy Das4d4339d2016-06-05 18:01:19 +0000105#include "llvm/Transforms/Scalar/IndVarSimplify.h"
Fedor Sergeev194a4072018-03-15 11:01:19 +0000106#include "llvm/Transforms/Scalar/InductiveRangeCheckElimination.h"
Sean Silva46590d52016-06-14 00:51:09 +0000107#include "llvm/Transforms/Scalar/JumpThreading.h"
Dehao Chenf400a092016-07-12 22:42:24 +0000108#include "llvm/Transforms/Scalar/LICM.h"
Chandler Carruth3bab7e12017-01-11 09:43:56 +0000109#include "llvm/Transforms/Scalar/LoopAccessAnalysisPrinter.h"
Teresa Johnson1eca6bc2016-08-13 04:11:27 +0000110#include "llvm/Transforms/Scalar/LoopDataPrefetch.h"
Jun Bum Limc837af32016-07-14 18:28:29 +0000111#include "llvm/Transforms/Scalar/LoopDeletion.h"
Adam Nemetb2593f72016-07-18 16:29:27 +0000112#include "llvm/Transforms/Scalar/LoopDistribute.h"
Dehao Chenb9f8e292016-07-12 18:45:51 +0000113#include "llvm/Transforms/Scalar/LoopIdiomRecognize.h"
Chandler Carruthbaabda92017-01-27 01:32:26 +0000114#include "llvm/Transforms/Scalar/LoopLoadElimination.h"
Chandler Carruth3bab7e12017-01-11 09:43:56 +0000115#include "llvm/Transforms/Scalar/LoopPassManager.h"
Artur Pilipenko8fb3d572017-01-25 16:00:44 +0000116#include "llvm/Transforms/Scalar/LoopPredication.h"
Justin Bognerd0d23412016-05-03 22:02:31 +0000117#include "llvm/Transforms/Scalar/LoopRotation.h"
Justin Bognerab6a5132016-05-03 21:47:32 +0000118#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
Chandler Carruthe9b18e32017-01-20 08:42:19 +0000119#include "llvm/Transforms/Scalar/LoopSink.h"
Dehao Chen6132ee82016-07-18 21:41:50 +0000120#include "llvm/Transforms/Scalar/LoopStrengthReduce.h"
Sean Silvae3c18a52016-07-19 23:54:23 +0000121#include "llvm/Transforms/Scalar/LoopUnrollPass.h"
Davide Italiano99223442016-05-13 22:52:35 +0000122#include "llvm/Transforms/Scalar/LowerAtomic.h"
Chandler Carruth43e590e2015-01-24 11:13:02 +0000123#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
Michael Kupersteine45d4d92016-07-28 22:08:41 +0000124#include "llvm/Transforms/Scalar/LowerGuardIntrinsic.h"
Sean Silva6347df02016-06-14 02:44:55 +0000125#include "llvm/Transforms/Scalar/MemCpyOptimizer.h"
Davide Italianob49aa5c2016-06-17 19:10:09 +0000126#include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
Wei Mi1cf58f82016-07-21 22:28:52 +0000127#include "llvm/Transforms/Scalar/NaryReassociate.h"
Davide Italianoe05e3302016-12-22 16:35:02 +0000128#include "llvm/Transforms/Scalar/NewGVN.h"
Davide Italiano1021c682016-05-25 23:38:53 +0000129#include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
Justin Bognerc2bf63d2016-04-26 23:39:29 +0000130#include "llvm/Transforms/Scalar/Reassociate.h"
Fedor Sergeev4b86d792017-12-15 09:32:11 +0000131#include "llvm/Transforms/Scalar/RewriteStatepointsForGC.h"
Davide Italiano98f7e0e2016-05-18 15:18:25 +0000132#include "llvm/Transforms/Scalar/SCCP.h"
Chandler Carruth29a18a42015-09-12 09:09:14 +0000133#include "llvm/Transforms/Scalar/SROA.h"
Chandler Carruth1353f9a2017-04-27 18:45:20 +0000134#include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +0000135#include "llvm/Transforms/Scalar/SimplifyCFG.h"
Justin Bognerb9394902016-04-22 19:54:10 +0000136#include "llvm/Transforms/Scalar/Sink.h"
Chandler Carruthc34f7892017-11-28 11:32:31 +0000137#include "llvm/Transforms/Scalar/SpeculateAroundPHIs.h"
Michael Kupersteinc4061862016-08-01 21:48:33 +0000138#include "llvm/Transforms/Scalar/SpeculativeExecution.h"
Sean Silva59fe82f2016-07-06 23:48:41 +0000139#include "llvm/Transforms/Scalar/TailRecursionElimination.h"
Xinliang David Li1eaecef2016-06-15 21:51:30 +0000140#include "llvm/Transforms/Utils/AddDiscriminators.h"
Wei Mie04d0ef2016-07-22 18:04:25 +0000141#include "llvm/Transforms/Utils/BreakCriticalEdges.h"
Hans Wennborge1ecd612017-11-14 21:09:45 +0000142#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
Easwaran Ramane12c4872016-06-09 19:44:46 +0000143#include "llvm/Transforms/Utils/LCSSA.h"
Rong Xu1c0e9b92016-10-18 21:36:27 +0000144#include "llvm/Transforms/Utils/LibCallsShrinkWrap.h"
Davide Italianocd96cfd2016-07-09 03:03:01 +0000145#include "llvm/Transforms/Utils/LoopSimplify.h"
Michael Kuperstein31b83992016-08-12 17:28:27 +0000146#include "llvm/Transforms/Utils/LowerInvoke.h"
Davide Italianocccf4f02016-06-14 03:22:22 +0000147#include "llvm/Transforms/Utils/Mem2Reg.h"
Mehdi Amini27d23792016-09-16 16:56:30 +0000148#include "llvm/Transforms/Utils/NameAnonGlobals.h"
Davide Italiano16284df2016-07-07 21:14:36 +0000149#include "llvm/Transforms/Utils/SimplifyInstructions.h"
Michael Kuperstein39feb622016-07-25 20:52:00 +0000150#include "llvm/Transforms/Utils/SymbolRewriter.h"
Sean Silvadb90d4d2016-07-09 22:56:50 +0000151#include "llvm/Transforms/Vectorize/LoopVectorize.h"
Sean Silva0dacbd82016-07-09 03:11:29 +0000152#include "llvm/Transforms/Vectorize/SLPVectorizer.h"
Davide Italianocccf4f02016-06-14 03:22:22 +0000153
Chandler Carruth66445382014-01-11 08:16:35 +0000154using namespace llvm;
155
Chandler Carruth719ffe12017-02-12 05:38:04 +0000156static cl::opt<unsigned> MaxDevirtIterations("pm-max-devirt-iterations",
157 cl::ReallyHidden, cl::init(4));
Xinliang David Li126157c2017-05-22 16:41:57 +0000158static cl::opt<bool>
159 RunPartialInlining("enable-npm-partial-inlining", cl::init(false),
160 cl::Hidden, cl::ZeroOrMore,
161 cl::desc("Run Partial inlinining pass"));
Chandler Carruth719ffe12017-02-12 05:38:04 +0000162
Davide Italiano8a09b8e2017-05-22 23:41:40 +0000163static cl::opt<bool>
Davide Italiano8e7d11a2017-05-22 23:47:11 +0000164 RunNewGVN("enable-npm-newgvn", cl::init(false),
Davide Italiano8a09b8e2017-05-22 23:41:40 +0000165 cl::Hidden, cl::ZeroOrMore,
166 cl::desc("Run NewGVN instead of GVN"));
167
Geoff Berry3cca1da2017-06-10 15:20:03 +0000168static cl::opt<bool> EnableEarlyCSEMemSSA(
Geoff Berry2573a192017-06-27 22:25:02 +0000169 "enable-npm-earlycse-memssa", cl::init(true), cl::Hidden,
170 cl::desc("Enable the EarlyCSE w/ MemorySSA pass for the new PM (default = on)"));
Geoff Berry3cca1da2017-06-10 15:20:03 +0000171
Chandler Carruthc246a4c2017-04-27 00:28:03 +0000172static cl::opt<bool> EnableGVNHoist(
173 "enable-npm-gvn-hoist", cl::init(false), cl::Hidden,
174 cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"));
175
Davide Italianobe1b6a92017-06-03 23:18:29 +0000176static cl::opt<bool> EnableGVNSink(
177 "enable-npm-gvn-sink", cl::init(false), cl::Hidden,
178 cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"));
179
Easwaran Ramanbdf20262018-01-09 19:39:35 +0000180static cl::opt<bool> EnableSyntheticCounts(
181 "enable-npm-synthetic-counts", cl::init(false), cl::Hidden, cl::ZeroOrMore,
182 cl::desc("Run synthetic function entry count generation "
183 "pass"));
184
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000185static Regex DefaultAliasRegex(
186 "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$");
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000187
Chandler Carruthe3f50642016-12-22 06:59:15 +0000188static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) {
189 switch (Level) {
190 case PassBuilder::O0:
191 case PassBuilder::O1:
192 case PassBuilder::O2:
193 case PassBuilder::O3:
194 return false;
195
196 case PassBuilder::Os:
197 case PassBuilder::Oz:
198 return true;
199 }
200 llvm_unreachable("Invalid optimization level!");
201}
202
Chandler Carruth66445382014-01-11 08:16:35 +0000203namespace {
204
Chandler Carruthd8330982014-01-12 09:34:22 +0000205/// \brief No-op module pass which does nothing.
Chandler Carruth66445382014-01-11 08:16:35 +0000206struct NoOpModulePass {
Sean Silvafd03ac62016-08-09 00:28:38 +0000207 PreservedAnalyses run(Module &M, ModuleAnalysisManager &) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000208 return PreservedAnalyses::all();
209 }
Chandler Carrutha13f27c2014-01-11 11:52:05 +0000210 static StringRef name() { return "NoOpModulePass"; }
Chandler Carruth66445382014-01-11 08:16:35 +0000211};
212
Chandler Carruth0b576b32015-01-06 02:50:06 +0000213/// \brief No-op module analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000214class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
215 friend AnalysisInfoMixin<NoOpModuleAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000216 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000217
218public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000219 struct Result {};
Sean Silvafd03ac62016-08-09 00:28:38 +0000220 Result run(Module &, ModuleAnalysisManager &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000221 static StringRef name() { return "NoOpModuleAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000222};
223
Chandler Carruth572e3402014-04-21 11:12:00 +0000224/// \brief No-op CGSCC pass which does nothing.
225struct NoOpCGSCCPass {
Chandler Carruth88823462016-08-24 09:37:14 +0000226 PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &,
227 LazyCallGraph &, CGSCCUpdateResult &UR) {
Chandler Carruth572e3402014-04-21 11:12:00 +0000228 return PreservedAnalyses::all();
229 }
230 static StringRef name() { return "NoOpCGSCCPass"; }
231};
232
Chandler Carruth0b576b32015-01-06 02:50:06 +0000233/// \brief No-op CGSCC analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000234class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
235 friend AnalysisInfoMixin<NoOpCGSCCAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000236 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000237
238public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000239 struct Result {};
Chandler Carruth88823462016-08-24 09:37:14 +0000240 Result run(LazyCallGraph::SCC &, CGSCCAnalysisManager &, LazyCallGraph &G) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000241 return Result();
242 }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000243 static StringRef name() { return "NoOpCGSCCAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000244};
245
Chandler Carruthd8330982014-01-12 09:34:22 +0000246/// \brief No-op function pass which does nothing.
247struct NoOpFunctionPass {
Sean Silva36e0d012016-08-09 00:28:15 +0000248 PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000249 return PreservedAnalyses::all();
250 }
Chandler Carruthd8330982014-01-12 09:34:22 +0000251 static StringRef name() { return "NoOpFunctionPass"; }
252};
253
Chandler Carruth0b576b32015-01-06 02:50:06 +0000254/// \brief No-op function analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000255class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
256 friend AnalysisInfoMixin<NoOpFunctionAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000257 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000258
259public:
Chandler Carruth0b576b32015-01-06 02:50:06 +0000260 struct Result {};
Sean Silva36e0d012016-08-09 00:28:15 +0000261 Result run(Function &, FunctionAnalysisManager &) { return Result(); }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000262 static StringRef name() { return "NoOpFunctionAnalysis"; }
Chandler Carruth0b576b32015-01-06 02:50:06 +0000263};
264
Justin Bognereecc3c82016-02-25 07:23:08 +0000265/// \brief No-op loop pass which does nothing.
266struct NoOpLoopPass {
Chandler Carruth410eaeb2017-01-11 06:23:21 +0000267 PreservedAnalyses run(Loop &L, LoopAnalysisManager &,
268 LoopStandardAnalysisResults &, LPMUpdater &) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000269 return PreservedAnalyses::all();
270 }
Justin Bognereecc3c82016-02-25 07:23:08 +0000271 static StringRef name() { return "NoOpLoopPass"; }
272};
273
274/// \brief No-op loop analysis.
Chandler Carruth30a07302016-03-11 10:33:22 +0000275class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
276 friend AnalysisInfoMixin<NoOpLoopAnalysis>;
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000277 static AnalysisKey Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000278
279public:
Justin Bognereecc3c82016-02-25 07:23:08 +0000280 struct Result {};
Chandler Carruth410eaeb2017-01-11 06:23:21 +0000281 Result run(Loop &, LoopAnalysisManager &, LoopStandardAnalysisResults &) {
282 return Result();
283 }
Justin Bognereecc3c82016-02-25 07:23:08 +0000284 static StringRef name() { return "NoOpLoopAnalysis"; }
Justin Bognereecc3c82016-02-25 07:23:08 +0000285};
286
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000287AnalysisKey NoOpModuleAnalysis::Key;
288AnalysisKey NoOpCGSCCAnalysis::Key;
289AnalysisKey NoOpFunctionAnalysis::Key;
290AnalysisKey NoOpLoopAnalysis::Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000291
Chandler Carruth66445382014-01-11 08:16:35 +0000292} // End anonymous namespace.
293
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000294void PassBuilder::invokePeepholeEPCallbacks(
295 FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
296 for (auto &C : PeepholeEPCallbacks)
297 C(FPM, Level);
298}
299
Chandler Carruth1ff77242015-03-07 09:02:36 +0000300void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000301#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000302 MAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000303#include "PassRegistry.def"
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000304
305 for (auto &C : ModuleAnalysisRegistrationCallbacks)
306 C(MAM);
Chandler Carruthb70f6732015-01-06 02:21:37 +0000307}
308
Chandler Carruth1ff77242015-03-07 09:02:36 +0000309void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000310#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000311 CGAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000312#include "PassRegistry.def"
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000313
314 for (auto &C : CGSCCAnalysisRegistrationCallbacks)
315 C(CGAM);
Chandler Carruthb70f6732015-01-06 02:21:37 +0000316}
317
Chandler Carruth1ff77242015-03-07 09:02:36 +0000318void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000319#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruthedf59962016-02-18 09:45:17 +0000320 FAM.registerPass([&] { return CREATE_PASS; });
Chandler Carruthb70f6732015-01-06 02:21:37 +0000321#include "PassRegistry.def"
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000322
323 for (auto &C : FunctionAnalysisRegistrationCallbacks)
324 C(FAM);
Chandler Carruthb70f6732015-01-06 02:21:37 +0000325}
326
Justin Bognereecc3c82016-02-25 07:23:08 +0000327void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) {
Chandler Carruth74a8a222016-06-17 07:15:29 +0000328#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
Justin Bognereecc3c82016-02-25 07:23:08 +0000329 LAM.registerPass([&] { return CREATE_PASS; });
330#include "PassRegistry.def"
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000331
332 for (auto &C : LoopAnalysisRegistrationCallbacks)
333 C(LAM);
Justin Bognereecc3c82016-02-25 07:23:08 +0000334}
335
Chandler Carruthe3f50642016-12-22 06:59:15 +0000336FunctionPassManager
337PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
Dehao Chen95f00302017-07-30 04:55:39 +0000338 ThinLTOPhase Phase,
339 bool DebugLogging) {
Chandler Carruthe3f50642016-12-22 06:59:15 +0000340 assert(Level != O0 && "Must request optimizations!");
341 FunctionPassManager FPM(DebugLogging);
342
343 // Form SSA out of local memory accesses after breaking apart aggregates into
344 // scalars.
345 FPM.addPass(SROA());
346
347 // Catch trivial redundancies
Geoff Berry3cca1da2017-06-10 15:20:03 +0000348 FPM.addPass(EarlyCSEPass(EnableEarlyCSEMemSSA));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000349
Davide Italianoc3688312017-06-01 23:08:14 +0000350 // Hoisting of scalars and load expressions.
351 if (EnableGVNHoist)
352 FPM.addPass(GVNHoistPass());
353
Davide Italianobe1b6a92017-06-03 23:18:29 +0000354 // Global value numbering based sinking.
355 if (EnableGVNSink) {
356 FPM.addPass(GVNSinkPass());
357 FPM.addPass(SimplifyCFGPass());
358 }
359
Chandler Carruthe3f50642016-12-22 06:59:15 +0000360 // Speculative execution if the target has divergent branches; otherwise nop.
361 FPM.addPass(SpeculativeExecutionPass());
362
363 // Optimize based on known information about branches, and cleanup afterward.
364 FPM.addPass(JumpThreadingPass());
365 FPM.addPass(CorrelatedValuePropagationPass());
366 FPM.addPass(SimplifyCFGPass());
Amjad Aboudf1f57a32018-01-25 12:06:32 +0000367 if (Level == O3)
368 FPM.addPass(AggressiveInstCombinePass());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000369 FPM.addPass(InstCombinePass());
370
371 if (!isOptimizingForSize(Level))
372 FPM.addPass(LibCallsShrinkWrapPass());
373
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000374 invokePeepholeEPCallbacks(FPM, Level);
375
Rong Xue1f42452017-10-23 22:21:29 +0000376 // For PGO use pipeline, try to optimize memory intrinsics such as memcpy
377 // using the size value profile. Don't perform this when optimizing for size.
378 if (PGOOpt && !PGOOpt->ProfileUseFile.empty() &&
379 !isOptimizingForSize(Level))
380 FPM.addPass(PGOMemOPSizeOpt());
381
Chandler Carruthe3f50642016-12-22 06:59:15 +0000382 FPM.addPass(TailCallElimPass());
383 FPM.addPass(SimplifyCFGPass());
384
385 // Form canonically associated expression trees, and simplify the trees using
386 // basic mathematical properties. For example, this will form (nearly)
387 // minimal multiplication trees.
388 FPM.addPass(ReassociatePass());
389
390 // Add the primary loop simplification pipeline.
391 // FIXME: Currently this is split into two loop pass pipelines because we run
392 // some function passes in between them. These can and should be replaced by
393 // loop pass equivalenst but those aren't ready yet. Specifically,
Vedant Kumar3a408532018-03-12 20:49:42 +0000394 // `SimplifyCFGPass` and `InstCombinePass` are used. We just have
395 // `LoopSimplifyCFGPass` which isn't yet powerful enough.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000396 LoopPassManager LPM1(DebugLogging), LPM2(DebugLogging);
397
398 // Rotate Loop - disable header duplication at -Oz
399 LPM1.addPass(LoopRotatePass(Level != Oz));
400 LPM1.addPass(LICMPass());
Chandler Carruth86248d52017-05-26 01:24:11 +0000401 LPM1.addPass(SimpleLoopUnswitchPass());
Chandler Carruth79b733b2017-01-26 23:21:17 +0000402 LPM2.addPass(IndVarSimplifyPass());
403 LPM2.addPass(LoopIdiomRecognizePass());
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000404
405 for (auto &C : LateLoopOptimizationsEPCallbacks)
406 C(LPM2, Level);
407
Chandler Carruth79b733b2017-01-26 23:21:17 +0000408 LPM2.addPass(LoopDeletionPass());
Dehao Chen95f00302017-07-30 04:55:39 +0000409 // Do not enable unrolling in PreLinkThinLTO phase during sample PGO
Dehao Chen3a9861422017-07-07 20:53:10 +0000410 // because it changes IR to makes profile annotation in back compile
411 // inaccurate.
Dehao Chen95f00302017-07-30 04:55:39 +0000412 if (Phase != ThinLTOPhase::PreLink ||
413 !PGOOpt || PGOOpt->SampleProfileFile.empty())
Teresa Johnsonecd90132017-08-02 20:35:29 +0000414 LPM2.addPass(LoopFullUnrollPass(Level));
Chandler Carruth79b733b2017-01-26 23:21:17 +0000415
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000416 for (auto &C : LoopOptimizerEndEPCallbacks)
417 C(LPM2, Level);
418
Chandler Carruth0ede22e2017-02-09 23:54:57 +0000419 // We provide the opt remark emitter pass for LICM to use. We only need to do
420 // this once as it is immutable.
421 FPM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
Fedor Sergeev02e7f022017-12-29 08:16:06 +0000422 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM1), DebugLogging));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000423 FPM.addPass(SimplifyCFGPass());
424 FPM.addPass(InstCombinePass());
Fedor Sergeev02e7f022017-12-29 08:16:06 +0000425 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2), DebugLogging));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000426
427 // Eliminate redundancies.
428 if (Level != O1) {
429 // These passes add substantial compile time so skip them at O1.
430 FPM.addPass(MergedLoadStoreMotionPass());
Davide Italiano8a09b8e2017-05-22 23:41:40 +0000431 if (RunNewGVN)
432 FPM.addPass(NewGVNPass());
433 else
434 FPM.addPass(GVN());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000435 }
436
437 // Specially optimize memory movement as it doesn't look like dataflow in SSA.
438 FPM.addPass(MemCpyOptPass());
439
440 // Sparse conditional constant propagation.
441 // FIXME: It isn't clear why we do this *after* loop passes rather than
442 // before...
443 FPM.addPass(SCCPPass());
444
445 // Delete dead bit computations (instcombine runs after to fold away the dead
446 // computations, and then ADCE will run later to exploit any new DCE
447 // opportunities that creates).
448 FPM.addPass(BDCEPass());
449
450 // Run instcombine after redundancy and dead bit elimination to exploit
451 // opportunities opened up by them.
452 FPM.addPass(InstCombinePass());
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000453 invokePeepholeEPCallbacks(FPM, Level);
Chandler Carruthe3f50642016-12-22 06:59:15 +0000454
455 // Re-consider control flow based optimizations after redundancy elimination,
456 // redo DCE, etc.
457 FPM.addPass(JumpThreadingPass());
458 FPM.addPass(CorrelatedValuePropagationPass());
459 FPM.addPass(DSEPass());
Fedor Sergeev02e7f022017-12-29 08:16:06 +0000460 FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass(), DebugLogging));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000461
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000462 for (auto &C : ScalarOptimizerLateEPCallbacks)
463 C(FPM, Level);
464
Chandler Carruthe3f50642016-12-22 06:59:15 +0000465 // Finally, do an expensive DCE pass to catch all the dead code exposed by
466 // the simplifications and basic cleanup after all the simplifications.
467 FPM.addPass(ADCEPass());
468 FPM.addPass(SimplifyCFGPass());
469 FPM.addPass(InstCombinePass());
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000470 invokePeepholeEPCallbacks(FPM, Level);
Chandler Carruthe3f50642016-12-22 06:59:15 +0000471
472 return FPM;
473}
474
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000475void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
476 PassBuilder::OptimizationLevel Level,
477 bool RunProfileGen,
478 std::string ProfileGenFile,
479 std::string ProfileUseFile) {
Davide Italiano513dfaa2017-02-13 15:26:22 +0000480 // Generally running simplification passes and the inliner with an high
481 // threshold results in smaller executables, but there may be cases where
482 // the size grows, so let's be conservative here and skip this simplification
483 // at -Os/Oz.
484 if (!isOptimizingForSize(Level)) {
485 InlineParams IP;
486
487 // In the old pass manager, this is a cl::opt. Should still this be one?
488 IP.DefaultThreshold = 75;
489
490 // FIXME: The hint threshold has the same value used by the regular inliner.
491 // This should probably be lowered after performance testing.
492 // FIXME: this comment is cargo culted from the old pass manager, revisit).
493 IP.HintThreshold = 325;
494
495 CGSCCPassManager CGPipeline(DebugLogging);
496
497 CGPipeline.addPass(InlinerPass(IP));
498
499 FunctionPassManager FPM;
500 FPM.addPass(SROA());
501 FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies.
502 FPM.addPass(SimplifyCFGPass()); // Merge & remove basic blocks.
503 FPM.addPass(InstCombinePass()); // Combine silly sequences.
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000504 invokePeepholeEPCallbacks(FPM, Level);
Davide Italiano513dfaa2017-02-13 15:26:22 +0000505
Davide Italiano513dfaa2017-02-13 15:26:22 +0000506 CGPipeline.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
507
508 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPipeline)));
509 }
510
Chandler Carruthf4d62c42017-05-25 07:15:09 +0000511 // Delete anything that is now dead to make sure that we don't instrument
512 // dead code. Instrumentation can end up keeping dead code around and
513 // dramatically increase code size.
514 MPM.addPass(GlobalDCEPass());
515
Davide Italiano513dfaa2017-02-13 15:26:22 +0000516 if (RunProfileGen) {
517 MPM.addPass(PGOInstrumentationGen());
518
Xinliang David Lib67530e2017-06-25 00:26:43 +0000519 FunctionPassManager FPM;
Fedor Sergeev02e7f022017-12-29 08:16:06 +0000520 FPM.addPass(
521 createFunctionToLoopPassAdaptor(LoopRotatePass(), DebugLogging));
Xinliang David Lib67530e2017-06-25 00:26:43 +0000522 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
523
Davide Italiano513dfaa2017-02-13 15:26:22 +0000524 // Add the profile lowering pass.
525 InstrProfOptions Options;
526 if (!ProfileGenFile.empty())
527 Options.InstrProfileOutput = ProfileGenFile;
Xinliang David Lib67530e2017-06-25 00:26:43 +0000528 Options.DoCounterPromotion = true;
Davide Italiano513dfaa2017-02-13 15:26:22 +0000529 MPM.addPass(InstrProfiling(Options));
530 }
531
532 if (!ProfileUseFile.empty())
533 MPM.addPass(PGOInstrumentationUse(ProfileUseFile));
534}
535
Easwaran Raman8249fac2017-06-28 13:33:49 +0000536static InlineParams
537getInlineParamsFromOptLevel(PassBuilder::OptimizationLevel Level) {
538 auto O3 = PassBuilder::O3;
539 unsigned OptLevel = Level > O3 ? 2 : Level;
540 unsigned SizeLevel = Level > O3 ? Level - O3 : 0;
541 return getInlineParams(OptLevel, SizeLevel);
542}
543
Chandler Carruthe3f50642016-12-22 06:59:15 +0000544ModulePassManager
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000545PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
Dehao Chen95f00302017-07-30 04:55:39 +0000546 ThinLTOPhase Phase,
547 bool DebugLogging) {
Chandler Carruthe3f50642016-12-22 06:59:15 +0000548 ModulePassManager MPM(DebugLogging);
549
Chandler Carruthe3f50642016-12-22 06:59:15 +0000550 // Do basic inference of function attributes from known properties of system
551 // libraries and other oracles.
552 MPM.addPass(InferFunctionAttrsPass());
553
554 // Create an early function pass manager to cleanup the output of the
555 // frontend.
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000556 FunctionPassManager EarlyFPM(DebugLogging);
557 EarlyFPM.addPass(SimplifyCFGPass());
558 EarlyFPM.addPass(SROA());
559 EarlyFPM.addPass(EarlyCSEPass());
560 EarlyFPM.addPass(LowerExpectIntrinsicPass());
Jun Bum Lim0c990072017-11-03 20:41:16 +0000561 if (Level == O3)
562 EarlyFPM.addPass(CallSiteSplittingPass());
563
Dehao Chen08f88312017-08-07 20:23:20 +0000564 // In SamplePGO ThinLTO backend, we need instcombine before profile annotation
565 // to convert bitcast to direct calls so that they can be inlined during the
566 // profile annotation prepration step.
567 // More details about SamplePGO design can be found in:
568 // https://research.google.com/pubs/pub45290.html
569 // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured.
570 if (PGOOpt && !PGOOpt->SampleProfileFile.empty() &&
571 Phase == ThinLTOPhase::PostLink)
572 EarlyFPM.addPass(InstCombinePass());
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000573 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000574
Dehao Chen08f88312017-08-07 20:23:20 +0000575 if (PGOOpt && !PGOOpt->SampleProfileFile.empty()) {
576 // Annotate sample profile right after early FPM to ensure freshness of
577 // the debug info.
Dehao Chend26dae02017-10-01 05:24:51 +0000578 MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile,
579 Phase == ThinLTOPhase::PreLink));
Dehao Chen08f88312017-08-07 20:23:20 +0000580 // Do not invoke ICP in the ThinLTOPrelink phase as it makes it hard
581 // for the profile annotation to be accurate in the ThinLTO backend.
582 if (Phase != ThinLTOPhase::PreLink)
583 // We perform early indirect call promotion here, before globalopt.
584 // This is important for the ThinLTO backend phase because otherwise
585 // imported available_externally functions look unreferenced and are
586 // removed.
587 MPM.addPass(PGOIndirectCallPromotion(Phase == ThinLTOPhase::PostLink,
588 true));
589 }
590
Malcolm Parsons21e545d2018-01-24 10:33:39 +0000591 // Interprocedural constant propagation now that basic cleanup has occurred
Chandler Carruthe3f50642016-12-22 06:59:15 +0000592 // and prior to optimizing globals.
593 // FIXME: This position in the pipeline hasn't been carefully considered in
594 // years, it should be re-analyzed.
595 MPM.addPass(IPSCCPPass());
596
Matthew Simpsoncb585582017-10-25 13:40:08 +0000597 // Attach metadata to indirect call sites indicating the set of functions
598 // they may target at run-time. This should follow IPSCCP.
599 MPM.addPass(CalledValuePropagationPass());
600
Chandler Carruthe3f50642016-12-22 06:59:15 +0000601 // Optimize globals to try and fold them into constants.
602 MPM.addPass(GlobalOptPass());
603
604 // Promote any localized globals to SSA registers.
605 // FIXME: Should this instead by a run of SROA?
606 // FIXME: We should probably run instcombine and simplify-cfg afterward to
607 // delete control flows that are dead once globals have been folded to
608 // constants.
609 MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
610
611 // Remove any dead arguments exposed by cleanups and constand folding
612 // globals.
613 MPM.addPass(DeadArgumentEliminationPass());
614
615 // Create a small function pass pipeline to cleanup after all the global
616 // optimizations.
617 FunctionPassManager GlobalCleanupPM(DebugLogging);
618 GlobalCleanupPM.addPass(InstCombinePass());
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000619 invokePeepholeEPCallbacks(GlobalCleanupPM, Level);
620
Chandler Carruthe3f50642016-12-22 06:59:15 +0000621 GlobalCleanupPM.addPass(SimplifyCFGPass());
622 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
623
Dehao Chen89d32262017-08-02 01:28:31 +0000624 // Add all the requested passes for instrumentation PGO, if requested.
625 if (PGOOpt && Phase != ThinLTOPhase::PostLink &&
626 (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())) {
627 addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
628 PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
629 MPM.addPass(PGOIndirectCallPromotion(false, false));
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000630 }
Davide Italiano513dfaa2017-02-13 15:26:22 +0000631
Easwaran Ramanbdf20262018-01-09 19:39:35 +0000632 // Synthesize function entry counts for non-PGO compilation.
633 if (EnableSyntheticCounts && !PGOOpt)
634 MPM.addPass(SyntheticCountsPropagation());
635
Chandler Carruthe87fc8c2017-02-12 05:34:04 +0000636 // Require the GlobalsAA analysis for the module so we can query it within
637 // the CGSCC pipeline.
638 MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000639
Easwaran Raman5e6f9bd2017-05-04 16:58:45 +0000640 // Require the ProfileSummaryAnalysis for the module so we can query it within
641 // the inliner pass.
642 MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
643
Chandler Carruthe3f50642016-12-22 06:59:15 +0000644 // Now begin the main postorder CGSCC pipeline.
645 // FIXME: The current CGSCC pipeline has its origins in the legacy pass
646 // manager and trying to emulate its precise behavior. Much of this doesn't
647 // make a lot of sense and we should revisit the core CGSCC structure.
648 CGSCCPassManager MainCGPipeline(DebugLogging);
649
650 // Note: historically, the PruneEH pass was run first to deduce nounwind and
651 // generally clean up exception handling overhead. It isn't clear this is
652 // valuable as the inliner doesn't currently care whether it is inlining an
653 // invoke or a call.
654
655 // Run the inliner first. The theory is that we are walking bottom-up and so
656 // the callees have already been fully optimized, and we want to inline them
657 // into the callers so that our optimizations can reflect that.
Dehao Chen95f00302017-07-30 04:55:39 +0000658 // For PreLinkThinLTO pass, we disable hot-caller heuristic for sample PGO
Dehao Chen3a9861422017-07-07 20:53:10 +0000659 // because it makes profile annotation in the backend inaccurate.
660 InlineParams IP = getInlineParamsFromOptLevel(Level);
Dehao Chen95f00302017-07-30 04:55:39 +0000661 if (Phase == ThinLTOPhase::PreLink &&
662 PGOOpt && !PGOOpt->SampleProfileFile.empty())
Dehao Chen3a9861422017-07-07 20:53:10 +0000663 IP.HotCallSiteThreshold = 0;
664 MainCGPipeline.addPass(InlinerPass(IP));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000665
666 // Now deduce any function attributes based in the current code.
667 MainCGPipeline.addPass(PostOrderFunctionAttrsPass());
668
Chandler Carruth0ede22e2017-02-09 23:54:57 +0000669 // When at O3 add argument promotion to the pass pipeline.
670 // FIXME: It isn't at all clear why this should be limited to O3.
671 if (Level == O3)
672 MainCGPipeline.addPass(ArgumentPromotionPass());
673
Chandler Carruthe3f50642016-12-22 06:59:15 +0000674 // Lastly, add the core function simplification pipeline nested inside the
675 // CGSCC walk.
676 MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
Dehao Chen95f00302017-07-30 04:55:39 +0000677 buildFunctionSimplificationPipeline(Level, Phase, DebugLogging)));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000678
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000679 for (auto &C : CGSCCOptimizerLateEPCallbacks)
680 C(MainCGPipeline, Level);
681
Chandler Carruth719ffe12017-02-12 05:38:04 +0000682 // We wrap the CGSCC pipeline in a devirtualization repeater. This will try
683 // to detect when we devirtualize indirect calls and iterate the SCC passes
684 // in that case to try and catch knock-on inlining or function attrs
685 // opportunities. Then we add it to the module pipeline by walking the SCCs
686 // in postorder (or bottom-up).
Chandler Carruthe3f50642016-12-22 06:59:15 +0000687 MPM.addPass(
Chandler Carruth719ffe12017-02-12 05:38:04 +0000688 createModuleToPostOrderCGSCCPassAdaptor(createDevirtSCCRepeatedPass(
Chandler Carruth19913b22017-08-11 05:47:13 +0000689 std::move(MainCGPipeline), MaxDevirtIterations)));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000690
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000691 return MPM;
692}
693
694ModulePassManager
695PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
696 bool DebugLogging) {
697 ModulePassManager MPM(DebugLogging);
698
699 // Optimize globals now that the module is fully simplified.
700 MPM.addPass(GlobalOptPass());
Davide Italianoe0707212017-10-05 18:36:01 +0000701 MPM.addPass(GlobalDCEPass());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000702
Xinliang David Li126157c2017-05-22 16:41:57 +0000703 // Run partial inlining pass to partially inline functions that have
704 // large bodies.
705 if (RunPartialInlining)
706 MPM.addPass(PartialInlinerPass());
707
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000708 // Remove avail extern fns and globals definitions since we aren't compiling
709 // an object file for later LTO. For LTO we want to preserve these so they
710 // are eligible for inlining at link-time. Note if they are unreferenced they
711 // will be removed by GlobalDCE later, so this only impacts referenced
712 // available externally globals. Eventually they will be suppressed during
713 // codegen, but eliminating here enables more opportunity for GlobalDCE as it
714 // may make globals referenced by available external functions dead and saves
715 // running remaining passes on the eliminated functions.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000716 MPM.addPass(EliminateAvailableExternallyPass());
717
718 // Do RPO function attribute inference across the module to forward-propagate
719 // attributes where applicable.
720 // FIXME: Is this really an optimization rather than a canonicalization?
721 MPM.addPass(ReversePostOrderFunctionAttrsPass());
722
Chandler Carruthe87fc8c2017-02-12 05:34:04 +0000723 // Re-require GloblasAA here prior to function passes. This is particularly
Chandler Carruthe3f50642016-12-22 06:59:15 +0000724 // useful as the above will have inlined, DCE'ed, and function-attr
725 // propagated everything. We should at this point have a reasonably minimal
726 // and richly annotated call graph. By computing aliasing and mod/ref
727 // information for all local globals here, the late loop passes and notably
728 // the vectorizer will be able to use them to help recognize vectorizable
729 // memory operations.
Chandler Carruthe87fc8c2017-02-12 05:34:04 +0000730 MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000731
732 FunctionPassManager OptimizePM(DebugLogging);
733 OptimizePM.addPass(Float2IntPass());
734 // FIXME: We need to run some loop optimizations to re-rotate loops after
735 // simplify-cfg and others undo their rotation.
736
737 // Optimize the loop execution. These passes operate on entire loop nests
738 // rather than on each loop in an inside-out manner, and so they are actually
739 // function passes.
Chandler Carrutha95ff382017-01-27 00:50:21 +0000740
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000741 for (auto &C : VectorizerStartEPCallbacks)
742 C(OptimizePM, Level);
743
Chandler Carrutha95ff382017-01-27 00:50:21 +0000744 // First rotate loops that may have been un-rotated by prior passes.
Fedor Sergeev02e7f022017-12-29 08:16:06 +0000745 OptimizePM.addPass(
746 createFunctionToLoopPassAdaptor(LoopRotatePass(), DebugLogging));
Chandler Carrutha95ff382017-01-27 00:50:21 +0000747
748 // Distribute loops to allow partial vectorization. I.e. isolate dependences
749 // into separate loop that would otherwise inhibit vectorization. This is
750 // currently only performed for loops marked with the metadata
751 // llvm.loop.distribute=true or when -enable-loop-distribute is specified.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000752 OptimizePM.addPass(LoopDistributePass());
Chandler Carrutha95ff382017-01-27 00:50:21 +0000753
754 // Now run the core loop vectorizer.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000755 OptimizePM.addPass(LoopVectorizePass());
Chandler Carrutha95ff382017-01-27 00:50:21 +0000756
Chandler Carruthbaabda92017-01-27 01:32:26 +0000757 // Eliminate loads by forwarding stores from the previous iteration to loads
758 // of the current iteration.
759 OptimizePM.addPass(LoopLoadEliminationPass());
Chandler Carrutha95ff382017-01-27 00:50:21 +0000760
761 // Cleanup after the loop optimization passes.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000762 OptimizePM.addPass(InstCombinePass());
763
Chandler Carrutha95ff382017-01-27 00:50:21 +0000764 // Now that we've formed fast to execute loop structures, we do further
765 // optimizations. These are run afterward as they might block doing complex
766 // analyses and transforms such as what are needed for loop vectorization.
767
Sanjay Patel0ab0c1a2017-12-14 22:05:20 +0000768 // Cleanup after loop vectorization, etc. Simplification passes like CVP and
769 // GVN, loop transforms, and others have already run, so it's now better to
770 // convert to more optimized IR using more aggressive simplify CFG options.
771 // The extra sinking transform can create larger basic blocks, so do this
772 // before SLP vectorization.
773 OptimizePM.addPass(SimplifyCFGPass(SimplifyCFGOptions().
774 forwardSwitchCondToPhi(true).
775 convertSwitchToLookupTable(true).
776 needCanonicalLoops(false).
777 sinkCommonInsts(true)));
778
Chandler Carruthe3f50642016-12-22 06:59:15 +0000779 // Optimize parallel scalar instruction chains into SIMD instructions.
780 OptimizePM.addPass(SLPVectorizerPass());
781
Chandler Carruthe3f50642016-12-22 06:59:15 +0000782 OptimizePM.addPass(InstCombinePass());
783
784 // Unroll small loops to hide loop backedge latency and saturate any parallel
Chandler Carrutha95ff382017-01-27 00:50:21 +0000785 // execution resources of an out-of-order processor. We also then need to
786 // clean up redundancies and loop invariant code.
787 // FIXME: It would be really good to use a loop-integrated instruction
788 // combiner for cleanup here so that the unrolling and LICM can be pipelined
789 // across the loop nests.
Teresa Johnsonecd90132017-08-02 20:35:29 +0000790 OptimizePM.addPass(LoopUnrollPass(Level));
Chandler Carrutha95ff382017-01-27 00:50:21 +0000791 OptimizePM.addPass(InstCombinePass());
Chandler Carruth0ede22e2017-02-09 23:54:57 +0000792 OptimizePM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
Fedor Sergeev02e7f022017-12-29 08:16:06 +0000793 OptimizePM.addPass(createFunctionToLoopPassAdaptor(LICMPass(), DebugLogging));
Chandler Carruthe3f50642016-12-22 06:59:15 +0000794
795 // Now that we've vectorized and unrolled loops, we may have more refined
796 // alignment information, try to re-derive it here.
797 OptimizePM.addPass(AlignmentFromAssumptionsPass());
798
Chandler Carrutha95ff382017-01-27 00:50:21 +0000799 // LoopSink pass sinks instructions hoisted by LICM, which serves as a
800 // canonicalization pass that enables other optimizations. As a result,
801 // LoopSink pass needs to be a very late IR pass to avoid undoing LICM
802 // result too early.
803 OptimizePM.addPass(LoopSinkPass());
804
805 // And finally clean up LCSSA form before generating code.
806 OptimizePM.addPass(InstSimplifierPass());
807
Sanjay Patel6fd43912017-09-09 13:38:18 +0000808 // This hoists/decomposes div/rem ops. It should run after other sink/hoist
809 // passes to avoid re-sinking, but before SimplifyCFG because it can allow
810 // flattening of blocks.
811 OptimizePM.addPass(DivRemPairsPass());
812
Filipe Cabecinhas92dc3482017-04-26 12:02:41 +0000813 // LoopSink (and other loop passes since the last simplifyCFG) might have
814 // resulted in single-entry-single-exit or empty blocks. Clean up the CFG.
815 OptimizePM.addPass(SimplifyCFGPass());
816
Chandler Carruthc34f7892017-11-28 11:32:31 +0000817 // Optimize PHIs by speculating around them when profitable. Note that this
818 // pass needs to be run after any PRE or similar pass as it is essentially
819 // inserting redudnancies into the progrem. This even includes SimplifyCFG.
820 OptimizePM.addPass(SpeculateAroundPHIsPass());
821
Chandler Carrutha95ff382017-01-27 00:50:21 +0000822 // Add the core optimizing pipeline.
Chandler Carruthe3f50642016-12-22 06:59:15 +0000823 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM)));
824
825 // Now we need to do some global optimization transforms.
826 // FIXME: It would seem like these should come first in the optimization
827 // pipeline and maybe be the bottom of the canonicalization pipeline? Weird
828 // ordering here.
829 MPM.addPass(GlobalDCEPass());
830 MPM.addPass(ConstantMergePass());
831
832 return MPM;
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000833}
834
Chandler Carruthe3f50642016-12-22 06:59:15 +0000835ModulePassManager
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000836PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
837 bool DebugLogging) {
838 assert(Level != O0 && "Must request optimizations for the default pipeline!");
839
840 ModulePassManager MPM(DebugLogging);
841
842 // Force any function attributes we want the rest of the pipeline to observe.
843 MPM.addPass(ForceFunctionAttrsPass());
844
David Blaikie0c64f5a2018-01-23 01:25:20 +0000845 // Apply module pipeline start EP callback.
846 for (auto &C : PipelineStartEPCallbacks)
847 C(MPM);
848
Dehao Chen08f88312017-08-07 20:23:20 +0000849 if (PGOOpt && PGOOpt->SamplePGOSupport)
Dehao Chence0842c2017-07-29 04:10:24 +0000850 MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
851
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000852 // Add the core simplification pipeline.
Dehao Chen95f00302017-07-30 04:55:39 +0000853 MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::None,
854 DebugLogging));
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000855
856 // Now add the optimization pipeline.
857 MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
858
859 return MPM;
860}
861
862ModulePassManager
863PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level,
864 bool DebugLogging) {
865 assert(Level != O0 && "Must request optimizations for the default pipeline!");
866
867 ModulePassManager MPM(DebugLogging);
868
869 // Force any function attributes we want the rest of the pipeline to observe.
870 MPM.addPass(ForceFunctionAttrsPass());
871
Dehao Chen08f88312017-08-07 20:23:20 +0000872 if (PGOOpt && PGOOpt->SamplePGOSupport)
Dehao Chence0842c2017-07-29 04:10:24 +0000873 MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
874
David Blaikie0c64f5a2018-01-23 01:25:20 +0000875 // Apply module pipeline start EP callback.
876 for (auto &C : PipelineStartEPCallbacks)
877 C(MPM);
878
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000879 // If we are planning to perform ThinLTO later, we don't bloat the code with
880 // unrolling/vectorization/... now. Just simplify the module as much as we
881 // can.
Dehao Chen95f00302017-07-30 04:55:39 +0000882 MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PreLink,
883 DebugLogging));
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000884
885 // Run partial inlining pass to partially inline functions that have
886 // large bodies.
887 // FIXME: It isn't clear whether this is really the right place to run this
888 // in ThinLTO. Because there is another canonicalization and simplification
889 // phase that will run after the thin link, running this here ends up with
890 // less information than will be available later and it may grow functions in
891 // ways that aren't beneficial.
892 if (RunPartialInlining)
893 MPM.addPass(PartialInlinerPass());
894
895 // Reduce the size of the IR as much as possible.
896 MPM.addPass(GlobalOptPass());
897
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000898 return MPM;
899}
900
901ModulePassManager
902PassBuilder::buildThinLTODefaultPipeline(OptimizationLevel Level,
903 bool DebugLogging) {
904 // FIXME: The summary index is not hooked in the new pass manager yet.
905 // When it's going to be hooked, enable WholeProgramDevirt and LowerTypeTest
906 // here.
907
908 ModulePassManager MPM(DebugLogging);
909
910 // Force any function attributes we want the rest of the pipeline to observe.
911 MPM.addPass(ForceFunctionAttrsPass());
912
913 // During the ThinLTO backend phase we perform early indirect call promotion
914 // here, before globalopt. Otherwise imported available_externally functions
915 // look unreferenced and are removed.
Dehao Chen08f88312017-08-07 20:23:20 +0000916 // FIXME: move this into buildModuleSimplificationPipeline to merge the logic
917 // with SamplePGO.
Dehao Chen2f4e2e22017-08-10 05:10:32 +0000918 if (!PGOOpt || PGOOpt->SampleProfileFile.empty())
Dehao Chen08f88312017-08-07 20:23:20 +0000919 MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
920 false /* SamplePGO */));
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000921
922 // Add the core simplification pipeline.
Dehao Chen95f00302017-07-30 04:55:39 +0000923 MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink,
924 DebugLogging));
Chandler Carruth8b3be4e2017-06-01 11:39:39 +0000925
926 // Now add the optimization pipeline.
927 MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
928
929 return MPM;
930}
931
932ModulePassManager
Chandler Carruthe3f50642016-12-22 06:59:15 +0000933PassBuilder::buildLTOPreLinkDefaultPipeline(OptimizationLevel Level,
934 bool DebugLogging) {
935 assert(Level != O0 && "Must request optimizations for the default pipeline!");
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000936 // FIXME: We should use a customized pre-link pipeline!
Chandler Carruthe3f50642016-12-22 06:59:15 +0000937 return buildPerModuleDefaultPipeline(Level, DebugLogging);
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000938}
939
Chandler Carruthe3f50642016-12-22 06:59:15 +0000940ModulePassManager PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
941 bool DebugLogging) {
942 assert(Level != O0 && "Must request optimizations for the default pipeline!");
943 ModulePassManager MPM(DebugLogging);
944
Davide Italiano089a9122017-01-24 00:57:39 +0000945 // Remove unused virtual tables to improve the quality of code generated by
946 // whole-program devirtualization and bitset lowering.
947 MPM.addPass(GlobalDCEPass());
Chandler Carruth8b5a74192016-02-28 22:16:03 +0000948
Davide Italiano089a9122017-01-24 00:57:39 +0000949 // Force any function attributes we want the rest of the pipeline to observe.
950 MPM.addPass(ForceFunctionAttrsPass());
Chandler Carruthe3f50642016-12-22 06:59:15 +0000951
Davide Italiano089a9122017-01-24 00:57:39 +0000952 // Do basic inference of function attributes from known properties of system
953 // libraries and other oracles.
954 MPM.addPass(InferFunctionAttrsPass());
955
956 if (Level > 1) {
Jun Bum Lim0c990072017-11-03 20:41:16 +0000957 FunctionPassManager EarlyFPM(DebugLogging);
958 EarlyFPM.addPass(CallSiteSplittingPass());
959 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
960
Davide Italiano089a9122017-01-24 00:57:39 +0000961 // Indirect call promotion. This should promote all the targets that are
962 // left by the earlier promotion pass that promotes intra-module targets.
963 // This two-step promotion is to save the compile time. For LTO, it should
964 // produce the same result as if we only do promotion here.
Dehao Chen2f31d0d2017-06-29 23:33:05 +0000965 MPM.addPass(PGOIndirectCallPromotion(
966 true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
Davide Italiano089a9122017-01-24 00:57:39 +0000967 // Propagate constants at call sites into the functions they call. This
968 // opens opportunities for globalopt (and inlining) by substituting function
969 // pointers passed as arguments to direct uses of functions.
970 MPM.addPass(IPSCCPPass());
Matthew Simpsoncb585582017-10-25 13:40:08 +0000971
972 // Attach metadata to indirect call sites indicating the set of functions
973 // they may target at run-time. This should follow IPSCCP.
974 MPM.addPass(CalledValuePropagationPass());
Davide Italiano089a9122017-01-24 00:57:39 +0000975 }
976
977 // Now deduce any function attributes based in the current code.
978 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
979 PostOrderFunctionAttrsPass()));
980
981 // Do RPO function attribute inference across the module to forward-propagate
982 // attributes where applicable.
983 // FIXME: Is this really an optimization rather than a canonicalization?
984 MPM.addPass(ReversePostOrderFunctionAttrsPass());
985
986 // Use inragne annotations on GEP indices to split globals where beneficial.
987 MPM.addPass(GlobalSplitPass());
988
989 // Run whole program optimization of virtual call when the list of callees
990 // is fixed.
991 MPM.addPass(WholeProgramDevirtPass());
992
993 // Stop here at -O1.
994 if (Level == 1)
995 return MPM;
996
997 // Optimize globals to try and fold them into constants.
998 MPM.addPass(GlobalOptPass());
999
1000 // Promote any localized globals to SSA registers.
1001 MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
1002
1003 // Linking modules together can lead to duplicate global constant, only
1004 // keep one copy of each constant.
1005 MPM.addPass(ConstantMergePass());
1006
1007 // Remove unused arguments from functions.
1008 MPM.addPass(DeadArgumentEliminationPass());
1009
1010 // Reduce the code after globalopt and ipsccp. Both can open up significant
1011 // simplification opportunities, and both can propagate functions through
1012 // function pointers. When this happens, we often have to resolve varargs
1013 // calls, etc, so let instcombine do this.
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001014 FunctionPassManager PeepholeFPM(DebugLogging);
Amjad Aboudf1f57a32018-01-25 12:06:32 +00001015 if (Level == O3)
1016 PeepholeFPM.addPass(AggressiveInstCombinePass());
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001017 PeepholeFPM.addPass(InstCombinePass());
1018 invokePeepholeEPCallbacks(PeepholeFPM, Level);
1019
1020 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(PeepholeFPM)));
Davide Italiano089a9122017-01-24 00:57:39 +00001021
1022 // Note: historically, the PruneEH pass was run first to deduce nounwind and
1023 // generally clean up exception handling overhead. It isn't clear this is
1024 // valuable as the inliner doesn't currently care whether it is inlining an
1025 // invoke or a call.
1026 // Run the inliner now.
Easwaran Raman8249fac2017-06-28 13:33:49 +00001027 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
1028 InlinerPass(getInlineParamsFromOptLevel(Level))));
Davide Italiano089a9122017-01-24 00:57:39 +00001029
1030 // Optimize globals again after we ran the inliner.
1031 MPM.addPass(GlobalOptPass());
1032
1033 // Garbage collect dead functions.
1034 // FIXME: Add ArgumentPromotion pass after once it's ported.
1035 MPM.addPass(GlobalDCEPass());
1036
1037 FunctionPassManager FPM(DebugLogging);
Davide Italiano089a9122017-01-24 00:57:39 +00001038 // The IPO Passes may leave cruft around. Clean up after them.
Davide Italiano089a9122017-01-24 00:57:39 +00001039 FPM.addPass(InstCombinePass());
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001040 invokePeepholeEPCallbacks(FPM, Level);
1041
Davide Italiano089a9122017-01-24 00:57:39 +00001042 FPM.addPass(JumpThreadingPass());
1043
1044 // Break up allocas
1045 FPM.addPass(SROA());
1046
1047 // Run a few AA driver optimizations here and now to cleanup the code.
1048 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1049
1050 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
1051 PostOrderFunctionAttrsPass()));
1052 // FIXME: here we run IP alias analysis in the legacy PM.
1053
1054 FunctionPassManager MainFPM;
1055
1056 // FIXME: once we fix LoopPass Manager, add LICM here.
1057 // FIXME: once we provide support for enabling MLSM, add it here.
1058 // FIXME: once we provide support for enabling NewGVN, add it here.
Davide Italiano8a09b8e2017-05-22 23:41:40 +00001059 if (RunNewGVN)
1060 MainFPM.addPass(NewGVNPass());
1061 else
1062 MainFPM.addPass(GVN());
Davide Italiano089a9122017-01-24 00:57:39 +00001063
1064 // Remove dead memcpy()'s.
1065 MainFPM.addPass(MemCpyOptPass());
1066
1067 // Nuke dead stores.
1068 MainFPM.addPass(DSEPass());
1069
1070 // FIXME: at this point, we run a bunch of loop passes:
1071 // indVarSimplify, loopDeletion, loopInterchange, loopUnrool,
1072 // loopVectorize. Enable them once the remaining issue with LPM
1073 // are sorted out.
1074
1075 MainFPM.addPass(InstCombinePass());
1076 MainFPM.addPass(SimplifyCFGPass());
1077 MainFPM.addPass(SCCPPass());
1078 MainFPM.addPass(InstCombinePass());
1079 MainFPM.addPass(BDCEPass());
1080
1081 // FIXME: We may want to run SLPVectorizer here.
1082 // After vectorization, assume intrinsics may tell us more
1083 // about pointer alignments.
1084#if 0
1085 MainFPM.add(AlignmentFromAssumptionsPass());
1086#endif
1087
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001088 // FIXME: Conditionally run LoadCombine here, after it's ported
1089 // (in case we still have this pass, given its questionable usefulness).
1090
Davide Italiano089a9122017-01-24 00:57:39 +00001091 MainFPM.addPass(InstCombinePass());
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001092 invokePeepholeEPCallbacks(MainFPM, Level);
Davide Italiano089a9122017-01-24 00:57:39 +00001093 MainFPM.addPass(JumpThreadingPass());
1094 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(MainFPM)));
1095
1096 // Create a function that performs CFI checks for cross-DSO calls with
1097 // targets in the current module.
1098 MPM.addPass(CrossDSOCFIPass());
1099
1100 // Lower type metadata and the type.test intrinsic. This pass supports
1101 // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs
1102 // to be run at link time if CFI is enabled. This pass does nothing if
1103 // CFI is disabled.
1104 // Enable once we add support for the summary in the new PM.
1105#if 0
Peter Collingbourne857aba42017-02-09 21:45:01 +00001106 MPM.addPass(LowerTypeTestsPass(Summary ? PassSummaryAction::Export :
1107 PassSummaryAction::None,
Davide Italiano089a9122017-01-24 00:57:39 +00001108 Summary));
1109#endif
1110
1111 // Add late LTO optimization passes.
1112 // Delete basic blocks, which optimization passes may have killed.
1113 MPM.addPass(createModuleToFunctionPassAdaptor(SimplifyCFGPass()));
1114
1115 // Drop bodies of available eternally objects to improve GlobalDCE.
1116 MPM.addPass(EliminateAvailableExternallyPass());
1117
1118 // Now that we have optimized the program, discard unreachable functions.
1119 MPM.addPass(GlobalDCEPass());
1120
1121 // FIXME: Enable MergeFuncs, conditionally, after ported, maybe.
Chandler Carruthe3f50642016-12-22 06:59:15 +00001122 return MPM;
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001123}
1124
Chandler Carruth060ad612016-12-23 20:38:19 +00001125AAManager PassBuilder::buildDefaultAAPipeline() {
1126 AAManager AA;
1127
1128 // The order in which these are registered determines their priority when
1129 // being queried.
1130
1131 // First we register the basic alias analysis that provides the majority of
1132 // per-function local AA logic. This is a stateless, on-demand local set of
1133 // AA techniques.
1134 AA.registerFunctionAnalysis<BasicAA>();
1135
1136 // Next we query fast, specialized alias analyses that wrap IR-embedded
1137 // information about aliasing.
1138 AA.registerFunctionAnalysis<ScopedNoAliasAA>();
1139 AA.registerFunctionAnalysis<TypeBasedAA>();
1140
1141 // Add support for querying global aliasing information when available.
Chandler Carruth534d6442016-12-24 05:11:17 +00001142 // Because the `AAManager` is a function analysis and `GlobalsAA` is a module
1143 // analysis, all that the `AAManager` can do is query for any *cached*
Chandler Carruthe87fc8c2017-02-12 05:34:04 +00001144 // results from `GlobalsAA` through a readonly proxy.
Chandler Carruth060ad612016-12-23 20:38:19 +00001145 AA.registerModuleAnalysis<GlobalsAA>();
Chandler Carruth060ad612016-12-23 20:38:19 +00001146
1147 return AA;
1148}
1149
Chandler Carruth241bf242016-08-03 07:44:48 +00001150static Optional<int> parseRepeatPassName(StringRef Name) {
1151 if (!Name.consume_front("repeat<") || !Name.consume_back(">"))
1152 return None;
1153 int Count;
1154 if (Name.getAsInteger(0, Count) || Count <= 0)
1155 return None;
1156 return Count;
1157}
1158
Chandler Carruth05ca5ac2016-12-28 11:07:33 +00001159static Optional<int> parseDevirtPassName(StringRef Name) {
1160 if (!Name.consume_front("devirt<") || !Name.consume_back(">"))
1161 return None;
1162 int Count;
1163 if (Name.getAsInteger(0, Count) || Count <= 0)
1164 return None;
1165 return Count;
1166}
1167
Chandler Carruth8b3be4e2017-06-01 11:39:39 +00001168/// Tests whether a pass name starts with a valid prefix for a default pipeline
1169/// alias.
1170static bool startsWithDefaultPipelineAliasPrefix(StringRef Name) {
1171 return Name.startswith("default") || Name.startswith("thinlto") ||
1172 Name.startswith("lto");
1173}
1174
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001175/// Tests whether registered callbacks will accept a given pass name.
1176///
1177/// When parsing a pipeline text, the type of the outermost pipeline may be
1178/// omitted, in which case the type is automatically determined from the first
1179/// pass name in the text. This may be a name that is handled through one of the
1180/// callbacks. We check this through the oridinary parsing callbacks by setting
1181/// up a dummy PassManager in order to not force the client to also handle this
1182/// type of query.
1183template <typename PassManagerT, typename CallbacksT>
1184static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
1185 if (!Callbacks.empty()) {
1186 PassManagerT DummyPM;
1187 for (auto &CB : Callbacks)
1188 if (CB(Name, DummyPM, {}))
1189 return true;
1190 }
1191 return false;
1192}
1193
1194template <typename CallbacksT>
1195static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) {
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001196 // Manually handle aliases for pre-configured pipeline fragments.
Chandler Carruth8b3be4e2017-06-01 11:39:39 +00001197 if (startsWithDefaultPipelineAliasPrefix(Name))
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001198 return DefaultAliasRegex.match(Name);
1199
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001200 // Explicitly handle pass manager names.
1201 if (Name == "module")
1202 return true;
1203 if (Name == "cgscc")
1204 return true;
1205 if (Name == "function")
1206 return true;
1207
Chandler Carruth241bf242016-08-03 07:44:48 +00001208 // Explicitly handle custom-parsed pass names.
1209 if (parseRepeatPassName(Name))
1210 return true;
1211
Chandler Carruth74a8a222016-06-17 07:15:29 +00001212#define MODULE_PASS(NAME, CREATE_PASS) \
1213 if (Name == NAME) \
1214 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +00001215#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001216 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +00001217 return true;
1218#include "PassRegistry.def"
1219
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001220 return callbacksAcceptPassName<ModulePassManager>(Name, Callbacks);
Chandler Carruth66445382014-01-11 08:16:35 +00001221}
1222
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001223template <typename CallbacksT>
1224static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001225 // Explicitly handle pass manager names.
1226 if (Name == "cgscc")
1227 return true;
1228 if (Name == "function")
1229 return true;
1230
Chandler Carruth241bf242016-08-03 07:44:48 +00001231 // Explicitly handle custom-parsed pass names.
1232 if (parseRepeatPassName(Name))
1233 return true;
Chandler Carruth05ca5ac2016-12-28 11:07:33 +00001234 if (parseDevirtPassName(Name))
1235 return true;
Chandler Carruth241bf242016-08-03 07:44:48 +00001236
Chandler Carruth74a8a222016-06-17 07:15:29 +00001237#define CGSCC_PASS(NAME, CREATE_PASS) \
1238 if (Name == NAME) \
1239 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +00001240#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001241 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +00001242 return true;
1243#include "PassRegistry.def"
1244
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001245 return callbacksAcceptPassName<CGSCCPassManager>(Name, Callbacks);
Chandler Carruth572e3402014-04-21 11:12:00 +00001246}
1247
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001248template <typename CallbacksT>
1249static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001250 // Explicitly handle pass manager names.
1251 if (Name == "function")
1252 return true;
1253 if (Name == "loop")
1254 return true;
1255
Chandler Carruth241bf242016-08-03 07:44:48 +00001256 // Explicitly handle custom-parsed pass names.
1257 if (parseRepeatPassName(Name))
1258 return true;
1259
Chandler Carruth74a8a222016-06-17 07:15:29 +00001260#define FUNCTION_PASS(NAME, CREATE_PASS) \
1261 if (Name == NAME) \
1262 return true;
Chandler Carruth628503e2015-01-06 02:10:51 +00001263#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001264 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
Chandler Carruth628503e2015-01-06 02:10:51 +00001265 return true;
1266#include "PassRegistry.def"
1267
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001268 return callbacksAcceptPassName<FunctionPassManager>(Name, Callbacks);
Chandler Carruthd8330982014-01-12 09:34:22 +00001269}
1270
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001271template <typename CallbacksT>
1272static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001273 // Explicitly handle pass manager names.
1274 if (Name == "loop")
1275 return true;
1276
Chandler Carruth241bf242016-08-03 07:44:48 +00001277 // Explicitly handle custom-parsed pass names.
1278 if (parseRepeatPassName(Name))
1279 return true;
1280
Chandler Carruth74a8a222016-06-17 07:15:29 +00001281#define LOOP_PASS(NAME, CREATE_PASS) \
1282 if (Name == NAME) \
1283 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +00001284#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1285 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1286 return true;
1287#include "PassRegistry.def"
1288
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001289 return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
Justin Bognereecc3c82016-02-25 07:23:08 +00001290}
1291
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001292Optional<std::vector<PassBuilder::PipelineElement>>
1293PassBuilder::parsePipelineText(StringRef Text) {
1294 std::vector<PipelineElement> ResultPipeline;
1295
1296 SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
1297 &ResultPipeline};
1298 for (;;) {
1299 std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
1300 size_t Pos = Text.find_first_of(",()");
1301 Pipeline.push_back({Text.substr(0, Pos), {}});
1302
1303 // If we have a single terminating name, we're done.
1304 if (Pos == Text.npos)
1305 break;
1306
1307 char Sep = Text[Pos];
1308 Text = Text.substr(Pos + 1);
1309 if (Sep == ',')
1310 // Just a name ending in a comma, continue.
1311 continue;
1312
1313 if (Sep == '(') {
1314 // Push the inner pipeline onto the stack to continue processing.
1315 PipelineStack.push_back(&Pipeline.back().InnerPipeline);
1316 continue;
1317 }
1318
1319 assert(Sep == ')' && "Bogus separator!");
1320 // When handling the close parenthesis, we greedily consume them to avoid
1321 // empty strings in the pipeline.
1322 do {
1323 // If we try to pop the outer pipeline we have unbalanced parentheses.
1324 if (PipelineStack.size() == 1)
1325 return None;
1326
1327 PipelineStack.pop_back();
1328 } while (Text.consume_front(")"));
1329
1330 // Check if we've finished parsing.
1331 if (Text.empty())
1332 break;
1333
1334 // Otherwise, the end of an inner pipeline always has to be followed by
1335 // a comma, and then we can continue.
1336 if (!Text.consume_front(","))
1337 return None;
1338 }
1339
1340 if (PipelineStack.size() > 1)
1341 // Unbalanced paretheses.
1342 return None;
1343
1344 assert(PipelineStack.back() == &ResultPipeline &&
1345 "Wrong pipeline at the bottom of the stack!");
1346 return {std::move(ResultPipeline)};
1347}
1348
1349bool PassBuilder::parseModulePass(ModulePassManager &MPM,
1350 const PipelineElement &E, bool VerifyEachPass,
1351 bool DebugLogging) {
1352 auto &Name = E.Name;
1353 auto &InnerPipeline = E.InnerPipeline;
1354
1355 // First handle complex passes like the pass managers which carry pipelines.
1356 if (!InnerPipeline.empty()) {
1357 if (Name == "module") {
1358 ModulePassManager NestedMPM(DebugLogging);
1359 if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
1360 DebugLogging))
1361 return false;
1362 MPM.addPass(std::move(NestedMPM));
1363 return true;
1364 }
1365 if (Name == "cgscc") {
1366 CGSCCPassManager CGPM(DebugLogging);
1367 if (!parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass,
1368 DebugLogging))
1369 return false;
Chandler Carruth19913b22017-08-11 05:47:13 +00001370 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001371 return true;
1372 }
1373 if (Name == "function") {
1374 FunctionPassManager FPM(DebugLogging);
1375 if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
1376 DebugLogging))
1377 return false;
1378 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1379 return true;
1380 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001381 if (auto Count = parseRepeatPassName(Name)) {
1382 ModulePassManager NestedMPM(DebugLogging);
1383 if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
1384 DebugLogging))
1385 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001386 MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001387 return true;
1388 }
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001389
1390 for (auto &C : ModulePipelineParsingCallbacks)
1391 if (C(Name, MPM, InnerPipeline))
1392 return true;
1393
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001394 // Normal passes can't have pipelines.
1395 return false;
1396 }
1397
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001398 // Manually handle aliases for pre-configured pipeline fragments.
Chandler Carruth8b3be4e2017-06-01 11:39:39 +00001399 if (startsWithDefaultPipelineAliasPrefix(Name)) {
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001400 SmallVector<StringRef, 3> Matches;
1401 if (!DefaultAliasRegex.match(Name, &Matches))
1402 return false;
1403 assert(Matches.size() == 3 && "Must capture two matched strings!");
1404
Jordan Rosef85a95f2016-07-25 18:34:51 +00001405 OptimizationLevel L = StringSwitch<OptimizationLevel>(Matches[2])
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001406 .Case("O0", O0)
1407 .Case("O1", O1)
1408 .Case("O2", O2)
1409 .Case("O3", O3)
1410 .Case("Os", Os)
1411 .Case("Oz", Oz);
Chandler Carruthe3f50642016-12-22 06:59:15 +00001412 if (L == O0)
1413 // At O0 we do nothing at all!
1414 return true;
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001415
1416 if (Matches[1] == "default") {
Chandler Carruthe3f50642016-12-22 06:59:15 +00001417 MPM.addPass(buildPerModuleDefaultPipeline(L, DebugLogging));
Chandler Carruth8b3be4e2017-06-01 11:39:39 +00001418 } else if (Matches[1] == "thinlto-pre-link") {
1419 MPM.addPass(buildThinLTOPreLinkDefaultPipeline(L, DebugLogging));
1420 } else if (Matches[1] == "thinlto") {
1421 MPM.addPass(buildThinLTODefaultPipeline(L, DebugLogging));
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001422 } else if (Matches[1] == "lto-pre-link") {
Chandler Carruthe3f50642016-12-22 06:59:15 +00001423 MPM.addPass(buildLTOPreLinkDefaultPipeline(L, DebugLogging));
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001424 } else {
1425 assert(Matches[1] == "lto" && "Not one of the matched options!");
Chandler Carruthe3f50642016-12-22 06:59:15 +00001426 MPM.addPass(buildLTODefaultPipeline(L, DebugLogging));
Chandler Carruth8b5a74192016-02-28 22:16:03 +00001427 }
1428 return true;
1429 }
1430
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001431 // Finally expand the basic registered passes from the .inc file.
Chandler Carruth58944182014-04-21 08:08:50 +00001432#define MODULE_PASS(NAME, CREATE_PASS) \
1433 if (Name == NAME) { \
1434 MPM.addPass(CREATE_PASS); \
1435 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +00001436 }
Chandler Carruth628503e2015-01-06 02:10:51 +00001437#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1438 if (Name == "require<" NAME ">") { \
Chandler Carruth9b35e6d2016-08-19 18:36:06 +00001439 MPM.addPass( \
1440 RequireAnalysisPass< \
1441 std::remove_reference<decltype(CREATE_PASS)>::type, Module>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +00001442 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001443 } \
1444 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001445 MPM.addPass(InvalidateAnalysisPass< \
1446 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001447 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +00001448 }
1449#include "PassRegistry.def"
1450
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001451 for (auto &C : ModulePipelineParsingCallbacks)
1452 if (C(Name, MPM, InnerPipeline))
1453 return true;
Chandler Carruth66445382014-01-11 08:16:35 +00001454 return false;
1455}
1456
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001457bool PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
1458 const PipelineElement &E, bool VerifyEachPass,
1459 bool DebugLogging) {
1460 auto &Name = E.Name;
1461 auto &InnerPipeline = E.InnerPipeline;
1462
1463 // First handle complex passes like the pass managers which carry pipelines.
1464 if (!InnerPipeline.empty()) {
1465 if (Name == "cgscc") {
1466 CGSCCPassManager NestedCGPM(DebugLogging);
1467 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1468 DebugLogging))
1469 return false;
1470 // Add the nested pass manager with the appropriate adaptor.
1471 CGPM.addPass(std::move(NestedCGPM));
1472 return true;
1473 }
1474 if (Name == "function") {
1475 FunctionPassManager FPM(DebugLogging);
1476 if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
1477 DebugLogging))
1478 return false;
1479 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruth19913b22017-08-11 05:47:13 +00001480 CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001481 return true;
1482 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001483 if (auto Count = parseRepeatPassName(Name)) {
1484 CGSCCPassManager NestedCGPM(DebugLogging);
1485 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1486 DebugLogging))
1487 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001488 CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001489 return true;
1490 }
Chandler Carruth05ca5ac2016-12-28 11:07:33 +00001491 if (auto MaxRepetitions = parseDevirtPassName(Name)) {
1492 CGSCCPassManager NestedCGPM(DebugLogging);
1493 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1494 DebugLogging))
1495 return false;
Chandler Carruth19913b22017-08-11 05:47:13 +00001496 CGPM.addPass(
1497 createDevirtSCCRepeatedPass(std::move(NestedCGPM), *MaxRepetitions));
Chandler Carruth05ca5ac2016-12-28 11:07:33 +00001498 return true;
1499 }
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001500
1501 for (auto &C : CGSCCPipelineParsingCallbacks)
1502 if (C(Name, CGPM, InnerPipeline))
1503 return true;
1504
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001505 // Normal passes can't have pipelines.
1506 return false;
1507 }
1508
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001509// Now expand the basic registered passes from the .inc file.
Chandler Carruth572e3402014-04-21 11:12:00 +00001510#define CGSCC_PASS(NAME, CREATE_PASS) \
1511 if (Name == NAME) { \
1512 CGPM.addPass(CREATE_PASS); \
1513 return true; \
1514 }
Chandler Carruth628503e2015-01-06 02:10:51 +00001515#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1516 if (Name == "require<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001517 CGPM.addPass(RequireAnalysisPass< \
Chandler Carruth9b35e6d2016-08-19 18:36:06 +00001518 std::remove_reference<decltype(CREATE_PASS)>::type, \
Chandler Carruth88823462016-08-24 09:37:14 +00001519 LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
1520 CGSCCUpdateResult &>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +00001521 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001522 } \
1523 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001524 CGPM.addPass(InvalidateAnalysisPass< \
1525 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001526 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +00001527 }
1528#include "PassRegistry.def"
1529
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001530 for (auto &C : CGSCCPipelineParsingCallbacks)
1531 if (C(Name, CGPM, InnerPipeline))
1532 return true;
Chandler Carruth572e3402014-04-21 11:12:00 +00001533 return false;
1534}
1535
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001536bool PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
1537 const PipelineElement &E,
1538 bool VerifyEachPass, bool DebugLogging) {
1539 auto &Name = E.Name;
1540 auto &InnerPipeline = E.InnerPipeline;
1541
1542 // First handle complex passes like the pass managers which carry pipelines.
1543 if (!InnerPipeline.empty()) {
1544 if (Name == "function") {
1545 FunctionPassManager NestedFPM(DebugLogging);
1546 if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
1547 DebugLogging))
1548 return false;
1549 // Add the nested pass manager with the appropriate adaptor.
1550 FPM.addPass(std::move(NestedFPM));
1551 return true;
1552 }
1553 if (Name == "loop") {
1554 LoopPassManager LPM(DebugLogging);
1555 if (!parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass,
1556 DebugLogging))
1557 return false;
1558 // Add the nested pass manager with the appropriate adaptor.
Fedor Sergeev02e7f022017-12-29 08:16:06 +00001559 FPM.addPass(
1560 createFunctionToLoopPassAdaptor(std::move(LPM), DebugLogging));
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001561 return true;
1562 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001563 if (auto Count = parseRepeatPassName(Name)) {
1564 FunctionPassManager NestedFPM(DebugLogging);
1565 if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
1566 DebugLogging))
1567 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001568 FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001569 return true;
1570 }
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001571
1572 for (auto &C : FunctionPipelineParsingCallbacks)
1573 if (C(Name, FPM, InnerPipeline))
1574 return true;
1575
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001576 // Normal passes can't have pipelines.
1577 return false;
1578 }
1579
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001580// Now expand the basic registered passes from the .inc file.
Chandler Carruth58944182014-04-21 08:08:50 +00001581#define FUNCTION_PASS(NAME, CREATE_PASS) \
1582 if (Name == NAME) { \
1583 FPM.addPass(CREATE_PASS); \
1584 return true; \
Chandler Carruth52eef882014-01-12 12:15:39 +00001585 }
Chandler Carruth628503e2015-01-06 02:10:51 +00001586#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1587 if (Name == "require<" NAME ">") { \
Chandler Carruth9b35e6d2016-08-19 18:36:06 +00001588 FPM.addPass( \
1589 RequireAnalysisPass< \
1590 std::remove_reference<decltype(CREATE_PASS)>::type, Function>()); \
Chandler Carruth628503e2015-01-06 02:10:51 +00001591 return true; \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001592 } \
1593 if (Name == "invalidate<" NAME ">") { \
Chandler Carruth470734b2016-02-26 12:30:18 +00001594 FPM.addPass(InvalidateAnalysisPass< \
1595 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Chandler Carruth3472ffb2015-01-06 04:49:44 +00001596 return true; \
Chandler Carruth628503e2015-01-06 02:10:51 +00001597 }
1598#include "PassRegistry.def"
1599
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001600 for (auto &C : FunctionPipelineParsingCallbacks)
1601 if (C(Name, FPM, InnerPipeline))
1602 return true;
Chandler Carruthd8330982014-01-12 09:34:22 +00001603 return false;
1604}
1605
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001606bool PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001607 bool VerifyEachPass, bool DebugLogging) {
Chandler Carruth241bf242016-08-03 07:44:48 +00001608 StringRef Name = E.Name;
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001609 auto &InnerPipeline = E.InnerPipeline;
1610
1611 // First handle complex passes like the pass managers which carry pipelines.
1612 if (!InnerPipeline.empty()) {
1613 if (Name == "loop") {
1614 LoopPassManager NestedLPM(DebugLogging);
1615 if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
1616 DebugLogging))
1617 return false;
1618 // Add the nested pass manager with the appropriate adaptor.
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001619 LPM.addPass(std::move(NestedLPM));
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001620 return true;
1621 }
Chandler Carruth241bf242016-08-03 07:44:48 +00001622 if (auto Count = parseRepeatPassName(Name)) {
1623 LoopPassManager NestedLPM(DebugLogging);
1624 if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
1625 DebugLogging))
1626 return false;
Chandler Carrutha053a882016-08-04 03:52:53 +00001627 LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM)));
Chandler Carruth241bf242016-08-03 07:44:48 +00001628 return true;
1629 }
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001630
1631 for (auto &C : LoopPipelineParsingCallbacks)
1632 if (C(Name, LPM, InnerPipeline))
1633 return true;
1634
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001635 // Normal passes can't have pipelines.
1636 return false;
1637 }
1638
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001639// Now expand the basic registered passes from the .inc file.
Justin Bognereecc3c82016-02-25 07:23:08 +00001640#define LOOP_PASS(NAME, CREATE_PASS) \
1641 if (Name == NAME) { \
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001642 LPM.addPass(CREATE_PASS); \
Justin Bognereecc3c82016-02-25 07:23:08 +00001643 return true; \
1644 }
1645#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1646 if (Name == "require<" NAME ">") { \
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001647 LPM.addPass(RequireAnalysisPass< \
Chandler Carruth410eaeb2017-01-11 06:23:21 +00001648 std::remove_reference<decltype(CREATE_PASS)>::type, Loop, \
1649 LoopAnalysisManager, LoopStandardAnalysisResults &, \
1650 LPMUpdater &>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +00001651 return true; \
1652 } \
1653 if (Name == "invalidate<" NAME ">") { \
Chandler Carruthfdc6ba12016-08-03 09:14:03 +00001654 LPM.addPass(InvalidateAnalysisPass< \
Chandler Carruth470734b2016-02-26 12:30:18 +00001655 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
Justin Bognereecc3c82016-02-25 07:23:08 +00001656 return true; \
1657 }
1658#include "PassRegistry.def"
1659
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001660 for (auto &C : LoopPipelineParsingCallbacks)
1661 if (C(Name, LPM, InnerPipeline))
1662 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +00001663 return false;
1664}
1665
Chandler Carruthedf59962016-02-18 09:45:17 +00001666bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
Chandler Carruth45a9c202016-03-11 09:15:11 +00001667#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1668 if (Name == NAME) { \
1669 AA.registerModuleAnalysis< \
1670 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
1671 return true; \
1672 }
Chandler Carruthedf59962016-02-18 09:45:17 +00001673#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1674 if (Name == NAME) { \
Chandler Carruth58dde8c2016-02-26 12:17:54 +00001675 AA.registerFunctionAnalysis< \
1676 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
Chandler Carruthedf59962016-02-18 09:45:17 +00001677 return true; \
1678 }
1679#include "PassRegistry.def"
1680
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001681 for (auto &C : AAParsingCallbacks)
1682 if (C(Name, AA))
1683 return true;
Chandler Carruthedf59962016-02-18 09:45:17 +00001684 return false;
1685}
1686
Justin Bognereecc3c82016-02-25 07:23:08 +00001687bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001688 ArrayRef<PipelineElement> Pipeline,
Justin Bognereecc3c82016-02-25 07:23:08 +00001689 bool VerifyEachPass,
1690 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001691 for (const auto &Element : Pipeline) {
1692 if (!parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging))
1693 return false;
1694 // FIXME: No verifier support for Loop passes!
Justin Bognereecc3c82016-02-25 07:23:08 +00001695 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001696 return true;
Justin Bognereecc3c82016-02-25 07:23:08 +00001697}
1698
Chandler Carruth1ff77242015-03-07 09:02:36 +00001699bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001700 ArrayRef<PipelineElement> Pipeline,
Chandler Carruth1ff77242015-03-07 09:02:36 +00001701 bool VerifyEachPass,
1702 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001703 for (const auto &Element : Pipeline) {
1704 if (!parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging))
1705 return false;
1706 if (VerifyEachPass)
1707 FPM.addPass(VerifierPass());
Chandler Carruthd8330982014-01-12 09:34:22 +00001708 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001709 return true;
Chandler Carruthd8330982014-01-12 09:34:22 +00001710}
1711
Chandler Carruth1ff77242015-03-07 09:02:36 +00001712bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001713 ArrayRef<PipelineElement> Pipeline,
Chandler Carruth1ff77242015-03-07 09:02:36 +00001714 bool VerifyEachPass,
1715 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001716 for (const auto &Element : Pipeline) {
1717 if (!parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging))
1718 return false;
1719 // FIXME: No verifier support for CGSCC passes!
Chandler Carruth572e3402014-04-21 11:12:00 +00001720 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001721 return true;
Chandler Carruth572e3402014-04-21 11:12:00 +00001722}
1723
NAKAMURA Takumia42f5282016-05-16 10:13:37 +00001724void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM,
1725 FunctionAnalysisManager &FAM,
1726 CGSCCAnalysisManager &CGAM,
1727 ModuleAnalysisManager &MAM) {
1728 MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
1729 MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
NAKAMURA Takumia42f5282016-05-16 10:13:37 +00001730 CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
1731 FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
1732 FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
1733 FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
1734 LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
1735}
1736
Chandler Carruth1ff77242015-03-07 09:02:36 +00001737bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001738 ArrayRef<PipelineElement> Pipeline,
Chandler Carruth1ff77242015-03-07 09:02:36 +00001739 bool VerifyEachPass,
1740 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001741 for (const auto &Element : Pipeline) {
1742 if (!parseModulePass(MPM, Element, VerifyEachPass, DebugLogging))
1743 return false;
1744 if (VerifyEachPass)
1745 MPM.addPass(VerifierPass());
Chandler Carruth66445382014-01-11 08:16:35 +00001746 }
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001747 return true;
Chandler Carruth66445382014-01-11 08:16:35 +00001748}
1749
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001750// Primary pass pipeline description parsing routine for a \c ModulePassManager
Chandler Carruth66445382014-01-11 08:16:35 +00001751// FIXME: Should this routine accept a TargetMachine or require the caller to
1752// pre-populate the analysis managers with target-specific stuff?
Chandler Carruth1ff77242015-03-07 09:02:36 +00001753bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
1754 StringRef PipelineText, bool VerifyEachPass,
1755 bool DebugLogging) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001756 auto Pipeline = parsePipelineText(PipelineText);
1757 if (!Pipeline || Pipeline->empty())
1758 return false;
Chandler Carruth66445382014-01-11 08:16:35 +00001759
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001760 // If the first name isn't at the module layer, wrap the pipeline up
1761 // automatically.
1762 StringRef FirstName = Pipeline->front().Name;
Chandler Carruth66445382014-01-11 08:16:35 +00001763
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001764 if (!isModulePassName(FirstName, ModulePipelineParsingCallbacks)) {
1765 if (isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001766 Pipeline = {{"cgscc", std::move(*Pipeline)}};
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001767 } else if (isFunctionPassName(FirstName,
1768 FunctionPipelineParsingCallbacks)) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001769 Pipeline = {{"function", std::move(*Pipeline)}};
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001770 } else if (isLoopPassName(FirstName, LoopPipelineParsingCallbacks)) {
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001771 Pipeline = {{"function", {{"loop", std::move(*Pipeline)}}}};
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001772 } else {
1773 for (auto &C : TopLevelPipelineParsingCallbacks)
1774 if (C(MPM, *Pipeline, VerifyEachPass, DebugLogging))
1775 return true;
1776
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001777 // Unknown pass name!
Chandler Carruth572e3402014-04-21 11:12:00 +00001778 return false;
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001779 }
Chandler Carruth572e3402014-04-21 11:12:00 +00001780 }
1781
Chandler Carruth6cb2ab22016-08-03 03:21:41 +00001782 return parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging);
Chandler Carruth66445382014-01-11 08:16:35 +00001783}
Chandler Carruthedf59962016-02-18 09:45:17 +00001784
Philip Pfaffe730f2f92017-07-10 10:57:55 +00001785// Primary pass pipeline description parsing routine for a \c CGSCCPassManager
1786bool PassBuilder::parsePassPipeline(CGSCCPassManager &CGPM,
1787 StringRef PipelineText, bool VerifyEachPass,
1788 bool DebugLogging) {
1789 auto Pipeline = parsePipelineText(PipelineText);
1790 if (!Pipeline || Pipeline->empty())
1791 return false;
1792
1793 StringRef FirstName = Pipeline->front().Name;
1794 if (!isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks))
1795 return false;
1796
1797 return parseCGSCCPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging);
1798}
1799
1800// Primary pass pipeline description parsing routine for a \c
1801// FunctionPassManager
1802bool PassBuilder::parsePassPipeline(FunctionPassManager &FPM,
1803 StringRef PipelineText, bool VerifyEachPass,
1804 bool DebugLogging) {
1805 auto Pipeline = parsePipelineText(PipelineText);
1806 if (!Pipeline || Pipeline->empty())
1807 return false;
1808
1809 StringRef FirstName = Pipeline->front().Name;
1810 if (!isFunctionPassName(FirstName, FunctionPipelineParsingCallbacks))
1811 return false;
1812
1813 return parseFunctionPassPipeline(FPM, *Pipeline, VerifyEachPass,
1814 DebugLogging);
1815}
1816
1817// Primary pass pipeline description parsing routine for a \c LoopPassManager
1818bool PassBuilder::parsePassPipeline(LoopPassManager &CGPM,
1819 StringRef PipelineText, bool VerifyEachPass,
1820 bool DebugLogging) {
1821 auto Pipeline = parsePipelineText(PipelineText);
1822 if (!Pipeline || Pipeline->empty())
1823 return false;
1824
1825 return parseLoopPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging);
1826}
1827
Chandler Carruthedf59962016-02-18 09:45:17 +00001828bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) {
Chandler Carruth060ad612016-12-23 20:38:19 +00001829 // If the pipeline just consists of the word 'default' just replace the AA
1830 // manager with our default one.
1831 if (PipelineText == "default") {
1832 AA = buildDefaultAAPipeline();
1833 return true;
1834 }
1835
Chandler Carruthedf59962016-02-18 09:45:17 +00001836 while (!PipelineText.empty()) {
1837 StringRef Name;
1838 std::tie(Name, PipelineText) = PipelineText.split(',');
1839 if (!parseAAPassName(AA, Name))
1840 return false;
1841 }
1842
1843 return true;
1844}