Mercurial > hg > CbC > CbC_llvm
comparison lib/Transforms/IPO/PassManagerBuilder.cpp @ 83:60c9769439b8 LLVM3.7
LLVM 3.7
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 18 Feb 2015 14:55:36 +0900 |
parents | 54457678186b |
children | 5e5d649e25d2 afa8332a0e37 |
comparison
equal
deleted
inserted
replaced
78:af83660cff7b | 83:60c9769439b8 |
---|---|
17 #include "llvm-c/Transforms/PassManagerBuilder.h" | 17 #include "llvm-c/Transforms/PassManagerBuilder.h" |
18 #include "llvm/ADT/SmallVector.h" | 18 #include "llvm/ADT/SmallVector.h" |
19 #include "llvm/Analysis/Passes.h" | 19 #include "llvm/Analysis/Passes.h" |
20 #include "llvm/IR/DataLayout.h" | 20 #include "llvm/IR/DataLayout.h" |
21 #include "llvm/IR/Verifier.h" | 21 #include "llvm/IR/Verifier.h" |
22 #include "llvm/PassManager.h" | 22 #include "llvm/IR/LegacyPassManager.h" |
23 #include "llvm/Support/CommandLine.h" | 23 #include "llvm/Support/CommandLine.h" |
24 #include "llvm/Support/ManagedStatic.h" | 24 #include "llvm/Support/ManagedStatic.h" |
25 #include "llvm/Target/TargetLibraryInfo.h" | 25 #include "llvm/Analysis/TargetLibraryInfo.h" |
26 #include "llvm/Target/TargetMachine.h" | 26 #include "llvm/Target/TargetMachine.h" |
27 #include "llvm/Target/TargetSubtargetInfo.h" | |
28 #include "llvm/Transforms/IPO.h" | 27 #include "llvm/Transforms/IPO.h" |
29 #include "llvm/Transforms/Scalar.h" | 28 #include "llvm/Transforms/Scalar.h" |
30 #include "llvm/Transforms/Vectorize.h" | 29 #include "llvm/Transforms/Vectorize.h" |
31 | 30 |
32 using namespace llvm; | 31 using namespace llvm; |
45 | 44 |
46 static cl::opt<bool> | 45 static cl::opt<bool> |
47 UseGVNAfterVectorization("use-gvn-after-vectorization", | 46 UseGVNAfterVectorization("use-gvn-after-vectorization", |
48 cl::init(false), cl::Hidden, | 47 cl::init(false), cl::Hidden, |
49 cl::desc("Run GVN instead of Early CSE after vectorization passes")); | 48 cl::desc("Run GVN instead of Early CSE after vectorization passes")); |
49 | |
50 static cl::opt<bool> ExtraVectorizerPasses( | |
51 "extra-vectorizer-passes", cl::init(false), cl::Hidden, | |
52 cl::desc("Run cleanup optimization passes after vectorization.")); | |
50 | 53 |
51 static cl::opt<bool> UseNewSROA("use-new-sroa", | 54 static cl::opt<bool> UseNewSROA("use-new-sroa", |
52 cl::init(true), cl::Hidden, | 55 cl::init(true), cl::Hidden, |
53 cl::desc("Enable the new, experimental SROA pass")); | 56 cl::desc("Enable the new, experimental SROA pass")); |
54 | 57 |
67 "vectorizer instead of before")); | 70 "vectorizer instead of before")); |
68 | 71 |
69 static cl::opt<bool> UseCFLAA("use-cfl-aa", | 72 static cl::opt<bool> UseCFLAA("use-cfl-aa", |
70 cl::init(false), cl::Hidden, | 73 cl::init(false), cl::Hidden, |
71 cl::desc("Enable the new, experimental CFL alias analysis")); | 74 cl::desc("Enable the new, experimental CFL alias analysis")); |
75 | |
76 static cl::opt<bool> | |
77 EnableMLSM("mlsm", cl::init(true), cl::Hidden, | |
78 cl::desc("Enable motion of merged load and store")); | |
72 | 79 |
73 PassManagerBuilder::PassManagerBuilder() { | 80 PassManagerBuilder::PassManagerBuilder() { |
74 OptLevel = 2; | 81 OptLevel = 2; |
75 SizeLevel = 0; | 82 SizeLevel = 0; |
76 LibraryInfo = nullptr; | 83 LibraryInfo = nullptr; |
85 LoadCombine = RunLoadCombine; | 92 LoadCombine = RunLoadCombine; |
86 DisableGVNLoadPRE = false; | 93 DisableGVNLoadPRE = false; |
87 VerifyInput = false; | 94 VerifyInput = false; |
88 VerifyOutput = false; | 95 VerifyOutput = false; |
89 StripDebug = false; | 96 StripDebug = false; |
97 MergeFunctions = false; | |
90 } | 98 } |
91 | 99 |
92 PassManagerBuilder::~PassManagerBuilder() { | 100 PassManagerBuilder::~PassManagerBuilder() { |
93 delete LibraryInfo; | 101 delete LibraryInfo; |
94 delete Inliner; | 102 delete Inliner; |
107 void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) { | 115 void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) { |
108 Extensions.push_back(std::make_pair(Ty, Fn)); | 116 Extensions.push_back(std::make_pair(Ty, Fn)); |
109 } | 117 } |
110 | 118 |
111 void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy, | 119 void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy, |
112 PassManagerBase &PM) const { | 120 legacy::PassManagerBase &PM) const { |
113 for (unsigned i = 0, e = GlobalExtensions->size(); i != e; ++i) | 121 for (unsigned i = 0, e = GlobalExtensions->size(); i != e; ++i) |
114 if ((*GlobalExtensions)[i].first == ETy) | 122 if ((*GlobalExtensions)[i].first == ETy) |
115 (*GlobalExtensions)[i].second(*this, PM); | 123 (*GlobalExtensions)[i].second(*this, PM); |
116 for (unsigned i = 0, e = Extensions.size(); i != e; ++i) | 124 for (unsigned i = 0, e = Extensions.size(); i != e; ++i) |
117 if (Extensions[i].first == ETy) | 125 if (Extensions[i].first == ETy) |
118 Extensions[i].second(*this, PM); | 126 Extensions[i].second(*this, PM); |
119 } | 127 } |
120 | 128 |
121 void | 129 void PassManagerBuilder::addInitialAliasAnalysisPasses( |
122 PassManagerBuilder::addInitialAliasAnalysisPasses(PassManagerBase &PM) const { | 130 legacy::PassManagerBase &PM) const { |
123 // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that | 131 // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that |
124 // BasicAliasAnalysis wins if they disagree. This is intended to help | 132 // BasicAliasAnalysis wins if they disagree. This is intended to help |
125 // support "obvious" type-punning idioms. | 133 // support "obvious" type-punning idioms. |
126 if (UseCFLAA) | 134 if (UseCFLAA) |
127 PM.add(createCFLAliasAnalysisPass()); | 135 PM.add(createCFLAliasAnalysisPass()); |
128 PM.add(createTypeBasedAliasAnalysisPass()); | 136 PM.add(createTypeBasedAliasAnalysisPass()); |
129 PM.add(createScopedNoAliasAAPass()); | 137 PM.add(createScopedNoAliasAAPass()); |
130 PM.add(createBasicAliasAnalysisPass()); | 138 PM.add(createBasicAliasAnalysisPass()); |
131 } | 139 } |
132 | 140 |
133 void PassManagerBuilder::populateFunctionPassManager(FunctionPassManager &FPM) { | 141 void PassManagerBuilder::populateFunctionPassManager( |
142 legacy::FunctionPassManager &FPM) { | |
134 addExtensionsToPM(EP_EarlyAsPossible, FPM); | 143 addExtensionsToPM(EP_EarlyAsPossible, FPM); |
135 | 144 |
136 // Add LibraryInfo if we have some. | 145 // Add LibraryInfo if we have some. |
137 if (LibraryInfo) FPM.add(new TargetLibraryInfo(*LibraryInfo)); | 146 if (LibraryInfo) |
147 FPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo)); | |
138 | 148 |
139 if (OptLevel == 0) return; | 149 if (OptLevel == 0) return; |
140 | 150 |
141 addInitialAliasAnalysisPasses(FPM); | 151 addInitialAliasAnalysisPasses(FPM); |
142 | 152 |
147 FPM.add(createScalarReplAggregatesPass()); | 157 FPM.add(createScalarReplAggregatesPass()); |
148 FPM.add(createEarlyCSEPass()); | 158 FPM.add(createEarlyCSEPass()); |
149 FPM.add(createLowerExpectIntrinsicPass()); | 159 FPM.add(createLowerExpectIntrinsicPass()); |
150 } | 160 } |
151 | 161 |
152 void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) { | 162 void PassManagerBuilder::populateModulePassManager( |
153 // If all optimizations are disabled, just run the always-inline pass. | 163 legacy::PassManagerBase &MPM) { |
164 // If all optimizations are disabled, just run the always-inline pass and, | |
165 // if enabled, the function merging pass. | |
154 if (OptLevel == 0) { | 166 if (OptLevel == 0) { |
155 if (Inliner) { | 167 if (Inliner) { |
156 MPM.add(Inliner); | 168 MPM.add(Inliner); |
157 Inliner = nullptr; | 169 Inliner = nullptr; |
158 } | 170 } |
159 | 171 |
160 // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC | 172 // FIXME: The BarrierNoopPass is a HACK! The inliner pass above implicitly |
161 // pass manager, but we don't want to add extensions into that pass manager. | 173 // creates a CGSCC pass manager, but we don't want to add extensions into |
162 // To prevent this we must insert a no-op module pass to reset the pass | 174 // that pass manager. To prevent this we insert a no-op module pass to reset |
163 // manager to get the same behavior as EP_OptimizerLast in non-O0 builds. | 175 // the pass manager to get the same behavior as EP_OptimizerLast in non-O0 |
164 if (!GlobalExtensions->empty() || !Extensions.empty()) | 176 // builds. The function merging pass is |
177 if (MergeFunctions) | |
178 MPM.add(createMergeFunctionsPass()); | |
179 else if (!GlobalExtensions->empty() || !Extensions.empty()) | |
165 MPM.add(createBarrierNoopPass()); | 180 MPM.add(createBarrierNoopPass()); |
166 | 181 |
167 addExtensionsToPM(EP_EnabledOnOptLevel0, MPM); | 182 addExtensionsToPM(EP_EnabledOnOptLevel0, MPM); |
168 return; | 183 return; |
169 } | 184 } |
170 | 185 |
171 // Add LibraryInfo if we have some. | 186 // Add LibraryInfo if we have some. |
172 if (LibraryInfo) MPM.add(new TargetLibraryInfo(*LibraryInfo)); | 187 if (LibraryInfo) |
188 MPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo)); | |
173 | 189 |
174 addInitialAliasAnalysisPasses(MPM); | 190 addInitialAliasAnalysisPasses(MPM); |
175 | 191 |
176 if (!DisableUnitAtATime) { | 192 if (!DisableUnitAtATime) { |
177 addExtensionsToPM(EP_ModuleOptimizerEarly, MPM); | 193 addExtensionsToPM(EP_ModuleOptimizerEarly, MPM); |
213 | 229 |
214 if (!DisableTailCalls) | 230 if (!DisableTailCalls) |
215 MPM.add(createTailCallEliminationPass()); // Eliminate tail calls | 231 MPM.add(createTailCallEliminationPass()); // Eliminate tail calls |
216 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs | 232 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs |
217 MPM.add(createReassociatePass()); // Reassociate expressions | 233 MPM.add(createReassociatePass()); // Reassociate expressions |
218 MPM.add(createLoopRotatePass()); // Rotate Loop | 234 // Rotate Loop - disable header duplication at -Oz |
235 MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1)); | |
219 MPM.add(createLICMPass()); // Hoist loop invariants | 236 MPM.add(createLICMPass()); // Hoist loop invariants |
220 MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3)); | 237 MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3)); |
221 MPM.add(createInstructionCombiningPass()); | 238 MPM.add(createInstructionCombiningPass()); |
222 MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars | 239 MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars |
223 MPM.add(createLoopIdiomPass()); // Recognize idioms like memset. | 240 MPM.add(createLoopIdiomPass()); // Recognize idioms like memset. |
226 if (!DisableUnrollLoops) | 243 if (!DisableUnrollLoops) |
227 MPM.add(createSimpleLoopUnrollPass()); // Unroll small loops | 244 MPM.add(createSimpleLoopUnrollPass()); // Unroll small loops |
228 addExtensionsToPM(EP_LoopOptimizerEnd, MPM); | 245 addExtensionsToPM(EP_LoopOptimizerEnd, MPM); |
229 | 246 |
230 if (OptLevel > 1) { | 247 if (OptLevel > 1) { |
231 MPM.add(createMergedLoadStoreMotionPass()); // Merge load/stores in diamond | 248 if (EnableMLSM) |
249 MPM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds | |
232 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies | 250 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies |
233 } | 251 } |
234 MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset | 252 MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset |
235 MPM.add(createSCCPPass()); // Constant prop with SCCP | 253 MPM.add(createSCCPPass()); // Constant prop with SCCP |
254 | |
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 | |
236 | 259 |
237 // Run instcombine after redundancy elimination to exploit opportunities | 260 // Run instcombine after redundancy elimination to exploit opportunities |
238 // opened up by them. | 261 // opened up by them. |
239 MPM.add(createInstructionCombiningPass()); | 262 MPM.add(createInstructionCombiningPass()); |
240 addExtensionsToPM(EP_Peephole, MPM); | 263 addExtensionsToPM(EP_Peephole, MPM); |
241 MPM.add(createJumpThreadingPass()); // Thread jumps | 264 MPM.add(createJumpThreadingPass()); // Thread jumps |
242 MPM.add(createCorrelatedValuePropagationPass()); | 265 MPM.add(createCorrelatedValuePropagationPass()); |
243 MPM.add(createDeadStoreEliminationPass()); // Delete dead stores | 266 MPM.add(createDeadStoreEliminationPass()); // Delete dead stores |
267 MPM.add(createLICMPass()); | |
244 | 268 |
245 addExtensionsToPM(EP_ScalarOptimizerLate, MPM); | 269 addExtensionsToPM(EP_ScalarOptimizerLate, MPM); |
246 | 270 |
247 if (RerollLoops) | 271 if (RerollLoops) |
248 MPM.add(createLoopRerollPass()); | 272 MPM.add(createLoopRerollPass()); |
275 | 299 |
276 // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC | 300 // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC |
277 // pass manager that we are specifically trying to avoid. To prevent this | 301 // pass manager that we are specifically trying to avoid. To prevent this |
278 // we must insert a no-op module pass to reset the pass manager. | 302 // we must insert a no-op module pass to reset the pass manager. |
279 MPM.add(createBarrierNoopPass()); | 303 MPM.add(createBarrierNoopPass()); |
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 | |
280 MPM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize)); | 311 MPM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize)); |
281 // FIXME: Because of #pragma vectorize enable, the passes below are always | 312 // FIXME: Because of #pragma vectorize enable, the passes below are always |
282 // inserted in the pipeline, even when the vectorizer doesn't run (ex. when | 313 // inserted in the pipeline, even when the vectorizer doesn't run (ex. when |
283 // on -O1 and no #pragma is found). Would be good to have these two passes | 314 // on -O1 and no #pragma is found). Would be good to have these two passes |
284 // as function calls, so that we can only pass them when the vectorizer | 315 // as function calls, so that we can only pass them when the vectorizer |
285 // changed the code. | 316 // changed the code. |
286 MPM.add(createInstructionCombiningPass()); | 317 MPM.add(createInstructionCombiningPass()); |
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 } | |
287 | 333 |
288 if (RunSLPAfterLoopVectorization) { | 334 if (RunSLPAfterLoopVectorization) { |
289 if (SLPVectorize) | 335 if (SLPVectorize) { |
290 MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains. | 336 MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains. |
337 if (OptLevel > 1 && ExtraVectorizerPasses) { | |
338 MPM.add(createEarlyCSEPass()); | |
339 } | |
340 } | |
291 | 341 |
292 if (BBVectorize) { | 342 if (BBVectorize) { |
293 MPM.add(createBBVectorizePass()); | 343 MPM.add(createBBVectorizePass()); |
294 MPM.add(createInstructionCombiningPass()); | 344 MPM.add(createInstructionCombiningPass()); |
295 addExtensionsToPM(EP_Peephole, MPM); | 345 addExtensionsToPM(EP_Peephole, MPM); |
304 } | 354 } |
305 } | 355 } |
306 | 356 |
307 addExtensionsToPM(EP_Peephole, MPM); | 357 addExtensionsToPM(EP_Peephole, MPM); |
308 MPM.add(createCFGSimplificationPass()); | 358 MPM.add(createCFGSimplificationPass()); |
359 MPM.add(createInstructionCombiningPass()); | |
309 | 360 |
310 if (!DisableUnrollLoops) | 361 if (!DisableUnrollLoops) |
311 MPM.add(createLoopUnrollPass()); // Unroll small loops | 362 MPM.add(createLoopUnrollPass()); // Unroll small loops |
312 | 363 |
313 // After vectorization and unrolling, assume intrinsics may tell us more | 364 // After vectorization and unrolling, assume intrinsics may tell us more |
323 if (OptLevel > 1) { | 374 if (OptLevel > 1) { |
324 MPM.add(createGlobalDCEPass()); // Remove dead fns and globals. | 375 MPM.add(createGlobalDCEPass()); // Remove dead fns and globals. |
325 MPM.add(createConstantMergePass()); // Merge dup global constants | 376 MPM.add(createConstantMergePass()); // Merge dup global constants |
326 } | 377 } |
327 } | 378 } |
379 | |
380 if (MergeFunctions) | |
381 MPM.add(createMergeFunctionsPass()); | |
382 | |
328 addExtensionsToPM(EP_OptimizerLast, MPM); | 383 addExtensionsToPM(EP_OptimizerLast, MPM); |
329 } | 384 } |
330 | 385 |
331 void PassManagerBuilder::addLTOOptimizationPasses(PassManagerBase &PM) { | 386 void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) { |
332 // Provide AliasAnalysis services for optimizations. | 387 // Provide AliasAnalysis services for optimizations. |
333 addInitialAliasAnalysisPasses(PM); | 388 addInitialAliasAnalysisPasses(PM); |
334 | 389 |
335 // Propagate constants at call sites into the functions they call. This | 390 // Propagate constants at call sites into the functions they call. This |
336 // opens opportunities for globalopt (and inlining) by substituting function | 391 // opens opportunities for globalopt (and inlining) by substituting function |
386 // Run a few AA driven optimizations here and now, to cleanup the code. | 441 // Run a few AA driven optimizations here and now, to cleanup the code. |
387 PM.add(createFunctionAttrsPass()); // Add nocapture. | 442 PM.add(createFunctionAttrsPass()); // Add nocapture. |
388 PM.add(createGlobalsModRefPass()); // IP alias analysis. | 443 PM.add(createGlobalsModRefPass()); // IP alias analysis. |
389 | 444 |
390 PM.add(createLICMPass()); // Hoist loop invariants. | 445 PM.add(createLICMPass()); // Hoist loop invariants. |
391 PM.add(createMergedLoadStoreMotionPass()); // Merge load/stores in diamonds | 446 if (EnableMLSM) |
447 PM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds. | |
392 PM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies. | 448 PM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies. |
393 PM.add(createMemCpyOptPass()); // Remove dead memcpys. | 449 PM.add(createMemCpyOptPass()); // Remove dead memcpys. |
394 | 450 |
395 // Nuke dead stores. | 451 // Nuke dead stores. |
396 PM.add(createDeadStoreEliminationPass()); | 452 PM.add(createDeadStoreEliminationPass()); |
397 | 453 |
398 // More loops are countable; try to optimize them. | 454 // More loops are countable; try to optimize them. |
399 PM.add(createIndVarSimplifyPass()); | 455 PM.add(createIndVarSimplifyPass()); |
400 PM.add(createLoopDeletionPass()); | 456 PM.add(createLoopDeletionPass()); |
401 PM.add(createLoopVectorizePass(true, true)); | 457 PM.add(createLoopVectorizePass(true, LoopVectorize)); |
402 | 458 |
403 // More scalar chains could be vectorized due to more alias information | 459 // More scalar chains could be vectorized due to more alias information |
404 PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains. | 460 if (RunSLPAfterLoopVectorization) |
461 if (SLPVectorize) | |
462 PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains. | |
405 | 463 |
406 // After vectorization, assume intrinsics may tell us more about pointer | 464 // After vectorization, assume intrinsics may tell us more about pointer |
407 // alignments. | 465 // alignments. |
408 PM.add(createAlignmentFromAssumptionsPass()); | 466 PM.add(createAlignmentFromAssumptionsPass()); |
409 | 467 |
419 // Delete basic blocks, which optimization passes may have killed. | 477 // Delete basic blocks, which optimization passes may have killed. |
420 PM.add(createCFGSimplificationPass()); | 478 PM.add(createCFGSimplificationPass()); |
421 | 479 |
422 // Now that we have optimized the program, discard unreachable functions. | 480 // Now that we have optimized the program, discard unreachable functions. |
423 PM.add(createGlobalDCEPass()); | 481 PM.add(createGlobalDCEPass()); |
424 } | 482 |
425 | 483 // FIXME: this is profitable (for compiler time) to do at -O0 too, but |
426 void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM, | 484 // currently it damages debug info. |
427 TargetMachine *TM) { | 485 if (MergeFunctions) |
428 if (TM) { | 486 PM.add(createMergeFunctionsPass()); |
429 const DataLayout *DL = TM->getSubtargetImpl()->getDataLayout(); | 487 } |
430 PM.add(new DataLayoutPass(*DL)); | 488 |
431 TM->addAnalysisPasses(PM); | 489 void PassManagerBuilder::populateLTOPassManager(legacy::PassManagerBase &PM) { |
432 } | |
433 | |
434 if (LibraryInfo) | 490 if (LibraryInfo) |
435 PM.add(new TargetLibraryInfo(*LibraryInfo)); | 491 PM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo)); |
436 | 492 |
437 if (VerifyInput) | 493 if (VerifyInput) |
438 PM.add(createVerifierPass()); | 494 PM.add(createVerifierPass()); |
439 | 495 |
440 if (StripDebug) | 496 if (StripDebug) |
513 | 569 |
514 void | 570 void |
515 LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB, | 571 LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB, |
516 LLVMPassManagerRef PM) { | 572 LLVMPassManagerRef PM) { |
517 PassManagerBuilder *Builder = unwrap(PMB); | 573 PassManagerBuilder *Builder = unwrap(PMB); |
518 FunctionPassManager *FPM = unwrap<FunctionPassManager>(PM); | 574 legacy::FunctionPassManager *FPM = unwrap<legacy::FunctionPassManager>(PM); |
519 Builder->populateFunctionPassManager(*FPM); | 575 Builder->populateFunctionPassManager(*FPM); |
520 } | 576 } |
521 | 577 |
522 void | 578 void |
523 LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB, | 579 LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB, |
524 LLVMPassManagerRef PM) { | 580 LLVMPassManagerRef PM) { |
525 PassManagerBuilder *Builder = unwrap(PMB); | 581 PassManagerBuilder *Builder = unwrap(PMB); |
526 PassManagerBase *MPM = unwrap(PM); | 582 legacy::PassManagerBase *MPM = unwrap(PM); |
527 Builder->populateModulePassManager(*MPM); | 583 Builder->populateModulePassManager(*MPM); |
528 } | 584 } |
529 | 585 |
530 void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB, | 586 void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB, |
531 LLVMPassManagerRef PM, | 587 LLVMPassManagerRef PM, |
532 LLVMBool Internalize, | 588 LLVMBool Internalize, |
533 LLVMBool RunInliner) { | 589 LLVMBool RunInliner) { |
534 PassManagerBuilder *Builder = unwrap(PMB); | 590 PassManagerBuilder *Builder = unwrap(PMB); |
535 PassManagerBase *LPM = unwrap(PM); | 591 legacy::PassManagerBase *LPM = unwrap(PM); |
536 | 592 |
537 // A small backwards compatibility hack. populateLTOPassManager used to take | 593 // A small backwards compatibility hack. populateLTOPassManager used to take |
538 // an RunInliner option. | 594 // an RunInliner option. |
539 if (RunInliner && !Builder->Inliner) | 595 if (RunInliner && !Builder->Inliner) |
540 Builder->Inliner = createFunctionInliningPass(); | 596 Builder->Inliner = createFunctionInliningPass(); |