Skip to content

Commit

Permalink
[docs][NewPM] Add example C++ code on how to actually use the new PM
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D112477
  • Loading branch information
aeubanks committed Oct 25, 2021
1 parent 9769e97 commit ce304a4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions llvm/docs/NewPassManager.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,43 @@ Overview
For an overview of the new pass manager, see the `blog post
<https://blog.llvm.org/posts/2021-03-26-the-new-pass-manager/>`_.

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 -O2 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
===============================

Expand Down

0 comments on commit ce304a4

Please sign in to comment.