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!
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
There's dual use: without LLVM_<PLUGIN>_LINK_INTO_TOOLS, the plugin
can be imported using the -load mechanism.
> 2. Does your patch make `PLUGIN_TOOL` obsolete (e.g.
> https://github.com/llvm-mirror/llvm/blob/master/lib/Transforms/Hello/CMakeLists.txt#L18)?
> AFAIK `PLUGIN_TOOL` is only needed to enable dynamically loaded plugins
> on Windows, but from what I can tell you achieved that without using it?
> (sadly I've not been able to test your patch on Windows)
PLUGIN_TOOL must be used to allow plugins such as "Hello" to link
against symbols of an executable. On Windows, import symbols need to
know which library it is imported from. "Hello" defines the executable
opt as source of its symbols, consequently it cannot be imported in
other executables such as bugpoint, llvm-reduce or clang. In addition
to use it, one must also set cmake -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS
to make the executable export those symbols. However, Windows dlls
have a limit of 2^16 imported symbols and LLVM exceeds that by far.
Therefore there is a util script extract_symbols.py to limit the
exports to those that are most probably used. However, I could not
(yet) make this work with Polly, there are always symbols missing.
But it doesn't even work on Linux since the linker only adds symbols
(from static libraries) that are required within the executable. So if
a plugin needs one that is not added to the executable, the plugin is
in bad luck. IMHO the concept of dynamically linking to symbols in
executables is pretty broken. LTO will worsen the problem since it
will inline public symbols and remove the ones unused inside the
executable.
tl;dr: They are different: D61446 for statically linking a plugin,
PLUGIN_TOOL is for dynamically linking a plugin.
Michael