0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 //===- PassManagerBuilder.cpp - Build Standard Pass -----------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 // The LLVM Compiler Infrastructure
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 // This file is distributed under the University of Illinois Open Source
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 // License. See LICENSE.TXT for details.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 // This file defines the PassManagerBuilder class, which is used to set up a
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 // "standard" optimization sequence suitable for languages like C and C++.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 #include "llvm-c/Transforms/PassManagerBuilder.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 #include "llvm/ADT/SmallVector.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 #include "llvm/Analysis/Passes.h"
|
77
|
20 #include "llvm/IR/DataLayout.h"
|
|
21 #include "llvm/IR/Verifier.h"
|
83
|
22 #include "llvm/IR/LegacyPassManager.h"
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 #include "llvm/Support/CommandLine.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 #include "llvm/Support/ManagedStatic.h"
|
83
|
25 #include "llvm/Analysis/TargetLibraryInfo.h"
|
77
|
26 #include "llvm/Target/TargetMachine.h"
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 #include "llvm/Transforms/IPO.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 #include "llvm/Transforms/Scalar.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 #include "llvm/Transforms/Vectorize.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 using namespace llvm;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 static cl::opt<bool>
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 RunLoopVectorization("vectorize-loops", cl::Hidden,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 cl::desc("Run the Loop vectorization passes"));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 static cl::opt<bool>
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 RunSLPVectorization("vectorize-slp", cl::Hidden,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 cl::desc("Run the SLP vectorization passes"));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 static cl::opt<bool>
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 RunBBVectorization("vectorize-slp-aggressive", cl::Hidden,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 cl::desc("Run the BB vectorization passes"));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 static cl::opt<bool>
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 UseGVNAfterVectorization("use-gvn-after-vectorization",
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 cl::init(false), cl::Hidden,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 cl::desc("Run GVN instead of Early CSE after vectorization passes"));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49
|
83
|
50 static cl::opt<bool> ExtraVectorizerPasses(
|
|
51 "extra-vectorizer-passes", cl::init(false), cl::Hidden,
|
|
52 cl::desc("Run cleanup optimization passes after vectorization."));
|
|
53
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 static cl::opt<bool> UseNewSROA("use-new-sroa",
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 cl::init(true), cl::Hidden,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 cl::desc("Enable the new, experimental SROA pass"));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 static cl::opt<bool>
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 RunLoopRerolling("reroll-loops", cl::Hidden,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 cl::desc("Run the loop rerolling pass"));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61
|
77
|
62 static cl::opt<bool> RunLoadCombine("combine-loads", cl::init(false),
|
|
63 cl::Hidden,
|
|
64 cl::desc("Run the load combining pass"));
|
|
65
|
|
66 static cl::opt<bool>
|
|
67 RunSLPAfterLoopVectorization("run-slp-after-loop-vectorization",
|
|
68 cl::init(true), cl::Hidden,
|
|
69 cl::desc("Run the SLP vectorizer (and BB vectorizer) after the Loop "
|
|
70 "vectorizer instead of before"));
|
|
71
|
|
72 static cl::opt<bool> UseCFLAA("use-cfl-aa",
|
|
73 cl::init(false), cl::Hidden,
|
|
74 cl::desc("Enable the new, experimental CFL alias analysis"));
|
|
75
|
83
|
76 static cl::opt<bool>
|
|
77 EnableMLSM("mlsm", cl::init(true), cl::Hidden,
|
|
78 cl::desc("Enable motion of merged load and store"));
|
|
79
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 PassManagerBuilder::PassManagerBuilder() {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 OptLevel = 2;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 SizeLevel = 0;
|
77
|
83 LibraryInfo = nullptr;
|
|
84 Inliner = nullptr;
|
|
85 DisableTailCalls = false;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 DisableUnitAtATime = false;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
87 DisableUnrollLoops = false;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 BBVectorize = RunBBVectorization;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 SLPVectorize = RunSLPVectorization;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 LoopVectorize = RunLoopVectorization;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 RerollLoops = RunLoopRerolling;
|
77
|
92 LoadCombine = RunLoadCombine;
|
|
93 DisableGVNLoadPRE = false;
|
|
94 VerifyInput = false;
|
|
95 VerifyOutput = false;
|
|
96 StripDebug = false;
|
83
|
97 MergeFunctions = false;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 PassManagerBuilder::~PassManagerBuilder() {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101 delete LibraryInfo;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 delete Inliner;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
104
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105 /// Set of global extensions, automatically added as part of the standard set.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106 static ManagedStatic<SmallVector<std::pair<PassManagerBuilder::ExtensionPointTy,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107 PassManagerBuilder::ExtensionFn>, 8> > GlobalExtensions;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109 void PassManagerBuilder::addGlobalExtension(
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110 PassManagerBuilder::ExtensionPointTy Ty,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111 PassManagerBuilder::ExtensionFn Fn) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
112 GlobalExtensions->push_back(std::make_pair(Ty, Fn));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115 void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
116 Extensions.push_back(std::make_pair(Ty, Fn));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119 void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy,
|
83
|
120 legacy::PassManagerBase &PM) const {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
121 for (unsigned i = 0, e = GlobalExtensions->size(); i != e; ++i)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122 if ((*GlobalExtensions)[i].first == ETy)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
123 (*GlobalExtensions)[i].second(*this, PM);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
124 for (unsigned i = 0, e = Extensions.size(); i != e; ++i)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
125 if (Extensions[i].first == ETy)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
126 Extensions[i].second(*this, PM);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
127 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
128
|
83
|
129 void PassManagerBuilder::addInitialAliasAnalysisPasses(
|
|
130 legacy::PassManagerBase &PM) const {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
131 // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
132 // BasicAliasAnalysis wins if they disagree. This is intended to help
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
133 // support "obvious" type-punning idioms.
|
77
|
134 if (UseCFLAA)
|
|
135 PM.add(createCFLAliasAnalysisPass());
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
136 PM.add(createTypeBasedAliasAnalysisPass());
|
77
|
137 PM.add(createScopedNoAliasAAPass());
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
138 PM.add(createBasicAliasAnalysisPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
139 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
140
|
83
|
141 void PassManagerBuilder::populateFunctionPassManager(
|
|
142 legacy::FunctionPassManager &FPM) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
143 addExtensionsToPM(EP_EarlyAsPossible, FPM);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
144
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
145 // Add LibraryInfo if we have some.
|
83
|
146 if (LibraryInfo)
|
|
147 FPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
148
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
149 if (OptLevel == 0) return;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
150
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
151 addInitialAliasAnalysisPasses(FPM);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
152
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
153 FPM.add(createCFGSimplificationPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
154 if (UseNewSROA)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
155 FPM.add(createSROAPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
156 else
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
157 FPM.add(createScalarReplAggregatesPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
158 FPM.add(createEarlyCSEPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
159 FPM.add(createLowerExpectIntrinsicPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
160 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
161
|
83
|
162 void PassManagerBuilder::populateModulePassManager(
|
|
163 legacy::PassManagerBase &MPM) {
|
|
164 // If all optimizations are disabled, just run the always-inline pass and,
|
|
165 // if enabled, the function merging pass.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
166 if (OptLevel == 0) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
167 if (Inliner) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
168 MPM.add(Inliner);
|
77
|
169 Inliner = nullptr;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
170 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
171
|
83
|
172 // FIXME: The BarrierNoopPass is a HACK! The inliner pass above implicitly
|
|
173 // creates a CGSCC pass manager, but we don't want to add extensions into
|
|
174 // that pass manager. To prevent this we insert a no-op module pass to reset
|
|
175 // the pass manager to get the same behavior as EP_OptimizerLast in non-O0
|
|
176 // builds. The function merging pass is
|
|
177 if (MergeFunctions)
|
|
178 MPM.add(createMergeFunctionsPass());
|
|
179 else if (!GlobalExtensions->empty() || !Extensions.empty())
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
180 MPM.add(createBarrierNoopPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
181
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
182 addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
183 return;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
184 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
185
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
186 // Add LibraryInfo if we have some.
|
83
|
187 if (LibraryInfo)
|
|
188 MPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
189
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
190 addInitialAliasAnalysisPasses(MPM);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
191
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
192 if (!DisableUnitAtATime) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
193 addExtensionsToPM(EP_ModuleOptimizerEarly, MPM);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
194
|
77
|
195 MPM.add(createIPSCCPPass()); // IP SCCP
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
196 MPM.add(createGlobalOptimizerPass()); // Optimize out global vars
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
197
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
198 MPM.add(createDeadArgEliminationPass()); // Dead argument elimination
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
199
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
200 MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE
|
77
|
201 addExtensionsToPM(EP_Peephole, MPM);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
202 MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
203 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
204
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
205 // Start of CallGraph SCC passes.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
206 if (!DisableUnitAtATime)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
207 MPM.add(createPruneEHPass()); // Remove dead EH info
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
208 if (Inliner) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
209 MPM.add(Inliner);
|
77
|
210 Inliner = nullptr;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
211 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
212 if (!DisableUnitAtATime)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
213 MPM.add(createFunctionAttrsPass()); // Set readonly/readnone attrs
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
214 if (OptLevel > 2)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
215 MPM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
216
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
217 // Start of function pass.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
218 // Break up aggregate allocas, using SSAUpdater.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
219 if (UseNewSROA)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
220 MPM.add(createSROAPass(/*RequiresDomTree*/ false));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
221 else
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
222 MPM.add(createScalarReplAggregatesPass(-1, false));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
223 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
224 MPM.add(createJumpThreadingPass()); // Thread jumps.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
225 MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
226 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
227 MPM.add(createInstructionCombiningPass()); // Combine silly seq's
|
77
|
228 addExtensionsToPM(EP_Peephole, MPM);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
229
|
77
|
230 if (!DisableTailCalls)
|
|
231 MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
232 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
233 MPM.add(createReassociatePass()); // Reassociate expressions
|
83
|
234 // Rotate Loop - disable header duplication at -Oz
|
|
235 MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
236 MPM.add(createLICMPass()); // Hoist loop invariants
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
237 MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
238 MPM.add(createInstructionCombiningPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
239 MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
240 MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
241 MPM.add(createLoopDeletionPass()); // Delete dead loops
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
242
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
243 if (!DisableUnrollLoops)
|
77
|
244 MPM.add(createSimpleLoopUnrollPass()); // Unroll small loops
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
245 addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
246
|
77
|
247 if (OptLevel > 1) {
|
83
|
248 if (EnableMLSM)
|
|
249 MPM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds
|
77
|
250 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
|
|
251 }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
252 MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
253 MPM.add(createSCCPPass()); // Constant prop with SCCP
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
254
|
83
|
255 // Delete dead bit computations (instcombine runs after to fold away the dead
|
|
256 // computations, and then ADCE will run later to exploit any new DCE
|
|
257 // opportunities that creates).
|
|
258 MPM.add(createBitTrackingDCEPass()); // Delete dead bit computations
|
|
259
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
260 // Run instcombine after redundancy elimination to exploit opportunities
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
261 // opened up by them.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
262 MPM.add(createInstructionCombiningPass());
|
77
|
263 addExtensionsToPM(EP_Peephole, MPM);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
264 MPM.add(createJumpThreadingPass()); // Thread jumps
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
265 MPM.add(createCorrelatedValuePropagationPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
266 MPM.add(createDeadStoreEliminationPass()); // Delete dead stores
|
83
|
267 MPM.add(createLICMPass());
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
268
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
269 addExtensionsToPM(EP_ScalarOptimizerLate, MPM);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
270
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
271 if (RerollLoops)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
272 MPM.add(createLoopRerollPass());
|
77
|
273 if (!RunSLPAfterLoopVectorization) {
|
|
274 if (SLPVectorize)
|
|
275 MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
276
|
77
|
277 if (BBVectorize) {
|
|
278 MPM.add(createBBVectorizePass());
|
|
279 MPM.add(createInstructionCombiningPass());
|
|
280 addExtensionsToPM(EP_Peephole, MPM);
|
|
281 if (OptLevel > 1 && UseGVNAfterVectorization)
|
|
282 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
|
|
283 else
|
|
284 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
285
|
77
|
286 // BBVectorize may have significantly shortened a loop body; unroll again.
|
|
287 if (!DisableUnrollLoops)
|
|
288 MPM.add(createLoopUnrollPass());
|
|
289 }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
290 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
291
|
77
|
292 if (LoadCombine)
|
|
293 MPM.add(createLoadCombinePass());
|
|
294
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
295 MPM.add(createAggressiveDCEPass()); // Delete dead instructions
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
296 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
297 MPM.add(createInstructionCombiningPass()); // Clean up after everything.
|
77
|
298 addExtensionsToPM(EP_Peephole, MPM);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
299
|
33
|
300 // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
|
|
301 // pass manager that we are specifically trying to avoid. To prevent this
|
|
302 // we must insert a no-op module pass to reset the pass manager.
|
|
303 MPM.add(createBarrierNoopPass());
|
83
|
304
|
|
305 // Re-rotate loops in all our loop nests. These may have fallout out of
|
|
306 // rotated form due to GVN or other transformations, and the vectorizer relies
|
|
307 // on the rotated form.
|
|
308 if (ExtraVectorizerPasses)
|
|
309 MPM.add(createLoopRotatePass());
|
|
310
|
33
|
311 MPM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize));
|
|
312 // FIXME: Because of #pragma vectorize enable, the passes below are always
|
|
313 // inserted in the pipeline, even when the vectorizer doesn't run (ex. when
|
|
314 // on -O1 and no #pragma is found). Would be good to have these two passes
|
|
315 // as function calls, so that we can only pass them when the vectorizer
|
|
316 // changed the code.
|
|
317 MPM.add(createInstructionCombiningPass());
|
83
|
318 if (OptLevel > 1 && ExtraVectorizerPasses) {
|
|
319 // At higher optimization levels, try to clean up any runtime overlap and
|
|
320 // alignment checks inserted by the vectorizer. We want to track correllated
|
|
321 // runtime checks for two inner loops in the same outer loop, fold any
|
|
322 // common computations, hoist loop-invariant aspects out of any outer loop,
|
|
323 // and unswitch the runtime checks if possible. Once hoisted, we may have
|
|
324 // dead (or speculatable) control flows or more combining opportunities.
|
|
325 MPM.add(createEarlyCSEPass());
|
|
326 MPM.add(createCorrelatedValuePropagationPass());
|
|
327 MPM.add(createInstructionCombiningPass());
|
|
328 MPM.add(createLICMPass());
|
|
329 MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
|
|
330 MPM.add(createCFGSimplificationPass());
|
|
331 MPM.add(createInstructionCombiningPass());
|
|
332 }
|
77
|
333
|
|
334 if (RunSLPAfterLoopVectorization) {
|
83
|
335 if (SLPVectorize) {
|
77
|
336 MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
|
83
|
337 if (OptLevel > 1 && ExtraVectorizerPasses) {
|
|
338 MPM.add(createEarlyCSEPass());
|
|
339 }
|
|
340 }
|
77
|
341
|
|
342 if (BBVectorize) {
|
|
343 MPM.add(createBBVectorizePass());
|
|
344 MPM.add(createInstructionCombiningPass());
|
|
345 addExtensionsToPM(EP_Peephole, MPM);
|
|
346 if (OptLevel > 1 && UseGVNAfterVectorization)
|
|
347 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
|
|
348 else
|
|
349 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
|
|
350
|
|
351 // BBVectorize may have significantly shortened a loop body; unroll again.
|
|
352 if (!DisableUnrollLoops)
|
|
353 MPM.add(createLoopUnrollPass());
|
|
354 }
|
|
355 }
|
|
356
|
|
357 addExtensionsToPM(EP_Peephole, MPM);
|
33
|
358 MPM.add(createCFGSimplificationPass());
|
83
|
359 MPM.add(createInstructionCombiningPass());
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
360
|
77
|
361 if (!DisableUnrollLoops)
|
|
362 MPM.add(createLoopUnrollPass()); // Unroll small loops
|
|
363
|
|
364 // After vectorization and unrolling, assume intrinsics may tell us more
|
|
365 // about pointer alignments.
|
|
366 MPM.add(createAlignmentFromAssumptionsPass());
|
|
367
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
368 if (!DisableUnitAtATime) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
369 // FIXME: We shouldn't bother with this anymore.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
370 MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
371
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
372 // GlobalOpt already deletes dead functions and globals, at -O2 try a
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
373 // late pass of GlobalDCE. It is capable of deleting dead cycles.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
374 if (OptLevel > 1) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
375 MPM.add(createGlobalDCEPass()); // Remove dead fns and globals.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
376 MPM.add(createConstantMergePass()); // Merge dup global constants
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
377 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
378 }
|
83
|
379
|
|
380 if (MergeFunctions)
|
|
381 MPM.add(createMergeFunctionsPass());
|
|
382
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
383 addExtensionsToPM(EP_OptimizerLast, MPM);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
384 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
385
|
83
|
386 void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
387 // Provide AliasAnalysis services for optimizations.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
388 addInitialAliasAnalysisPasses(PM);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
389
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
390 // Propagate constants at call sites into the functions they call. This
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
391 // opens opportunities for globalopt (and inlining) by substituting function
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
392 // pointers passed as arguments to direct uses of functions.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
393 PM.add(createIPSCCPPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
394
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
395 // Now that we internalized some globals, see if we can hack on them!
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
396 PM.add(createGlobalOptimizerPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
397
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
398 // Linking modules together can lead to duplicated global constants, only
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
399 // keep one copy of each constant.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
400 PM.add(createConstantMergePass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
401
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
402 // Remove unused arguments from functions.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
403 PM.add(createDeadArgEliminationPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
404
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
405 // Reduce the code after globalopt and ipsccp. Both can open up significant
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
406 // simplification opportunities, and both can propagate functions through
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
407 // function pointers. When this happens, we often have to resolve varargs
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
408 // calls, etc, so let instcombine do this.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
409 PM.add(createInstructionCombiningPass());
|
77
|
410 addExtensionsToPM(EP_Peephole, PM);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
411
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
412 // Inline small functions
|
77
|
413 bool RunInliner = Inliner;
|
|
414 if (RunInliner) {
|
|
415 PM.add(Inliner);
|
|
416 Inliner = nullptr;
|
|
417 }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
418
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
419 PM.add(createPruneEHPass()); // Remove dead EH info.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
420
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
421 // Optimize globals again if we ran the inliner.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
422 if (RunInliner)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
423 PM.add(createGlobalOptimizerPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
424 PM.add(createGlobalDCEPass()); // Remove dead functions.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
425
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
426 // If we didn't decide to inline a function, check to see if we can
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
427 // transform it to pass arguments by value instead of by reference.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
428 PM.add(createArgumentPromotionPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
429
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
430 // The IPO passes may leave cruft around. Clean up after them.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
431 PM.add(createInstructionCombiningPass());
|
77
|
432 addExtensionsToPM(EP_Peephole, PM);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
433 PM.add(createJumpThreadingPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
434
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
435 // Break up allocas
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
436 if (UseNewSROA)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
437 PM.add(createSROAPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
438 else
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
439 PM.add(createScalarReplAggregatesPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
440
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
441 // Run a few AA driven optimizations here and now, to cleanup the code.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
442 PM.add(createFunctionAttrsPass()); // Add nocapture.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
443 PM.add(createGlobalsModRefPass()); // IP alias analysis.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
444
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
445 PM.add(createLICMPass()); // Hoist loop invariants.
|
83
|
446 if (EnableMLSM)
|
|
447 PM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
448 PM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
449 PM.add(createMemCpyOptPass()); // Remove dead memcpys.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
450
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
451 // Nuke dead stores.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
452 PM.add(createDeadStoreEliminationPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
453
|
77
|
454 // More loops are countable; try to optimize them.
|
|
455 PM.add(createIndVarSimplifyPass());
|
|
456 PM.add(createLoopDeletionPass());
|
83
|
457 PM.add(createLoopVectorizePass(true, LoopVectorize));
|
77
|
458
|
|
459 // More scalar chains could be vectorized due to more alias information
|
83
|
460 if (RunSLPAfterLoopVectorization)
|
|
461 if (SLPVectorize)
|
|
462 PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
|
77
|
463
|
|
464 // After vectorization, assume intrinsics may tell us more about pointer
|
|
465 // alignments.
|
|
466 PM.add(createAlignmentFromAssumptionsPass());
|
|
467
|
|
468 if (LoadCombine)
|
|
469 PM.add(createLoadCombinePass());
|
|
470
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
471 // Cleanup and simplify the code after the scalar optimizations.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
472 PM.add(createInstructionCombiningPass());
|
77
|
473 addExtensionsToPM(EP_Peephole, PM);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
474
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
475 PM.add(createJumpThreadingPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
476
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
477 // Delete basic blocks, which optimization passes may have killed.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
478 PM.add(createCFGSimplificationPass());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
479
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
480 // Now that we have optimized the program, discard unreachable functions.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
481 PM.add(createGlobalDCEPass());
|
83
|
482
|
|
483 // FIXME: this is profitable (for compiler time) to do at -O0 too, but
|
|
484 // currently it damages debug info.
|
|
485 if (MergeFunctions)
|
|
486 PM.add(createMergeFunctionsPass());
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
487 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
488
|
83
|
489 void PassManagerBuilder::populateLTOPassManager(legacy::PassManagerBase &PM) {
|
77
|
490 if (LibraryInfo)
|
83
|
491 PM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
|
77
|
492
|
|
493 if (VerifyInput)
|
|
494 PM.add(createVerifierPass());
|
|
495
|
|
496 if (StripDebug)
|
|
497 PM.add(createStripSymbolsPass(true));
|
|
498
|
|
499 if (VerifyInput)
|
|
500 PM.add(createDebugInfoVerifierPass());
|
|
501
|
|
502 if (OptLevel != 0)
|
|
503 addLTOOptimizationPasses(PM);
|
|
504
|
|
505 if (VerifyOutput) {
|
|
506 PM.add(createVerifierPass());
|
|
507 PM.add(createDebugInfoVerifierPass());
|
|
508 }
|
|
509 }
|
|
510
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
511 inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
512 return reinterpret_cast<PassManagerBuilder*>(P);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
513 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
514
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
515 inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
516 return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
517 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
518
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
519 LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate() {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
520 PassManagerBuilder *PMB = new PassManagerBuilder();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
521 return wrap(PMB);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
522 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
523
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
524 void LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
525 PassManagerBuilder *Builder = unwrap(PMB);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
526 delete Builder;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
527 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
528
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
529 void
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
530 LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
531 unsigned OptLevel) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
532 PassManagerBuilder *Builder = unwrap(PMB);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
533 Builder->OptLevel = OptLevel;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
534 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
535
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
536 void
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
537 LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
538 unsigned SizeLevel) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
539 PassManagerBuilder *Builder = unwrap(PMB);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
540 Builder->SizeLevel = SizeLevel;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
541 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
542
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
543 void
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
544 LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
545 LLVMBool Value) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
546 PassManagerBuilder *Builder = unwrap(PMB);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
547 Builder->DisableUnitAtATime = Value;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
548 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
549
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
550 void
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
551 LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
552 LLVMBool Value) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
553 PassManagerBuilder *Builder = unwrap(PMB);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
554 Builder->DisableUnrollLoops = Value;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
555 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
556
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
557 void
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
558 LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
559 LLVMBool Value) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
560 // NOTE: The simplify-libcalls pass has been removed.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
561 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
562
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
563 void
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
564 LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
565 unsigned Threshold) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
566 PassManagerBuilder *Builder = unwrap(PMB);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
567 Builder->Inliner = createFunctionInliningPass(Threshold);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
568 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
569
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
570 void
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
571 LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
572 LLVMPassManagerRef PM) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
573 PassManagerBuilder *Builder = unwrap(PMB);
|
83
|
574 legacy::FunctionPassManager *FPM = unwrap<legacy::FunctionPassManager>(PM);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
575 Builder->populateFunctionPassManager(*FPM);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
576 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
577
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
578 void
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
579 LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
580 LLVMPassManagerRef PM) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
581 PassManagerBuilder *Builder = unwrap(PMB);
|
83
|
582 legacy::PassManagerBase *MPM = unwrap(PM);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
583 Builder->populateModulePassManager(*MPM);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
584 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
585
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
586 void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
587 LLVMPassManagerRef PM,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
588 LLVMBool Internalize,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
589 LLVMBool RunInliner) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
590 PassManagerBuilder *Builder = unwrap(PMB);
|
83
|
591 legacy::PassManagerBase *LPM = unwrap(PM);
|
77
|
592
|
|
593 // A small backwards compatibility hack. populateLTOPassManager used to take
|
|
594 // an RunInliner option.
|
|
595 if (RunInliner && !Builder->Inliner)
|
|
596 Builder->Inliner = createFunctionInliningPass();
|
|
597
|
|
598 Builder->populateLTOPassManager(*LPM);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
599 }
|