PassManagerBuilder.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. //===- PassManagerBuilder.cpp - Build Standard Pass -----------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines the PassManagerBuilder class, which is used to set up a
  10. // "standard" optimization sequence suitable for languages like C and C++.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/Transforms/IPO/PassManagerBuilder.h"
  14. #include "llvm-c/Transforms/PassManagerBuilder.h"
  15. #include "llvm/ADT/STLExtras.h"
  16. #include "llvm/ADT/SmallVector.h"
  17. #include "llvm/Analysis/GlobalsModRef.h"
  18. #include "llvm/Analysis/ScopedNoAliasAA.h"
  19. #include "llvm/Analysis/TargetLibraryInfo.h"
  20. #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
  21. #include "llvm/IR/LegacyPassManager.h"
  22. #include "llvm/Support/CommandLine.h"
  23. #include "llvm/Support/ManagedStatic.h"
  24. #include "llvm/Target/CGPassBuilderOption.h"
  25. #include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
  26. #include "llvm/Transforms/IPO.h"
  27. #include "llvm/Transforms/IPO/Attributor.h"
  28. #include "llvm/Transforms/IPO/ForceFunctionAttrs.h"
  29. #include "llvm/Transforms/IPO/FunctionAttrs.h"
  30. #include "llvm/Transforms/IPO/InferFunctionAttrs.h"
  31. #include "llvm/Transforms/InstCombine/InstCombine.h"
  32. #include "llvm/Transforms/Instrumentation.h"
  33. #include "llvm/Transforms/Scalar.h"
  34. #include "llvm/Transforms/Scalar/GVN.h"
  35. #include "llvm/Transforms/Scalar/LICM.h"
  36. #include "llvm/Transforms/Scalar/LoopUnrollPass.h"
  37. #include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h"
  38. #include "llvm/Transforms/Utils.h"
  39. #include "llvm/Transforms/Vectorize.h"
  40. using namespace llvm;
  41. PassManagerBuilder::PassManagerBuilder() {
  42. OptLevel = 2;
  43. SizeLevel = 0;
  44. LibraryInfo = nullptr;
  45. Inliner = nullptr;
  46. DisableUnrollLoops = false;
  47. SLPVectorize = false;
  48. LoopVectorize = true;
  49. LoopsInterleaved = true;
  50. LicmMssaOptCap = SetLicmMssaOptCap;
  51. LicmMssaNoAccForPromotionCap = SetLicmMssaNoAccForPromotionCap;
  52. DisableGVNLoadPRE = false;
  53. ForgetAllSCEVInLoopUnroll = ForgetSCEVInLoopUnroll;
  54. VerifyInput = false;
  55. VerifyOutput = false;
  56. MergeFunctions = false;
  57. DivergentTarget = false;
  58. CallGraphProfile = true;
  59. }
  60. PassManagerBuilder::~PassManagerBuilder() {
  61. delete LibraryInfo;
  62. delete Inliner;
  63. }
  64. void PassManagerBuilder::addInitialAliasAnalysisPasses(
  65. legacy::PassManagerBase &PM) const {
  66. // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
  67. // BasicAliasAnalysis wins if they disagree. This is intended to help
  68. // support "obvious" type-punning idioms.
  69. PM.add(createTypeBasedAAWrapperPass());
  70. PM.add(createScopedNoAliasAAWrapperPass());
  71. }
  72. void PassManagerBuilder::populateFunctionPassManager(
  73. legacy::FunctionPassManager &FPM) {
  74. // Add LibraryInfo if we have some.
  75. if (LibraryInfo)
  76. FPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
  77. if (OptLevel == 0) return;
  78. addInitialAliasAnalysisPasses(FPM);
  79. // Lower llvm.expect to metadata before attempting transforms.
  80. // Compare/branch metadata may alter the behavior of passes like SimplifyCFG.
  81. FPM.add(createLowerExpectIntrinsicPass());
  82. FPM.add(createCFGSimplificationPass());
  83. FPM.add(createSROAPass());
  84. FPM.add(createEarlyCSEPass());
  85. }
  86. void PassManagerBuilder::addFunctionSimplificationPasses(
  87. legacy::PassManagerBase &MPM) {
  88. // Start of function pass.
  89. // Break up aggregate allocas, using SSAUpdater.
  90. assert(OptLevel >= 1 && "Calling function optimizer with no optimization level!");
  91. MPM.add(createSROAPass());
  92. MPM.add(createEarlyCSEPass(true /* Enable mem-ssa. */)); // Catch trivial redundancies
  93. if (OptLevel > 1) {
  94. // Speculative execution if the target has divergent branches; otherwise nop.
  95. MPM.add(createSpeculativeExecutionIfHasBranchDivergencePass());
  96. MPM.add(createJumpThreadingPass()); // Thread jumps.
  97. MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
  98. }
  99. MPM.add(
  100. createCFGSimplificationPass(SimplifyCFGOptions().convertSwitchRangeToICmp(
  101. true))); // Merge & remove BBs
  102. // Combine silly seq's
  103. MPM.add(createInstructionCombiningPass());
  104. if (SizeLevel == 0)
  105. MPM.add(createLibCallsShrinkWrapPass());
  106. // TODO: Investigate the cost/benefit of tail call elimination on debugging.
  107. if (OptLevel > 1)
  108. MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
  109. MPM.add(
  110. createCFGSimplificationPass(SimplifyCFGOptions().convertSwitchRangeToICmp(
  111. true))); // Merge & remove BBs
  112. MPM.add(createReassociatePass()); // Reassociate expressions
  113. // Begin the loop pass pipeline.
  114. // The simple loop unswitch pass relies on separate cleanup passes. Schedule
  115. // them first so when we re-process a loop they run before other loop
  116. // passes.
  117. MPM.add(createLoopInstSimplifyPass());
  118. MPM.add(createLoopSimplifyCFGPass());
  119. // Try to remove as much code from the loop header as possible,
  120. // to reduce amount of IR that will have to be duplicated. However,
  121. // do not perform speculative hoisting the first time as LICM
  122. // will destroy metadata that may not need to be destroyed if run
  123. // after loop rotation.
  124. // TODO: Investigate promotion cap for O1.
  125. MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap,
  126. /*AllowSpeculation=*/false));
  127. // Rotate Loop - disable header duplication at -Oz
  128. MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1, false));
  129. // TODO: Investigate promotion cap for O1.
  130. MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap,
  131. /*AllowSpeculation=*/true));
  132. MPM.add(createSimpleLoopUnswitchLegacyPass(OptLevel == 3));
  133. // FIXME: We break the loop pass pipeline here in order to do full
  134. // simplifycfg. Eventually loop-simplifycfg should be enhanced to replace the
  135. // need for this.
  136. MPM.add(createCFGSimplificationPass(
  137. SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
  138. MPM.add(createInstructionCombiningPass());
  139. // We resume loop passes creating a second loop pipeline here.
  140. MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
  141. MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
  142. MPM.add(createLoopDeletionPass()); // Delete dead loops
  143. // Unroll small loops and perform peeling.
  144. MPM.add(createSimpleLoopUnrollPass(OptLevel, DisableUnrollLoops,
  145. ForgetAllSCEVInLoopUnroll));
  146. // This ends the loop pass pipelines.
  147. // Break up allocas that may now be splittable after loop unrolling.
  148. MPM.add(createSROAPass());
  149. if (OptLevel > 1) {
  150. MPM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds
  151. MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
  152. }
  153. MPM.add(createSCCPPass()); // Constant prop with SCCP
  154. // Delete dead bit computations (instcombine runs after to fold away the dead
  155. // computations, and then ADCE will run later to exploit any new DCE
  156. // opportunities that creates).
  157. MPM.add(createBitTrackingDCEPass()); // Delete dead bit computations
  158. // Run instcombine after redundancy elimination to exploit opportunities
  159. // opened up by them.
  160. MPM.add(createInstructionCombiningPass());
  161. if (OptLevel > 1) {
  162. MPM.add(createJumpThreadingPass()); // Thread jumps
  163. MPM.add(createCorrelatedValuePropagationPass());
  164. }
  165. MPM.add(createAggressiveDCEPass()); // Delete dead instructions
  166. MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset
  167. // TODO: Investigate if this is too expensive at O1.
  168. if (OptLevel > 1) {
  169. MPM.add(createDeadStoreEliminationPass()); // Delete dead stores
  170. MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap,
  171. /*AllowSpeculation=*/true));
  172. }
  173. // Merge & remove BBs and sink & hoist common instructions.
  174. MPM.add(createCFGSimplificationPass(
  175. SimplifyCFGOptions().hoistCommonInsts(true).sinkCommonInsts(true)));
  176. // Clean up after everything.
  177. MPM.add(createInstructionCombiningPass());
  178. }
  179. /// FIXME: Should LTO cause any differences to this set of passes?
  180. void PassManagerBuilder::addVectorPasses(legacy::PassManagerBase &PM,
  181. bool IsFullLTO) {
  182. PM.add(createLoopVectorizePass(!LoopsInterleaved, !LoopVectorize));
  183. if (IsFullLTO) {
  184. // The vectorizer may have significantly shortened a loop body; unroll
  185. // again. Unroll small loops to hide loop backedge latency and saturate any
  186. // parallel execution resources of an out-of-order processor. We also then
  187. // need to clean up redundancies and loop invariant code.
  188. // FIXME: It would be really good to use a loop-integrated instruction
  189. // combiner for cleanup here so that the unrolling and LICM can be pipelined
  190. // across the loop nests.
  191. PM.add(createLoopUnrollPass(OptLevel, DisableUnrollLoops,
  192. ForgetAllSCEVInLoopUnroll));
  193. PM.add(createWarnMissedTransformationsPass());
  194. }
  195. if (!IsFullLTO) {
  196. // Eliminate loads by forwarding stores from the previous iteration to loads
  197. // of the current iteration.
  198. PM.add(createLoopLoadEliminationPass());
  199. }
  200. // Cleanup after the loop optimization passes.
  201. PM.add(createInstructionCombiningPass());
  202. // Now that we've formed fast to execute loop structures, we do further
  203. // optimizations. These are run afterward as they might block doing complex
  204. // analyses and transforms such as what are needed for loop vectorization.
  205. // Cleanup after loop vectorization, etc. Simplification passes like CVP and
  206. // GVN, loop transforms, and others have already run, so it's now better to
  207. // convert to more optimized IR using more aggressive simplify CFG options.
  208. // The extra sinking transform can create larger basic blocks, so do this
  209. // before SLP vectorization.
  210. PM.add(createCFGSimplificationPass(SimplifyCFGOptions()
  211. .forwardSwitchCondToPhi(true)
  212. .convertSwitchRangeToICmp(true)
  213. .convertSwitchToLookupTable(true)
  214. .needCanonicalLoops(false)
  215. .hoistCommonInsts(true)
  216. .sinkCommonInsts(true)));
  217. if (IsFullLTO) {
  218. PM.add(createSCCPPass()); // Propagate exposed constants
  219. PM.add(createInstructionCombiningPass()); // Clean up again
  220. PM.add(createBitTrackingDCEPass());
  221. }
  222. // Optimize parallel scalar instruction chains into SIMD instructions.
  223. if (SLPVectorize) {
  224. PM.add(createSLPVectorizerPass());
  225. }
  226. // Enhance/cleanup vector code.
  227. PM.add(createVectorCombinePass());
  228. if (!IsFullLTO) {
  229. PM.add(createInstructionCombiningPass());
  230. // Unroll small loops
  231. PM.add(createLoopUnrollPass(OptLevel, DisableUnrollLoops,
  232. ForgetAllSCEVInLoopUnroll));
  233. if (!DisableUnrollLoops) {
  234. // LoopUnroll may generate some redundency to cleanup.
  235. PM.add(createInstructionCombiningPass());
  236. // Runtime unrolling will introduce runtime check in loop prologue. If the
  237. // unrolled loop is a inner loop, then the prologue will be inside the
  238. // outer loop. LICM pass can help to promote the runtime check out if the
  239. // checked value is loop invariant.
  240. PM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap,
  241. /*AllowSpeculation=*/true));
  242. }
  243. PM.add(createWarnMissedTransformationsPass());
  244. }
  245. // After vectorization and unrolling, assume intrinsics may tell us more
  246. // about pointer alignments.
  247. PM.add(createAlignmentFromAssumptionsPass());
  248. if (IsFullLTO)
  249. PM.add(createInstructionCombiningPass());
  250. }
  251. void PassManagerBuilder::populateModulePassManager(
  252. legacy::PassManagerBase &MPM) {
  253. MPM.add(createAnnotation2MetadataLegacyPass());
  254. // Allow forcing function attributes as a debugging and tuning aid.
  255. MPM.add(createForceFunctionAttrsLegacyPass());
  256. // If all optimizations are disabled, just run the always-inline pass and,
  257. // if enabled, the function merging pass.
  258. if (OptLevel == 0) {
  259. if (Inliner) {
  260. MPM.add(Inliner);
  261. Inliner = nullptr;
  262. }
  263. // FIXME: The BarrierNoopPass is a HACK! The inliner pass above implicitly
  264. // creates a CGSCC pass manager, but we don't want to add extensions into
  265. // that pass manager. To prevent this we insert a no-op module pass to reset
  266. // the pass manager to get the same behavior as EP_OptimizerLast in non-O0
  267. // builds. The function merging pass is
  268. if (MergeFunctions)
  269. MPM.add(createMergeFunctionsPass());
  270. return;
  271. }
  272. // Add LibraryInfo if we have some.
  273. if (LibraryInfo)
  274. MPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
  275. addInitialAliasAnalysisPasses(MPM);
  276. // Infer attributes about declarations if possible.
  277. MPM.add(createInferFunctionAttrsLegacyPass());
  278. if (OptLevel > 2)
  279. MPM.add(createCallSiteSplittingPass());
  280. MPM.add(createIPSCCPPass()); // IP SCCP
  281. MPM.add(createCalledValuePropagationPass());
  282. MPM.add(createGlobalOptimizerPass()); // Optimize out global vars
  283. // Promote any localized global vars.
  284. MPM.add(createPromoteMemoryToRegisterPass());
  285. MPM.add(createDeadArgEliminationPass()); // Dead argument elimination
  286. MPM.add(createInstructionCombiningPass()); // Clean up after IPCP & DAE
  287. MPM.add(
  288. createCFGSimplificationPass(SimplifyCFGOptions().convertSwitchRangeToICmp(
  289. true))); // Clean up after IPCP & DAE
  290. // We add a module alias analysis pass here. In part due to bugs in the
  291. // analysis infrastructure this "works" in that the analysis stays alive
  292. // for the entire SCC pass run below.
  293. MPM.add(createGlobalsAAWrapperPass());
  294. // Start of CallGraph SCC passes.
  295. bool RunInliner = false;
  296. if (Inliner) {
  297. MPM.add(Inliner);
  298. Inliner = nullptr;
  299. RunInliner = true;
  300. }
  301. MPM.add(createPostOrderFunctionAttrsLegacyPass());
  302. addFunctionSimplificationPasses(MPM);
  303. // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
  304. // pass manager that we are specifically trying to avoid. To prevent this
  305. // we must insert a no-op module pass to reset the pass manager.
  306. MPM.add(createBarrierNoopPass());
  307. if (OptLevel > 1)
  308. // Remove avail extern fns and globals definitions if we aren't
  309. // compiling an object file for later LTO. For LTO we want to preserve
  310. // these so they are eligible for inlining at link-time. Note if they
  311. // are unreferenced they will be removed by GlobalDCE later, so
  312. // this only impacts referenced available externally globals.
  313. // Eventually they will be suppressed during codegen, but eliminating
  314. // here enables more opportunity for GlobalDCE as it may make
  315. // globals referenced by available external functions dead
  316. // and saves running remaining passes on the eliminated functions.
  317. MPM.add(createEliminateAvailableExternallyPass());
  318. MPM.add(createReversePostOrderFunctionAttrsPass());
  319. // The inliner performs some kind of dead code elimination as it goes,
  320. // but there are cases that are not really caught by it. We might
  321. // at some point consider teaching the inliner about them, but it
  322. // is OK for now to run GlobalOpt + GlobalDCE in tandem as their
  323. // benefits generally outweight the cost, making the whole pipeline
  324. // faster.
  325. if (RunInliner) {
  326. MPM.add(createGlobalOptimizerPass());
  327. MPM.add(createGlobalDCEPass());
  328. }
  329. // We add a fresh GlobalsModRef run at this point. This is particularly
  330. // useful as the above will have inlined, DCE'ed, and function-attr
  331. // propagated everything. We should at this point have a reasonably minimal
  332. // and richly annotated call graph. By computing aliasing and mod/ref
  333. // information for all local globals here, the late loop passes and notably
  334. // the vectorizer will be able to use them to help recognize vectorizable
  335. // memory operations.
  336. //
  337. // Note that this relies on a bug in the pass manager which preserves
  338. // a module analysis into a function pass pipeline (and throughout it) so
  339. // long as the first function pass doesn't invalidate the module analysis.
  340. // Thus both Float2Int and LoopRotate have to preserve AliasAnalysis for
  341. // this to work. Fortunately, it is trivial to preserve AliasAnalysis
  342. // (doing nothing preserves it as it is required to be conservatively
  343. // correct in the face of IR changes).
  344. MPM.add(createGlobalsAAWrapperPass());
  345. MPM.add(createFloat2IntPass());
  346. MPM.add(createLowerConstantIntrinsicsPass());
  347. // Re-rotate loops in all our loop nests. These may have fallout out of
  348. // rotated form due to GVN or other transformations, and the vectorizer relies
  349. // on the rotated form. Disable header duplication at -Oz.
  350. MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1, false));
  351. // Distribute loops to allow partial vectorization. I.e. isolate dependences
  352. // into separate loop that would otherwise inhibit vectorization. This is
  353. // currently only performed for loops marked with the metadata
  354. // llvm.loop.distribute=true or when -enable-loop-distribute is specified.
  355. MPM.add(createLoopDistributePass());
  356. addVectorPasses(MPM, /* IsFullLTO */ false);
  357. // FIXME: We shouldn't bother with this anymore.
  358. MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
  359. // GlobalOpt already deletes dead functions and globals, at -O2 try a
  360. // late pass of GlobalDCE. It is capable of deleting dead cycles.
  361. if (OptLevel > 1) {
  362. MPM.add(createGlobalDCEPass()); // Remove dead fns and globals.
  363. MPM.add(createConstantMergePass()); // Merge dup global constants
  364. }
  365. if (MergeFunctions)
  366. MPM.add(createMergeFunctionsPass());
  367. // LoopSink pass sinks instructions hoisted by LICM, which serves as a
  368. // canonicalization pass that enables other optimizations. As a result,
  369. // LoopSink pass needs to be a very late IR pass to avoid undoing LICM
  370. // result too early.
  371. MPM.add(createLoopSinkPass());
  372. // Get rid of LCSSA nodes.
  373. MPM.add(createInstSimplifyLegacyPass());
  374. // This hoists/decomposes div/rem ops. It should run after other sink/hoist
  375. // passes to avoid re-sinking, but before SimplifyCFG because it can allow
  376. // flattening of blocks.
  377. MPM.add(createDivRemPairsPass());
  378. // LoopSink (and other loop passes since the last simplifyCFG) might have
  379. // resulted in single-entry-single-exit or empty blocks. Clean up the CFG.
  380. MPM.add(createCFGSimplificationPass(
  381. SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
  382. }
  383. LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate() {
  384. PassManagerBuilder *PMB = new PassManagerBuilder();
  385. return wrap(PMB);
  386. }
  387. void LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB) {
  388. PassManagerBuilder *Builder = unwrap(PMB);
  389. delete Builder;
  390. }
  391. void
  392. LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB,
  393. unsigned OptLevel) {
  394. PassManagerBuilder *Builder = unwrap(PMB);
  395. Builder->OptLevel = OptLevel;
  396. }
  397. void
  398. LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB,
  399. unsigned SizeLevel) {
  400. PassManagerBuilder *Builder = unwrap(PMB);
  401. Builder->SizeLevel = SizeLevel;
  402. }
  403. void
  404. LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB,
  405. LLVMBool Value) {
  406. // NOTE: The DisableUnitAtATime switch has been removed.
  407. }
  408. void
  409. LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB,
  410. LLVMBool Value) {
  411. PassManagerBuilder *Builder = unwrap(PMB);
  412. Builder->DisableUnrollLoops = Value;
  413. }
  414. void
  415. LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB,
  416. LLVMBool Value) {
  417. // NOTE: The simplify-libcalls pass has been removed.
  418. }
  419. void
  420. LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB,
  421. unsigned Threshold) {
  422. PassManagerBuilder *Builder = unwrap(PMB);
  423. Builder->Inliner = createFunctionInliningPass(Threshold);
  424. }
  425. void
  426. LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB,
  427. LLVMPassManagerRef PM) {
  428. PassManagerBuilder *Builder = unwrap(PMB);
  429. legacy::FunctionPassManager *FPM = unwrap<legacy::FunctionPassManager>(PM);
  430. Builder->populateFunctionPassManager(*FPM);
  431. }
  432. void
  433. LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB,
  434. LLVMPassManagerRef PM) {
  435. PassManagerBuilder *Builder = unwrap(PMB);
  436. legacy::PassManagerBase *MPM = unwrap(PM);
  437. Builder->populateModulePassManager(*MPM);
  438. }