[llvm-dev] [RFC] Generalize out-of-tree pass support
Serge Guelton via llvm-dev
llvm-dev at lists.llvm.org
Fri Sep 20 06:56:13 PDT 2019
Hi folks,
I've been working for a few months on a proposal to make it easier to develop
out-of-tree passes, and have them linked either statically or dynamically,
within LLVM. This includes automatic integration within clang, opt and bugpoint.
The goal is to lower the bar for people who develop out-of tree passes: they can
maintain their code base in a third-party repo, pick it at config time and build
it statically or dynamically.
As a side-effect, this provides a generalization of the polly-specific code
that spread at several locations of the code base (and removes most of the
explicit mention of Polly itself, without removing the functionality, obviously).
Both legacy and new pass managers are supported.
>From the review's documentation:
LLVM provides a mechanism to automatically register pass plugins within
``clang``, ``opt`` and ``bugpoint``. One first needs to create an independent
project and add it to either ``tools/`` or, using the MonoRepo layout, at the
root of the repo alongside other projects. This project must contain the
following minimal ``CMakeLists.txt``:
.. code-block:: cmake
add_llvm_pass_plugin(Name source0.cpp)
The pass must provide two entry points for the new pass manager, one for static
registration and one for dynamically loaded plugins:
- ``llvm::PassPluginLibraryInfo get##Name##PluginInfo();``
- ``extern "C" ::llvm::PassPluginLibraryInfo llvmGetPassPluginInfo() LLVM_ATTRIBUTE_WEAK;``
Pass plugins are compiled and link dynamically by default, but it's
possible to set the following variables to change this behavior:
- ``LLVM_${NAME}_LINK_INTO_TOOLS``, when sets to ``ON``, turns the project into
a statically linked extension
The review also contains an example of pass plugin, `llvm/examples/Bye/Bye.cpp`.
The associated review is available at https://reviews.llvm.org/D61446, Michael
Kruse has already done a lot of review, I think it's time to gather more
feedback, so if you're interested... jump in!
More information about the llvm-dev
mailing list