The LLVM test suite cannot be run on the MinGW port at this point of time.
All of the llvm tools and the cfe build with some manual modifications at the source code level and will (probely) work as intended - Not tested throughly.
bugpoint is excluded to be be build.
Further information about the LLVM directory structure and tool chain can be found on the main Getting Started page.
Before you begin to use the LLVM system, review the requirements given below. This may save you some trouble by knowing ahead of time what hardware and software you will need.
Any system that can adequately run MinGW is fine. The LLVM source tree and object files, libraries and executables will consume approximately two GB in debug mode.
Note, that the installation instructions relates to the older version 1.0 of MinGW for Windows.
From MinGW.org you should install at least MinGW-3.1.0-1+.exe, MSYS-1.0.10+.exe, gcc-core-3.4.1+ and gcc-g++-3.4.1+.
From MinGWiki you should download and install in the MinGW folder (in that order): Bison (rename or exclude the m4.exe version from that package) and Flex.
Do not use MinGW binutils 2.13.90 and 2.15.91, due to a mangler bug in ld. Upgrade to at least to binutils 2.15.94 or build binutils 2.15 from source (http://gnu.ftp.org/gnu/binutils). Building binutlis on the local machine requires dmake and perl 5.8.5+. Build perl with dmake in cmd.exe. Note, if dmake can't find gcc, try set your path to the folder where gcc lives (though you have followed the README.win32 for perl). Then, you should do:
If you want to compile the cfe then upgrade to texinfo 4.5+ from http://sourceforge.net/projects/gnuwin32.
If you want to create your own makefiles from autoconf, then you should upgrade to at least autoconf 2.59+ and automake 1.9.2+
If you want to be able to test the llvm tools and cfe (This cannot be achieved yet), you should at least do:
The remainder of this guide is meant to get you up and running with LLVM using MinGW.
In your .profile add: export CPPFLAGS="-DLLVM_ON_WIN32".
Following guide line follows the style given in <--a href="http://llvm.cs.uiuc.edu/docs/CFEBuildInstrs.html"--> Bootstrapping the LLVM C/C++ Front-End.
Unfortunately, the MSYS bash-shell cannot understand options given on the command line in the abbreviated form: OPTION="opt1 ... optn", but understands options given on the form: OPTION+=opt1 ... OPTION+=optn.
Configure and build the LLVM libraries and tools. In below case we have objdir != srcdir:
% cd objdir % srcdir/configure --prefix=/some/path/you/can/install/to \
--enable-targets=x86 % make tools-only TOOLLINKOPTSB+=-limagehelp TOOLLINKOPTSB+=-lpsapi \
LDFLAGS+=-Wl,--no-keep-memory -r
Install the tools to your --prefix=/some/path/you/can/install/to and add it to your PATH:
% make install
Unpack the C/C++ front-end source.
Make "build" and "install" directories as siblings of the "src" tree:
% pwd /usr/local/example/cfrontend/src % cd .. % mkdir build install % export CFEINSTALL=/some/path/you/can/install/to % cd build
Configure, build, and install the GCC front-end:
% cfe-srcdir/configure --prefix=$CFEINSTALL --disable-threads --disable-nls \
--disable-shared --enable-languages=c,c++ --program-prefix=llvm- \
--srcdir=../../../src/llvm-gcc-1/llvm-gcc --includedir=/C/MinGW mingw32 % make CFLAGS=-O LIBCFLAGS+=-g LIBCFLAGS+=-O2 LIBCXXFLAGS+=-g \
LIBCXXFLAGS+=-O2 LIBCXXFLAGS+=-fno-implicit-templates all % make install
Put $CFEINSTALL/bin into your PATH.
Go back into the LLVM source tree proper. Rerun configure, using the same options as the last time. This will cause the configuration to now find the newly built llvm-gcc and llvm-g++ executables.
Rebuild your source tree. This shouldn't cause the whole thing to be rebuilt, but it should build the runtime libraries. After the tree is built, install the runtime libraries into your GCC front-end build tree. These are the commands you need:
% make TOOLLINKOPTSB+=-ldbghelp TOOLLINKOPTSB+=-lpsapi \
LDFLAGS+=-Wl,--no-keep-memory -r % make -C runtime install-bytecode
Optionally, build a symbol table for the newly installed runtime libraries. Although this step is optional, you are strongly encouraged to do this as the symbol tables will make a significant difference in your link times. Use the llvm-ranlib tool to do this, as follows:
% cd $CFEINSTALL/lib % llvm-ranlib libiberty.a % llvm-ranlib libstdc++.a % llvm-ranlib libsupc++.a % cd $CFEINSTALL/lib/gcc/target-triplet/3.4-llvm % llvm-ranlib libgcc.a % llvm-ranlib libgcov.a
Not all is working yet: Test the newly-installed C frontend by one or more of the following means:
#include <stdio.h>
int main() {
printf("hello world\n");
return 0;
}
Next, compile the C file into a LLVM bytecode file:
% llvm-gcc hello.c -o hello
Note that you should have already built the tools and they have to be in your path, at least gccas and gccld.
This will create two result files: hello and hello.bc. The hello.bc is the LLVM bytecode that corresponds the the compiled program and the library facilities that it required. hello is a simple shell script that runs the bytecode file with lli, making the result directly executable. Note that all LLVM optimizations are enabled by default, so there is no need for a "-O3" switch.
Note: while you cannot do this step on Windows, you can do it on a Unix system and transfer hello.bc to Windows.
Run the program. To make sure the program ran, execute the following command:
% lli hello.bc
Use the llvm-dis utility to take a look at the LLVM assembly code:
% llvm-dis < hello.bc | less
Compile the program to native assembly using the LLC code generator:
% llc hello.bc -o hello.s
Assemble the native assembly language file into a program:
Not currently possible, but eventually will use NASMW.
Execute the native code program:
% ./hello.native
If you are having problems building or using LLVM, or if you have any other general questions about LLVM, please consult the Frequently Asked Questions page.
This document is just an introduction to how to use LLVM to do some simple things... there are many more interesting and complicated things that you can do that aren't documented here (but we'll gladly accept a patch if you want to write something up!). For more information about LLVM, check out: