blob: 8dadc17f2097518cee20ab41782323d7a042956f [file] [log] [blame]
Guochun Shif4688a82002-07-17 23:05:56 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3 <head>
Chris Lattner7fe7f812002-07-24 19:51:14 +00004 <title>Getting Started with LLVM System</title>
Guochun Shif4688a82002-07-17 23:05:56 +00005 </head>
6
Chris Lattner945de2d2002-07-24 19:59:33 +00007 <body bgcolor=white>
Chris Lattner1db872d2002-09-06 16:26:13 +00008 <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 <!--=====================================================================-->
Chris Lattner945de2d2002-07-24 19:59:33 +000017
Guochun Shif4688a82002-07-17 23:05:56 +000018 <ul>
Chris Lattner1db872d2002-09-06 16:26:13 +000019 <li><a href="#overview">Overview</a>
20 <li><a href="#starting">Getting started with LLVM</a>
Chris Lattner7fe7f812002-07-24 19:51:14 +000021 <ol>
Chris Lattner1db872d2002-09-06 16:26:13 +000022 <li><a href="#quickstart">Getting started quickly (a summary)</a>
23 <li><a href="#checkout">Checkout LLVM from CVS</a>
24 <li><a href="#terminology">Terminology and Notation</tt></a>
25 <li><a href="#objfiles">The location for object files</tt></a>
26 <li><a href="#config">Local Configuration Options</tt></a>
27 <li><a href="#environment">Setting up your environment</a>
28 <li><a href="#compile">Compiling the source code</a>
Chris Lattner7fe7f812002-07-24 19:51:14 +000029 </ol>
Guochun Shif4688a82002-07-17 23:05:56 +000030 <li><a href="#layout">Program layout</a>
31 <ol>
Chris Lattner7fe7f812002-07-24 19:51:14 +000032 <li><a href="#cvsdir">CVS directories</a>
Chris Lattner44ac6592002-08-09 16:14:56 +000033 <li><a href="#dd"><tt>Depend</tt>, <tt>Debug</tt>, &amp;
34 <tt>Release</tt> directories</a></li>
35 <li><a href="#include"><tt>llvm/include</tt></a>
36 <li><a href="#lib"><tt>llvm/lib</tt></a>
37 <li><a href="#test"><tt>llvm/test</tt></a>
38 <li><a href="#tools"><tt>llvm/tools</tt></a>
Guochun Shif4688a82002-07-17 23:05:56 +000039 </ol>
Chris Lattner7fe7f812002-07-24 19:51:14 +000040 <li><a href="#tutorial">An example using the LLVM tool chain</a>
Guochun Shif4688a82002-07-17 23:05:56 +000041 <li><a href="#links">Links</a>
42 </ul>
Guochun Shif4688a82002-07-17 23:05:56 +000043
Chris Lattner7fe7f812002-07-24 19:51:14 +000044
Chris Lattner7fe7f812002-07-24 19:51:14 +000045 <!--=====================================================================-->
Chris Lattner1db872d2002-09-06 16:26:13 +000046 <center>
47 <h2><a name="overview"><b>Overview</b></a></h2>
48 </center>
Chris Lattner7fe7f812002-07-24 19:51:14 +000049 <!--=====================================================================-->
50
Chris Lattner1db872d2002-09-06 16:26:13 +000051 <p>The <a href"starting">next section</a> of this guide is meant to get
52 you up and running with LLVM, and to give you some basic information about
53 the LLVM environment. The <a href"#quickstart">first subsection</a> gives
54 a short summary for those who are already familiar with the system and
55 want to get started as quickly as possible.
56
57 <p>The later sections of this guide describe the <a
Chris Lattner4b2e2912002-09-19 19:56:53 +000058 href"#layout">general layout</a> of the the LLVM source-tree, a <a
Chris Lattner1db872d2002-09-06 16:26:13 +000059 href="#tutorial">simple example</a> using the LLVM tool chain, and <a
60 href="#links">links</a> to find more information about LLVM or to get
61 help via e-mail.
62
63 <!--=====================================================================-->
64 <center>
65 <h2><a name="starting"><b>Getting Started</b></a></h2>
66 </center>
67 <!--=====================================================================-->
68
69
70 <!--=====================================================================-->
71 <h3><a name="quickstart"><b>Getting Started Quickly (A Summary)</b></a></h3>
72 <!--=====================================================================-->
73
74 Here's the short story for getting up and running quickly with LLVM:
Chris Lattner96768ea2003-02-14 04:22:13 +000075 <ol>
Chris Lattner1db872d2002-09-06 16:26:13 +000076 <li>Find the path to the CVS repository containing LLVM (we'll call this <i>CVSROOTDIR</i>).
77 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
78 <li><tt>cvs -d <i>CVSROOTDIR</i> checkout llvm</tt>
Chris Lattner1db872d2002-09-06 16:26:13 +000079 <li><tt>cd llvm</tt>
Chris Lattner96768ea2003-02-14 04:22:13 +000080 <li>Edit <tt>Makefile.config</tt> to set local paths. This includes
81 setting the install location of the C frontend, and the various paths
82 to the C and C++ compilers used to build LLVM itself.
Chris Lattner1e8166a2003-05-11 21:50:06 +000083 <li>Set your LLVM_LIB_SEARCH_PATH environment variable.
Chris Lattner1db872d2002-09-06 16:26:13 +000084 <li><tt>gmake -k |& tee gnumake.out
85 &nbsp;&nbsp;&nbsp;# this is csh or tcsh syntax</tt>
Chris Lattner96768ea2003-02-14 04:22:13 +000086 </ol>
Chris Lattner1db872d2002-09-06 16:26:13 +000087
88 <p>See <a href="#environment">Setting up your environment</a> on tips to
Chris Lattner4b2e2912002-09-19 19:56:53 +000089 simplify working with the LLVM front-end and compiled tools. See the
Chris Lattner1db872d2002-09-06 16:26:13 +000090 other sub-sections below for other useful details in working with LLVM,
91 or go straight to <a href="#layout">Program Layout</a> to learn about the
92 layout of the source code tree.
Chris Lattner7fe7f812002-07-24 19:51:14 +000093
94 <!------------------------------------------------------------------------->
Chris Lattner1db872d2002-09-06 16:26:13 +000095 <h3><a name="terminology">Terminology and Notation</a></h3>
Chris Lattner7fe7f812002-07-24 19:51:14 +000096 <!------------------------------------------------------------------------->
97
Chris Lattner1db872d2002-09-06 16:26:13 +000098 <p>Through this manual, the following names are used to denote paths
99 specific to the local system and working environment. <i>These are not
100 environment variables you need to set, but just strings used in the rest
101 of this document below.</i>. In any of the examples below, simply replace
102 each of these names with the appropriate pathname on your local system.
103 All these paths are absolute:</p>
104 <ul>
105 </ul>
Chris Lattnercefbd322002-08-13 21:10:30 +0000106
107 <!------------------------------------------------------------------------->
Chris Lattner1db872d2002-09-06 16:26:13 +0000108 <h3><a name="checkout">Checkout LLVM from CVS</a></h3>
Chris Lattnercefbd322002-08-13 21:10:30 +0000109 <!------------------------------------------------------------------------->
110
Chris Lattner1db872d2002-09-06 16:26:13 +0000111 <p>Before checking out the source code, you will need to know the path to
112 CVS repository containing LLVM source code (we'll call this
113 <i>CVSROOTDIR</i> below). Ask the person responsible for your local LLVM
114 installation to give you this path.
Chris Lattnercefbd322002-08-13 21:10:30 +0000115
Chris Lattner1db872d2002-09-06 16:26:13 +0000116 <p>To get a fresh copy of the entire source code, all you
117 need to do is check it out from CVS as follows:
118 <ul>
119 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
120 <li><tt>cvs -d <i>CVSROOTDIR</i> checkout llvm</tt></p>
121 </ul>
122
123 <p>This will create an '<tt>llvm</tt>' directory in the current
124 directory and fully populate it with the LLVM source code, Makefiles,
125 test directories, and local copies of documentation files.</p>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000126
127 <!------------------------------------------------------------------------->
Chris Lattner1db872d2002-09-06 16:26:13 +0000128 <h3><a name="config">Local Configuration Options</a></h3>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000129 <!------------------------------------------------------------------------->
Chris Lattner1db872d2002-09-06 16:26:13 +0000130
131 <p>The file <tt>llvm/Makefile.config</tt>
132 defines the following path variables,
133 which are specific to a particular installation of LLVM.
134 These should need to be modified only once after checking out a copy
135 of LLVM (if the default values do not already match your system):
136
137 <ul>
Chris Lattner4b2e2912002-09-19 19:56:53 +0000138 <p><li><i>CXX</i> = Path to C++ compiler to use.
Chris Lattner1db872d2002-09-06 16:26:13 +0000139 <p><li><i>LLVM_OBJ_DIR</i> = Path to the llvm directory where
140 object files should be placed.
141 (See the Section on <a href=#objfiles>
142 The location for LLVM object files</a>
143 for more information.)
144 <p><li><i>LLVMGCCDIR</i> = Path to the location of the LLVM front-end
145 binaries and associated libraries.
Chris Lattner1db872d2002-09-06 16:26:13 +0000146 <p><li><i>PURIFY</i> = Path to the purify program.
147 </ul>
148
Chris Lattner1e8166a2003-05-11 21:50:06 +0000149 In addition to settings in this file, you must set a
150 <tt>LLVM_LIB_SEARCH_PATH</tt> environment variable in your startup scripts.
151 This environment variable is used to locate "system" libraries like
152 "<tt>-lc</tt>" and "<tt>-lm</tt>" when linking. This variable should be set
153 to the absolute path for the bytecode-libs subdirectory of the C front-end
154 install. For example,
155 <tt>/home/vadve/lattner/local/x86/llvm-gcc/bytecode-libs</tt> for the X86
156 version of the C front-end, on our research machines.<p>
157
Chris Lattner1db872d2002-09-06 16:26:13 +0000158 <!------------------------------------------------------------------------->
159 <h3><a name="objfiles">The location for LLVM object files</a></h3>
160 <!------------------------------------------------------------------------->
161
162 <p>The LLVM make system sends most output files generated during the build
163 into the directory defined by the variable LLVM_OBJ_DIR in
Chris Lattner4b2e2912002-09-19 19:56:53 +0000164 <tt>llvm/Makefile.config</tt>. This can be either just your normal LLVM
165 source tree or some other directory writable by you. You may wish to put
166 object files on a different filesystem either to keep them from being backed
167 up or to speed up local builds.
Chris Lattner1db872d2002-09-06 16:26:13 +0000168
Chris Lattner4b2e2912002-09-19 19:56:53 +0000169 <p>If you do not wish to use a different location for object files (building
170 into the source tree directly), just set this variable to ".".<p>
Chris Lattner1db872d2002-09-06 16:26:13 +0000171
172 <!------------------------------------------------------------------------->
173 <h3><a name="environment">Setting up your environment</a></h3>
174 <!------------------------------------------------------------------------->
175
176 <i>NOTE: This step is optional but will set up your environment so you
Chris Lattner4b2e2912002-09-19 19:56:53 +0000177 can use the compiled LLVM tools with as little hassle as
178 possible.</i>)
Chris Lattner1db872d2002-09-06 16:26:13 +0000179
180 <p>Add the following lines to your <tt>.cshrc</tt> (or the corresponding
181 lines to your <tt>.profile</tt> if you use a bourne shell derivative).
Chris Lattner7fe7f812002-07-24 19:51:14 +0000182
183 <pre>
Chris Lattner1db872d2002-09-06 16:26:13 +0000184 # Make the C front end easy to use...
Chris Lattner4b2e2912002-09-19 19:56:53 +0000185 alias llvmgcc <i>LLVMGCCDIR</i><tt>/bin/llvm-gcc</tt>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000186
187 # Make the LLVM tools easy to use...
Chris Lattner74e91b22003-06-08 15:33:25 +0000188 setenv PATH <i>LLVM_OBJ_DIR</i>/llvm/tools/Debug:${PATH}
Chris Lattner7fe7f812002-07-24 19:51:14 +0000189 </pre>
Chris Lattner1db872d2002-09-06 16:26:13 +0000190 The <tt>llvmgcc</tt> alias is useful because the C compiler is not
191 included in the CVS tree you just checked out.
192
Chris Lattner4b2e2912002-09-19 19:56:53 +0000193 <p>The other <a href="#tools">LLVM tools</a> are part of the LLVM
Chris Lattner1db872d2002-09-06 16:26:13 +0000194 source base, and built when compiling LLVM. They will be built into the
195 <tt><i>LLVM_OBJ_DIR</i>/tools/Debug</tt> directory.</p>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000196
197 <!------------------------------------------------------------------------->
Chris Lattner1db872d2002-09-06 16:26:13 +0000198 <h3><a name="compile">Compiling the source code</a></h3>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000199 <!------------------------------------------------------------------------->
200
Chris Lattner4b2e2912002-09-19 19:56:53 +0000201 <p>Every directory in the LLVM source tree includes a <tt>Makefile</tt> to
202 build it, and any subdirectories that it contains. These makefiles require
203 that you use <tt>gmake</tt>, instead of <tt>make</tt> to build them, but can
Chris Lattner7fe7f812002-07-24 19:51:14 +0000204 otherwise be used freely. To build the entire LLVM system, just enter the
205 top level <tt>llvm</tt> directory and type <tt>gmake</tt>. A few minutes
206 later you will hopefully have a freshly compiled toolchain waiting for you
207 in <tt>llvm/tools/Debug</tt>. If you want to look at the libraries that
208 were compiled, look in <tt>llvm/lib/Debug</tt>.</p>
209
Chris Lattner4b2e2912002-09-19 19:56:53 +0000210 If you get an error talking about a <tt>/localhome</tt> directory, follow
211 the instructions in the section about <a href="#environment">Setting Up Your
Chris Lattner1db872d2002-09-06 16:26:13 +0000212 Environment.</a>
Chris Lattnercefbd322002-08-13 21:10:30 +0000213
Chris Lattner44ac6592002-08-09 16:14:56 +0000214
Chris Lattner7fe7f812002-07-24 19:51:14 +0000215
216 <!--=====================================================================-->
Chris Lattner1db872d2002-09-06 16:26:13 +0000217 <center>
218 <h2><a name="layout"><b>Program Layout</b></a></h2>
219 </center>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000220 <!--=====================================================================-->
221
Chris Lattner44ac6592002-08-09 16:14:56 +0000222 <p>One useful source of infomation about the LLVM sourcebase is the LLVM <a
223 href="http://www.doxygen.org">doxygen</a> documentation, available at <tt><a
Chris Lattner7fe7f812002-07-24 19:51:14 +0000224 href="http://llvm.cs.uiuc.edu/doxygen/">http://llvm.cs.uiuc.edu/doxygen/</a></tt>. The
225 following is a brief introduction to code layout:</p>
226
227
228 <!------------------------------------------------------------------------->
Chris Lattner44ac6592002-08-09 16:14:56 +0000229 <h3><a name="cvsdir"><tt>CVS</tt> directories</a></h3>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000230 <!------------------------------------------------------------------------->
231
Chris Lattner44ac6592002-08-09 16:14:56 +0000232 Every directory checked out of CVS will contain a <tt>CVS</tt> directory,
233 for the most part these can just be ignored.
Chris Lattner7fe7f812002-07-24 19:51:14 +0000234
235
236 <!------------------------------------------------------------------------->
Chris Lattner44ac6592002-08-09 16:14:56 +0000237 <h3><a name="ddr"><tt>Depend</tt>, <tt>Debug</tt>, &amp; <tt>Release</tt>
238 directories</a></h3>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000239 <!------------------------------------------------------------------------->
240
Chris Lattner44ac6592002-08-09 16:14:56 +0000241 If you are building with the "<tt>BUILD_ROOT=.</tt>" option enabled in the
242 <tt>Makefile.common</tt> file, most source directories will contain two
243 directories, <tt>Depend</tt> and <tt>Debug</tt>. The <tt>Depend</tt>
244 directory contains automatically generated dependance files which are used
245 during compilation to make sure that source files get rebuilt if a header
246 file they use is modified. The <tt>Debug</tt> directory holds the object
Chris Lattner7fe7f812002-07-24 19:51:14 +0000247 files, library files and executables that are used for building a debug
Chris Lattner44ac6592002-08-09 16:14:56 +0000248 enabled build. The <tt>Release</tt> directory is created to hold the same
249 files when the <tt>ENABLE_OPTIMIZED=1</tt> flag is passed to <tt>gmake</tt>,
250 causing an optimized built to be performed.<p>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000251
252
253 <!------------------------------------------------------------------------->
Chris Lattner44ac6592002-08-09 16:14:56 +0000254 <h3><a name="include"><tt>llvm/include</tt></a></h3>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000255 <!------------------------------------------------------------------------->
256
257 This directory contains public header files exported from the LLVM
Chris Lattner44ac6592002-08-09 16:14:56 +0000258 library. The two main subdirectories of this directory are:<p>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000259
260 <ol>
261 <li><tt>llvm/include/llvm</tt> - This directory contains all of the LLVM
262 specific header files. This directory also has subdirectories for
Chris Lattner4b2e2912002-09-19 19:56:53 +0000263 different portions of LLVM: <tt>Analysis</tt>, <tt>CodeGen</tt>,
Chris Lattner7fe7f812002-07-24 19:51:14 +0000264 <tt>Reoptimizer</tt>, <tt>Target</tt>, <tt>Transforms</tt>, etc...
265
266 <li><tt>llvm/include/Support</tt> - This directory contains generic
267 support libraries that are independant of LLVM, but are used by LLVM.
268 For example, some C++ STL utilities and a Command Line option processing
269 library.
270 </ol>
271
272 <!------------------------------------------------------------------------->
Chris Lattner44ac6592002-08-09 16:14:56 +0000273 <h3><a name="lib"><tt>llvm/lib</tt></a></h3>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000274 <!------------------------------------------------------------------------->
275
276 This directory contains most source files of LLVM system. In LLVM almost all
277 code exists in libraries, making it very easy to share code among the
278 different <a href="#tools">tools</a>.<p>
279
280 <dl compact>
281 <dt><tt>llvm/lib/VMCore/</tt><dd> This directory holds the core LLVM
282 source files that implement core classes like Instruction and BasicBlock.
283
284 <dt><tt>llvm/lib/AsmParser/</tt><dd> This directory holds the source code
285 for the LLVM assembly language parser library.
286
287 <dt><tt>llvm/lib/ByteCode/</tt><dd> This directory holds code for reading
288 and write LLVM bytecode.
289
Chris Lattner4b2e2912002-09-19 19:56:53 +0000290 <dt><tt>llvm/lib/CWriter/</tt><dd> This directory implements the LLVM to C
Chris Lattner7fe7f812002-07-24 19:51:14 +0000291 converter.
292
293 <dt><tt>llvm/lib/Analysis/</tt><dd> This directory contains a variety of
294 different program analyses, such as Dominator Information, Call Graphs,
295 Induction Variables, Interval Identification, Natural Loop Identification,
296 etc...
297
298 <dt><tt>llvm/lib/Transforms/</tt><dd> This directory contains the source
299 code for the LLVM to LLVM program transformations, such as Aggressive Dead
Misha Brukman82c89b92003-05-20 21:01:22 +0000300 Code Elimination, Sparse Conditional Constant Propagation, Inlining, Loop
Chris Lattner7fe7f812002-07-24 19:51:14 +0000301 Invarient Code Motion, Dead Global Elimination, Pool Allocation, and many
302 others...
303
304 <dt><tt>llvm/lib/Target/</tt><dd> This directory contains files that
305 describe various target architectures for code generation. For example,
306 the llvm/lib/Target/Sparc directory holds the Sparc machine
307 description.<br>
308
309 <dt><tt>llvm/lib/CodeGen/</tt><dd> This directory contains the major parts
310 of the code generator: Instruction Selector, Instruction Scheduling, and
311 Register Allocation.
312
313 <dt><tt>llvm/lib/Reoptimizer/</tt><dd> This directory holds code related
314 to the runtime reoptimizer framework that is currently under development.
315
316 <dt><tt>llvm/lib/Support/</tt><dd> This directory contains the source code
317 that corresponds to the header files located in
318 <tt>llvm/include/Support/</tt>.
319 </dl>
320
321 <!------------------------------------------------------------------------->
Chris Lattner44ac6592002-08-09 16:14:56 +0000322 <h3><a name="test"><tt>llvm/test</tt></a></h3>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000323 <!------------------------------------------------------------------------->
324
325 <p>This directory contains regression tests and source code that is used to
326 test the LLVM infrastructure...</p>
327
328 <!------------------------------------------------------------------------->
Chris Lattner44ac6592002-08-09 16:14:56 +0000329 <h3><a name="tools"><tt>llvm/tools</tt></a></h3>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000330 <!------------------------------------------------------------------------->
331
332 <p>The <b>tools</b> directory contains the executables built out of the
333 libraries above, which form the main part of the user interface. You can
334 always get help for a tool by typing <tt>tool_name --help</tt>. The
335 following is a brief introduction to the most important tools.</p>
336
337 <dl compact>
338 <dt><tt><b>as</b></tt><dd>The assembler transforms the human readable
Chris Lattner4b2e2912002-09-19 19:56:53 +0000339 LLVM assembly to LLVM bytecode.<p>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000340
Chris Lattner4b2e2912002-09-19 19:56:53 +0000341 <dt><tt><b>dis</b></tt><dd>The disassembler transforms the LLVM bytecode
342 to human readable LLVM assembly. Additionally it can convert LLVM
Chris Lattner7fe7f812002-07-24 19:51:14 +0000343 bytecode to C, which is enabled with the <tt>-c</tt> option.<p>
344
345 <dt><tt><b>lli</b></tt><dd> <tt>lli</tt> is the LLVM interpreter, which
346 can directly execute LLVM bytecode (although very slowly...). In addition
347 to a simple intepreter, <tt>lli</tt> is also has debugger and tracing
348 modes (entered by specifying <tt>-debug</tt> or <tt>-trace</tt> on the
349 command line, respectively).<p>
350
351 <dt><tt><b>llc</b></tt><dd> <tt>llc</tt> is the LLVM backend compiler,
352 which translates LLVM bytecode to a SPARC assembly file.<p>
353
354 <dt><tt><b>llvmgcc</b></tt><dd> <tt>llvmgcc</tt> is a GCC based C frontend
355 that has been retargeted to emit LLVM code as the machine code output. It
356 works just like any other GCC compiler, taking the typical <tt>-c, -S, -E,
357 -o</tt> options that are typically used. The source code for the
358 <tt>llvmgcc</tt> tool is currently not included in the LLVM cvs tree
359 because it is quite large and not very interesting.<p>
360
361 <ol>
Chris Lattner1db872d2002-09-06 16:26:13 +0000362 <dt><tt><b>gccas</b></tt><dd> This tool is invoked by the
Chris Lattner7fe7f812002-07-24 19:51:14 +0000363 <tt>llvmgcc</tt> frontend as the "assembler" part of the compiler. This
Chris Lattner1db872d2002-09-06 16:26:13 +0000364 tool actually assembles LLVM assembly to LLVM bytecode,
365 performs a variety of optimizations,
Chris Lattner7fe7f812002-07-24 19:51:14 +0000366 and outputs LLVM bytecode. Thus when you invoke <tt>llvmgcc -c x.c -o
367 x.o</tt>, you are causing <tt>gccas</tt> to be run, which writes the
368 <tt>x.o</tt> file (which is an LLVM bytecode file that can be
369 disassembled or manipulated just like any other bytecode file). The
370 command line interface to <tt>gccas</tt> is designed to be as close as
Chris Lattner96768ea2003-02-14 04:22:13 +0000371 possible to the <b>system</b> '<tt>as</tt>' utility so that the gcc
Chris Lattner7fe7f812002-07-24 19:51:14 +0000372 frontend itself did not have to be modified to interface to a "wierd"
373 assembler.<p>
374
Chris Lattner4b2e2912002-09-19 19:56:53 +0000375 <dt><tt><b>gccld</b></tt><dd> <tt>gccld</tt> links together several LLVM
Chris Lattner7fe7f812002-07-24 19:51:14 +0000376 bytecode files into one bytecode file and does some optimization. It is
377 the linker invoked by the gcc frontend when multiple .o files need to be
378 linked together. Like <tt>gccas</tt> the command line interface of
379 <tt>gccld</tt> is designed to match the system linker, to aid
380 interfacing with the GCC frontend.<p>
381 </ol>
382
Chris Lattner4b2e2912002-09-19 19:56:53 +0000383 <dt><tt><b>opt</b></tt><dd> <tt>opt</tt> reads LLVM bytecode, applies a
Chris Lattner7fe7f812002-07-24 19:51:14 +0000384 series of LLVM to LLVM transformations (which are specified on the command
385 line), and then outputs the resultant bytecode. The '<tt>opt --help</tt>'
386 command is a good way to get a list of the program transformations
387 available in LLVM.<p>
388
389
390 <dt><tt><b>analyze</b></tt><dd> <tt>analyze</tt> is used to run a specific
391 analysis on an input LLVM bytecode file and print out the results. It is
392 primarily useful for debugging analyses, or familiarizing yourself with
393 what an analysis does.<p>
394
395 </dl>
396
397 <!--=====================================================================-->
398 <h2><a name="tutorial">An example using the LLVM tool chain</h2>
399 <!--=====================================================================-->
400
401 <ol>
402 <li>First, create a simple C file, name it 'hello.c':
403 <pre>
404 #include &lt;stdio.h&gt;
405 int main() {
406 printf("hello world\n");
407 return 0;
408 }
409 </pre>
410
411 <li>Next, compile the C file into a LLVM bytecode file:<p>
412
413 <tt>% llvmgcc hello.c -o hello</tt><p>
414
415 This will create two result files: <tt>hello</tt> and
416 <tt>hello.bc</tt>. The <tt>hello.bc</tt> is the LLVM bytecode that
417 corresponds the the compiled program and the library facilities that it
418 required. <tt>hello</tt> is a simple shell script that runs the bytecode
419 file with <tt>lli</tt>, making the result directly executable.<p>
420
421 <li>Run the program. To make sure the program ran, execute one of the
422 following commands:<p>
423
424 <tt>% ./hello</tt><p>
425
426 or<p>
427
428 <tt>% lli hello.bc</tt><p>
429
430 <li>Use the <tt>dis</tt> utility to take a look at the LLVM assembly
431 code:<p>
432
433 <tt>% dis < hello.bc | less</tt><p>
434
435 <li>Compile the program to native Sparc assembly using the code
436 generator:<p>
437
438 <tt>% llc hello.bc -o hello.s</tt><p>
439
440 <li>Assemble the native sparc assemble file into a program:<p>
441
442 <tt>% /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.sparc</tt><p>
443
444 <li>Execute the native sparc program:<p>
445
446 <tt>% ./hello.sparc</tt><p>
447
448 </ol>
449
450
451 <!--=====================================================================-->
452 <h2><a name="links">Links</a></h2>
453 <!--=====================================================================-->
454
455 <p>This document is just an <b>introduction</b> to how to use LLVM to do
456 some simple things... there are many more interesting and complicated things
457 that you can do that aren't documented here (but we'll gladly accept a patch
458 if you want to write something up!). For more information about LLVM, check
459 out:</p>
460
461 <ul>
462 <li><a href="http://llvm.cs.uiuc.edu/">LLVM homepage</a></li>
Misha Brukman8e9da622003-05-26 00:17:49 +0000463 <li><a href="http://llvm.cs.uiuc.edu/doxygen/">LLVM doxygen tree</a></li>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000464 </ul>
465
466 <hr>
467
468 If you have any questions or run into any snags (or you have any
Chris Lattner1db872d2002-09-06 16:26:13 +0000469 additions...), please send an email to
Chris Lattner1db872d2002-09-06 16:26:13 +0000470 <a href="mailto:sabre@nondot.org">Chris Lattner</a>.</p>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000471
Guochun Shif4688a82002-07-17 23:05:56 +0000472 <!-- Created: Mon Jul 1 02:29:02 CDT 2002 -->
473 <!-- hhmts start -->
Chris Lattner74e91b22003-06-08 15:33:25 +0000474Last modified: Tue Jun 3 22:06:43 CDT 2003
Guochun Shif4688a82002-07-17 23:05:56 +0000475<!-- hhmts end -->
476 </body>
477</html>