[llvm] ce304a4 - [docs][NewPM] Add example C++ code on how to actually use the new PM

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 25 13:24:45 PDT 2021


Author: Arthur Eubanks
Date: 2021-10-25T13:24:20-07:00
New Revision: ce304a452a8ccd8d4ec75260d8438bbbf3953568

URL: https://github.com/llvm/llvm-project/commit/ce304a452a8ccd8d4ec75260d8438bbbf3953568
DIFF: https://github.com/llvm/llvm-project/commit/ce304a452a8ccd8d4ec75260d8438bbbf3953568.diff

LOG: [docs][NewPM] Add example C++ code on how to actually use the new PM

Differential Revision: https://reviews.llvm.org/D112477

Added: 
    

Modified: 
    llvm/docs/NewPassManager.rst

Removed: 
    


################################################################################
diff  --git a/llvm/docs/NewPassManager.rst b/llvm/docs/NewPassManager.rst
index 55898ef3b1fe..81886857aa8d 100644
--- a/llvm/docs/NewPassManager.rst
+++ b/llvm/docs/NewPassManager.rst
@@ -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
 ===============================
 


        


More information about the llvm-commits mailing list