[LLVMdev] problem with my LLVM pass

1,832 views
Skip to first unread message

Jun Koi

unread,
Oct 5, 2012, 3:34:46 AM10/5/12
to llv...@cs.uiuc.edu
hi,

i am wondering if this link is still updated?

http://www.llvm.org/docs/CMake.html#developing-llvm-pass-out-of-source

i follow the instruction from the link, and create in my ~/test/
directory the CMakeLists.txt with following content:

$cat test/CMakeLists.txt

find_package(LLVM)

# Define add_llvm_* macro's.
include(AddLLVM)

add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})

add_subdirectory(Hello)
======

inside test/, i put Hello/ directory, copied from
llvm-3.1.src/lib/Transforms/Hello.

then inside test/, i tried to compile:

test$ cmake .
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Warning at CMakeLists.txt:1 (find_package):
Could not find module FindLLVM.cmake or a configuration file for package
LLVM.

Adjust CMAKE_MODULE_PATH to find FindLLVM.cmake or set LLVM_DIR to the
directory containing a CMake configuration file for LLVM. The file will
have one of the following names:

LLVMConfig.cmake
llvm-config.cmake

CMake Error at CMakeLists.txt:4 (include):
include could not find load file:

AddLLVM

CMake Error at Hello/CMakeLists.txt:1 (add_llvm_loadable_module):
Unknown CMake command "add_llvm_loadable_module".

CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as

cmake_minimum_required(VERSION 2.8)

should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.

-- Configuring incomplete, errors occurred!
=======

any idea on how to fix the problem?

thanks,
Jun
_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

David Chisnall

unread,
Oct 5, 2012, 3:39:34 AM10/5/12
to Jun Koi, llv...@cs.uiuc.edu
On 5 Oct 2012, at 08:34, Jun Koi wrote:

> any idea on how to fix the problem?

The correct solution is to fix the LLVM build to install the .cmake files in a location that CMake knows about. The hacky solution that I've used is just to copy them into the correct place manually.

David

Jun Koi

unread,
Oct 5, 2012, 3:45:11 AM10/5/12
to David Chisnall, llv...@cs.uiuc.edu
On Fri, Oct 5, 2012 at 3:39 PM, David Chisnall
<David.C...@cl.cam.ac.uk> wrote:
> On 5 Oct 2012, at 08:34, Jun Koi wrote:
>
>> any idea on how to fix the problem?
>
> The correct solution is to fix the LLVM build to install the .cmake files in a location that CMake knows about.

could you please elaborate?

> The hacky solution that I've used is just to copy them into the correct place manually.

could you please elaborate? what do i need to copy, and where?

if that matters, i compiled and installed llvm 3.1 from source in normal way:

./configure; make; make install


thanks,
Jun

Jun Koi

unread,
Oct 9, 2012, 9:25:50 AM10/9/12
to David Chisnall, llv...@cs.uiuc.edu
On Fri, Oct 5, 2012 at 3:45 PM, Jun Koi <junko...@gmail.com> wrote:
> On Fri, Oct 5, 2012 at 3:39 PM, David Chisnall
> <David.C...@cl.cam.ac.uk> wrote:
>> On 5 Oct 2012, at 08:34, Jun Koi wrote:
>>
>>> any idea on how to fix the problem?
>>
>> The correct solution is to fix the LLVM build to install the .cmake files in a location that CMake knows about.
>
> could you please elaborate?
>
>> The hacky solution that I've used is just to copy them into the correct place manually.
>
> could you please elaborate? what do i need to copy, and where?
>
> if that matters, i compiled and installed llvm 3.1 from source in normal way:
>
> ./configure; make; make install

any help on this sample LLVM pass, please?

Jun Koi

unread,
Oct 18, 2012, 5:19:52 AM10/18/12
to David Chisnall, llv...@cs.uiuc.edu
On Tue, Oct 9, 2012 at 9:25 PM, Jun Koi <junko...@gmail.com> wrote:
> On Fri, Oct 5, 2012 at 3:45 PM, Jun Koi <junko...@gmail.com> wrote:
>> On Fri, Oct 5, 2012 at 3:39 PM, David Chisnall
>> <David.C...@cl.cam.ac.uk> wrote:
>>> On 5 Oct 2012, at 08:34, Jun Koi wrote:
>>>
>>>> any idea on how to fix the problem?
>>>
>>> The correct solution is to fix the LLVM build to install the .cmake files in a location that CMake knows about.
>>
>> could you please elaborate?
>>
>>> The hacky solution that I've used is just to copy them into the correct place manually.
>>
>> could you please elaborate? what do i need to copy, and where?
>>
>> if that matters, i compiled and installed llvm 3.1 from source in normal way:
>>
>> ./configure; make; make install
>
> any help on this sample LLVM pass, please?

any help, please? i am still stuck on this problem.

