[clang] [CIR][CMake] Add missing MLIR tablegen dependencies to CIR libraries (PR #235185)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 23 19:33:34 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Konstantinos Parasyris (koparasy)
<details>
<summary>Changes</summary>
ClangIR libraries include MLIR and CIR headers that need tablegen-generated `.inc` files, but nothing makes their objects wait for those files. These libraries list `MLIRIR` and friends under a bare `LINK_LIBS`, so the generated headers have to come from `DEPENDS`, and the existing `DEPENDS` lists are incomplete.
In a cold build (no `.ninja_deps`), this is a race. A parallel build can compile these objects before the headers exist:
```
fatal error: mlir/IR/BuiltinTypeInterfaces.h.inc: No such file or directory
```
It is rarely seen because incremental builds remember the header dependency, and a full `ninja` usually generates the headers in time through other libraries that do depend on them. It started showing up on a ccache'd downstream bot after ClangIR was enabled by default (#<!-- -->221291).
Deterministic repro on a fresh build directory:
```
cmake -G Ninja -S llvm -B build
-DLLVM_ENABLE_PROJECTS=clang DCLANG_ENABLE_CIR=ON
ninja -C build obj.MLIRCIRInterfaces
```
`obj.clangCIRLoweringCommon`, `obj.clangCIRLoweringDirectToLLVM` and `obj.clangCIRFrontendAction` fail the same way.
Fix:
- Add `mlir-headers` to `DEPENDS` of those four libraries. This matches MLIR's own `add_mlir_dialect_library`/`add_mlir_conversion_library` convention. `mlir-generic-headers` is not enough: it misses dialect headers that CIR includes, such as Ptr's `MemorySpaceAttrInterfaces.h.inc` and LLVMIR's `LLVMTypeInterfaces.h.inc`.
- Add `MLIRCIRPassIncGen` to `clangCIRLoweringCommon` and `clangCIRLoweringDirectToLLVM`. Both include `clang/CIR/Dialect/Passes.h`, which needs the generated `Passes.h.inc`.
Tested by building each of the 12 CIR object libraries as its only target, starting from a clean build directory each time. Without this change, the four libraries above fail. With it, all 12 build.
---
Full diff: https://github.com/llvm/llvm-project/pull/235185.diff
4 Files Affected:
- (modified) clang/lib/CIR/FrontendAction/CMakeLists.txt (+1)
- (modified) clang/lib/CIR/Interfaces/CMakeLists.txt (+1)
- (modified) clang/lib/CIR/Lowering/CMakeLists.txt (+2)
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/CMakeLists.txt (+2)
``````````diff
diff --git a/clang/lib/CIR/FrontendAction/CMakeLists.txt b/clang/lib/CIR/FrontendAction/CMakeLists.txt
index f83e5b04b9ada..411f1acc5f2b0 100644
--- a/clang/lib/CIR/FrontendAction/CMakeLists.txt
+++ b/clang/lib/CIR/FrontendAction/CMakeLists.txt
@@ -16,6 +16,7 @@ add_clang_library(clangCIRFrontendAction
MLIRBuiltinLocationAttributesIncGen
MLIRBytecodeOpInterfaceIncGen
MLIRBuiltinOpsIncGen
+ mlir-headers
LINK_LIBS
clangAST
diff --git a/clang/lib/CIR/Interfaces/CMakeLists.txt b/clang/lib/CIR/Interfaces/CMakeLists.txt
index 960dd0dcca5f4..5665bccf55ca0 100644
--- a/clang/lib/CIR/Interfaces/CMakeLists.txt
+++ b/clang/lib/CIR/Interfaces/CMakeLists.txt
@@ -25,6 +25,7 @@ add_clang_library(MLIRCIRInterfaces
MLIRInferTypeOpInterfaceIncGen
MLIRLoopLikeInterfaceIncGen
MLIRSideEffectInterfacesIncGen
+ mlir-headers
LINK_LIBS
MLIRIR
diff --git a/clang/lib/CIR/Lowering/CMakeLists.txt b/clang/lib/CIR/Lowering/CMakeLists.txt
index 93ca5436d96f9..5a3171b22168d 100644
--- a/clang/lib/CIR/Lowering/CMakeLists.txt
+++ b/clang/lib/CIR/Lowering/CMakeLists.txt
@@ -10,6 +10,8 @@ add_clang_library(clangCIRLoweringCommon
DEPENDS
MLIRBuiltinLocationAttributesIncGen
MLIRBytecodeOpInterfaceIncGen
+ MLIRCIRPassIncGen
+ mlir-headers
LINK_LIBS
clangCIR
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/CMakeLists.txt b/clang/lib/CIR/Lowering/DirectToLLVM/CMakeLists.txt
index ff68221ad59df..9bb9940b0cbd5 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/CMakeLists.txt
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/CMakeLists.txt
@@ -16,6 +16,8 @@ add_clang_library(clangCIRLoweringDirectToLLVM
MLIRBuiltinLocationAttributesIncGen
MLIRBytecodeOpInterfaceIncGen
MLIRCIROpInterfacesIncGen
+ MLIRCIRPassIncGen
+ mlir-headers
LINK_LIBS
clangCIRLoweringCommon
``````````
</details>
https://github.com/llvm/llvm-project/pull/235185
More information about the cfe-commits
mailing list