blob: a6ea989e92ae3d36c32ec0fcebc24d17a0b44a27 [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).
John Criswell7a73b802003-06-30 21:59:07 +0000250 <p><li><i>--enable-jit</i> =
251 Compile the Just In Time (JIT) functionality. This is not available
252 on all platforms.
253 </ul>
254
255 In addition to running <tt>configure</tt>, you must set the
John Criswell85ed3612003-06-12 19:34:44 +0000256 <tt>LLVM_LIB_SEARCH_PATH</tt> environment variable in your startup scripts.
257 This environment variable is used to locate "system" libraries like
258 "<tt>-lc</tt>" and "<tt>-lm</tt>" when linking. This variable should be set
259 to the absolute path for the bytecode-libs subdirectory of the C front-end
John Criswell7a73b802003-06-30 21:59:07 +0000260 install. For example, one might set <tt>LLVM_LIB_SEARCH_PATH</tt> to
John Criswell85ed3612003-06-12 19:34:44 +0000261 <tt>/home/vadve/lattner/local/x86/llvm-gcc/bytecode-libs</tt> for the X86
262 version of the C front-end on our research machines.<p>
263
264 <!------------------------------------------------------------------------->
265 <h3><a name="objfiles">The location for LLVM object files</a></h3>
266 <!------------------------------------------------------------------------->
267
268 <p>The LLVM make system sends most output files generated during the build
269 into the directory defined by the variable OBJ_ROOT in
270 <tt>llvm/Makefile.config</tt>. This can be either just your normal LLVM
271 source tree or some other directory writable by you. You may wish to put
272 object files on a different filesystem either to keep them from being backed
273 up or to speed up local builds.
274
John Criswell7a73b802003-06-30 21:59:07 +0000275 <p>If you wish to place output files into a separate directory, use the
276 <tt>--with-objroot=<i>directory</i></tt> option of <tt>configure</tt> to
277 set the top level directory of where the object files will go. Otherwise,
278 leave this option unspecified, and <tt>configure</tt> will place files
279 within the LLVM source tree.
John Criswell85ed3612003-06-12 19:34:44 +0000280
281 <!------------------------------------------------------------------------->
282 <h3><a name="environment">Setting up your environment</a></h3>
283 <!------------------------------------------------------------------------->
284
285 <i>NOTE: This step is optional but will set up your environment so you
286 can use the compiled LLVM tools with as little hassle as
287 possible.</i>)
288
289 <p>Add the following lines to your <tt>.cshrc</tt> (or the corresponding
290 lines to your <tt>.profile</tt> if you use a bourne shell derivative).
291
292 <pre>
293 # Make the C front end easy to use...
294 alias llvmgcc <i>LLVMGCCDIR</i><tt>/bin/llvm-gcc</tt>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000295
296 # Make the LLVM tools easy to use...
John Criswell85ed3612003-06-12 19:34:44 +0000297 setenv PATH <i>OBJ_ROOT</i>/llvm/tools/Debug:${PATH}
298 </pre>
299 The <tt>llvmgcc</tt> alias is useful because the C compiler is not
300 included in the CVS tree you just checked out.
John Criswell7a73b802003-06-30 21:59:07 +0000301
John Criswell85ed3612003-06-12 19:34:44 +0000302 <p>The other <a href="#tools">LLVM tools</a> are part of the LLVM
303 source base and built when compiling LLVM. They will be built into the
304 <tt><i>OBJ_ROOT</i>/tools/Debug</tt> directory.</p>
305
306 <!------------------------------------------------------------------------->
307 <h3><a name="compile">Compiling the source code</a></h3>
308 <!------------------------------------------------------------------------->
309
310 <p>Every directory in the LLVM source tree includes a <tt>Makefile</tt> to
311 build it and any subdirectories that it contains. These makefiles require
John Criswell7a73b802003-06-30 21:59:07 +0000312 that you use GNU Make (sometimes called <tt>gmake</tt>) instead of
313 <tt>make</tt> to
John Criswell85ed3612003-06-12 19:34:44 +0000314 build them, but can
315 otherwise be used freely. To build the entire LLVM system, just enter the
316 top level <tt>llvm</tt> directory and type <tt>gmake</tt>. A few minutes
317 later you will hopefully have a freshly compiled toolchain waiting for you
318 in <tt><i>OBJ_ROOT</i>/llvm/tools/Debug</tt>. If you want to look at the
John Criswell7a73b802003-06-30 21:59:07 +0000319 libraries that
320 were compiled, look in <tt><i>OBJ_ROOT</i>/llvm/lib/Debug</tt>.</p>
John Criswell85ed3612003-06-12 19:34:44 +0000321
322 If you get an error about a <tt>/localhome</tt> directory, follow the
323 instructions in the section about <a href="#environment">Setting Up Your
324 Environment.</a>
325
326
327
328 <!--=====================================================================-->
329 <center>
330 <h2><a name="layout"><b>Program Layout</b></a></h2>
331 </center>
332 <!--=====================================================================-->
333
334 <p>One useful source of infomation about the LLVM sourcebase is the LLVM <a
335 href="http://www.doxygen.org">doxygen</a> documentation, available at <tt><a
336 href="http://llvm.cs.uiuc.edu/doxygen/">http://llvm.cs.uiuc.edu/doxygen/</a></tt>. The
337 following is a brief introduction to code layout:</p>
338
339
340 <!------------------------------------------------------------------------->
341 <h3><a name="cvsdir"><tt>CVS</tt> directories</a></h3>
342 <!------------------------------------------------------------------------->
343
344 Every directory checked out of CVS will contain a <tt>CVS</tt> directory;
345 for the most part these can just be ignored.
346
347
348 <!------------------------------------------------------------------------->
349 <h3><a name="ddr"><tt>Depend</tt>, <tt>Debug</tt>, &amp; <tt>Release</tt>
Chris Lattner44ac6592002-08-09 16:14:56 +0000350 directories</a></h3>
John Criswell85ed3612003-06-12 19:34:44 +0000351 <!------------------------------------------------------------------------->
352
353 If you are building with the "<tt>OBJ_ROOT=.</tt>" option enabled in the
John Criswell7a73b802003-06-30 21:59:07 +0000354 <tt>Makefile.config</tt> file (i.e. you did not specify
355 <tt>--with-objroot</tt> when you ran <tt>configure</tt>), most source
356 directories will contain two
John Criswell85ed3612003-06-12 19:34:44 +0000357 directories, <tt>Depend</tt> and <tt>Debug</tt>. The <tt>Depend</tt>
358 directory contains automatically generated dependance files which are used
359 during compilation to make sure that source files get rebuilt if a header
360 file they use is modified. The <tt>Debug</tt> directory holds the object
361 files, library files, and executables that are used for building a debug
362 enabled build. The <tt>Release</tt> directory is created to hold the same
363 files when the <tt>ENABLE_OPTIMIZED=1</tt> flag is passed to <tt>gmake</tt>,
John Criswell7a73b802003-06-30 21:59:07 +0000364 causing an optimized build to be performed.<p>
John Criswell85ed3612003-06-12 19:34:44 +0000365
366
367 <!------------------------------------------------------------------------->
368 <h3><a name="include"><tt>llvm/include</tt></a></h3>
369 <!------------------------------------------------------------------------->
370
371 This directory contains public header files exported from the LLVM
John Criswell7a73b802003-06-30 21:59:07 +0000372 library. The three main subdirectories of this directory are:<p>
John Criswell85ed3612003-06-12 19:34:44 +0000373
John Criswell8df90e02003-06-11 20:46:40 +0000374 <ol>
John Criswell85ed3612003-06-12 19:34:44 +0000375 <li><tt>llvm/include/llvm</tt> - This directory contains all of the LLVM
376 specific header files. This directory also has subdirectories for
377 different portions of LLVM: <tt>Analysis</tt>, <tt>CodeGen</tt>,
378 <tt>Reoptimizer</tt>, <tt>Target</tt>, <tt>Transforms</tt>, etc...
379
380 <li><tt>llvm/include/Support</tt> - This directory contains generic
381 support libraries that are independant of LLVM, but are used by LLVM.
John Criswell7a73b802003-06-30 21:59:07 +0000382 For example, some C++ STL utilities and a Command Line option processing
383 library.
384
385 <li><tt>llvm/include/Config</tt> - This directory contains header files
386 configured by the <tt>configure</tt> script. They wrap "standard" UNIX
387 and C header files. Source code can include these header files which
388 automatically take care of the conditional #includes that the configure
389 script generates.
Chris Lattner7fe7f812002-07-24 19:51:14 +0000390 </ol>
John Criswell85ed3612003-06-12 19:34:44 +0000391
392 <!------------------------------------------------------------------------->
393 <h3><a name="lib"><tt>llvm/lib</tt></a></h3>
394 <!------------------------------------------------------------------------->
395
John Criswell7a73b802003-06-30 21:59:07 +0000396 This directory contains most of the source files of the LLVM system. In
397 LLVM almost all
398 code exists in libraries, making it very easy to share code among the
John Criswell85ed3612003-06-12 19:34:44 +0000399 different <a href="#tools">tools</a>.<p>
400
401 <dl compact>
402 <dt><tt>llvm/lib/VMCore/</tt><dd> This directory holds the core LLVM
403 source files that implement core classes like Instruction and BasicBlock.
404
405 <dt><tt>llvm/lib/AsmParser/</tt><dd> This directory holds the source code
406 for the LLVM assembly language parser library.
407
408 <dt><tt>llvm/lib/ByteCode/</tt><dd> This directory holds code for reading
409 and write LLVM bytecode.
410
411 <dt><tt>llvm/lib/CWriter/</tt><dd> This directory implements the LLVM to C
412 converter.
413
414 <dt><tt>llvm/lib/Analysis/</tt><dd> This directory contains a variety of
415 different program analyses, such as Dominator Information, Call Graphs,
416 Induction Variables, Interval Identification, Natural Loop Identification,
417 etc...
418
419 <dt><tt>llvm/lib/Transforms/</tt><dd> This directory contains the source
420 code for the LLVM to LLVM program transformations, such as Aggressive Dead
421 Code Elimination, Sparse Conditional Constant Propagation, Inlining, Loop
422 Invarient Code Motion, Dead Global Elimination, Pool Allocation, and many
423 others...
424
425 <dt><tt>llvm/lib/Target/</tt><dd> This directory contains files that
426 describe various target architectures for code generation. For example,
427 the llvm/lib/Target/Sparc directory holds the Sparc machine
428 description.<br>
429
430 <dt><tt>llvm/lib/CodeGen/</tt><dd> This directory contains the major parts
431 of the code generator: Instruction Selector, Instruction Scheduling, and
432 Register Allocation.
433
434 <dt><tt>llvm/lib/Reoptimizer/</tt><dd> This directory holds code related
435 to the runtime reoptimizer framework that is currently under development.
436
437 <dt><tt>llvm/lib/Support/</tt><dd> This directory contains the source code
438 that corresponds to the header files located in
439 <tt>llvm/include/Support/</tt>.
440 </dl>
441
442 <!------------------------------------------------------------------------->
443 <h3><a name="test"><tt>llvm/test</tt></a></h3>
444 <!------------------------------------------------------------------------->
445
446 <p>This directory contains regression tests and source code that is used to
447 test the LLVM infrastructure...</p>
448
449 <!------------------------------------------------------------------------->
450 <h3><a name="tools"><tt>llvm/tools</tt></a></h3>
451 <!------------------------------------------------------------------------->
452
453 <p>The <b>tools</b> directory contains the executables built out of the
454 libraries above, which form the main part of the user interface. You can
455 always get help for a tool by typing <tt>tool_name --help</tt>. The
456 following is a brief introduction to the most important tools.</p>
457
458 <dl compact>
459 <dt><tt><b>as</b></tt><dd>The assembler transforms the human readable
460 LLVM assembly to LLVM bytecode.<p>
461
462 <dt><tt><b>dis</b></tt><dd>The disassembler transforms the LLVM bytecode
463 to human readable LLVM assembly. Additionally it can convert LLVM
464 bytecode to C, which is enabled with the <tt>-c</tt> option.<p>
465
466 <dt><tt><b>lli</b></tt><dd> <tt>lli</tt> is the LLVM interpreter, which
467 can directly execute LLVM bytecode (although very slowly...). In addition
468 to a simple intepreter, <tt>lli</tt> is also has debugger and tracing
469 modes (entered by specifying <tt>-debug</tt> or <tt>-trace</tt> on the
470 command line, respectively).<p>
471
472 <dt><tt><b>llc</b></tt><dd> <tt>llc</tt> is the LLVM backend compiler,
473 which translates LLVM bytecode to a SPARC assembly file.<p>
474
475 <dt><tt><b>llvmgcc</b></tt><dd> <tt>llvmgcc</tt> is a GCC based C frontend
476 that has been retargeted to emit LLVM code as the machine code output. It
477 works just like any other GCC compiler, taking the typical <tt>-c, -S, -E,
478 -o</tt> options that are typically used. The source code for the
479 <tt>llvmgcc</tt> tool is currently not included in the LLVM cvs tree
480 because it is quite large and not very interesting.<p>
481
482 <ol>
483 <dt><tt><b>gccas</b></tt><dd> This tool is invoked by the
484 <tt>llvmgcc</tt> frontend as the "assembler" part of the compiler. This
485 tool actually assembles LLVM assembly to LLVM bytecode,
John Criswell7a73b802003-06-30 21:59:07 +0000486 performs a variety of optimizations,
John Criswell85ed3612003-06-12 19:34:44 +0000487 and outputs LLVM bytecode. Thus when you invoke <tt>llvmgcc -c x.c -o
488 x.o</tt>, you are causing <tt>gccas</tt> to be run, which writes the
489 <tt>x.o</tt> file (which is an LLVM bytecode file that can be
490 disassembled or manipulated just like any other bytecode file). The
491 command line interface to <tt>gccas</tt> is designed to be as close as
492 possible to the <b>system</b> '<tt>as</tt>' utility so that the gcc
493 frontend itself did not have to be modified to interface to a "wierd"
494 assembler.<p>
495
496 <dt><tt><b>gccld</b></tt><dd> <tt>gccld</tt> links together several LLVM
497 bytecode files into one bytecode file and does some optimization. It is
498 the linker invoked by the gcc frontend when multiple .o files need to be
499 linked together. Like <tt>gccas</tt> the command line interface of
500 <tt>gccld</tt> is designed to match the system linker, to aid
501 interfacing with the GCC frontend.<p>
502 </ol>
503
504 <dt><tt><b>opt</b></tt><dd> <tt>opt</tt> reads LLVM bytecode, applies a
505 series of LLVM to LLVM transformations (which are specified on the command
506 line), and then outputs the resultant bytecode. The '<tt>opt --help</tt>'
507 command is a good way to get a list of the program transformations
508 available in LLVM.<p>
509
510
511 <dt><tt><b>analyze</b></tt><dd> <tt>analyze</tt> is used to run a specific
512 analysis on an input LLVM bytecode file and print out the results. It is
513 primarily useful for debugging analyses, or familiarizing yourself with
514 what an analysis does.<p>
515
516 </dl>
517
518 <!--=====================================================================-->
519 <h2><a name="tutorial">An example using the LLVM tool chain</h2>
520 <!--=====================================================================-->
521
522 <ol>
523 <li>First, create a simple C file, name it 'hello.c':
524 <pre>
525 #include &lt;stdio.h&gt;
526 int main() {
527 printf("hello world\n");
528 return 0;
529 }
530 </pre>
531
532 <li>Next, compile the C file into a LLVM bytecode file:<p>
533
534 <tt>% llvmgcc hello.c -o hello</tt><p>
535
536 This will create two result files: <tt>hello</tt> and
537 <tt>hello.bc</tt>. The <tt>hello.bc</tt> is the LLVM bytecode that
538 corresponds the the compiled program and the library facilities that it
539 required. <tt>hello</tt> is a simple shell script that runs the bytecode
540 file with <tt>lli</tt>, making the result directly executable.<p>
541
542 <li>Run the program. To make sure the program ran, execute one of the
543 following commands:<p>
John Criswell8df90e02003-06-11 20:46:40 +0000544
John Criswell85ed3612003-06-12 19:34:44 +0000545 <tt>% ./hello</tt><p>
546
547 or<p>
548
549 <tt>% lli hello.bc</tt><p>
550
551 <li>Use the <tt>dis</tt> utility to take a look at the LLVM assembly
552 code:<p>
553
554 <tt>% dis < hello.bc | less</tt><p>
555
556 <li>Compile the program to native Sparc assembly using the code
557 generator:<p>
558
559 <tt>% llc hello.bc -o hello.s</tt><p>
560
561 <li>Assemble the native sparc assemble file into a program:<p>
562
563 <tt>% /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.sparc</tt><p>
564
565 <li>Execute the native sparc program:<p>
566
567 <tt>% ./hello.sparc</tt><p>
568
569 </ol>
570
571
572 <!--=====================================================================-->
573 <h2><a name="links">Links</a></h2>
574 <!--=====================================================================-->
575
576 <p>This document is just an <b>introduction</b> to how to use LLVM to do
577 some simple things... there are many more interesting and complicated things
578 that you can do that aren't documented here (but we'll gladly accept a patch
579 if you want to write something up!). For more information about LLVM, check
580 out:</p>
581
582 <ul>
583 <li><a href="http://llvm.cs.uiuc.edu/">LLVM homepage</a></li>
584 <li><a href="http://llvm.cs.uiuc.edu/doxygen/">LLVM doxygen tree</a></li>
585 </ul>
586
587 <hr>
588
589 If you have any questions or run into any snags (or you have any
590 additions...), please send an email to
591 <a href="mailto:sabre@nondot.org">Chris Lattner</a>.</p>
592
593 <!-- Created: Mon Jul 1 02:29:02 CDT 2002 -->
594 <!-- hhmts start -->
595Last modified: Tue Jun 3 22:06:43 CDT 2003
596<!-- hhmts end -->
597 </body>
Guochun Shif4688a82002-07-17 23:05:56 +0000598</html>