Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1 | ==================================== |
Mehdi Amini | 5d9068c | 2015-08-03 23:17:44 +0000 | [diff] [blame] | 2 | Getting Started with the LLVM System |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 3 | ==================================== |
| 4 | |
Sean Silva | 7d31849 | 2012-12-20 03:32:39 +0000 | [diff] [blame] | 5 | .. contents:: |
| 6 | :local: |
| 7 | |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 8 | Overview |
| 9 | ======== |
| 10 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 11 | Welcome to the LLVM project! In order to get started, you first need to know |
| 12 | some basic information. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 13 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 14 | First, the LLVM project has multiple components. The core of the project is |
| 15 | itself called "LLVM". This contains all of the tools, libraries, and header |
| 16 | files needed to process an intermediate representation and convert it into |
| 17 | object files. It contains an assembler, disassembler, bitcode analyzer and |
| 18 | bitcode optimizer. It also contains basic regression tests. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 19 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 20 | Another piece is the `Clang <http://clang.llvm.org/>`_ front end. This |
| 21 | component compiles C, C++, Objective C, and Objective C++ code into LLVM bitcode |
| 22 | -- and from there into object files, using LLVM. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 23 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 24 | There are other components as well: |
| 25 | the `libc++ C++ standard library <https://libcxx.llvm.org>`_, |
| 26 | the `LLD linker <https://lld.llvm.org>`_, and more. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 27 | |
| 28 | Getting Started Quickly (A Summary) |
| 29 | =================================== |
| 30 | |
| 31 | The LLVM Getting Started documentation may be out of date. So, the `Clang |
| 32 | Getting Started <http://clang.llvm.org/get_started.html>`_ page might also be a |
| 33 | good place to start. |
| 34 | |
| 35 | Here's the short story for getting up and running quickly with LLVM: |
| 36 | |
| 37 | #. Read the documentation. |
| 38 | #. Read the documentation. |
| 39 | #. Remember that you were warned twice about reading the documentation. |
Philip Reames | 79a6578 | 2016-02-06 19:20:26 +0000 | [diff] [blame] | 40 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 41 | #. Checkout LLVM (including related subprojects like Clang): |
Philip Reames | 79a6578 | 2016-02-06 19:20:26 +0000 | [diff] [blame] | 42 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 43 | * ``git clone https://github.com/llvm/llvm-project.git`` |
| 44 | * Or, on windows, ``git clone --config core.autocrlf=false |
| 45 | https://github.com/llvm/llvm-project.git`` |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 46 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 47 | #. Configure and build LLVM and Clang:. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 48 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 49 | * ``cd llvm-project`` |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 50 | * ``mkdir build`` |
| 51 | * ``cd build`` |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 52 | * ``cmake -G <generator> [options] ../llvm`` |
Mehdi Amini | 5d9068c | 2015-08-03 23:17:44 +0000 | [diff] [blame] | 53 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 54 | Some common generators are: |
| 55 | |
Nico Weber | c056d20 | 2016-03-28 20:32:38 +0000 | [diff] [blame] | 56 | * ``Ninja`` --- for generating `Ninja <https://ninja-build.org>`_ |
Nico Weber | 8c94859 | 2016-03-28 21:00:21 +0000 | [diff] [blame] | 57 | build files. Most llvm developers use Ninja. |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 58 | * ``Unix Makefiles`` --- for generating make-compatible parallel makefiles. |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 59 | * ``Visual Studio`` --- for generating Visual Studio projects and |
Nico Weber | 8c94859 | 2016-03-28 21:00:21 +0000 | [diff] [blame] | 60 | solutions. |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 61 | * ``Xcode`` --- for generating Xcode projects. |
Mehdi Amini | 5d9068c | 2015-08-03 23:17:44 +0000 | [diff] [blame] | 62 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 63 | Some Common options: |
| 64 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 65 | * ``-DLLVM_ENABLE_PROJECTS='...'`` --- semicolon-separated list of the LLVM |
| 66 | subprojects you'd like to additionally build. Can include any of: clang, |
| 67 | libcxx, libcxxabi, libunwind, lldb, compiler-rt, lld, polly, or |
| 68 | debuginfo-tests. |
| 69 | |
| 70 | For example, to build LLVM, Clang, libcxx, and libcxxabi, use |
| 71 | ``-DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi"``. |
| 72 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 73 | * ``-DCMAKE_INSTALL_PREFIX=directory`` --- Specify for *directory* the full |
| 74 | pathname of where you want the LLVM tools and libraries to be installed |
| 75 | (default ``/usr/local``). |
| 76 | |
| 77 | * ``-DCMAKE_BUILD_TYPE=type`` --- Valid options for *type* are Debug, |
| 78 | Release, RelWithDebInfo, and MinSizeRel. Default is Debug. |
| 79 | |
| 80 | * ``-DLLVM_ENABLE_ASSERTIONS=On`` --- Compile with assertion checks enabled |
| 81 | (default is Yes for Debug builds, No for all other build types). |
| 82 | |
Chris Bieneman | 67dcb7d | 2015-03-14 21:20:32 +0000 | [diff] [blame] | 83 | * Run your build tool of choice! |
| 84 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 85 | * The default target (i.e. ``ninja`` or ``make``) will build all of LLVM. |
Chris Bieneman | 67dcb7d | 2015-03-14 21:20:32 +0000 | [diff] [blame] | 86 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 87 | * The ``check-all`` target (i.e. ``ninja check-all``) will run the |
Chris Bieneman | 67dcb7d | 2015-03-14 21:20:32 +0000 | [diff] [blame] | 88 | regression tests to ensure everything is in working order. |
| 89 | |
| 90 | * CMake will generate build targets for each tool and library, and most |
| 91 | LLVM sub-projects generate their own ``check-<project>`` target. |
| 92 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 93 | * Running a serial build will be *slow*. Make sure you run a parallel |
| 94 | build. That's already done by default in Ninja; for ``make``, use |
| 95 | ``make -j NNN`` (with an appropriate value of NNN, e.g. number of CPUs |
| 96 | you have.) |
Philip Reames | 3e299e1 | 2016-02-06 19:43:40 +0000 | [diff] [blame] | 97 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 98 | * For more information see `CMake <CMake.html>`_ |
| 99 | |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 100 | * If you get an "internal compiler error (ICE)" or test failures, see |
Chris Bieneman | 67dcb7d | 2015-03-14 21:20:32 +0000 | [diff] [blame] | 101 | `below`_. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 102 | |
| 103 | Consult the `Getting Started with LLVM`_ section for detailed information on |
Mitch Phillips | 67f0700 | 2017-10-23 17:37:41 +0000 | [diff] [blame] | 104 | configuring and compiling LLVM. Go to `Directory Layout`_ to learn about the |
Philip Reames | 55cdcca | 2016-02-07 15:49:57 +0000 | [diff] [blame] | 105 | layout of the source code tree. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 106 | |
| 107 | Requirements |
| 108 | ============ |
| 109 | |
| 110 | Before you begin to use the LLVM system, review the requirements given below. |
| 111 | This may save you some trouble by knowing ahead of time what hardware and |
| 112 | software you will need. |
| 113 | |
| 114 | Hardware |
| 115 | -------- |
| 116 | |
Chandler Carruth | 19061dd | 2014-02-27 09:33:55 +0000 | [diff] [blame] | 117 | LLVM is known to work on the following host platforms: |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 118 | |
Chandler Carruth | adf2c60 | 2014-02-27 09:41:13 +0000 | [diff] [blame] | 119 | ================== ===================== ============= |
Mehdi Amini | 5d9068c | 2015-08-03 23:17:44 +0000 | [diff] [blame] | 120 | OS Arch Compilers |
Chandler Carruth | adf2c60 | 2014-02-27 09:41:13 +0000 | [diff] [blame] | 121 | ================== ===================== ============= |
Mehdi Amini | 5d9068c | 2015-08-03 23:17:44 +0000 | [diff] [blame] | 122 | Linux x86\ :sup:`1` GCC, Clang |
| 123 | Linux amd64 GCC, Clang |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 124 | Linux ARM GCC, Clang |
Mehdi Amini | 5d9068c | 2015-08-03 23:17:44 +0000 | [diff] [blame] | 125 | Linux PowerPC GCC, Clang |
| 126 | Solaris V9 (Ultrasparc) GCC |
| 127 | FreeBSD x86\ :sup:`1` GCC, Clang |
| 128 | FreeBSD amd64 GCC, Clang |
Kamil Rytarowski | bb7651b | 2017-04-22 16:11:23 +0000 | [diff] [blame] | 129 | NetBSD x86\ :sup:`1` GCC, Clang |
| 130 | NetBSD amd64 GCC, Clang |
Mehdi Amini | 5d9068c | 2015-08-03 23:17:44 +0000 | [diff] [blame] | 131 | MacOS X\ :sup:`2` PowerPC GCC |
| 132 | MacOS X x86 GCC, Clang |
| 133 | Cygwin/Win32 x86\ :sup:`1, 3` GCC |
| 134 | Windows x86\ :sup:`1` Visual Studio |
| 135 | Windows x64 x86-64 Visual Studio |
Chandler Carruth | adf2c60 | 2014-02-27 09:41:13 +0000 | [diff] [blame] | 136 | ================== ===================== ============= |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 137 | |
| 138 | .. note:: |
| 139 | |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 140 | #. Code generation supported for Pentium processors and up |
| 141 | #. Code generation supported for 32-bit ABI only |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 142 | #. To use LLVM modules on Win32-based system, you may configure LLVM |
Philip Reames | 56df681 | 2016-02-07 15:58:35 +0000 | [diff] [blame] | 143 | with ``-DBUILD_SHARED_LIBS=On``. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 144 | |
Philip Reames | 56df681 | 2016-02-07 15:58:35 +0000 | [diff] [blame] | 145 | Note that Debug builds require a lot of time and disk space. An LLVM-only build |
| 146 | will need about 1-3 GB of space. A full build of LLVM and Clang will need around |
| 147 | 15-20 GB of disk space. The exact space requirements will vary by system. (It |
Mitch Phillips | 67f0700 | 2017-10-23 17:37:41 +0000 | [diff] [blame] | 148 | is so large because of all the debugging information and the fact that the |
| 149 | libraries are statically linked into multiple tools). |
Philip Reames | 56df681 | 2016-02-07 15:58:35 +0000 | [diff] [blame] | 150 | |
Hans Wennborg | 83f6dc2 | 2018-06-13 09:11:10 +0000 | [diff] [blame] | 151 | If you are space-constrained, you can build only selected tools or only |
Philip Reames | 56df681 | 2016-02-07 15:58:35 +0000 | [diff] [blame] | 152 | selected targets. The Release build requires considerably less space. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 153 | |
| 154 | The LLVM suite *may* compile on other platforms, but it is not guaranteed to do |
| 155 | so. If compilation is successful, the LLVM utilities should be able to |
| 156 | assemble, disassemble, analyze, and optimize LLVM bitcode. Code generation |
| 157 | should work as well, although the generated native code may not work on your |
| 158 | platform. |
| 159 | |
| 160 | Software |
| 161 | -------- |
| 162 | |
| 163 | Compiling LLVM requires that you have several software packages installed. The |
| 164 | table below lists those required packages. The Package column is the usual name |
| 165 | for the software package that LLVM depends on. The Version column provides |
| 166 | "known to work" versions of the package. The Notes column describes how LLVM |
| 167 | uses the package and provides other details. |
| 168 | |
Chandler Carruth | 5fb0df0 | 2014-02-27 09:46:09 +0000 | [diff] [blame] | 169 | =========================================================== ============ ========================================== |
| 170 | Package Version Notes |
| 171 | =========================================================== ============ ========================================== |
| 172 | `GNU Make <http://savannah.gnu.org/projects/make>`_ 3.79, 3.79.1 Makefile/build processor |
Hans Wennborg | ef6469f | 2019-02-08 11:06:27 +0000 | [diff] [blame] | 173 | `GCC <http://gcc.gnu.org/>`_ >=5.1.0 C/C++ compiler\ :sup:`1` |
Rafael Espindola | 708bc15 | 2014-12-12 15:29:31 +0000 | [diff] [blame] | 174 | `python <http://www.python.org/>`_ >=2.7 Automated test suite\ :sup:`2` |
Nico Weber | 51d98d3 | 2016-03-28 21:24:46 +0000 | [diff] [blame] | 175 | `zlib <http://zlib.net>`_ >=1.2.3.4 Compression library\ :sup:`3` |
Chandler Carruth | 5fb0df0 | 2014-02-27 09:46:09 +0000 | [diff] [blame] | 176 | =========================================================== ============ ========================================== |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 177 | |
| 178 | .. note:: |
| 179 | |
| 180 | #. Only the C and C++ languages are needed so there's no need to build the |
| 181 | other languages for LLVM's purposes. See `below` for specific version |
| 182 | info. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 183 | #. Only needed if you want to run the automated test suite in the |
| 184 | ``llvm/test`` directory. |
Sean Silva | aede1c9 | 2014-03-02 00:21:42 +0000 | [diff] [blame] | 185 | #. Optional, adds compression / uncompression capabilities to selected LLVM |
Alexey Samsonov | ee03c94 | 2013-04-23 08:28:39 +0000 | [diff] [blame] | 186 | tools. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 187 | |
| 188 | Additionally, your compilation host is expected to have the usual plethora of |
| 189 | Unix utilities. Specifically: |
| 190 | |
| 191 | * **ar** --- archive library builder |
| 192 | * **bzip2** --- bzip2 command for distribution generation |
| 193 | * **bunzip2** --- bunzip2 command for distribution checking |
| 194 | * **chmod** --- change permissions on a file |
| 195 | * **cat** --- output concatenation utility |
| 196 | * **cp** --- copy files |
Mehdi Amini | 5d9068c | 2015-08-03 23:17:44 +0000 | [diff] [blame] | 197 | * **date** --- print the current date/time |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 198 | * **echo** --- print to standard output |
| 199 | * **egrep** --- extended regular expression search utility |
| 200 | * **find** --- find files/dirs in a file system |
| 201 | * **grep** --- regular expression search utility |
| 202 | * **gzip** --- gzip command for distribution generation |
| 203 | * **gunzip** --- gunzip command for distribution checking |
Mehdi Amini | 5d9068c | 2015-08-03 23:17:44 +0000 | [diff] [blame] | 204 | * **install** --- install directories/files |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 205 | * **mkdir** --- create a directory |
| 206 | * **mv** --- move (rename) files |
| 207 | * **ranlib** --- symbol table builder for archive libraries |
| 208 | * **rm** --- remove (delete) files and directories |
| 209 | * **sed** --- stream editor for transforming output |
| 210 | * **sh** --- Bourne shell for make build scripts |
| 211 | * **tar** --- tape archive for distribution generation |
| 212 | * **test** --- test things in file system |
| 213 | * **unzip** --- unzip command for distribution checking |
| 214 | * **zip** --- zip command for distribution generation |
| 215 | |
| 216 | .. _below: |
| 217 | .. _check here: |
| 218 | |
Chandler Carruth | 36b191f | 2014-02-27 10:35:57 +0000 | [diff] [blame] | 219 | Host C++ Toolchain, both Compiler and Standard Library |
| 220 | ------------------------------------------------------ |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 221 | |
| 222 | LLVM is very demanding of the host C++ compiler, and as such tends to expose |
Hans Wennborg | ef6469f | 2019-02-08 11:06:27 +0000 | [diff] [blame] | 223 | bugs in the compiler. We also attempt to follow improvements and developments in |
| 224 | the C++ language and library reasonably closely. As such, we require a modern |
| 225 | host C++ toolchain, both compiler and standard library, in order to build LLVM. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 226 | |
Hans Wennborg | ef6469f | 2019-02-08 11:06:27 +0000 | [diff] [blame] | 227 | LLVM is written using the subset of C++ documented in :doc:`coding |
| 228 | standards<CodingStandards>`. To enforce this language version, we check the most |
| 229 | popular host toolchains for specific minimum versions in our build systems: |
| 230 | |
| 231 | * Clang 3.5 |
| 232 | * Apple Clang 6.0 |
| 233 | * GCC 5.1 |
| 234 | * Visual Studio 2017 |
| 235 | |
| 236 | The below versions currently soft-error as we transition to the new compiler |
| 237 | versions listed above. The LLVM codebase is currently known to compile correctly |
| 238 | with the following compilers, though this will change in the near future: |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 239 | |
Chandler Carruth | 36b191f | 2014-02-27 10:35:57 +0000 | [diff] [blame] | 240 | * Clang 3.1 |
Hans Wennborg | ef6469f | 2019-02-08 11:06:27 +0000 | [diff] [blame] | 241 | * Apple Clang 3.1 |
Teresa Johnson | 5618317 | 2016-10-18 17:17:37 +0000 | [diff] [blame] | 242 | * GCC 4.8 |
Reid Kleckner | 36850aa | 2016-12-15 19:08:02 +0000 | [diff] [blame] | 243 | * Visual Studio 2015 (Update 3) |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 244 | |
Chandler Carruth | 36b191f | 2014-02-27 10:35:57 +0000 | [diff] [blame] | 245 | Anything older than these toolchains *may* work, but will require forcing the |
| 246 | build system with a special option and is not really a supported host platform. |
| 247 | Also note that older versions of these compilers have often crashed or |
| 248 | miscompiled LLVM. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 249 | |
Chandler Carruth | 36b191f | 2014-02-27 10:35:57 +0000 | [diff] [blame] | 250 | For less widely used host toolchains such as ICC or xlC, be aware that a very |
| 251 | recent version may be required to support all of the C++ features used in LLVM. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 252 | |
Chandler Carruth | 36b191f | 2014-02-27 10:35:57 +0000 | [diff] [blame] | 253 | We track certain versions of software that are *known* to fail when used as |
| 254 | part of the host toolchain. These even include linkers at times. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 255 | |
| 256 | **GNU ld 2.16.X**. Some 2.16.X versions of the ld linker will produce very long |
| 257 | warning messages complaining that some "``.gnu.linkonce.t.*``" symbol was |
| 258 | defined in a discarded section. You can safely ignore these messages as they are |
| 259 | erroneous and the linkage is correct. These messages disappear using ld 2.17. |
| 260 | |
| 261 | **GNU binutils 2.17**: Binutils 2.17 contains `a bug |
Sean Silva | 59ccfb0 | 2012-10-07 18:49:28 +0000 | [diff] [blame] | 262 | <http://sourceware.org/bugzilla/show_bug.cgi?id=3111>`__ which causes huge link |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 263 | times (minutes instead of seconds) when building LLVM. We recommend upgrading |
| 264 | to a newer version (2.17.50.0.4 or later). |
| 265 | |
| 266 | **GNU Binutils 2.19.1 Gold**: This version of Gold contained `a bug |
Sean Silva | 59ccfb0 | 2012-10-07 18:49:28 +0000 | [diff] [blame] | 267 | <http://sourceware.org/bugzilla/show_bug.cgi?id=9836>`__ which causes |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 268 | intermittent failures when building LLVM with position independent code. The |
| 269 | symptom is an error about cyclic dependencies. We recommend upgrading to a |
| 270 | newer version of Gold. |
| 271 | |
Chandler Carruth | baed825 | 2014-02-28 10:56:57 +0000 | [diff] [blame] | 272 | Getting a Modern Host C++ Toolchain |
| 273 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 274 | |
Chandler Carruth | ed0b862 | 2014-02-28 11:11:41 +0000 | [diff] [blame] | 275 | This section mostly applies to Linux and older BSDs. On Mac OS X, you should |
| 276 | have a sufficiently modern Xcode, or you will likely need to upgrade until you |
Reid Kleckner | dee834c | 2016-10-19 23:04:41 +0000 | [diff] [blame] | 277 | do. Windows does not have a "system compiler", so you must install either Visual |
| 278 | Studio 2015 or a recent version of mingw64. FreeBSD 10.0 and newer have a modern |
Chandler Carruth | ed0b862 | 2014-02-28 11:11:41 +0000 | [diff] [blame] | 279 | Clang as the system compiler. |
Chandler Carruth | baed825 | 2014-02-28 10:56:57 +0000 | [diff] [blame] | 280 | |
Chandler Carruth | 67814df | 2014-02-28 11:09:33 +0000 | [diff] [blame] | 281 | However, some Linux distributions and some other or older BSDs sometimes have |
Chandler Carruth | baed825 | 2014-02-28 10:56:57 +0000 | [diff] [blame] | 282 | extremely old versions of GCC. These steps attempt to help you upgrade you |
| 283 | compiler even on such a system. However, if at all possible, we encourage you |
| 284 | to use a recent version of a distribution with a modern system compiler that |
Hiroshi Inoue | d1b456b | 2018-01-29 05:17:03 +0000 | [diff] [blame] | 285 | meets these requirements. Note that it is tempting to install a prior |
Chandler Carruth | baed825 | 2014-02-28 10:56:57 +0000 | [diff] [blame] | 286 | version of Clang and libc++ to be the host compiler, however libc++ was not |
| 287 | well tested or set up to build on Linux until relatively recently. As |
| 288 | a consequence, this guide suggests just using libstdc++ and a modern GCC as the |
| 289 | initial host in a bootstrap, and then using Clang (and potentially libc++). |
| 290 | |
| 291 | The first step is to get a recent GCC toolchain installed. The most common |
| 292 | distribution on which users have struggled with the version requirements is |
| 293 | Ubuntu Precise, 12.04 LTS. For this distribution, one easy option is to install |
Chandler Carruth | a20d48d | 2014-02-28 12:09:14 +0000 | [diff] [blame] | 294 | the `toolchain testing PPA`_ and use it to install a modern GCC. There is |
Hans Wennborg | ef6469f | 2019-02-08 11:06:27 +0000 | [diff] [blame] | 295 | a really nice discussions of this on the `ask ubuntu stack exchange`_ and a |
| 296 | `github gist`_ with updated commands. However, not all users can use PPAs and |
| 297 | there are many other distributions, so it may be necessary (or just useful, if |
| 298 | you're here you *are* doing compiler development after all) to build and install |
| 299 | GCC from source. It is also quite easy to do these days. |
Chandler Carruth | a20d48d | 2014-02-28 12:09:14 +0000 | [diff] [blame] | 300 | |
| 301 | .. _toolchain testing PPA: |
| 302 | https://launchpad.net/~ubuntu-toolchain-r/+archive/test |
| 303 | .. _ask ubuntu stack exchange: |
Hans Wennborg | ef6469f | 2019-02-08 11:06:27 +0000 | [diff] [blame] | 304 | https://askubuntu.com/questions/466651/how-do-i-use-the-latest-gcc-on-ubuntu/581497#58149 |
| 305 | .. _github gist: |
| 306 | https://gist.github.com/application2000/73fd6f4bf1be6600a2cf9f56315a2d91 |
Chandler Carruth | baed825 | 2014-02-28 10:56:57 +0000 | [diff] [blame] | 307 | |
Hans Wennborg | ef6469f | 2019-02-08 11:06:27 +0000 | [diff] [blame] | 308 | Easy steps for installing GCC 5.1.0: |
Chandler Carruth | baed825 | 2014-02-28 10:56:57 +0000 | [diff] [blame] | 309 | |
| 310 | .. code-block:: console |
| 311 | |
Hans Wennborg | ef6469f | 2019-02-08 11:06:27 +0000 | [diff] [blame] | 312 | % gcc_version=5.1.0 |
| 313 | % wget https://ftp.gnu.org/gnu/gcc/gcc-${gcc_version}/gcc-${gcc_version}.tar.bz2 |
| 314 | % wget https://ftp.gnu.org/gnu/gcc/gcc-${gcc_version}/gcc-${gcc_version}.tar.bz2.sig |
JF Bastien | 60085fb | 2015-07-01 03:32:08 +0000 | [diff] [blame] | 315 | % wget https://ftp.gnu.org/gnu/gnu-keyring.gpg |
Hans Wennborg | ef6469f | 2019-02-08 11:06:27 +0000 | [diff] [blame] | 316 | % signature_invalid=`gpg --verify --no-default-keyring --keyring ./gnu-keyring.gpg gcc-${gcc_version}.tar.bz2.sig` |
JF Bastien | 60085fb | 2015-07-01 03:32:08 +0000 | [diff] [blame] | 317 | % if [ $signature_invalid ]; then echo "Invalid signature" ; exit 1 ; fi |
Hans Wennborg | ef6469f | 2019-02-08 11:06:27 +0000 | [diff] [blame] | 318 | % tar -xvjf gcc-${gcc_version}.tar.bz2 |
| 319 | % cd gcc-${gcc_version} |
Chandler Carruth | 345ca69 | 2014-02-28 12:14:56 +0000 | [diff] [blame] | 320 | % ./contrib/download_prerequisites |
| 321 | % cd .. |
Hans Wennborg | ef6469f | 2019-02-08 11:06:27 +0000 | [diff] [blame] | 322 | % mkdir gcc-${gcc_version}-build |
| 323 | % cd gcc-${gcc_version}-build |
| 324 | % $PWD/../gcc-${gcc_version}/configure --prefix=$HOME/toolchains --enable-languages=c,c++ |
Chandler Carruth | 345ca69 | 2014-02-28 12:14:56 +0000 | [diff] [blame] | 325 | % make -j$(nproc) |
| 326 | % make install |
Chandler Carruth | baed825 | 2014-02-28 10:56:57 +0000 | [diff] [blame] | 327 | |
Chandler Carruth | a20d48d | 2014-02-28 12:09:14 +0000 | [diff] [blame] | 328 | For more details, check out the excellent `GCC wiki entry`_, where I got most |
| 329 | of this information from. |
| 330 | |
| 331 | .. _GCC wiki entry: |
Hans Wennborg | ef6469f | 2019-02-08 11:06:27 +0000 | [diff] [blame] | 332 | https://gcc.gnu.org/wiki/InstallingGCC |
Chandler Carruth | baed825 | 2014-02-28 10:56:57 +0000 | [diff] [blame] | 333 | |
Reid Kleckner | cdc41f5 | 2014-08-01 21:40:53 +0000 | [diff] [blame] | 334 | Once you have a GCC toolchain, configure your build of LLVM to use the new |
| 335 | toolchain for your host compiler and C++ standard library. Because the new |
| 336 | version of libstdc++ is not on the system library search path, you need to pass |
| 337 | extra linker flags so that it can be found at link time (``-L``) and at runtime |
| 338 | (``-rpath``). If you are using CMake, this invocation should produce working |
| 339 | binaries: |
| 340 | |
| 341 | .. code-block:: console |
| 342 | |
| 343 | % mkdir build |
| 344 | % cd build |
| 345 | % CC=$HOME/toolchains/bin/gcc CXX=$HOME/toolchains/bin/g++ \ |
| 346 | cmake .. -DCMAKE_CXX_LINK_FLAGS="-Wl,-rpath,$HOME/toolchains/lib64 -L$HOME/toolchains/lib64" |
| 347 | |
| 348 | If you fail to set rpath, most LLVM binaries will fail on startup with a message |
| 349 | from the loader similar to ``libstdc++.so.6: version `GLIBCXX_3.4.20' not |
| 350 | found``. This means you need to tweak the -rpath linker flag. |
Chandler Carruth | baed825 | 2014-02-28 10:56:57 +0000 | [diff] [blame] | 351 | |
Hans Wennborg | ef6469f | 2019-02-08 11:06:27 +0000 | [diff] [blame] | 352 | When you build Clang, you will need to give *it* access to modern C++ |
Chandler Carruth | baed825 | 2014-02-28 10:56:57 +0000 | [diff] [blame] | 353 | standard library in order to use it as your new host in part of a bootstrap. |
| 354 | There are two easy ways to do this, either build (and install) libc++ along |
| 355 | with Clang and then use it with the ``-stdlib=libc++`` compile and link flag, |
| 356 | or install Clang into the same prefix (``$HOME/toolchains`` above) as GCC. |
| 357 | Clang will look within its own prefix for libstdc++ and use it if found. You |
| 358 | can also add an explicit prefix for Clang to look in for a GCC toolchain with |
| 359 | the ``--gcc-toolchain=/opt/my/gcc/prefix`` flag, passing it to both compile and |
| 360 | link commands when using your just-built-Clang to bootstrap. |
| 361 | |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 362 | .. _Getting Started with LLVM: |
| 363 | |
| 364 | Getting Started with LLVM |
| 365 | ========================= |
| 366 | |
| 367 | The remainder of this guide is meant to get you up and running with LLVM and to |
| 368 | give you some basic information about the LLVM environment. |
| 369 | |
| 370 | The later sections of this guide describe the `general layout`_ of the LLVM |
| 371 | source tree, a `simple example`_ using the LLVM tool chain, and `links`_ to find |
| 372 | more information about LLVM or to get help via e-mail. |
| 373 | |
| 374 | Terminology and Notation |
| 375 | ------------------------ |
| 376 | |
| 377 | Throughout this manual, the following names are used to denote paths specific to |
| 378 | the local system and working environment. *These are not environment variables |
| 379 | you need to set but just strings used in the rest of this document below*. In |
| 380 | any of the examples below, simply replace each of these names with the |
| 381 | appropriate pathname on your local system. All these paths are absolute: |
| 382 | |
| 383 | ``SRC_ROOT`` |
| 384 | |
| 385 | This is the top level directory of the LLVM source tree. |
| 386 | |
| 387 | ``OBJ_ROOT`` |
| 388 | |
| 389 | This is the top level directory of the LLVM object tree (i.e. the tree where |
| 390 | object files and compiled programs will be placed. It can be the same as |
| 391 | SRC_ROOT). |
| 392 | |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 393 | Unpacking the LLVM Archives |
| 394 | --------------------------- |
| 395 | |
| 396 | If you have the LLVM distribution, you will need to unpack it before you can |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 397 | begin to compile it. LLVM is distributed as a number of different |
| 398 | subprojects. Each one has its own download which is a TAR archive that is |
| 399 | compressed with the gzip program. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 400 | |
| 401 | The files are as follows, with *x.y* marking the version number: |
| 402 | |
| 403 | ``llvm-x.y.tar.gz`` |
| 404 | |
| 405 | Source release for the LLVM libraries and tools. |
| 406 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 407 | ``cfe-x.y.tar.gz`` |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 408 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 409 | Source release for the Clang frontend. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 410 | |
Sean Silva | 8a0f3f7 | 2013-01-10 06:39:37 +0000 | [diff] [blame] | 411 | .. _checkout: |
| 412 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 413 | Checkout LLVM from Git |
| 414 | ---------------------- |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 415 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 416 | You can also checkout the source code for LLVM from Git. While the LLVM |
| 417 | project's official source-code repository is Subversion, we are in the process |
| 418 | of migrating to git. We currently recommend that all developers use Git for |
| 419 | day-to-day development. |
| 420 | |
| 421 | .. note:: |
| 422 | |
| 423 | Passing ``--config core.autocrlf=false`` should not be required in |
| 424 | the future after we adjust the .gitattribute settings correctly, but |
| 425 | is required for Windows users at the time of this writing. |
| 426 | |
| 427 | Simply run: |
| 428 | |
| 429 | .. code-block:: console |
| 430 | |
| 431 | % git clone https://github.com/llvm/llvm-project.git` |
| 432 | |
| 433 | or on Windows, |
| 434 | |
| 435 | .. code-block:: console |
| 436 | |
| 437 | % git clone --config core.autocrlf=false https://github.com/llvm/llvm-project.git |
| 438 | |
| 439 | This will create an '``llvm-project``' directory in the current directory and |
| 440 | fully populate it with all of the source code, test directories, and local |
| 441 | copies of documentation files for LLVM and all the related subprojects. Note |
| 442 | that unlike the tarballs, which contain each subproject in a separate file, the |
| 443 | git repository contains all of the projects together. |
| 444 | |
| 445 | If you want to get a specific release (as opposed to the most recent revision), |
| 446 | you can check out a tag after cloning the repository. E.g., `git checkout |
| 447 | llvmorg-6.0.1` inside the ``llvm-project`` directory created by the above |
| 448 | command. Use `git tag -l` to list all of them. |
| 449 | |
| 450 | Sending patches |
| 451 | ^^^^^^^^^^^^^^^ |
| 452 | |
| 453 | Please read `Developer Policy <DeveloperPolicy.html#one-off-patches>`_, too. |
| 454 | |
| 455 | We don't currently accept github pull requests, so you'll need to send patches |
| 456 | either via emailing to llvm-commits, or, preferably, via :ref:`Phabricator |
| 457 | <phabricator-reviews>`. |
| 458 | |
| 459 | You'll generally want to make sure your branch has a single commit, |
| 460 | corresponding to the review you wish to send, up-to-date with the upstream |
| 461 | ``origin/master`` branch, and doesn't contain merges. Once you have that, you |
| 462 | can use ``git show`` or ``git format-patch`` to output the diff, and attach it |
| 463 | to a Phabricator review (or to an email message). |
| 464 | |
| 465 | However, using the "Arcanist" tool is often easier. After `installing |
| 466 | arcanist`_, you can upload the latest commit using: |
| 467 | |
| 468 | .. code-block:: console |
| 469 | |
| 470 | % arc diff HEAD~1 |
| 471 | |
| 472 | Additionally, before sending a patch for review, please also try to ensure it's |
| 473 | formatted properly. We use ``clang-format`` for this, which has git integration |
| 474 | through the ``git-clang-format`` script. On some systems, it may already be |
| 475 | installed (or be installable via your package manager). If so, you can simply |
| 476 | run it -- the following command will format only the code changed in the most |
| 477 | recent commit: |
| 478 | |
| 479 | .. code-block:: console |
| 480 | |
| 481 | % git clang-format HEAD~1 |
| 482 | |
| 483 | Note that this modifies the files, but doesn't commit them -- you'll likely want |
| 484 | to run |
| 485 | |
| 486 | .. code-block:: console |
| 487 | |
| 488 | % git commit --amend -a |
| 489 | |
| 490 | in order to update the last commit with all pending changes. |
| 491 | |
| 492 | .. note:: |
| 493 | If you don't already have ``clang-format`` or ``git clang-format`` installed |
| 494 | on your system, the ``clang-format`` binary will be built alongside clang, and |
| 495 | the git integration can be run from |
| 496 | ``clang/tools/clang-format/git-clang-format``. |
| 497 | |
| 498 | |
| 499 | .. _commit_from_git: |
| 500 | |
| 501 | For developers to commit changes from Git |
| 502 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 503 | |
| 504 | A helper script is provided in ``llvm/utils/git-svn/git-llvm``. After you add it |
| 505 | to your path, you can push committed changes upstream with ``git llvm |
| 506 | push``. While this creates a Subversion checkout and patches it under the hood, |
| 507 | it does not require you to have interaction with it. |
| 508 | |
| 509 | .. code-block:: console |
| 510 | |
| 511 | % export PATH=$PATH:$TOP_LEVEL_DIR/llvm-project/llvm/utils/git-svn/ |
| 512 | % git llvm push |
| 513 | |
| 514 | Within a couple minutes after pushing to subversion, the svn commit will have |
| 515 | been converted back to a Git commit, and made its way into the official Git |
| 516 | repository. At that point, ``git pull`` should get back the changes as they were |
| 517 | committed. |
| 518 | |
| 519 | You'll likely want to ``git pull --rebase`` to get the official git commit |
| 520 | downloaded back to your repository. The SVN revision numbers of each commit can |
| 521 | be found at the end of the commit message, e.g. ``llvm-svn: 350914``. |
| 522 | |
| 523 | You may also find the ``-n`` flag useful, like ``git llvm push -n``. This runs |
| 524 | through all the steps of committing _without_ actually doing the commit, and |
| 525 | tell you what it would have done. That can be useful if you're unsure whether |
| 526 | the right thing will happen. |
| 527 | |
| 528 | Checkout via SVN (deprecated) |
| 529 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 530 | |
| 531 | Until we have fully migrated to Git, you may also get a fresh copy of |
| 532 | the code from the official Subversion repository. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 533 | |
| 534 | * ``cd where-you-want-llvm-to-live`` |
| 535 | * Read-Only: ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm`` |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 536 | * Read-Write: ``svn co https://user@llvm.org/svn/llvm-project/llvm/trunk llvm`` |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 537 | |
| 538 | This will create an '``llvm``' directory in the current directory and fully |
| 539 | populate it with the LLVM source code, Makefiles, test directories, and local |
| 540 | copies of documentation files. |
| 541 | |
| 542 | If you want to get a specific release (as opposed to the most recent revision), |
Hans Wennborg | 2a6c2bd | 2017-11-30 23:47:30 +0000 | [diff] [blame] | 543 | you can check it out from the '``tags``' directory (instead of '``trunk``'). The |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 544 | following releases are located in the following subdirectories of the '``tags``' |
| 545 | directory: |
| 546 | |
Hans Wennborg | 2a6c2bd | 2017-11-30 23:47:30 +0000 | [diff] [blame] | 547 | * Release 3.5.0 and later: **RELEASE_350/final** and so on |
| 548 | * Release 2.9 through 3.4: **RELEASE_29/final** and so on |
| 549 | * Release 1.1 through 2.8: **RELEASE_11** and so on |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 550 | * Release 1.0: **RELEASE_1** |
| 551 | |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 552 | Local LLVM Configuration |
| 553 | ------------------------ |
| 554 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 555 | Once checked out repository, the LLVM suite source code must be configured |
| 556 | before being built. This process uses CMake. Unlinke the normal ``configure`` |
| 557 | script, CMake generates the build files in whatever format you request as well |
| 558 | as various ``*.inc`` files, and ``llvm/include/Config/config.h``. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 559 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 560 | Variables are passed to ``cmake`` on the command line using the format |
| 561 | ``-D<variable name>=<value>``. The following variables are some common options |
| 562 | used by people developing LLVM. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 563 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 564 | +-------------------------+----------------------------------------------------+ |
| 565 | | Variable | Purpose | |
| 566 | +=========================+====================================================+ |
| 567 | | CMAKE_C_COMPILER | Tells ``cmake`` which C compiler to use. By | |
| 568 | | | default, this will be /usr/bin/cc. | |
| 569 | +-------------------------+----------------------------------------------------+ |
| 570 | | CMAKE_CXX_COMPILER | Tells ``cmake`` which C++ compiler to use. By | |
| 571 | | | default, this will be /usr/bin/c++. | |
| 572 | +-------------------------+----------------------------------------------------+ |
| 573 | | CMAKE_BUILD_TYPE | Tells ``cmake`` what type of build you are trying | |
| 574 | | | to generate files for. Valid options are Debug, | |
| 575 | | | Release, RelWithDebInfo, and MinSizeRel. Default | |
| 576 | | | is Debug. | |
| 577 | +-------------------------+----------------------------------------------------+ |
| 578 | | CMAKE_INSTALL_PREFIX | Specifies the install directory to target when | |
| 579 | | | running the install action of the build files. | |
| 580 | +-------------------------+----------------------------------------------------+ |
| 581 | | LLVM_TARGETS_TO_BUILD | A semicolon delimited list controlling which | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 582 | | | targets will be built and linked into llvm. | |
| 583 | | | The default list is defined as | |
| 584 | | | ``LLVM_ALL_TARGETS``, and can be set to include | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 585 | | | out-of-tree targets. The default value includes: | |
James Y Knight | 257fabb | 2016-05-05 14:35:40 +0000 | [diff] [blame] | 586 | | | ``AArch64, AMDGPU, ARM, BPF, Hexagon, Mips, | |
| 587 | | | MSP430, NVPTX, PowerPC, Sparc, SystemZ, X86, | |
| 588 | | | XCore``. | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 589 | | | | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 590 | +-------------------------+----------------------------------------------------+ |
| 591 | | LLVM_ENABLE_DOXYGEN | Build doxygen-based documentation from the source | |
| 592 | | | code This is disabled by default because it is | |
| 593 | | | slow and generates a lot of output. | |
| 594 | +-------------------------+----------------------------------------------------+ |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 595 | | LLVM_ENABLE_PROJECTS | A semicolon-delimited list selecting which of the | |
| 596 | | | other LLVM subprojects to additionally build. (Only| |
| 597 | | | effective when using a side-by-side project layout | |
| 598 | | | e.g. via git). The default list is empty. Can | |
| 599 | | | include: clang, libcxx, libcxxabi, libunwind, lldb,| |
| 600 | | | compiler-rt, lld, polly, or debuginfo-tests. | |
| 601 | +-------------------------+----------------------------------------------------+ |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 602 | | LLVM_ENABLE_SPHINX | Build sphinx-based documentation from the source | |
| 603 | | | code. This is disabled by default because it is | |
Jonathan Roelofs | 56d588a | 2017-03-20 17:49:36 +0000 | [diff] [blame] | 604 | | | slow and generates a lot of output. Sphinx version | |
| 605 | | | 1.5 or later recommended. | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 606 | +-------------------------+----------------------------------------------------+ |
| 607 | | LLVM_BUILD_LLVM_DYLIB | Generate libLLVM.so. This library contains a | |
| 608 | | | default set of LLVM components that can be | |
| 609 | | | overridden with ``LLVM_DYLIB_COMPONENTS``. The | |
| 610 | | | default contains most of LLVM and is defined in | |
| 611 | | | ``tools/llvm-shlib/CMakelists.txt``. | |
| 612 | +-------------------------+----------------------------------------------------+ |
| 613 | | LLVM_OPTIMIZED_TABLEGEN | Builds a release tablegen that gets used during | |
| 614 | | | the LLVM build. This can dramatically speed up | |
| 615 | | | debug builds. | |
| 616 | +-------------------------+----------------------------------------------------+ |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 617 | |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 618 | To configure LLVM, follow these steps: |
| 619 | |
| 620 | #. Change directory into the object root directory: |
| 621 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 622 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 623 | |
| 624 | % cd OBJ_ROOT |
| 625 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 626 | #. Run the ``cmake``: |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 627 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 628 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 629 | |
Joel Galenson | aee71c0 | 2018-07-30 15:14:24 +0000 | [diff] [blame] | 630 | % cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/install/path |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 631 | [other options] SRC_ROOT |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 632 | |
| 633 | Compiling the LLVM Suite Source Code |
| 634 | ------------------------------------ |
| 635 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 636 | Unlike with autotools, with CMake your build type is defined at configuration. |
| 637 | If you want to change your build type, you can re-run cmake with the following |
| 638 | invocation: |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 639 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 640 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 641 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 642 | % cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=type SRC_ROOT |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 643 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 644 | Between runs, CMake preserves the values set for all options. CMake has the |
| 645 | following build types defined: |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 646 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 647 | Debug |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 648 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 649 | These builds are the default. The build system will compile the tools and |
| 650 | libraries unoptimized, with debugging information, and asserts enabled. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 651 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 652 | Release |
| 653 | |
| 654 | For these builds, the build system will compile the tools and libraries |
| 655 | with optimizations enabled and not generate debug info. CMakes default |
| 656 | optimization level is -O3. This can be configured by setting the |
| 657 | ``CMAKE_CXX_FLAGS_RELEASE`` variable on the CMake command line. |
| 658 | |
| 659 | RelWithDebInfo |
| 660 | |
| 661 | These builds are useful when debugging. They generate optimized binaries with |
| 662 | debug information. CMakes default optimization level is -O2. This can be |
| 663 | configured by setting the ``CMAKE_CXX_FLAGS_RELWITHDEBINFO`` variable on the |
| 664 | CMake command line. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 665 | |
| 666 | Once you have LLVM configured, you can build it by entering the *OBJ_ROOT* |
| 667 | directory and issuing the following command: |
| 668 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 669 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 670 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 671 | % make |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 672 | |
| 673 | If the build fails, please `check here`_ to see if you are using a version of |
| 674 | GCC that is known not to compile LLVM. |
| 675 | |
| 676 | If you have multiple processors in your machine, you may wish to use some of the |
| 677 | parallel build options provided by GNU Make. For example, you could use the |
| 678 | command: |
| 679 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 680 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 681 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 682 | % make -j2 |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 683 | |
| 684 | There are several special targets which are useful when working with the LLVM |
| 685 | source code: |
| 686 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 687 | ``make clean`` |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 688 | |
| 689 | Removes all files generated by the build. This includes object files, |
| 690 | generated C/C++ files, libraries, and executables. |
| 691 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 692 | ``make install`` |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 693 | |
| 694 | Installs LLVM header files, libraries, tools, and documentation in a hierarchy |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 695 | under ``$PREFIX``, specified with ``CMAKE_INSTALL_PREFIX``, which |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 696 | defaults to ``/usr/local``. |
| 697 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 698 | ``make docs-llvm-html`` |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 699 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 700 | If configured with ``-DLLVM_ENABLE_SPHINX=On``, this will generate a directory |
| 701 | at ``OBJ_ROOT/docs/html`` which contains the HTML formatted documentation. |
Joel Jones | b92ef12 | 2012-11-15 21:15:08 +0000 | [diff] [blame] | 702 | |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 703 | Cross-Compiling LLVM |
| 704 | -------------------- |
| 705 | |
| 706 | It is possible to cross-compile LLVM itself. That is, you can create LLVM |
| 707 | executables and libraries to be hosted on a platform different from the platform |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 708 | where they are built (a Canadian Cross build). To generate build files for |
| 709 | cross-compiling CMake provides a variable ``CMAKE_TOOLCHAIN_FILE`` which can |
| 710 | define compiler flags and variables used during the CMake test operations. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 711 | |
Hiroshi Inoue | 8040eab | 2018-01-26 08:15:29 +0000 | [diff] [blame] | 712 | The result of such a build is executables that are not runnable on the build |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 713 | host but can be executed on the target. As an example the following CMake |
| 714 | invocation can generate build files targeting iOS. This will work on Mac OS X |
| 715 | with the latest Xcode: |
| 716 | |
| 717 | .. code-block:: console |
| 718 | |
Pete Cooper | b6cc95a | 2015-12-04 21:59:04 +0000 | [diff] [blame] | 719 | % cmake -G "Ninja" -DCMAKE_OSX_ARCHITECTURES="armv7;armv7s;arm64" |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 720 | -DCMAKE_TOOLCHAIN_FILE=<PATH_TO_LLVM>/cmake/platforms/iOS.cmake |
| 721 | -DCMAKE_BUILD_TYPE=Release -DLLVM_BUILD_RUNTIME=Off -DLLVM_INCLUDE_TESTS=Off |
| 722 | -DLLVM_INCLUDE_EXAMPLES=Off -DLLVM_ENABLE_BACKTRACES=Off [options] |
| 723 | <PATH_TO_LLVM> |
| 724 | |
| 725 | Note: There are some additional flags that need to be passed when building for |
| 726 | iOS due to limitations in the iOS SDK. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 727 | |
Renato Golin | 6b4e9ba | 2013-09-26 08:57:07 +0000 | [diff] [blame] | 728 | Check :doc:`HowToCrossCompileLLVM` and `Clang docs on how to cross-compile in general |
| 729 | <http://clang.llvm.org/docs/CrossCompilation.html>`_ for more information |
| 730 | about cross-compiling. |
| 731 | |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 732 | The Location of LLVM Object Files |
| 733 | --------------------------------- |
| 734 | |
| 735 | The LLVM build system is capable of sharing a single LLVM source tree among |
| 736 | several LLVM builds. Hence, it is possible to build LLVM for several different |
| 737 | platforms or configurations using the same source tree. |
| 738 | |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 739 | * Change directory to where the LLVM object files should live: |
| 740 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 741 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 742 | |
| 743 | % cd OBJ_ROOT |
| 744 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 745 | * Run ``cmake``: |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 746 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 747 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 748 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 749 | % cmake -G "Unix Makefiles" SRC_ROOT |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 750 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 751 | The LLVM build will create a structure underneath *OBJ_ROOT* that matches the |
| 752 | LLVM source tree. At each level where source files are present in the source |
| 753 | tree there will be a corresponding ``CMakeFiles`` directory in the *OBJ_ROOT*. |
| 754 | Underneath that directory there is another directory with a name ending in |
| 755 | ``.dir`` under which you'll find object files for each source. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 756 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 757 | For example: |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 758 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 759 | .. code-block:: console |
Mehdi Amini | 5d9068c | 2015-08-03 23:17:44 +0000 | [diff] [blame] | 760 | |
Chris Bieneman | 1bba751 | 2015-03-13 01:58:14 +0000 | [diff] [blame] | 761 | % cd llvm_build_dir |
| 762 | % find lib/Support/ -name APFloat* |
| 763 | lib/Support/CMakeFiles/LLVMSupport.dir/APFloat.cpp.o |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 764 | |
| 765 | Optional Configuration Items |
| 766 | ---------------------------- |
| 767 | |
| 768 | If you're running on a Linux system that supports the `binfmt_misc |
Dmitri Gribenko | 9409a64 | 2013-03-25 17:08:25 +0000 | [diff] [blame] | 769 | <http://en.wikipedia.org/wiki/binfmt_misc>`_ |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 770 | module, and you have root access on the system, you can set your system up to |
| 771 | execute LLVM bitcode files directly. To do this, use commands like this (the |
| 772 | first command may not be required if you are already using the module): |
| 773 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 774 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 775 | |
| 776 | % mount -t binfmt_misc none /proc/sys/fs/binfmt_misc |
| 777 | % echo ':llvm:M::BC::/path/to/lli:' > /proc/sys/fs/binfmt_misc/register |
| 778 | % chmod u+x hello.bc (if needed) |
| 779 | % ./hello.bc |
| 780 | |
| 781 | This allows you to execute LLVM bitcode files directly. On Debian, you can also |
| 782 | use this command instead of the 'echo' command above: |
| 783 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 784 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 785 | |
| 786 | % sudo update-binfmts --install llvm /path/to/lli --magic 'BC' |
| 787 | |
| 788 | .. _Program Layout: |
| 789 | .. _general layout: |
| 790 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 791 | Directory Layout |
| 792 | ================ |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 793 | |
| 794 | One useful source of information about the LLVM source base is the LLVM `doxygen |
Mitch Phillips | 67f0700 | 2017-10-23 17:37:41 +0000 | [diff] [blame] | 795 | <http://www.doxygen.org/>`_ documentation available at |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 796 | `<http://llvm.org/doxygen/>`_. The following is a brief introduction to code |
| 797 | layout: |
| 798 | |
| 799 | ``llvm/examples`` |
| 800 | ----------------- |
| 801 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 802 | Simple examples using the LLVM IR and JIT. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 803 | |
| 804 | ``llvm/include`` |
| 805 | ---------------- |
| 806 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 807 | Public header files exported from the LLVM library. The three main subdirectories: |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 808 | |
| 809 | ``llvm/include/llvm`` |
| 810 | |
Mitch Phillips | 67f0700 | 2017-10-23 17:37:41 +0000 | [diff] [blame] | 811 | All LLVM-specific header files, and subdirectories for different portions of |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 812 | LLVM: ``Analysis``, ``CodeGen``, ``Target``, ``Transforms``, etc... |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 813 | |
| 814 | ``llvm/include/llvm/Support`` |
| 815 | |
Mitch Phillips | 67f0700 | 2017-10-23 17:37:41 +0000 | [diff] [blame] | 816 | Generic support libraries provided with LLVM but not necessarily specific to |
| 817 | LLVM. For example, some C++ STL utilities and a Command Line option processing |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 818 | library store header files here. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 819 | |
| 820 | ``llvm/include/llvm/Config`` |
| 821 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 822 | Header files configured by ``cmake``. They wrap "standard" UNIX and |
| 823 | C header files. Source code can include these header files which |
| 824 | automatically take care of the conditional #includes that ``cmake`` |
| 825 | generates. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 826 | |
| 827 | ``llvm/lib`` |
| 828 | ------------ |
| 829 | |
Mitch Phillips | 67f0700 | 2017-10-23 17:37:41 +0000 | [diff] [blame] | 830 | Most source files are here. By putting code in libraries, LLVM makes it easy to |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 831 | share code among the `tools`_. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 832 | |
Seo Sanghyeon | e5639d3 | 2014-10-29 05:20:39 +0000 | [diff] [blame] | 833 | ``llvm/lib/IR/`` |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 834 | |
Mitch Phillips | 67f0700 | 2017-10-23 17:37:41 +0000 | [diff] [blame] | 835 | Core LLVM source files that implement core classes like Instruction and |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 836 | BasicBlock. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 837 | |
| 838 | ``llvm/lib/AsmParser/`` |
| 839 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 840 | Source code for the LLVM assembly language parser library. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 841 | |
Michael Liao | 0262db3 | 2013-06-11 18:09:21 +0000 | [diff] [blame] | 842 | ``llvm/lib/Bitcode/`` |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 843 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 844 | Code for reading and writing bitcode. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 845 | |
| 846 | ``llvm/lib/Analysis/`` |
| 847 | |
Mitch Phillips | 67f0700 | 2017-10-23 17:37:41 +0000 | [diff] [blame] | 848 | A variety of program analyses, such as Call Graphs, Induction Variables, |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 849 | Natural Loop Identification, etc. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 850 | |
| 851 | ``llvm/lib/Transforms/`` |
| 852 | |
Mitch Phillips | 67f0700 | 2017-10-23 17:37:41 +0000 | [diff] [blame] | 853 | IR-to-IR program transformations, such as Aggressive Dead Code Elimination, |
| 854 | Sparse Conditional Constant Propagation, Inlining, Loop Invariant Code Motion, |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 855 | Dead Global Elimination, and many others. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 856 | |
| 857 | ``llvm/lib/Target/`` |
| 858 | |
Mitch Phillips | 67f0700 | 2017-10-23 17:37:41 +0000 | [diff] [blame] | 859 | Files describing target architectures for code generation. For example, |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 860 | ``llvm/lib/Target/X86`` holds the X86 machine description. |
Mehdi Amini | 5d9068c | 2015-08-03 23:17:44 +0000 | [diff] [blame] | 861 | |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 862 | ``llvm/lib/CodeGen/`` |
| 863 | |
Mitch Phillips | 67f0700 | 2017-10-23 17:37:41 +0000 | [diff] [blame] | 864 | The major parts of the code generator: Instruction Selector, Instruction |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 865 | Scheduling, and Register Allocation. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 866 | |
| 867 | ``llvm/lib/MC/`` |
| 868 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 869 | (FIXME: T.B.D.) ....? |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 870 | |
| 871 | ``llvm/lib/ExecutionEngine/`` |
| 872 | |
Mitch Phillips | 67f0700 | 2017-10-23 17:37:41 +0000 | [diff] [blame] | 873 | Libraries for directly executing bitcode at runtime in interpreted and |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 874 | JIT-compiled scenarios. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 875 | |
| 876 | ``llvm/lib/Support/`` |
| 877 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 878 | Source code that corresponding to the header files in ``llvm/include/ADT/`` |
| 879 | and ``llvm/include/Support/``. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 880 | |
| 881 | ``llvm/projects`` |
| 882 | ----------------- |
| 883 | |
Mitch Phillips | 67f0700 | 2017-10-23 17:37:41 +0000 | [diff] [blame] | 884 | Projects not strictly part of LLVM but shipped with LLVM. This is also the |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 885 | directory for creating your own LLVM-based projects which leverage the LLVM |
| 886 | build system. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 887 | |
| 888 | ``llvm/test`` |
| 889 | ------------- |
| 890 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 891 | Feature and regression tests and other sanity checks on LLVM infrastructure. These |
| 892 | are intended to run quickly and cover a lot of territory without being exhaustive. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 893 | |
| 894 | ``test-suite`` |
| 895 | -------------- |
| 896 | |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 897 | A comprehensive correctness, performance, and benchmarking test suite |
| 898 | for LLVM. This comes in a ``separate git repository |
| 899 | <https://github.com/llvm/llvm-test-suite>``, because it contains a |
| 900 | large amount of third-party code under a variety of licenses. For |
| 901 | details see the :doc:`Testing Guide <TestingGuide>` document. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 902 | |
| 903 | .. _tools: |
| 904 | |
| 905 | ``llvm/tools`` |
| 906 | -------------- |
| 907 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 908 | Executables built out of the libraries |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 909 | above, which form the main part of the user interface. You can always get help |
| 910 | for a tool by typing ``tool_name -help``. The following is a brief introduction |
| 911 | to the most important tools. More detailed information is in |
| 912 | the `Command Guide <CommandGuide/index.html>`_. |
| 913 | |
| 914 | ``bugpoint`` |
| 915 | |
| 916 | ``bugpoint`` is used to debug optimization passes or code generation backends |
| 917 | by narrowing down the given test case to the minimum number of passes and/or |
| 918 | instructions that still cause a problem, whether it is a crash or |
| 919 | miscompilation. See `<HowToSubmitABug.html>`_ for more information on using |
| 920 | ``bugpoint``. |
| 921 | |
| 922 | ``llvm-ar`` |
| 923 | |
| 924 | The archiver produces an archive containing the given LLVM bitcode files, |
| 925 | optionally with an index for faster lookup. |
Mehdi Amini | 5d9068c | 2015-08-03 23:17:44 +0000 | [diff] [blame] | 926 | |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 927 | ``llvm-as`` |
| 928 | |
| 929 | The assembler transforms the human readable LLVM assembly to LLVM bitcode. |
| 930 | |
| 931 | ``llvm-dis`` |
| 932 | |
| 933 | The disassembler transforms the LLVM bitcode to human readable LLVM assembly. |
| 934 | |
| 935 | ``llvm-link`` |
| 936 | |
| 937 | ``llvm-link``, not surprisingly, links multiple LLVM modules into a single |
| 938 | program. |
Mehdi Amini | 5d9068c | 2015-08-03 23:17:44 +0000 | [diff] [blame] | 939 | |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 940 | ``lli`` |
| 941 | |
| 942 | ``lli`` is the LLVM interpreter, which can directly execute LLVM bitcode |
| 943 | (although very slowly...). For architectures that support it (currently x86, |
| 944 | Sparc, and PowerPC), by default, ``lli`` will function as a Just-In-Time |
| 945 | compiler (if the functionality was compiled in), and will execute the code |
| 946 | *much* faster than the interpreter. |
| 947 | |
| 948 | ``llc`` |
| 949 | |
| 950 | ``llc`` is the LLVM backend compiler, which translates LLVM bitcode to a |
Rafael Espindola | 31e9ec9 | 2017-03-29 14:27:38 +0000 | [diff] [blame] | 951 | native code assembly file. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 952 | |
| 953 | ``opt`` |
| 954 | |
| 955 | ``opt`` reads LLVM bitcode, applies a series of LLVM to LLVM transformations |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 956 | (which are specified on the command line), and outputs the resultant |
| 957 | bitcode. '``opt -help``' is a good way to get a list of the |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 958 | program transformations available in LLVM. |
| 959 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 960 | ``opt`` can also run a specific analysis on an input LLVM bitcode |
| 961 | file and print the results. Primarily useful for debugging |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 962 | analyses, or familiarizing yourself with what an analysis does. |
| 963 | |
| 964 | ``llvm/utils`` |
| 965 | -------------- |
| 966 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 967 | Utilities for working with LLVM source code; some are part of the build process |
| 968 | because they are code generators for parts of the infrastructure. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 969 | |
| 970 | |
| 971 | ``codegen-diff`` |
| 972 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 973 | ``codegen-diff`` finds differences between code that LLC |
| 974 | generates and code that LLI generates. This is useful if you are |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 975 | debugging one of them, assuming that the other generates correct output. For |
| 976 | the full user manual, run ```perldoc codegen-diff'``. |
| 977 | |
| 978 | ``emacs/`` |
| 979 | |
Mitch Phillips | 67f0700 | 2017-10-23 17:37:41 +0000 | [diff] [blame] | 980 | Emacs and XEmacs syntax highlighting for LLVM assembly files and TableGen |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 981 | description files. See the ``README`` for information on using them. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 982 | |
| 983 | ``getsrcs.sh`` |
| 984 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 985 | Finds and outputs all non-generated source files, |
| 986 | useful if one wishes to do a lot of development across directories |
| 987 | and does not want to find each file. One way to use it is to run, |
| 988 | for example: ``xemacs `utils/getsources.sh``` from the top of the LLVM source |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 989 | tree. |
| 990 | |
| 991 | ``llvmgrep`` |
| 992 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 993 | Performs an ``egrep -H -n`` on each source file in LLVM and |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 994 | passes to it a regular expression provided on ``llvmgrep``'s command |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 995 | line. This is an efficient way of searching the source base for a |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 996 | particular regular expression. |
| 997 | |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 998 | ``TableGen/`` |
| 999 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 1000 | Contains the tool used to generate register |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1001 | descriptions, instruction set descriptions, and even assemblers from common |
| 1002 | TableGen description files. |
| 1003 | |
| 1004 | ``vim/`` |
| 1005 | |
Philip Reames | a22f43f | 2016-02-07 16:23:32 +0000 | [diff] [blame] | 1006 | vim syntax-highlighting for LLVM assembly files |
| 1007 | and TableGen description files. See the ``README`` for how to use them. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1008 | |
| 1009 | .. _simple example: |
| 1010 | |
| 1011 | An Example Using the LLVM Tool Chain |
| 1012 | ==================================== |
| 1013 | |
| 1014 | This section gives an example of using LLVM with the Clang front end. |
| 1015 | |
| 1016 | Example with clang |
| 1017 | ------------------ |
| 1018 | |
| 1019 | #. First, create a simple C file, name it 'hello.c': |
| 1020 | |
Sean Silva | a8759dd | 2012-10-10 17:07:23 +0000 | [diff] [blame] | 1021 | .. code-block:: c |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1022 | |
| 1023 | #include <stdio.h> |
| 1024 | |
| 1025 | int main() { |
| 1026 | printf("hello world\n"); |
| 1027 | return 0; |
| 1028 | } |
| 1029 | |
| 1030 | #. Next, compile the C file into a native executable: |
| 1031 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 1032 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1033 | |
| 1034 | % clang hello.c -o hello |
| 1035 | |
| 1036 | .. note:: |
| 1037 | |
| 1038 | Clang works just like GCC by default. The standard -S and -c arguments |
| 1039 | work as usual (producing a native .s or .o file, respectively). |
| 1040 | |
Daniel Dunbar | 1323006 | 2013-08-16 23:30:19 +0000 | [diff] [blame] | 1041 | #. Next, compile the C file into an LLVM bitcode file: |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1042 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 1043 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1044 | |
| 1045 | % clang -O3 -emit-llvm hello.c -c -o hello.bc |
| 1046 | |
| 1047 | The -emit-llvm option can be used with the -S or -c options to emit an LLVM |
| 1048 | ``.ll`` or ``.bc`` file (respectively) for the code. This allows you to use |
| 1049 | the `standard LLVM tools <CommandGuide/index.html>`_ on the bitcode file. |
| 1050 | |
| 1051 | #. Run the program in both forms. To run the program, use: |
| 1052 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 1053 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1054 | |
| 1055 | % ./hello |
Mehdi Amini | 5d9068c | 2015-08-03 23:17:44 +0000 | [diff] [blame] | 1056 | |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1057 | and |
| 1058 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 1059 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1060 | |
| 1061 | % lli hello.bc |
| 1062 | |
Dmitri Gribenko | c796af6 | 2012-11-18 10:32:14 +0000 | [diff] [blame] | 1063 | The second examples shows how to invoke the LLVM JIT, :doc:`lli |
| 1064 | <CommandGuide/lli>`. |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1065 | |
| 1066 | #. Use the ``llvm-dis`` utility to take a look at the LLVM assembly code: |
| 1067 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 1068 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1069 | |
| 1070 | % llvm-dis < hello.bc | less |
| 1071 | |
| 1072 | #. Compile the program to native assembly using the LLC code generator: |
| 1073 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 1074 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1075 | |
| 1076 | % llc hello.bc -o hello.s |
| 1077 | |
| 1078 | #. Assemble the native assembly language file into a program: |
| 1079 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 1080 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1081 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 1082 | % /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.native # On Solaris |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1083 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 1084 | % gcc hello.s -o hello.native # On others |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1085 | |
| 1086 | #. Execute the native code program: |
| 1087 | |
Dmitri Gribenko | 527036d | 2012-12-12 13:56:37 +0000 | [diff] [blame] | 1088 | .. code-block:: console |
Bill Wendling | f93c55a | 2012-10-07 07:10:13 +0000 | [diff] [blame] | 1089 | |
| 1090 | % ./hello.native |
| 1091 | |
| 1092 | Note that using clang to compile directly to native code (i.e. when the |
| 1093 | ``-emit-llvm`` option is not present) does steps 6/7/8 for you. |
| 1094 | |
| 1095 | Common Problems |
| 1096 | =============== |
| 1097 | |
| 1098 | If you are having problems building or using LLVM, or if you have any other |
| 1099 | general questions about LLVM, please consult the `Frequently Asked |
| 1100 | Questions <FAQ.html>`_ page. |
| 1101 | |
| 1102 | .. _links: |
| 1103 | |
| 1104 | Links |
| 1105 | ===== |
| 1106 | |
| 1107 | This document is just an **introduction** on how to use LLVM to do some simple |
| 1108 | things... there are many more interesting and complicated things that you can do |
| 1109 | that aren't documented here (but we'll gladly accept a patch if you want to |
| 1110 | write something up!). For more information about LLVM, check out: |
| 1111 | |
| 1112 | * `LLVM Homepage <http://llvm.org/>`_ |
| 1113 | * `LLVM Doxygen Tree <http://llvm.org/doxygen/>`_ |
| 1114 | * `Starting a Project that Uses LLVM <http://llvm.org/docs/Projects.html>`_ |
James Y Knight | 8986b31 | 2019-01-14 22:27:32 +0000 | [diff] [blame] | 1115 | |
| 1116 | .. _installing arcanist: https://secure.phabricator.com/book/phabricator/article/arcanist_quick_start/ |