903d73560d1d8d6f4e7e73d2a6d118699a1b0f54
[oota-llvm.git] / docs / GettingStarted.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3   <head>
4     <title>Getting Started with LLVM System</title>
5   </head>
6
7   <body bgcolor=white>
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>
14     </font></h1></center>
15
16     <!--=====================================================================-->
17     <h2><a name="Contents">Contents</a></h2>
18     <!--=====================================================================-->
19
20     <ul>
21       <li><a href="#overview">Overview</a>
22       <ol>
23           <li><a href="#requirements">Requirements</a>
24           <ol>
25               <li><a href="#hardware">Hardware</a>
26               <li><a href="#software">Software</a>
27           </ol>
28       </ol>
29       <li><a href="#quickstart">Getting Started Quickly (A Summary)</a>
30       <li><a href="#starting">Getting started with LLVM</a>
31         <ol>
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>
40         </ol>
41       <li><a href="#layout">Program layout</a>
42       <ol>
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>
49         </ol>
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>
54     </ul>
55
56
57     <!--=====================================================================-->
58     <center>
59     <h2><a name="overview"><b>Overview</b></a></h2>
60     </center>
61     <hr>
62     <!--=====================================================================-->
63
64     Welcome to LLVM!  In order to get started, you first need to know some
65     basic information.
66
67     <p>
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.
72     <p>
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.
78
79     <!--=====================================================================-->
80     <h3><a name="requirements"><b>Requirements</b></a></h3>
81     <!--=====================================================================-->
82
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.
86
87     <!--=====================================================================-->
88     <h4><a name="hardware"><b>Hardware</b></a></h4>
89     <!--=====================================================================-->
90     LLVM is known to work on the following platforms:
91     <ul>
92         <li> Linux on x86
93         <ul>
94             <li> Approximately 760 MB of Free Disk Space
95             <ul>
96                 <li>Source code: 30 MB
97                 <li>Object code: 670 MB
98                 <li>GCC front end: 60 MB
99             </ul>
100         </ul>
101
102         <p>
103
104         <li> Solaris on SparcV9 (Ultrasparc)
105         <ul>
106             <li> Approximately 1.24 GB of Free Disk Space
107             <ul>
108                 <li>Source code: 30 MB
109                 <li>Object code: 1000 MB
110                 <li>GCC front end: 210 MB
111             </ul>
112         </ul>
113     </ul>
114
115     <p>
116     If you want to compile your own version of the GCC front end, you will need
117     additional disk space:
118     </p>
119
120     <ul>
121         <li>Linux on x86
122         <ul>
123             <li> Approximately 249 MB of Free Disk Space
124             <ul>
125                 <li>Source code: 146 MB
126                 <li>Object code: 82 MB
127                 <li>Installed binaries: 21 MB
128             </ul>
129         </ul>
130
131         <p>
132
133         <li>Solaris on Sparc
134         <ul>
135             <li> Approximately 264 MB of Free Disk Space
136             <ul>
137                 <li>Source code: 146 MB
138                 <li>Object code: 93 MB
139                 <li>Installed binaries: 25 MB
140             </ul>
141         </ul>
142     </ul>
143
144     <p>
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.
150     </p>
151
152     <!--=====================================================================-->
153     <h4><a name="software"><b>Software</b></a></h4>
154     <!--=====================================================================-->
155     <p>
156
157     Unpacking the distribution requires the following tools:
158     <dl compact>
159         <dt>GNU Zip (gzip)
160         <dt>GNU Tar
161         <dd>
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
164         is untested.
165     </dl>
166
167     Compiling LLVM requires that you have several different software packages
168     installed:
169
170     <dl compact>
171         <dt> GCC
172         <dd>
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.
175
176         <p>
177         Note that we currently do not support any other C++ compiler.
178         </p>
179
180         <dt> GNU Make
181         <dd>
182         The LLVM build system relies upon GNU Make extensions.  Therefore, you
183         will need GNU Make (sometimes known as gmake) to build LLVM.
184         <p>
185
186         <dt> Flex and Bison
187         <dd>
188         The LLVM source code is built using flex and bison.  You will not be
189         able to configure and compile LLVM without them.
190         <p>
191
192         <dt> GNU M4
193         <dd>
194         If you are installing Bison on your machine for the first time, you
195         will need GNU M4 (version 1.4 or higher).
196     </dl>
197
198     <p>
199     There are some additional tools that you may want to have when working with
200     LLVM:
201     </p>
202
203     <ul>
204         <li>GNU Autoconf
205         <li>GNU M4
206         <p>
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
209         or higher).
210         </p>
211     </ul>
212
213
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.
219
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
224     help via e-mail.
225
226     <!--=====================================================================-->
227     <center>
228     <h2><a name="quickstart"><b>Getting Started Quickly (A Summary)</b></a></h2>
229     </center>
230     <hr>
231     <!--=====================================================================-->
232
233     Here's the short story for getting up and running quickly with LLVM:
234     <ol>
235         <li>Install the GCC front end:
236         <ol>
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
239             -</tt>
240         </ol>
241
242         <p>
243
244         <li>Get the Source Code
245         <ul>
246             <li>With the distributed files:
247             <ol>
248                 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
249                 <li><tt>gunzip --stdout llvm.tar.gz | tar -xvf -</tt>
250                 <li><tt>cd llvm</tt>
251             </ol>
252
253             <p>
254
255             <li>With anonymous CVS access:
256             <ol>
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>
261                 <li><tt>cd llvm</tt>
262             </ol>
263         </ul>
264         </ul>
265
266         <p>
267
268         <li>Configure the LLVM Build Environment
269         <ol>
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:
274                 <ul>
275                     <li><tt>--with-llvmgccdir=<i>directory</i></tt>
276                     <br>
277                     Specify where the LLVM GCC frontend is installed.
278                 </ul>
279         </ol>
280
281         <p>
282
283         <li>Build the LLVM Suite
284         <ol>
285             <li>Set your LLVM_LIB_SEARCH_PATH environment variable.
286             <li><tt>gmake -k |& tee gnumake.out
287             &nbsp;&nbsp;&nbsp;# this is csh or tcsh syntax</tt>
288         </ol>
289
290         <p>
291
292     </ol>
293
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
300     information.
301
302     <!--=====================================================================-->
303     <center>
304     <h2><a name="starting"><b>Getting Started with LLVM</b></a></h2>
305     </center>
306     <hr>
307     <!--=====================================================================-->
308
309     <!------------------------------------------------------------------------->
310     <h3><a name="terminology">Terminology and Notation</a></h3>
311     <!------------------------------------------------------------------------->
312
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>
319     <dl compact>
320         <dt>CVSROOTDIR
321         <dd>
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
324         give you this path.
325         <p>
326
327         <dt>SRC_ROOT
328         <dd>
329         This is the top level directory of the LLVM source tree.
330         <p>
331
332         <dt>OBJ_ROOT
333         <dd>
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).
337         <p>
338
339         <dt>LLVMGCCDIR
340         <dd>
341         This is the where the LLVM GCC Front End is installed.
342         <p>
343         For the pre-built GCC front end binaries, the LLVMGCCDIR is the
344         <tt>cfrontend/<i>platform</i>/llvm-gcc</tt>.
345
346         <dt>GCCSRC
347         <dd>
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).
350         <p>
351
352         <dt>GCCOBJ
353         <dd>
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.
357     </dl>
358
359     <!------------------------------------------------------------------------->
360     <h3><a name="environment">Setting Up Your Environment</a></h3>
361     <!------------------------------------------------------------------------->
362
363     <p>
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>.
368
369     <dl compact>
370         <dt><tt>LLVM_LIB_SEARCH_PATH</tt>=<tt><i>LLVMGCCDIR</i>/llvm-gcc/bytecode-libs</tt>
371         <dd>
372         This environment variable helps the LLVM GCC front end find bytecode
373         libraries that it will need for compilation.
374         <p>
375
376         <dt>alias llvmgcc <i>LLVMGCCDIR</i><tt>/bin/llvm-gcc</tt>
377         <dt>alias llvmg++ <i>LLVMGCCDIR</i><tt>/bin/llvm-g++</tt>
378         <dd>
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.
381     </dl>
382
383     <!------------------------------------------------------------------------->
384     <h3><a name="unpack">Unpacking the LLVM Archives</a></h3>
385     <!------------------------------------------------------------------------->
386
387     <p>
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.
391     </p>
392
393     <p> The four files are as follows:
394     <dl compact>
395         <dt>llvm.tar.gz
396         <dd>This is the source code to the LLVM suite.
397         <p>
398
399         <dt>cfrontend.sparc.tar.gz
400         <dd>This is the binary release of the GCC front end for Solaris/Sparc.
401         <p>
402
403         <dt>cfrontend.x86.tar.gz
404         <dd>This is the binary release of the GCC front end for Linux/x86.
405         <p>
406
407         <dt>cfrontend-src.tar.gz
408         <dd>This is the source code release of the GCC front end.
409         <p>
410     </dl>
411
412     <!------------------------------------------------------------------------->
413     <h3><a name="checkout">Checkout LLVM from CVS</a></h3>
414     <!------------------------------------------------------------------------->
415
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
418     follows:
419     <ul>
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>
422     </ul>
423
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>
427
428     <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.
432     </p>
433
434     <!------------------------------------------------------------------------->
435     <h3><a name="installcf">Install the GCC Front End</a></h3>
436     <!------------------------------------------------------------------------->
437
438     <p>
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.
443     </p>
444
445     <p>
446     To install the GCC front end, do the following:
447     <ol>
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
450         -</tt>
451     </ol>
452
453     <!------------------------------------------------------------------------->
454     <h3><a name="config">Local LLVM Configuration</a></h3>
455     <!------------------------------------------------------------------------->
456
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.
462
463     <p>
464     The following environment variables are used by the <tt>configure</tt>
465     script to configure the build system:
466     </p>
467
468     <table border=1>
469         <tr>
470             <th>Variable</th>
471             <th>
472             Purpose
473             </th>
474         </tr>
475
476         <tr>
477             <td>CC</td>
478             <td>
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.
483             </td>
484         </tr>
485
486         <tr>
487             <td>CXX</td>
488             <td>
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.
493             </td>
494         </tr>
495     </table>
496
497     <p>
498     The following options can be used to set or enable LLVM specific options:
499     </p>
500
501     <dl compact>
502     <dt><i>--with-llvmgccdir=LLVMGCCDIR</i>
503     <dd>
504         Path to the location where the LLVM C front end binaries and
505         associated libraries will be installed.
506         <p>
507     <dt><i>--enable-optimized</i>
508     <dd>
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).
512         <p>
513     <dt><i>--enable-jit</i>
514     <dd>
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.
518         <p>
519     <dt><i>--enable-spec2000</i>
520     <dt><i>--enable-spec2000=&lt;<tt>directory</tt>&gt;</i>
521     <dd>
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.
528     </dl>
529
530     <p>
531     To configure LLVM, follow these steps:
532     <ol>
533         <li>Change directory into the object root directory:
534         <br>
535         <tt>cd <i>OBJ_ROOT</i></tt>
536         <p>
537
538         <li>Run the <ttconfigure</tt> script located in the LLVM source tree:
539         <br>
540         <tt><i>SRC_ROOT</i>/configure</tt>
541         <p>
542     </ol>
543     </p>
544
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>
554
555     <!------------------------------------------------------------------------->
556     <h3><a name="compile">Compiling the LLVM Suite Source Code</a></h3>
557     <!------------------------------------------------------------------------->
558
559     Once you have configured LLVM, you can build it.  There are three types of
560     builds:
561
562     <dl compact>
563         <dt>Debug Builds
564         <dd>
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.
568         <p>
569
570         <dt>Release (Optimized) Builds
571         <dd>
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. 
577         <p>
578
579         <dt>Profile Builds
580         <dd>
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.
585     </dl>
586
587     Once you have LLVM configured, you can build it by entering the OBJ_ROOT
588     directory and issuing the following command:
589     <p>
590     <tt>gmake</tt>
591
592     <p>
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
595     use the command:
596     </p>
597
598     <p>
599     <tt>gmake -j2</tt>
600
601     <p>
602     There are several special targets which are useful when working with the LLVM
603     source code:
604
605     <dl compact>
606         <dt><tt>gmake clean</tt>
607         <dd>
608         Removes all files generated by the build.  This includes object files,
609         generated C/C++ files, libraries, and executables.
610         <p>
611
612         <dt><tt>gmake distclean</tt>
613         <dd>
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.
617         <p>
618
619         <dt><tt>gmake install</tt>
620         <dd>
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
625         them.
626         <p>
627
628     </dl>
629
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:
632
633     <dl compact>
634         <dt><tt>gmake ENABLE_OPTIMIZED=1</tt>
635         <dd>
636         Perform a Release (Optimized) build.
637         <p>
638
639         <dt><tt>gmake ENABLE_PROFILING=1</tt>
640         <dd>
641         Perform a Profiling build.
642         <p>
643
644         <dt><tt>gmake VERBOSE=1</tt>
645         <dd>
646         Print what <tt>gmake</tt> is doing on standard output.
647         <p>
648     </dl>
649
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.
654
655     <!------------------------------------------------------------------------->
656     <h3><a name="objfiles">The Location of LLVM Object Files</a></h3>
657     <!------------------------------------------------------------------------->
658
659     <p>
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.
663     <p>
664     This is accomplished in the typical autoconf manner:
665     <ul>
666         <li>Change directory to where the LLVM object files should live:
667         <p>
668         <tt>cd <i>OBJ_ROOT</i></tt>
669
670         <li>Run the <tt>configure</tt> script found in the LLVM source directory:
671         <p>
672         <tt><i>SRC_ROOT</i>/configure</tt>
673     </ul>
674
675     <p>
676     The LLVM build will place files underneath <i>OBJ_ROOT</i> in directories
677     named after the build type:
678     </p>
679
680     <dl compact>
681         <dt>Debug Builds
682         <dd>
683         <dl compact>
684             <dt>Tools
685             <dd><tt><i>OBJ_ROOT</i>/tools/Debug</tt>
686             <dt>Libraries
687             <dd><tt><i>OBJ_ROOT</i>/lib/Debug</tt>
688         </dl>
689         <p>
690
691         <dt>Release Builds
692         <dd>
693         <dl compact>
694             <dt>Tools
695             <dd><tt><i>OBJ_ROOT</i>/tools/Release</tt>
696             <dt>Libraries
697             <dd><tt><i>OBJ_ROOT</i>/lib/Release</tt>
698         </dl>
699         <p>
700
701         <dt>Profile Builds
702         <dd>
703         <dl compact>
704             <dt>Tools
705             <dd><tt><i>OBJ_ROOT</i>/tools/Profile</tt>
706             <dt>Libraries
707             <dd><tt><i>OBJ_ROOT</i>/lib/Profile</tt>
708         </dl>
709     </dl>
710
711     <!--=====================================================================-->
712     <center>
713     <h2><a name="layout"><b>Program Layout</b></a></h2>
714     </center>
715     <hr>
716     <!--=====================================================================-->
717
718     <p>
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:
723     </p>
724
725     <!------------------------------------------------------------------------->
726     <h3><a name="cvsdir"><tt>CVS</tt> directories</a></h3>
727     <!------------------------------------------------------------------------->
728
729     Every directory checked out of CVS will contain a <tt>CVS</tt> directory;
730     for the most part these can just be ignored.
731
732
733     <!------------------------------------------------------------------------->
734     <h3><a name="include"><tt>llvm/include</tt></a></h3>
735     <!------------------------------------------------------------------------->
736
737     This directory contains public header files exported from the LLVM
738     library. The three main subdirectories of this directory are:<p>
739
740     <ol>
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...
745
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
749        library.
750
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
755        script generates.
756     </ol>
757
758     <!------------------------------------------------------------------------->
759     <h3><a name="lib"><tt>llvm/lib</tt></a></h3>
760     <!------------------------------------------------------------------------->
761
762     This directory contains most of the source files of the LLVM system. In
763     LLVM almost all
764     code exists in libraries, making it very easy to share code among the
765     different <a href="#tools">tools</a>.<p>
766
767      <dl compact>
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.
770
771       <dt><tt>llvm/lib/AsmParser/</tt><dd> This directory holds the source code
772       for the LLVM assembly language parser library.
773
774       <dt><tt>llvm/lib/ByteCode/</tt><dd> This directory holds code for reading
775       and write LLVM bytecode.
776
777       <dt><tt>llvm/lib/CWriter/</tt><dd> This directory implements the LLVM to C
778       converter.
779
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,
783       etc...
784
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...
789
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
793       description.<br>
794               
795       <dt><tt>llvm/lib/CodeGen/</tt><dd> This directory contains the major parts
796       of the code generator: Instruction Selector, Instruction Scheduling, and
797       Register Allocation.
798
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>.
802     </dl>
803
804     <!------------------------------------------------------------------------->
805     <h3><a name="runtime"><tt>llvm/runtime</tt></a></h3>
806     <!------------------------------------------------------------------------->
807
808     <p>
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
812     version of glibc.
813     </p>
814
815     <p>
816     Unlike the rest of the LLVM suite, this directory needs the LLVM GCC front end
817     to compile.
818     </p>
819
820     <!------------------------------------------------------------------------->
821     <h3><a name="test"><tt>llvm/test</tt></a></h3>
822     <!------------------------------------------------------------------------->
823
824     <p>This directory contains regression tests and source code that is used to
825     test the LLVM infrastructure.
826     </p>
827
828     <!------------------------------------------------------------------------->
829     <h3><a name="tools"><tt>llvm/tools</tt></a></h3>
830     <!------------------------------------------------------------------------->
831
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>
836
837     <dl compact>
838       <dt>
839
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>
844
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>
851
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
854       lookup.<p>
855       
856       <dt><tt><b>llvm-as</b></tt><dd>The assembler transforms the human readable
857       LLVM assembly to LLVM bytecode.<p>
858
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>
862
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>
865       
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>
874
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>
877
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>
884
885       <ol>
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>
897
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>
904       </ol>
905
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>
911
912     </dl>
913
914     <!------------------------------------------------------------------------->
915     <h3><a name="utils"><tt>llvm/utils</tt></a></h3>
916     <!------------------------------------------------------------------------->
917
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.
921
922     <dl compact>
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>
927
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>
933
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>
941
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>
947
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
953       tree.<p>
954       
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>
962
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>
968
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
972       files.<p>
973
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>
979  
980     </dl>
981
982     <!--=====================================================================-->
983     <h2><center><a name="cfront">Compiling the LLVM GCC Front End</center></h2>
984     <hr>
985     <!--=====================================================================-->
986
987     <p>
988     <b>
989     This step is optional if you have the GCC front end binary distribution for
990     your platform.
991     </b>
992     </p>
993
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.
996     <p>
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:
1000
1001     <ol>
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.
1007
1008         <li><tt>cd <i>GCCOBJ</i></tt>
1009
1010         <li>Configure the source code:
1011         <ul>
1012             <li>On Linux/x86, use
1013             <ul>
1014                 <li><tt><i>GCCSRC</i>/configure --prefix=<i>LLVMGCCDIR</i>
1015                 --enable-languages=c</tt>
1016             </ul>
1017
1018             <li>On Solaris/Sparc, use
1019             <ul>
1020                 <li><tt><i>GCCSRC</i>/configure --prefix=<i>LLVMGCCDIR</i>
1021                  --enable-languages=c --target=sparcv9-sun-solaris2</tt>
1022             </ul>
1023         </ul>
1024
1025         <li><tt>gmake</tt>
1026
1027         <li>The build will eventually fail.  Don't worry; chances are good that
1028         everything that needed to build is built.
1029
1030         <li><tt>gmake -k install</tt>
1031     </ol>
1032
1033     <p>
1034     Once this is done, you should have a built front end compiler in
1035     <tt><i>LLVMGCCDIR</i></tt>.
1036     </p>
1037
1038     <!--=====================================================================-->
1039     <h2>
1040     <center><a name="tutorial">An Example Using the LLVM Tool Chain</center>
1041     </h2>
1042     <hr>
1043     <!--=====================================================================-->
1044
1045     <ol>
1046     <li>First, create a simple C file, name it 'hello.c':
1047        <pre>
1048    #include &lt;stdio.h&gt;
1049    int main() {
1050      printf("hello world\n");
1051      return 0;
1052    }
1053        </pre>
1054
1055     <li>Next, compile the C file into a LLVM bytecode file:<p>
1056
1057       <tt>% llvmgcc hello.c -o hello</tt><p>
1058
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>
1064
1065     <li>Run the program. To make sure the program ran, execute one of the
1066     following commands:<p>
1067       
1068       <tt>% ./hello</tt><p>
1069  
1070       or<p>
1071
1072       <tt>% lli hello.bc</tt><p>
1073
1074     <li>Use the <tt>llvm-dis</tt> utility to take a look at the LLVM assembly
1075     code:<p>
1076
1077       <tt>% llvm-dis < hello.bc | less</tt><p>
1078
1079     <li>Compile the program to native Sparc assembly using the code
1080     generator (assuming you are currently on a Sparc system):<p>
1081
1082       <tt>% llc hello.bc -o hello.s</tt><p>
1083
1084     <li>Assemble the native sparc assemble file into a program:<p>
1085
1086       <tt>% /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.sparc</tt><p>
1087
1088     <li>Execute the native sparc program:<p>
1089
1090       <tt>% ./hello.sparc</tt><p>
1091
1092     </ol>
1093
1094
1095     <!--=====================================================================-->
1096     <h2>
1097     <center><a name="problems">Common Problems</a></center>
1098     </h2>
1099     <hr>
1100     <!--=====================================================================-->
1101
1102     Below are common problems and their remedies:
1103
1104     <dl compact>
1105         <dt><b>When I run configure, it finds the wrong C compiler.</b>
1106         <dd>
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.
1110
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>
1113         explicitly.
1114         <p>
1115
1116         <dt><b>I compile the code, and I get some error about /localhome</b>.
1117         <dd>
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.
1121         <p>
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.
1125
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>
1128         <dd>
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:
1132         <ol>
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.
1137             <p>
1138
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:
1141             <p>
1142             <tt>PATH=<the path without the bad program> ./configure ...</tt>
1143             <p>
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.
1147         </ol>
1148
1149         <dt><b>I've upgraded to a new version of LLVM, and I get strange build
1150         errors.</b>
1151         <dd>
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.
1155         <p>
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.
1159         <p>
1160
1161     </dl>
1162
1163     <!--=====================================================================-->
1164     <h2><center><a name="links">Links</a></center></h2>
1165     <hr>
1166     <!--=====================================================================-->
1167
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
1172     out:</p>
1173
1174     <ul>
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>
1178     </ul>
1179
1180     <hr>
1181
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>
1185
1186             <!-- Created: Mon Jul  1 02:29:02 CDT 2002 -->
1187             <!-- hhmts start -->
1188 Last modified: Mon Aug 11 13:52:22 CDT 2003
1189 <!-- hhmts end -->
1190   </body>
1191 </html>