diff options
| author | Serge Guelton <sguelton@redhat.com> | 2019-07-04 14:03:11 +0000 |
|---|---|---|
| committer | Serge Guelton <sguelton@redhat.com> | 2019-07-04 14:03:11 +0000 |
| commit | 85fc597f26c81a187c5514d47ee997bc2ea87b1c (patch) | |
| tree | edf04bb3aa4b96515477b5eff5c1c5de730ea871 /llvm/docs/WritingAnLLVMPass.rst | |
| parent | 5f73e37af8585da5e9d54acb1302c4a394a8147d (diff) | |
| download | bcm5719-llvm-85fc597f26c81a187c5514d47ee997bc2ea87b1c.tar.gz bcm5719-llvm-85fc597f26c81a187c5514d47ee997bc2ea87b1c.zip | |
Document legacy pass manager extension points
Differential Revision: https://reviews.llvm.org/D64093
llvm-svn: 365142
Diffstat (limited to 'llvm/docs/WritingAnLLVMPass.rst')
| -rw-r--r-- | llvm/docs/WritingAnLLVMPass.rst | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/llvm/docs/WritingAnLLVMPass.rst b/llvm/docs/WritingAnLLVMPass.rst index 7e2cabb9e8f..386f3d61d0e 100644 --- a/llvm/docs/WritingAnLLVMPass.rst +++ b/llvm/docs/WritingAnLLVMPass.rst @@ -178,6 +178,18 @@ without modifying it then the third argument is set to ``true``; if a pass is 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++ @@ -185,9 +197,12 @@ As a whole, the ``.cpp`` file looks like: #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; @@ -200,12 +215,17 @@ As a whole, the ``.cpp`` file looks like: } }; // 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 |

