[Mlir-commits] [mlir] [MLIR] Make MLIRRegisterAllPasses depend on mlir-headers (PR #196913)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon May 11 02:46:15 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Fujun Han (Peter9606)

<details>
<summary>Changes</summary>

Summary
Declare an explicit CMake dependency from MLIRRegisterAllPasses on the mlir-headers aggregate target so RegisterAllPasses.cpp is not compiled before dialect pass TableGen outputs (e.g. Passes.h.inc) are up to date.

Problem
RegisterAllPasses.cpp includes many dialect Transforms/Passes.h headers, which pull in TableGen-generated Passes.h.inc files. Those generated headers are produced by mlir-tblgen targets that are wired into the mlir-headers custom target (via add_mlir_dialect_tablegen_target / add_dependencies(mlir-headers …)).

MLIRRegisterAllPasses is built with add_mlir_library, which always adds mlir-generic-headers to DEPENDS but does not add mlir-headers by default. That leaves a real build-order gap: the translation unit can compile while generated pass registration headers are stale or not yet regenerated for the current build graph. In the worst case, registerAllPasses() can omit passes that exist in Passes.td and their C++ implementations—symptoms such as mlir-opt --help missing a pass until a full rebuild match that failure mode.

This is not specific to any one dialect; the same class of issue applies whenever a newly added pass is registered through generated headers included from this TU (upstream examples include GPU attach-target style passes and AMDGPU-related pipelines that surface on mlir-opt --help).

Solution
In mlir/lib/CMakeLists.txt, for MLIRRegisterAllPasses, add:

DEPENDS
mlir-headers
after PARTIAL_SOURCES_INTENDED and before LINK_LIBS PUBLIC, with a short comment documenting why the dependency exists.

Testing
No new lit test: validating this race properly would require encoding Ninja/build-graph ordering or reproducing a parallel incremental race in CI, which is brittle. The fix is the substantive correction; the comment and this description document the invariant for reviewers.
Local verification after configure + build:
```
cmake --build <build> --target mlir-opt -j$(nproc)
<build>/bin/mlir-opt --help | grep -E 'rocdl-attach-target|nvvm-attach-target|amdgpu-'
```
(or any stable upstream pass names appropriate to your tree) to confirm GPU/AMDGPU-related passes still appear in the help listing.

---
Full diff: https://github.com/llvm/llvm-project/pull/196913.diff


1 Files Affected:

- (modified) mlir/lib/CMakeLists.txt (+6) 


``````````diff
diff --git a/mlir/lib/CMakeLists.txt b/mlir/lib/CMakeLists.txt
index d7a6e28d98586..576942b78f4a8 100644
--- a/mlir/lib/CMakeLists.txt
+++ b/mlir/lib/CMakeLists.txt
@@ -41,6 +41,12 @@ add_mlir_library(MLIRRegisterAllPasses
 
   PARTIAL_SOURCES_INTENDED
 
+  # This TU includes dialect pass registration headers that depend on
+  # TableGen outputs (e.g. Passes.h.inc) wired into mlir-headers. Without this
+  # dependency it may compile before those headers are regenerated.
+  DEPENDS
+  mlir-headers
+
   LINK_LIBS PUBLIC
   ${dialect_libs} # Some passes are part of the dialect libs
   ${conversion_libs}

``````````

</details>


https://github.com/llvm/llvm-project/pull/196913


More information about the Mlir-commits mailing list