i fixed CMakeLists.txt in the root directory to be like below:

$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
# A convenience variable:
set(LLVM_ROOT "/usr" CACHE /usr/ "Root of LLVM install.")
# A bit of a sanity check:
if( NOT EXISTS ${LLVM_ROOT}/include/llvm )
message(FATAL_ERROR "LLVM_ROOT (${LLVM_ROOT}) is not a valid LLVM install")
endif()

# We incorporate the CMake features provided by LLVM:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT}/share/llvm/cmake")
#include(LLVMConfig)

# Now set the header and library paths:
include_directories( ${LLVM_INCLUDE_DIRS} )
link_directories( ${LLVM_LIBRARY_DIRS} )
add_definitions( ${LLVM_DEFINITIONS} )
# Let's suppose we want to build a JIT compiler with support for
# binary code (no interpreter):
# llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES jit native)
# Finally, we link the LLVM libraries to our executable:
target_link_libraries(myHello ${REQ_LLVM_LIBRARIES})

add_subdirectory(Hello)
#####

and the content of Hello/CMakeLists.txt is like below:

$ cat Hello/CMakeLists.txt
cmake_minimum_required(VERSION 2.8)

add_llvm_loadable_module(LLVMHello
Hello.cpp
)
####

now i compiled again, but there is still one error:

$ cmake .
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at Hello/CMakeLists.txt:3 (add_llvm_loadable_module):
Unknown CMake command "add_llvm_loadable_module".


-- Configuring incomplete, errors occurred!
#####

so CMake doesnt understand "add_llvm_loadable_module". how to fix this?

Duncan Sands

unread,
Oct 18, 2012, 5:33:26 AM10/18/12
to llv...@cs.uiuc.edu
Hi Jun,

On 18/10/12 11:19, Jun Koi wrote:
> On Tue, Oct 9, 2012 at 9:25 PM, Jun Koi <junko...@gmail.com> wrote:
>> On Fri, Oct 5, 2012 at 3:45 PM, Jun Koi <junko...@gmail.com> wrote:
>>> On Fri, Oct 5, 2012 at 3:39 PM, David Chisnall
>>> <David.C...@cl.cam.ac.uk> wrote:
>>>> On 5 Oct 2012, at 08:34, Jun Koi wrote:
>>>>
>>>>> any idea on how to fix the problem?
>>>>
>>>> The correct solution is to fix the LLVM build to install the .cmake files in a location that CMake knows about.
>>>
>>> could you please elaborate?
>>>
>>>> The hacky solution that I've used is just to copy them into the correct place manually.
>>>
>>> could you please elaborate? what do i need to copy, and where?
>>>
>>> if that matters, i compiled and installed llvm 3.1 from source in normal way:
>>>
>>> ./configure; make; make install
>>
>> any help on this sample LLVM pass, please?
>
> any help, please? i am still stuck on this problem.

don't use cmake?

Ciao, Duncan.

Jun Koi

unread,
Oct 18, 2012, 5:38:17 AM10/18/12
to Duncan Sands, llv...@cs.uiuc.edu
On Thu, Oct 18, 2012 at 5:33 PM, Duncan Sands <bald...@free.fr> wrote:
> Hi Jun,
>
>
> On 18/10/12 11:19, Jun Koi wrote:
>>
>> On Tue, Oct 9, 2012 at 9:25 PM, Jun Koi <junko...@gmail.com> wrote:
>>>
>>> On Fri, Oct 5, 2012 at 3:45 PM, Jun Koi <junko...@gmail.com> wrote:
>>>>
>>>> On Fri, Oct 5, 2012 at 3:39 PM, David Chisnall
>>>> <David.C...@cl.cam.ac.uk> wrote:
>>>>>
>>>>> On 5 Oct 2012, at 08:34, Jun Koi wrote:
>>>>>
>>>>>> any idea on how to fix the problem?
>>>>>
>>>>>
>>>>> The correct solution is to fix the LLVM build to install the .cmake
>>>>> files in a location that CMake knows about.
>>>>
>>>>
>>>> could you please elaborate?
>>>>
>>>>> The hacky solution that I've used is just to copy them into the
>>>>> correct place manually.
>>>>
>>>>
>>>> could you please elaborate? what do i need to copy, and where?
>>>>
>>>> if that matters, i compiled and installed llvm 3.1 from source in normal
>>>> way:
>>>>
>>>> ./configure; make; make install
>>>
>>>
>>> any help on this sample LLVM pass, please?
>>
>>
>> any help, please? i am still stuck on this problem.
>
>
> don't use cmake?
>

you mean i should not use cmake? what is wrong here?

cmake is still preferred as i want to compile my code with MS Visual
Studio on Windows, too.

thanks,
Jun

Duncan Sands

