1*9880d681SAndroid Build Coastguard Worker //===- PassManagerBuilder.cpp - Build Standard Pass -----------------------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file defines the PassManagerBuilder class, which is used to set up a
11*9880d681SAndroid Build Coastguard Worker // "standard" optimization sequence suitable for languages like C and C++.
12*9880d681SAndroid Build Coastguard Worker //
13*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/IPO/PassManagerBuilder.h"
16*9880d681SAndroid Build Coastguard Worker #include "llvm-c/Transforms/PassManagerBuilder.h"
17*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SmallVector.h"
18*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/BasicAliasAnalysis.h"
19*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/CFLAndersAliasAnalysis.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/CFLSteensAliasAnalysis.h"
21*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/GlobalsModRef.h"
22*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/Passes.h"
23*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/ScopedNoAliasAA.h"
24*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/TargetLibraryInfo.h"
25*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
26*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/DataLayout.h"
27*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/LegacyPassManager.h"
28*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/ModuleSummaryIndex.h"
29*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Verifier.h"
30*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/CommandLine.h"
31*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/ManagedStatic.h"
32*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetMachine.h"
33*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/IPO.h"
34*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/IPO/ForceFunctionAttrs.h"
35*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/IPO/FunctionAttrs.h"
36*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/IPO/InferFunctionAttrs.h"
37*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/Instrumentation.h"
38*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/Scalar.h"
39*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/Scalar/GVN.h"
40*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/Vectorize.h"
41*9880d681SAndroid Build Coastguard Worker
42*9880d681SAndroid Build Coastguard Worker using namespace llvm;
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker static cl::opt<bool>
45*9880d681SAndroid Build Coastguard Worker RunLoopVectorization("vectorize-loops", cl::Hidden,
46*9880d681SAndroid Build Coastguard Worker cl::desc("Run the Loop vectorization passes"));
47*9880d681SAndroid Build Coastguard Worker
48*9880d681SAndroid Build Coastguard Worker static cl::opt<bool>
49*9880d681SAndroid Build Coastguard Worker RunSLPVectorization("vectorize-slp", cl::Hidden,
50*9880d681SAndroid Build Coastguard Worker cl::desc("Run the SLP vectorization passes"));
51*9880d681SAndroid Build Coastguard Worker
52*9880d681SAndroid Build Coastguard Worker static cl::opt<bool>
53*9880d681SAndroid Build Coastguard Worker RunBBVectorization("vectorize-slp-aggressive", cl::Hidden,
54*9880d681SAndroid Build Coastguard Worker cl::desc("Run the BB vectorization passes"));
55*9880d681SAndroid Build Coastguard Worker
56*9880d681SAndroid Build Coastguard Worker static cl::opt<bool>
57*9880d681SAndroid Build Coastguard Worker UseGVNAfterVectorization("use-gvn-after-vectorization",
58*9880d681SAndroid Build Coastguard Worker cl::init(false), cl::Hidden,
59*9880d681SAndroid Build Coastguard Worker cl::desc("Run GVN instead of Early CSE after vectorization passes"));
60*9880d681SAndroid Build Coastguard Worker
61*9880d681SAndroid Build Coastguard Worker static cl::opt<bool> ExtraVectorizerPasses(
62*9880d681SAndroid Build Coastguard Worker "extra-vectorizer-passes", cl::init(false), cl::Hidden,
63*9880d681SAndroid Build Coastguard Worker cl::desc("Run cleanup optimization passes after vectorization."));
64*9880d681SAndroid Build Coastguard Worker
65*9880d681SAndroid Build Coastguard Worker static cl::opt<bool>
66*9880d681SAndroid Build Coastguard Worker RunLoopRerolling("reroll-loops", cl::Hidden,
67*9880d681SAndroid Build Coastguard Worker cl::desc("Run the loop rerolling pass"));
68*9880d681SAndroid Build Coastguard Worker
69*9880d681SAndroid Build Coastguard Worker static cl::opt<bool>
70*9880d681SAndroid Build Coastguard Worker RunFloat2Int("float-to-int", cl::Hidden, cl::init(true),
71*9880d681SAndroid Build Coastguard Worker cl::desc("Run the float2int (float demotion) pass"));
72*9880d681SAndroid Build Coastguard Worker
73*9880d681SAndroid Build Coastguard Worker static cl::opt<bool> RunLoadCombine("combine-loads", cl::init(false),
74*9880d681SAndroid Build Coastguard Worker cl::Hidden,
75*9880d681SAndroid Build Coastguard Worker cl::desc("Run the load combining pass"));
76*9880d681SAndroid Build Coastguard Worker
77*9880d681SAndroid Build Coastguard Worker static cl::opt<bool>
78*9880d681SAndroid Build Coastguard Worker RunSLPAfterLoopVectorization("run-slp-after-loop-vectorization",
79*9880d681SAndroid Build Coastguard Worker cl::init(true), cl::Hidden,
80*9880d681SAndroid Build Coastguard Worker cl::desc("Run the SLP vectorizer (and BB vectorizer) after the Loop "
81*9880d681SAndroid Build Coastguard Worker "vectorizer instead of before"));
82*9880d681SAndroid Build Coastguard Worker
83*9880d681SAndroid Build Coastguard Worker // Experimental option to use CFL-AA
84*9880d681SAndroid Build Coastguard Worker enum class CFLAAType { None, Steensgaard, Andersen, Both };
85*9880d681SAndroid Build Coastguard Worker static cl::opt<CFLAAType>
86*9880d681SAndroid Build Coastguard Worker UseCFLAA("use-cfl-aa", cl::init(CFLAAType::None), cl::Hidden,
87*9880d681SAndroid Build Coastguard Worker cl::desc("Enable the new, experimental CFL alias analysis"),
88*9880d681SAndroid Build Coastguard Worker cl::values(clEnumValN(CFLAAType::None, "none", "Disable CFL-AA"),
89*9880d681SAndroid Build Coastguard Worker clEnumValN(CFLAAType::Steensgaard, "steens",
90*9880d681SAndroid Build Coastguard Worker "Enable unification-based CFL-AA"),
91*9880d681SAndroid Build Coastguard Worker clEnumValN(CFLAAType::Andersen, "anders",
92*9880d681SAndroid Build Coastguard Worker "Enable inclusion-based CFL-AA"),
93*9880d681SAndroid Build Coastguard Worker clEnumValN(CFLAAType::Both, "both",
94*9880d681SAndroid Build Coastguard Worker "Enable both variants of CFL-aa"),
95*9880d681SAndroid Build Coastguard Worker clEnumValEnd));
96*9880d681SAndroid Build Coastguard Worker
97*9880d681SAndroid Build Coastguard Worker static cl::opt<bool>
98*9880d681SAndroid Build Coastguard Worker EnableMLSM("mlsm", cl::init(true), cl::Hidden,
99*9880d681SAndroid Build Coastguard Worker cl::desc("Enable motion of merged load and store"));
100*9880d681SAndroid Build Coastguard Worker
101*9880d681SAndroid Build Coastguard Worker static cl::opt<bool> EnableLoopInterchange(
102*9880d681SAndroid Build Coastguard Worker "enable-loopinterchange", cl::init(false), cl::Hidden,
103*9880d681SAndroid Build Coastguard Worker cl::desc("Enable the new, experimental LoopInterchange Pass"));
104*9880d681SAndroid Build Coastguard Worker
105*9880d681SAndroid Build Coastguard Worker static cl::opt<bool> EnableNonLTOGlobalsModRef(
106*9880d681SAndroid Build Coastguard Worker "enable-non-lto-gmr", cl::init(true), cl::Hidden,
107*9880d681SAndroid Build Coastguard Worker cl::desc(
108*9880d681SAndroid Build Coastguard Worker "Enable the GlobalsModRef AliasAnalysis outside of the LTO pipeline."));
109*9880d681SAndroid Build Coastguard Worker
110*9880d681SAndroid Build Coastguard Worker static cl::opt<bool> EnableLoopLoadElim(
111*9880d681SAndroid Build Coastguard Worker "enable-loop-load-elim", cl::init(true), cl::Hidden,
112*9880d681SAndroid Build Coastguard Worker cl::desc("Enable the LoopLoadElimination Pass"));
113*9880d681SAndroid Build Coastguard Worker
114*9880d681SAndroid Build Coastguard Worker static cl::opt<std::string> RunPGOInstrGen(
115*9880d681SAndroid Build Coastguard Worker "profile-generate", cl::init(""), cl::Hidden,
116*9880d681SAndroid Build Coastguard Worker cl::desc("Enable generation phase of PGO instrumentation and specify the "
117*9880d681SAndroid Build Coastguard Worker "path of profile data file"));
118*9880d681SAndroid Build Coastguard Worker
119*9880d681SAndroid Build Coastguard Worker static cl::opt<std::string> RunPGOInstrUse(
120*9880d681SAndroid Build Coastguard Worker "profile-use", cl::init(""), cl::Hidden, cl::value_desc("filename"),
121*9880d681SAndroid Build Coastguard Worker cl::desc("Enable use phase of PGO instrumentation and specify the path "
122*9880d681SAndroid Build Coastguard Worker "of profile data file"));
123*9880d681SAndroid Build Coastguard Worker
124*9880d681SAndroid Build Coastguard Worker static cl::opt<bool> UseLoopVersioningLICM(
125*9880d681SAndroid Build Coastguard Worker "enable-loop-versioning-licm", cl::init(false), cl::Hidden,
126*9880d681SAndroid Build Coastguard Worker cl::desc("Enable the experimental Loop Versioning LICM pass"));
127*9880d681SAndroid Build Coastguard Worker
PassManagerBuilder()128*9880d681SAndroid Build Coastguard Worker PassManagerBuilder::PassManagerBuilder() {
129*9880d681SAndroid Build Coastguard Worker OptLevel = 2;
130*9880d681SAndroid Build Coastguard Worker SizeLevel = 0;
131*9880d681SAndroid Build Coastguard Worker LibraryInfo = nullptr;
132*9880d681SAndroid Build Coastguard Worker Inliner = nullptr;
133*9880d681SAndroid Build Coastguard Worker ModuleSummary = nullptr;
134*9880d681SAndroid Build Coastguard Worker DisableUnitAtATime = false;
135*9880d681SAndroid Build Coastguard Worker DisableUnrollLoops = false;
136*9880d681SAndroid Build Coastguard Worker BBVectorize = RunBBVectorization;
137*9880d681SAndroid Build Coastguard Worker SLPVectorize = RunSLPVectorization;
138*9880d681SAndroid Build Coastguard Worker LoopVectorize = RunLoopVectorization;
139*9880d681SAndroid Build Coastguard Worker RerollLoops = RunLoopRerolling;
140*9880d681SAndroid Build Coastguard Worker LoadCombine = RunLoadCombine;
141*9880d681SAndroid Build Coastguard Worker DisableGVNLoadPRE = false;
142*9880d681SAndroid Build Coastguard Worker VerifyInput = false;
143*9880d681SAndroid Build Coastguard Worker VerifyOutput = false;
144*9880d681SAndroid Build Coastguard Worker MergeFunctions = false;
145*9880d681SAndroid Build Coastguard Worker PrepareForLTO = false;
146*9880d681SAndroid Build Coastguard Worker PGOInstrGen = RunPGOInstrGen;
147*9880d681SAndroid Build Coastguard Worker PGOInstrUse = RunPGOInstrUse;
148*9880d681SAndroid Build Coastguard Worker PrepareForThinLTO = false;
149*9880d681SAndroid Build Coastguard Worker PerformThinLTO = false;
150*9880d681SAndroid Build Coastguard Worker }
151*9880d681SAndroid Build Coastguard Worker
~PassManagerBuilder()152*9880d681SAndroid Build Coastguard Worker PassManagerBuilder::~PassManagerBuilder() {
153*9880d681SAndroid Build Coastguard Worker delete LibraryInfo;
154*9880d681SAndroid Build Coastguard Worker delete Inliner;
155*9880d681SAndroid Build Coastguard Worker }
156*9880d681SAndroid Build Coastguard Worker
157*9880d681SAndroid Build Coastguard Worker /// Set of global extensions, automatically added as part of the standard set.
158*9880d681SAndroid Build Coastguard Worker static ManagedStatic<SmallVector<std::pair<PassManagerBuilder::ExtensionPointTy,
159*9880d681SAndroid Build Coastguard Worker PassManagerBuilder::ExtensionFn>, 8> > GlobalExtensions;
160*9880d681SAndroid Build Coastguard Worker
addGlobalExtension(PassManagerBuilder::ExtensionPointTy Ty,PassManagerBuilder::ExtensionFn Fn)161*9880d681SAndroid Build Coastguard Worker void PassManagerBuilder::addGlobalExtension(
162*9880d681SAndroid Build Coastguard Worker PassManagerBuilder::ExtensionPointTy Ty,
163*9880d681SAndroid Build Coastguard Worker PassManagerBuilder::ExtensionFn Fn) {
164*9880d681SAndroid Build Coastguard Worker GlobalExtensions->push_back(std::make_pair(Ty, std::move(Fn)));
165*9880d681SAndroid Build Coastguard Worker }
166*9880d681SAndroid Build Coastguard Worker
addExtension(ExtensionPointTy Ty,ExtensionFn Fn)167*9880d681SAndroid Build Coastguard Worker void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) {
168*9880d681SAndroid Build Coastguard Worker Extensions.push_back(std::make_pair(Ty, std::move(Fn)));
169*9880d681SAndroid Build Coastguard Worker }
170*9880d681SAndroid Build Coastguard Worker
addExtensionsToPM(ExtensionPointTy ETy,legacy::PassManagerBase & PM) const171*9880d681SAndroid Build Coastguard Worker void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy,
172*9880d681SAndroid Build Coastguard Worker legacy::PassManagerBase &PM) const {
173*9880d681SAndroid Build Coastguard Worker for (unsigned i = 0, e = GlobalExtensions->size(); i != e; ++i)
174*9880d681SAndroid Build Coastguard Worker if ((*GlobalExtensions)[i].first == ETy)
175*9880d681SAndroid Build Coastguard Worker (*GlobalExtensions)[i].second(*this, PM);
176*9880d681SAndroid Build Coastguard Worker for (unsigned i = 0, e = Extensions.size(); i != e; ++i)
177*9880d681SAndroid Build Coastguard Worker if (Extensions[i].first == ETy)
178*9880d681SAndroid Build Coastguard Worker Extensions[i].second(*this, PM);
179*9880d681SAndroid Build Coastguard Worker }
180*9880d681SAndroid Build Coastguard Worker
addInitialAliasAnalysisPasses(legacy::PassManagerBase & PM) const181*9880d681SAndroid Build Coastguard Worker void PassManagerBuilder::addInitialAliasAnalysisPasses(
182*9880d681SAndroid Build Coastguard Worker legacy::PassManagerBase &PM) const {
183*9880d681SAndroid Build Coastguard Worker switch (UseCFLAA) {
184*9880d681SAndroid Build Coastguard Worker case CFLAAType::Steensgaard:
185*9880d681SAndroid Build Coastguard Worker PM.add(createCFLSteensAAWrapperPass());
186*9880d681SAndroid Build Coastguard Worker break;
187*9880d681SAndroid Build Coastguard Worker case CFLAAType::Andersen:
188*9880d681SAndroid Build Coastguard Worker PM.add(createCFLAndersAAWrapperPass());
189*9880d681SAndroid Build Coastguard Worker break;
190*9880d681SAndroid Build Coastguard Worker case CFLAAType::Both:
191*9880d681SAndroid Build Coastguard Worker PM.add(createCFLSteensAAWrapperPass());
192*9880d681SAndroid Build Coastguard Worker PM.add(createCFLAndersAAWrapperPass());
193*9880d681SAndroid Build Coastguard Worker break;
194*9880d681SAndroid Build Coastguard Worker default:
195*9880d681SAndroid Build Coastguard Worker break;
196*9880d681SAndroid Build Coastguard Worker }
197*9880d681SAndroid Build Coastguard Worker
198*9880d681SAndroid Build Coastguard Worker // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
199*9880d681SAndroid Build Coastguard Worker // BasicAliasAnalysis wins if they disagree. This is intended to help
200*9880d681SAndroid Build Coastguard Worker // support "obvious" type-punning idioms.
201*9880d681SAndroid Build Coastguard Worker PM.add(createTypeBasedAAWrapperPass());
202*9880d681SAndroid Build Coastguard Worker PM.add(createScopedNoAliasAAWrapperPass());
203*9880d681SAndroid Build Coastguard Worker }
204*9880d681SAndroid Build Coastguard Worker
addInstructionCombiningPass(legacy::PassManagerBase & PM) const205*9880d681SAndroid Build Coastguard Worker void PassManagerBuilder::addInstructionCombiningPass(
206*9880d681SAndroid Build Coastguard Worker legacy::PassManagerBase &PM) const {
207*9880d681SAndroid Build Coastguard Worker bool ExpensiveCombines = OptLevel > 2;
208*9880d681SAndroid Build Coastguard Worker PM.add(createInstructionCombiningPass(ExpensiveCombines));
209*9880d681SAndroid Build Coastguard Worker }
210*9880d681SAndroid Build Coastguard Worker
populateFunctionPassManager(legacy::FunctionPassManager & FPM)211*9880d681SAndroid Build Coastguard Worker void PassManagerBuilder::populateFunctionPassManager(
212*9880d681SAndroid Build Coastguard Worker legacy::FunctionPassManager &FPM) {
213*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_EarlyAsPossible, FPM);
214*9880d681SAndroid Build Coastguard Worker
215*9880d681SAndroid Build Coastguard Worker // Add LibraryInfo if we have some.
216*9880d681SAndroid Build Coastguard Worker if (LibraryInfo)
217*9880d681SAndroid Build Coastguard Worker FPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
218*9880d681SAndroid Build Coastguard Worker
219*9880d681SAndroid Build Coastguard Worker if (OptLevel == 0) return;
220*9880d681SAndroid Build Coastguard Worker
221*9880d681SAndroid Build Coastguard Worker addInitialAliasAnalysisPasses(FPM);
222*9880d681SAndroid Build Coastguard Worker
223*9880d681SAndroid Build Coastguard Worker FPM.add(createCFGSimplificationPass());
224*9880d681SAndroid Build Coastguard Worker FPM.add(createSROAPass());
225*9880d681SAndroid Build Coastguard Worker FPM.add(createEarlyCSEPass());
226*9880d681SAndroid Build Coastguard Worker FPM.add(createLowerExpectIntrinsicPass());
227*9880d681SAndroid Build Coastguard Worker }
228*9880d681SAndroid Build Coastguard Worker
229*9880d681SAndroid Build Coastguard Worker // Do PGO instrumentation generation or use pass as the option specified.
addPGOInstrPasses(legacy::PassManagerBase & MPM)230*9880d681SAndroid Build Coastguard Worker void PassManagerBuilder::addPGOInstrPasses(legacy::PassManagerBase &MPM) {
231*9880d681SAndroid Build Coastguard Worker if (!PGOInstrGen.empty()) {
232*9880d681SAndroid Build Coastguard Worker MPM.add(createPGOInstrumentationGenLegacyPass());
233*9880d681SAndroid Build Coastguard Worker // Add the profile lowering pass.
234*9880d681SAndroid Build Coastguard Worker InstrProfOptions Options;
235*9880d681SAndroid Build Coastguard Worker Options.InstrProfileOutput = PGOInstrGen;
236*9880d681SAndroid Build Coastguard Worker MPM.add(createInstrProfilingLegacyPass(Options));
237*9880d681SAndroid Build Coastguard Worker }
238*9880d681SAndroid Build Coastguard Worker if (!PGOInstrUse.empty())
239*9880d681SAndroid Build Coastguard Worker MPM.add(createPGOInstrumentationUseLegacyPass(PGOInstrUse));
240*9880d681SAndroid Build Coastguard Worker }
addFunctionSimplificationPasses(legacy::PassManagerBase & MPM)241*9880d681SAndroid Build Coastguard Worker void PassManagerBuilder::addFunctionSimplificationPasses(
242*9880d681SAndroid Build Coastguard Worker legacy::PassManagerBase &MPM) {
243*9880d681SAndroid Build Coastguard Worker // Start of function pass.
244*9880d681SAndroid Build Coastguard Worker // Break up aggregate allocas, using SSAUpdater.
245*9880d681SAndroid Build Coastguard Worker MPM.add(createSROAPass());
246*9880d681SAndroid Build Coastguard Worker MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
247*9880d681SAndroid Build Coastguard Worker // Speculative execution if the target has divergent branches; otherwise nop.
248*9880d681SAndroid Build Coastguard Worker MPM.add(createSpeculativeExecutionIfHasBranchDivergencePass());
249*9880d681SAndroid Build Coastguard Worker MPM.add(createJumpThreadingPass()); // Thread jumps.
250*9880d681SAndroid Build Coastguard Worker MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
251*9880d681SAndroid Build Coastguard Worker MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
252*9880d681SAndroid Build Coastguard Worker // Combine silly seq's
253*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(MPM);
254*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_Peephole, MPM);
255*9880d681SAndroid Build Coastguard Worker
256*9880d681SAndroid Build Coastguard Worker MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
257*9880d681SAndroid Build Coastguard Worker MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
258*9880d681SAndroid Build Coastguard Worker MPM.add(createReassociatePass()); // Reassociate expressions
259*9880d681SAndroid Build Coastguard Worker // Rotate Loop - disable header duplication at -Oz
260*9880d681SAndroid Build Coastguard Worker MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
261*9880d681SAndroid Build Coastguard Worker MPM.add(createLICMPass()); // Hoist loop invariants
262*9880d681SAndroid Build Coastguard Worker MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
263*9880d681SAndroid Build Coastguard Worker MPM.add(createCFGSimplificationPass());
264*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(MPM);
265*9880d681SAndroid Build Coastguard Worker MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
266*9880d681SAndroid Build Coastguard Worker MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
267*9880d681SAndroid Build Coastguard Worker MPM.add(createLoopDeletionPass()); // Delete dead loops
268*9880d681SAndroid Build Coastguard Worker if (EnableLoopInterchange) {
269*9880d681SAndroid Build Coastguard Worker MPM.add(createLoopInterchangePass()); // Interchange loops
270*9880d681SAndroid Build Coastguard Worker MPM.add(createCFGSimplificationPass());
271*9880d681SAndroid Build Coastguard Worker }
272*9880d681SAndroid Build Coastguard Worker if (!DisableUnrollLoops)
273*9880d681SAndroid Build Coastguard Worker MPM.add(createSimpleLoopUnrollPass()); // Unroll small loops
274*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
275*9880d681SAndroid Build Coastguard Worker
276*9880d681SAndroid Build Coastguard Worker if (OptLevel > 1) {
277*9880d681SAndroid Build Coastguard Worker if (EnableMLSM)
278*9880d681SAndroid Build Coastguard Worker MPM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds
279*9880d681SAndroid Build Coastguard Worker MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
280*9880d681SAndroid Build Coastguard Worker }
281*9880d681SAndroid Build Coastguard Worker MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset
282*9880d681SAndroid Build Coastguard Worker MPM.add(createSCCPPass()); // Constant prop with SCCP
283*9880d681SAndroid Build Coastguard Worker
284*9880d681SAndroid Build Coastguard Worker // Delete dead bit computations (instcombine runs after to fold away the dead
285*9880d681SAndroid Build Coastguard Worker // computations, and then ADCE will run later to exploit any new DCE
286*9880d681SAndroid Build Coastguard Worker // opportunities that creates).
287*9880d681SAndroid Build Coastguard Worker MPM.add(createBitTrackingDCEPass()); // Delete dead bit computations
288*9880d681SAndroid Build Coastguard Worker
289*9880d681SAndroid Build Coastguard Worker // Run instcombine after redundancy elimination to exploit opportunities
290*9880d681SAndroid Build Coastguard Worker // opened up by them.
291*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(MPM);
292*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_Peephole, MPM);
293*9880d681SAndroid Build Coastguard Worker MPM.add(createJumpThreadingPass()); // Thread jumps
294*9880d681SAndroid Build Coastguard Worker MPM.add(createCorrelatedValuePropagationPass());
295*9880d681SAndroid Build Coastguard Worker MPM.add(createDeadStoreEliminationPass()); // Delete dead stores
296*9880d681SAndroid Build Coastguard Worker MPM.add(createLICMPass());
297*9880d681SAndroid Build Coastguard Worker
298*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_ScalarOptimizerLate, MPM);
299*9880d681SAndroid Build Coastguard Worker
300*9880d681SAndroid Build Coastguard Worker if (RerollLoops)
301*9880d681SAndroid Build Coastguard Worker MPM.add(createLoopRerollPass());
302*9880d681SAndroid Build Coastguard Worker if (!RunSLPAfterLoopVectorization) {
303*9880d681SAndroid Build Coastguard Worker if (SLPVectorize)
304*9880d681SAndroid Build Coastguard Worker MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
305*9880d681SAndroid Build Coastguard Worker
306*9880d681SAndroid Build Coastguard Worker if (BBVectorize) {
307*9880d681SAndroid Build Coastguard Worker MPM.add(createBBVectorizePass());
308*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(MPM);
309*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_Peephole, MPM);
310*9880d681SAndroid Build Coastguard Worker if (OptLevel > 1 && UseGVNAfterVectorization)
311*9880d681SAndroid Build Coastguard Worker MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
312*9880d681SAndroid Build Coastguard Worker else
313*9880d681SAndroid Build Coastguard Worker MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
314*9880d681SAndroid Build Coastguard Worker
315*9880d681SAndroid Build Coastguard Worker // BBVectorize may have significantly shortened a loop body; unroll again.
316*9880d681SAndroid Build Coastguard Worker if (!DisableUnrollLoops)
317*9880d681SAndroid Build Coastguard Worker MPM.add(createLoopUnrollPass());
318*9880d681SAndroid Build Coastguard Worker }
319*9880d681SAndroid Build Coastguard Worker }
320*9880d681SAndroid Build Coastguard Worker
321*9880d681SAndroid Build Coastguard Worker if (LoadCombine)
322*9880d681SAndroid Build Coastguard Worker MPM.add(createLoadCombinePass());
323*9880d681SAndroid Build Coastguard Worker
324*9880d681SAndroid Build Coastguard Worker MPM.add(createAggressiveDCEPass()); // Delete dead instructions
325*9880d681SAndroid Build Coastguard Worker MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
326*9880d681SAndroid Build Coastguard Worker // Clean up after everything.
327*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(MPM);
328*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_Peephole, MPM);
329*9880d681SAndroid Build Coastguard Worker }
330*9880d681SAndroid Build Coastguard Worker
populateModulePassManager(legacy::PassManagerBase & MPM)331*9880d681SAndroid Build Coastguard Worker void PassManagerBuilder::populateModulePassManager(
332*9880d681SAndroid Build Coastguard Worker legacy::PassManagerBase &MPM) {
333*9880d681SAndroid Build Coastguard Worker // Allow forcing function attributes as a debugging and tuning aid.
334*9880d681SAndroid Build Coastguard Worker MPM.add(createForceFunctionAttrsLegacyPass());
335*9880d681SAndroid Build Coastguard Worker
336*9880d681SAndroid Build Coastguard Worker // If all optimizations are disabled, just run the always-inline pass and,
337*9880d681SAndroid Build Coastguard Worker // if enabled, the function merging pass.
338*9880d681SAndroid Build Coastguard Worker if (OptLevel == 0) {
339*9880d681SAndroid Build Coastguard Worker addPGOInstrPasses(MPM);
340*9880d681SAndroid Build Coastguard Worker if (Inliner) {
341*9880d681SAndroid Build Coastguard Worker MPM.add(Inliner);
342*9880d681SAndroid Build Coastguard Worker Inliner = nullptr;
343*9880d681SAndroid Build Coastguard Worker }
344*9880d681SAndroid Build Coastguard Worker
345*9880d681SAndroid Build Coastguard Worker // FIXME: The BarrierNoopPass is a HACK! The inliner pass above implicitly
346*9880d681SAndroid Build Coastguard Worker // creates a CGSCC pass manager, but we don't want to add extensions into
347*9880d681SAndroid Build Coastguard Worker // that pass manager. To prevent this we insert a no-op module pass to reset
348*9880d681SAndroid Build Coastguard Worker // the pass manager to get the same behavior as EP_OptimizerLast in non-O0
349*9880d681SAndroid Build Coastguard Worker // builds. The function merging pass is
350*9880d681SAndroid Build Coastguard Worker if (MergeFunctions)
351*9880d681SAndroid Build Coastguard Worker MPM.add(createMergeFunctionsPass());
352*9880d681SAndroid Build Coastguard Worker else if (!GlobalExtensions->empty() || !Extensions.empty())
353*9880d681SAndroid Build Coastguard Worker MPM.add(createBarrierNoopPass());
354*9880d681SAndroid Build Coastguard Worker
355*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
356*9880d681SAndroid Build Coastguard Worker return;
357*9880d681SAndroid Build Coastguard Worker }
358*9880d681SAndroid Build Coastguard Worker
359*9880d681SAndroid Build Coastguard Worker // Add LibraryInfo if we have some.
360*9880d681SAndroid Build Coastguard Worker if (LibraryInfo)
361*9880d681SAndroid Build Coastguard Worker MPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
362*9880d681SAndroid Build Coastguard Worker
363*9880d681SAndroid Build Coastguard Worker addInitialAliasAnalysisPasses(MPM);
364*9880d681SAndroid Build Coastguard Worker
365*9880d681SAndroid Build Coastguard Worker if (!DisableUnitAtATime) {
366*9880d681SAndroid Build Coastguard Worker // Infer attributes about declarations if possible.
367*9880d681SAndroid Build Coastguard Worker MPM.add(createInferFunctionAttrsLegacyPass());
368*9880d681SAndroid Build Coastguard Worker
369*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_ModuleOptimizerEarly, MPM);
370*9880d681SAndroid Build Coastguard Worker
371*9880d681SAndroid Build Coastguard Worker MPM.add(createIPSCCPPass()); // IP SCCP
372*9880d681SAndroid Build Coastguard Worker MPM.add(createGlobalOptimizerPass()); // Optimize out global vars
373*9880d681SAndroid Build Coastguard Worker // Promote any localized global vars.
374*9880d681SAndroid Build Coastguard Worker MPM.add(createPromoteMemoryToRegisterPass());
375*9880d681SAndroid Build Coastguard Worker
376*9880d681SAndroid Build Coastguard Worker MPM.add(createDeadArgEliminationPass()); // Dead argument elimination
377*9880d681SAndroid Build Coastguard Worker
378*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(MPM); // Clean up after IPCP & DAE
379*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_Peephole, MPM);
380*9880d681SAndroid Build Coastguard Worker MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
381*9880d681SAndroid Build Coastguard Worker }
382*9880d681SAndroid Build Coastguard Worker
383*9880d681SAndroid Build Coastguard Worker if (!PerformThinLTO) {
384*9880d681SAndroid Build Coastguard Worker /// PGO instrumentation is added during the compile phase for ThinLTO, do
385*9880d681SAndroid Build Coastguard Worker /// not run it a second time
386*9880d681SAndroid Build Coastguard Worker addPGOInstrPasses(MPM);
387*9880d681SAndroid Build Coastguard Worker // Indirect call promotion that promotes intra-module targets only.
388*9880d681SAndroid Build Coastguard Worker MPM.add(createPGOIndirectCallPromotionLegacyPass());
389*9880d681SAndroid Build Coastguard Worker }
390*9880d681SAndroid Build Coastguard Worker
391*9880d681SAndroid Build Coastguard Worker if (EnableNonLTOGlobalsModRef)
392*9880d681SAndroid Build Coastguard Worker // We add a module alias analysis pass here. In part due to bugs in the
393*9880d681SAndroid Build Coastguard Worker // analysis infrastructure this "works" in that the analysis stays alive
394*9880d681SAndroid Build Coastguard Worker // for the entire SCC pass run below.
395*9880d681SAndroid Build Coastguard Worker MPM.add(createGlobalsAAWrapperPass());
396*9880d681SAndroid Build Coastguard Worker
397*9880d681SAndroid Build Coastguard Worker // Start of CallGraph SCC passes.
398*9880d681SAndroid Build Coastguard Worker if (!DisableUnitAtATime)
399*9880d681SAndroid Build Coastguard Worker MPM.add(createPruneEHPass()); // Remove dead EH info
400*9880d681SAndroid Build Coastguard Worker if (Inliner) {
401*9880d681SAndroid Build Coastguard Worker MPM.add(Inliner);
402*9880d681SAndroid Build Coastguard Worker Inliner = nullptr;
403*9880d681SAndroid Build Coastguard Worker }
404*9880d681SAndroid Build Coastguard Worker if (!DisableUnitAtATime)
405*9880d681SAndroid Build Coastguard Worker MPM.add(createPostOrderFunctionAttrsLegacyPass());
406*9880d681SAndroid Build Coastguard Worker if (OptLevel > 2)
407*9880d681SAndroid Build Coastguard Worker MPM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args
408*9880d681SAndroid Build Coastguard Worker
409*9880d681SAndroid Build Coastguard Worker addFunctionSimplificationPasses(MPM);
410*9880d681SAndroid Build Coastguard Worker
411*9880d681SAndroid Build Coastguard Worker // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
412*9880d681SAndroid Build Coastguard Worker // pass manager that we are specifically trying to avoid. To prevent this
413*9880d681SAndroid Build Coastguard Worker // we must insert a no-op module pass to reset the pass manager.
414*9880d681SAndroid Build Coastguard Worker MPM.add(createBarrierNoopPass());
415*9880d681SAndroid Build Coastguard Worker
416*9880d681SAndroid Build Coastguard Worker if (!DisableUnitAtATime && OptLevel > 1 && !PrepareForLTO &&
417*9880d681SAndroid Build Coastguard Worker !PrepareForThinLTO)
418*9880d681SAndroid Build Coastguard Worker // Remove avail extern fns and globals definitions if we aren't
419*9880d681SAndroid Build Coastguard Worker // compiling an object file for later LTO. For LTO we want to preserve
420*9880d681SAndroid Build Coastguard Worker // these so they are eligible for inlining at link-time. Note if they
421*9880d681SAndroid Build Coastguard Worker // are unreferenced they will be removed by GlobalDCE later, so
422*9880d681SAndroid Build Coastguard Worker // this only impacts referenced available externally globals.
423*9880d681SAndroid Build Coastguard Worker // Eventually they will be suppressed during codegen, but eliminating
424*9880d681SAndroid Build Coastguard Worker // here enables more opportunity for GlobalDCE as it may make
425*9880d681SAndroid Build Coastguard Worker // globals referenced by available external functions dead
426*9880d681SAndroid Build Coastguard Worker // and saves running remaining passes on the eliminated functions.
427*9880d681SAndroid Build Coastguard Worker MPM.add(createEliminateAvailableExternallyPass());
428*9880d681SAndroid Build Coastguard Worker
429*9880d681SAndroid Build Coastguard Worker if (!DisableUnitAtATime)
430*9880d681SAndroid Build Coastguard Worker MPM.add(createReversePostOrderFunctionAttrsPass());
431*9880d681SAndroid Build Coastguard Worker
432*9880d681SAndroid Build Coastguard Worker // If we are planning to perform ThinLTO later, let's not bloat the code with
433*9880d681SAndroid Build Coastguard Worker // unrolling/vectorization/... now. We'll first run the inliner + CGSCC passes
434*9880d681SAndroid Build Coastguard Worker // during ThinLTO and perform the rest of the optimizations afterward.
435*9880d681SAndroid Build Coastguard Worker if (PrepareForThinLTO) {
436*9880d681SAndroid Build Coastguard Worker // Reduce the size of the IR as much as possible.
437*9880d681SAndroid Build Coastguard Worker MPM.add(createGlobalOptimizerPass());
438*9880d681SAndroid Build Coastguard Worker // Rename anon function to be able to export them in the summary.
439*9880d681SAndroid Build Coastguard Worker MPM.add(createNameAnonFunctionPass());
440*9880d681SAndroid Build Coastguard Worker return;
441*9880d681SAndroid Build Coastguard Worker }
442*9880d681SAndroid Build Coastguard Worker
443*9880d681SAndroid Build Coastguard Worker if (PerformThinLTO)
444*9880d681SAndroid Build Coastguard Worker // Optimize globals now when performing ThinLTO, this enables more
445*9880d681SAndroid Build Coastguard Worker // optimizations later.
446*9880d681SAndroid Build Coastguard Worker MPM.add(createGlobalOptimizerPass());
447*9880d681SAndroid Build Coastguard Worker
448*9880d681SAndroid Build Coastguard Worker // Scheduling LoopVersioningLICM when inlining is over, because after that
449*9880d681SAndroid Build Coastguard Worker // we may see more accurate aliasing. Reason to run this late is that too
450*9880d681SAndroid Build Coastguard Worker // early versioning may prevent further inlining due to increase of code
451*9880d681SAndroid Build Coastguard Worker // size. By placing it just after inlining other optimizations which runs
452*9880d681SAndroid Build Coastguard Worker // later might get benefit of no-alias assumption in clone loop.
453*9880d681SAndroid Build Coastguard Worker if (UseLoopVersioningLICM) {
454*9880d681SAndroid Build Coastguard Worker MPM.add(createLoopVersioningLICMPass()); // Do LoopVersioningLICM
455*9880d681SAndroid Build Coastguard Worker MPM.add(createLICMPass()); // Hoist loop invariants
456*9880d681SAndroid Build Coastguard Worker }
457*9880d681SAndroid Build Coastguard Worker
458*9880d681SAndroid Build Coastguard Worker if (EnableNonLTOGlobalsModRef)
459*9880d681SAndroid Build Coastguard Worker // We add a fresh GlobalsModRef run at this point. This is particularly
460*9880d681SAndroid Build Coastguard Worker // useful as the above will have inlined, DCE'ed, and function-attr
461*9880d681SAndroid Build Coastguard Worker // propagated everything. We should at this point have a reasonably minimal
462*9880d681SAndroid Build Coastguard Worker // and richly annotated call graph. By computing aliasing and mod/ref
463*9880d681SAndroid Build Coastguard Worker // information for all local globals here, the late loop passes and notably
464*9880d681SAndroid Build Coastguard Worker // the vectorizer will be able to use them to help recognize vectorizable
465*9880d681SAndroid Build Coastguard Worker // memory operations.
466*9880d681SAndroid Build Coastguard Worker //
467*9880d681SAndroid Build Coastguard Worker // Note that this relies on a bug in the pass manager which preserves
468*9880d681SAndroid Build Coastguard Worker // a module analysis into a function pass pipeline (and throughout it) so
469*9880d681SAndroid Build Coastguard Worker // long as the first function pass doesn't invalidate the module analysis.
470*9880d681SAndroid Build Coastguard Worker // Thus both Float2Int and LoopRotate have to preserve AliasAnalysis for
471*9880d681SAndroid Build Coastguard Worker // this to work. Fortunately, it is trivial to preserve AliasAnalysis
472*9880d681SAndroid Build Coastguard Worker // (doing nothing preserves it as it is required to be conservatively
473*9880d681SAndroid Build Coastguard Worker // correct in the face of IR changes).
474*9880d681SAndroid Build Coastguard Worker MPM.add(createGlobalsAAWrapperPass());
475*9880d681SAndroid Build Coastguard Worker
476*9880d681SAndroid Build Coastguard Worker if (RunFloat2Int)
477*9880d681SAndroid Build Coastguard Worker MPM.add(createFloat2IntPass());
478*9880d681SAndroid Build Coastguard Worker
479*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_VectorizerStart, MPM);
480*9880d681SAndroid Build Coastguard Worker
481*9880d681SAndroid Build Coastguard Worker // Re-rotate loops in all our loop nests. These may have fallout out of
482*9880d681SAndroid Build Coastguard Worker // rotated form due to GVN or other transformations, and the vectorizer relies
483*9880d681SAndroid Build Coastguard Worker // on the rotated form. Disable header duplication at -Oz.
484*9880d681SAndroid Build Coastguard Worker MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
485*9880d681SAndroid Build Coastguard Worker
486*9880d681SAndroid Build Coastguard Worker // Distribute loops to allow partial vectorization. I.e. isolate dependences
487*9880d681SAndroid Build Coastguard Worker // into separate loop that would otherwise inhibit vectorization. This is
488*9880d681SAndroid Build Coastguard Worker // currently only performed for loops marked with the metadata
489*9880d681SAndroid Build Coastguard Worker // llvm.loop.distribute=true or when -enable-loop-distribute is specified.
490*9880d681SAndroid Build Coastguard Worker MPM.add(createLoopDistributePass(/*ProcessAllLoopsByDefault=*/false));
491*9880d681SAndroid Build Coastguard Worker
492*9880d681SAndroid Build Coastguard Worker MPM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize));
493*9880d681SAndroid Build Coastguard Worker
494*9880d681SAndroid Build Coastguard Worker // Eliminate loads by forwarding stores from the previous iteration to loads
495*9880d681SAndroid Build Coastguard Worker // of the current iteration.
496*9880d681SAndroid Build Coastguard Worker if (EnableLoopLoadElim)
497*9880d681SAndroid Build Coastguard Worker MPM.add(createLoopLoadEliminationPass());
498*9880d681SAndroid Build Coastguard Worker
499*9880d681SAndroid Build Coastguard Worker // FIXME: Because of #pragma vectorize enable, the passes below are always
500*9880d681SAndroid Build Coastguard Worker // inserted in the pipeline, even when the vectorizer doesn't run (ex. when
501*9880d681SAndroid Build Coastguard Worker // on -O1 and no #pragma is found). Would be good to have these two passes
502*9880d681SAndroid Build Coastguard Worker // as function calls, so that we can only pass them when the vectorizer
503*9880d681SAndroid Build Coastguard Worker // changed the code.
504*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(MPM);
505*9880d681SAndroid Build Coastguard Worker if (OptLevel > 1 && ExtraVectorizerPasses) {
506*9880d681SAndroid Build Coastguard Worker // At higher optimization levels, try to clean up any runtime overlap and
507*9880d681SAndroid Build Coastguard Worker // alignment checks inserted by the vectorizer. We want to track correllated
508*9880d681SAndroid Build Coastguard Worker // runtime checks for two inner loops in the same outer loop, fold any
509*9880d681SAndroid Build Coastguard Worker // common computations, hoist loop-invariant aspects out of any outer loop,
510*9880d681SAndroid Build Coastguard Worker // and unswitch the runtime checks if possible. Once hoisted, we may have
511*9880d681SAndroid Build Coastguard Worker // dead (or speculatable) control flows or more combining opportunities.
512*9880d681SAndroid Build Coastguard Worker MPM.add(createEarlyCSEPass());
513*9880d681SAndroid Build Coastguard Worker MPM.add(createCorrelatedValuePropagationPass());
514*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(MPM);
515*9880d681SAndroid Build Coastguard Worker MPM.add(createLICMPass());
516*9880d681SAndroid Build Coastguard Worker MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
517*9880d681SAndroid Build Coastguard Worker MPM.add(createCFGSimplificationPass());
518*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(MPM);
519*9880d681SAndroid Build Coastguard Worker }
520*9880d681SAndroid Build Coastguard Worker
521*9880d681SAndroid Build Coastguard Worker if (RunSLPAfterLoopVectorization) {
522*9880d681SAndroid Build Coastguard Worker if (SLPVectorize) {
523*9880d681SAndroid Build Coastguard Worker MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
524*9880d681SAndroid Build Coastguard Worker if (OptLevel > 1 && ExtraVectorizerPasses) {
525*9880d681SAndroid Build Coastguard Worker MPM.add(createEarlyCSEPass());
526*9880d681SAndroid Build Coastguard Worker }
527*9880d681SAndroid Build Coastguard Worker }
528*9880d681SAndroid Build Coastguard Worker
529*9880d681SAndroid Build Coastguard Worker if (BBVectorize) {
530*9880d681SAndroid Build Coastguard Worker MPM.add(createBBVectorizePass());
531*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(MPM);
532*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_Peephole, MPM);
533*9880d681SAndroid Build Coastguard Worker if (OptLevel > 1 && UseGVNAfterVectorization)
534*9880d681SAndroid Build Coastguard Worker MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
535*9880d681SAndroid Build Coastguard Worker else
536*9880d681SAndroid Build Coastguard Worker MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
537*9880d681SAndroid Build Coastguard Worker
538*9880d681SAndroid Build Coastguard Worker // BBVectorize may have significantly shortened a loop body; unroll again.
539*9880d681SAndroid Build Coastguard Worker if (!DisableUnrollLoops)
540*9880d681SAndroid Build Coastguard Worker MPM.add(createLoopUnrollPass());
541*9880d681SAndroid Build Coastguard Worker }
542*9880d681SAndroid Build Coastguard Worker }
543*9880d681SAndroid Build Coastguard Worker
544*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_Peephole, MPM);
545*9880d681SAndroid Build Coastguard Worker MPM.add(createCFGSimplificationPass());
546*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(MPM);
547*9880d681SAndroid Build Coastguard Worker
548*9880d681SAndroid Build Coastguard Worker if (!DisableUnrollLoops) {
549*9880d681SAndroid Build Coastguard Worker MPM.add(createLoopUnrollPass()); // Unroll small loops
550*9880d681SAndroid Build Coastguard Worker
551*9880d681SAndroid Build Coastguard Worker // LoopUnroll may generate some redundency to cleanup.
552*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(MPM);
553*9880d681SAndroid Build Coastguard Worker
554*9880d681SAndroid Build Coastguard Worker // Runtime unrolling will introduce runtime check in loop prologue. If the
555*9880d681SAndroid Build Coastguard Worker // unrolled loop is a inner loop, then the prologue will be inside the
556*9880d681SAndroid Build Coastguard Worker // outer loop. LICM pass can help to promote the runtime check out if the
557*9880d681SAndroid Build Coastguard Worker // checked value is loop invariant.
558*9880d681SAndroid Build Coastguard Worker MPM.add(createLICMPass());
559*9880d681SAndroid Build Coastguard Worker
560*9880d681SAndroid Build Coastguard Worker // Get rid of LCSSA nodes.
561*9880d681SAndroid Build Coastguard Worker MPM.add(createInstructionSimplifierPass());
562*9880d681SAndroid Build Coastguard Worker }
563*9880d681SAndroid Build Coastguard Worker
564*9880d681SAndroid Build Coastguard Worker // After vectorization and unrolling, assume intrinsics may tell us more
565*9880d681SAndroid Build Coastguard Worker // about pointer alignments.
566*9880d681SAndroid Build Coastguard Worker MPM.add(createAlignmentFromAssumptionsPass());
567*9880d681SAndroid Build Coastguard Worker
568*9880d681SAndroid Build Coastguard Worker if (!DisableUnitAtATime) {
569*9880d681SAndroid Build Coastguard Worker // FIXME: We shouldn't bother with this anymore.
570*9880d681SAndroid Build Coastguard Worker MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
571*9880d681SAndroid Build Coastguard Worker
572*9880d681SAndroid Build Coastguard Worker // GlobalOpt already deletes dead functions and globals, at -O2 try a
573*9880d681SAndroid Build Coastguard Worker // late pass of GlobalDCE. It is capable of deleting dead cycles.
574*9880d681SAndroid Build Coastguard Worker if (OptLevel > 1) {
575*9880d681SAndroid Build Coastguard Worker MPM.add(createGlobalDCEPass()); // Remove dead fns and globals.
576*9880d681SAndroid Build Coastguard Worker MPM.add(createConstantMergePass()); // Merge dup global constants
577*9880d681SAndroid Build Coastguard Worker }
578*9880d681SAndroid Build Coastguard Worker }
579*9880d681SAndroid Build Coastguard Worker
580*9880d681SAndroid Build Coastguard Worker if (MergeFunctions)
581*9880d681SAndroid Build Coastguard Worker MPM.add(createMergeFunctionsPass());
582*9880d681SAndroid Build Coastguard Worker
583*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_OptimizerLast, MPM);
584*9880d681SAndroid Build Coastguard Worker }
585*9880d681SAndroid Build Coastguard Worker
addLTOOptimizationPasses(legacy::PassManagerBase & PM)586*9880d681SAndroid Build Coastguard Worker void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
587*9880d681SAndroid Build Coastguard Worker // Remove unused virtual tables to improve the quality of code generated by
588*9880d681SAndroid Build Coastguard Worker // whole-program devirtualization and bitset lowering.
589*9880d681SAndroid Build Coastguard Worker PM.add(createGlobalDCEPass());
590*9880d681SAndroid Build Coastguard Worker
591*9880d681SAndroid Build Coastguard Worker // Provide AliasAnalysis services for optimizations.
592*9880d681SAndroid Build Coastguard Worker addInitialAliasAnalysisPasses(PM);
593*9880d681SAndroid Build Coastguard Worker
594*9880d681SAndroid Build Coastguard Worker if (ModuleSummary)
595*9880d681SAndroid Build Coastguard Worker PM.add(createFunctionImportPass(ModuleSummary));
596*9880d681SAndroid Build Coastguard Worker
597*9880d681SAndroid Build Coastguard Worker // Allow forcing function attributes as a debugging and tuning aid.
598*9880d681SAndroid Build Coastguard Worker PM.add(createForceFunctionAttrsLegacyPass());
599*9880d681SAndroid Build Coastguard Worker
600*9880d681SAndroid Build Coastguard Worker // Infer attributes about declarations if possible.
601*9880d681SAndroid Build Coastguard Worker PM.add(createInferFunctionAttrsLegacyPass());
602*9880d681SAndroid Build Coastguard Worker
603*9880d681SAndroid Build Coastguard Worker if (OptLevel > 1) {
604*9880d681SAndroid Build Coastguard Worker // Indirect call promotion. This should promote all the targets that are
605*9880d681SAndroid Build Coastguard Worker // left by the earlier promotion pass that promotes intra-module targets.
606*9880d681SAndroid Build Coastguard Worker // This two-step promotion is to save the compile time. For LTO, it should
607*9880d681SAndroid Build Coastguard Worker // produce the same result as if we only do promotion here.
608*9880d681SAndroid Build Coastguard Worker PM.add(createPGOIndirectCallPromotionLegacyPass(true));
609*9880d681SAndroid Build Coastguard Worker
610*9880d681SAndroid Build Coastguard Worker // Propagate constants at call sites into the functions they call. This
611*9880d681SAndroid Build Coastguard Worker // opens opportunities for globalopt (and inlining) by substituting function
612*9880d681SAndroid Build Coastguard Worker // pointers passed as arguments to direct uses of functions.
613*9880d681SAndroid Build Coastguard Worker PM.add(createIPSCCPPass());
614*9880d681SAndroid Build Coastguard Worker }
615*9880d681SAndroid Build Coastguard Worker
616*9880d681SAndroid Build Coastguard Worker // Infer attributes about definitions. The readnone attribute in particular is
617*9880d681SAndroid Build Coastguard Worker // required for virtual constant propagation.
618*9880d681SAndroid Build Coastguard Worker PM.add(createPostOrderFunctionAttrsLegacyPass());
619*9880d681SAndroid Build Coastguard Worker PM.add(createReversePostOrderFunctionAttrsPass());
620*9880d681SAndroid Build Coastguard Worker
621*9880d681SAndroid Build Coastguard Worker // Apply whole-program devirtualization and virtual constant propagation.
622*9880d681SAndroid Build Coastguard Worker PM.add(createWholeProgramDevirtPass());
623*9880d681SAndroid Build Coastguard Worker
624*9880d681SAndroid Build Coastguard Worker // That's all we need at opt level 1.
625*9880d681SAndroid Build Coastguard Worker if (OptLevel == 1)
626*9880d681SAndroid Build Coastguard Worker return;
627*9880d681SAndroid Build Coastguard Worker
628*9880d681SAndroid Build Coastguard Worker // Now that we internalized some globals, see if we can hack on them!
629*9880d681SAndroid Build Coastguard Worker PM.add(createGlobalOptimizerPass());
630*9880d681SAndroid Build Coastguard Worker // Promote any localized global vars.
631*9880d681SAndroid Build Coastguard Worker PM.add(createPromoteMemoryToRegisterPass());
632*9880d681SAndroid Build Coastguard Worker
633*9880d681SAndroid Build Coastguard Worker // Linking modules together can lead to duplicated global constants, only
634*9880d681SAndroid Build Coastguard Worker // keep one copy of each constant.
635*9880d681SAndroid Build Coastguard Worker PM.add(createConstantMergePass());
636*9880d681SAndroid Build Coastguard Worker
637*9880d681SAndroid Build Coastguard Worker // Remove unused arguments from functions.
638*9880d681SAndroid Build Coastguard Worker PM.add(createDeadArgEliminationPass());
639*9880d681SAndroid Build Coastguard Worker
640*9880d681SAndroid Build Coastguard Worker // Reduce the code after globalopt and ipsccp. Both can open up significant
641*9880d681SAndroid Build Coastguard Worker // simplification opportunities, and both can propagate functions through
642*9880d681SAndroid Build Coastguard Worker // function pointers. When this happens, we often have to resolve varargs
643*9880d681SAndroid Build Coastguard Worker // calls, etc, so let instcombine do this.
644*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(PM);
645*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_Peephole, PM);
646*9880d681SAndroid Build Coastguard Worker
647*9880d681SAndroid Build Coastguard Worker // Inline small functions
648*9880d681SAndroid Build Coastguard Worker bool RunInliner = Inliner;
649*9880d681SAndroid Build Coastguard Worker if (RunInliner) {
650*9880d681SAndroid Build Coastguard Worker PM.add(Inliner);
651*9880d681SAndroid Build Coastguard Worker Inliner = nullptr;
652*9880d681SAndroid Build Coastguard Worker }
653*9880d681SAndroid Build Coastguard Worker
654*9880d681SAndroid Build Coastguard Worker PM.add(createPruneEHPass()); // Remove dead EH info.
655*9880d681SAndroid Build Coastguard Worker
656*9880d681SAndroid Build Coastguard Worker // Optimize globals again if we ran the inliner.
657*9880d681SAndroid Build Coastguard Worker if (RunInliner)
658*9880d681SAndroid Build Coastguard Worker PM.add(createGlobalOptimizerPass());
659*9880d681SAndroid Build Coastguard Worker PM.add(createGlobalDCEPass()); // Remove dead functions.
660*9880d681SAndroid Build Coastguard Worker
661*9880d681SAndroid Build Coastguard Worker // If we didn't decide to inline a function, check to see if we can
662*9880d681SAndroid Build Coastguard Worker // transform it to pass arguments by value instead of by reference.
663*9880d681SAndroid Build Coastguard Worker PM.add(createArgumentPromotionPass());
664*9880d681SAndroid Build Coastguard Worker
665*9880d681SAndroid Build Coastguard Worker // The IPO passes may leave cruft around. Clean up after them.
666*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(PM);
667*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_Peephole, PM);
668*9880d681SAndroid Build Coastguard Worker PM.add(createJumpThreadingPass());
669*9880d681SAndroid Build Coastguard Worker
670*9880d681SAndroid Build Coastguard Worker // Break up allocas
671*9880d681SAndroid Build Coastguard Worker PM.add(createSROAPass());
672*9880d681SAndroid Build Coastguard Worker
673*9880d681SAndroid Build Coastguard Worker // Run a few AA driven optimizations here and now, to cleanup the code.
674*9880d681SAndroid Build Coastguard Worker PM.add(createPostOrderFunctionAttrsLegacyPass()); // Add nocapture.
675*9880d681SAndroid Build Coastguard Worker PM.add(createGlobalsAAWrapperPass()); // IP alias analysis.
676*9880d681SAndroid Build Coastguard Worker
677*9880d681SAndroid Build Coastguard Worker PM.add(createLICMPass()); // Hoist loop invariants.
678*9880d681SAndroid Build Coastguard Worker if (EnableMLSM)
679*9880d681SAndroid Build Coastguard Worker PM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds.
680*9880d681SAndroid Build Coastguard Worker PM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies.
681*9880d681SAndroid Build Coastguard Worker PM.add(createMemCpyOptPass()); // Remove dead memcpys.
682*9880d681SAndroid Build Coastguard Worker
683*9880d681SAndroid Build Coastguard Worker // Nuke dead stores.
684*9880d681SAndroid Build Coastguard Worker PM.add(createDeadStoreEliminationPass());
685*9880d681SAndroid Build Coastguard Worker
686*9880d681SAndroid Build Coastguard Worker // More loops are countable; try to optimize them.
687*9880d681SAndroid Build Coastguard Worker PM.add(createIndVarSimplifyPass());
688*9880d681SAndroid Build Coastguard Worker PM.add(createLoopDeletionPass());
689*9880d681SAndroid Build Coastguard Worker if (EnableLoopInterchange)
690*9880d681SAndroid Build Coastguard Worker PM.add(createLoopInterchangePass());
691*9880d681SAndroid Build Coastguard Worker
692*9880d681SAndroid Build Coastguard Worker if (!DisableUnrollLoops)
693*9880d681SAndroid Build Coastguard Worker PM.add(createSimpleLoopUnrollPass()); // Unroll small loops
694*9880d681SAndroid Build Coastguard Worker PM.add(createLoopVectorizePass(true, LoopVectorize));
695*9880d681SAndroid Build Coastguard Worker // The vectorizer may have significantly shortened a loop body; unroll again.
696*9880d681SAndroid Build Coastguard Worker if (!DisableUnrollLoops)
697*9880d681SAndroid Build Coastguard Worker PM.add(createLoopUnrollPass());
698*9880d681SAndroid Build Coastguard Worker
699*9880d681SAndroid Build Coastguard Worker // Now that we've optimized loops (in particular loop induction variables),
700*9880d681SAndroid Build Coastguard Worker // we may have exposed more scalar opportunities. Run parts of the scalar
701*9880d681SAndroid Build Coastguard Worker // optimizer again at this point.
702*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(PM); // Initial cleanup
703*9880d681SAndroid Build Coastguard Worker PM.add(createCFGSimplificationPass()); // if-convert
704*9880d681SAndroid Build Coastguard Worker PM.add(createSCCPPass()); // Propagate exposed constants
705*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(PM); // Clean up again
706*9880d681SAndroid Build Coastguard Worker PM.add(createBitTrackingDCEPass());
707*9880d681SAndroid Build Coastguard Worker
708*9880d681SAndroid Build Coastguard Worker // More scalar chains could be vectorized due to more alias information
709*9880d681SAndroid Build Coastguard Worker if (RunSLPAfterLoopVectorization)
710*9880d681SAndroid Build Coastguard Worker if (SLPVectorize)
711*9880d681SAndroid Build Coastguard Worker PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
712*9880d681SAndroid Build Coastguard Worker
713*9880d681SAndroid Build Coastguard Worker // After vectorization, assume intrinsics may tell us more about pointer
714*9880d681SAndroid Build Coastguard Worker // alignments.
715*9880d681SAndroid Build Coastguard Worker PM.add(createAlignmentFromAssumptionsPass());
716*9880d681SAndroid Build Coastguard Worker
717*9880d681SAndroid Build Coastguard Worker if (LoadCombine)
718*9880d681SAndroid Build Coastguard Worker PM.add(createLoadCombinePass());
719*9880d681SAndroid Build Coastguard Worker
720*9880d681SAndroid Build Coastguard Worker // Cleanup and simplify the code after the scalar optimizations.
721*9880d681SAndroid Build Coastguard Worker addInstructionCombiningPass(PM);
722*9880d681SAndroid Build Coastguard Worker addExtensionsToPM(EP_Peephole, PM);
723*9880d681SAndroid Build Coastguard Worker
724*9880d681SAndroid Build Coastguard Worker PM.add(createJumpThreadingPass());
725*9880d681SAndroid Build Coastguard Worker }
726*9880d681SAndroid Build Coastguard Worker
addLateLTOOptimizationPasses(legacy::PassManagerBase & PM)727*9880d681SAndroid Build Coastguard Worker void PassManagerBuilder::addLateLTOOptimizationPasses(
728*9880d681SAndroid Build Coastguard Worker legacy::PassManagerBase &PM) {
729*9880d681SAndroid Build Coastguard Worker // Delete basic blocks, which optimization passes may have killed.
730*9880d681SAndroid Build Coastguard Worker PM.add(createCFGSimplificationPass());
731*9880d681SAndroid Build Coastguard Worker
732*9880d681SAndroid Build Coastguard Worker // Drop bodies of available externally objects to improve GlobalDCE.
733*9880d681SAndroid Build Coastguard Worker PM.add(createEliminateAvailableExternallyPass());
734*9880d681SAndroid Build Coastguard Worker
735*9880d681SAndroid Build Coastguard Worker // Now that we have optimized the program, discard unreachable functions.
736*9880d681SAndroid Build Coastguard Worker PM.add(createGlobalDCEPass());
737*9880d681SAndroid Build Coastguard Worker
738*9880d681SAndroid Build Coastguard Worker // FIXME: this is profitable (for compiler time) to do at -O0 too, but
739*9880d681SAndroid Build Coastguard Worker // currently it damages debug info.
740*9880d681SAndroid Build Coastguard Worker if (MergeFunctions)
741*9880d681SAndroid Build Coastguard Worker PM.add(createMergeFunctionsPass());
742*9880d681SAndroid Build Coastguard Worker }
743*9880d681SAndroid Build Coastguard Worker
populateThinLTOPassManager(legacy::PassManagerBase & PM)744*9880d681SAndroid Build Coastguard Worker void PassManagerBuilder::populateThinLTOPassManager(
745*9880d681SAndroid Build Coastguard Worker legacy::PassManagerBase &PM) {
746*9880d681SAndroid Build Coastguard Worker PerformThinLTO = true;
747*9880d681SAndroid Build Coastguard Worker
748*9880d681SAndroid Build Coastguard Worker if (VerifyInput)
749*9880d681SAndroid Build Coastguard Worker PM.add(createVerifierPass());
750*9880d681SAndroid Build Coastguard Worker
751*9880d681SAndroid Build Coastguard Worker if (ModuleSummary)
752*9880d681SAndroid Build Coastguard Worker PM.add(createFunctionImportPass(ModuleSummary));
753*9880d681SAndroid Build Coastguard Worker
754*9880d681SAndroid Build Coastguard Worker populateModulePassManager(PM);
755*9880d681SAndroid Build Coastguard Worker
756*9880d681SAndroid Build Coastguard Worker if (VerifyOutput)
757*9880d681SAndroid Build Coastguard Worker PM.add(createVerifierPass());
758*9880d681SAndroid Build Coastguard Worker PerformThinLTO = false;
759*9880d681SAndroid Build Coastguard Worker }
760*9880d681SAndroid Build Coastguard Worker
populateLTOPassManager(legacy::PassManagerBase & PM)761*9880d681SAndroid Build Coastguard Worker void PassManagerBuilder::populateLTOPassManager(legacy::PassManagerBase &PM) {
762*9880d681SAndroid Build Coastguard Worker if (LibraryInfo)
763*9880d681SAndroid Build Coastguard Worker PM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
764*9880d681SAndroid Build Coastguard Worker
765*9880d681SAndroid Build Coastguard Worker if (VerifyInput)
766*9880d681SAndroid Build Coastguard Worker PM.add(createVerifierPass());
767*9880d681SAndroid Build Coastguard Worker
768*9880d681SAndroid Build Coastguard Worker if (OptLevel != 0)
769*9880d681SAndroid Build Coastguard Worker addLTOOptimizationPasses(PM);
770*9880d681SAndroid Build Coastguard Worker
771*9880d681SAndroid Build Coastguard Worker // Create a function that performs CFI checks for cross-DSO calls with targets
772*9880d681SAndroid Build Coastguard Worker // in the current module.
773*9880d681SAndroid Build Coastguard Worker PM.add(createCrossDSOCFIPass());
774*9880d681SAndroid Build Coastguard Worker
775*9880d681SAndroid Build Coastguard Worker // Lower type metadata and the type.test intrinsic. This pass supports Clang's
776*9880d681SAndroid Build Coastguard Worker // control flow integrity mechanisms (-fsanitize=cfi*) and needs to run at
777*9880d681SAndroid Build Coastguard Worker // link time if CFI is enabled. The pass does nothing if CFI is disabled.
778*9880d681SAndroid Build Coastguard Worker PM.add(createLowerTypeTestsPass());
779*9880d681SAndroid Build Coastguard Worker
780*9880d681SAndroid Build Coastguard Worker if (OptLevel != 0)
781*9880d681SAndroid Build Coastguard Worker addLateLTOOptimizationPasses(PM);
782*9880d681SAndroid Build Coastguard Worker
783*9880d681SAndroid Build Coastguard Worker if (VerifyOutput)
784*9880d681SAndroid Build Coastguard Worker PM.add(createVerifierPass());
785*9880d681SAndroid Build Coastguard Worker }
786*9880d681SAndroid Build Coastguard Worker
unwrap(LLVMPassManagerBuilderRef P)787*9880d681SAndroid Build Coastguard Worker inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
788*9880d681SAndroid Build Coastguard Worker return reinterpret_cast<PassManagerBuilder*>(P);
789*9880d681SAndroid Build Coastguard Worker }
790*9880d681SAndroid Build Coastguard Worker
wrap(PassManagerBuilder * P)791*9880d681SAndroid Build Coastguard Worker inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) {
792*9880d681SAndroid Build Coastguard Worker return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
793*9880d681SAndroid Build Coastguard Worker }
794*9880d681SAndroid Build Coastguard Worker
LLVMPassManagerBuilderCreate()795*9880d681SAndroid Build Coastguard Worker LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate() {
796*9880d681SAndroid Build Coastguard Worker PassManagerBuilder *PMB = new PassManagerBuilder();
797*9880d681SAndroid Build Coastguard Worker return wrap(PMB);
798*9880d681SAndroid Build Coastguard Worker }
799*9880d681SAndroid Build Coastguard Worker
LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB)800*9880d681SAndroid Build Coastguard Worker void LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB) {
801*9880d681SAndroid Build Coastguard Worker PassManagerBuilder *Builder = unwrap(PMB);
802*9880d681SAndroid Build Coastguard Worker delete Builder;
803*9880d681SAndroid Build Coastguard Worker }
804*9880d681SAndroid Build Coastguard Worker
805*9880d681SAndroid Build Coastguard Worker void
LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB,unsigned OptLevel)806*9880d681SAndroid Build Coastguard Worker LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB,
807*9880d681SAndroid Build Coastguard Worker unsigned OptLevel) {
808*9880d681SAndroid Build Coastguard Worker PassManagerBuilder *Builder = unwrap(PMB);
809*9880d681SAndroid Build Coastguard Worker Builder->OptLevel = OptLevel;
810*9880d681SAndroid Build Coastguard Worker }
811*9880d681SAndroid Build Coastguard Worker
812*9880d681SAndroid Build Coastguard Worker void
LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB,unsigned SizeLevel)813*9880d681SAndroid Build Coastguard Worker LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB,
814*9880d681SAndroid Build Coastguard Worker unsigned SizeLevel) {
815*9880d681SAndroid Build Coastguard Worker PassManagerBuilder *Builder = unwrap(PMB);
816*9880d681SAndroid Build Coastguard Worker Builder->SizeLevel = SizeLevel;
817*9880d681SAndroid Build Coastguard Worker }
818*9880d681SAndroid Build Coastguard Worker
819*9880d681SAndroid Build Coastguard Worker void
LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB,LLVMBool Value)820*9880d681SAndroid Build Coastguard Worker LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB,
821*9880d681SAndroid Build Coastguard Worker LLVMBool Value) {
822*9880d681SAndroid Build Coastguard Worker PassManagerBuilder *Builder = unwrap(PMB);
823*9880d681SAndroid Build Coastguard Worker Builder->DisableUnitAtATime = Value;
824*9880d681SAndroid Build Coastguard Worker }
825*9880d681SAndroid Build Coastguard Worker
826*9880d681SAndroid Build Coastguard Worker void
LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB,LLVMBool Value)827*9880d681SAndroid Build Coastguard Worker LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB,
828*9880d681SAndroid Build Coastguard Worker LLVMBool Value) {
829*9880d681SAndroid Build Coastguard Worker PassManagerBuilder *Builder = unwrap(PMB);
830*9880d681SAndroid Build Coastguard Worker Builder->DisableUnrollLoops = Value;
831*9880d681SAndroid Build Coastguard Worker }
832*9880d681SAndroid Build Coastguard Worker
833*9880d681SAndroid Build Coastguard Worker void
LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB,LLVMBool Value)834*9880d681SAndroid Build Coastguard Worker LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB,
835*9880d681SAndroid Build Coastguard Worker LLVMBool Value) {
836*9880d681SAndroid Build Coastguard Worker // NOTE: The simplify-libcalls pass has been removed.
837*9880d681SAndroid Build Coastguard Worker }
838*9880d681SAndroid Build Coastguard Worker
839*9880d681SAndroid Build Coastguard Worker void
LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB,unsigned Threshold)840*9880d681SAndroid Build Coastguard Worker LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB,
841*9880d681SAndroid Build Coastguard Worker unsigned Threshold) {
842*9880d681SAndroid Build Coastguard Worker PassManagerBuilder *Builder = unwrap(PMB);
843*9880d681SAndroid Build Coastguard Worker Builder->Inliner = createFunctionInliningPass(Threshold);
844*9880d681SAndroid Build Coastguard Worker }
845*9880d681SAndroid Build Coastguard Worker
846*9880d681SAndroid Build Coastguard Worker void
LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB,LLVMPassManagerRef PM)847*9880d681SAndroid Build Coastguard Worker LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB,
848*9880d681SAndroid Build Coastguard Worker LLVMPassManagerRef PM) {
849*9880d681SAndroid Build Coastguard Worker PassManagerBuilder *Builder = unwrap(PMB);
850*9880d681SAndroid Build Coastguard Worker legacy::FunctionPassManager *FPM = unwrap<legacy::FunctionPassManager>(PM);
851*9880d681SAndroid Build Coastguard Worker Builder->populateFunctionPassManager(*FPM);
852*9880d681SAndroid Build Coastguard Worker }
853*9880d681SAndroid Build Coastguard Worker
854*9880d681SAndroid Build Coastguard Worker void
LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB,LLVMPassManagerRef PM)855*9880d681SAndroid Build Coastguard Worker LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB,
856*9880d681SAndroid Build Coastguard Worker LLVMPassManagerRef PM) {
857*9880d681SAndroid Build Coastguard Worker PassManagerBuilder *Builder = unwrap(PMB);
858*9880d681SAndroid Build Coastguard Worker legacy::PassManagerBase *MPM = unwrap(PM);
859*9880d681SAndroid Build Coastguard Worker Builder->populateModulePassManager(*MPM);
860*9880d681SAndroid Build Coastguard Worker }
861*9880d681SAndroid Build Coastguard Worker
LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,LLVMPassManagerRef PM,LLVMBool Internalize,LLVMBool RunInliner)862*9880d681SAndroid Build Coastguard Worker void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,
863*9880d681SAndroid Build Coastguard Worker LLVMPassManagerRef PM,
864*9880d681SAndroid Build Coastguard Worker LLVMBool Internalize,
865*9880d681SAndroid Build Coastguard Worker LLVMBool RunInliner) {
866*9880d681SAndroid Build Coastguard Worker PassManagerBuilder *Builder = unwrap(PMB);
867*9880d681SAndroid Build Coastguard Worker legacy::PassManagerBase *LPM = unwrap(PM);
868*9880d681SAndroid Build Coastguard Worker
869*9880d681SAndroid Build Coastguard Worker // A small backwards compatibility hack. populateLTOPassManager used to take
870*9880d681SAndroid Build Coastguard Worker // an RunInliner option.
871*9880d681SAndroid Build Coastguard Worker if (RunInliner && !Builder->Inliner)
872*9880d681SAndroid Build Coastguard Worker Builder->Inliner = createFunctionInliningPass();
873*9880d681SAndroid Build Coastguard Worker
874*9880d681SAndroid Build Coastguard Worker Builder->populateLTOPassManager(*LPM);
875*9880d681SAndroid Build Coastguard Worker }
876