3b556564732a317abbc643badaf435491a018592
[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       <li><a href="#quickstart">Getting Started Quickly (A Summary)</a>
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
29       <li><a href="#starting">Getting Started with LLVM</a>
30         <ol>
31           <li><a href="#terminology">Terminology and Notation</tt></a>
32           <li><a href="#environment">Setting Up Your Environment</a>
33           <li><a href="#unpack">Unpacking the LLVM Archives</a>
34           <li><a href="#checkout">Checkout LLVM from CVS</a>
35           <li><a href="#installcf">Install the GCC Front End</a>
36           <li><a href="#config">Local LLVM Configuration</tt></a>
37           <li><a href="#compile">Compiling the LLVM Suite Source Code</a>
38           <li><a href="#objfiles">The Location of LLVM Object Files</tt></a>
39         </ol>
40       <li><a href="#layout">Program layout</a>
41       <ol>
42         <li><a href="#cvsdir"><tt>CVS</tt> directories</a>
43         <li><a href="#include"><tt>llvm/include</tt></a>
44         <li><a href="#lib"><tt>llvm/lib</tt></a>
45         <li><a href="#runtime"><tt>llvm/runtime</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="#tutorial">An Example Using the LLVM Tool Chain</a>
51       <li><a href="#problems">Common Problems</a>
52       <li><a href="#links">Links</a>
53     </ul>
54
55
56     <!--=====================================================================-->
57     <center>
58     <h2><a name="overview"><b>Overview</b></a></h2>
59     </center>
60     <hr>
61     <!--=====================================================================-->
62
63     Welcome to LLVM!  In order to get started, you first need to know some
64     basic information.
65
66     <p>
67     First, LLVM comes in two pieces.  The first piece is the LLVM suite.  This
68     contains all of the tools, libraries, and header files needed to use the
69     low level virtual machine.  It contains an assembler, disassembler,
70     bytecode analyzer, and bytecode optimizer.  It also contains a test suite
71     that can be used 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     <center>
81     <h2><a name="quickstart"><b>Getting Started Quickly (A Summary)</b></a></h2>
82     </center>
83     <hr>
84     <!--=====================================================================-->
85
86     Here's the short story for getting up and running quickly with LLVM:
87     <ol>
88         <li>Install the GCC front end:
89         <ol>
90             <li><tt>cd <i>where-you-want-the-C-front-end-to-live</i></tt>
91             <li><tt>gunzip --stdout cfrontend.<i>platform</i>.tar.gz | tar -xvf
92             -</tt>
93         </ol>
94
95         <p>
96
97         <li>Get the Source Code
98         <ul>
99             <li>With the distributed files:
100             <ol>
101                 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
102                 <li><tt>gunzip --stdout llvm.tar.gz | tar -xvf -</tt>
103                 <li><tt>cd llvm</tt>
104             </ol>
105
106             <p>
107
108             <li>With anonymous CVS access:
109             <ol>
110                 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
111                 <li><tt>cvs -d :pserver:anon@llvm-cvs.cs.uiuc.edu:/var/cvs/llvm login</tt>
112                                 <li>Hit the return key when prompted for the password.
113                 <li><tt>cvs -z3 -d :pserver:anon@llvm-cvs.cs.uiuc.edu:/var/cvs/llvm co llvm</tt>
114                 <li><tt>cd llvm</tt>
115             </ol>
116         </ul>
117         </ul>
118
119         <p>
120
121         <li>Configure the LLVM Build Environment
122         <ol>
123             <li>Change directory to where you want to store the LLVM object
124             files and run <tt>configure</tt> to configure the Makefiles and
125             header files for the default platform.
126             Useful options include:
127                 <ul>
128                     <li><tt>--with-llvmgccdir=<i>directory</i></tt>
129                     <br>
130                     Specify where the LLVM GCC frontend is installed.
131                     <p>
132
133                     <li><tt>--enable-spec2000=<i>directory</i></tt>
134                     <br>
135                     Enable the SPEC2000 benchmarks for testing.  The SPEC2000
136                     benchmarks should be available in <tt><i>directory</i></tt>.
137                 </ul>
138         </ol>
139
140         <p>
141
142         <li>Build the LLVM Suite
143         <ol>
144             <li>Set your LLVM_LIB_SEARCH_PATH environment variable.
145             <li><tt>gmake -k |& tee gnumake.out
146             &nbsp;&nbsp;&nbsp;# this is csh or tcsh syntax</tt>
147         </ol>
148
149         <p>
150
151     </ol>
152
153     <p>
154     Consult the <a href="starting">Getting Started with LLVM</a> section for
155     detailed information on configuring and compiling LLVM.  See
156     <a href="#environment">Setting Up Your Environment</a> for tips that
157     simplify working with the GCC front end and LLVM tools.  Go to
158     <a href="#layout">Program Layout</a> to learn about the layout of the
159     source code tree.
160
161     <!--=====================================================================-->
162     <center>
163     <h2><a name="requirements"><b>Requirements</b></a></h2>
164     </center>
165     <hr>
166     <!--=====================================================================-->
167
168     Before you begin to use the LLVM system, review the requirements given
169     below.  This may save you some trouble by knowing ahead of time what
170     hardware and software you will need.
171
172     <!--=====================================================================-->
173     <h3><a name="hardware"><b>Hardware</b></a></h3>
174     <!--=====================================================================-->
175     LLVM is known to work on the following platforms:
176     <ul>
177         <li> Linux on x86 (Pentium and above)
178         <ul>
179             <li> Approximately 760 MB of Free Disk Space
180             <ul>
181                 <li>Source code: 30 MB
182                 <li>Object code: 670 MB
183                 <li>GCC front end: 60 MB
184             </ul>
185         </ul>
186
187         <p>
188
189         <li> Solaris on SparcV9 (Ultrasparc)
190         <ul>
191             <li> Approximately 1.24 GB of Free Disk Space
192             <ul>
193                 <li>Source code: 30 MB
194                 <li>Object code: 1000 MB
195                 <li>GCC front end: 210 MB
196             </ul>
197         </ul>
198     </ul>
199
200     The LLVM suite <i>may</i> compile on other platforms, but it is not
201     guaranteed to do so.  If compilation is successful, the LLVM utilities
202     should be able to assemble, disassemble, analyze, and optimize LLVM
203     bytecode.  Code generation should work as well, although the generated
204     native code may not work on your platform.
205     <p>
206     The GCC front end is not very portable at the moment.  If you want to get
207     it to work on another platform, you can always request
208     <a href="mailto:llvm-request@zion.cs.uiuc.edu">a copy of the source</a>
209     and try to compile it on your platform.
210     </p>
211
212     <!--=====================================================================-->
213     <h3><a name="software"><b>Software</b></a></h3>
214     <!--=====================================================================-->
215     <p>
216
217     Compiling LLVM requires that you have several software packages installed:
218
219     <ul compact>
220         <li>
221         <a href="http://gcc.gnu.org">GCC 3.x with C and C++ language support</a>
222
223         <li>
224         <a href="http://savannah.gnu.org/projects/make">GNU Make</a>
225
226         <li>
227         <a href="http://www.gnu.org/software/flex">Flex</a>
228
229         <li>
230         <a href="http://www.gnu.org/software/bison/bison.html">Bison</a>
231     </ul>
232
233     <p>
234     There are some additional tools that you may want to have when working with
235     LLVM:
236     </p>
237
238     <ul>
239         <li><A href="http://www.gnu.org/software/autoconf">GNU Autoconf</A>
240         <li><A href="http://savannah.gnu.org/projects/m4">GNU M4</A>
241         <p>
242         If you want to make changes to the configure scripts, you will need
243         GNU autoconf (2.57 or higher), and consequently, GNU M4 (version 1.4
244         or higher).
245         </p>
246
247                 <li><A href="http://www.codesourcery.com/qm/qmtest">QMTest</A>
248                 <li><A href="http://www.python.org">Python</A>
249         <p>
250         These are needed to use the LLVM test suite.
251     </ul>
252
253
254     <p>The remainder of this guide is meant to get you up and running with
255     LLVM and to give you some basic information about the LLVM environment.
256     A <a href="#starting">complete guide to installation</a> is provided in the
257     next section.
258
259     <p>The later sections of this guide describe the <a
260     href="#layout">general layout</a> of the the LLVM source tree, a <a
261     href="#tutorial">simple example</a> using the LLVM tool chain, and <a
262     href="#links">links</a> to find more information about LLVM or to get
263     help via e-mail.
264
265     <!--=====================================================================-->
266     <center>
267     <h2><a name="starting"><b>Getting Started with LLVM</b></a></h2>
268     </center>
269     <hr>
270     <!--=====================================================================-->
271
272     <!------------------------------------------------------------------------->
273     <h3><a name="terminology">Terminology and Notation</a></h3>
274     <!------------------------------------------------------------------------->
275
276     <p>Throughout this manual, the following names are used to denote paths
277     specific to the local system and working environment.  <i>These are not
278     environment variables you need to set but just strings used in the rest
279     of this document below</i>.  In any of the examples below, simply replace
280     each of these names with the appropriate pathname on your local system.
281     All these paths are absolute:</p>
282     <dl compact>
283         <dt>SRC_ROOT
284         <dd>
285         This is the top level directory of the LLVM source tree.
286         <p>
287
288         <dt>OBJ_ROOT
289         <dd>
290         This is the top level directory of the LLVM object tree (i.e. the
291         tree where object files and compiled programs will be placed.  It
292         can be the same as SRC_ROOT).
293         <p>
294
295         <dt>LLVMGCCDIR
296         <dd>
297         This is the where the LLVM GCC Front End is installed.
298         <p>
299         For the pre-built GCC front end binaries, the LLVMGCCDIR is
300         <tt>cfrontend/<i>platform</i>/llvm-gcc</tt>.
301     </dl>
302
303     <!------------------------------------------------------------------------->
304     <h3><a name="environment">Setting Up Your Environment</a></h3>
305     <!------------------------------------------------------------------------->
306
307     <p>
308     In order to compile and use LLVM, you will need to set some environment
309     variables.  There are also some shell aliases which you may find useful.
310     You can set these on the command line, or better yet, set them in your
311     <tt>.cshrc</tt> or <tt>.profile</tt>.
312
313     <dl compact>
314         <dt><tt>LLVM_LIB_SEARCH_PATH</tt>=<tt><i>LLVMGCCDIR</i>/llvm-gcc/bytecode-libs</tt>
315         <dd>
316         This environment variable helps the LLVM GCC front end find bytecode
317         libraries that it will need for compilation.
318         <p>
319
320         <dt>alias llvmgcc <i>LLVMGCCDIR</i><tt>/llvm-gcc/bin/gcc</tt>
321         <dt>alias llvmg++ <i>LLVMGCCDIR</i><tt>/llvm-gcc/bin/g++</tt>
322         <dd>
323         This alias allows you to use the LLVM C and C++ front ends without putting
324         them in your <tt>PATH</tt> or typing in their complete pathnames.
325     </dl>
326
327     <!------------------------------------------------------------------------->
328     <h3><a name="unpack">Unpacking the LLVM Archives</a></h3>
329     <!------------------------------------------------------------------------->
330
331     <p>
332     If you have the LLVM distribution, you will need to unpack it before you
333     can begin to compile it.  LLVM is distributed as a set of three files.  Each
334     file is a TAR archive that is compressed with the gzip program.
335     </p>
336
337     <p> The three files are as follows:
338     <dl compact>
339         <dt>llvm.tar.gz
340         <dd>This is the source code to the LLVM suite.
341         <p>
342
343         <dt>cfrontend.sparc.tar.gz
344         <dd>This is the binary release of the GCC front end for Solaris/Sparc.
345         <p>
346
347         <dt>cfrontend.x86.tar.gz
348         <dd>This is the binary release of the GCC front end for Linux/x86.
349     </dl>
350
351     <!------------------------------------------------------------------------->
352     <h3><a name="checkout">Checkout LLVM from CVS</a></h3>
353     <!------------------------------------------------------------------------->
354
355     <p>If you have access to our CVS repository, you can get a fresh copy of
356     the entire source code.  All you need to do is check it out from CVS as
357     follows:
358     <ul>
359     <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
360         <li><tt>cvs -d :pserver:anon@llvm-cvs.cs.uiuc.edu:/var/cvs/llvm login</tt>
361         <li>Hit the return key when prompted for the password.
362         <li><tt>cvs -z3 -d :pserver:anon@llvm-cvs.cs.uiuc.edu:/var/cvs/llvm co llvm</tt>
363     </ul>
364
365     <p>This will create an '<tt>llvm</tt>' directory in the current
366     directory and fully populate it with the LLVM source code, Makefiles,
367     test directories, and local copies of documentation files.</p>
368
369     <p>
370     Note that the GCC front end is not included in the CVS repository.  You
371     should have downloaded the binary distribution for your platform.
372     </p>
373
374     <!------------------------------------------------------------------------->
375     <h3><a name="installcf">Install the GCC Front End</a></h3>
376     <!------------------------------------------------------------------------->
377
378     <p>
379     Before configuring and compiling the LLVM suite, you need to extract the
380     LLVM GCC front end from the binary distribution.  It is used for building the
381     bytecode libraries later used by the GCC front end for linking programs, and
382     its location must be specified when the LLVM suite is configured.
383     </p>
384
385     <p>
386     To install the GCC front end, do the following:
387     <ol>
388         <li><tt>cd <i>where-you-want-the-front-end-to-live</i></tt>
389         <li><tt>gunzip --stdout cfrontend.<i>platform</i>.tar.gz | tar -xvf
390         -</tt>
391     </ol>
392
393     <!------------------------------------------------------------------------->
394     <h3><a name="config">Local LLVM Configuration</a></h3>
395     <!------------------------------------------------------------------------->
396
397     <p>Once checked out from the CVS repository, the LLVM suite source code
398     must be configured via the <tt>configure</tt> script.  This script sets
399     variables in <tt>llvm/Makefile.config</tt> and
400     <tt>llvm/include/Config/config.h</tt>.  It also populates <i>OBJ_ROOT</i>
401     with the Makefiles needed to build LLVM.
402
403     <p>
404     The following environment variables are used by the <tt>configure</tt>
405     script to configure the build system:
406     </p>
407
408     <table border=1>
409         <tr>
410             <th>Variable</th>
411             <th>
412             Purpose
413             </th>
414         </tr>
415
416         <tr>
417             <td>CC</td>
418             <td>
419             Tells <tt>configure</tt> which C compiler to use.  By default,
420             <tt>configure</tt> will look for the first GCC C compiler in
421             <tt>PATH</tt>.  Use this variable to override
422             <tt>configure</tt>'s default behavior.
423             </td>
424         </tr>
425
426         <tr>
427             <td>CXX</td>
428             <td>
429             Tells <tt>configure</tt> which C++ compiler to use.  By default,
430             <tt>configure</tt> will look for the first GCC C++ compiler in
431             <tt>PATH</tt>.  Use this variable to override
432             <tt>configure</tt>'s default behavior.
433             </td>
434         </tr>
435     </table>
436
437     <p>
438     The following options can be used to set or enable LLVM specific options:
439     </p>
440
441     <dl compact>
442     <dt><i>--with-llvmgccdir=LLVMGCCDIR</i>
443     <dd>
444         Path to the location where the LLVM C front end binaries and
445         associated libraries will be installed.
446         <p>
447     <dt><i>--enable-optimized</i>
448     <dd>
449         Enables optimized compilation by default (debugging symbols are removed
450         and GCC optimization flags are enabled).  The default is to use an
451         unoptimized build (also known as a debug build).
452         <p>
453     <dt><i>--enable-jit</i>
454     <dd>
455         Compile the Just In Time (JIT) functionality.  This is not available
456         on all platforms.  The default is dependent on platform, so it is best
457         to explicitly enable it if you want it.
458         <p>
459     <dt><i>--enable-spec2000</i>
460     <dt><i>--enable-spec2000=&lt;<tt>directory</tt>&gt;</i>
461     <dd>
462         Enable the use of SPEC2000 when testing LLVM.  This is disabled by default
463         (unless <tt>configure</tt> finds SPEC2000 installed).  By specifying
464         <tt>directory</tt>, you can tell configure where to find the SPEC2000
465         benchmarks.  If <tt>directory</tt> is left unspecified, <tt>configure</tt>
466         uses the default value
467         <tt>/home/vadve/shared/benchmarks/speccpu2000/benchspec</tt>.
468     </dl>
469
470     <p>
471     To configure LLVM, follow these steps:
472     <ol>
473         <li>Change directory into the object root directory:
474         <br>
475         <tt>cd <i>OBJ_ROOT</i></tt>
476         <p>
477
478         <li>Run the <tt>configure</tt> script located in the LLVM source tree:
479         <br>
480         <tt><i>SRC_ROOT</i>/configure</tt>
481         <p>
482     </ol>
483     </p>
484
485     In addition to running <tt>configure</tt>, you must set the
486     <tt>LLVM_LIB_SEARCH_PATH</tt> environment variable in your startup scripts.
487     This environment variable is used to locate "system" libraries like
488     "<tt>-lc</tt>" and "<tt>-lm</tt>" when linking.  This variable should be set
489     to the absolute path for the bytecode-libs subdirectory of the GCC front end
490     install, or <i>LLVMGCCDIR</i>/llvm-gcc/bytecode-libs.  For example, one might
491     set <tt>LLVM_LIB_SEARCH_PATH</tt> to
492     <tt>/home/vadve/lattner/local/x86/llvm-gcc/bytecode-libs</tt> for the X86
493     version of the GCC front end on our research machines.<p>
494
495     <!------------------------------------------------------------------------->
496     <h3><a name="compile">Compiling the LLVM Suite Source Code</a></h3>
497     <!------------------------------------------------------------------------->
498
499     Once you have configured LLVM, you can build it.  There are three types of
500     builds:
501
502     <dl compact>
503         <dt>Debug Builds
504         <dd>
505         These builds are the default when one types <tt>gmake</tt> (unless the
506         <tt>--enable-optimized</tt> option was used during configuration).  The
507         build system will compile the tools and libraries with debugging
508         information.
509         <p>
510
511         <dt>Release (Optimized) Builds
512         <dd>
513         These builds are enabled with the <tt>--enable-optimized</tt> option to
514         <tt>configure</tt> or by specifying <tt>ENABLE_OPTIMIZED=1</tt> on the
515         <tt>gmake</tt> command line.  For these builds, the build system will
516         compile the tools and libraries with GCC optimizations enabled and strip
517         debugging information from the libraries and executables it generates. 
518         <p>
519
520         <dt>Profile Builds
521         <dd>
522         These builds are for use with profiling.  They compile profiling
523         information into the code for use with programs like <tt>gprof</tt>.
524         Profile builds must be started by specifying <tt>ENABLE_PROFILING=1</tt>
525         on the <tt>gmake</tt> command line.
526     </dl>
527
528     Once you have LLVM configured, you can build it by entering the
529     <i>OBJ_ROOT</i> directory and issuing the following command:
530     <p>
531     <tt>gmake</tt>
532
533     <p>
534     If you have multiple processors in your machine, you may wish to use some
535     of the parallel build options provided by GNU Make.  For example, you could
536     use the command:
537     </p>
538
539     <p>
540     <tt>gmake -j2</tt>
541
542     <p>
543     There are several special targets which are useful when working with the LLVM
544     source code:
545
546     <dl compact>
547         <dt><tt>gmake clean</tt>
548         <dd>
549         Removes all files generated by the build.  This includes object files,
550         generated C/C++ files, libraries, and executables.
551         <p>
552
553         <dt><tt>gmake distclean</tt>
554         <dd>
555         Removes everything that <tt>gmake clean</tt> does, but also removes
556         files generated by <tt>configure</tt>.  It attempts to return the
557         source tree to the original state in which it was shipped.
558         <p>
559
560         <dt><tt>gmake install</tt>
561         <dd>
562         Installs LLVM files into the proper location.  For the most part,
563         this does nothing, but it does install bytecode libraries into the
564         GCC front end's bytecode library directory.  If you need to update
565         your bytecode libraries, this is the target to use once you've built
566         them.
567         <p>
568
569     </dl>
570
571     It is also possible to override default values from <tt>configure</tt> by
572     declaring variables on the command line.  The following are some examples:
573
574     <dl compact>
575         <dt><tt>gmake ENABLE_OPTIMIZED=1</tt>
576         <dd>
577         Perform a Release (Optimized) build.
578         <p>
579
580         <dt><tt>gmake ENABLE_PROFILING=1</tt>
581         <dd>
582         Perform a Profiling build.
583         <p>
584
585         <dt><tt>gmake VERBOSE=1</tt>
586         <dd>
587         Print what <tt>gmake</tt> is doing on standard output.
588         <p>
589     </dl>
590
591     Every directory in the LLVM object tree includes a <tt>Makefile</tt> to
592     build it and any subdirectories that it contains.  Entering any directory
593     inside the LLVM object tree and typing <tt>gmake</tt> should rebuild
594     anything in or below that directory that is out of date.
595
596     <!------------------------------------------------------------------------->
597     <h3><a name="objfiles">The Location of LLVM Object Files</a></h3>
598     <!------------------------------------------------------------------------->
599
600     <p>
601     The LLVM build system is capable of sharing a single LLVM source tree among
602     several LLVM builds.  Hence, it is possible to build LLVM for several
603     different platforms or configurations using the same source tree.
604     <p>
605     This is accomplished in the typical autoconf manner:
606     <ul>
607         <li>Change directory to where the LLVM object files should live:
608         <p>
609         <tt>cd <i>OBJ_ROOT</i></tt>
610
611         <li>Run the <tt>configure</tt> script found in the LLVM source directory:
612         <p>
613         <tt><i>SRC_ROOT</i>/configure</tt>
614     </ul>
615
616     <p>
617     The LLVM build will place files underneath <i>OBJ_ROOT</i> in directories
618     named after the build type:
619     </p>
620
621     <dl compact>
622         <dt>Debug Builds
623         <dd>
624         <dl compact>
625             <dt>Tools
626             <dd><tt><i>OBJ_ROOT</i>/tools/Debug</tt>
627             <dt>Libraries
628             <dd><tt><i>OBJ_ROOT</i>/lib/Debug</tt>
629         </dl>
630         <p>
631
632         <dt>Release Builds
633         <dd>
634         <dl compact>
635             <dt>Tools
636             <dd><tt><i>OBJ_ROOT</i>/tools/Release</tt>
637             <dt>Libraries
638             <dd><tt><i>OBJ_ROOT</i>/lib/Release</tt>
639         </dl>
640         <p>
641
642         <dt>Profile Builds
643         <dd>
644         <dl compact>
645             <dt>Tools
646             <dd><tt><i>OBJ_ROOT</i>/tools/Profile</tt>
647             <dt>Libraries
648             <dd><tt><i>OBJ_ROOT</i>/lib/Profile</tt>
649         </dl>
650     </dl>
651
652     <!--=====================================================================-->
653     <center>
654     <h2><a name="layout"><b>Program Layout</b></a></h2>
655     </center>
656     <hr>
657     <!--=====================================================================-->
658
659     <p>
660     One useful source of information about the LLVM source base is the LLVM <a
661     href="http://www.doxygen.org">doxygen</a> documentation, available at <tt><a
662     href="http://llvm.cs.uiuc.edu/doxygen/">http://llvm.cs.uiuc.edu/doxygen/</a></tt>.
663     The following is a brief introduction to code layout:
664     </p>
665
666     <!------------------------------------------------------------------------->
667     <h3><a name="cvsdir"><tt>CVS</tt> directories</a></h3>
668     <!------------------------------------------------------------------------->
669
670     Every directory checked out of CVS will contain a <tt>CVS</tt> directory;
671     for the most part these can just be ignored.
672
673
674     <!------------------------------------------------------------------------->
675     <h3><a name="include"><tt>llvm/include</tt></a></h3>
676     <!------------------------------------------------------------------------->
677
678     This directory contains public header files exported from the LLVM
679     library. The three main subdirectories of this directory are:<p>
680
681     <ol>
682        <li><tt>llvm/include/llvm</tt> - This directory contains all of the LLVM
683        specific header files.  This directory also has subdirectories for
684        different portions of LLVM: <tt>Analysis</tt>, <tt>CodeGen</tt>,
685        <tt>Target</tt>, <tt>Transforms</tt>, etc...
686
687        <li><tt>llvm/include/Support</tt> - This directory contains generic
688        support libraries that are independent of LLVM, but are used by LLVM.
689        For example, some C++ STL utilities and a Command Line option processing
690        library store their header files here.
691
692        <li><tt>llvm/include/Config</tt> - This directory contains header files
693        configured by the <tt>configure</tt> script.  They wrap "standard" UNIX
694        and C header files.  Source code can include these header files which
695        automatically take care of the conditional #includes that the
696        <tt>configure</tt> script generates.
697     </ol>
698
699     <!------------------------------------------------------------------------->
700     <h3><a name="lib"><tt>llvm/lib</tt></a></h3>
701     <!------------------------------------------------------------------------->
702
703     This directory contains most of the source files of the LLVM system. In
704     LLVM, almost all
705     code exists in libraries, making it very easy to share code among the
706     different <a href="#tools">tools</a>.<p>
707
708      <dl compact>
709       <dt><tt>llvm/lib/VMCore/</tt><dd> This directory holds the core LLVM
710       source files that implement core classes like Instruction and BasicBlock.
711
712       <dt><tt>llvm/lib/AsmParser/</tt><dd> This directory holds the source code
713       for the LLVM assembly language parser library.
714
715       <dt><tt>llvm/lib/ByteCode/</tt><dd> This directory holds code for reading
716       and write LLVM bytecode.
717
718       <dt><tt>llvm/lib/CWriter/</tt><dd> This directory implements the LLVM to C
719       converter.
720
721       <dt><tt>llvm/lib/Analysis/</tt><dd> This directory contains a variety of
722       different program analyses, such as Dominator Information, Call Graphs,
723       Induction Variables, Interval Identification, Natural Loop Identification,
724       etc...
725
726       <dt><tt>llvm/lib/Transforms/</tt><dd> This directory contains the source
727       code for the LLVM to LLVM program transformations, such as Aggressive Dead
728       Code Elimination, Sparse Conditional Constant Propagation, Inlining, Loop
729       Invariant Code Motion, Dead Global Elimination, and many others...
730
731       <dt><tt>llvm/lib/Target/</tt><dd> This directory contains files that
732       describe various target architectures for code generation.  For example,
733       the llvm/lib/Target/Sparc directory holds the Sparc machine
734       description.<br>
735               
736       <dt><tt>llvm/lib/CodeGen/</tt><dd> This directory contains the major parts
737       of the code generator: Instruction Selector, Instruction Scheduling, and
738       Register Allocation.
739
740       <dt><tt>llvm/lib/Support/</tt><dd> This directory contains the source code
741       that corresponds to the header files located in
742       <tt>llvm/include/Support/</tt>.
743     </dl>
744
745     <!------------------------------------------------------------------------->
746     <h3><a name="runtime"><tt>llvm/runtime</tt></a></h3>
747     <!------------------------------------------------------------------------->
748
749     <p>
750     This directory contains libraries which are compiled into LLVM bytecode and
751     used when linking programs with the GCC front end.  Most of these libraries
752     are skeleton versions of real libraries; for example, libc is a stripped down
753     version of glibc.
754     </p>
755
756     <p>
757     Unlike the rest of the LLVM suite, this directory needs the LLVM GCC front end
758     to compile.
759     </p>
760
761     <!------------------------------------------------------------------------->
762     <h3><a name="test"><tt>llvm/test</tt></a></h3>
763     <!------------------------------------------------------------------------->
764
765     <p>This directory contains regression tests and source code that is used to
766     test the LLVM infrastructure.
767     </p>
768
769     <!------------------------------------------------------------------------->
770     <h3><a name="tools"><tt>llvm/tools</tt></a></h3>
771     <!------------------------------------------------------------------------->
772
773     <p>The <b>tools</b> directory contains the executables built out of the
774     libraries above, which form the main part of the user interface.  You can
775     always get help for a tool by typing <tt>tool_name --help</tt>.  The
776     following is a brief introduction to the most important tools.</p>
777
778     <dl compact>
779       <dt>
780
781       <dt><tt><b>analyze</b></tt><dd> <tt>analyze</tt> is used to run a specific
782       analysis on an input LLVM bytecode file and print out the results.  It is
783       primarily useful for debugging analyses, or familiarizing yourself with
784       what an analysis does.<p>
785
786       <dt><tt><b>bugpoint</b></tt><dd> <tt>bugpoint</tt> is used to debug
787       optimization passes or code generation backends by narrowing down the
788       given test case to the minimum number of passes and/or instructions that
789       still cause a problem, whether it is a crash or miscompilation. See <a
790       href="HowToSubmitABug.html">HowToSubmitABug.html</a> for more information
791       on using <tt>bugpoint</tt>.<p>
792
793       <dt><tt><b>llvm-ar</b></tt><dd>The archiver produces an archive containing
794       the given LLVM bytecode files, optionally with an index for faster
795       lookup.<p>
796       
797       <dt><tt><b>llvm-as</b></tt><dd>The assembler transforms the human readable
798       LLVM assembly to LLVM bytecode.<p>
799
800       <dt><tt><b>llvm-dis</b></tt><dd>The disassembler transforms the LLVM
801       bytecode to human readable LLVM assembly.  Additionally, it can convert
802       LLVM bytecode to C, which is enabled with the <tt>-c</tt> option.<p>
803
804       <dt><tt><b>llvm-link</b></tt><dd> <tt>llvm-link</tt>, not surprisingly,
805       links multiple LLVM modules into a single program.<p>
806       
807       <dt><tt><b>lli</b></tt><dd> <tt>lli</tt> is the LLVM interpreter, which
808       can directly execute LLVM bytecode (although very slowly...). In addition
809       to a simple interpreter, <tt>lli</tt> also has a tracing mode (entered by
810       specifying <tt>-trace</tt> on the command line). Finally, for
811       architectures that support it (currently only x86 and Sparc), by default,
812       <tt>lli</tt> will function as a Just-In-Time compiler (if the
813       functionality was compiled in), and will execute the code <i>much</i>
814       faster than the interpreter.<p>
815
816       <dt><tt><b>llc</b></tt><dd> <tt>llc</tt> is the LLVM backend compiler,
817       which translates LLVM bytecode to a SPARC or x86 assembly file.<p>
818
819       <dt><tt><b>llvmgcc</b></tt><dd> <tt>llvmgcc</tt> is a GCC-based C frontend
820       that has been retargeted to emit LLVM code as the machine code output.  It
821       works just like any other GCC compiler, taking the typical <tt>-c, -S, -E,
822       -o</tt> options that are typically used.  The source code for the
823       <tt>llvmgcc</tt> tool is currently not included in the LLVM CVS tree
824       because it is quite large and not very interesting.<p>
825
826       <ol>
827         <dt><tt><b>gccas</b></tt><dd> This tool is invoked by the
828         <tt>llvmgcc</tt> frontend as the "assembler" part of the compiler.  This
829         tool actually assembles LLVM assembly to LLVM bytecode,
830         performs a variety of optimizations, and outputs LLVM bytecode.  Thus
831         when you invoke <tt>llvmgcc -c x.c -o x.o</tt>, you are causing
832         <tt>gccas</tt> to be run, which writes the <tt>x.o</tt> file (which is
833         an LLVM bytecode file that can be disassembled or manipulated just like
834         any other bytecode file).  The command line interface to <tt>gccas</tt>
835         is designed to be as close as possible to the <b>system</b>
836         `<tt>as</tt>' utility so that the gcc frontend itself did not have to be
837         modified to interface to a "weird" assembler.<p>
838
839         <dt><tt><b>gccld</b></tt><dd> <tt>gccld</tt> links together several LLVM
840         bytecode files into one bytecode file and does some optimization.  It is
841         the linker invoked by the GCC frontend when multiple .o files need to be
842         linked together.  Like <tt>gccas</tt>, the command line interface of
843         <tt>gccld</tt> is designed to match the system linker, to aid
844         interfacing with the GCC frontend.<p>
845       </ol>
846
847       <dt><tt><b>opt</b></tt><dd> <tt>opt</tt> reads LLVM bytecode, applies a
848       series of LLVM to LLVM transformations (which are specified on the command
849       line), and then outputs the resultant bytecode.  The '<tt>opt --help</tt>'
850       command is a good way to get a list of the program transformations
851       available in LLVM.<p>
852
853     </dl>
854
855     <!------------------------------------------------------------------------->
856     <h3><a name="utils"><tt>llvm/utils</tt></a></h3>
857     <!------------------------------------------------------------------------->
858
859     This directory contains utilities for working with LLVM source code, and some
860     of the utilities are actually required as part of the build process because
861     they are code generators for parts of LLVM infrastructure.
862
863     <dl compact>
864       <td><tt><b>Burg/</b></tt><dd> <tt>Burg</tt> is an instruction selector
865       generator -- it builds trees on which it then performs pattern-matching to
866       select instructions according to the patterns the user has specified. Burg
867       is currently used in the Sparc V9 backend.<p>
868
869       <dt><tt><b>codegen-diff</b></tt><dd> <tt>codegen-diff</tt> is a script
870       that finds differences between code that LLC generates and code that LLI
871       generates. This is a useful tool if you are debugging one of them,
872       assuming that the other generates correct output. For the full user
873       manual, run <tt>`perldoc codegen-diff'</tt>.<p>
874
875       <dt><tt><b>cvsupdate</b></tt><dd> <tt>cvsupdate</tt> is a script that will
876       update your CVS tree, but produce a much cleaner and more organized output
877       than simply running <tt>`cvs -z3 up -dP'</tt> will. For example, it will group
878       together all the new and updated files and modified files in separate
879       sections, so you can see at a glance what has changed. If you are at the
880       top of your LLVM CVS tree, running <tt>utils/cvsupdate</tt> is the
881       preferred way of updating the tree.<p>
882
883       <dt><tt><b>emacs/</b></tt><dd> The <tt>emacs</tt> directory contains
884       syntax-highlighting files which will work with Emacs and XEmacs editors,
885       providing syntax highlighting support for LLVM assembly files and TableGen
886       description files. For information on how to use the syntax files, consult
887       the <tt>README</tt> file in that directory.<p>
888
889       <dt><tt><b>getsrcs.sh</b></tt><dd> The <tt>getsrcs.sh</tt> script finds
890       and outputs all non-generated source files, which is useful if one wishes
891       to do a lot of development across directories and does not want to
892       individually find each file. One way to use it is to run, for example:
893       <tt>xemacs `utils/getsources.sh`</tt> from the top of your LLVM source
894       tree.<p>
895       
896       <dt><tt><b>makellvm</b></tt><dd> The <tt>makellvm</tt> script compiles all
897       files in the current directory and then compiles and links the tool that
898       is the first argument. For example, assuming you are in the directory
899       <tt>llvm/lib/Target/Sparc</tt>, if <tt>makellvm</tt> is in your path,
900       simply running <tt>makellvm llc</tt> will make a build of the current
901       directory, switch to directory <tt>llvm/tools/llc</tt> and build it,
902       causing a re-linking of LLC.<p>
903
904       <dt><tt><b>NightlyTest.pl</b></tt> and
905       <tt><b>NightlyTestTemplate.html</b></tt><dd> These files are used in a
906       cron script to generate nightly status reports of the functionality of
907       tools, and the results can be seen by following the appropriate link on
908       the <a href="http://llvm.cs.uiuc.edu/">LLVM homepage</a>.<p>
909
910       <dt><tt><b>TableGen/</b></tt><dd> The <tt>TableGen</tt> directory contains
911       the tool used to generate register descriptions, instruction set
912       descriptions, and even assemblers from common TableGen description
913       files.<p>
914
915       <dt><tt><b>vim/</b></tt><dd> The <tt>vim</tt> directory contains
916       syntax-highlighting files which will work with the VIM editor, providing
917       syntax highlighting support for LLVM assembly files and TableGen
918       description files. For information on how to use the syntax files, consult
919       the <tt>README</tt> file in that directory.<p>
920  
921     </dl>
922
923     <!--=====================================================================-->
924     <h2>
925     <center><a name="tutorial">An Example Using the LLVM Tool Chain</center>
926     </h2>
927     <hr>
928     <!--=====================================================================-->
929
930     <ol>
931     <li>First, create a simple C file, name it 'hello.c':
932        <pre>
933    #include &lt;stdio.h&gt;
934    int main() {
935      printf("hello world\n");
936      return 0;
937    }
938        </pre>
939
940     <li>Next, compile the C file into a LLVM bytecode file:<p>
941
942       <tt>% llvmgcc hello.c -o hello</tt><p>
943
944       This will create two result files: <tt>hello</tt> and
945       <tt>hello.bc</tt>. The <tt>hello.bc</tt> is the LLVM bytecode that
946       corresponds the the compiled program and the library facilities that it
947       required.  <tt>hello</tt> is a simple shell script that runs the bytecode
948       file with <tt>lli</tt>, making the result directly executable.<p>
949
950     <li>Run the program. To make sure the program ran, execute one of the
951     following commands:<p>
952       
953       <tt>% ./hello</tt><p>
954  
955       or<p>
956
957       <tt>% lli hello.bc</tt><p>
958
959     <li>Use the <tt>llvm-dis</tt> utility to take a look at the LLVM assembly
960     code:<p>
961
962       <tt>% llvm-dis < hello.bc | less</tt><p>
963
964     <li>Compile the program to native Sparc assembly using the code
965     generator (assuming you are currently on a Sparc system):<p>
966
967       <tt>% llc hello.bc -o hello.s</tt><p>
968
969     <li>Assemble the native sparc assemble file into a program:<p>
970
971       <tt>% /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.sparc</tt><p>
972
973     <li>Execute the native sparc program:<p>
974
975       <tt>% ./hello.sparc</tt><p>
976
977     </ol>
978
979
980     <!--=====================================================================-->
981     <h2>
982     <center><a name="problems">Common Problems</a></center>
983     </h2>
984     <hr>
985     <!--=====================================================================-->
986
987     If you are having problems building or using LLVM, or if you have any other
988     general questions about LLVM, please consult the
989         <a href="FAQ.html">Frequently Asked Questions</a> page.
990
991     <!--=====================================================================-->
992     <h2><center><a name="links">Links</a></center></h2>
993     <hr>
994     <!--=====================================================================-->
995
996     <p>This document is just an <b>introduction</b> to how to use LLVM to do
997     some simple things... there are many more interesting and complicated things
998     that you can do that aren't documented here (but we'll gladly accept a patch
999     if you want to write something up!).  For more information about LLVM, check
1000     out:</p>
1001
1002     <ul>
1003     <li><a href="http://llvm.cs.uiuc.edu/">LLVM homepage</a></li>
1004     <li><a href="http://llvm.cs.uiuc.edu/doxygen/">LLVM doxygen tree</a></li>
1005     <li><a href="http://llvm.cs.uiuc.edu/docs/Projects.html">Starting a Project that Uses LLVM</a></li>
1006     </ul>
1007
1008     <hr>
1009
1010     If you have any questions or run into any snags (or you have any
1011     additions...), please send an email to
1012     <a href="mailto:sabre@nondot.org">Chris Lattner</a>.</p>
1013
1014             <!-- Created: Mon Jul  1 02:29:02 CDT 2002 -->
1015             <!-- hhmts start -->
1016 Last modified: Mon Aug 11 13:52:22 CDT 2003
1017 <!-- hhmts end -->
1018   </body>
1019 </html>