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

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 25 11:47:25 PDT 2021


aeubanks created this revision.
aeubanks added a reviewer: asbirlea.
Herald added a subscriber: awarzynski.
Herald added a reviewer: ctetreau.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112477

Files:
  llvm/docs/NewPassManager.rst


Index: llvm/docs/NewPassManager.rst
===================================================================
--- llvm/docs/NewPassManager.rst
+++ llvm/docs/NewPassManager.rst
@@ -11,6 +11,43 @@
 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 -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
 ===============================
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112477.382074.patch
Type: text/x-patch
Size: 1732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211025/2fa29245/attachment.bin>


More information about the llvm-commits mailing list