Scott Pakin via llvm-dev
2019-Jul-10 19:45 UTC
[llvm-dev] Looking for an out-of-source "Hello, world" LLVM/Clang pass example
I'm looking for a "Hello, world" pass example that ideally has all of the following properties: 1) Complete. That is, it should have functional CMakeLists.txt, etc. files. 2) Out-of-source. That is, it should build against a binary LLVM installation. 3) Modern. That is, I don't want to use any deprecated APIs or CMake macros. 4) Clang-compatible. That is, I'd like the pass to be able to run directly from Clang instead of having to generate bitcode, run opt on it, and then feed it back to Clang for linking. Does such an example exist and if so, where can I find it? Here's what I've considered to date: * llvm/lib/Transforms/Hello, but this appears to be in-source only. * http://llvm.org/docs/WritingAnLLVMPass.html, but this example doesn't appear to be runnable directly from Clang. * https://llvm.org/docs/CMake.html, but its proposed CMake line of "add_llvm_library(LLVMPassname MODULE Pass.cpp)" blows up with CMake Error at /usr/local/lib/cmake/llvm/AddLLVM.cmake:659 (install): install TARGETS given no LIBRARY DESTINATION for module target "Hello". Call Stack (most recent call first): Hello/CMakeLists.txt:3 (add_llvm_library) (Perhaps this is fixable with additional CMake macro calls, but that's what I list "Complete" as a desideratum.) * https://llvm.org/devmtg/2015-10/slides/GueltonGuinet-BuildingTestingDebuggingASimpleOutOfTreePass.pdf, but this uses add_llvm_loadable_module in CMake, which I read in some thread is likely to go away, and the legacy pass manager, while is also likely to go away, to make the pass usable from Clang. See my predicament? What's a poor pass-writer to do? Thanks in advance, -- Scott
Florian Hahn via llvm-dev
2019-Jul-10 20:17 UTC
[llvm-dev] Looking for an out-of-source "Hello, world" LLVM/Clang pass example
Hi,> On Jul 10, 2019, at 20:45, Scott Pakin via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > I'm looking for a "Hello, world" pass example that ideally has all of > the following properties: > > 1) Complete. That is, it should have functional CMakeLists.txt, > etc. files. > > 2) Out-of-source. That is, it should build against a binary LLVM > installation. > > 3) Modern. That is, I don't want to use any deprecated APIs or > CMake macros. > > 4) Clang-compatible. That is, I'd like the pass to be able to run > directly from Clang instead of having to generate bitcode, run > opt on it, and then feed it back to Clang for linking. > > Does such an example exist and if so, where can I find it?http://www.cs.cornell.edu/~asampson/blog/llvm.html describes how to create an out-of-source pass (see 'Let’s Write a Pass’). I think it is for LLVM 3.8 though. Cheers, Florian
Scott Pakin via llvm-dev
2019-Jul-10 23:54 UTC
[llvm-dev] Looking for an out-of-source "Hello, world" LLVM/Clang pass example
Florian, On 7/10/19 2:17 PM, Florian Hahn wrote:> http://www.cs.cornell.edu/~asampson/blog/llvm.html describes how to > create an out-of-source pass (see 'Let’s Write a Pass’). I think it > is for LLVM 3.8 though.Thanks for pointing that out. I had actually recently stumbled across that page (and the GitHub repository it references, https://github.com/sampsyo/llvm-pass-skeleton) while searching for an answer to my questions but wasn't sure how up-to-date the information is: * Is add_library the currently recommended CMake macro call for building an LLVM pass? http://llvm.org/docs/WritingAnLLVMPass.html and https://llvm.org/docs/CMake.html both point to add_llvm_library, which I couldn't get to work. * Is the legacy pass manager still the right way to make a pass Clang-callable? There's a currently active thread on this list, "Status of the New Pass Manager", that makes me think I have some code-rewriting in my future. -- Scott