problem with my LLVM pass

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)

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

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

any help on this sample LLVM pass, please?

thanks,
Jun

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)

Hi Jun,

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

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.

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 Writing an LLVM Pass — LLVM 18.0.0git documentation
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

i am wondering if this link is still updated?

Building LLVM with CMake — LLVM 18.0.0git documentation

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.

> 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 Writing an LLVM Pass — LLVM 18.0.0git documentation
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?

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. :slight_smile:

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

Hi Jun,

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 Writing an LLVM Pass — LLVM 18.0.0git documentation
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?

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: Creating an LLVM Project — LLVM 18.0.0git documentation

Cheers,
  Roel

i am wondering if this link is still updated?

Building LLVM with CMake — LLVM 18.0.0git documentation

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.

$ 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

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

From: Jun Koi [mailto:junkoi2004@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.

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

thanks.

work flawlessly for me, thanks!
Jun

awesome, thanks!

Jun