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> |
| 3 | <head> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 4 | <title>Getting Started with LLVM System</title> |
Guochun Shi | f4688a8 | 2002-07-17 23:05:56 +0000 | [diff] [blame] | 5 | </head> |
| 6 | |
Chris Lattner | 945de2d | 2002-07-24 19:59:33 +0000 | [diff] [blame] | 7 | <body bgcolor=white> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 8 | <center><h1>Getting Started with the LLVM System<br><font size=3>By: <a |
| 9 | href="mailto:gshi1@uiuc.edu">Guochun Shi</a>, |
| 10 | <a href="mailto:sabre@nondot.org">Chris Lattner</a> and |
| 11 | <a href="http://www.cs.uiuc.edu/~vadve">Vikram Adve</a> |
| 12 | </font></h1></center> |
| 13 | |
| 14 | <!--=====================================================================--> |
| 15 | <h2><a name="Contents">Contents</a></h2> |
| 16 | <!--=====================================================================--> |
Chris Lattner | 945de2d | 2002-07-24 19:59:33 +0000 | [diff] [blame] | 17 | |
Guochun Shi | f4688a8 | 2002-07-17 23:05:56 +0000 | [diff] [blame] | 18 | <ul> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 19 | <li><a href="#overview">Overview</a> |
| 20 | <li><a href="#starting">Getting started with LLVM</a> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 21 | <ol> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 22 | <li><a href="#quickstart">Getting started quickly (a summary)</a> |
| 23 | <li><a href="#checkout">Checkout LLVM from CVS</a> |
| 24 | <li><a href="#terminology">Terminology and Notation</tt></a> |
| 25 | <li><a href="#objfiles">The location for object files</tt></a> |
| 26 | <li><a href="#config">Local Configuration Options</tt></a> |
| 27 | <li><a href="#environment">Setting up your environment</a> |
| 28 | <li><a href="#compile">Compiling the source code</a> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 29 | </ol> |
Guochun Shi | f4688a8 | 2002-07-17 23:05:56 +0000 | [diff] [blame] | 30 | <li><a href="#layout">Program layout</a> |
| 31 | <ol> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 32 | <li><a href="#cvsdir">CVS directories</a> |
Chris Lattner | 44ac659 | 2002-08-09 16:14:56 +0000 | [diff] [blame] | 33 | <li><a href="#dd"><tt>Depend</tt>, <tt>Debug</tt>, & |
| 34 | <tt>Release</tt> directories</a></li> |
| 35 | <li><a href="#include"><tt>llvm/include</tt></a> |
| 36 | <li><a href="#lib"><tt>llvm/lib</tt></a> |
| 37 | <li><a href="#test"><tt>llvm/test</tt></a> |
| 38 | <li><a href="#tools"><tt>llvm/tools</tt></a> |
Guochun Shi | f4688a8 | 2002-07-17 23:05:56 +0000 | [diff] [blame] | 39 | </ol> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 40 | <li><a href="#tutorial">An example using the LLVM tool chain</a> |
Guochun Shi | f4688a8 | 2002-07-17 23:05:56 +0000 | [diff] [blame] | 41 | <li><a href="#links">Links</a> |
| 42 | </ul> |
Guochun Shi | f4688a8 | 2002-07-17 23:05:56 +0000 | [diff] [blame] | 43 | |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 44 | |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 45 | <!--=====================================================================--> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 46 | <center> |
| 47 | <h2><a name="overview"><b>Overview</b></a></h2> |
| 48 | </center> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 49 | <!--=====================================================================--> |
| 50 | |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 51 | <p>The <a href"starting">next section</a> of this guide is meant to get |
| 52 | you up and running with LLVM, and to give you some basic information about |
| 53 | the LLVM environment. The <a href"#quickstart">first subsection</a> gives |
| 54 | a short summary for those who are already familiar with the system and |
| 55 | want to get started as quickly as possible. |
| 56 | |
| 57 | <p>The later sections of this guide describe the <a |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 58 | href"#layout">general layout</a> of the the LLVM source-tree, a <a |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 59 | href="#tutorial">simple example</a> using the LLVM tool chain, and <a |
| 60 | href="#links">links</a> to find more information about LLVM or to get |
| 61 | help via e-mail. |
| 62 | |
| 63 | <!--=====================================================================--> |
| 64 | <center> |
| 65 | <h2><a name="starting"><b>Getting Started</b></a></h2> |
| 66 | </center> |
| 67 | <!--=====================================================================--> |
| 68 | |
| 69 | |
| 70 | <!--=====================================================================--> |
| 71 | <h3><a name="quickstart"><b>Getting Started Quickly (A Summary)</b></a></h3> |
| 72 | <!--=====================================================================--> |
| 73 | |
| 74 | Here's the short story for getting up and running quickly with LLVM: |
Chris Lattner | 96768ea | 2003-02-14 04:22:13 +0000 | [diff] [blame] | 75 | <ol> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 76 | <li>Find the path to the CVS repository containing LLVM (we'll call this <i>CVSROOTDIR</i>). |
| 77 | <li><tt>cd <i>where-you-want-llvm-to-live</i></tt> |
| 78 | <li><tt>cvs -d <i>CVSROOTDIR</i> checkout llvm</tt> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 79 | <li><tt>cd llvm</tt> |
Chris Lattner | 96768ea | 2003-02-14 04:22:13 +0000 | [diff] [blame] | 80 | <li>Edit <tt>Makefile.config</tt> to set local paths. This includes |
| 81 | setting the install location of the C frontend, and the various paths |
| 82 | to the C and C++ compilers used to build LLVM itself. |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 83 | <li><tt>gmake -k |& tee gnumake.out |
| 84 | # this is csh or tcsh syntax</tt> |
Chris Lattner | 96768ea | 2003-02-14 04:22:13 +0000 | [diff] [blame] | 85 | </ol> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 86 | |
| 87 | <p>See <a href="#environment">Setting up your environment</a> on tips to |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 88 | simplify working with the LLVM front-end and compiled tools. See the |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 89 | other sub-sections below for other useful details in working with LLVM, |
| 90 | or go straight to <a href="#layout">Program Layout</a> to learn about the |
| 91 | layout of the source code tree. |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 92 | |
| 93 | <!-------------------------------------------------------------------------> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 94 | <h3><a name="terminology">Terminology and Notation</a></h3> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 95 | <!-------------------------------------------------------------------------> |
| 96 | |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 97 | <p>Through this manual, the following names are used to denote paths |
| 98 | specific to the local system and working environment. <i>These are not |
| 99 | environment variables you need to set, but just strings used in the rest |
| 100 | of this document below.</i>. In any of the examples below, simply replace |
| 101 | each of these names with the appropriate pathname on your local system. |
| 102 | All these paths are absolute:</p> |
| 103 | <ul> |
| 104 | </ul> |
Chris Lattner | cefbd32 | 2002-08-13 21:10:30 +0000 | [diff] [blame] | 105 | |
| 106 | <!-------------------------------------------------------------------------> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 107 | <h3><a name="checkout">Checkout LLVM from CVS</a></h3> |
Chris Lattner | cefbd32 | 2002-08-13 21:10:30 +0000 | [diff] [blame] | 108 | <!-------------------------------------------------------------------------> |
| 109 | |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 110 | <p>Before checking out the source code, you will need to know the path to |
| 111 | CVS repository containing LLVM source code (we'll call this |
| 112 | <i>CVSROOTDIR</i> below). Ask the person responsible for your local LLVM |
| 113 | installation to give you this path. |
Chris Lattner | cefbd32 | 2002-08-13 21:10:30 +0000 | [diff] [blame] | 114 | |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 115 | <p>To get a fresh copy of the entire source code, all you |
| 116 | need to do is check it out from CVS as follows: |
| 117 | <ul> |
| 118 | <li><tt>cd <i>where-you-want-llvm-to-live</i></tt> |
| 119 | <li><tt>cvs -d <i>CVSROOTDIR</i> checkout llvm</tt></p> |
| 120 | </ul> |
| 121 | |
| 122 | <p>This will create an '<tt>llvm</tt>' directory in the current |
| 123 | directory and fully populate it with the LLVM source code, Makefiles, |
| 124 | test directories, and local copies of documentation files.</p> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 125 | |
| 126 | <!-------------------------------------------------------------------------> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 127 | <h3><a name="config">Local Configuration Options</a></h3> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 128 | <!-------------------------------------------------------------------------> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 129 | |
| 130 | <p>The file <tt>llvm/Makefile.config</tt> |
| 131 | defines the following path variables, |
| 132 | which are specific to a particular installation of LLVM. |
| 133 | These should need to be modified only once after checking out a copy |
| 134 | of LLVM (if the default values do not already match your system): |
| 135 | |
| 136 | <ul> |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 137 | <p><li><i>CXX</i> = Path to C++ compiler to use. |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 138 | <p><li><i>LLVM_OBJ_DIR</i> = Path to the llvm directory where |
| 139 | object files should be placed. |
| 140 | (See the Section on <a href=#objfiles> |
| 141 | The location for LLVM object files</a> |
| 142 | for more information.) |
| 143 | <p><li><i>LLVMGCCDIR</i> = Path to the location of the LLVM front-end |
| 144 | binaries and associated libraries. |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 145 | <p><li><i>PURIFY</i> = Path to the purify program. |
| 146 | </ul> |
| 147 | |
| 148 | <!-------------------------------------------------------------------------> |
| 149 | <h3><a name="objfiles">The location for LLVM object files</a></h3> |
| 150 | <!-------------------------------------------------------------------------> |
| 151 | |
| 152 | <p>The LLVM make system sends most output files generated during the build |
| 153 | into the directory defined by the variable LLVM_OBJ_DIR in |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 154 | <tt>llvm/Makefile.config</tt>. This can be either just your normal LLVM |
| 155 | source tree or some other directory writable by you. You may wish to put |
| 156 | object files on a different filesystem either to keep them from being backed |
| 157 | up or to speed up local builds. |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 158 | |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 159 | <p>If you do not wish to use a different location for object files (building |
| 160 | into the source tree directly), just set this variable to ".".<p> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 161 | |
| 162 | <!-------------------------------------------------------------------------> |
| 163 | <h3><a name="environment">Setting up your environment</a></h3> |
| 164 | <!-------------------------------------------------------------------------> |
| 165 | |
| 166 | <i>NOTE: This step is optional but will set up your environment so you |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 167 | can use the compiled LLVM tools with as little hassle as |
| 168 | possible.</i>) |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 169 | |
| 170 | <p>Add the following lines to your <tt>.cshrc</tt> (or the corresponding |
| 171 | lines to your <tt>.profile</tt> if you use a bourne shell derivative). |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 172 | |
| 173 | <pre> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 174 | # Make the C front end easy to use... |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 175 | alias llvmgcc <i>LLVMGCCDIR</i><tt>/bin/llvm-gcc</tt> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 176 | |
| 177 | # Make the LLVM tools easy to use... |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 178 | setenv PATH <i>LLVM_OBJ_DIR</i>/tools/Debug:${PATH} |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 179 | </pre> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 180 | The <tt>llvmgcc</tt> alias is useful because the C compiler is not |
| 181 | included in the CVS tree you just checked out. |
| 182 | |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 183 | <p>The other <a href="#tools">LLVM tools</a> are part of the LLVM |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 184 | source base, and built when compiling LLVM. They will be built into the |
| 185 | <tt><i>LLVM_OBJ_DIR</i>/tools/Debug</tt> directory.</p> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 186 | |
| 187 | <!-------------------------------------------------------------------------> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 188 | <h3><a name="compile">Compiling the source code</a></h3> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 189 | <!-------------------------------------------------------------------------> |
| 190 | |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 191 | <p>Every directory in the LLVM source tree includes a <tt>Makefile</tt> to |
| 192 | build it, and any subdirectories that it contains. These makefiles require |
| 193 | that you use <tt>gmake</tt>, instead of <tt>make</tt> to build them, but can |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 194 | otherwise be used freely. To build the entire LLVM system, just enter the |
| 195 | top level <tt>llvm</tt> directory and type <tt>gmake</tt>. A few minutes |
| 196 | later you will hopefully have a freshly compiled toolchain waiting for you |
| 197 | in <tt>llvm/tools/Debug</tt>. If you want to look at the libraries that |
| 198 | were compiled, look in <tt>llvm/lib/Debug</tt>.</p> |
| 199 | |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 200 | If you get an error talking about a <tt>/localhome</tt> directory, follow |
| 201 | the instructions in the section about <a href="#environment">Setting Up Your |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 202 | Environment.</a> |
Chris Lattner | cefbd32 | 2002-08-13 21:10:30 +0000 | [diff] [blame] | 203 | |
Chris Lattner | 44ac659 | 2002-08-09 16:14:56 +0000 | [diff] [blame] | 204 | |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 205 | |
| 206 | <!--=====================================================================--> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 207 | <center> |
| 208 | <h2><a name="layout"><b>Program Layout</b></a></h2> |
| 209 | </center> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 210 | <!--=====================================================================--> |
| 211 | |
Chris Lattner | 44ac659 | 2002-08-09 16:14:56 +0000 | [diff] [blame] | 212 | <p>One useful source of infomation about the LLVM sourcebase is the LLVM <a |
| 213 | href="http://www.doxygen.org">doxygen</a> documentation, available at <tt><a |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 214 | href="http://llvm.cs.uiuc.edu/doxygen/">http://llvm.cs.uiuc.edu/doxygen/</a></tt>. The |
| 215 | following is a brief introduction to code layout:</p> |
| 216 | |
| 217 | |
| 218 | <!-------------------------------------------------------------------------> |
Chris Lattner | 44ac659 | 2002-08-09 16:14:56 +0000 | [diff] [blame] | 219 | <h3><a name="cvsdir"><tt>CVS</tt> directories</a></h3> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 220 | <!-------------------------------------------------------------------------> |
| 221 | |
Chris Lattner | 44ac659 | 2002-08-09 16:14:56 +0000 | [diff] [blame] | 222 | Every directory checked out of CVS will contain a <tt>CVS</tt> directory, |
| 223 | for the most part these can just be ignored. |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 224 | |
| 225 | |
| 226 | <!-------------------------------------------------------------------------> |
Chris Lattner | 44ac659 | 2002-08-09 16:14:56 +0000 | [diff] [blame] | 227 | <h3><a name="ddr"><tt>Depend</tt>, <tt>Debug</tt>, & <tt>Release</tt> |
| 228 | directories</a></h3> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 229 | <!-------------------------------------------------------------------------> |
| 230 | |
Chris Lattner | 44ac659 | 2002-08-09 16:14:56 +0000 | [diff] [blame] | 231 | If you are building with the "<tt>BUILD_ROOT=.</tt>" option enabled in the |
| 232 | <tt>Makefile.common</tt> file, most source directories will contain two |
| 233 | directories, <tt>Depend</tt> and <tt>Debug</tt>. The <tt>Depend</tt> |
| 234 | directory contains automatically generated dependance files which are used |
| 235 | during compilation to make sure that source files get rebuilt if a header |
| 236 | file they use is modified. The <tt>Debug</tt> directory holds the object |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 237 | files, library files and executables that are used for building a debug |
Chris Lattner | 44ac659 | 2002-08-09 16:14:56 +0000 | [diff] [blame] | 238 | enabled build. The <tt>Release</tt> directory is created to hold the same |
| 239 | files when the <tt>ENABLE_OPTIMIZED=1</tt> flag is passed to <tt>gmake</tt>, |
| 240 | causing an optimized built to be performed.<p> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 241 | |
| 242 | |
| 243 | <!-------------------------------------------------------------------------> |
Chris Lattner | 44ac659 | 2002-08-09 16:14:56 +0000 | [diff] [blame] | 244 | <h3><a name="include"><tt>llvm/include</tt></a></h3> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 245 | <!-------------------------------------------------------------------------> |
| 246 | |
| 247 | This directory contains public header files exported from the LLVM |
Chris Lattner | 44ac659 | 2002-08-09 16:14:56 +0000 | [diff] [blame] | 248 | library. The two main subdirectories of this directory are:<p> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 249 | |
| 250 | <ol> |
| 251 | <li><tt>llvm/include/llvm</tt> - This directory contains all of the LLVM |
| 252 | specific header files. This directory also has subdirectories for |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 253 | different portions of LLVM: <tt>Analysis</tt>, <tt>CodeGen</tt>, |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 254 | <tt>Reoptimizer</tt>, <tt>Target</tt>, <tt>Transforms</tt>, etc... |
| 255 | |
| 256 | <li><tt>llvm/include/Support</tt> - This directory contains generic |
| 257 | support libraries that are independant of LLVM, but are used by LLVM. |
| 258 | For example, some C++ STL utilities and a Command Line option processing |
| 259 | library. |
| 260 | </ol> |
| 261 | |
| 262 | <!-------------------------------------------------------------------------> |
Chris Lattner | 44ac659 | 2002-08-09 16:14:56 +0000 | [diff] [blame] | 263 | <h3><a name="lib"><tt>llvm/lib</tt></a></h3> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 264 | <!-------------------------------------------------------------------------> |
| 265 | |
| 266 | This directory contains most source files of LLVM system. In LLVM almost all |
| 267 | code exists in libraries, making it very easy to share code among the |
| 268 | different <a href="#tools">tools</a>.<p> |
| 269 | |
| 270 | <dl compact> |
| 271 | <dt><tt>llvm/lib/VMCore/</tt><dd> This directory holds the core LLVM |
| 272 | source files that implement core classes like Instruction and BasicBlock. |
| 273 | |
| 274 | <dt><tt>llvm/lib/AsmParser/</tt><dd> This directory holds the source code |
| 275 | for the LLVM assembly language parser library. |
| 276 | |
| 277 | <dt><tt>llvm/lib/ByteCode/</tt><dd> This directory holds code for reading |
| 278 | and write LLVM bytecode. |
| 279 | |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 280 | <dt><tt>llvm/lib/CWriter/</tt><dd> This directory implements the LLVM to C |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 281 | converter. |
| 282 | |
| 283 | <dt><tt>llvm/lib/Analysis/</tt><dd> This directory contains a variety of |
| 284 | different program analyses, such as Dominator Information, Call Graphs, |
| 285 | Induction Variables, Interval Identification, Natural Loop Identification, |
| 286 | etc... |
| 287 | |
| 288 | <dt><tt>llvm/lib/Transforms/</tt><dd> This directory contains the source |
| 289 | code for the LLVM to LLVM program transformations, such as Aggressive Dead |
| 290 | Code Elimination, Sparse Conditional Constant Propogation, Inlining, Loop |
| 291 | Invarient Code Motion, Dead Global Elimination, Pool Allocation, and many |
| 292 | others... |
| 293 | |
| 294 | <dt><tt>llvm/lib/Target/</tt><dd> This directory contains files that |
| 295 | describe various target architectures for code generation. For example, |
| 296 | the llvm/lib/Target/Sparc directory holds the Sparc machine |
| 297 | description.<br> |
| 298 | |
| 299 | <dt><tt>llvm/lib/CodeGen/</tt><dd> This directory contains the major parts |
| 300 | of the code generator: Instruction Selector, Instruction Scheduling, and |
| 301 | Register Allocation. |
| 302 | |
| 303 | <dt><tt>llvm/lib/Reoptimizer/</tt><dd> This directory holds code related |
| 304 | to the runtime reoptimizer framework that is currently under development. |
| 305 | |
| 306 | <dt><tt>llvm/lib/Support/</tt><dd> This directory contains the source code |
| 307 | that corresponds to the header files located in |
| 308 | <tt>llvm/include/Support/</tt>. |
| 309 | </dl> |
| 310 | |
| 311 | <!-------------------------------------------------------------------------> |
Chris Lattner | 44ac659 | 2002-08-09 16:14:56 +0000 | [diff] [blame] | 312 | <h3><a name="test"><tt>llvm/test</tt></a></h3> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 313 | <!-------------------------------------------------------------------------> |
| 314 | |
| 315 | <p>This directory contains regression tests and source code that is used to |
| 316 | test the LLVM infrastructure...</p> |
| 317 | |
| 318 | <!-------------------------------------------------------------------------> |
Chris Lattner | 44ac659 | 2002-08-09 16:14:56 +0000 | [diff] [blame] | 319 | <h3><a name="tools"><tt>llvm/tools</tt></a></h3> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 320 | <!-------------------------------------------------------------------------> |
| 321 | |
| 322 | <p>The <b>tools</b> directory contains the executables built out of the |
| 323 | libraries above, which form the main part of the user interface. You can |
| 324 | always get help for a tool by typing <tt>tool_name --help</tt>. The |
| 325 | following is a brief introduction to the most important tools.</p> |
| 326 | |
| 327 | <dl compact> |
| 328 | <dt><tt><b>as</b></tt><dd>The assembler transforms the human readable |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 329 | LLVM assembly to LLVM bytecode.<p> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 330 | |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 331 | <dt><tt><b>dis</b></tt><dd>The disassembler transforms the LLVM bytecode |
| 332 | to human readable LLVM assembly. Additionally it can convert LLVM |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 333 | bytecode to C, which is enabled with the <tt>-c</tt> option.<p> |
| 334 | |
| 335 | <dt><tt><b>lli</b></tt><dd> <tt>lli</tt> is the LLVM interpreter, which |
| 336 | can directly execute LLVM bytecode (although very slowly...). In addition |
| 337 | to a simple intepreter, <tt>lli</tt> is also has debugger and tracing |
| 338 | modes (entered by specifying <tt>-debug</tt> or <tt>-trace</tt> on the |
| 339 | command line, respectively).<p> |
| 340 | |
| 341 | <dt><tt><b>llc</b></tt><dd> <tt>llc</tt> is the LLVM backend compiler, |
| 342 | which translates LLVM bytecode to a SPARC assembly file.<p> |
| 343 | |
| 344 | <dt><tt><b>llvmgcc</b></tt><dd> <tt>llvmgcc</tt> is a GCC based C frontend |
| 345 | that has been retargeted to emit LLVM code as the machine code output. It |
| 346 | works just like any other GCC compiler, taking the typical <tt>-c, -S, -E, |
| 347 | -o</tt> options that are typically used. The source code for the |
| 348 | <tt>llvmgcc</tt> tool is currently not included in the LLVM cvs tree |
| 349 | because it is quite large and not very interesting.<p> |
| 350 | |
| 351 | <ol> |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 352 | <dt><tt><b>gccas</b></tt><dd> This tool is invoked by the |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 353 | <tt>llvmgcc</tt> frontend as the "assembler" part of the compiler. This |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 354 | tool actually assembles LLVM assembly to LLVM bytecode, |
| 355 | performs a variety of optimizations, |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 356 | and outputs LLVM bytecode. Thus when you invoke <tt>llvmgcc -c x.c -o |
| 357 | x.o</tt>, you are causing <tt>gccas</tt> to be run, which writes the |
| 358 | <tt>x.o</tt> file (which is an LLVM bytecode file that can be |
| 359 | disassembled or manipulated just like any other bytecode file). The |
| 360 | command line interface to <tt>gccas</tt> is designed to be as close as |
Chris Lattner | 96768ea | 2003-02-14 04:22:13 +0000 | [diff] [blame] | 361 | possible to the <b>system</b> '<tt>as</tt>' utility so that the gcc |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 362 | frontend itself did not have to be modified to interface to a "wierd" |
| 363 | assembler.<p> |
| 364 | |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 365 | <dt><tt><b>gccld</b></tt><dd> <tt>gccld</tt> links together several LLVM |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 366 | bytecode files into one bytecode file and does some optimization. It is |
| 367 | the linker invoked by the gcc frontend when multiple .o files need to be |
| 368 | linked together. Like <tt>gccas</tt> the command line interface of |
| 369 | <tt>gccld</tt> is designed to match the system linker, to aid |
| 370 | interfacing with the GCC frontend.<p> |
| 371 | </ol> |
| 372 | |
Chris Lattner | 4b2e291 | 2002-09-19 19:56:53 +0000 | [diff] [blame] | 373 | <dt><tt><b>opt</b></tt><dd> <tt>opt</tt> reads LLVM bytecode, applies a |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 374 | series of LLVM to LLVM transformations (which are specified on the command |
| 375 | line), and then outputs the resultant bytecode. The '<tt>opt --help</tt>' |
| 376 | command is a good way to get a list of the program transformations |
| 377 | available in LLVM.<p> |
| 378 | |
| 379 | |
| 380 | <dt><tt><b>analyze</b></tt><dd> <tt>analyze</tt> is used to run a specific |
| 381 | analysis on an input LLVM bytecode file and print out the results. It is |
| 382 | primarily useful for debugging analyses, or familiarizing yourself with |
| 383 | what an analysis does.<p> |
| 384 | |
| 385 | </dl> |
| 386 | |
| 387 | <!--=====================================================================--> |
| 388 | <h2><a name="tutorial">An example using the LLVM tool chain</h2> |
| 389 | <!--=====================================================================--> |
| 390 | |
| 391 | <ol> |
| 392 | <li>First, create a simple C file, name it 'hello.c': |
| 393 | <pre> |
| 394 | #include <stdio.h> |
| 395 | int main() { |
| 396 | printf("hello world\n"); |
| 397 | return 0; |
| 398 | } |
| 399 | </pre> |
| 400 | |
| 401 | <li>Next, compile the C file into a LLVM bytecode file:<p> |
| 402 | |
| 403 | <tt>% llvmgcc hello.c -o hello</tt><p> |
| 404 | |
| 405 | This will create two result files: <tt>hello</tt> and |
| 406 | <tt>hello.bc</tt>. The <tt>hello.bc</tt> is the LLVM bytecode that |
| 407 | corresponds the the compiled program and the library facilities that it |
| 408 | required. <tt>hello</tt> is a simple shell script that runs the bytecode |
| 409 | file with <tt>lli</tt>, making the result directly executable.<p> |
| 410 | |
| 411 | <li>Run the program. To make sure the program ran, execute one of the |
| 412 | following commands:<p> |
| 413 | |
| 414 | <tt>% ./hello</tt><p> |
| 415 | |
| 416 | or<p> |
| 417 | |
| 418 | <tt>% lli hello.bc</tt><p> |
| 419 | |
| 420 | <li>Use the <tt>dis</tt> utility to take a look at the LLVM assembly |
| 421 | code:<p> |
| 422 | |
| 423 | <tt>% dis < hello.bc | less</tt><p> |
| 424 | |
| 425 | <li>Compile the program to native Sparc assembly using the code |
| 426 | generator:<p> |
| 427 | |
| 428 | <tt>% llc hello.bc -o hello.s</tt><p> |
| 429 | |
| 430 | <li>Assemble the native sparc assemble file into a program:<p> |
| 431 | |
| 432 | <tt>% /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.sparc</tt><p> |
| 433 | |
| 434 | <li>Execute the native sparc program:<p> |
| 435 | |
| 436 | <tt>% ./hello.sparc</tt><p> |
| 437 | |
| 438 | </ol> |
| 439 | |
| 440 | |
| 441 | <!--=====================================================================--> |
| 442 | <h2><a name="links">Links</a></h2> |
| 443 | <!--=====================================================================--> |
| 444 | |
| 445 | <p>This document is just an <b>introduction</b> to how to use LLVM to do |
| 446 | some simple things... there are many more interesting and complicated things |
| 447 | that you can do that aren't documented here (but we'll gladly accept a patch |
| 448 | if you want to write something up!). For more information about LLVM, check |
| 449 | out:</p> |
| 450 | |
| 451 | <ul> |
| 452 | <li><a href="http://llvm.cs.uiuc.edu/">LLVM homepage</a></li> |
| 453 | <li><a href="http://tank.cs.uiuc.edu/doxygen/">LLVM doxygen tree</a></li> |
| 454 | </ul> |
| 455 | |
| 456 | <hr> |
| 457 | |
| 458 | If you have any questions or run into any snags (or you have any |
Chris Lattner | 1db872d | 2002-09-06 16:26:13 +0000 | [diff] [blame] | 459 | additions...), please send an email to |
| 460 | <a href="mailto:hldnbrnd@uiuc.edu">Nicholas Hildenbrandt</a> or |
| 461 | <a href="mailto:sabre@nondot.org">Chris Lattner</a>.</p> |
Chris Lattner | 7fe7f81 | 2002-07-24 19:51:14 +0000 | [diff] [blame] | 462 | |
Guochun Shi | f4688a8 | 2002-07-17 23:05:56 +0000 | [diff] [blame] | 463 | <!-- Created: Mon Jul 1 02:29:02 CDT 2002 --> |
| 464 | <!-- hhmts start --> |
Chris Lattner | 96768ea | 2003-02-14 04:22:13 +0000 | [diff] [blame] | 465 | Last modified: Thu Feb 13 22:20:39 CST 2003 |
Guochun Shi | f4688a8 | 2002-07-17 23:05:56 +0000 | [diff] [blame] | 466 | <!-- hhmts end --> |
| 467 | </body> |
| 468 | </html> |