[llvm-dev] [RFC] Generalize out-of-tree pass support

Serge Guelton via llvm-dev llvm-dev at lists.llvm.org
Mon Sep 23 01:45:12 PDT 2019


> 1. As far as I can tell, this mechanism relies on the plugin
being located somewhere within LLVM the tree so that everything happens
within one CMake run. Otherwise the pass registration won't work - at least
in the case of static linking. IMHO this is fine - AFAIK it's not
something that could easily be worked around.

One can use `LLVM_ENABLE_PROJECTS` and
`LLVM_EXTERNAL_${project}_SOURCE_DIR`, so this is fully parametric.

> 2. Does your patch make `PLUGIN_TOOL` obsolete

I'll double -check and update the patch accordingly if needs be. At first
glance I'd say I'm generalizing PLUGIN_TOOL, but missed the error message
for unsupported platform.

> 3. At the coming LLVM Dev Meeting I'll be presenting a tutorial on
writing LLVM passes for beginners and I'd like to advertise this patch

Good :-)


On Sun, Sep 22, 2019 at 2:12 PM Andrzej Warzynski <Andrzej.Warzynski at arm.com>
wrote:

> Hello Serge,
>
> Thank you for doing this - that's a lot of great work that makes LLVM
> plugin registration very straightforward to use. The implementation and
> the interface make a lot of sense! I've noticed other people on the
> mailing list asking for similar functionality, so there's definitely
> need for this sort of infrastructure. I do hope that it lands in LLVM
> sooner rather than later.
>
> I have a few questions/remarks:
> 1. As far as I can tell, this mechanism relies on the plugin being
> located somewhere within LLVM the tree so that everything happens within
> one CMake run. Otherwise the pass registration won't work - at least in
> the case of static linking. IMHO this is fine - AFAIK it's not something
> that could easily be worked around.
>
> 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)
>
> 3. At the coming LLVM Dev Meeting I'll be presenting a tutorial on
> writing LLVM passes for beginners and I'd like to advertise this patch.
> Is that OK with you? I think that this is really worthwhile sharing with
> the wider community.
>
> Thanks again for working on this,
> -Andrzej
>
>
> On 20/09/2019 14:56, Serge Guelton via llvm-dev 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!
> >
> > _______________________________________________
> > LLVM Developers mailing list
> > llvm-dev at lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190923/5eeec221/attachment.html>


More information about the llvm-dev mailing list