Using LLVM with Ada

Dear all,

I'm trying to exploit the LLVM framework to optimize my Ada programs.
To this extent I compiled the Ada f-e from source (v. 2.5).
However, while trying to compile a simple HelloWorld example I get several
errors dealing with undefined references (while invoking LLVM on hello).
Arguably I missed something on the right way to use the LLVM tools
with Ada sourcecode.

I would really appreciate an exhaustive example of succesfull compilation
of Ada programs with LLVM.

Thanks in advance.

Regards,

Enrico

Hi Enrico, did you follow the instructions here
   http://llvm.org/docs/GCCFEBuildInstrs.html#ada
to build llvm-gcc with Ada support?

To this extent I compiled the Ada f-e from source (v. 2.5).

If by 2.5 you mean LLVM-2.5 I suggest you use something more recent, for
example LLVM-2.7.

However, while trying to compile a simple HelloWorld example I get several
errors dealing with undefined references (while invoking LLVM on hello).

Please show how you tried to compile it and what the undefined references
were.

Arguably I missed something on the right way to use the LLVM tools
with Ada sourcecode.

You are supposed to be able to use llvm-gcc in the same way as gcc.

Ciao,

Duncan.

Dear Duncan,

thank you for the prompt reaction!

Quoting Duncan Sands <baldrick@free.fr>:

Hi Enrico, did you follow the instructions here
   http://llvm.org/docs/GCCFEBuildInstrs.html#ada
to build llvm-gcc with Ada support?

Yes. I succesfully followed the instructions to build the LLVM Ada f-e.

If by 2.5 you mean LLVM-2.5 I suggest you use something more recent, for
example LLVM-2.7.

I was probably misled by the instructrions themselves which state:
"Compilers known to work with the LLVM 2.5 release are gcc-4.2 and the 2005,
2006 and 2007 versions of the GNAT GPL Edition. GNAT GPL 2008, gcc-4.3 and
later will not work."

Please show how you tried to compile it and what the undefined references
were.
You are supposed to be able to use llvm-gcc in the same way as gcc.

Actually I was able to compile my program by invoking "gnatmake" provided by
the llvm-gcc f-e and I obtained an optimized version of my
excutable.

However, I would be interested in calling different llvm tools in a
non-transparent way. For example I would like to call llvm-gcc to obtain
the LLVM intermediate representation of a compilation module
(e.g., llvm-gcc -c hello.adb) and then invoke different llvm tools.
The problem is that I do not know how to include the information
from the .ali files generated by gnat. In the lack of such information
llvmc (for example) is not able to find a proper main for my program and
raises an undefined reference error.
I was wandering if it is actually possible to exploit the LLVM framework in
such a sequential manner as it is for C programs.

By the way, I'll try LLVM 2.7 and the respective version of LLVM-GCC.

Thanks again and best regards,

Enrico

Hi Enrico,

However, I would be interested in calling different llvm tools in a
non-transparent way. For example I would like to call llvm-gcc to obtain
the LLVM intermediate representation of a compilation module
(e.g., llvm-gcc -c hello.adb) and then invoke different llvm tools.

you should add -emit-llvm to the command line (or optimized at -O4 or
above), for example
   llvm-gcc -c hello.adb -emit-llvm -o hello.bc
results in LLVM bitcode in hello.bc. You don't have to name the output
hello.bc, but it is traditional to use the .bc extension for bitcode.

The problem is that I do not know how to include the information
from the .ali files generated by gnat. In the lack of such information
llvmc (for example) is not able to find a proper main for my program and
raises an undefined reference error.

The main program is generated by "gnatbind". You can just run gnatbind
by hand to produce the main program which you can then also compile to
bitcode using llvm-gcc. You can link everything together to get one huge
module containing bitcode for your entire program if you like (good for
doing link-time optimization). If you make use of the gold plugin (see
http://llvm.org/docs/GoldPlugin.html) then this is all very easy, otherwise
you will have to play around a little bit to get this working nicely with
gnatlink.

By the way, I never used llvmc myself, just the usual tools (llvm-ld or
llvm-link, opt, llc) by hand.

I was wandering if it is actually possible to exploit the LLVM framework in
such a sequential manner as it is for C programs.

It is.

Ciao,

Duncan.

Hi Enrico,

If by 2.5 you mean LLVM-2.5 I suggest you use something more recent, for
example LLVM-2.7.

I was probably misled by the instructrions themselves which state:
"Compilers known to work with the LLVM 2.5 release are gcc-4.2 and the 2005,
2006 and 2007 versions of the GNAT GPL Edition. GNAT GPL 2008, gcc-4.3 and
later will not work."

I've updated the instructions to LLVM-2.7. Thanks for pointing out that they
were out of date!

Ciao,

Duncan.