[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 13:24:48 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGce304a452a8c: [docs][NewPM] Add example C++ code on how to actually use the new PM (authored by aeubanks).
Changed prior to commit:
https://reviews.llvm.org/D112477?vs=382074&id=382103#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112477/new/
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 -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
===============================
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112477.382103.patch
Type: text/x-patch
Size: 1732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211025/552c16f2/attachment.bin>
More information about the llvm-commits
mailing list