From 77f746998104af8ade4c3b2d947c9311fd1af836 Mon Sep 17 00:00:00 2001
From: Bill Wendling If you would like to get the LLVM test suite (a separate package as of 1.4),
you get it from the Subversion repository: By placing it in the llvm/projects, it will be automatically
configured by the LLVM configure script as well as automatically updated when
you run svn update.
- cd llvm/projects
- svn co http://llvm.org/svn/llvm-project/test-suite/trunk llvm-test
+% cd llvm/projects
+% svn co http://llvm.org/svn/llvm-project/test-suite/trunk llvm-test
+
To configure LLVM, follow these steps:
Change directory into the object root directory:
-% cd OBJ_ROOT
Run the configure script located in the LLVM source + tree:
+ +% SRC_ROOT/configure --prefix=/install/path [other options]+
Once you have LLVM configured, you can build it by entering the OBJ_ROOT directory and issuing the following command:
-gmake
+% gmake
If the build fails, please check here to see if you are using a version of GCC that is known not to compile LLVM.
@@ -944,7 +949,7 @@ If you have multiple processors in your machine, you may wish to use some of the parallel build options provided by GNU Make. For example, you could use the command: -gmake -j2
+% gmake -j2
There are several special targets which are useful when working with the LLVM source code:
@@ -1082,12 +1087,12 @@ platforms or configurations using the same source tree.Change directory to where the LLVM object files should live:
-cd OBJ_ROOT
% cd OBJ_ROOT
Run the configure script found in the LLVM source directory:
-SRC_ROOT/configure
% SRC_ROOT/configure
The LLVM build will place files underneath OBJ_ROOT in directories @@ -1143,10 +1148,10 @@ first command may not be required if you are already using the module):
- $ mount -t binfmt_misc none /proc/sys/fs/binfmt_misc - $ echo ':llvm:M::llvm::/path/to/lli:' > /proc/sys/fs/binfmt_misc/register - $ chmod u+x hello.bc (if needed) - $ ./hello.bc +$ mount -t binfmt_misc none /proc/sys/fs/binfmt_misc +$ echo ':llvm:M::llvm::/path/to/lli:' > /proc/sys/fs/binfmt_misc/register +$ chmod u+x hello.bc (if needed) +$ ./hello.bc
- #include <stdio.h> - int main() { - printf("hello world\n"); - return 0; - } -
First, create a simple C file, name it 'hello.c':
+ ++#include <stdio.h> + +int main() { + printf("hello world\n"); + return 0; +} +
Next, compile the C file into a native executable:
-% llvm-gcc hello.c -o hello
+% llvm-gcc hello.c -o hello
Note that llvm-gcc works just like GCC by default. The standard -S and -c arguments work as usual (producing a native .s or .o file, - respectively).
+ respectively).Next, compile the C file into a LLVM bitcode file:
-% llvm-gcc -O3 -emit-llvm hello.c -c -o hello.bc
+ +% llvm-gcc -O3 -emit-llvm hello.c -c -o hello.bc
The -emit-llvm option can be used with the -S or -c options to emit an LLVM ".ll" or ".bc" file (respectively) for the code. This allows you @@ -1532,11 +1542,11 @@ output.
Run the program in both forms. To run the program, use:
-% ./hello
+% ./hello
and
-% lli hello.bc
+% lli hello.bc
The second examples shows how to invoke the LLVM JIT, lli.
Use the llvm-dis utility to take a look at the LLVM assembly code:
-% llvm-dis < hello.bc | less
llvm-dis < hello.bc | less+
Compile the program to native assembly using the LLC code generator:
-% llc hello.bc -o hello.s
+% llc hello.bc -o hello.s
Assemble the native assembly language file into a program:
-Solaris:% /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.native
-Others:% gcc hello.s -o hello.native
++Solaris: % /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.native + +Others: % gcc hello.s -o hello.native ++
Execute the native code program:
-% ./hello.native
+% ./hello.native
Note that using llvm-gcc to compile directly to native code (i.e. when the -emit-llvm option is not present) does steps 6/7/8 for you.
-- 2.34.1