1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <title>Getting Started with LLVM System</title>
8 <center><h1>Getting Started with the LLVM System<br><font size=3>By: <a
9 href="mailto:gshi1@uiuc.edu">Guochun Shi</a>,
10 <a href="mailto:sabre@nondot.org">Chris Lattner</a>,
11 <a href="mailto:criswell@uiuc.edu">John Criswell</a>,
12 <a href="http://misha.brukman.net">Misha Brukman</a>, and
13 <a href="http://www.cs.uiuc.edu/~vadve">Vikram Adve</a>
16 <!--=====================================================================-->
17 <h2><a name="Contents">Contents</a></h2>
18 <!--=====================================================================-->
21 <li><a href="#overview">Overview</a>
23 <li><a href="#requirements">Requirements</a>
25 <li><a href="#hardware">Hardware</a>
26 <li><a href="#software">Software</a>
29 <li><a href="#quickstart">Getting Started Quickly (A Summary)</a>
30 <li><a href="#starting">Getting started with LLVM</a>
32 <li><a href="#terminology">Terminology and Notation</tt></a>
33 <li><a href="#environment">Setting Up Your Environment</a>
34 <li><a href="#unpack">Unpacking the LLVM Archives</a>
35 <li><a href="#checkout">Checkout LLVM from CVS</a>
36 <li><a href="#installcf">Install the C Front End</a>
37 <li><a href="#config">Local LLVM Configuration</tt></a>
38 <li><a href="#compile">Compiling the LLVM Suite Source Code</a>
39 <li><a href="#objfiles">The Location of LLVM Object Files</tt></a>
41 <li><a href="#layout">Program layout</a>
43 <li><a href="#cvsdir"><tt>CVS</tt> directories</a>
44 <li><a href="#include"><tt>llvm/include</tt></a>
45 <li><a href="#lib"><tt>llvm/lib</tt></a>
46 <li><a href="#test"><tt>llvm/test</tt></a>
47 <li><a href="#tools"><tt>llvm/tools</tt></a>
48 <li><a href="#utils"><tt>llvm/utils</tt></a>
50 <li><a href="#cfront">Compiling the LLVM GCC Front End</a>
51 <li><a href="#tutorial">An Example Using the LLVM Tool Chain</a>
52 <li><a href="#problems">Common Problems</a>
53 <li><a href="#links">Links</a>
57 <!--=====================================================================-->
59 <h2><a name="overview"><b>Overview</b></a></h2>
62 <!--=====================================================================-->
64 Welcome to LLVM! In order to get started, you first need to know some
68 First, LLVM comes in two pieces. The first piece is the LLVM suite. This
69 contains all of the tools, libraries, and header files needed to use the
70 low level virtual machine. It also contains a test suite that can be used
71 to test the LLVM tools and the GCC front end.
73 The second piece is the GCC front end. This component provides a version
74 of GCC that compiles C and C++ code into LLVM bytecode. Currently, the
75 GCC front end is a modified version of GCC 3.4 (we track the GCC 3.4
76 development). Once compiled into LLVM bytecode, a program can be
77 manipulated with the LLVM tools from the LLVM suite.
79 <!--=====================================================================-->
80 <h3><a name="requirements"><b>Requirements</b></a></h3>
81 <!--=====================================================================-->
83 Before you begin to use the LLVM system, review the requirements given
84 below. This may save you some trouble by knowing ahead of time what
85 hardware and software you will need.
87 <!--=====================================================================-->
88 <h4><a name="hardware"><b>Hardware</b></a></h4>
89 <!--=====================================================================-->
90 LLVM is known to work on the following platforms:
94 <li> Approximately 760 MB of Free Disk Space
96 <li>Source code: 30 MB
97 <li>Object code: 670 MB
98 <li>GCC front end: 60 MB
104 <li> Solaris on SparcV9 (Ultrasparc)
106 <li> Approximately 1.24 GB of Free Disk Space
108 <li>Source code: 30 MB
109 <li>Object code: 1000 MB
110 <li>GCC front end: 210 MB
116 If you want to compile your own version of the GCC front end, you will need
117 additional disk space:
123 <li> Approximately 249 MB of Free Disk Space
125 <li>Source code: 146 MB
126 <li>Object code: 82 MB
127 <li>Installed binaries: 21 MB
135 <li> Approximately 264 MB of Free Disk Space
137 <li>Source code: 146 MB
138 <li>Object code: 93 MB
139 <li>Installed binaries: 25 MB
145 LLVM <i>may</i> compile on other platforms. The LLVM utilities should work
146 on other platforms, so it should be possible to generate and produce LLVM
147 bytecode on unsupported platforms (although bytecode generated on one
148 platform may not work on another platform). However, the code generators
149 and Just-In-Time (JIT) compilers only generate SparcV9 or x86 machine code.
152 <!--=====================================================================-->
153 <h4><a name="software"><b>Software</b></a></h4>
154 <!--=====================================================================-->
157 Unpacking the distribution requires the following tools:
162 These tools are needed to uncompress and unarchive the software.
163 Regular Solaris <tt>tar</tt> may work for unpacking the TAR archive but
167 Compiling LLVM requires that you have several different software packages
173 The GNU Compiler Collection must be installed with C and C++ language
174 support. GCC 3.2.x works, and GCC 3.x is generally supported.
177 Note that we currently do not support any other C++ compiler.
182 The LLVM build system relies upon GNU Make extensions. Therefore, you
183 will need GNU Make (sometimes known as gmake) to build LLVM.
188 The LLVM source code is built using flex and bison. You will not be
189 able to configure and compile LLVM without them.
194 If you are installing Bison on your machine for the first time, you
195 will need GNU M4 (version 1.4 or higher).
199 There are some additional tools that you may want to have when working with
207 If you want to make changes to the configure scripts, you will need
208 GNU autoconf (2.53 or higher), and consequently, GNU M4 (version 1.4
214 <p>The remainder of this guide is meant to get you up and running with
215 LLVM and to give you some basic information about the LLVM environment.
216 The <a href"#quickstart">next section</a> gives a short summary for those
217 who are already familiar with the system and want to get started as quickly
218 as possible. A more complete description is provided after that.
220 <p>The later sections of this guide describe the <a
221 href="#layout">general layout</a> of the the LLVM source-tree, a <a
222 href="#tutorial">simple example</a> using the LLVM tool chain, and <a
223 href="#links">links</a> to find more information about LLVM or to get
226 <!--=====================================================================-->
228 <h2><a name="quickstart"><b>Getting Started Quickly (A Summary)</b></a></h2>
231 <!--=====================================================================-->
233 Here's the short story for getting up and running quickly with LLVM:
235 <li>Install the GCC front end:
237 <li><tt>cd <i>where-you-want-the-C-front-end-to-live</i></tt>
238 <li><tt>gunzip --stdout cfrontend.<i>platform</i>.tar.gz | tar -xvf
244 <li>Get the Source Code
246 <li>With the distributed files:
248 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
249 <li><tt>gunzip --stdout llvm.tar.gz | tar -xvf -</tt>
255 <li>With anonymous CVS access:
257 <li>Find the path to the CVS repository containing LLVM (we'll
258 call this <i>CVSROOTDIR</i>).
259 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
260 <li><tt>cvs -d <i>CVSROOTDIR</i> checkout llvm</tt>
268 <li>Configure the LLVM Build Environment
270 <li>Change directory to where you want to store the LLVM object
271 files and run <tt>configure</tt> to configure the Makefiles and
272 header files for the default platform.
273 Useful options include:
275 <li><tt>--with-llvmgccdir=<i>directory</i></tt>
277 Specify where the LLVM GCC frontend is installed.
283 <li>Build the LLVM Suite
285 <li>Set your LLVM_LIB_SEARCH_PATH environment variable.
286 <li><tt>gmake -k |& tee gnumake.out
287 # this is csh or tcsh syntax</tt>
294 <p>See <a href="#environment">Setting Up Your Environment</a> on tips to
295 simplify working with the LLVM front-end and compiled tools. See the
296 next section for other useful details in working with LLVM,
297 or go straight to <a href="#layout">Program Layout</a> to learn about the
298 layout of the source code tree. For information on building the GCC front
299 end yourself, see <a href="#cfront">Compiling the LLVM GCC Front End</a> for
302 <!--=====================================================================-->
304 <h2><a name="starting"><b>Getting Started with LLVM</b></a></h2>
307 <!--=====================================================================-->
309 <!------------------------------------------------------------------------->
310 <h3><a name="terminology">Terminology and Notation</a></h3>
311 <!------------------------------------------------------------------------->
313 <p>Throughout this manual, the following names are used to denote paths
314 specific to the local system and working environment. <i>These are not
315 environment variables you need to set but just strings used in the rest
316 of this document below</i>. In any of the examples below, simply replace
317 each of these names with the appropriate pathname on your local system.
318 All these paths are absolute:</p>
322 This is the path for the CVS repository containing the LLVM source
323 code. Ask the person responsible for your local LLVM installation to
329 This is the top level directory of the LLVM source tree.
334 This is the top level directory of the LLVM object tree (i.e. the
335 tree where object files and compiled programs will be placed. It
336 can be the same as SRC_ROOT).
341 This is the where the LLVM GCC Front End is installed.
343 For the pre-built GCC front end binaries, the LLVMGCCDIR is the
344 <tt>cfrontend/<i>platform</i>/llvm-gcc</tt>.
348 This is the location of the LLVM GCC front end source code (used
349 only if the LLVM GCC front end is being compiled).
354 This is the location of the LLVM GCC front end object code (used
355 only if the LLVM GCC front end is being compiled). It can be
356 safely removed once the LLVM GCC front end is built and installed.
359 <!------------------------------------------------------------------------->
360 <h3><a name="environment">Setting Up Your Environment</a></h3>
361 <!------------------------------------------------------------------------->
364 In order to compile and use LLVM, you will need to set some environment
365 variables. There are also some shell aliases which you may find useful.
366 You can set these on the command line, or better yet, set them in your
367 <tt>.cshrc</tt> or <tt>.profile</tt>.
370 <dt><tt>LLVM_LIB_SEARCH_PATH</tt>=<tt><i>LLVMGCCDIR</i>/llvm-gcc/bytecode-libs</tt>
372 This environment variable helps the LLVM GCC front end find bytecode
373 libraries that it will need for compilation.
376 <dt>alias llvmgcc <i>LLVMGCCDIR</i><tt>/bin/llvm-gcc</tt>
377 <dt>alias llvmg++ <i>LLVMGCCDIR</i><tt>/bin/llvm-g++</tt>
379 This alias allows you to use the LLVM C and C++ front ends without putting
380 them in your <tt>PATH</tt> or typing in their complete pathnames.
383 <!------------------------------------------------------------------------->
384 <h3><a name="unpack">Unpacking the LLVM Archives</a></h3>
385 <!------------------------------------------------------------------------->
388 If you have the LLVM distribution, you will need to unpack it before you
389 can begin to compile it. LLVM is distributed as a set of four files. Each
390 file is a TAR archive that is compressed with the gzip program.
393 <p> The four files are as follows:
396 <dd>This is the source code to the LLVM suite.
399 <dt>cfrontend.sparc.tar.gz
400 <dd>This is the binary release of the GCC front end for Solaris/Sparc.
403 <dt>cfrontend.x86.tar.gz
404 <dd>This is the binary release of the GCC front end for Linux/x86.
407 <dt>cfrontend-src.tar.gz
408 <dd>This is the source code release of the GCC front end.
412 <!------------------------------------------------------------------------->
413 <h3><a name="checkout">Checkout LLVM from CVS</a></h3>
414 <!------------------------------------------------------------------------->
416 <p>If you have access to our CVS repository, you can get a fresh copy of
417 the entire source code. All you need to do is check it out from CVS as
420 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
421 <li><tt>cvs -d <i>CVSROOTDIR</i> checkout llvm</tt></p>
424 <p>This will create an '<tt>llvm</tt>' directory in the current
425 directory and fully populate it with the LLVM source code, Makefiles,
426 test directories, and local copies of documentation files.</p>
429 Note that the GCC front end is not included in the CVS repository. You
430 should have either downloaded the source, or better yet, downloaded the
431 binary distribution for your platform.
434 <!------------------------------------------------------------------------->
435 <h3><a name="installcf">Install the GCC Front End</a></h3>
436 <!------------------------------------------------------------------------->
439 Before configuring and compiling the LLVM suite, you need to extract the
440 LLVM GCC front end from the binary distribution. It is used for building the
441 bytecode libraries later used by the GCC front end for linking programs, and
442 its location must be specified when the LLVM suite is configured.
446 To install the GCC front end, do the following:
448 <li><tt>cd <i>where-you-want-the-front-end-to-live</i></tt>
449 <li><tt>gunzip --stdout cfrontend.<i>platform</i>.tar.gz | tar -xvf
453 <!------------------------------------------------------------------------->
454 <h3><a name="config">Local LLVM Configuration</a></h3>
455 <!------------------------------------------------------------------------->
457 <p>Once checked out from the CVS repository, the LLVM suite source code
458 must be configured via the <tt>configure</tt> script. This script sets
459 variables in <tt>llvm/Makefile.config</tt> and
460 <tt>llvm/include/Config/config.h</tt>. It also populates OBJ_ROOT with
461 the Makefiles needed to build LLVM.
464 The following environment variables are used by the <tt>configure</tt>
465 script to configure the build system:
479 Tells <tt>configure</tt> which C compiler to use. By default,
480 <tt>configure</tt> will look for the first GCC compiler in
481 <tt>PATH</tt>. Use this variable to override
482 <tt>configure</tt>'s default behavior.
489 Tells <tt>configure</tt> which C++ compiler to use. By default,
490 <tt>configure</tt> will look for the first GCC compiler in
491 <tt>PATH</tt>. Use this variable to override
492 <tt>configure</tt>'s default behavior.
498 The following options can be used to set or enable LLVM specific options:
502 <dt><i>--with-llvmgccdir=LLVMGCCDIR</i>
504 Path to the location where the LLVM C front end binaries and
505 associated libraries will be installed.
507 <dt><i>--enable-optimized</i>
509 Enables optimized compilation by defaulat (debugging symbols are removed
510 and GCC optimization flags are enabled). The default is to use an
511 unoptimized build (also known as a debug build).
513 <dt><i>--enable-jit</i>
515 Compile the Just In Time (JIT) functionality. This is not available
516 on all platforms. The default is dependent on platform, so it is best
517 to explicitly enable it if you want it.
519 <dt><i>--enable-spec2000</i>
520 <dt><i>--enable-spec2000=<<tt>directory</tt>></i>
522 Enable the use of SPEC2000 when testing LLVM. This is disabled by default
523 (unless <tt>configure</tt> find SPEC2000 installed). By specifying
524 <tt>directory</tt>, you can tell configure where to find the SPEC2000
525 benchmarks. If <tt>directory</tt> is left unspecified, it
526 <tt>configure</tt> uses a default value for our internal
527 installation of SPEC2000.
531 To configure LLVM, follow these steps:
533 <li>Change directory into the object root directory:
535 <tt>cd <i>OBJ_ROOT</i></tt>
538 <li>Run the <ttconfigure</tt> script located in the LLVM source tree:
540 <tt><i>SRC_ROOT</i>/configure</tt>
545 In addition to running <tt>configure</tt>, you must set the
546 <tt>LLVM_LIB_SEARCH_PATH</tt> environment variable in your startup scripts.
547 This environment variable is used to locate "system" libraries like
548 "<tt>-lc</tt>" and "<tt>-lm</tt>" when linking. This variable should be set
549 to the absolute path for the bytecode-libs subdirectory of the GCC front end
550 install, or LLVMGCCDIR/llvm-gcc/bytecode-libs. For example, one might
551 set <tt>LLVM_LIB_SEARCH_PATH</tt> to
552 <tt>/home/vadve/lattner/local/x86/llvm-gcc/bytecode-libs</tt> for the X86
553 version of the C front-end on our research machines.<p>
555 <!------------------------------------------------------------------------->
556 <h3><a name="compile">Compiling the LLVM Suite Source Code</a></h3>
557 <!------------------------------------------------------------------------->
559 Once you have configured LLVM, you can build it. There are three types of
565 These builds are the default when one types <tt>gmake</tt> (unless the
566 <tt>--enable-optimized</tt> option was used during configuration). They
567 compile the tools and libraries with debugging information.
570 <dt>Release (Optimized) Builds
572 These builds are enabled with the <tt>--enable-optimized</tt> option to
573 <tt>configure</tt> or by specifying <tt>ENABLE_OPTIMIZED=1</tt> on the
574 <tt>gmake</tt> command line. They compile the tools and libraries with GCC
575 optimizer flags on and strip debugging information from the libraries
576 and executables it generates.
581 These builds are for use with profiling. They compile profiling
582 information into the code for use with programs like <tt>gprof</tt>.
583 Profile builds must be started by specifying <tt>ENABLE_PROFILING=1</tt>
584 on the <tt>gmake</tt> command line.
587 Once you have LLVM configured, you can build it by entering the OBJ_ROOT
588 directory and issuing the following command:
593 If you have multiple processors in your machine, you may wish to use some
594 of the parallel build options provided by GNU Make. For example, you could
602 There are several special targets which are useful when working with the LLVM
606 <dt><tt>gmake clean</tt>
608 Removes all files generated by the build. This includes object files,
609 generated C/C++ files, libraries, and executables.
612 <dt><tt>gmake distclean</tt>
614 Removes everything that <tt>gmake clean</tt> does, but also removes
615 files generated by <tt>configure</tt>. It attempts to return the
616 source tree to the original state in which it was shipped.
619 <dt><tt>gmake install</tt>
621 Installs LLVM files into the proper location. For the most part,
622 this does nothing, but it does install bytecode libraries into the
623 GCC front end's bytecode library directory. If you need to update
624 your bytecode libraries, this is the target to use once you've built
630 It is also possible to override default values from <tt>configure</tt> by
631 declaring variables on the command line. The following are some examples:
634 <dt><tt>gmake ENABLE_OPTIMIZED=1</tt>
636 Perform a Release (Optimized) build.
639 <dt><tt>gmake ENABLE_PROFILING=1</tt>
641 Perform a Profiling build.
644 <dt><tt>gmake VERBOSE=1</tt>
646 Print what <tt>gmake</tt> is doing on standard output.
650 Every directory in the LLVM object tree includes a <tt>Makefile</tt> to
651 build it and any subdirectories that it contains. Entering any directory
652 inside the LLVM object tree and typing <tt>gmake</tt> should rebuild
653 anything in or below that directory that is out of date.
655 <!------------------------------------------------------------------------->
656 <h3><a name="objfiles">The Location of LLVM Object Files</a></h3>
657 <!------------------------------------------------------------------------->
660 The LLVM build system is capable of sharing a single LLVM source tree among
661 several LLVM builds. Hence, it is possible to build LLVM for several
662 different platforms or configurations using the same source tree.
664 This is accomplished in the typical autoconf manner:
666 <li>Change directory to where the LLVM object files should live:
668 <tt>cd <i>OBJ_ROOT</i></tt>
670 <li>Run the <tt>configure</tt> script found in the LLVM source directory:
672 <tt><i>SRC_ROOT</i>/configure</tt>
676 The LLVM build will place files underneath <i>OBJ_ROOT</i> in directories
677 named after the build type:
685 <dd><tt><i>OBJ_ROOT</i>/tools/Debug</tt>
687 <dd><tt><i>OBJ_ROOT</i>/lib/Debug</tt>
695 <dd><tt><i>OBJ_ROOT</i>/tools/Release</tt>
697 <dd><tt><i>OBJ_ROOT</i>/lib/Release</tt>
705 <dd><tt><i>OBJ_ROOT</i>/tools/Profile</tt>
707 <dd><tt><i>OBJ_ROOT</i>/lib/Profile</tt>
711 <!--=====================================================================-->
713 <h2><a name="layout"><b>Program Layout</b></a></h2>
716 <!--=====================================================================-->
719 One useful source of information about the LLVM source base is the LLVM <a
720 href="http://www.doxygen.org">doxygen</a> documentation, available at <tt><a
721 href="http://llvm.cs.uiuc.edu/doxygen/">http://llvm.cs.uiuc.edu/doxygen/</a></tt>.
722 The following is a brief introduction to code layout:
725 <!------------------------------------------------------------------------->
726 <h3><a name="cvsdir"><tt>CVS</tt> directories</a></h3>
727 <!------------------------------------------------------------------------->
729 Every directory checked out of CVS will contain a <tt>CVS</tt> directory;
730 for the most part these can just be ignored.
733 <!------------------------------------------------------------------------->
734 <h3><a name="include"><tt>llvm/include</tt></a></h3>
735 <!------------------------------------------------------------------------->
737 This directory contains public header files exported from the LLVM
738 library. The three main subdirectories of this directory are:<p>
741 <li><tt>llvm/include/llvm</tt> - This directory contains all of the LLVM
742 specific header files. This directory also has subdirectories for
743 different portions of LLVM: <tt>Analysis</tt>, <tt>CodeGen</tt>,
744 <tt>Target</tt>, <tt>Transforms</tt>, etc...
746 <li><tt>llvm/include/Support</tt> - This directory contains generic
747 support libraries that are independent of LLVM, but are used by LLVM.
748 For example, some C++ STL utilities and a Command Line option processing
751 <li><tt>llvm/include/Config</tt> - This directory contains header files
752 configured by the <tt>configure</tt> script. They wrap "standard" UNIX
753 and C header files. Source code can include these header files which
754 automatically take care of the conditional #includes that the configure
758 <!------------------------------------------------------------------------->
759 <h3><a name="lib"><tt>llvm/lib</tt></a></h3>
760 <!------------------------------------------------------------------------->
762 This directory contains most of the source files of the LLVM system. In
764 code exists in libraries, making it very easy to share code among the
765 different <a href="#tools">tools</a>.<p>
768 <dt><tt>llvm/lib/VMCore/</tt><dd> This directory holds the core LLVM
769 source files that implement core classes like Instruction and BasicBlock.
771 <dt><tt>llvm/lib/AsmParser/</tt><dd> This directory holds the source code
772 for the LLVM assembly language parser library.
774 <dt><tt>llvm/lib/ByteCode/</tt><dd> This directory holds code for reading
775 and write LLVM bytecode.
777 <dt><tt>llvm/lib/CWriter/</tt><dd> This directory implements the LLVM to C
780 <dt><tt>llvm/lib/Analysis/</tt><dd> This directory contains a variety of
781 different program analyses, such as Dominator Information, Call Graphs,
782 Induction Variables, Interval Identification, Natural Loop Identification,
785 <dt><tt>llvm/lib/Transforms/</tt><dd> This directory contains the source
786 code for the LLVM to LLVM program transformations, such as Aggressive Dead
787 Code Elimination, Sparse Conditional Constant Propagation, Inlining, Loop
788 Invarient Code Motion, Dead Global Elimination, and many others...
790 <dt><tt>llvm/lib/Target/</tt><dd> This directory contains files that
791 describe various target architectures for code generation. For example,
792 the llvm/lib/Target/Sparc directory holds the Sparc machine
795 <dt><tt>llvm/lib/CodeGen/</tt><dd> This directory contains the major parts
796 of the code generator: Instruction Selector, Instruction Scheduling, and
799 <dt><tt>llvm/lib/Support/</tt><dd> This directory contains the source code
800 that corresponds to the header files located in
801 <tt>llvm/include/Support/</tt>.
804 <!------------------------------------------------------------------------->
805 <h3><a name="runtime"><tt>llvm/runtime</tt></a></h3>
806 <!------------------------------------------------------------------------->
809 This directory contains libraries which are compiled into LLVM bytecode and
810 used when linking programs with the GCC front end. Most of these libraries
811 are skeleton versions of real libraries; for example, libc is a stripped down
816 Unlike the rest of the LLVM suite, this directory needs the LLVM GCC front end
820 <!------------------------------------------------------------------------->
821 <h3><a name="test"><tt>llvm/test</tt></a></h3>
822 <!------------------------------------------------------------------------->
824 <p>This directory contains regression tests and source code that is used to
825 test the LLVM infrastructure.
828 <!------------------------------------------------------------------------->
829 <h3><a name="tools"><tt>llvm/tools</tt></a></h3>
830 <!------------------------------------------------------------------------->
832 <p>The <b>tools</b> directory contains the executables built out of the
833 libraries above, which form the main part of the user interface. You can
834 always get help for a tool by typing <tt>tool_name --help</tt>. The
835 following is a brief introduction to the most important tools.</p>
840 <dt><tt><b>analyze</b></tt><dd> <tt>analyze</tt> is used to run a specific
841 analysis on an input LLVM bytecode file and print out the results. It is
842 primarily useful for debugging analyses, or familiarizing yourself with
843 what an analysis does.<p>
845 <dt><tt><b>bugpoint</b></tt><dd> <tt>bugpoint</tt> is used to debug
846 optimization passes or code generation backends by narrowing down the
847 given test case to the minimum number of passes and/or instructions that
848 still cause a problem, whether it is a crash or miscompilation. See <a
849 href="HowToSubmitABug.html">HowToSubmitABug.html</a> for more information
850 on using <tt>bugpoint</tt>.<p>
852 <dt><tt><b>llvm-ar</b></tt><dd>The archiver produces an archive containing
853 the given LLVM bytecode files, optionally with an index for faster
856 <dt><tt><b>llvm-as</b></tt><dd>The assembler transforms the human readable
857 LLVM assembly to LLVM bytecode.<p>
859 <dt><tt><b>llvm-dis</b></tt><dd>The disassembler transforms the LLVM
860 bytecode to human readable LLVM assembly. Additionally, it can convert
861 LLVM bytecode to C, which is enabled with the <tt>-c</tt> option.<p>
863 <dt><tt><b>llvm-link</b></tt><dd> <tt>llvm-link</tt>, not surprisingly,
864 links multiple LLVM modules into a single program.<p>
866 <dt><tt><b>lli</b></tt><dd> <tt>lli</tt> is the LLVM interpreter, which
867 can directly execute LLVM bytecode (although very slowly...). In addition
868 to a simple interpreter, <tt>lli</tt> also has a tracing mode (entered by
869 specifying <tt>-trace</tt> on the command line). Finally, for
870 architectures that support it (currently only x86 and Sparc), by default,
871 <tt>lli</tt> will function as a Just-In-Time compiler (if the
872 functionality was compiled in), and will execute the code <i>much</i>
873 faster than the interpreter.<p>
875 <dt><tt><b>llc</b></tt><dd> <tt>llc</tt> is the LLVM backend compiler,
876 which translates LLVM bytecode to a SPARC or x86 assembly file.<p>
878 <dt><tt><b>llvmgcc</b></tt><dd> <tt>llvmgcc</tt> is a GCC-based C frontend
879 that has been retargeted to emit LLVM code as the machine code output. It
880 works just like any other GCC compiler, taking the typical <tt>-c, -S, -E,
881 -o</tt> options that are typically used. The source code for the
882 <tt>llvmgcc</tt> tool is currently not included in the LLVM cvs tree
883 because it is quite large and not very interesting.<p>
886 <dt><tt><b>gccas</b></tt><dd> This tool is invoked by the
887 <tt>llvmgcc</tt> frontend as the "assembler" part of the compiler. This
888 tool actually assembles LLVM assembly to LLVM bytecode,
889 performs a variety of optimizations, and outputs LLVM bytecode. Thus
890 when you invoke <tt>llvmgcc -c x.c -o x.o</tt>, you are causing
891 <tt>gccas</tt> to be run, which writes the <tt>x.o</tt> file (which is
892 an LLVM bytecode file that can be disassembled or manipulated just like
893 any other bytecode file). The command line interface to <tt>gccas</tt>
894 is designed to be as close as possible to the <b>system</b>
895 `<tt>as</tt>' utility so that the gcc frontend itself did not have to be
896 modified to interface to a "weird" assembler.<p>
898 <dt><tt><b>gccld</b></tt><dd> <tt>gccld</tt> links together several LLVM
899 bytecode files into one bytecode file and does some optimization. It is
900 the linker invoked by the gcc frontend when multiple .o files need to be
901 linked together. Like <tt>gccas</tt> the command line interface of
902 <tt>gccld</tt> is designed to match the system linker, to aid
903 interfacing with the GCC frontend.<p>
906 <dt><tt><b>opt</b></tt><dd> <tt>opt</tt> reads LLVM bytecode, applies a
907 series of LLVM to LLVM transformations (which are specified on the command
908 line), and then outputs the resultant bytecode. The '<tt>opt --help</tt>'
909 command is a good way to get a list of the program transformations
910 available in LLVM.<p>
914 <!------------------------------------------------------------------------->
915 <h3><a name="utils"><tt>llvm/utils</tt></a></h3>
916 <!------------------------------------------------------------------------->
918 This directory contains utilities for working with LLVM sourcecode, and some
919 of the utilities are actually required as part of the build process because
920 they are code generators for parts of LLVM infrastructure.
923 <td><tt><b>Burg/</b></tt><dd> <tt>Burg</tt> is an instruction selector
924 generator -- it builds trees on which it then performs pattern-matching to
925 select instructions according to the patterns the user has specified. Burg
926 is currently used in the Sparc V9 backend.<p>
928 <dt><tt><b>codegen-diff</b></tt><dd> <tt>codegen-diff</tt> is a script
929 that finds differences between code that LLC generates and code that LLI
930 generates. This is a useful tool if you are debugging one of them,
931 assuming that the other generates correct output. For the full user
932 manual, run <tt>`perldoc codegen-diff'</tt>.<p>
934 <dt><tt><b>cvsupdate</b></tt><dd> <tt>cvsupdate</tt> is a script that will
935 update your CVS tree, but produce a much cleaner and more organized output
936 than simply running <tt>`cvs up -dP'</tt> will. For example, it will group
937 together all the new and updated files and modified files in separate
938 sections, so you can see at a glance what has changed. If you are at the
939 top of your LLVM CVS tree, running <tt>utils/cvsupdate</tt> is the
940 preferred way of updating the tree.<p>
942 <dt><tt><b>emacs/</b></tt><dd> The <tt>emacs</tt> directory contains
943 syntax-highlighting files which will work with Emacs and XEmacs editors,
944 providing syntax highlighting support for LLVM assembly files and TableGen
945 description files. For information on how to use the syntax files, consult
946 the <tt>README</tt> file in that directory.<p>
948 <dt><tt><b>getsrcs.sh</b></tt><dd> The <tt>getsrcs.sh</tt> script finds
949 and outputs all non-generated source files, which is useful if one wishes
950 to do a lot of development across directories and does not want to
951 individually find each file. One way to use it is to run, for example:
952 <tt>xemacs `utils/getsources.sh`</tt> from the top of your LLVM source
955 <dt><tt><b>makellvm</b></tt><dd> The <tt>makellvm</tt> script compiles all
956 files in the current directory and then compiles and links the tool that
957 is the first argument. For example, assuming you are in the directory
958 <tt>llvm/lib/Target/Sparc</tt>, if <tt>makellvm</tt> is in your path,
959 simply running <tt>makellvm llc</tt> will make a build of the current
960 directory, switch to directory <tt>llvm/tools/llc</tt> and build it,
961 causing a re-linking of LLC.<p>
963 <dt><tt><b>NightlyTest.pl</b></tt> and
964 <tt><b>NightlyTestTemplate.html</b></tt><dd> These files are used in a
965 cron script to generate nightly status reports of the functionality of
966 tools, and the results can be seen by following the appropriate link on
967 the <a href="http://llvm.cs.uiuc.edu/">LLVM homepage</a>.<p>
969 <dt><tt><b>TableGen/</b></tt><dd> The <tt>TableGen</tt> directory contains
970 the tool used to generate register descriptions, instruction set
971 descriptions, and even assemblers from common TableGen description
974 <dt><tt><b>vim/</b></tt><dd> The <tt>vim</tt> directory contains
975 syntax-highlighting files which will work with the VIM editor, providing
976 syntax highlighting support for LLVM assembly files and TableGen
977 description files. For information on how to use the syntax files, consult
978 the <tt>README</tt> file in that directory.<p>
982 <!--=====================================================================-->
983 <h2><center><a name="cfront">Compiling the LLVM GCC Front End</center></h2>
985 <!--=====================================================================-->
989 This step is optional if you have the GCC front end binary distribution for
994 Now that you have the LLVM suite built, you can build the GCC front end. For
995 those of you that have built GCC before, the process is very similar.
997 Be forewarned, though: the build system for the GCC front end is not as
998 polished as the rest of the LLVM code, so there will be many warnings and
999 errors that you will need to ignore for now:
1002 <li>Ensure that <tt><i>OBJ_ROOT</i>/llvm/tools/Debug</tt> is at the
1003 <i>end</i> of your <tt>PATH</tt> environment variable. The front end
1004 build needs to know where to find the LLVM tools, but you want to
1005 ensure that these tools are not found before the system assembler and
1006 linker that you normally use for compilation.
1008 <li><tt>cd <i>GCCOBJ</i></tt>
1010 <li>Configure the source code:
1012 <li>On Linux/x86, use
1014 <li><tt><i>GCCSRC</i>/configure --prefix=<i>LLVMGCCDIR</i>
1015 --enable-languages=c</tt>
1018 <li>On Solaris/Sparc, use
1020 <li><tt><i>GCCSRC</i>/configure --prefix=<i>LLVMGCCDIR</i>
1021 --enable-languages=c --target=sparcv9-sun-solaris2</tt>
1027 <li>The build will eventually fail. Don't worry; chances are good that
1028 everything that needed to build is built.
1030 <li><tt>gmake -k install</tt>
1034 Once this is done, you should have a built front end compiler in
1035 <tt><i>LLVMGCCDIR</i></tt>.
1038 <!--=====================================================================-->
1040 <center><a name="tutorial">An Example Using the LLVM Tool Chain</center>
1043 <!--=====================================================================-->
1046 <li>First, create a simple C file, name it 'hello.c':
1048 #include <stdio.h>
1050 printf("hello world\n");
1055 <li>Next, compile the C file into a LLVM bytecode file:<p>
1057 <tt>% llvmgcc hello.c -o hello</tt><p>
1059 This will create two result files: <tt>hello</tt> and
1060 <tt>hello.bc</tt>. The <tt>hello.bc</tt> is the LLVM bytecode that
1061 corresponds the the compiled program and the library facilities that it
1062 required. <tt>hello</tt> is a simple shell script that runs the bytecode
1063 file with <tt>lli</tt>, making the result directly executable.<p>
1065 <li>Run the program. To make sure the program ran, execute one of the
1066 following commands:<p>
1068 <tt>% ./hello</tt><p>
1072 <tt>% lli hello.bc</tt><p>
1074 <li>Use the <tt>llvm-dis</tt> utility to take a look at the LLVM assembly
1077 <tt>% llvm-dis < hello.bc | less</tt><p>
1079 <li>Compile the program to native Sparc assembly using the code
1080 generator (assuming you are currently on a Sparc system):<p>
1082 <tt>% llc hello.bc -o hello.s</tt><p>
1084 <li>Assemble the native sparc assemble file into a program:<p>
1086 <tt>% /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.sparc</tt><p>
1088 <li>Execute the native sparc program:<p>
1090 <tt>% ./hello.sparc</tt><p>
1095 <!--=====================================================================-->
1097 <center><a name="problems">Common Problems</a></center>
1100 <!--=====================================================================-->
1102 Below are common problems and their remedies:
1105 <dt><b>When I run configure, it finds the wrong C compiler.</b>
1107 The <tt>configure</tt> script attempts to locate first <tt>gcc</tt> and
1108 then <tt>cc</tt>, unless it finds compiler paths set in <tt>CC</tt> and
1109 <tt>CXX</tt> for the C and C++ compiler, respectively.
1111 If <tt>configure</tt> finds the wrong compiler, either adjust your
1112 <tt>PATH</tt> environment variable or set <tt>CC</tt> and <tt>CXX</tt>
1116 <dt><b>I compile the code, and I get some error about /localhome</b>.
1118 There are several possible causes for this. The first is that you
1119 didn't set a pathname properly when using <tt>configure</tt>, and it
1120 defaulted to a pathname that we use on our research machines.
1122 Another possibility is that we hardcoded a path in our Makefiles. If
1123 you see this, please email the LLVM bug mailing list with the name of
1124 the offending Makefile and a description of what is wrong with it.
1126 <dt><b>The <tt>configure</tt> script finds the right C compiler, but it
1127 uses the LLVM linker from a previous build. What do I do?</b>
1129 The <tt>configure</tt> script uses the <tt>PATH</tt> to find
1130 executables, so if it's grabbing the wrong linker/assembler/etc, there
1131 are two ways to fix it:
1133 <li>Adjust your <tt>PATH</tt> environment variable so that the
1134 correct program appears first in the <tt>PATH</tt>. This may work,
1135 but may not be convenient when you want them <i>first</i> in your
1136 path for other work.
1139 <li>Run <tt>configure</tt> with an alternative <tt>PATH</tt> that
1140 is correct. In a Borne compatible shell, the syntax would be:
1142 <tt>PATH=<the path without the bad program> ./configure ...</tt>
1144 This is still somewhat inconvenient, but it allows
1145 <tt>configure</tt> to do its work without having to adjust your
1146 <tt>PATH</tt> permanently.
1149 <dt><b>I've upgraded to a new version of LLVM, and I get strange build
1152 Sometimes changes to the LLVM source code alters how the build system
1153 works. Changes in libtool, autoconf, or header file dependencies are
1154 especially prone to this sort of problem.
1156 The best thing to try is to remove the old files and re-build. In most
1157 cases, this takes care of the problem. To do this, just type <tt>make
1158 clean</tt> and then <tt>make</tt> in the directory that fails to build.
1163 <!--=====================================================================-->
1164 <h2><center><a name="links">Links</a></center></h2>
1166 <!--=====================================================================-->
1168 <p>This document is just an <b>introduction</b> to how to use LLVM to do
1169 some simple things... there are many more interesting and complicated things
1170 that you can do that aren't documented here (but we'll gladly accept a patch
1171 if you want to write something up!). For more information about LLVM, check
1175 <li><a href="http://llvm.cs.uiuc.edu/">LLVM homepage</a></li>
1176 <li><a href="http://llvm.cs.uiuc.edu/doxygen/">LLVM doxygen tree</a></li>
1177 <li><a href="http://llvm.cs.uiuc.edu/docs/Projects.html">Starting a Project that Uses LLVM</a></li>
1182 If you have any questions or run into any snags (or you have any
1183 additions...), please send an email to
1184 <a href="mailto:sabre@nondot.org">Chris Lattner</a>.</p>
1186 <!-- Created: Mon Jul 1 02:29:02 CDT 2002 -->
1187 <!-- hhmts start -->
1188 Last modified: Mon Aug 11 13:52:22 CDT 2003