Update, Oct. 21: After the Clang Area Team accepted the proposal, the pull request enabling the ClangIR build by default was merged. In the RFC thread, LLVM developer Fangrui Song (MaskRay) said Chrome’s toolchain expects to disable it downstream, Android plans to configure it off and Red Hat may disable it, and the compile-time tracker now builds without it.
LLVM developers are debating whether to build ClangIR by default whenever Clang is compiled. Erich Keane opened the RFC on the LLVM Discourse forum on Sept. 4 along with a matching pull request. The change would not alter how Clang generates code: users would still have to pass -fclangir to use the new pipeline, and a -DCLANG_ENABLE_CIR=Off flag would let builders leave it out.
ClangIR is an MLIR-based intermediate representation that sits between Clang’s syntax tree and LLVM IR and keeps more of the original C and C++ semantics. “As many of you know, a large number of folks have been working on ClangIR implementation over the last few years,” Keane wrote. He said the work has been upstreamed to the point that its incubator repository closed about six months earlier.
The case for it
Keane said Clang with -fclangir passes more than 98% of the LLVM SingleSource test suite and 100% of MultiSource, and that the libcxx test suite is above 98%. A -fclangir stage-two build of Clang itself only gets through about 30% of a ninja build, which he attributed to a handful of ABI issues. He also listed features ClangIR still lacks, including modules, debug info, sanitizers and non-x86 target support, which is why the RFC does not propose turning -fclangir on by default.
Supporters pointed to early optimization and analysis work. Intern Rithik Sharma described a pass that recognizes standard library calls such as std::find and lowers them to C library routines like memchr. Bruno Cardoso Lopes said a CIR-based version of clang-tidy’s bugprone-use-after-move check ran 3 to 5 times faster on a large share of his team’s codebase. GPU work predates the RFC: a 2024 Google Summer of Code project added OpenCL C support, and all 20 OpenCL C benchmarks from the Polybench-GPU suite compiled through ClangIR and passed validation.
The cost
Building ClangIR pulls in MLIR as a Clang dependency. Keane estimated that would add roughly a third to the compiler’s build time. Alexis Engelke measured a 131.5% increase in build wall time and a 209.6% increase in peak memory on his setup, and argued the cost outweighs the benefit for people who only want a C/C++ front end for LLVM IR. Tom Stellard asked why the code couldn’t be enabled only in pre-commit CI instead. Keane said building it by default is how ClangIR reaches distributions and users, and that he is looking at trimming how much of MLIR gets compiled.


WebProNews is an iEntry Publication