Just as a bit of clarification, there is also a recent buzz around the net related to LLVM and GHC/Haskell due to the LLVM code-gen functionality integrated into GHC by David Terei in his thesis. Although that is definitely very cool, it's different than the LLVM module.
There are a few posts by Bryan and Lennart that discuss the LLVM module here (which I'm listing for completeness and also for my own reference):
- O'Sullivan: "LLVM Bindings for Haskell" (January 3, 2008)
- Lennart: "LLVM" (January 7, 2009)
- Lennart: "LLVM Arithmetic" (January 10, 2009)
- Lennart: "A Performance Update" (January 21, 2009)
- Lennart: "More LLVM" (June 10, 2009)
I thought I'd write a post on how I did it in case anyone else is having similar issues.
First, you need to install LLVM. I took some cues from the install guide for unladen swallow (the fast Python implementation on LLVM and using a jit compiler that Google is sponsoring) and also from the LLVM getting started page.
Specifically, I installed LLVM 2.7 and also the gcc front end (not required to my knowledge but looked interesting/useful). Here are the commands I used:
> wget 'http://llvm.org/releases/2.7/llvm-gcc-4.2-2.7-x86_64-apple-darwin10.tgz'
> wget 'http://llvm.org/releases/2.7/llvm-2.7.tgz'
> tar xzf llvm-gcc-4.2-2.7-x86_64-apple-darwin10.tgz
Once you've untarred the gcc binaries, move them to the location you want to install them at. Be careful with just dropping folders onto existing folder hierarchies on Mac -- this has an effect of replacing the target folders as opposed to adding the contents to the existing tree (a discovery learned through tears I can tell you). Continuing:
> tar xzf llvm-gcc-4.2-2.7-x86_64-apple-darwin10.tgz
Once you've untarred the gcc binaries, move them to the location you want to install them at. Be careful with just dropping folders onto existing folder hierarchies on Mac -- this has an effect of replacing the target folders as opposed to adding the contents to the existing tree (a discovery learned through tears I can tell you). Continuing:
> tar xzf llvm-2.7.tgz
> mkdir llvm_build
> cd llvm_build
> ../llvm-2.7/configure --prefix={prefix path if not installing to default} --with-llvmgccdir={path to llvm-gcc binaries}
Note: if you'd like the O'Caml bindings, add "--with-ocaml-libdir={path to your ocaml library}". For example, the values for me were:
* --prefix=/Users/{uname}/.local --with-llvmgcdir=/Users/{uname}/.local --with-ocaml-libdir=/usr/local/lib/ocaml
If you're installing to the standard locations and installed the gcc front end in a standard area on the path, you don't need the above configuration flags. I decided to install to a custom location and so required the flags myself.
Note: if you'd like the O'Caml bindings, add "--with-ocaml-libdir={path to your ocaml library}". For example, the values for me were:
* --prefix=/Users/{uname}/.local --with-llvmgcdir=/Users/{uname}/.local --with-ocaml-libdir=/usr/local/lib/ocaml
If you're installing to the standard locations and installed the gcc front end in a standard area on the path, you don't need the above configuration flags. I decided to install to a custom location and so required the flags myself.
At this point you are ready to compile LLVM. I had successfully downloaded and built llvm many times before and confirmed the tools worked (llc, lli, etc.). However, I could never succeed in getting the Haskell LLVM module to build. The big breakthrough came from this e-mail which indicates a need to declare the variable "UNIVERSAL" as follows:
> UNIVERSAL=1 gmake -j4
This will take a while to compile. The 4 after the j flag indicates the number of processors to use. Once compilation completes, you need to:
> UNIVERSAL=1 gmake -j4
This will take a while to compile. The 4 after the j flag indicates the number of processors to use. Once compilation completes, you need to:
> gmake install
> cabal install llvm
and you're done!

You should see more on that module soon. It will be used in GHC's LLVM backend :)
ReplyDelete