Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 1 | //===- PassManagerBuilder.cpp - Build Standard Pass -----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the PassManagerBuilder class, which is used to set up a |
| 11 | // "standard" optimization sequence suitable for languages like C and C++. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | |
| 16 | #include "llvm/Transforms/IPO/PassManagerBuilder.h" |
Rafael Espindola | 69cb216 | 2011-08-09 22:17:34 +0000 | [diff] [blame] | 17 | #include "llvm-c/Transforms/PassManagerBuilder.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/SmallVector.h" |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 19 | #include "llvm/Analysis/Passes.h" |
Hal Finkel | de5e5ec | 2012-02-01 03:51:43 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/Verifier.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 21 | #include "llvm/PassManager.h" |
Hal Finkel | de5e5ec | 2012-02-01 03:51:43 +0000 | [diff] [blame] | 22 | #include "llvm/Support/CommandLine.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 23 | #include "llvm/Support/ManagedStatic.h" |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetLibraryInfo.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 25 | #include "llvm/Transforms/IPO.h" |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 26 | #include "llvm/Transforms/Scalar.h" |
Hal Finkel | de5e5ec | 2012-02-01 03:51:43 +0000 | [diff] [blame] | 27 | #include "llvm/Transforms/Vectorize.h" |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 28 | |
| 29 | using namespace llvm; |
| 30 | |
Hal Finkel | de5e5ec | 2012-02-01 03:51:43 +0000 | [diff] [blame] | 31 | static cl::opt<bool> |
Andrew Trick | 76c25dc | 2013-03-06 19:04:56 +0000 | [diff] [blame] | 32 | RunLoopVectorization("vectorize-loops", |
Nadav Rotem | 9210cc3 | 2012-10-30 18:37:43 +0000 | [diff] [blame] | 33 | cl::desc("Run the Loop vectorization passes")); |
Nadav Rotem | d233b78 | 2012-10-29 16:36:25 +0000 | [diff] [blame] | 34 | |
| 35 | static cl::opt<bool> |
Nadav Rotem | 1129a83 | 2013-04-15 05:39:58 +0000 | [diff] [blame^] | 36 | RunSLPVectorization("vectorize-slp", |
| 37 | cl::desc("Run the SLP vectorization passes")); |
| 38 | |
| 39 | static cl::opt<bool> |
| 40 | RunBBVectorization("vectorize-slp-aggressive", |
| 41 | cl::desc("Run the BB vectorization passes")); |
Hal Finkel | de5e5ec | 2012-02-01 03:51:43 +0000 | [diff] [blame] | 42 | |
Hal Finkel | 064551e | 2012-04-13 17:15:33 +0000 | [diff] [blame] | 43 | static cl::opt<bool> |
| 44 | UseGVNAfterVectorization("use-gvn-after-vectorization", |
| 45 | cl::init(false), cl::Hidden, |
| 46 | cl::desc("Run GVN instead of Early CSE after vectorization passes")); |
| 47 | |
Chandler Carruth | 713aa94 | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 48 | static cl::opt<bool> UseNewSROA("use-new-sroa", |
Chandler Carruth | 1fe4fae | 2012-10-02 04:24:01 +0000 | [diff] [blame] | 49 | cl::init(true), cl::Hidden, |
Chandler Carruth | 713aa94 | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 50 | cl::desc("Enable the new, experimental SROA pass")); |
| 51 | |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 52 | PassManagerBuilder::PassManagerBuilder() { |
| 53 | OptLevel = 2; |
| 54 | SizeLevel = 0; |
| 55 | LibraryInfo = 0; |
| 56 | Inliner = 0; |
| 57 | DisableSimplifyLibCalls = false; |
| 58 | DisableUnitAtATime = false; |
| 59 | DisableUnrollLoops = false; |
Nadav Rotem | 1129a83 | 2013-04-15 05:39:58 +0000 | [diff] [blame^] | 60 | BBVectorize = RunBBVectorization; |
Nadav Rotem | 8849838 | 2013-04-15 04:54:42 +0000 | [diff] [blame] | 61 | SLPVectorize = RunSLPVectorization; |
Nadav Rotem | d233b78 | 2012-10-29 16:36:25 +0000 | [diff] [blame] | 62 | LoopVectorize = RunLoopVectorization; |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | PassManagerBuilder::~PassManagerBuilder() { |
| 66 | delete LibraryInfo; |
| 67 | delete Inliner; |
| 68 | } |
| 69 | |
David Chisnall | 7a817ea | 2011-08-16 13:58:41 +0000 | [diff] [blame] | 70 | /// Set of global extensions, automatically added as part of the standard set. |
| 71 | static ManagedStatic<SmallVector<std::pair<PassManagerBuilder::ExtensionPointTy, |
| 72 | PassManagerBuilder::ExtensionFn>, 8> > GlobalExtensions; |
| 73 | |
| 74 | void PassManagerBuilder::addGlobalExtension( |
| 75 | PassManagerBuilder::ExtensionPointTy Ty, |
| 76 | PassManagerBuilder::ExtensionFn Fn) { |
| 77 | GlobalExtensions->push_back(std::make_pair(Ty, Fn)); |
| 78 | } |
| 79 | |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 80 | void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) { |
| 81 | Extensions.push_back(std::make_pair(Ty, Fn)); |
| 82 | } |
| 83 | |
| 84 | void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy, |
| 85 | PassManagerBase &PM) const { |
David Chisnall | 7a817ea | 2011-08-16 13:58:41 +0000 | [diff] [blame] | 86 | for (unsigned i = 0, e = GlobalExtensions->size(); i != e; ++i) |
| 87 | if ((*GlobalExtensions)[i].first == ETy) |
| 88 | (*GlobalExtensions)[i].second(*this, PM); |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 89 | for (unsigned i = 0, e = Extensions.size(); i != e; ++i) |
| 90 | if (Extensions[i].first == ETy) |
| 91 | Extensions[i].second(*this, PM); |
| 92 | } |
| 93 | |
| 94 | void |
| 95 | PassManagerBuilder::addInitialAliasAnalysisPasses(PassManagerBase &PM) const { |
| 96 | // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that |
| 97 | // BasicAliasAnalysis wins if they disagree. This is intended to help |
| 98 | // support "obvious" type-punning idioms. |
| 99 | PM.add(createTypeBasedAliasAnalysisPass()); |
| 100 | PM.add(createBasicAliasAnalysisPass()); |
| 101 | } |
| 102 | |
| 103 | void PassManagerBuilder::populateFunctionPassManager(FunctionPassManager &FPM) { |
| 104 | addExtensionsToPM(EP_EarlyAsPossible, FPM); |
| 105 | |
| 106 | // Add LibraryInfo if we have some. |
| 107 | if (LibraryInfo) FPM.add(new TargetLibraryInfo(*LibraryInfo)); |
| 108 | |
| 109 | if (OptLevel == 0) return; |
| 110 | |
| 111 | addInitialAliasAnalysisPasses(FPM); |
| 112 | |
| 113 | FPM.add(createCFGSimplificationPass()); |
Chandler Carruth | 713aa94 | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 114 | if (UseNewSROA) |
| 115 | FPM.add(createSROAPass()); |
| 116 | else |
| 117 | FPM.add(createScalarReplAggregatesPass()); |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 118 | FPM.add(createEarlyCSEPass()); |
| 119 | FPM.add(createLowerExpectIntrinsicPass()); |
| 120 | } |
| 121 | |
| 122 | void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) { |
| 123 | // If all optimizations are disabled, just run the always-inline pass. |
| 124 | if (OptLevel == 0) { |
| 125 | if (Inliner) { |
| 126 | MPM.add(Inliner); |
| 127 | Inliner = 0; |
| 128 | } |
Chandler Carruth | 63a1eb6 | 2012-10-18 08:05:46 +0000 | [diff] [blame] | 129 | |
| 130 | // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC |
| 131 | // pass manager, but we don't want to add extensions into that pass manager. |
| 132 | // To prevent this we must insert a no-op module pass to reset the pass |
| 133 | // manager to get the same behavior as EP_OptimizerLast in non-O0 builds. |
| 134 | if (!GlobalExtensions->empty() || !Extensions.empty()) |
| 135 | MPM.add(createBarrierNoopPass()); |
| 136 | |
Kostya Serebryany | af65a8c | 2011-11-30 22:19:26 +0000 | [diff] [blame] | 137 | addExtensionsToPM(EP_EnabledOnOptLevel0, MPM); |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 138 | return; |
| 139 | } |
| 140 | |
| 141 | // Add LibraryInfo if we have some. |
| 142 | if (LibraryInfo) MPM.add(new TargetLibraryInfo(*LibraryInfo)); |
| 143 | |
| 144 | addInitialAliasAnalysisPasses(MPM); |
| 145 | |
| 146 | if (!DisableUnitAtATime) { |
Dan Gohman | 7d4c87e | 2012-01-17 20:51:32 +0000 | [diff] [blame] | 147 | addExtensionsToPM(EP_ModuleOptimizerEarly, MPM); |
| 148 | |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 149 | MPM.add(createGlobalOptimizerPass()); // Optimize out global vars |
| 150 | |
| 151 | MPM.add(createIPSCCPPass()); // IP SCCP |
| 152 | MPM.add(createDeadArgEliminationPass()); // Dead argument elimination |
| 153 | |
| 154 | MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE |
| 155 | MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE |
| 156 | } |
| 157 | |
| 158 | // Start of CallGraph SCC passes. |
| 159 | if (!DisableUnitAtATime) |
| 160 | MPM.add(createPruneEHPass()); // Remove dead EH info |
| 161 | if (Inliner) { |
| 162 | MPM.add(Inliner); |
| 163 | Inliner = 0; |
| 164 | } |
| 165 | if (!DisableUnitAtATime) |
| 166 | MPM.add(createFunctionAttrsPass()); // Set readonly/readnone attrs |
| 167 | if (OptLevel > 2) |
| 168 | MPM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args |
| 169 | |
| 170 | // Start of function pass. |
| 171 | // Break up aggregate allocas, using SSAUpdater. |
Chandler Carruth | 1c8db50 | 2012-09-15 11:43:14 +0000 | [diff] [blame] | 172 | if (UseNewSROA) |
| 173 | MPM.add(createSROAPass(/*RequiresDomTree*/ false)); |
| 174 | else |
| 175 | MPM.add(createScalarReplAggregatesPass(-1, false)); |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 176 | MPM.add(createEarlyCSEPass()); // Catch trivial redundancies |
| 177 | if (!DisableSimplifyLibCalls) |
| 178 | MPM.add(createSimplifyLibCallsPass()); // Library Call Optimizations |
| 179 | MPM.add(createJumpThreadingPass()); // Thread jumps. |
| 180 | MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals |
| 181 | MPM.add(createCFGSimplificationPass()); // Merge & remove BBs |
| 182 | MPM.add(createInstructionCombiningPass()); // Combine silly seq's |
| 183 | |
| 184 | MPM.add(createTailCallEliminationPass()); // Eliminate tail calls |
| 185 | MPM.add(createCFGSimplificationPass()); // Merge & remove BBs |
| 186 | MPM.add(createReassociatePass()); // Reassociate expressions |
| 187 | MPM.add(createLoopRotatePass()); // Rotate Loop |
| 188 | MPM.add(createLICMPass()); // Hoist loop invariants |
| 189 | MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3)); |
| 190 | MPM.add(createInstructionCombiningPass()); |
| 191 | MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars |
| 192 | MPM.add(createLoopIdiomPass()); // Recognize idioms like memset. |
| 193 | MPM.add(createLoopDeletionPass()); // Delete dead loops |
Nadav Rotem | d15c0c7 | 2012-10-17 18:25:06 +0000 | [diff] [blame] | 194 | |
Nadav Rotem | b7c7729 | 2013-01-04 17:57:44 +0000 | [diff] [blame] | 195 | if (LoopVectorize && OptLevel > 2) |
Nadav Rotem | ae3b652 | 2012-12-12 19:29:45 +0000 | [diff] [blame] | 196 | MPM.add(createLoopVectorizePass()); |
Nadav Rotem | d15c0c7 | 2012-10-17 18:25:06 +0000 | [diff] [blame] | 197 | |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 198 | if (!DisableUnrollLoops) |
| 199 | MPM.add(createLoopUnrollPass()); // Unroll small loops |
| 200 | addExtensionsToPM(EP_LoopOptimizerEnd, MPM); |
| 201 | |
| 202 | if (OptLevel > 1) |
| 203 | MPM.add(createGVNPass()); // Remove redundancies |
| 204 | MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset |
| 205 | MPM.add(createSCCPPass()); // Constant prop with SCCP |
| 206 | |
| 207 | // Run instcombine after redundancy elimination to exploit opportunities |
| 208 | // opened up by them. |
| 209 | MPM.add(createInstructionCombiningPass()); |
| 210 | MPM.add(createJumpThreadingPass()); // Thread jumps |
| 211 | MPM.add(createCorrelatedValuePropagationPass()); |
| 212 | MPM.add(createDeadStoreEliminationPass()); // Delete dead stores |
| 213 | |
| 214 | addExtensionsToPM(EP_ScalarOptimizerLate, MPM); |
| 215 | |
Nadav Rotem | 8849838 | 2013-04-15 04:54:42 +0000 | [diff] [blame] | 216 | if (SLPVectorize) { |
Nadav Rotem | 1129a83 | 2013-04-15 05:39:58 +0000 | [diff] [blame^] | 217 | MPM.add(createSLPVectorizerPass()); |
| 218 | MPM.add(createEarlyCSEPass()); |
| 219 | } |
| 220 | |
| 221 | if (BBVectorize) { |
Hal Finkel | de5e5ec | 2012-02-01 03:51:43 +0000 | [diff] [blame] | 222 | MPM.add(createBBVectorizePass()); |
| 223 | MPM.add(createInstructionCombiningPass()); |
Hal Finkel | 064551e | 2012-04-13 17:15:33 +0000 | [diff] [blame] | 224 | if (OptLevel > 1 && UseGVNAfterVectorization) |
| 225 | MPM.add(createGVNPass()); // Remove redundancies |
| 226 | else |
| 227 | MPM.add(createEarlyCSEPass()); // Catch trivial redundancies |
Hal Finkel | c0b3d4c | 2013-01-29 00:22:49 +0000 | [diff] [blame] | 228 | |
| 229 | // BBVectorize may have significantly shortened a loop body; unroll again. |
| 230 | if (!DisableUnrollLoops) |
| 231 | MPM.add(createLoopUnrollPass()); |
Hal Finkel | de5e5ec | 2012-02-01 03:51:43 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 234 | MPM.add(createAggressiveDCEPass()); // Delete dead instructions |
| 235 | MPM.add(createCFGSimplificationPass()); // Merge & remove BBs |
| 236 | MPM.add(createInstructionCombiningPass()); // Clean up after everything. |
| 237 | |
| 238 | if (!DisableUnitAtATime) { |
| 239 | // FIXME: We shouldn't bother with this anymore. |
| 240 | MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes |
| 241 | |
Evan Cheng | f5fdc14 | 2012-09-28 21:23:26 +0000 | [diff] [blame] | 242 | // GlobalOpt already deletes dead functions and globals, at -O2 try a |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 243 | // late pass of GlobalDCE. It is capable of deleting dead cycles. |
Evan Cheng | f5fdc14 | 2012-09-28 21:23:26 +0000 | [diff] [blame] | 244 | if (OptLevel > 1) { |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 245 | MPM.add(createGlobalDCEPass()); // Remove dead fns and globals. |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 246 | MPM.add(createConstantMergePass()); // Merge dup global constants |
Evan Cheng | f5fdc14 | 2012-09-28 21:23:26 +0000 | [diff] [blame] | 247 | } |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 248 | } |
Kostya Serebryany | 1db3949 | 2012-03-23 23:22:59 +0000 | [diff] [blame] | 249 | addExtensionsToPM(EP_OptimizerLast, MPM); |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM, |
| 253 | bool Internalize, |
Bill Wendling | 3197b44 | 2012-04-02 22:16:50 +0000 | [diff] [blame] | 254 | bool RunInliner, |
| 255 | bool DisableGVNLoadPRE) { |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 256 | // Provide AliasAnalysis services for optimizations. |
| 257 | addInitialAliasAnalysisPasses(PM); |
| 258 | |
| 259 | // Now that composite has been compiled, scan through the module, looking |
| 260 | // for a main function. If main is defined, mark all other functions |
| 261 | // internal. |
Rafael Espindola | e5551ed | 2012-10-26 18:47:48 +0000 | [diff] [blame] | 262 | if (Internalize) { |
| 263 | std::vector<const char*> E; |
| 264 | E.push_back("main"); |
| 265 | PM.add(createInternalizePass(E)); |
| 266 | } |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 267 | |
| 268 | // Propagate constants at call sites into the functions they call. This |
| 269 | // opens opportunities for globalopt (and inlining) by substituting function |
| 270 | // pointers passed as arguments to direct uses of functions. |
| 271 | PM.add(createIPSCCPPass()); |
| 272 | |
| 273 | // Now that we internalized some globals, see if we can hack on them! |
| 274 | PM.add(createGlobalOptimizerPass()); |
| 275 | |
| 276 | // Linking modules together can lead to duplicated global constants, only |
| 277 | // keep one copy of each constant. |
| 278 | PM.add(createConstantMergePass()); |
| 279 | |
| 280 | // Remove unused arguments from functions. |
| 281 | PM.add(createDeadArgEliminationPass()); |
| 282 | |
| 283 | // Reduce the code after globalopt and ipsccp. Both can open up significant |
| 284 | // simplification opportunities, and both can propagate functions through |
| 285 | // function pointers. When this happens, we often have to resolve varargs |
| 286 | // calls, etc, so let instcombine do this. |
| 287 | PM.add(createInstructionCombiningPass()); |
| 288 | |
| 289 | // Inline small functions |
| 290 | if (RunInliner) |
| 291 | PM.add(createFunctionInliningPass()); |
| 292 | |
| 293 | PM.add(createPruneEHPass()); // Remove dead EH info. |
| 294 | |
| 295 | // Optimize globals again if we ran the inliner. |
| 296 | if (RunInliner) |
| 297 | PM.add(createGlobalOptimizerPass()); |
| 298 | PM.add(createGlobalDCEPass()); // Remove dead functions. |
| 299 | |
| 300 | // If we didn't decide to inline a function, check to see if we can |
| 301 | // transform it to pass arguments by value instead of by reference. |
| 302 | PM.add(createArgumentPromotionPass()); |
| 303 | |
| 304 | // The IPO passes may leave cruft around. Clean up after them. |
| 305 | PM.add(createInstructionCombiningPass()); |
| 306 | PM.add(createJumpThreadingPass()); |
| 307 | // Break up allocas |
Chandler Carruth | 713aa94 | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 308 | if (UseNewSROA) |
| 309 | PM.add(createSROAPass()); |
| 310 | else |
| 311 | PM.add(createScalarReplAggregatesPass()); |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 312 | |
| 313 | // Run a few AA driven optimizations here and now, to cleanup the code. |
| 314 | PM.add(createFunctionAttrsPass()); // Add nocapture. |
| 315 | PM.add(createGlobalsModRefPass()); // IP alias analysis. |
| 316 | |
Bill Wendling | 3197b44 | 2012-04-02 22:16:50 +0000 | [diff] [blame] | 317 | PM.add(createLICMPass()); // Hoist loop invariants. |
| 318 | PM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies. |
| 319 | PM.add(createMemCpyOptPass()); // Remove dead memcpys. |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 320 | // Nuke dead stores. |
| 321 | PM.add(createDeadStoreEliminationPass()); |
| 322 | |
| 323 | // Cleanup and simplify the code after the scalar optimizations. |
| 324 | PM.add(createInstructionCombiningPass()); |
| 325 | |
| 326 | PM.add(createJumpThreadingPass()); |
| 327 | |
| 328 | // Delete basic blocks, which optimization passes may have killed. |
| 329 | PM.add(createCFGSimplificationPass()); |
| 330 | |
| 331 | // Now that we have optimized the program, discard unreachable functions. |
| 332 | PM.add(createGlobalDCEPass()); |
| 333 | } |
Rafael Espindola | 69cb216 | 2011-08-09 22:17:34 +0000 | [diff] [blame] | 334 | |
Dmitri Gribenko | 79c07d2 | 2012-11-15 16:51:49 +0000 | [diff] [blame] | 335 | LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate() { |
Rafael Espindola | 69cb216 | 2011-08-09 22:17:34 +0000 | [diff] [blame] | 336 | PassManagerBuilder *PMB = new PassManagerBuilder(); |
| 337 | return wrap(PMB); |
| 338 | } |
| 339 | |
| 340 | void LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB) { |
| 341 | PassManagerBuilder *Builder = unwrap(PMB); |
| 342 | delete Builder; |
| 343 | } |
| 344 | |
| 345 | void |
| 346 | LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB, |
| 347 | unsigned OptLevel) { |
| 348 | PassManagerBuilder *Builder = unwrap(PMB); |
| 349 | Builder->OptLevel = OptLevel; |
| 350 | } |
| 351 | |
| 352 | void |
| 353 | LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB, |
| 354 | unsigned SizeLevel) { |
| 355 | PassManagerBuilder *Builder = unwrap(PMB); |
| 356 | Builder->SizeLevel = SizeLevel; |
| 357 | } |
| 358 | |
| 359 | void |
| 360 | LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB, |
| 361 | LLVMBool Value) { |
| 362 | PassManagerBuilder *Builder = unwrap(PMB); |
| 363 | Builder->DisableUnitAtATime = Value; |
| 364 | } |
| 365 | |
| 366 | void |
| 367 | LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB, |
| 368 | LLVMBool Value) { |
| 369 | PassManagerBuilder *Builder = unwrap(PMB); |
| 370 | Builder->DisableUnrollLoops = Value; |
| 371 | } |
| 372 | |
| 373 | void |
| 374 | LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB, |
| 375 | LLVMBool Value) { |
| 376 | PassManagerBuilder *Builder = unwrap(PMB); |
| 377 | Builder->DisableSimplifyLibCalls = Value; |
| 378 | } |
| 379 | |
| 380 | void |
| 381 | LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB, |
| 382 | unsigned Threshold) { |
| 383 | PassManagerBuilder *Builder = unwrap(PMB); |
| 384 | Builder->Inliner = createFunctionInliningPass(Threshold); |
| 385 | } |
| 386 | |
| 387 | void |
| 388 | LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB, |
| 389 | LLVMPassManagerRef PM) { |
| 390 | PassManagerBuilder *Builder = unwrap(PMB); |
| 391 | FunctionPassManager *FPM = unwrap<FunctionPassManager>(PM); |
| 392 | Builder->populateFunctionPassManager(*FPM); |
| 393 | } |
| 394 | |
| 395 | void |
| 396 | LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB, |
| 397 | LLVMPassManagerRef PM) { |
| 398 | PassManagerBuilder *Builder = unwrap(PMB); |
| 399 | PassManagerBase *MPM = unwrap(PM); |
| 400 | Builder->populateModulePassManager(*MPM); |
| 401 | } |
| 402 | |
| 403 | void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB, |
| 404 | LLVMPassManagerRef PM, |
Nick Lewycky | 0ebc084 | 2013-03-10 21:58:22 +0000 | [diff] [blame] | 405 | LLVMBool Internalize, |
| 406 | LLVMBool RunInliner) { |
Rafael Espindola | 69cb216 | 2011-08-09 22:17:34 +0000 | [diff] [blame] | 407 | PassManagerBuilder *Builder = unwrap(PMB); |
| 408 | PassManagerBase *LPM = unwrap(PM); |
Nick Lewycky | 0ebc084 | 2013-03-10 21:58:22 +0000 | [diff] [blame] | 409 | Builder->populateLTOPassManager(*LPM, Internalize != 0, RunInliner != 0); |
Rafael Espindola | 69cb216 | 2011-08-09 22:17:34 +0000 | [diff] [blame] | 410 | } |