xref: /llvm-project-15.0.7/README.md (revision d356cdcf)
10dc6249aSGreg Bedwell# The LLVM Compiler Infrastructure
2ec937b91SJames Y Knight
3*d356cdcfSPriyansh SinghThis directory and its sub-directories contain the source code for LLVM,
4ec937b91SJames Y Knighta toolkit for the construction of highly optimized compilers,
5905ccf8bSEvandro Menezesoptimizers, and run-time environments.
6da6384fbSMeike Baumgärtner
7effcdc3aSFlorian HahnThe README briefly describes how to get started with building LLVM.
8effcdc3aSFlorian HahnFor more information on how to contribute to the LLVM project, please
9effcdc3aSFlorian Hahntake a look at the
10effcdc3aSFlorian Hahn[Contributing to LLVM](https://llvm.org/docs/Contributing.html) guide.
11effcdc3aSFlorian Hahn
12da6384fbSMeike Baumgärtner## Getting Started with the LLVM System
13da6384fbSMeike Baumgärtner
141cb29916SPriyansh SinghTaken from [here](https://llvm.org/docs/GettingStarted.html).
15da6384fbSMeike Baumgärtner
16da6384fbSMeike Baumgärtner### Overview
17da6384fbSMeike Baumgärtner
18da6384fbSMeike BaumgärtnerWelcome to the LLVM project!
19da6384fbSMeike Baumgärtner
20da6384fbSMeike BaumgärtnerThe LLVM project has multiple components. The core of the project is
21da6384fbSMeike Baumgärtneritself called "LLVM". This contains all of the tools, libraries, and header
2247a11a97SPaul Robinsonfiles needed to process intermediate representations and convert them into
23da6384fbSMeike Baumgärtnerobject files. Tools include an assembler, disassembler, bitcode analyzer, and
24da6384fbSMeike Baumgärtnerbitcode optimizer. It also contains basic regression tests.
25da6384fbSMeike Baumgärtner
26da6384fbSMeike BaumgärtnerC-like languages use the [Clang](http://clang.llvm.org/) frontend. This
2759dd6250SAustin Conloncomponent compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode
28da6384fbSMeike Baumgärtner-- and from there into object files, using LLVM.
29da6384fbSMeike Baumgärtner
30da6384fbSMeike BaumgärtnerOther components include:
31da6384fbSMeike Baumgärtnerthe [libc++ C++ standard library](https://libcxx.llvm.org),
32da6384fbSMeike Baumgärtnerthe [LLD linker](https://lld.llvm.org), and more.
33da6384fbSMeike Baumgärtner
34da6384fbSMeike Baumgärtner### Getting the Source Code and Building LLVM
35da6384fbSMeike Baumgärtner
36da6384fbSMeike BaumgärtnerThe LLVM Getting Started documentation may be out of date. The [Clang
37da6384fbSMeike BaumgärtnerGetting Started](http://clang.llvm.org/get_started.html) page might have more
38da6384fbSMeike Baumgärtneraccurate information.
39da6384fbSMeike Baumgärtner
40905ccf8bSEvandro MenezesThis is an example work-flow and configuration to get and build the LLVM source:
41da6384fbSMeike Baumgärtner
42905ccf8bSEvandro Menezes1. Checkout LLVM (including related sub-projects like Clang):
43da6384fbSMeike Baumgärtner
44da6384fbSMeike Baumgärtner     * ``git clone https://github.com/llvm/llvm-project.git``
45da6384fbSMeike Baumgärtner
46da6384fbSMeike Baumgärtner     * Or, on windows, ``git clone --config core.autocrlf=false
47da6384fbSMeike Baumgärtner    https://github.com/llvm/llvm-project.git``
48da6384fbSMeike Baumgärtner
49da6384fbSMeike Baumgärtner2. Configure and build LLVM and Clang:
50da6384fbSMeike Baumgärtner
51da6384fbSMeike Baumgärtner     * ``cd llvm-project``
52da6384fbSMeike Baumgärtner
538eda10caSEbrahim Byagowi     * ``cmake -S llvm -B build -G <generator> [options]``
54da6384fbSMeike Baumgärtner
55905ccf8bSEvandro Menezes        Some common build system generators are:
56da6384fbSMeike Baumgärtner
57da6384fbSMeike Baumgärtner        * ``Ninja`` --- for generating [Ninja](https://ninja-build.org)
58da6384fbSMeike Baumgärtner          build files. Most llvm developers use Ninja.
59da6384fbSMeike Baumgärtner        * ``Unix Makefiles`` --- for generating make-compatible parallel makefiles.
60da6384fbSMeike Baumgärtner        * ``Visual Studio`` --- for generating Visual Studio projects and
61da6384fbSMeike Baumgärtner          solutions.
62da6384fbSMeike Baumgärtner        * ``Xcode`` --- for generating Xcode projects.
63da6384fbSMeike Baumgärtner
6402c01839SMichael Forster        Some common options:
65da6384fbSMeike Baumgärtner
664ae83bb2SLouis Dionne        * ``-DLLVM_ENABLE_PROJECTS='...'`` and ``-DLLVM_ENABLE_RUNTIMES='...'`` ---
674ae83bb2SLouis Dionne          semicolon-separated list of the LLVM sub-projects and runtimes you'd like to
684ae83bb2SLouis Dionne          additionally build. ``LLVM_ENABLE_PROJECTS`` can include any of: clang,
694ae83bb2SLouis Dionne          clang-tools-extra, cross-project-tests, flang, libc, libclc, lld, lldb,
704ae83bb2SLouis Dionne          mlir, openmp, polly, or pstl. ``LLVM_ENABLE_RUNTIMES`` can include any of
714ae83bb2SLouis Dionne          libcxx, libcxxabi, libunwind, compiler-rt, libc or openmp. Some runtime
724ae83bb2SLouis Dionne          projects can be specified either in ``LLVM_ENABLE_PROJECTS`` or in
734ae83bb2SLouis Dionne          ``LLVM_ENABLE_RUNTIMES``.
74da6384fbSMeike Baumgärtner
75da6384fbSMeike Baumgärtner          For example, to build LLVM, Clang, libcxx, and libcxxabi, use
764ae83bb2SLouis Dionne          ``-DLLVM_ENABLE_PROJECTS="clang" -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi"``.
77da6384fbSMeike Baumgärtner
78da6384fbSMeike Baumgärtner        * ``-DCMAKE_INSTALL_PREFIX=directory`` --- Specify for *directory* the full
79da6384fbSMeike Baumgärtner          path name of where you want the LLVM tools and libraries to be installed
804ae83bb2SLouis Dionne          (default ``/usr/local``). Be careful if you install runtime libraries: if
814ae83bb2SLouis Dionne          your system uses those provided by LLVM (like libc++ or libc++abi), you
824ae83bb2SLouis Dionne          must not overwrite your system's copy of those libraries, since that
834ae83bb2SLouis Dionne          could render your system unusable. In general, using something like
844ae83bb2SLouis Dionne          ``/usr`` is not advised, but ``/usr/local`` is fine.
85da6384fbSMeike Baumgärtner
86da6384fbSMeike Baumgärtner        * ``-DCMAKE_BUILD_TYPE=type`` --- Valid options for *type* are Debug,
87da6384fbSMeike Baumgärtner          Release, RelWithDebInfo, and MinSizeRel. Default is Debug.
88da6384fbSMeike Baumgärtner
89da6384fbSMeike Baumgärtner        * ``-DLLVM_ENABLE_ASSERTIONS=On`` --- Compile with assertion checks enabled
90da6384fbSMeike Baumgärtner          (default is Yes for Debug builds, No for all other build types).
91da6384fbSMeike Baumgärtner
928eda10caSEbrahim Byagowi      * ``cmake --build build [-- [options] <target>]`` or your build system specified above
93905ccf8bSEvandro Menezes        directly.
94da6384fbSMeike Baumgärtner
95da6384fbSMeike Baumgärtner        * The default target (i.e. ``ninja`` or ``make``) will build all of LLVM.
96da6384fbSMeike Baumgärtner
97da6384fbSMeike Baumgärtner        * The ``check-all`` target (i.e. ``ninja check-all``) will run the
98da6384fbSMeike Baumgärtner          regression tests to ensure everything is in working order.
99da6384fbSMeike Baumgärtner
100905ccf8bSEvandro Menezes        * CMake will generate targets for each tool and library, and most
101da6384fbSMeike Baumgärtner          LLVM sub-projects generate their own ``check-<project>`` target.
102da6384fbSMeike Baumgärtner
103905ccf8bSEvandro Menezes        * Running a serial build will be **slow**. To improve speed, try running a
104905ccf8bSEvandro Menezes          parallel build. That's done by default in Ninja; for ``make``, use the option
105bb50d47aSHeiko Thiel          ``-j NNN``, where ``NNN`` is the number of parallel jobs to run.
106bb50d47aSHeiko Thiel          In most cases, you get the best performance if you specify the number of CPU threads you have.
107bb50d47aSHeiko Thiel          On some Unix systems, you can specify this with ``-j$(nproc)``.
108da6384fbSMeike Baumgärtner
1091cb29916SPriyansh Singh      * For more information see [CMake](https://llvm.org/docs/CMake.html).
110da6384fbSMeike Baumgärtner
111da6384fbSMeike BaumgärtnerConsult the
112da6384fbSMeike Baumgärtner[Getting Started with LLVM](https://llvm.org/docs/GettingStarted.html#getting-started-with-llvm)
113da6384fbSMeike Baumgärtnerpage for detailed information on configuring and compiling LLVM. You can visit
114da6384fbSMeike Baumgärtner[Directory Layout](https://llvm.org/docs/GettingStarted.html#directory-layout)
115da6384fbSMeike Baumgärtnerto learn about the layout of the source code tree.
116ed76de7dSSylvestre Ledru
117ed76de7dSSylvestre Ledru## Getting in touch
118ed76de7dSSylvestre Ledru
119ed76de7dSSylvestre LedruJoin [LLVM Discourse forums](https://discourse.llvm.org/), [discord chat](https://discord.gg/xS7Z362) or #llvm IRC channel on [OFTC](https://oftc.net/).
120ed76de7dSSylvestre Ledru
121ed76de7dSSylvestre LedruThe LLVM project has adopted a [code of conduct](https://llvm.org/docs/CodeOfConduct.html) for
122ed76de7dSSylvestre Ledruparticipants to all modes of communication within the project.
123