unread,
Oct 18, 2012, 5:42:00 AM10/18/12
to Jun Koi, llv...@cs.uiuc.edu
Hi Jun,

>> don't use cmake?
>>
>
> you mean i should not use cmake? what is wrong here?

LLVM cmake support is missing all kinds of features compared to configure+make
(search for cmake bug reports in bugzilla to find these). Your issue is
probably just another missing feature. So if you don't want to hack on cmake I
suggest you use configure+make if possible.

> cmake is still preferred as i want to compile my code with MS Visual
> Studio on Windows, too.

In order to make progress on your pass I suggest you use configure and make for
the moment, and in parallel try to resolve the cmake problem yourself.

Ciao, Duncan.

Jun Koi

unread,
Oct 18, 2012, 6:11:09 AM10/18/12
to Duncan Sands, llv...@cs.uiuc.edu
On Thu, Oct 18, 2012 at 5:42 PM, Duncan Sands <bald...@free.fr> wrote:
> Hi Jun,
>
>
>>> don't use cmake?
>>>
>>
>> you mean i should not use cmake? what is wrong here?
>
>
> LLVM cmake support is missing all kinds of features compared to
> configure+make
> (search for cmake bug reports in bugzilla to find these). Your issue is
> probably just another missing feature. So if you don't want to hack on
> cmake I
> suggest you use configure+make if possible.
>
>
>> cmake is still preferred as i want to compile my code with MS Visual
>> Studio on Windows, too.
>
>
> In order to make progress on your pass I suggest you use configure and make
> for
> the moment, and in parallel try to resolve the cmake problem yourself.

this is a smart idea, thanks!

so i moved the code to under llvm-3.1.src/lib/Transforms/, and use the
Makefile from http://www.llvm.org/docs/WritingAnLLVMPass.html#makefile
all the compilation went flawless without any problem.

then this requires me to put my code into the LLVM source tree, and i
dont like this.
i tried to move my code and my Makefile elsewhere, and compilation failed.
so the questions are:

(1) how can i fix the Makefile, so i can compile my pass from anywhere?

(2) is it (pass compilation) possible without the LLVM source code?

thanks,
Jun

Sameer Sahasrabuddhe

unread,
Oct 18, 2012, 7:22:58 AM10/18/12
to Jun Koi, llv...@cs.uiuc.edu
On Fri, 5 Oct 2012 13:04:46 +0530
Jun Koi <junko...@gmail.com> wrote:

> i am wondering if this link is still updated?
>
> http://www.llvm.org/docs/CMake.html#developing-llvm-pass-out-of-source
>
> i follow the instruction from the link, and create in my ~/test/
> directory the CMakeLists.txt with following content:
>

<snip>

> CMake Warning at CMakeLists.txt:1 (find_package):
> Could not find module FindLLVM.cmake or a configuration file for
> package LLVM.

This error occurs when llvm-config is not in the path. I tried the same
thing by copying the CMake snippets from the above page into a new file:

$ cd test
$ cat CMakeLists.txt
find_package(LLVM)

# Define add_llvm_* macro's.
include(AddLLVM)

add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})

add_subdirectory(<pass name>)

add_llvm_loadable_module(LLVMPassname
Pass.cpp
)

$ cmake .

Everything worked at this stage.

But if I removed llvm-config from my PATH, I get the following error
instead:

$ cmake .
....
CMake Warning at CMakeLists.txt:1 (find_package):
Could not find module FindLLVM.cmake or a configuration file for
package LLVM.

Adjust CMAKE_MODULE_PATH to find FindLLVM.cmake or set LLVM_DIR to the
directory containing a CMake configuration file for LLVM. The file
will have one of the following names:

LLVMConfig.cmake
llvm-config.cmake

So I tried what cmake says:

$ cmake -DLLVM_DIR=/usr/share/llvm/cmake .

This worked with both 2.8.3 and 2.8.9

Hope that helps!
Sameer.

Peter Boström

unread,
Oct 18, 2012, 7:24:58 AM10/18/12
to Jun Koi, llv...@cs.uiuc.edu
I build a LLVM pass for my thesis to a .so file separately from the
tree, and run it using opt -load my_pass.so -my_pass file.bc

I don't claim that this is how it's supposed to be done, but it's
working for me, so it's at least possible. I'm still learning a lot
here. :)

https://github.com/pbos/spinn/blob/master/Makefile

The 'llvm-spinn.so' rule builds my pass, and an example of how the pass
is then used (opt -load) is under 'plug-test'.

- Peter

Roel Jordans

unread,
Oct 18, 2012, 7:25:35 AM10/18/12
to llv...@cs.uiuc.edu
Hi Jun,
You can use the sample project as a template to get your code outside of
the LLVM source tree. That worked for me.

More info: http://llvm.org/docs/Projects.html

Cheers,
Roel

Jun Koi

