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