Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using GHC with LLVM 3.2

Tags:

llvm

ghc

I have LLVM/opt-3.2 installed along with llvm-3.2.0.2, and I just installed GHC 7.6.2 from the Ubuntu package. However, when I try to compile ghc with -fllvm -v3, I get the error:

*** CodeGen:
*** LlVM CodeGen:
Error (figuring out LLVM version): fd:10: hGetLine: end of file

<no location info>:
    Warning: Couldn't figure out LLVM version!
             Make sure you have installed LLVM
*** LLVM Optimiser:
'opt-3.0' '/tmp/ghc17812_0/ghc17812_0.ll' '-o' '/tmp/ghc17812_0/ghc17812_0.bc' '-mem2reg' '--enable-tbaa=true'
*** Deleting temp files:
...
ghc: could not execute: opt-3.0

opt is in my path, but the version is 3.2, not 3.0. If it isn't the hackage llvm package that makes GHC look for the proper version of opt, what is it?

like image 965
crockeea Avatar asked Oct 13 '13 05:10

crockeea


2 Answers

Just want to comment that this is still a thing. Instructions for OSX:

> brew tap homebrew/dupes
> brew install homebrew/versions/llvm34

And keep an alias in my .bashrc:

alias ghc-llvm="ghc -O2 -fllvm -pgmlo opt-3.4 -pgmlc llc-3.4"

Make sure you get llvm34 and not llvm35. I also found that you really want to pass -O2 with LLVM. Without it is very slow.

like image 57
Michael Fox Avatar answered Nov 07 '22 07:11

Michael Fox


There seem to be two relevant ghc-tracs for this: one and two.

In the latter trac, a user mentioned the options "-pgmlo" and "-pgmlc", which can be found here.

I was able to fix my problem by adding "-pgmlo opt -pgmlc llc" to the list of GHC options.

As an alternative, you can edit /usr/lib/ghc/settings and make sure it has the following lines:

("LLVM llc command", "llc"),
("LLVM opt command", "opt")

I'd still like to know why GHC tries to find opt-3.0 by default.

like image 40
crockeea Avatar answered Nov 07 '22 08:11

crockeea