diff --git a/llvm/docs/NewPassManager.rst b/llvm/docs/NewPassManager.rst --- a/llvm/docs/NewPassManager.rst +++ b/llvm/docs/NewPassManager.rst @@ -11,6 +11,43 @@ For an overview of the new pass manager, see the `blog post `_. +Just Tell Me How To Run The Default Optimization Pipeline With The New Pass Manager +=================================================================================== + +.. code-block:: c++ + + // Create the analysis managers. + LoopAnalysisManager LAM; + FunctionAnalysisManager FAM; + CGSCCAnalysisManager CGAM; + ModuleAnalysisManager MAM; + + // Create the new pass manager builder. + // Take a look at the PassBuilder constructor parameters for more + // customization, e.g. specifying a TargetMachine or various debugging + // options. + PassBuilder PB; + + // Make sure to use the default alias analysis pipeline, otherwise we'll end + // up only using a subset of the available analyses. + FAM.registerPass([&] { return PB.buildDefaultAAPipeline(); }); + + // Register all the basic analyses with the managers. + PB.registerModuleAnalyses(MAM); + PB.registerCGSCCAnalyses(CGAM); + PB.registerFunctionAnalyses(FAM); + PB.registerLoopAnalyses(LAM); + PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); + + // Create the pass manager. + // This one corresponds to a typical -O3 optimization pipeline. + ModulePassManager MPM = PB.buildPerModuleDefaultPipeline(OptimizationLevel::O2); + + // Optimize the IR! + MPM.run(MyModule, MAM); + +The C API also supports most of this, see ``llvm-c/Transforms/PassBuilder.h``. + Adding Passes to a Pass Manager ===============================