ClangIR#
Warning
ClangIR is not included in a default clang build yet. The documentation may be incomplete and out-of-date.
ClangIR (CIR) is a high-level representation in Clang that reflects aspects of the C/C++ languages and their extensions. It is implemented using MLIR and occupies a position between Clang’s AST and LLVM IR.
Follow and contribute to upstream development through the
ClangIR-labeled issues and pull
requests on
llvm-project. See the ClangIR Design
Documents for in-depth coverage of CIR’s design.
Using ClangIR#
Note
Until #221291 lands, you
need a build of Clang with CIR enabled. Configure
LLVM with
-DLLVM_ENABLE_PROJECTS="clang;mlir" and -DCLANG_ENABLE_CIR=ON.
ClangIR is an MLIR dialect tightly integrated with Clang: it lives in the Clang project rather than as a standalone in-tree dialect.
Pass -fclangir to the Clang driver to compile through CIR (AST to CIR to
CIR passes to LLVM IR and the backend). In order to inspect CIR output, use
-emit-cir, the equivalent of -emit-llvm for CIR.
See this Compiler Explorer example, which shows the flow of compilation through CIR, from higher-level CIR constructs to lower-level ones, the pipeline viewer is convenient for following along.
ClangIR Design Documents#
RFCs#
September 2026: RFC: Enable ClangIR Build By Default
June 2026: [RFC][ClangIR] Making CIR Pipeline Boundaries First-Class Driver Artifacts
January 2024: RFC: Upstreaming ClangIR
June 2022: RFC: An MLIR based Clang IR (CIR)
Talks and posts#
Dec 2025: GSoC 2025: ClangIR upstreaming
Oct 2025: US LLVM Developers Meeting (keynote). ClangIR: Upstreaming an Incubator Project. video, pdf
Oct 2025: A High-Level Overview of Address Spaces: Their Place in ClangIR and LLVM
Jun 2025: Asia LLVM. ClangIR’s Footprint: A quick compile-time impact report. video, pdf
Mar 2025: Cambridge Computer Science Group Projects. Award on technical achievement. CUDA Support for ClangIR. video
Nov 2024: Supercomputing Workshop. Introducing ClangIR, High-Level IR for the C/C++ Family of Languages. pdf
Sep 2024: GSoC 2024: ABI Lowering in ClangIR
Oct 2023: US LLVM Developers Meeting. Evolution of ClangIR: A Year of Progress, Challenges, and Future Plans. video, pdf
History#
ClangIR started in October 2021. In June 2022, an RFC proposing to incorporate the project — then in very early stages — into llvm-project led to ClangIR becoming part of the LLVM incubator, where development happened for the following years. In January 2024, the upstreaming RFC was accepted as the graduation step from the incubator (now archived), and ClangIR has been developed directly upstream ever since, superseding the incubator in most functionality.