[PATCH] D64093: Document legacy pass manager extension points
serge via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 2 12:28:24 PDT 2019
serge-sans-paille created this revision.
serge-sans-paille added a reviewer: xbolva00.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This is a follow-up to https://reviews.llvm.org/rL364937
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D64093
Files:
llvm/docs/ReleaseNotes.rst
llvm/docs/WritingAnLLVMPass.rst
Index: llvm/docs/WritingAnLLVMPass.rst
===================================================================
--- llvm/docs/WritingAnLLVMPass.rst
+++ llvm/docs/WritingAnLLVMPass.rst
@@ -176,6 +176,18 @@
an analysis pass, for example dominator tree pass, then ``true`` is supplied as
the fourth argument.
+If we want to register the pass as a step of an existing pipeline, some extension
+points are provided, e.g. ``PassManagerBuilder::EP_EarlyAsPossible`` to apply our
+pass before any optimization, or ``PassManagerBuilder::EP_FullLinkTimeOptimizationLast``
+to apply it after Link Time Optimizations.
+
+.. code-block:: c++
+
+ static llvm::RegisterStandardPasses Y(
+ llvm::PassManagerBuilder::EP_EarlyAsPossible,
+ [](const llvm::PassManagerBuilder &Builder,
+ llvm::legacy::PassManagerBase &PM) { PM.add(new Hello()); });
+
As a whole, the ``.cpp`` file looks like:
.. code-block:: c++
@@ -183,9 +195,12 @@
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
-
+
+ #include "llvm/IR/LegacyPassManager.h"
+ #include "llvm/Transforms/IPO/PassManagerBuilder.h"
+
using namespace llvm;
-
+
namespace {
struct Hello : public FunctionPass {
static char ID;
@@ -198,12 +213,17 @@
}
}; // end of struct Hello
} // end of anonymous namespace
-
+
char Hello::ID = 0;
static RegisterPass<Hello> X("hello", "Hello World Pass",
false /* Only looks at CFG */,
false /* Analysis Pass */);
+ static RegisterStandardPasses Y(
+ PassManagerBuilder::EP_EarlyAsPossible,
+ [](const PassManagerBuilder &Builder,
+ legacy::PassManagerBase &PM) { PM.add(new Hello()); });
+
Now that it's all together, compile the file with a simple "``gmake``" command
from the top level of your build directory and you should get a new file
"``lib/LLVMHello.so``". Note that everything in this file is
Index: llvm/docs/ReleaseNotes.rst
===================================================================
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -45,6 +45,10 @@
the platform's libc) without specifying ``-ffreestanding`` may need to either
pass ``-fno-builtin-bcmp``, or provide a ``bcmp`` function.
+* Two new extension points, namely ``EP_FullLinkTimeOptimizationEarly`` and
+ ``EP_FullLinkTimeOptimizationLast`` are available for plugins to specialize
+ the legacy pass manager full LTO pipeline.
+
.. NOTE
If you would like to document a larger change, then you can add a
subsection about it right here. You can copy the following boilerplate
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64093.207602.patch
Type: text/x-patch
Size: 2666 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190702/8fed77a5/attachment.bin>
More information about the llvm-commits
mailing list