[llvm-dev] [RFC] Generalize out-of-tree pass support
Serge Guelton via llvm-dev
llvm-dev at lists.llvm.org
Tue Jan 14 02:18:38 PST 2020
Hi Folks,
some update on the « compiler extension » topic.
The main patch landed last week and received a bunch of update meanwhile.
It's almost complete, so let me describe it some more,
based on a thread [0] on cfe-commits at lists.llvm.org.
# What's this patch all about?
Proposing a common infrastructure to write LLVM pass plugins linked
dynamically (a.ka. MODULE in the cmake terminology) or statically
(just a STATIC library) and have them work gracefully within
opt/clang/bugpoint.
Polly already had several hooks to provide this behavior. At such, this
patch is a generalization of the approach.
# What problem does it solve?
Dynamically loaded plugins are an easy way to jump into LLVM, but they are
not natural to use for the end-users: no one wants to type
clang -Xclang -load -Xclang /clang/install/path/.../MyPlugin.so
my_source.c on a regular basis.
The next step is generally to write a regular LLVM pass, register it in
clang / opt pipelines, which involves a few modifications to the original
tree.
With this patch, one can write a top-level project, say StuffyDoll, that's
separated from llvm-project source, and use the cmake
-DCMAKE_ENABLE_PROJECTS=clang;StuffyDoll
to have it being compiled alongside LLVM, then use the
-DLLVM_STUFFYDOLL_LINK_INTO_TOOLS=[ON|OFF]
option to switch between the module or static build. When using the static
build, the appropriate clang/opt/bugpoint hooks are automatically installed,
which means *no* modification outside of StuffyDoll.
# How should I use it?
Probably through reading the in-tree example [1], after reading the
documentation [2] :-)
# Is it working for all platforms?
It's 100% functional on Linux, waiting for https://reviews.llvm.org/D72493
to be accepted[3] to fully work on OSX, and it only works for static builds
on Windows.
[0]
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20200106/300726.html
[1] https://github.com/llvm/llvm-project/tree/master/llvm/examples/Bye
[2] http://llvm.org/docs/WritingAnLLVMPass.html#building-pass-plugins
[3] If you've read so far, you might be interested enough to participate in
the review ;-)
On Fri, Sep 20, 2019 at 3:56 PM Serge Guelton <sguelton at redhat.com> wrote:
> 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!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200114/1e53a1de/attachment.html>
More information about the llvm-dev
mailing list