blob: 903d73560d1d8d6f4e7e73d2a6d118699a1b0f54 [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>,
John Criswellcb27f1e2003-07-01 21:55:57 +000010 <a href="mailto:sabre@nondot.org">Chris Lattner</a>,
Misha Brukmanc103adf2003-08-11 18:45:46 +000011 <a href="mailto:criswell@uiuc.edu">John Criswell</a>,
12 <a href="http://misha.brukman.net">Misha Brukman</a>, and
John Criswell85ed3612003-06-12 19:34:44 +000013 <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>
John Criswellce760f62003-07-03 16:01:38 +000022 <ol>
John Criswell7a73b802003-06-30 21:59:07 +000023 <li><a href="#requirements">Requirements</a>
24 <ol>
25 <li><a href="#hardware">Hardware</a>
26 <li><a href="#software">Software</a>
27 </ol>
John Criswellce760f62003-07-03 16:01:38 +000028 </ol>
John Criswell20d2d3e2003-10-10 14:26:14 +000029 <li><a href="#quickstart">Getting Started Quickly (A Summary)</a>
John Criswellce760f62003-07-03 16:01:38 +000030 <li><a href="#starting">Getting started with LLVM</a>
31 <ol>
John Criswell85ed3612003-06-12 19:34:44 +000032 <li><a href="#terminology">Terminology and Notation</tt></a>
John Criswell0b459202003-07-08 20:35:59 +000033 <li><a href="#environment">Setting Up Your Environment</a>
John Criswell312a68c2003-07-07 19:27:35 +000034 <li><a href="#unpack">Unpacking the LLVM Archives</a>
John Criswellce760f62003-07-03 16:01:38 +000035 <li><a href="#checkout">Checkout LLVM from CVS</a>
John Criswell0b459202003-07-08 20:35:59 +000036 <li><a href="#installcf">Install the C Front End</a>
37 <li><a href="#config">Local LLVM Configuration</tt></a>
John Criswellce760f62003-07-03 16:01:38 +000038 <li><a href="#compile">Compiling the LLVM Suite Source Code</a>
John Criswell0b459202003-07-08 20:35:59 +000039 <li><a href="#objfiles">The Location of LLVM Object Files</tt></a>
John Criswell85ed3612003-06-12 19:34:44 +000040 </ol>
41 <li><a href="#layout">Program layout</a>
Misha Brukmanc103adf2003-08-11 18:45:46 +000042 <ol>
43 <li><a href="#cvsdir"><tt>CVS</tt> directories</a>
44 <li><a href="#include"><tt>llvm/include</tt></a>
45 <li><a href="#lib"><tt>llvm/lib</tt></a>
46 <li><a href="#test"><tt>llvm/test</tt></a>
47 <li><a href="#tools"><tt>llvm/tools</tt></a>
48 <li><a href="#utils"><tt>llvm/utils</tt></a>
49 </ol>
John Criswell20d2d3e2003-10-10 14:26:14 +000050 <li><a href="#cfront">Compiling the LLVM GCC Front End</a>
John Criswell0b459202003-07-08 20:35:59 +000051 <li><a href="#tutorial">An Example Using the LLVM Tool Chain</a>
52 <li><a href="#problems">Common Problems</a>
John Criswell85ed3612003-06-12 19:34:44 +000053 <li><a href="#links">Links</a>
54 </ul>
55
56
57 <!--=====================================================================-->
58 <center>
59 <h2><a name="overview"><b>Overview</b></a></h2>
60 </center>
John Criswell20d2d3e2003-10-10 14:26:14 +000061 <hr>
John Criswell85ed3612003-06-12 19:34:44 +000062 <!--=====================================================================-->
63
John Criswellce760f62003-07-03 16:01:38 +000064 Welcome to LLVM! In order to get started, you first need to know some
65 basic information.
66
67 <p>
68 First, LLVM comes in two pieces. The first piece is the LLVM suite. This
69 contains all of the tools, libraries, and header files needed to use the
70 low level virtual machine. It also contains a test suite that can be used
John Criswell20d2d3e2003-10-10 14:26:14 +000071 to test the LLVM tools and the GCC front end.
John Criswellce760f62003-07-03 16:01:38 +000072 <p>
John Criswell20d2d3e2003-10-10 14:26:14 +000073 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.
John Criswellce760f62003-07-03 16:01:38 +000078
79 <!--=====================================================================-->
80 <h3><a name="requirements"><b>Requirements</b></a></h3>
81 <!--=====================================================================-->
82
83 Before you begin to use the LLVM system, review the requirements given
84 below. This may save you some trouble by knowing ahead of time what
85 hardware and software you will need.
86
87 <!--=====================================================================-->
88 <h4><a name="hardware"><b>Hardware</b></a></h4>
89 <!--=====================================================================-->
90 LLVM is known to work on the following platforms:
91 <ul>
92 <li> Linux on x86
93 <ul>
John Criswell0b459202003-07-08 20:35:59 +000094 <li> Approximately 760 MB of Free Disk Space
John Criswellce760f62003-07-03 16:01:38 +000095 <ul>
96 <li>Source code: 30 MB
97 <li>Object code: 670 MB
John Criswell20d2d3e2003-10-10 14:26:14 +000098 <li>GCC front end: 60 MB
John Criswellce760f62003-07-03 16:01:38 +000099 </ul>
100 </ul>
John Criswell0b459202003-07-08 20:35:59 +0000101
102 <p>
103
John Criswellce760f62003-07-03 16:01:38 +0000104 <li> Solaris on SparcV9 (Ultrasparc)
105 <ul>
John Criswell0b459202003-07-08 20:35:59 +0000106 <li> Approximately 1.24 GB of Free Disk Space
John Criswellce760f62003-07-03 16:01:38 +0000107 <ul>
108 <li>Source code: 30 MB
109 <li>Object code: 1000 MB
John Criswell20d2d3e2003-10-10 14:26:14 +0000110 <li>GCC front end: 210 MB
John Criswellce760f62003-07-03 16:01:38 +0000111 </ul>
112 </ul>
113 </ul>
114
John Criswell0b459202003-07-08 20:35:59 +0000115 <p>
John Criswell20d2d3e2003-10-10 14:26:14 +0000116 If you want to compile your own version of the GCC front end, you will need
John Criswell0b459202003-07-08 20:35:59 +0000117 additional disk space:
118 </p>
119
120 <ul>
121 <li>Linux on x86
122 <ul>
123 <li> Approximately 249 MB of Free Disk Space
124 <ul>
125 <li>Source code: 146 MB
126 <li>Object code: 82 MB
127 <li>Installed binaries: 21 MB
128 </ul>
129 </ul>
130
131 <p>
132
133 <li>Solaris on Sparc
134 <ul>
135 <li> Approximately 264 MB of Free Disk Space
136 <ul>
137 <li>Source code: 146 MB
138 <li>Object code: 93 MB
139 <li>Installed binaries: 25 MB
140 </ul>
141 </ul>
142 </ul>
143
144 <p>
John Criswellce760f62003-07-03 16:01:38 +0000145 LLVM <i>may</i> compile on other platforms. The LLVM utilities should work
146 on other platforms, so it should be possible to generate and produce LLVM
147 bytecode on unsupported platforms (although bytecode generated on one
148 platform may not work on another platform). However, the code generators
Misha Brukmanc56e5822003-07-03 16:29:36 +0000149 and Just-In-Time (JIT) compilers only generate SparcV9 or x86 machine code.
John Criswell0b459202003-07-08 20:35:59 +0000150 </p>
John Criswellce760f62003-07-03 16:01:38 +0000151
152 <!--=====================================================================-->
153 <h4><a name="software"><b>Software</b></a></h4>
154 <!--=====================================================================-->
155 <p>
John Criswell6dd90d22003-07-03 16:43:01 +0000156
157 Unpacking the distribution requires the following tools:
158 <dl compact>
159 <dt>GNU Zip (gzip)
160 <dt>GNU Tar
161 <dd>
162 These tools are needed to uncompress and unarchive the software.
163 Regular Solaris <tt>tar</tt> may work for unpacking the TAR archive but
164 is untested.
165 </dl>
166
John Criswellce760f62003-07-03 16:01:38 +0000167 Compiling LLVM requires that you have several different software packages
168 installed:
169
170 <dl compact>
171 <dt> GCC
172 <dd>
173 The GNU Compiler Collection must be installed with C and C++ language
174 support. GCC 3.2.x works, and GCC 3.x is generally supported.
175
176 <p>
177 Note that we currently do not support any other C++ compiler.
178 </p>
179
180 <dt> GNU Make
181 <dd>
182 The LLVM build system relies upon GNU Make extensions. Therefore, you
183 will need GNU Make (sometimes known as gmake) to build LLVM.
184 <p>
185
186 <dt> Flex and Bison
187 <dd>
188 The LLVM source code is built using flex and bison. You will not be
189 able to configure and compile LLVM without them.
190 <p>
191
192 <dt> GNU M4
193 <dd>
194 If you are installing Bison on your machine for the first time, you
195 will need GNU M4 (version 1.4 or higher).
196 </dl>
197
198 <p>
199 There are some additional tools that you may want to have when working with
200 LLVM:
201 </p>
202
203 <ul>
204 <li>GNU Autoconf
205 <li>GNU M4
206 <p>
207 If you want to make changes to the configure scripts, you will need
208 GNU autoconf (2.53 or higher), and consequently, GNU M4 (version 1.4
209 or higher).
210 </p>
211 </ul>
212
213
John Criswell20d2d3e2003-10-10 14:26:14 +0000214 <p>The remainder of this guide is meant to get you up and running with
215 LLVM and to give you some basic information about the LLVM environment.
216 The <a href"#quickstart">next section</a> gives a short summary for those
217 who are already familiar with the system and want to get started as quickly
218 as possible. A more complete description is provided after that.
John Criswell85ed3612003-06-12 19:34:44 +0000219
220 <p>The later sections of this guide describe the <a
John Criswellcb27f1e2003-07-01 21:55:57 +0000221 href="#layout">general layout</a> of the the LLVM source-tree, a <a
John Criswell85ed3612003-06-12 19:34:44 +0000222 href="#tutorial">simple example</a> using the LLVM tool chain, and <a
223 href="#links">links</a> to find more information about LLVM or to get
224 help via e-mail.
225
226 <!--=====================================================================-->
227 <center>
John Criswell20d2d3e2003-10-10 14:26:14 +0000228 <h2><a name="quickstart"><b>Getting Started Quickly (A Summary)</b></a></h2>
John Criswell85ed3612003-06-12 19:34:44 +0000229 </center>
John Criswell20d2d3e2003-10-10 14:26:14 +0000230 <hr>
John Criswell85ed3612003-06-12 19:34:44 +0000231 <!--=====================================================================-->
232
233 Here's the short story for getting up and running quickly with LLVM:
Chris Lattner96768ea2003-02-14 04:22:13 +0000234 <ol>
John Criswell20d2d3e2003-10-10 14:26:14 +0000235 <li>Install the GCC front end:
John Criswellce760f62003-07-03 16:01:38 +0000236 <ol>
John Criswell0b459202003-07-08 20:35:59 +0000237 <li><tt>cd <i>where-you-want-the-C-front-end-to-live</i></tt>
238 <li><tt>gunzip --stdout cfrontend.<i>platform</i>.tar.gz | tar -xvf
239 -</tt>
240 </ol>
John Criswell7a73b802003-06-30 21:59:07 +0000241
John Criswell0b459202003-07-08 20:35:59 +0000242 <p>
243
244 <li>Get the Source Code
245 <ul>
246 <li>With the distributed files:
247 <ol>
248 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
249 <li><tt>gunzip --stdout llvm.tar.gz | tar -xvf -</tt>
John Criswell0b459202003-07-08 20:35:59 +0000250 <li><tt>cd llvm</tt>
251 </ol>
252
253 <p>
254
255 <li>With anonymous CVS access:
256 <ol>
Misha Brukmanc103adf2003-08-11 18:45:46 +0000257 <li>Find the path to the CVS repository containing LLVM (we'll
258 call this <i>CVSROOTDIR</i>).
John Criswell0b459202003-07-08 20:35:59 +0000259 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
260 <li><tt>cvs -d <i>CVSROOTDIR</i> checkout llvm</tt>
261 <li><tt>cd llvm</tt>
262 </ol>
263 </ul>
264 </ul>
265
266 <p>
267
268 <li>Configure the LLVM Build Environment
269 <ol>
John Criswell20d2d3e2003-10-10 14:26:14 +0000270 <li>Change directory to where you want to store the LLVM object
271 files and run <tt>configure</tt> to configure the Makefiles and
272 header files for the default platform.
John Criswell0b459202003-07-08 20:35:59 +0000273 Useful options include:
274 <ul>
John Criswell0b459202003-07-08 20:35:59 +0000275 <li><tt>--with-llvmgccdir=<i>directory</i></tt>
276 <br>
John Criswell20d2d3e2003-10-10 14:26:14 +0000277 Specify where the LLVM GCC frontend is installed.
John Criswell0b459202003-07-08 20:35:59 +0000278 </ul>
279 </ol>
280
281 <p>
282
283 <li>Build the LLVM Suite
284 <ol>
285 <li>Set your LLVM_LIB_SEARCH_PATH environment variable.
286 <li><tt>gmake -k |& tee gnumake.out
John Criswellce760f62003-07-03 16:01:38 +0000287 &nbsp;&nbsp;&nbsp;# this is csh or tcsh syntax</tt>
288 </ol>
John Criswell0b459202003-07-08 20:35:59 +0000289
John Criswellce760f62003-07-03 16:01:38 +0000290 <p>
John Criswell0b459202003-07-08 20:35:59 +0000291
Chris Lattner96768ea2003-02-14 04:22:13 +0000292 </ol>
John Criswell85ed3612003-06-12 19:34:44 +0000293
John Criswell0b459202003-07-08 20:35:59 +0000294 <p>See <a href="#environment">Setting Up Your Environment</a> on tips to
John Criswell85ed3612003-06-12 19:34:44 +0000295 simplify working with the LLVM front-end and compiled tools. See the
John Criswell20d2d3e2003-10-10 14:26:14 +0000296 next section for other useful details in working with LLVM,
John Criswell85ed3612003-06-12 19:34:44 +0000297 or go straight to <a href="#layout">Program Layout</a> to learn about the
John Criswell20d2d3e2003-10-10 14:26:14 +0000298 layout of the source code tree. For information on building the GCC front
299 end yourself, see <a href="#cfront">Compiling the LLVM GCC Front End</a> for
John Criswell0b459202003-07-08 20:35:59 +0000300 information.
John Criswell85ed3612003-06-12 19:34:44 +0000301
John Criswell20d2d3e2003-10-10 14:26:14 +0000302 <!--=====================================================================-->
303 <center>
304 <h2><a name="starting"><b>Getting Started with LLVM</b></a></h2>
305 </center>
306 <hr>
307 <!--=====================================================================-->
308
John Criswell85ed3612003-06-12 19:34:44 +0000309 <!------------------------------------------------------------------------->
310 <h3><a name="terminology">Terminology and Notation</a></h3>
311 <!------------------------------------------------------------------------->
312
313 <p>Throughout this manual, the following names are used to denote paths
314 specific to the local system and working environment. <i>These are not
John Criswell7a73b802003-06-30 21:59:07 +0000315 environment variables you need to set but just strings used in the rest
316 of this document below</i>. In any of the examples below, simply replace
John Criswell85ed3612003-06-12 19:34:44 +0000317 each of these names with the appropriate pathname on your local system.
Chris Lattner1db872d2002-09-06 16:26:13 +0000318 All these paths are absolute:</p>
John Criswellce760f62003-07-03 16:01:38 +0000319 <dl compact>
320 <dt>CVSROOTDIR
321 <dd>
322 This is the path for the CVS repository containing the LLVM source
323 code. Ask the person responsible for your local LLVM installation to
324 give you this path.
325 <p>
326
John Criswell20d2d3e2003-10-10 14:26:14 +0000327 <dt>SRC_ROOT
328 <dd>
329 This is the top level directory of the LLVM source tree.
330 <p>
331
John Criswellce760f62003-07-03 16:01:38 +0000332 <dt>OBJ_ROOT
333 <dd>
John Criswell20d2d3e2003-10-10 14:26:14 +0000334 This is the top level directory of the LLVM object tree (i.e. the
335 tree where object files and compiled programs will be placed. It
336 can be the same as SRC_ROOT).
John Criswellce760f62003-07-03 16:01:38 +0000337 <p>
338
339 <dt>LLVMGCCDIR
340 <dd>
John Criswell20d2d3e2003-10-10 14:26:14 +0000341 This is the where the LLVM GCC Front End is installed.
John Criswellce760f62003-07-03 16:01:38 +0000342 <p>
John Criswell20d2d3e2003-10-10 14:26:14 +0000343 For the pre-built GCC front end binaries, the LLVMGCCDIR is the
John Criswella27028b2003-07-03 16:49:40 +0000344 <tt>cfrontend/<i>platform</i>/llvm-gcc</tt>.
John Criswellce760f62003-07-03 16:01:38 +0000345
346 <dt>GCCSRC
347 <dd>
John Criswell20d2d3e2003-10-10 14:26:14 +0000348 This is the location of the LLVM GCC front end source code (used
349 only if the LLVM GCC front end is being compiled).
John Criswellce760f62003-07-03 16:01:38 +0000350 <p>
351
352 <dt>GCCOBJ
353 <dd>
John Criswell20d2d3e2003-10-10 14:26:14 +0000354 This is the location of the LLVM GCC front end object code (used
355 only if the LLVM GCC front end is being compiled). It can be
356 safely removed once the LLVM GCC front end is built and installed.
John Criswellce760f62003-07-03 16:01:38 +0000357 </dl>
358
359 <!------------------------------------------------------------------------->
John Criswell0b459202003-07-08 20:35:59 +0000360 <h3><a name="environment">Setting Up Your Environment</a></h3>
John Criswellce760f62003-07-03 16:01:38 +0000361 <!------------------------------------------------------------------------->
362
363 <p>
364 In order to compile and use LLVM, you will need to set some environment
365 variables. There are also some shell aliases which you may find useful.
366 You can set these on the command line, or better yet, set them in your
367 <tt>.cshrc</tt> or <tt>.profile</tt>.
368
369 <dl compact>
370 <dt><tt>LLVM_LIB_SEARCH_PATH</tt>=<tt><i>LLVMGCCDIR</i>/llvm-gcc/bytecode-libs</tt>
371 <dd>
John Criswell20d2d3e2003-10-10 14:26:14 +0000372 This environment variable helps the LLVM GCC front end find bytecode
John Criswellce760f62003-07-03 16:01:38 +0000373 libraries that it will need for compilation.
374 <p>
375
John Criswellce760f62003-07-03 16:01:38 +0000376 <dt>alias llvmgcc <i>LLVMGCCDIR</i><tt>/bin/llvm-gcc</tt>
John Criswell20d2d3e2003-10-10 14:26:14 +0000377 <dt>alias llvmg++ <i>LLVMGCCDIR</i><tt>/bin/llvm-g++</tt>
John Criswellce760f62003-07-03 16:01:38 +0000378 <dd>
John Criswell20d2d3e2003-10-10 14:26:14 +0000379 This alias allows you to use the LLVM C and C++ front ends without putting
380 them in your <tt>PATH</tt> or typing in their complete pathnames.
John Criswellce760f62003-07-03 16:01:38 +0000381 </dl>
John Criswell85ed3612003-06-12 19:34:44 +0000382
383 <!------------------------------------------------------------------------->
John Criswell312a68c2003-07-07 19:27:35 +0000384 <h3><a name="unpack">Unpacking the LLVM Archives</a></h3>
385 <!------------------------------------------------------------------------->
386
387 <p>
388 If you have the LLVM distribution, you will need to unpack it before you
389 can begin to compile it. LLVM is distributed as a set of four files. Each
390 file is a TAR archive that is compressed with the gzip program.
391 </p>
392
John Criswell0b459202003-07-08 20:35:59 +0000393 <p> The four files are as follows:
John Criswell312a68c2003-07-07 19:27:35 +0000394 <dl compact>
395 <dt>llvm.tar.gz
396 <dd>This is the source code to the LLVM suite.
397 <p>
398
399 <dt>cfrontend.sparc.tar.gz
John Criswell20d2d3e2003-10-10 14:26:14 +0000400 <dd>This is the binary release of the GCC front end for Solaris/Sparc.
John Criswell312a68c2003-07-07 19:27:35 +0000401 <p>
402
403 <dt>cfrontend.x86.tar.gz
John Criswell20d2d3e2003-10-10 14:26:14 +0000404 <dd>This is the binary release of the GCC front end for Linux/x86.
John Criswell312a68c2003-07-07 19:27:35 +0000405 <p>
406
407 <dt>cfrontend-src.tar.gz
John Criswell20d2d3e2003-10-10 14:26:14 +0000408 <dd>This is the source code release of the GCC front end.
John Criswell312a68c2003-07-07 19:27:35 +0000409 <p>
410 </dl>
411
John Criswell312a68c2003-07-07 19:27:35 +0000412 <!------------------------------------------------------------------------->
John Criswell85ed3612003-06-12 19:34:44 +0000413 <h3><a name="checkout">Checkout LLVM from CVS</a></h3>
414 <!------------------------------------------------------------------------->
415
John Criswell312a68c2003-07-07 19:27:35 +0000416 <p>If you have access to our CVS repository, you can get a fresh copy of
417 the entire source code. All you need to do is check it out from CVS as
418 follows:
John Criswell85ed3612003-06-12 19:34:44 +0000419 <ul>
420 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
421 <li><tt>cvs -d <i>CVSROOTDIR</i> checkout llvm</tt></p>
422 </ul>
423
424 <p>This will create an '<tt>llvm</tt>' directory in the current
425 directory and fully populate it with the LLVM source code, Makefiles,
426 test directories, and local copies of documentation files.</p>
427
John Criswellce760f62003-07-03 16:01:38 +0000428 <p>
John Criswell20d2d3e2003-10-10 14:26:14 +0000429 Note that the GCC front end is not included in the CVS repository. You
John Criswellce760f62003-07-03 16:01:38 +0000430 should have either downloaded the source, or better yet, downloaded the
431 binary distribution for your platform.
432 </p>
433
John Criswell85ed3612003-06-12 19:34:44 +0000434 <!------------------------------------------------------------------------->
John Criswell20d2d3e2003-10-10 14:26:14 +0000435 <h3><a name="installcf">Install the GCC Front End</a></h3>
John Criswell0b459202003-07-08 20:35:59 +0000436 <!------------------------------------------------------------------------->
437
438 <p>
John Criswell20d2d3e2003-10-10 14:26:14 +0000439 Before configuring and compiling the LLVM suite, you need to extract the
440 LLVM GCC front end from the binary distribution. It is used for building the
441 bytecode libraries later used by the GCC front end for linking programs, and
442 its location must be specified when the LLVM suite is configured.
John Criswell0b459202003-07-08 20:35:59 +0000443 </p>
444
445 <p>
John Criswell20d2d3e2003-10-10 14:26:14 +0000446 To install the GCC front end, do the following:
John Criswell0b459202003-07-08 20:35:59 +0000447 <ol>
448 <li><tt>cd <i>where-you-want-the-front-end-to-live</i></tt>
449 <li><tt>gunzip --stdout cfrontend.<i>platform</i>.tar.gz | tar -xvf
450 -</tt>
451 </ol>
452
453 <!------------------------------------------------------------------------->
John Criswellce760f62003-07-03 16:01:38 +0000454 <h3><a name="config">Local LLVM Configuration</a></h3>
John Criswell85ed3612003-06-12 19:34:44 +0000455 <!------------------------------------------------------------------------->
456
John Criswellce760f62003-07-03 16:01:38 +0000457 <p>Once checked out from the CVS repository, the LLVM suite source code
458 must be configured via the <tt>configure</tt> script. This script sets
459 variables in <tt>llvm/Makefile.config</tt> and
John Criswell20d2d3e2003-10-10 14:26:14 +0000460 <tt>llvm/include/Config/config.h</tt>. It also populates OBJ_ROOT with
461 the Makefiles needed to build LLVM.
John Criswell7a73b802003-06-30 21:59:07 +0000462
463 <p>
John Criswell0b459202003-07-08 20:35:59 +0000464 The following environment variables are used by the <tt>configure</tt>
465 script to configure the build system:
John Criswell7a73b802003-06-30 21:59:07 +0000466 </p>
John Criswell85ed3612003-06-12 19:34:44 +0000467
John Criswell0b459202003-07-08 20:35:59 +0000468 <table border=1>
469 <tr>
470 <th>Variable</th>
471 <th>
472 Purpose
473 </th>
474 </tr>
John Criswell85ed3612003-06-12 19:34:44 +0000475
John Criswell0b459202003-07-08 20:35:59 +0000476 <tr>
477 <td>CC</td>
478 <td>
479 Tells <tt>configure</tt> which C compiler to use. By default,
480 <tt>configure</tt> will look for the first GCC compiler in
481 <tt>PATH</tt>. Use this variable to override
482 <tt>configure</tt>'s default behavior.
483 </td>
484 </tr>
485
486 <tr>
487 <td>CXX</td>
488 <td>
489 Tells <tt>configure</tt> which C++ compiler to use. By default,
490 <tt>configure</tt> will look for the first GCC compiler in
491 <tt>PATH</tt>. Use this variable to override
492 <tt>configure</tt>'s default behavior.
493 </td>
494 </tr>
495 </table>
496
497 <p>
John Criswell7a73b802003-06-30 21:59:07 +0000498 The following options can be used to set or enable LLVM specific options:
John Criswell0b459202003-07-08 20:35:59 +0000499 </p>
John Criswell7a73b802003-06-30 21:59:07 +0000500
John Criswellce760f62003-07-03 16:01:38 +0000501 <dl compact>
John Criswellce760f62003-07-03 16:01:38 +0000502 <dt><i>--with-llvmgccdir=LLVMGCCDIR</i>
503 <dd>
504 Path to the location where the LLVM C front end binaries and
505 associated libraries will be installed.
506 <p>
507 <dt><i>--enable-optimized</i>
508 <dd>
John Criswell20d2d3e2003-10-10 14:26:14 +0000509 Enables optimized compilation by defaulat (debugging symbols are removed
510 and GCC optimization flags are enabled). The default is to use an
511 unoptimized build (also known as a debug build).
John Criswellce760f62003-07-03 16:01:38 +0000512 <p>
513 <dt><i>--enable-jit</i>
514 <dd>
John Criswell7a73b802003-06-30 21:59:07 +0000515 Compile the Just In Time (JIT) functionality. This is not available
John Criswellce760f62003-07-03 16:01:38 +0000516 on all platforms. The default is dependent on platform, so it is best
517 to explicitly enable it if you want it.
John Criswell20d2d3e2003-10-10 14:26:14 +0000518 <p>
519 <dt><i>--enable-spec2000</i>
520 <dt><i>--enable-spec2000=&lt;<tt>directory</tt>&gt;</i>
521 <dd>
522 Enable the use of SPEC2000 when testing LLVM. This is disabled by default
523 (unless <tt>configure</tt> find SPEC2000 installed). By specifying
524 <tt>directory</tt>, you can tell configure where to find the SPEC2000
525 benchmarks. If <tt>directory</tt> is left unspecified, it
526 <tt>configure</tt> uses a default value for our internal
527 installation of SPEC2000.
John Criswellce760f62003-07-03 16:01:38 +0000528 </dl>
John Criswell7a73b802003-06-30 21:59:07 +0000529
John Criswell20d2d3e2003-10-10 14:26:14 +0000530 <p>
531 To configure LLVM, follow these steps:
532 <ol>
533 <li>Change directory into the object root directory:
534 <br>
535 <tt>cd <i>OBJ_ROOT</i></tt>
536 <p>
537
538 <li>Run the <ttconfigure</tt> script located in the LLVM source tree:
539 <br>
540 <tt><i>SRC_ROOT</i>/configure</tt>
541 <p>
542 </ol>
543 </p>
544
John Criswell7a73b802003-06-30 21:59:07 +0000545 In addition to running <tt>configure</tt>, you must set the
John Criswell85ed3612003-06-12 19:34:44 +0000546 <tt>LLVM_LIB_SEARCH_PATH</tt> environment variable in your startup scripts.
547 This environment variable is used to locate "system" libraries like
548 "<tt>-lc</tt>" and "<tt>-lm</tt>" when linking. This variable should be set
John Criswell20d2d3e2003-10-10 14:26:14 +0000549 to the absolute path for the bytecode-libs subdirectory of the GCC front end
John Criswellce760f62003-07-03 16:01:38 +0000550 install, or LLVMGCCDIR/llvm-gcc/bytecode-libs. For example, one might
551 set <tt>LLVM_LIB_SEARCH_PATH</tt> to
John Criswell85ed3612003-06-12 19:34:44 +0000552 <tt>/home/vadve/lattner/local/x86/llvm-gcc/bytecode-libs</tt> for the X86
553 version of the C front-end on our research machines.<p>
554
555 <!------------------------------------------------------------------------->
John Criswellce760f62003-07-03 16:01:38 +0000556 <h3><a name="compile">Compiling the LLVM Suite Source Code</a></h3>
557 <!------------------------------------------------------------------------->
558
559 Once you have configured LLVM, you can build it. There are three types of
560 builds:
561
562 <dl compact>
563 <dt>Debug Builds
564 <dd>
John Criswell20d2d3e2003-10-10 14:26:14 +0000565 These builds are the default when one types <tt>gmake</tt> (unless the
566 <tt>--enable-optimized</tt> option was used during configuration). They
567 compile the tools and libraries with debugging information.
John Criswellce760f62003-07-03 16:01:38 +0000568 <p>
569
570 <dt>Release (Optimized) Builds
571 <dd>
572 These builds are enabled with the <tt>--enable-optimized</tt> option to
John Criswell20d2d3e2003-10-10 14:26:14 +0000573 <tt>configure</tt> or by specifying <tt>ENABLE_OPTIMIZED=1</tt> on the
574 <tt>gmake</tt> command line. They compile the tools and libraries with GCC
John Criswellce760f62003-07-03 16:01:38 +0000575 optimizer flags on and strip debugging information from the libraries
576 and executables it generates.
577 <p>
578
579 <dt>Profile Builds
580 <dd>
581 These builds are for use with profiling. They compile profiling
582 information into the code for use with programs like <tt>gprof</tt>.
John Criswell20d2d3e2003-10-10 14:26:14 +0000583 Profile builds must be started by specifying <tt>ENABLE_PROFILING=1</tt>
584 on the <tt>gmake</tt> command line.
John Criswellce760f62003-07-03 16:01:38 +0000585 </dl>
586
John Criswell20d2d3e2003-10-10 14:26:14 +0000587 Once you have LLVM configured, you can build it by entering the OBJ_ROOT
588 directory and issuing the following command:
John Criswellce760f62003-07-03 16:01:38 +0000589 <p>
John Criswell0b459202003-07-08 20:35:59 +0000590 <tt>gmake</tt>
John Criswellce760f62003-07-03 16:01:38 +0000591
592 <p>
593 If you have multiple processors in your machine, you may wish to use some
594 of the parallel build options provided by GNU Make. For example, you could
595 use the command:
596 </p>
597
598 <p>
John Criswell0b459202003-07-08 20:35:59 +0000599 <tt>gmake -j2</tt>
John Criswellce760f62003-07-03 16:01:38 +0000600
601 <p>
John Criswell20d2d3e2003-10-10 14:26:14 +0000602 There are several special targets which are useful when working with the LLVM
John Criswellce760f62003-07-03 16:01:38 +0000603 source code:
604
605 <dl compact>
John Criswell0b459202003-07-08 20:35:59 +0000606 <dt><tt>gmake clean</tt>
John Criswellce760f62003-07-03 16:01:38 +0000607 <dd>
608 Removes all files generated by the build. This includes object files,
609 generated C/C++ files, libraries, and executables.
610 <p>
611
John Criswell0b459202003-07-08 20:35:59 +0000612 <dt><tt>gmake distclean</tt>
John Criswellce760f62003-07-03 16:01:38 +0000613 <dd>
John Criswell0b459202003-07-08 20:35:59 +0000614 Removes everything that <tt>gmake clean</tt> does, but also removes
John Criswellce760f62003-07-03 16:01:38 +0000615 files generated by <tt>configure</tt>. It attempts to return the
616 source tree to the original state in which it was shipped.
617 <p>
John Criswell20d2d3e2003-10-10 14:26:14 +0000618
619 <dt><tt>gmake install</tt>
620 <dd>
621 Installs LLVM files into the proper location. For the most part,
622 this does nothing, but it does install bytecode libraries into the
623 GCC front end's bytecode library directory. If you need to update
624 your bytecode libraries, this is the target to use once you've built
625 them.
626 <p>
627
John Criswellce760f62003-07-03 16:01:38 +0000628 </dl>
629
630 It is also possible to override default values from <tt>configure</tt> by
631 declaring variables on the command line. The following are some examples:
632
633 <dl compact>
John Criswell0b459202003-07-08 20:35:59 +0000634 <dt><tt>gmake ENABLE_OPTIMIZED=1</tt>
John Criswellce760f62003-07-03 16:01:38 +0000635 <dd>
636 Perform a Release (Optimized) build.
637 <p>
638
John Criswell0b459202003-07-08 20:35:59 +0000639 <dt><tt>gmake ENABLE_PROFILING=1</tt>
John Criswellce760f62003-07-03 16:01:38 +0000640 <dd>
641 Perform a Profiling build.
642 <p>
643
John Criswell0b459202003-07-08 20:35:59 +0000644 <dt><tt>gmake VERBOSE=1</tt>
John Criswellce760f62003-07-03 16:01:38 +0000645 <dd>
John Criswell0b459202003-07-08 20:35:59 +0000646 Print what <tt>gmake</tt> is doing on standard output.
John Criswellce760f62003-07-03 16:01:38 +0000647 <p>
648 </dl>
649
John Criswell20d2d3e2003-10-10 14:26:14 +0000650 Every directory in the LLVM object tree includes a <tt>Makefile</tt> to
John Criswellce760f62003-07-03 16:01:38 +0000651 build it and any subdirectories that it contains. Entering any directory
John Criswell20d2d3e2003-10-10 14:26:14 +0000652 inside the LLVM object tree and typing <tt>gmake</tt> should rebuild
John Criswellce760f62003-07-03 16:01:38 +0000653 anything in or below that directory that is out of date.
654
655 <!------------------------------------------------------------------------->
John Criswell0b459202003-07-08 20:35:59 +0000656 <h3><a name="objfiles">The Location of LLVM Object Files</a></h3>
John Criswell85ed3612003-06-12 19:34:44 +0000657 <!------------------------------------------------------------------------->
658
John Criswellce760f62003-07-03 16:01:38 +0000659 <p>
John Criswell20d2d3e2003-10-10 14:26:14 +0000660 The LLVM build system is capable of sharing a single LLVM source tree among
661 several LLVM builds. Hence, it is possible to build LLVM for several
662 different platforms or configurations using the same source tree.
John Criswellef0096f2003-08-08 22:36:30 +0000663 <p>
John Criswell20d2d3e2003-10-10 14:26:14 +0000664 This is accomplished in the typical autoconf manner:
665 <ul>
666 <li>Change directory to where the LLVM object files should live:
667 <p>
668 <tt>cd <i>OBJ_ROOT</i></tt>
John Criswell85ed3612003-06-12 19:34:44 +0000669
John Criswell20d2d3e2003-10-10 14:26:14 +0000670 <li>Run the <tt>configure</tt> script found in the LLVM source directory:
671 <p>
672 <tt><i>SRC_ROOT</i>/configure</tt>
673 </ul>
John Criswell85ed3612003-06-12 19:34:44 +0000674
John Criswellce760f62003-07-03 16:01:38 +0000675 <p>
676 The LLVM build will place files underneath <i>OBJ_ROOT</i> in directories
677 named after the build type:
678 </p>
John Criswell85ed3612003-06-12 19:34:44 +0000679
John Criswellce760f62003-07-03 16:01:38 +0000680 <dl compact>
681 <dt>Debug Builds
682 <dd>
683 <dl compact>
684 <dt>Tools
John Criswell20d2d3e2003-10-10 14:26:14 +0000685 <dd><tt><i>OBJ_ROOT</i>/tools/Debug</tt>
John Criswellce760f62003-07-03 16:01:38 +0000686 <dt>Libraries
John Criswell20d2d3e2003-10-10 14:26:14 +0000687 <dd><tt><i>OBJ_ROOT</i>/lib/Debug</tt>
John Criswellce760f62003-07-03 16:01:38 +0000688 </dl>
689 <p>
John Criswell85ed3612003-06-12 19:34:44 +0000690
John Criswellce760f62003-07-03 16:01:38 +0000691 <dt>Release Builds
692 <dd>
693 <dl compact>
694 <dt>Tools
John Criswell20d2d3e2003-10-10 14:26:14 +0000695 <dd><tt><i>OBJ_ROOT</i>/tools/Release</tt>
John Criswellce760f62003-07-03 16:01:38 +0000696 <dt>Libraries
John Criswell20d2d3e2003-10-10 14:26:14 +0000697 <dd><tt><i>OBJ_ROOT</i>/lib/Release</tt>
John Criswellce760f62003-07-03 16:01:38 +0000698 </dl>
699 <p>
Chris Lattner7fe7f812002-07-24 19:51:14 +0000700
John Criswellce760f62003-07-03 16:01:38 +0000701 <dt>Profile Builds
702 <dd>
703 <dl compact>
704 <dt>Tools
John Criswell20d2d3e2003-10-10 14:26:14 +0000705 <dd><tt><i>OBJ_ROOT</i>/tools/Profile</tt>
John Criswellce760f62003-07-03 16:01:38 +0000706 <dt>Libraries
John Criswell20d2d3e2003-10-10 14:26:14 +0000707 <dd><tt><i>OBJ_ROOT</i>/lib/Profile</tt>
John Criswellce760f62003-07-03 16:01:38 +0000708 </dl>
709 </dl>
John Criswell85ed3612003-06-12 19:34:44 +0000710
711 <!--=====================================================================-->
712 <center>
713 <h2><a name="layout"><b>Program Layout</b></a></h2>
714 </center>
John Criswell20d2d3e2003-10-10 14:26:14 +0000715 <hr>
John Criswell85ed3612003-06-12 19:34:44 +0000716 <!--=====================================================================-->
717
John Criswell20d2d3e2003-10-10 14:26:14 +0000718 <p>
719 One useful source of information about the LLVM source base is the LLVM <a
John Criswell85ed3612003-06-12 19:34:44 +0000720 href="http://www.doxygen.org">doxygen</a> documentation, available at <tt><a
John Criswell20d2d3e2003-10-10 14:26:14 +0000721 href="http://llvm.cs.uiuc.edu/doxygen/">http://llvm.cs.uiuc.edu/doxygen/</a></tt>.
722 The following is a brief introduction to code layout:
723 </p>
John Criswell85ed3612003-06-12 19:34:44 +0000724
725 <!------------------------------------------------------------------------->
726 <h3><a name="cvsdir"><tt>CVS</tt> directories</a></h3>
727 <!------------------------------------------------------------------------->
728
729 Every directory checked out of CVS will contain a <tt>CVS</tt> directory;
730 for the most part these can just be ignored.
731
732
733 <!------------------------------------------------------------------------->
John Criswell85ed3612003-06-12 19:34:44 +0000734 <h3><a name="include"><tt>llvm/include</tt></a></h3>
735 <!------------------------------------------------------------------------->
736
737 This directory contains public header files exported from the LLVM
John Criswell7a73b802003-06-30 21:59:07 +0000738 library. The three main subdirectories of this directory are:<p>
John Criswell85ed3612003-06-12 19:34:44 +0000739
John Criswell8df90e02003-06-11 20:46:40 +0000740 <ol>
John Criswell85ed3612003-06-12 19:34:44 +0000741 <li><tt>llvm/include/llvm</tt> - This directory contains all of the LLVM
742 specific header files. This directory also has subdirectories for
743 different portions of LLVM: <tt>Analysis</tt>, <tt>CodeGen</tt>,
John Criswell20d2d3e2003-10-10 14:26:14 +0000744 <tt>Target</tt>, <tt>Transforms</tt>, etc...
John Criswell85ed3612003-06-12 19:34:44 +0000745
746 <li><tt>llvm/include/Support</tt> - This directory contains generic
John Criswellce760f62003-07-03 16:01:38 +0000747 support libraries that are independent of LLVM, but are used by LLVM.
John Criswell7a73b802003-06-30 21:59:07 +0000748 For example, some C++ STL utilities and a Command Line option processing
749 library.
750
751 <li><tt>llvm/include/Config</tt> - This directory contains header files
752 configured by the <tt>configure</tt> script. They wrap "standard" UNIX
753 and C header files. Source code can include these header files which
754 automatically take care of the conditional #includes that the configure
755 script generates.
Chris Lattner7fe7f812002-07-24 19:51:14 +0000756 </ol>
John Criswell85ed3612003-06-12 19:34:44 +0000757
758 <!------------------------------------------------------------------------->
759 <h3><a name="lib"><tt>llvm/lib</tt></a></h3>
760 <!------------------------------------------------------------------------->
761
John Criswell7a73b802003-06-30 21:59:07 +0000762 This directory contains most of the source files of the LLVM system. In
763 LLVM almost all
764 code exists in libraries, making it very easy to share code among the
John Criswell85ed3612003-06-12 19:34:44 +0000765 different <a href="#tools">tools</a>.<p>
766
767 <dl compact>
768 <dt><tt>llvm/lib/VMCore/</tt><dd> This directory holds the core LLVM
769 source files that implement core classes like Instruction and BasicBlock.
770
771 <dt><tt>llvm/lib/AsmParser/</tt><dd> This directory holds the source code
772 for the LLVM assembly language parser library.
773
774 <dt><tt>llvm/lib/ByteCode/</tt><dd> This directory holds code for reading
775 and write LLVM bytecode.
776
777 <dt><tt>llvm/lib/CWriter/</tt><dd> This directory implements the LLVM to C
778 converter.
779
780 <dt><tt>llvm/lib/Analysis/</tt><dd> This directory contains a variety of
781 different program analyses, such as Dominator Information, Call Graphs,
782 Induction Variables, Interval Identification, Natural Loop Identification,
783 etc...
784
785 <dt><tt>llvm/lib/Transforms/</tt><dd> This directory contains the source
786 code for the LLVM to LLVM program transformations, such as Aggressive Dead
787 Code Elimination, Sparse Conditional Constant Propagation, Inlining, Loop
John Criswell0c4dccc2003-08-08 22:46:30 +0000788 Invarient Code Motion, Dead Global Elimination, and many others...
John Criswell85ed3612003-06-12 19:34:44 +0000789
790 <dt><tt>llvm/lib/Target/</tt><dd> This directory contains files that
791 describe various target architectures for code generation. For example,
792 the llvm/lib/Target/Sparc directory holds the Sparc machine
793 description.<br>
794
795 <dt><tt>llvm/lib/CodeGen/</tt><dd> This directory contains the major parts
796 of the code generator: Instruction Selector, Instruction Scheduling, and
797 Register Allocation.
798
John Criswell85ed3612003-06-12 19:34:44 +0000799 <dt><tt>llvm/lib/Support/</tt><dd> This directory contains the source code
800 that corresponds to the header files located in
801 <tt>llvm/include/Support/</tt>.
802 </dl>
803
804 <!------------------------------------------------------------------------->
John Criswell20d2d3e2003-10-10 14:26:14 +0000805 <h3><a name="runtime"><tt>llvm/runtime</tt></a></h3>
806 <!------------------------------------------------------------------------->
807
808 <p>
809 This directory contains libraries which are compiled into LLVM bytecode and
810 used when linking programs with the GCC front end. Most of these libraries
811 are skeleton versions of real libraries; for example, libc is a stripped down
812 version of glibc.
813 </p>
814
815 <p>
816 Unlike the rest of the LLVM suite, this directory needs the LLVM GCC front end
817 to compile.
818 </p>
819
820 <!------------------------------------------------------------------------->
John Criswell85ed3612003-06-12 19:34:44 +0000821 <h3><a name="test"><tt>llvm/test</tt></a></h3>
822 <!------------------------------------------------------------------------->
823
824 <p>This directory contains regression tests and source code that is used to
John Criswell20d2d3e2003-10-10 14:26:14 +0000825 test the LLVM infrastructure.
826 </p>
John Criswell85ed3612003-06-12 19:34:44 +0000827
828 <!------------------------------------------------------------------------->
829 <h3><a name="tools"><tt>llvm/tools</tt></a></h3>
830 <!------------------------------------------------------------------------->
831
832 <p>The <b>tools</b> directory contains the executables built out of the
833 libraries above, which form the main part of the user interface. You can
834 always get help for a tool by typing <tt>tool_name --help</tt>. The
835 following is a brief introduction to the most important tools.</p>
836
837 <dl compact>
Misha Brukmanef0ad412003-10-06 19:23:34 +0000838 <dt>
839
840 <dt><tt><b>analyze</b></tt><dd> <tt>analyze</tt> is used to run a specific
841 analysis on an input LLVM bytecode file and print out the results. It is
842 primarily useful for debugging analyses, or familiarizing yourself with
843 what an analysis does.<p>
844
845 <dt><tt><b>bugpoint</b></tt><dd> <tt>bugpoint</tt> is used to debug
846 optimization passes or code generation backends by narrowing down the
847 given test case to the minimum number of passes and/or instructions that
848 still cause a problem, whether it is a crash or miscompilation. See <a
849 href="HowToSubmitABug.html">HowToSubmitABug.html</a> for more information
850 on using <tt>bugpoint</tt>.<p>
851
852 <dt><tt><b>llvm-ar</b></tt><dd>The archiver produces an archive containing
853 the given LLVM bytecode files, optionally with an index for faster
854 lookup.<p>
855
Misha Brukmana0a0a032003-08-28 22:02:50 +0000856 <dt><tt><b>llvm-as</b></tt><dd>The assembler transforms the human readable
John Criswell85ed3612003-06-12 19:34:44 +0000857 LLVM assembly to LLVM bytecode.<p>
858
Misha Brukmana0a0a032003-08-28 22:02:50 +0000859 <dt><tt><b>llvm-dis</b></tt><dd>The disassembler transforms the LLVM
Misha Brukmanef0ad412003-10-06 19:23:34 +0000860 bytecode to human readable LLVM assembly. Additionally, it can convert
Misha Brukmana0a0a032003-08-28 22:02:50 +0000861 LLVM bytecode to C, which is enabled with the <tt>-c</tt> option.<p>
John Criswell85ed3612003-06-12 19:34:44 +0000862
Misha Brukmanef0ad412003-10-06 19:23:34 +0000863 <dt><tt><b>llvm-link</b></tt><dd> <tt>llvm-link</tt>, not surprisingly,
864 links multiple LLVM modules into a single program.<p>
865
John Criswell85ed3612003-06-12 19:34:44 +0000866 <dt><tt><b>lli</b></tt><dd> <tt>lli</tt> is the LLVM interpreter, which
867 can directly execute LLVM bytecode (although very slowly...). In addition
Misha Brukmanef0ad412003-10-06 19:23:34 +0000868 to a simple interpreter, <tt>lli</tt> also has a tracing mode (entered by
869 specifying <tt>-trace</tt> on the command line). Finally, for
870 architectures that support it (currently only x86 and Sparc), by default,
871 <tt>lli</tt> will function as a Just-In-Time compiler (if the
872 functionality was compiled in), and will execute the code <i>much</i>
873 faster than the interpreter.<p>
John Criswell85ed3612003-06-12 19:34:44 +0000874
875 <dt><tt><b>llc</b></tt><dd> <tt>llc</tt> is the LLVM backend compiler,
Misha Brukmanc56e5822003-07-03 16:29:36 +0000876 which translates LLVM bytecode to a SPARC or x86 assembly file.<p>
John Criswell85ed3612003-06-12 19:34:44 +0000877
Misha Brukmanef0ad412003-10-06 19:23:34 +0000878 <dt><tt><b>llvmgcc</b></tt><dd> <tt>llvmgcc</tt> is a GCC-based C frontend
John Criswell85ed3612003-06-12 19:34:44 +0000879 that has been retargeted to emit LLVM code as the machine code output. It
880 works just like any other GCC compiler, taking the typical <tt>-c, -S, -E,
881 -o</tt> options that are typically used. The source code for the
882 <tt>llvmgcc</tt> tool is currently not included in the LLVM cvs tree
883 because it is quite large and not very interesting.<p>
884
885 <ol>
886 <dt><tt><b>gccas</b></tt><dd> This tool is invoked by the
887 <tt>llvmgcc</tt> frontend as the "assembler" part of the compiler. This
888 tool actually assembles LLVM assembly to LLVM bytecode,
Misha Brukmanef0ad412003-10-06 19:23:34 +0000889 performs a variety of optimizations, and outputs LLVM bytecode. Thus
890 when you invoke <tt>llvmgcc -c x.c -o x.o</tt>, you are causing
891 <tt>gccas</tt> to be run, which writes the <tt>x.o</tt> file (which is
892 an LLVM bytecode file that can be disassembled or manipulated just like
893 any other bytecode file). The command line interface to <tt>gccas</tt>
894 is designed to be as close as possible to the <b>system</b>
895 `<tt>as</tt>' utility so that the gcc frontend itself did not have to be
896 modified to interface to a "weird" assembler.<p>
John Criswell85ed3612003-06-12 19:34:44 +0000897
898 <dt><tt><b>gccld</b></tt><dd> <tt>gccld</tt> links together several LLVM
899 bytecode files into one bytecode file and does some optimization. It is
900 the linker invoked by the gcc frontend when multiple .o files need to be
901 linked together. Like <tt>gccas</tt> the command line interface of
902 <tt>gccld</tt> is designed to match the system linker, to aid
903 interfacing with the GCC frontend.<p>
904 </ol>
905
906 <dt><tt><b>opt</b></tt><dd> <tt>opt</tt> reads LLVM bytecode, applies a
907 series of LLVM to LLVM transformations (which are specified on the command
908 line), and then outputs the resultant bytecode. The '<tt>opt --help</tt>'
909 command is a good way to get a list of the program transformations
910 available in LLVM.<p>
911
John Criswell85ed3612003-06-12 19:34:44 +0000912 </dl>
John Criswell0b459202003-07-08 20:35:59 +0000913
Misha Brukmanc103adf2003-08-11 18:45:46 +0000914 <!------------------------------------------------------------------------->
915 <h3><a name="utils"><tt>llvm/utils</tt></a></h3>
916 <!------------------------------------------------------------------------->
917
918 This directory contains utilities for working with LLVM sourcecode, and some
919 of the utilities are actually required as part of the build process because
920 they are code generators for parts of LLVM infrastructure.
921
922 <dl compact>
Misha Brukmane0db8152003-08-11 19:13:12 +0000923 <td><tt><b>Burg/</b></tt><dd> <tt>Burg</tt> is an instruction selector
Misha Brukmanc103adf2003-08-11 18:45:46 +0000924 generator -- it builds trees on which it then performs pattern-matching to
925 select instructions according to the patterns the user has specified. Burg
926 is currently used in the Sparc V9 backend.<p>
927
928 <dt><tt><b>codegen-diff</b></tt><dd> <tt>codegen-diff</tt> is a script
929 that finds differences between code that LLC generates and code that LLI
930 generates. This is a useful tool if you are debugging one of them,
931 assuming that the other generates correct output. For the full user
932 manual, run <tt>`perldoc codegen-diff'</tt>.<p>
933
934 <dt><tt><b>cvsupdate</b></tt><dd> <tt>cvsupdate</tt> is a script that will
935 update your CVS tree, but produce a much cleaner and more organized output
936 than simply running <tt>`cvs up -dP'</tt> will. For example, it will group
937 together all the new and updated files and modified files in separate
938 sections, so you can see at a glance what has changed. If you are at the
939 top of your LLVM CVS tree, running <tt>utils/cvsupdate</tt> is the
940 preferred way of updating the tree.<p>
941
Misha Brukmane0db8152003-08-11 19:13:12 +0000942 <dt><tt><b>emacs/</b></tt><dd> The <tt>emacs</tt> directory contains
Misha Brukmanc103adf2003-08-11 18:45:46 +0000943 syntax-highlighting files which will work with Emacs and XEmacs editors,
944 providing syntax highlighting support for LLVM assembly files and TableGen
Misha Brukmane0db8152003-08-11 19:13:12 +0000945 description files. For information on how to use the syntax files, consult
946 the <tt>README</tt> file in that directory.<p>
Misha Brukmanc103adf2003-08-11 18:45:46 +0000947
948 <dt><tt><b>getsrcs.sh</b></tt><dd> The <tt>getsrcs.sh</tt> script finds
949 and outputs all non-generated source files, which is useful if one wishes
950 to do a lot of development across directories and does not want to
951 individually find each file. One way to use it is to run, for example:
952 <tt>xemacs `utils/getsources.sh`</tt> from the top of your LLVM source
953 tree.<p>
954
955 <dt><tt><b>makellvm</b></tt><dd> The <tt>makellvm</tt> script compiles all
956 files in the current directory and then compiles and links the tool that
957 is the first argument. For example, assuming you are in the directory
958 <tt>llvm/lib/Target/Sparc</tt>, if <tt>makellvm</tt> is in your path,
959 simply running <tt>makellvm llc</tt> will make a build of the current
960 directory, switch to directory <tt>llvm/tools/llc</tt> and build it,
961 causing a re-linking of LLC.<p>
962
963 <dt><tt><b>NightlyTest.pl</b></tt> and
964 <tt><b>NightlyTestTemplate.html</b></tt><dd> These files are used in a
965 cron script to generate nightly status reports of the functionality of
966 tools, and the results can be seen by following the appropriate link on
967 the <a href="http://llvm.cs.uiuc.edu/">LLVM homepage</a>.<p>
968
Misha Brukmane0db8152003-08-11 19:13:12 +0000969 <dt><tt><b>TableGen/</b></tt><dd> The <tt>TableGen</tt> directory contains
Misha Brukmanc103adf2003-08-11 18:45:46 +0000970 the tool used to generate register descriptions, instruction set
Chris Lattnera8f5de32003-08-11 18:53:14 +0000971 descriptions, and even assemblers from common TableGen description
Misha Brukmanc103adf2003-08-11 18:45:46 +0000972 files.<p>
973
Misha Brukmane0db8152003-08-11 19:13:12 +0000974 <dt><tt><b>vim/</b></tt><dd> The <tt>vim</tt> directory contains
Misha Brukmanc103adf2003-08-11 18:45:46 +0000975 syntax-highlighting files which will work with the VIM editor, providing
976 syntax highlighting support for LLVM assembly files and TableGen
Misha Brukmane0db8152003-08-11 19:13:12 +0000977 description files. For information on how to use the syntax files, consult
978 the <tt>README</tt> file in that directory.<p>
Misha Brukmanc103adf2003-08-11 18:45:46 +0000979
980 </dl>
981
John Criswell85ed3612003-06-12 19:34:44 +0000982 <!--=====================================================================-->
John Criswell20d2d3e2003-10-10 14:26:14 +0000983 <h2><center><a name="cfront">Compiling the LLVM GCC Front End</center></h2>
984 <hr>
John Criswell0b459202003-07-08 20:35:59 +0000985 <!--=====================================================================-->
986
987 <p>
988 <b>
John Criswell20d2d3e2003-10-10 14:26:14 +0000989 This step is optional if you have the GCC front end binary distribution for
John Criswell0b459202003-07-08 20:35:59 +0000990 your platform.
991 </b>
992 </p>
993
John Criswell20d2d3e2003-10-10 14:26:14 +0000994 Now that you have the LLVM suite built, you can build the GCC front end. For
John Criswell0b459202003-07-08 20:35:59 +0000995 those of you that have built GCC before, the process is very similar.
996 <p>
John Criswell20d2d3e2003-10-10 14:26:14 +0000997 Be forewarned, though: the build system for the GCC front end is not as
John Criswell0b459202003-07-08 20:35:59 +0000998 polished as the rest of the LLVM code, so there will be many warnings and
999 errors that you will need to ignore for now:
1000
1001 <ol>
1002 <li>Ensure that <tt><i>OBJ_ROOT</i>/llvm/tools/Debug</tt> is at the
1003 <i>end</i> of your <tt>PATH</tt> environment variable. The front end
1004 build needs to know where to find the LLVM tools, but you want to
1005 ensure that these tools are not found before the system assembler and
1006 linker that you normally use for compilation.
1007
1008 <li><tt>cd <i>GCCOBJ</i></tt>
1009
1010 <li>Configure the source code:
1011 <ul>
1012 <li>On Linux/x86, use
1013 <ul>
1014 <li><tt><i>GCCSRC</i>/configure --prefix=<i>LLVMGCCDIR</i>
1015 --enable-languages=c</tt>
1016 </ul>
1017
1018 <li>On Solaris/Sparc, use
1019 <ul>
1020 <li><tt><i>GCCSRC</i>/configure --prefix=<i>LLVMGCCDIR</i>
1021 --enable-languages=c --target=sparcv9-sun-solaris2</tt>
1022 </ul>
1023 </ul>
1024
1025 <li><tt>gmake</tt>
1026
1027 <li>The build will eventually fail. Don't worry; chances are good that
1028 everything that needed to build is built.
1029
1030 <li><tt>gmake -k install</tt>
1031 </ol>
1032
1033 <p>
1034 Once this is done, you should have a built front end compiler in
1035 <tt><i>LLVMGCCDIR</i></tt>.
1036 </p>
1037
1038 <!--=====================================================================-->
1039 <h2>
1040 <center><a name="tutorial">An Example Using the LLVM Tool Chain</center>
1041 </h2>
John Criswell20d2d3e2003-10-10 14:26:14 +00001042 <hr>
John Criswell85ed3612003-06-12 19:34:44 +00001043 <!--=====================================================================-->
1044
1045 <ol>
1046 <li>First, create a simple C file, name it 'hello.c':
1047 <pre>
1048 #include &lt;stdio.h&gt;
1049 int main() {
1050 printf("hello world\n");
1051 return 0;
1052 }
1053 </pre>
1054
1055 <li>Next, compile the C file into a LLVM bytecode file:<p>
1056
1057 <tt>% llvmgcc hello.c -o hello</tt><p>
1058
1059 This will create two result files: <tt>hello</tt> and
1060 <tt>hello.bc</tt>. The <tt>hello.bc</tt> is the LLVM bytecode that
1061 corresponds the the compiled program and the library facilities that it
1062 required. <tt>hello</tt> is a simple shell script that runs the bytecode
1063 file with <tt>lli</tt>, making the result directly executable.<p>
1064
1065 <li>Run the program. To make sure the program ran, execute one of the
1066 following commands:<p>
John Criswell8df90e02003-06-11 20:46:40 +00001067
John Criswell85ed3612003-06-12 19:34:44 +00001068 <tt>% ./hello</tt><p>
1069
1070 or<p>
1071
1072 <tt>% lli hello.bc</tt><p>
1073
Misha Brukmana0a0a032003-08-28 22:02:50 +00001074 <li>Use the <tt>llvm-dis</tt> utility to take a look at the LLVM assembly
John Criswell85ed3612003-06-12 19:34:44 +00001075 code:<p>
1076
Misha Brukmana0a0a032003-08-28 22:02:50 +00001077 <tt>% llvm-dis < hello.bc | less</tt><p>
John Criswell85ed3612003-06-12 19:34:44 +00001078
1079 <li>Compile the program to native Sparc assembly using the code
Misha Brukmanc56e5822003-07-03 16:29:36 +00001080 generator (assuming you are currently on a Sparc system):<p>
John Criswell85ed3612003-06-12 19:34:44 +00001081
1082 <tt>% llc hello.bc -o hello.s</tt><p>
1083
1084 <li>Assemble the native sparc assemble file into a program:<p>
1085
1086 <tt>% /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.sparc</tt><p>
1087
1088 <li>Execute the native sparc program:<p>
1089
1090 <tt>% ./hello.sparc</tt><p>
1091
1092 </ol>
1093
1094
1095 <!--=====================================================================-->
John Criswell0b459202003-07-08 20:35:59 +00001096 <h2>
1097 <center><a name="problems">Common Problems</a></center>
1098 </h2>
John Criswell20d2d3e2003-10-10 14:26:14 +00001099 <hr>
John Criswellce760f62003-07-03 16:01:38 +00001100 <!--=====================================================================-->
1101
1102 Below are common problems and their remedies:
1103
1104 <dl compact>
1105 <dt><b>When I run configure, it finds the wrong C compiler.</b>
1106 <dd>
1107 The <tt>configure</tt> script attempts to locate first <tt>gcc</tt> and
1108 then <tt>cc</tt>, unless it finds compiler paths set in <tt>CC</tt> and
1109 <tt>CXX</tt> for the C and C++ compiler, respectively.
1110
1111 If <tt>configure</tt> finds the wrong compiler, either adjust your
1112 <tt>PATH</tt> environment variable or set <tt>CC</tt> and <tt>CXX</tt>
1113 explicitly.
1114 <p>
1115
1116 <dt><b>I compile the code, and I get some error about /localhome</b>.
1117 <dd>
1118 There are several possible causes for this. The first is that you
1119 didn't set a pathname properly when using <tt>configure</tt>, and it
1120 defaulted to a pathname that we use on our research machines.
1121 <p>
1122 Another possibility is that we hardcoded a path in our Makefiles. If
1123 you see this, please email the LLVM bug mailing list with the name of
1124 the offending Makefile and a description of what is wrong with it.
1125
1126 <dt><b>The <tt>configure</tt> script finds the right C compiler, but it
1127 uses the LLVM linker from a previous build. What do I do?</b>
1128 <dd>
1129 The <tt>configure</tt> script uses the <tt>PATH</tt> to find
1130 executables, so if it's grabbing the wrong linker/assembler/etc, there
1131 are two ways to fix it:
1132 <ol>
1133 <li>Adjust your <tt>PATH</tt> environment variable so that the
1134 correct program appears first in the <tt>PATH</tt>. This may work,
1135 but may not be convenient when you want them <i>first</i> in your
1136 path for other work.
1137 <p>
1138
1139 <li>Run <tt>configure</tt> with an alternative <tt>PATH</tt> that
1140 is correct. In a Borne compatible shell, the syntax would be:
1141 <p>
1142 <tt>PATH=<the path without the bad program> ./configure ...</tt>
1143 <p>
1144 This is still somewhat inconvenient, but it allows
1145 <tt>configure</tt> to do its work without having to adjust your
1146 <tt>PATH</tt> permanently.
1147 </ol>
John Criswell3c852b62003-08-08 22:43:39 +00001148
1149 <dt><b>I've upgraded to a new version of LLVM, and I get strange build
1150 errors.</b>
1151 <dd>
1152 Sometimes changes to the LLVM source code alters how the build system
1153 works. Changes in libtool, autoconf, or header file dependencies are
1154 especially prone to this sort of problem.
1155 <p>
1156 The best thing to try is to remove the old files and re-build. In most
1157 cases, this takes care of the problem. To do this, just type <tt>make
1158 clean</tt> and then <tt>make</tt> in the directory that fails to build.
1159 <p>
1160
John Criswellce760f62003-07-03 16:01:38 +00001161 </dl>
1162
1163 <!--=====================================================================-->
John Criswell0b459202003-07-08 20:35:59 +00001164 <h2><center><a name="links">Links</a></center></h2>
John Criswell20d2d3e2003-10-10 14:26:14 +00001165 <hr>
John Criswell85ed3612003-06-12 19:34:44 +00001166 <!--=====================================================================-->
1167
1168 <p>This document is just an <b>introduction</b> to how to use LLVM to do
1169 some simple things... there are many more interesting and complicated things
1170 that you can do that aren't documented here (but we'll gladly accept a patch
1171 if you want to write something up!). For more information about LLVM, check
1172 out:</p>
1173
1174 <ul>
1175 <li><a href="http://llvm.cs.uiuc.edu/">LLVM homepage</a></li>
1176 <li><a href="http://llvm.cs.uiuc.edu/doxygen/">LLVM doxygen tree</a></li>
John Criswellce760f62003-07-03 16:01:38 +00001177 <li><a href="http://llvm.cs.uiuc.edu/docs/Projects.html">Starting a Project that Uses LLVM</a></li>
John Criswell85ed3612003-06-12 19:34:44 +00001178 </ul>
1179
1180 <hr>
1181
1182 If you have any questions or run into any snags (or you have any
1183 additions...), please send an email to
1184 <a href="mailto:sabre@nondot.org">Chris Lattner</a>.</p>
1185
1186 <!-- Created: Mon Jul 1 02:29:02 CDT 2002 -->
1187 <!-- hhmts start -->
Chris Lattnera8f5de32003-08-11 18:53:14 +00001188Last modified: Mon Aug 11 13:52:22 CDT 2003
John Criswell85ed3612003-06-12 19:34:44 +00001189<!-- hhmts end -->
1190 </body>
Guochun Shif4688a82002-07-17 23:05:56 +00001191</html>