Alexis Engelke b82c7fc652
[CMake][LLVM] Add PCH infrastructure and LLVMSupport PCH (#176420)
This patch implements PCH support. PCH is enabled by default, unless
noted below, and can be disabled with
-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON.

* Libraries can define precompiled headers using a newly added
PRECOMPILE_HEADERS keyword. If specified, the listed headers will be
compiled into a pre-compiled header using standard CMake mechanisms.

* Libraries that don't define their own PRECOMPILE_HEADERS but directly
depend on a library or component that defines its own PCH will reuse
that PCH. This reuse is not transitive to prevent excessive use of
unrelated headers. If multiple dependencies provide a reusable PCH, the
first one with the longest dependency chain (stored in the CMake target
property LLVM_PCH_PRIORITY) is used. However, due to CMake limitations,
only PCH from targets that are already defined can be reused; therefore
libraries that should reuse a PCH must be defined later in the CMake
file (=> add_subdirectory order matters).

* Libraries and executables can prevent PCH reuse with the keyword
DISABLE_PCH_REUSE. This both prevents reuse from dependencies and reuse
by other dependants. This is useful when, e.g., internal headers are
used in the PCH or the used headers are unlikely to provide benefits for
dependants.

* Precompiled headers are only used for C++ sources, not for C.

* With GCC, PCH provide very little benefits (tested with GCC 14 and 15)
due to increased template instatiation costs, but substantially increase
max-rss and build directory size. Therefore, disable PCH with GCC by
default; this can be explicitly overridden on the command line with
-DCMAKE_DISABLE_PRECOMPILE_HEADERS=OFF.

* With ccache and non-Clang compilers, changes in macro definitions are
not always accurately forwarded with ccache's preprocessed mode. To be
on the safe side, when ccache is enabled, disable PCH with all non-Clang
compilers; this can be explicitly overridden.

* With sccache, changes in macro definitions are not identified, which
in some cases can lead to false positive cache hits. Conservatively
disable PCH with sccache by default.

* Add a base PCH to LLVMSupport, which includes widely used standard
library and Support+ADT headers. The pch.h is placed in include so that
later PCH headers can extend that list of headers.

* Flang PCH use is ported to the general mechanism.

Addition of PCH headers for other components (e.g., IR, CodeGen) will be
posted as separate PRs.

RFC:
https://discourse.llvm.org/t/rfc-use-pre-compiled-headers-to-speed-up-llvm-build-by-1-5-2x/89345
2026-02-20 12:07:18 +01:00
2026-01-21 23:14:07 +01:00

The LLVM Compiler Infrastructure

OpenSSF Scorecard OpenSSF Best Practices libc++

Welcome to the LLVM project!

This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.

The LLVM project has multiple components. The core of the project is itself called "LLVM". This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.

C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.

Other components include: the libc++ C++ standard library, the LLD linker, and more.

Getting the Source Code and Building LLVM

Consult the Getting Started with LLVM page for information on building and running LLVM.

For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.

Getting in touch

Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.

The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.

Description
The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
Readme 5.7 GiB
Languages
LLVM 42.4%
C++ 30.1%
C 12.8%
Assembly 9.8%
MLIR 1.6%
Other 2.9%