blob: 70b56c94088b805759a6eb3680a5e7da9a9be07f [file] [log] [blame]
Guochun Shif4688a82002-07-17 23:05:56 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
John Criswell85ed3612003-06-12 19:34:44 +00003 <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> and
11 <a href="http://www.cs.uiuc.edu/~vadve">Vikram Adve</a>
12 </font></h1></center>
13
14 <!--=====================================================================-->
15 <h2><a name="Contents">Contents</a></h2>
16 <!--=====================================================================-->
17
18 <ul>
19 <li><a href="#overview">Overview</a>
20 <li><a href="#starting">Getting started with LLVM</a>
21 <ol>
John Criswell7a73b802003-06-30 21:59:07 +000022 <li><a href="#requirements">Requirements</a>
23 <ol>
24 <li><a href="#hardware">Hardware</a>
25 <li><a href="#software">Software</a>
26 </ol>
John Criswell85ed3612003-06-12 19:34:44 +000027 <li><a href="#quickstart">Getting started quickly (a summary)</a>
28 <li><a href="#checkout">Checkout LLVM from CVS</a>
29 <li><a href="#terminology">Terminology and Notation</tt></a>
30 <li><a href="#objfiles">The location for object files</tt></a>
31 <li><a href="#config">Local Configuration Options</tt></a>
32 <li><a href="#environment">Setting up your environment</a>
33 <li><a href="#compile">Compiling the source code</a>
34 </ol>
35 <li><a href="#layout">Program layout</a>
36 <ol>
37 <li><a href="#cvsdir">CVS directories</a>
38 <li><a href="#dd"><tt>Depend</tt>, <tt>Debug</tt>, &amp;
39 <tt>Release</tt> directories</a></li>
40 <li><a href="#include"><tt>llvm/include</tt></a>
41 <li><a href="#lib"><tt>llvm/lib</tt></a>
42 <li><a href="#test"><tt>llvm/test</tt></a>
43 <li><a href="#tools"><tt>llvm/tools</tt></a>
44 </ol>
45 <li><a href="#tutorial">An example using the LLVM tool chain</a>
46 <li><a href="#links">Links</a>
47 </ul>
48
49
50 <!--=====================================================================-->
51 <center>
52 <h2><a name="overview"><b>Overview</b></a></h2>
53 </center>
54 <!--=====================================================================-->
55
56 <p>The <a href"starting">next section</a> of this guide is meant to get
57 you up and running with LLVM and to give you some basic information about
58 the LLVM environment. The <a href"#quickstart">first subsection</a> gives
59 a short summary for those who are already familiar with the system and
60 want to get started as quickly as possible.
61
62 <p>The later sections of this guide describe the <a
63 href"#layout">general layout</a> of the the LLVM source-tree, a <a
64 href="#tutorial">simple example</a> using the LLVM tool chain, and <a
65 href="#links">links</a> to find more information about LLVM or to get
66 help via e-mail.
67
68 <!--=====================================================================-->
69 <center>
70 <h2><a name="starting"><b>Getting Started</b></a></h2>
71 </center>
72 <!--=====================================================================-->
73
John Criswell7a73b802003-06-30 21:59:07 +000074 <!--=====================================================================-->
75 <h3><a name="requirements"><b>Requirements</b></a></h3>
76 <!--=====================================================================-->
77
78 <!--=====================================================================-->
79 <h4><a name="hardware"><b>Hardware</b></a></h4>
80 <!--=====================================================================-->
81 LLVM is known to work on the following platforms:
82 <ul>
83 <li> Linux on x86
84 <ul>
85 <li> Approximately 700 MB of Free Disk Space
86 <ul>
87 <li>Source code: 30 MB
88 <li>Object code: 670 MB
89 </ul>
90 </ul>
91 <li> Solaris on Sparc
92 <ul>
93 <li> Approximately 1.03 GB of Free Disk Space
94 <ul>
95 <li>Source code: 30 MB
96 <li>Object code: 1000 MB
97 </ul>
98 </ul>
99 </ul>
100
101 LLVM may compile on other platforms. While the LLVM utilities should work,
102 they will only generate Sparc or x86 machine code.
103
104 <!--=====================================================================-->
105 <h4><a name="software"><b>Software</b></a></h4>
106 <!--=====================================================================-->
107 <p>
108 Compiling LLVM requires that you have several different software packages
109 installed:
110
111 <ul>
112 <li> GCC
113 <p>
114 The GNU Compiler Collection must be installed with C and C++ language
115 support. GCC 3.x is supported, although some effort has been made to
116 support GCC 2.96.
117 </p>
118
119 <p>
120 Note that we currently do not support any other C++ compiler.
121 </p>
122
123 <li> GNU Make
124 <p>
125 The LLVM build system relies upon GNU Make extensions. Therefore, you
126 will need GNU Make (sometimes known as gmake) to build LLVM.
127 </p>
128
129 <li> Flex and Bison
130 <p>
131 The LLVM source code is built using flex and bison. You will not be
132 able to configure and compile LLVM without them.
133 </p>
134 </ul>
135
136 <p>
137 There are some additional tools that you may want to have when working with
138 LLVM:
139 </p>
140
141 <ul>
142 <li> GNU Autoconf and GNU M4
143 <p>
144 If you want to make changes to the autoconf scripts which configure LLVM
145 for compilation, you will need GNU autoconf, and consequently, GNU M4.
146 LLVM was built with autoconf 2.53, so that release and any later
147 release should work.
148 </p>
149 </ul>
John Criswell85ed3612003-06-12 19:34:44 +0000150
151 <!--=====================================================================-->
152 <h3><a name="quickstart"><b>Getting Started Quickly (A Summary)</b></a></h3>
153 <!--=====================================================================-->
154
155 Here's the short story for getting up and running quickly with LLVM:
Chris Lattner96768ea2003-02-14 04:22:13 +0000156 <ol>
John Criswell85ed3612003-06-12 19:34:44 +0000157 <li>Find the path to the CVS repository containing LLVM (we'll call this <i>CVSROOTDIR</i>).
158 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
159 <li><tt>cvs -d <i>CVSROOTDIR</i> checkout llvm</tt>
160 <li><tt>cd llvm</tt>
John Criswell7a73b802003-06-30 21:59:07 +0000161 <li>Run <tt>configure</tt> to configure the Makefiles and header files.
162 Useful options include:
163 <ul>
164 <li><tt>--with-objroot=<i>directory</i></tt>
165 <br>
166 Specifiy where object files should be placed during the build.
167
168 <li><tt>--with-llvmgccdir=<i>directory</i></tt>
169 <br>
170 Specifiy where the LLVM C frontend has been installed.
171 </ul>
John Criswell85ed3612003-06-12 19:34:44 +0000172 <li>Set your LLVM_LIB_SEARCH_PATH environment variable.
173 <li><tt>gmake -k |& tee gnumake.out
174 &nbsp;&nbsp;&nbsp;# this is csh or tcsh syntax</tt>
Chris Lattner96768ea2003-02-14 04:22:13 +0000175 </ol>
John Criswell85ed3612003-06-12 19:34:44 +0000176
177 <p>See <a href="#environment">Setting up your environment</a> on tips to
178 simplify working with the LLVM front-end and compiled tools. See the
179 other sub-sections below for other useful details in working with LLVM,
180 or go straight to <a href="#layout">Program Layout</a> to learn about the
181 layout of the source code tree.
182
183 <!------------------------------------------------------------------------->
184 <h3><a name="terminology">Terminology and Notation</a></h3>
185 <!------------------------------------------------------------------------->
186
187 <p>Throughout this manual, the following names are used to denote paths
188 specific to the local system and working environment. <i>These are not
John Criswell7a73b802003-06-30 21:59:07 +0000189 environment variables you need to set but just strings used in the rest
190 of this document below</i>. In any of the examples below, simply replace
John Criswell85ed3612003-06-12 19:34:44 +0000191 each of these names with the appropriate pathname on your local system.
Chris Lattner1db872d2002-09-06 16:26:13 +0000192 All these paths are absolute:</p>
John Criswell85ed3612003-06-12 19:34:44 +0000193 <ul>
194 </ul>
195
196 <!------------------------------------------------------------------------->
197 <h3><a name="checkout">Checkout LLVM from CVS</a></h3>
198 <!------------------------------------------------------------------------->
199
200 <p>Before checking out the source code, you will need to know the path to
John Criswell7a73b802003-06-30 21:59:07 +0000201 the CVS repository containing the LLVM source code (we'll call this
John Criswell85ed3612003-06-12 19:34:44 +0000202 <i>CVSROOTDIR</i> below). Ask the person responsible for your local LLVM
203 installation to give you this path.
204
205 <p>To get a fresh copy of the entire source code, all you
206 need to do is check it out from CVS as follows:
207 <ul>
208 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
209 <li><tt>cvs -d <i>CVSROOTDIR</i> checkout llvm</tt></p>
210 </ul>
211
212 <p>This will create an '<tt>llvm</tt>' directory in the current
213 directory and fully populate it with the LLVM source code, Makefiles,
214 test directories, and local copies of documentation files.</p>
215
216 <!------------------------------------------------------------------------->
217 <h3><a name="config">Local Configuration Options</a></h3>
218 <!------------------------------------------------------------------------->
219
John Criswell7a73b802003-06-30 21:59:07 +0000220 <p>Once checked out from the CVS repository, options and pathnames specific
221 to an installation of LLVM can be set via the <tt>configure</tt> script.
222 This script sets variables in <tt>llvm/Makefile.config</tt> and
223 <tt>llvm/include/Config/config.h</tt>.
224
225 <p>
226 The following environment variables are used by <tt>configure</tt> to
227 configure Makefile.config:
228 </p>
John Criswell85ed3612003-06-12 19:34:44 +0000229
230 <ul>
John Criswell7a73b802003-06-30 21:59:07 +0000231 <p><li><i>CXX</i> = Pathname of the C++ compiler to use.
232 <p><li><i>CC</i> = Pathname of the C compiler to use.
John Criswell85ed3612003-06-12 19:34:44 +0000233 </ul>
234
John Criswell7a73b802003-06-30 21:59:07 +0000235 The following options can be used to set or enable LLVM specific options:
236
237 <ul>
238 <p><li><i>--with-objroot=LLVM_OBJ_ROOT</i> =
239 Path to the directory where
240 object files, libraries, and executables should be placed.
241 (See the Section on <a href=#objfiles>
242 The location for LLVM object files</a>
243 for more information.)
244 <p><li><i>--with-llvmgccdir=LLVMGCCDIR</i> =
245 Path to the location of the LLVM front-end
246 binaries and associated libraries.
247 <p><li><i>--enable-optimized</i> =
248 Enables optimized compilation (debugging symbols are removed and GCC
249 optimization flags are enabled).
250 <p><li><i>--enable-profiling</i> =
251 Enables profiling compilation (compiler flags needed to add profiling
252 data are enabled).
253 <p><li><i>--enable-verbose</i> =
254 Enables verbose messages during the compile.
255 <p><li><i>--enable-jit</i> =
256 Compile the Just In Time (JIT) functionality. This is not available
257 on all platforms.
258 </ul>
259
260 In addition to running <tt>configure</tt>, you must set the
John Criswell85ed3612003-06-12 19:34:44 +0000261 <tt>LLVM_LIB_SEARCH_PATH</tt> environment variable in your startup scripts.
262 This environment variable is used to locate "system" libraries like
263 "<tt>-lc</tt>" and "<tt>-lm</tt>" when linking. This variable should be set
264 to the absolute path for the bytecode-libs subdirectory of the C front-end
John Criswell7a73b802003-06-30 21:59:07 +0000265 install. For example, one might set <tt>LLVM_LIB_SEARCH_PATH</tt> to
John Criswell85ed3612003-06-12 19:34:44 +0000266 <tt>/home/vadve/lattner/local/x86/llvm-gcc/bytecode-libs</tt> for the X86
267 version of the C front-end on our research machines.<p>
268
269 <!------------------------------------------------------------------------->
270 <h3><a name="objfiles">The location for LLVM object files</a></h3>
271 <!------------------------------------------------------------------------->
272
273 <p>The LLVM make system sends most output files generated during the build
274 into the directory defined by the variable OBJ_ROOT in
275 <tt>llvm/Makefile.config</tt>. This can be either just your normal LLVM
276 source tree or some other directory writable by you. You may wish to put
277 object files on a different filesystem either to keep them from being backed
278 up or to speed up local builds.
279
John Criswell7a73b802003-06-30 21:59:07 +0000280 <p>If you wish to place output files into a separate directory, use the
281 <tt>--with-objroot=<i>directory</i></tt> option of <tt>configure</tt> to
282 set the top level directory of where the object files will go. Otherwise,
283 leave this option unspecified, and <tt>configure</tt> will place files
284 within the LLVM source tree.
John Criswell85ed3612003-06-12 19:34:44 +0000285
286 <!------------------------------------------------------------------------->
287 <h3><a name="environment">Setting up your environment</a></h3>
288 <!------------------------------------------------------------------------->
289
290 <i>NOTE: This step is optional but will set up your environment so you
291 can use the compiled LLVM tools with as little hassle as
292 possible.</i>)
293
294 <p>Add the following lines to your <tt>.cshrc</tt> (or the corresponding
295 lines to your <tt>.profile</tt> if you use a bourne shell derivative).
296
297 <pre>
298 # Make the C front end easy to use...
299 alias llvmgcc <i>LLVMGCCDIR</i><tt>/bin/llvm-gcc</tt>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000300
301 # Make the LLVM tools easy to use...
John Criswell85ed3612003-06-12 19:34:44 +0000302 setenv PATH <i>OBJ_ROOT</i>/llvm/tools/Debug:${PATH}
303 </pre>
304 The <tt>llvmgcc</tt> alias is useful because the C compiler is not
305 included in the CVS tree you just checked out.
John Criswell7a73b802003-06-30 21:59:07 +0000306
John Criswell85ed3612003-06-12 19:34:44 +0000307 <p>The other <a href="#tools">LLVM tools</a> are part of the LLVM
308 source base and built when compiling LLVM. They will be built into the
309 <tt><i>OBJ_ROOT</i>/tools/Debug</tt> directory.</p>
310
311 <!------------------------------------------------------------------------->
312 <h3><a name="compile">Compiling the source code</a></h3>
313 <!------------------------------------------------------------------------->
314
315 <p>Every directory in the LLVM source tree includes a <tt>Makefile</tt> to
316 build it and any subdirectories that it contains. These makefiles require
John Criswell7a73b802003-06-30 21:59:07 +0000317 that you use GNU Make (sometimes called <tt>gmake</tt>) instead of
318 <tt>make</tt> to
John Criswell85ed3612003-06-12 19:34:44 +0000319 build them, but can
320 otherwise be used freely. To build the entire LLVM system, just enter the
321 top level <tt>llvm</tt> directory and type <tt>gmake</tt>. A few minutes
322 later you will hopefully have a freshly compiled toolchain waiting for you
323 in <tt><i>OBJ_ROOT</i>/llvm/tools/Debug</tt>. If you want to look at the
John Criswell7a73b802003-06-30 21:59:07 +0000324 libraries that
325 were compiled, look in <tt><i>OBJ_ROOT</i>/llvm/lib/Debug</tt>.</p>
John Criswell85ed3612003-06-12 19:34:44 +0000326
327 If you get an error about a <tt>/localhome</tt> directory, follow the
328 instructions in the section about <a href="#environment">Setting Up Your
329 Environment.</a>
330
331
332
333 <!--=====================================================================-->
334 <center>
335 <h2><a name="layout"><b>Program Layout</b></a></h2>
336 </center>
337 <!--=====================================================================-->
338
339 <p>One useful source of infomation about the LLVM sourcebase is the LLVM <a
340 href="http://www.doxygen.org">doxygen</a> documentation, available at <tt><a
341 href="http://llvm.cs.uiuc.edu/doxygen/">http://llvm.cs.uiuc.edu/doxygen/</a></tt>. The
342 following is a brief introduction to code layout:</p>
343
344
345 <!------------------------------------------------------------------------->
346 <h3><a name="cvsdir"><tt>CVS</tt> directories</a></h3>
347 <!------------------------------------------------------------------------->
348
349 Every directory checked out of CVS will contain a <tt>CVS</tt> directory;
350 for the most part these can just be ignored.
351
352
353 <!------------------------------------------------------------------------->
354 <h3><a name="ddr"><tt>Depend</tt>, <tt>Debug</tt>, &amp; <tt>Release</tt>
Chris Lattner44ac6592002-08-09 16:14:56 +0000355 directories</a></h3>
John Criswell85ed3612003-06-12 19:34:44 +0000356 <!------------------------------------------------------------------------->
357
358 If you are building with the "<tt>OBJ_ROOT=.</tt>" option enabled in the
John Criswell7a73b802003-06-30 21:59:07 +0000359 <tt>Makefile.config</tt> file (i.e. you did not specify
360 <tt>--with-objroot</tt> when you ran <tt>configure</tt>), most source
361 directories will contain two
John Criswell85ed3612003-06-12 19:34:44 +0000362 directories, <tt>Depend</tt> and <tt>Debug</tt>. The <tt>Depend</tt>
363 directory contains automatically generated dependance files which are used
364 during compilation to make sure that source files get rebuilt if a header
365 file they use is modified. The <tt>Debug</tt> directory holds the object
366 files, library files, and executables that are used for building a debug
367 enabled build. The <tt>Release</tt> directory is created to hold the same
368 files when the <tt>ENABLE_OPTIMIZED=1</tt> flag is passed to <tt>gmake</tt>,
John Criswell7a73b802003-06-30 21:59:07 +0000369 causing an optimized build to be performed.<p>
John Criswell85ed3612003-06-12 19:34:44 +0000370
371
372 <!------------------------------------------------------------------------->
373 <h3><a name="include"><tt>llvm/include</tt></a></h3>
374 <!------------------------------------------------------------------------->
375
376 This directory contains public header files exported from the LLVM
John Criswell7a73b802003-06-30 21:59:07 +0000377 library. The three main subdirectories of this directory are:<p>
John Criswell85ed3612003-06-12 19:34:44 +0000378
John Criswell8df90e02003-06-11 20:46:40 +0000379 <ol>
John Criswell85ed3612003-06-12 19:34:44 +0000380 <li><tt>llvm/include/llvm</tt> - This directory contains all of the LLVM
381 specific header files. This directory also has subdirectories for
382 different portions of LLVM: <tt>Analysis</tt>, <tt>CodeGen</tt>,
383 <tt>Reoptimizer</tt>, <tt>Target</tt>, <tt>Transforms</tt>, etc...
384
385 <li><tt>llvm/include/Support</tt> - This directory contains generic
386 support libraries that are independant of LLVM, but are used by LLVM.
John Criswell7a73b802003-06-30 21:59:07 +0000387 For example, some C++ STL utilities and a Command Line option processing
388 library.
389
390 <li><tt>llvm/include/Config</tt> - This directory contains header files
391 configured by the <tt>configure</tt> script. They wrap "standard" UNIX
392 and C header files. Source code can include these header files which
393 automatically take care of the conditional #includes that the configure
394 script generates.
Chris Lattner7fe7f812002-07-24 19:51:14 +0000395 </ol>
John Criswell85ed3612003-06-12 19:34:44 +0000396
397 <!------------------------------------------------------------------------->
398 <h3><a name="lib"><tt>llvm/lib</tt></a></h3>
399 <!------------------------------------------------------------------------->
400
John Criswell7a73b802003-06-30 21:59:07 +0000401 This directory contains most of the source files of the LLVM system. In
402 LLVM almost all
403 code exists in libraries, making it very easy to share code among the
John Criswell85ed3612003-06-12 19:34:44 +0000404 different <a href="#tools">tools</a>.<p>
405
406 <dl compact>
407 <dt><tt>llvm/lib/VMCore/</tt><dd> This directory holds the core LLVM
408 source files that implement core classes like Instruction and BasicBlock.
409
410 <dt><tt>llvm/lib/AsmParser/</tt><dd> This directory holds the source code
411 for the LLVM assembly language parser library.
412
413 <dt><tt>llvm/lib/ByteCode/</tt><dd> This directory holds code for reading
414 and write LLVM bytecode.
415
416 <dt><tt>llvm/lib/CWriter/</tt><dd> This directory implements the LLVM to C
417 converter.
418
419 <dt><tt>llvm/lib/Analysis/</tt><dd> This directory contains a variety of
420 different program analyses, such as Dominator Information, Call Graphs,
421 Induction Variables, Interval Identification, Natural Loop Identification,
422 etc...
423
424 <dt><tt>llvm/lib/Transforms/</tt><dd> This directory contains the source
425 code for the LLVM to LLVM program transformations, such as Aggressive Dead
426 Code Elimination, Sparse Conditional Constant Propagation, Inlining, Loop
427 Invarient Code Motion, Dead Global Elimination, Pool Allocation, and many
428 others...
429
430 <dt><tt>llvm/lib/Target/</tt><dd> This directory contains files that
431 describe various target architectures for code generation. For example,
432 the llvm/lib/Target/Sparc directory holds the Sparc machine
433 description.<br>
434
435 <dt><tt>llvm/lib/CodeGen/</tt><dd> This directory contains the major parts
436 of the code generator: Instruction Selector, Instruction Scheduling, and
437 Register Allocation.
438
439 <dt><tt>llvm/lib/Reoptimizer/</tt><dd> This directory holds code related
440 to the runtime reoptimizer framework that is currently under development.
441
442 <dt><tt>llvm/lib/Support/</tt><dd> This directory contains the source code
443 that corresponds to the header files located in
444 <tt>llvm/include/Support/</tt>.
445 </dl>
446
447 <!------------------------------------------------------------------------->
448 <h3><a name="test"><tt>llvm/test</tt></a></h3>
449 <!------------------------------------------------------------------------->
450
451 <p>This directory contains regression tests and source code that is used to
452 test the LLVM infrastructure...</p>
453
454 <!------------------------------------------------------------------------->
455 <h3><a name="tools"><tt>llvm/tools</tt></a></h3>
456 <!------------------------------------------------------------------------->
457
458 <p>The <b>tools</b> directory contains the executables built out of the
459 libraries above, which form the main part of the user interface. You can
460 always get help for a tool by typing <tt>tool_name --help</tt>. The
461 following is a brief introduction to the most important tools.</p>
462
463 <dl compact>
464 <dt><tt><b>as</b></tt><dd>The assembler transforms the human readable
465 LLVM assembly to LLVM bytecode.<p>
466
467 <dt><tt><b>dis</b></tt><dd>The disassembler transforms the LLVM bytecode
468 to human readable LLVM assembly. Additionally it can convert LLVM
469 bytecode to C, which is enabled with the <tt>-c</tt> option.<p>
470
471 <dt><tt><b>lli</b></tt><dd> <tt>lli</tt> is the LLVM interpreter, which
472 can directly execute LLVM bytecode (although very slowly...). In addition
473 to a simple intepreter, <tt>lli</tt> is also has debugger and tracing
474 modes (entered by specifying <tt>-debug</tt> or <tt>-trace</tt> on the
475 command line, respectively).<p>
476
477 <dt><tt><b>llc</b></tt><dd> <tt>llc</tt> is the LLVM backend compiler,
478 which translates LLVM bytecode to a SPARC assembly file.<p>
479
480 <dt><tt><b>llvmgcc</b></tt><dd> <tt>llvmgcc</tt> is a GCC based C frontend
481 that has been retargeted to emit LLVM code as the machine code output. It
482 works just like any other GCC compiler, taking the typical <tt>-c, -S, -E,
483 -o</tt> options that are typically used. The source code for the
484 <tt>llvmgcc</tt> tool is currently not included in the LLVM cvs tree
485 because it is quite large and not very interesting.<p>
486
487 <ol>
488 <dt><tt><b>gccas</b></tt><dd> This tool is invoked by the
489 <tt>llvmgcc</tt> frontend as the "assembler" part of the compiler. This
490 tool actually assembles LLVM assembly to LLVM bytecode,
John Criswell7a73b802003-06-30 21:59:07 +0000491 performs a variety of optimizations,
John Criswell85ed3612003-06-12 19:34:44 +0000492 and outputs LLVM bytecode. Thus when you invoke <tt>llvmgcc -c x.c -o
493 x.o</tt>, you are causing <tt>gccas</tt> to be run, which writes the
494 <tt>x.o</tt> file (which is an LLVM bytecode file that can be
495 disassembled or manipulated just like any other bytecode file). The
496 command line interface to <tt>gccas</tt> is designed to be as close as
497 possible to the <b>system</b> '<tt>as</tt>' utility so that the gcc
498 frontend itself did not have to be modified to interface to a "wierd"
499 assembler.<p>
500
501 <dt><tt><b>gccld</b></tt><dd> <tt>gccld</tt> links together several LLVM
502 bytecode files into one bytecode file and does some optimization. It is
503 the linker invoked by the gcc frontend when multiple .o files need to be
504 linked together. Like <tt>gccas</tt> the command line interface of
505 <tt>gccld</tt> is designed to match the system linker, to aid
506 interfacing with the GCC frontend.<p>
507 </ol>
508
509 <dt><tt><b>opt</b></tt><dd> <tt>opt</tt> reads LLVM bytecode, applies a
510 series of LLVM to LLVM transformations (which are specified on the command
511 line), and then outputs the resultant bytecode. The '<tt>opt --help</tt>'
512 command is a good way to get a list of the program transformations
513 available in LLVM.<p>
514
515
516 <dt><tt><b>analyze</b></tt><dd> <tt>analyze</tt> is used to run a specific
517 analysis on an input LLVM bytecode file and print out the results. It is
518 primarily useful for debugging analyses, or familiarizing yourself with
519 what an analysis does.<p>
520
521 </dl>
522
523 <!--=====================================================================-->
524 <h2><a name="tutorial">An example using the LLVM tool chain</h2>
525 <!--=====================================================================-->
526
527 <ol>
528 <li>First, create a simple C file, name it 'hello.c':
529 <pre>
530 #include &lt;stdio.h&gt;
531 int main() {
532 printf("hello world\n");
533 return 0;
534 }
535 </pre>
536
537 <li>Next, compile the C file into a LLVM bytecode file:<p>
538
539 <tt>% llvmgcc hello.c -o hello</tt><p>
540
541 This will create two result files: <tt>hello</tt> and
542 <tt>hello.bc</tt>. The <tt>hello.bc</tt> is the LLVM bytecode that
543 corresponds the the compiled program and the library facilities that it
544 required. <tt>hello</tt> is a simple shell script that runs the bytecode
545 file with <tt>lli</tt>, making the result directly executable.<p>
546
547 <li>Run the program. To make sure the program ran, execute one of the
548 following commands:<p>
John Criswell8df90e02003-06-11 20:46:40 +0000549
John Criswell85ed3612003-06-12 19:34:44 +0000550 <tt>% ./hello</tt><p>
551
552 or<p>
553
554 <tt>% lli hello.bc</tt><p>
555
556 <li>Use the <tt>dis</tt> utility to take a look at the LLVM assembly
557 code:<p>
558
559 <tt>% dis < hello.bc | less</tt><p>
560
561 <li>Compile the program to native Sparc assembly using the code
562 generator:<p>
563
564 <tt>% llc hello.bc -o hello.s</tt><p>
565
566 <li>Assemble the native sparc assemble file into a program:<p>
567
568 <tt>% /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.sparc</tt><p>
569
570 <li>Execute the native sparc program:<p>
571
572 <tt>% ./hello.sparc</tt><p>
573
574 </ol>
575
576
577 <!--=====================================================================-->
578 <h2><a name="links">Links</a></h2>
579 <!--=====================================================================-->
580
581 <p>This document is just an <b>introduction</b> to how to use LLVM to do
582 some simple things... there are many more interesting and complicated things
583 that you can do that aren't documented here (but we'll gladly accept a patch
584 if you want to write something up!). For more information about LLVM, check
585 out:</p>
586
587 <ul>
588 <li><a href="http://llvm.cs.uiuc.edu/">LLVM homepage</a></li>
589 <li><a href="http://llvm.cs.uiuc.edu/doxygen/">LLVM doxygen tree</a></li>
590 </ul>
591
592 <hr>
593
594 If you have any questions or run into any snags (or you have any
595 additions...), please send an email to
596 <a href="mailto:sabre@nondot.org">Chris Lattner</a>.</p>
597
598 <!-- Created: Mon Jul 1 02:29:02 CDT 2002 -->
599 <!-- hhmts start -->
600Last modified: Tue Jun 3 22:06:43 CDT 2003
601<!-- hhmts end -->
602 </body>
Guochun Shif4688a82002-07-17 23:05:56 +0000603</html>