unread,
Oct 18, 2012, 10:53:24 AM10/18/12
to Sameer Sahasrabuddhe, llv...@cs.uiuc.edu
On Thu, Oct 18, 2012 at 7:22 PM, Sameer Sahasrabuddhe
<sameer.sah...@amd.com> wrote:
> On Fri, 5 Oct 2012 13:04:46 +0530
> Jun Koi <junko...@gmail.com> wrote:
>
>> i am wondering if this link is still updated?
>>
>> http://www.llvm.org/docs/CMake.html#developing-llvm-pass-out-of-source
>>
>> i follow the instruction from the link, and create in my ~/test/
>> directory the CMakeLists.txt with following content:
>>
>
> <snip>
>
>> CMake Warning at CMakeLists.txt:1 (find_package):
>> Could not find module FindLLVM.cmake or a configuration file for
>> package LLVM.
>
> This error occurs when llvm-config is not in the path. I tried the same
> thing by copying the CMake snippets from the above page into a new file:
>

no, this is not true on my case. on my machine, llvm-config is in the
path, and can be called from anywhere.
perhaps that works for older LLVM, but not for 3.1. there is no such a
thing as /usr/share/llvm/cmake
and the suggestion from cmake above is not true, either: on 3.1, i
cannot find LLVMConfig.cmake and llvm-config.cmake

thanks,
Jun

Sahasrabuddhe, Sameer

unread,
Oct 18, 2012, 12:59:12 PM10/18/12
to Jun Koi, llv...@cs.uiuc.edu
> -----Original Message-----
> From: Jun Koi [mailto:junko...@gmail.com]
> Sent: Thursday, October 18, 2012 8:23 PM
> >
> > $ cmake -DLLVM_DIR=/usr/share/llvm/cmake .
> >
> > This worked with both 2.8.3 and 2.8.9
>
> perhaps that works for older LLVM, but not for 3.1.

Actually I am using the tip of the trunk and not a release. But I think it does not matter ... an eyeballing of the 3.1 directory shows that the cmake scripts are all there, at least in the source.

> there is no such a
> thing as /usr/share/llvm/cmake
> and the suggestion from cmake above is not true, either: on 3.1, i
> cannot find LLVMConfig.cmake and llvm-config.cmake

I was not entirely honest with that path. The actual path that I use is non-standard location where LLVM gets installed. And there is definitely a "share/llvm/cmake" directory in that place.

Here is another possibility ... are you building LLVM itself with configure/make or with cmake? I don't have access to my build setup right now to check this possibility, but I think the configure/make version does not install the cmake scripts. At least that's what it looks like from the top-level Makefiles. Maybe everything is working for me because of the fact that I use cmake+ninja to build and install my LLVM/Clang/Polly setup?

Sameer.

Jun Koi

unread,
Oct 18, 2012, 11:06:49 PM10/18/12
to Sahasrabuddhe, Sameer, llv...@cs.uiuc.edu
On Fri, Oct 19, 2012 at 12:59 AM, Sahasrabuddhe, Sameer
<Sameer.Sah...@amd.com> wrote:
>> -----Original Message-----
>> From: Jun Koi [mailto:junko...@gmail.com]
>> Sent: Thursday, October 18, 2012 8:23 PM
>> >
>> > $ cmake -DLLVM_DIR=/usr/share/llvm/cmake .
>> >
>> > This worked with both 2.8.3 and 2.8.9
>>
>> perhaps that works for older LLVM, but not for 3.1.
>
> Actually I am using the tip of the trunk and not a release. But I think it does not matter ... an eyeballing of the 3.1 directory shows that the cmake scripts are all there, at least in the source.
>
>> there is no such a
>> thing as /usr/share/llvm/cmake
>> and the suggestion from cmake above is not true, either: on 3.1, i
>> cannot find LLVMConfig.cmake and llvm-config.cmake
>
> I was not entirely honest with that path. The actual path that I use is non-standard location where LLVM gets installed. And there is definitely a "share/llvm/cmake" directory in that place.
>
> Here is another possibility ... are you building LLVM itself with configure/make or with cmake? I don't have access to my build setup right now to check this possibility, but I think the configure/make version does not install the cmake scripts. At least that's what it looks like from the top-level Makefiles. Maybe everything is working for me because of the fact that I use cmake+ninja to build and install my LLVM/Clang/Polly setup?

you are right: i compiled llvm with configure & make. then i guess
that is why i miss the cmake file.

thanks.

Jun Koi

unread,
Oct 18, 2012, 11:32:43 PM10/18/12
to Peter Boström, llv...@cs.uiuc.edu
work flawlessly for me, thanks!
Jun

Jun Koi

unread,
Oct 18, 2012, 11:33:25 PM10/18/12
to Roel Jordans, llv...@cs.uiuc.edu
awesome, thanks!

Jun
Reply all
Reply to author
Forward
0 new messages