[Mlir-commits] [mlir] [mlir, CMake] Depend only on the generated headers included across dialects (PR #221829)
Fangrui Song
llvmlistbot at llvm.org
Mon Sep 7 13:49:42 PDT 2026
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/221829
add_mlir_dialect_library and its conversion, extension and translation
counterparts depend on mlir-headers, which depends on the tablegen
target of every dialect. Linking one dialect therefore requires
generating every dialect's headers: building clang with ClangIR runs
tablegen over 231 MLIR .td files, covering Linalg, Tosa, SPIRV, XeGPU,
ArmSME, MPI and WasmSSA.
Some tablegen targets produce headers that other dialects' public
headers include. Move them to mlir-generic-headers, which
add_mlir_library already depends on, and drop the blanket dependency.
MLIRTransformDialect relied on it for its own generated headers; declare
them.
`ninja clang` with CIR enabled drops from 4577 to 4158 build edges and
from 231 to 135 .td files.
Created by Opus 5
>From 646389ac80fa1cd8f196a9709df204b275a13c34 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Sun, 6 Sep 2026 18:18:39 -0700
Subject: [PATCH] [mlir,CMake] Depend only on the generated headers included
across dialects
add_mlir_dialect_library and its conversion, extension and translation
counterparts depend on mlir-headers, which depends on the tablegen
target of every dialect. Linking one dialect therefore requires
generating every dialect's headers: building clang with ClangIR runs
tablegen over 231 MLIR .td files, covering Linalg, Tosa, SPIRV, XeGPU,
ArmSME, MPI and WasmSSA.
Some tablegen targets produce headers that other dialects' public
headers include. Move them to mlir-generic-headers, which
add_mlir_library already depends on, and drop the blanket dependency.
MLIRTransformDialect relied on it for its own generated headers; declare
them.
`ninja clang` with CIR enabled drops from 4577 to 4158 build edges and
from 231 to 135 .td files.
Created by Opus 5
---
mlir/cmake/modules/AddMLIR.cmake | 8 ++++----
mlir/include/mlir/Dialect/ArmSME/IR/CMakeLists.txt | 1 +
mlir/include/mlir/Dialect/Bufferization/IR/CMakeLists.txt | 4 ++--
mlir/include/mlir/Dialect/DLTI/CMakeLists.txt | 2 +-
mlir/include/mlir/Dialect/NVGPU/IR/CMakeLists.txt | 1 +
mlir/include/mlir/Dialect/SparseTensor/IR/CMakeLists.txt | 2 +-
mlir/include/mlir/Dialect/Transform/IR/CMakeLists.txt | 4 ++--
mlir/include/mlir/Dialect/Vector/IR/CMakeLists.txt | 1 +
mlir/include/mlir/Dialect/XeGPU/IR/CMakeLists.txt | 2 +-
mlir/include/mlir/Transforms/CMakeLists.txt | 2 +-
mlir/lib/Analysis/CMakeLists.txt | 3 ---
mlir/lib/Dialect/Transform/IR/CMakeLists.txt | 5 +++++
12 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake
index d3f534a02f9de..09bfca0f6bf60 100644
--- a/mlir/cmake/modules/AddMLIR.cmake
+++ b/mlir/cmake/modules/AddMLIR.cmake
@@ -677,25 +677,25 @@ endfunction()
# Declare the library associated with a dialect.
function(add_mlir_dialect_library name)
set_property(GLOBAL APPEND PROPERTY MLIR_DIALECT_LIBS ${name})
- add_mlir_library(${ARGV} DEPENDS mlir-headers)
+ add_mlir_library(${ARGV})
endfunction(add_mlir_dialect_library)
# Declare the library associated with a conversion.
function(add_mlir_conversion_library name)
set_property(GLOBAL APPEND PROPERTY MLIR_CONVERSION_LIBS ${name})
- add_mlir_library(${ARGV} DEPENDS mlir-headers)
+ add_mlir_library(${ARGV})
endfunction(add_mlir_conversion_library)
# Declare the library associated with an extension.
function(add_mlir_extension_library name)
set_property(GLOBAL APPEND PROPERTY MLIR_EXTENSION_LIBS ${name})
- add_mlir_library(${ARGV} DEPENDS mlir-headers)
+ add_mlir_library(${ARGV})
endfunction(add_mlir_extension_library)
# Declare the library associated with a translation.
function(add_mlir_translation_library name)
set_property(GLOBAL APPEND PROPERTY MLIR_TRANSLATION_LIBS ${name})
- add_mlir_library(${ARGV} DEPENDS mlir-headers)
+ add_mlir_library(${ARGV})
endfunction(add_mlir_translation_library)
# Verification tools to aid debugging.
diff --git a/mlir/include/mlir/Dialect/ArmSME/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/ArmSME/IR/CMakeLists.txt
index b937f192c2515..9d5be06278212 100644
--- a/mlir/include/mlir/Dialect/ArmSME/IR/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/ArmSME/IR/CMakeLists.txt
@@ -1,4 +1,5 @@
add_mlir_dialect(ArmSME arm_sme ArmSME)
+add_dependencies(mlir-generic-headers MLIRArmSMEIncGen)
# Generate declarations and definitions of ArmSME Ops
set(LLVM_TARGET_DEFINITIONS ArmSMEOps.td)
diff --git a/mlir/include/mlir/Dialect/Bufferization/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/Bufferization/IR/CMakeLists.txt
index 4e79862ec9a7b..2ffced4187272 100644
--- a/mlir/include/mlir/Dialect/Bufferization/IR/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/Bufferization/IR/CMakeLists.txt
@@ -8,9 +8,9 @@ add_mlir_interface(BufferViewFlowOpInterface)
set(LLVM_TARGET_DEFINITIONS BufferizationEnums.td)
mlir_tablegen(BufferizationEnums.h.inc -gen-enum-decls)
mlir_tablegen(BufferizationEnums.cpp.inc -gen-enum-defs)
-add_mlir_dialect_tablegen_target(MLIRBufferizationEnumsIncGen)
+add_mlir_generic_tablegen_target(MLIRBufferizationEnumsIncGen)
set(LLVM_TARGET_DEFINITIONS BufferizationTypeInterfaces.td)
mlir_tablegen(BufferizationTypeInterfaces.h.inc -gen-type-interface-decls)
mlir_tablegen(BufferizationTypeInterfaces.cpp.inc -gen-type-interface-defs)
-add_mlir_dialect_tablegen_target(MLIRBufferizationTypeInterfacesIncGen)
+add_mlir_generic_tablegen_target(MLIRBufferizationTypeInterfacesIncGen)
diff --git a/mlir/include/mlir/Dialect/DLTI/CMakeLists.txt b/mlir/include/mlir/Dialect/DLTI/CMakeLists.txt
index a7695e67e2d8a..93fc522791666 100644
--- a/mlir/include/mlir/Dialect/DLTI/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/DLTI/CMakeLists.txt
@@ -6,4 +6,4 @@ add_mlir_doc(DLTIAttrs DLTIDialect Dialects/ -gen-dialect-doc)
set(LLVM_TARGET_DEFINITIONS DLTIAttrs.td)
mlir_tablegen(DLTIAttrs.h.inc -gen-attrdef-decls -attrdefs-dialect=dlti)
mlir_tablegen(DLTIAttrs.cpp.inc -gen-attrdef-defs -attrdefs-dialect=dlti)
-add_mlir_dialect_tablegen_target(MLIRDLTIAttrsIncGen)
+add_mlir_generic_tablegen_target(MLIRDLTIAttrsIncGen)
diff --git a/mlir/include/mlir/Dialect/NVGPU/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/NVGPU/IR/CMakeLists.txt
index 02e7a5307b201..e52a169c2b620 100644
--- a/mlir/include/mlir/Dialect/NVGPU/IR/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/NVGPU/IR/CMakeLists.txt
@@ -1,4 +1,5 @@
add_mlir_dialect(NVGPU nvgpu)
+add_dependencies(mlir-generic-headers MLIRNVGPUIncGen)
add_mlir_doc(NVGPUOps NVGPU Dialects/ -gen-dialect-doc -dialect nvgpu)
set(LLVM_TARGET_DEFINITIONS NVGPUOps.td)
diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/SparseTensor/IR/CMakeLists.txt
index 12048b494cf43..abc23a711a928 100644
--- a/mlir/include/mlir/Dialect/SparseTensor/IR/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/SparseTensor/IR/CMakeLists.txt
@@ -16,4 +16,4 @@ add_mlir_dialect_tablegen_target(MLIRSparseTensorTypesIncGen)
set(LLVM_TARGET_DEFINITIONS SparseTensorInterfaces.td)
mlir_tablegen(SparseTensorInterfaces.h.inc -gen-op-interface-decls)
mlir_tablegen(SparseTensorInterfaces.cpp.inc -gen-op-interface-defs)
-add_mlir_dialect_tablegen_target(MLIRSparseTensorInterfacesIncGen)
+add_mlir_generic_tablegen_target(MLIRSparseTensorInterfacesIncGen)
diff --git a/mlir/include/mlir/Dialect/Transform/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/Transform/IR/CMakeLists.txt
index 7ec923bfa4a0e..fe6c6c85e0304 100644
--- a/mlir/include/mlir/Dialect/Transform/IR/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/Transform/IR/CMakeLists.txt
@@ -16,10 +16,10 @@ add_mlir_doc(TransformTypes TransformTypes Dialects/ -gen-typedef-doc -dialect=t
set(LLVM_TARGET_DEFINITIONS TransformAttrs.td)
mlir_tablegen(TransformDialectEnums.h.inc -gen-enum-decls)
mlir_tablegen(TransformDialectEnums.cpp.inc -gen-enum-defs)
-add_mlir_dialect_tablegen_target(MLIRTransformDialectEnumIncGen)
+add_mlir_generic_tablegen_target(MLIRTransformDialectEnumIncGen)
mlir_tablegen(TransformAttrs.h.inc -gen-attrdef-decls)
mlir_tablegen(TransformAttrs.cpp.inc -gen-attrdef-defs)
-add_mlir_dialect_tablegen_target(MLIRTransformDialectAttributesIncGen)
+add_mlir_generic_tablegen_target(MLIRTransformDialectAttributesIncGen)
add_mlir_dialect(TransformOps transform)
add_mlir_doc(TransformOps TransformOps Dialects/ -gen-op-doc -dialect=transform)
diff --git a/mlir/include/mlir/Dialect/Vector/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/Vector/IR/CMakeLists.txt
index ede818b9b3496..23af5c099b0c5 100644
--- a/mlir/include/mlir/Dialect/Vector/IR/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/Vector/IR/CMakeLists.txt
@@ -1,4 +1,5 @@
add_mlir_dialect(Vector vector)
+add_dependencies(mlir-generic-headers MLIRVectorIncGen)
add_mlir_doc(VectorOps VectorOps Dialects/ -gen-op-doc -dialect=vector)
# Add Vector operations
diff --git a/mlir/include/mlir/Dialect/XeGPU/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/XeGPU/IR/CMakeLists.txt
index b10219f71b531..5f9d534576fd4 100644
--- a/mlir/include/mlir/Dialect/XeGPU/IR/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/XeGPU/IR/CMakeLists.txt
@@ -19,4 +19,4 @@ add_mlir_dialect_tablegen_target(MLIRXeGPUAttrInterfaceIncGen)
set(LLVM_TARGET_DEFINITIONS XeGPUAttrs.td)
mlir_tablegen(XeGPUOpInterface.h.inc -gen-op-interface-decls)
mlir_tablegen(XeGPUOpInterface.cpp.inc -gen-op-interface-defs)
-add_mlir_dialect_tablegen_target(MLIRXeGPUOpInterfaceIncGen)
+add_mlir_generic_tablegen_target(MLIRXeGPUOpInterfaceIncGen)
diff --git a/mlir/include/mlir/Transforms/CMakeLists.txt b/mlir/include/mlir/Transforms/CMakeLists.txt
index 1b57a3482c1bb..3340702ca9dec 100644
--- a/mlir/include/mlir/Transforms/CMakeLists.txt
+++ b/mlir/include/mlir/Transforms/CMakeLists.txt
@@ -7,6 +7,6 @@ add_mlir_dialect_tablegen_target(MLIRTransformsPassIncGen)
set(LLVM_TARGET_DEFINITIONS DialectInlinerInterface.td)
mlir_tablegen(DialectInlinerInterface.h.inc -gen-dialect-interface-decls)
-add_mlir_dialect_tablegen_target(MLIRTransformsDialectInterfaceIncGen)
+add_mlir_generic_tablegen_target(MLIRTransformsDialectInterfaceIncGen)
add_mlir_doc(Passes GeneralPasses ./ -gen-pass-doc)
diff --git a/mlir/lib/Analysis/CMakeLists.txt b/mlir/lib/Analysis/CMakeLists.txt
index 2712ab503663e..43d71aaf5e2dc 100644
--- a/mlir/lib/Analysis/CMakeLists.txt
+++ b/mlir/lib/Analysis/CMakeLists.txt
@@ -47,9 +47,6 @@ add_mlir_library(MLIRAnalysis
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Analysis
- DEPENDS
- mlir-headers
-
LINK_LIBS PUBLIC
MLIRCallInterfaces
MLIRControlFlowInterfaces
diff --git a/mlir/lib/Dialect/Transform/IR/CMakeLists.txt b/mlir/lib/Dialect/Transform/IR/CMakeLists.txt
index 5b4989f328e69..35ebe59cc21dc 100644
--- a/mlir/lib/Dialect/Transform/IR/CMakeLists.txt
+++ b/mlir/lib/Dialect/Transform/IR/CMakeLists.txt
@@ -5,6 +5,11 @@ add_mlir_dialect_library(MLIRTransformDialect
TransformTypes.cpp
Utils.cpp
+ DEPENDS
+ MLIRTransformDialectIncGen
+ MLIRTransformOpsIncGen
+ MLIRTransformTypesIncGen
+
LINK_LIBS PUBLIC
MLIRCastInterfaces
MLIRFunctionInterfaces
More information about the Mlir-commits
mailing list