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