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

Fujun Han llvmlistbot at llvm.org
Mon May 11 02:45:21 PDT 2026


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

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.

>From 25cf9f63ac4342f1c5b5e1e4054290bc64055194 Mon Sep 17 00:00:00 2001
From: Fujun Han <fujun.han at iluvatar.com>
Date: Mon, 11 May 2026 17:40:51 +0800
Subject: [PATCH] [MLIR] Make MLIRRegisterAllPasses depend on mlir-headers

RegisterAllPasses.cpp includes dialect Transforms/Passes.h headers that pull
in generated Passes.h.inc files. Those are produced by mlir-tblgen targets
that add_dependencies(mlir-headers ...). add_mlir_library only appended
mlir-generic-headers by default, so this TU could compile too early relative
to TableGen outputs and registerAllPasses() could miss newly added passes.

Signed-off-by: Fujun Han <fujun.han at iluvatar.com>
---
 mlir/lib/CMakeLists.txt | 6 ++++++
 1 file changed, 6 insertions(+)

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}



More information about the Mlir-commits mailing list