What Are the Main Sub-Projects Within the LLVM Monorepo?
The LLVM monorepo hosts 15+ distinct sub-projects—including the core LLVM infrastructure, Clang front-end, LLDB debugger, compiler-rt sanitizers, libc++ standard library, MLIR framework, and specialized tools like Flang and Bolt—each organized as a top-level directory with independent build systems.
The llvm/llvm-project repository consolidates the entire LLVM ecosystem into a single version-controlled codebase. Understanding the main sub-projects within the LLVM monorepo is essential for contributors and users who need to build specific components or integrate LLVM tools into their development workflows. Each sub-project resides in its own top-level directory and contains dedicated CMake configurations, test suites, and documentation.
Core Compiler Infrastructure
The foundation of the LLVM ecosystem consists of the intermediate representation, optimization passes, and language front-ends.
LLVM Core
Located in llvm/, this sub-project provides the core compiler infrastructure: the LLVM intermediate representation (IR), optimization passes, code generators, and the main llvm-* libraries. The entry point for building is llvm/CMakeLists.txt, which defines targets for the X86, AArch64, and other backends.
Clang
The clang/ directory houses the C, C++, Objective-C, and Objective-C++ front-end. Clang provides the clang driver, libclang C API, and the clang-tooling infrastructure for building source-level tools. Configure builds using clang/CMakeLists.txt.
Clang-tools-extra
Found under clang/tools/extra/, this directory contains additional tools that ship alongside Clang, including clang-tidy (linting), clangd (language server), clang-format (code formatting), and clang-proxy.
Runtime Libraries and Sanitizers
These sub-projects provide essential runtime support for compiled programs.
compiler-rt
The compiler-rt/ directory contains runtime libraries for sanitizers such as AddressSanitizer, ThreadSanitizer, and MemorySanitizer, plus compiler-builtins implementations. When you compile with -fsanitize=address, Clang automatically links against the runtime libraries built from this sub-project.
libcxx, libcxxabi, and libunwind
- libcxx/: Implements the C++ standard library (libc++)
- libcxxabi/: Provides the C++ ABI library for exception handling and RTTI
- libunwind/: Supplies a portable unwind library compatible with the C++ ABI
OpenMP Runtime
The openmp/ directory contains libomp, the OpenMP runtime library required for programs compiled with -fopenmp.
Developer Tools
LLDB
Located in lldb/, this is the LLVM debugger—a modern, high-performance debugger supporting multiple languages and platforms. The build is configured via lldb/CMakeLists.txt.
lld
The lld/ sub-project implements the LLVM linker, supporting both ELF (Linux/Unix) and Mach-O (macOS) binary formats.
Bolt
Found in bolt/, Binary Optimizer and Layout Tool is a post-link optimizer that rewrites binaries to improve performance through better code layout and optimization.
Specialized Compilation Frameworks
MLIR
The mlir/ directory contains the Multi-Level Intermediate Representation framework for building reusable compiler infrastructure. MLIR enables domain-specific compiler development through customizable dialects and transformations.
Polly
Located in polly/, this is a high-level loop optimizer using polyhedral compilation techniques to optimize loop nests automatically.
Flang
The flang/ sub-project provides the Fortran front-end for LLVM, enabling compilation of modern Fortran standards.
Building Multiple Sub-Projects Together
When configuring the monorepo build, use the LLVM_ENABLE_PROJECTS CMake variable to select which sub-projects to compile. The following example builds the core infrastructure plus Clang, the linker, debugger, MLIR, and specialized tools:
# Clone the repository
git clone --depth 1 https://github.com/llvm/llvm-project.git
cd llvm-project
# Create build directory
mkdir build && cd build
# Configure with multiple sub-projects
cmake -G "Ninja" \
-DLLVM_ENABLE_PROJECTS="clang;lld;lldb;mlir;polly;flang;bolt" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_TARGETS_TO_BUILD="X86;AArch64" \
../llvm
ninja
Key configuration points:
- List desired sub-projects in
LLVM_ENABLE_PROJECTSseparated by semicolons - Each sub-project listed must have its directory present at the top level
- The build system automatically resolves dependencies between selected components
Practical Usage Examples
Using libc++ Instead of libstdc++
Compile C++ programs against the LLVM standard library:
// example.cpp
#include <vector>
#include <iostream>
int main() {
std::vector<int> v = {1, 2, 3};
for (int x : v) std::cout << x << ' ';
return 0;
}
clang++ -stdlib=libc++ -lc++abi \
-L/path/to/libcxx/build/lib \
-I/path/to/libcxx/include \
example.cpp -o example
The -stdlib=libc++ flag instructs Clang to use the headers and libraries from the libcxx sub-project rather than the system default.
Running AddressSanitizer
The compiler-rt sub-project provides runtime support for sanitizers:
clang -fsanitize=address -g buggy.c -o buggy
./buggy
When a memory error is detected, AddressSanitizer prints a detailed report using the runtime library from compiler-rt/.
Defining an MLIR Dialect
For compiler developers extending MLIR:
#include "mlir/IR/Dialect.h"
#include "mlir/IR/Builders.h"
using namespace mlir;
struct MyDialect : public Dialect {
explicit MyDialect(MLIRContext *ctx) : Dialect("my", ctx) {}
};
int main() {
MLIRContext ctx;
ctx.getOrLoadDialect<MyDialect>();
// Build MLIR operations using the custom dialect
}
Compile against the mlir libraries:
clang++ dialect.cpp -Illvm/include -Imlir/include \
-Lbuild/lib -lMLIR -lLLVMCore -o custom_dialect
Summary
- The LLVM monorepo organizes 15+ sub-projects as top-level directories, each with independent CMake configurations
- Core infrastructure lives in
llvm/(IR and backends) andclang/(C/C++ front-end) - Runtime support comes from
compiler-rt/(sanitizers),libcxx/(standard library), andlibunwind/(stack unwinding) - Developer tools include
lldb/(debugger),lld/(linker), andbolt/(post-link optimizer) - Specialized frameworks such as
mlir/(multi-level IR),flang/(Fortran), andpolly/(polyhedral optimization) support domain-specific compilation needs - Use
LLVM_ENABLE_PROJECTSin the CMake configuration to select which components to build from the unified repository
Frequently Asked Questions
How do I build only specific sub-projects from the LLVM monorepo?
Configure CMake with the LLVM_ENABLE_PROJECTS variable listing only the directories you need. For example, -DLLVM_ENABLE_PROJECTS="clang;lld" builds only Clang and the linker while skipping LLDB, MLIR, and other components. Run the configuration from a build directory pointing to ../llvm as the source root.
What is the difference between libcxx and libcxxabi in the LLVM monorepo?
libcxx implements the C++ standard library (containers, algorithms, iostreams), while libcxxabi implements the low-level ABI details required for exception handling, dynamic_cast, and thread-safe static initialization. When building libc++ from source, you typically need both sub-projects, linking with -lc++abi when using -stdlib=libc++.
Which sub-project provides AddressSanitizer and other sanitizers?
compiler-rt supplies the runtime libraries for AddressSanitizer, ThreadSanitizer, MemorySanitizer, and other instrumentation tools. When you compile with -fsanitize=address, Clang automatically links the appropriate runtime object files built from the compiler-rt/ directory.
Where is the Fortran compiler in the LLVM project?
Flang is the Fortran front-end located in the flang/ directory at the top level of the monorepo. It supports modern Fortran standards and integrates with the LLVM back-end for code generation. Build it by including flang in your LLVM_ENABLE_PROJECTS list.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →