[clang] [CMake] Link only the MLIR dialects ClangIR uses (PR #221616)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 6 17:25:05 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Fangrui Song (MaskRay)
<details>
<summary>Changes</summary>
CIR's sources reference Arith, DLTI, Func, LLVM, OpenACC, OpenMP and
Ptr, and cir-opt registers only the CIR dialects plus MemRef and LLVM.
Link those instead, which keeps Linalg, Vector, SPIRV, SparseTensor,
Tosa and GPU out of the clang build graph.
CLANG_ENABLE_CIR=ON adds 2135 build edges to the clang target; this
removes 694 of them.
LLM-aided
---
Full diff: https://github.com/llvm/llvm-project/pull/221616.diff
6 Files Affected:
- (modified) clang/lib/CIR/CodeGen/CMakeLists.txt (+8-4)
- (modified) clang/lib/CIR/FrontendAction/CMakeLists.txt (-2)
- (modified) clang/lib/CIR/Interfaces/CMakeLists.txt (-1)
- (modified) clang/lib/CIR/Lowering/CMakeLists.txt (-3)
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/CMakeLists.txt (+5-3)
- (modified) clang/tools/cir-opt/CMakeLists.txt (+2-5)
``````````diff
diff --git a/clang/lib/CIR/CodeGen/CMakeLists.txt b/clang/lib/CIR/CodeGen/CMakeLists.txt
index 0fd5cdfb02540..c4bd520fc61b7 100644
--- a/clang/lib/CIR/CodeGen/CMakeLists.txt
+++ b/clang/lib/CIR/CodeGen/CMakeLists.txt
@@ -1,11 +1,10 @@
set(
LLVM_LINK_COMPONENTS
Core
+ FrontendOpenMP
Support
)
-get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
-
add_clang_library(clangCIR
CIRDataLayoutSpec.cpp
CIRGenerator.cpp
@@ -64,18 +63,23 @@ add_clang_library(clangCIR
DEPENDS
MLIRCIR
MLIRCIROpInterfacesIncGen
- ${dialect_libs}
LINK_LIBS
clangAST
clangBasic
clangCodeGenUtils
clangLex
- ${dialect_libs}
CIRRegisterAllDialects
CIROpenACCSupport
CIROpenMPSupport
+ MLIRArithDialect
MLIRCIR
MLIRCIRInterfaces
+ MLIRDLTIDialect
+ MLIRLLVMDialect
+ MLIROpenACCDialect
+ MLIROpenMPDialect
+ MLIROpenMPUtils
+ MLIRPtrMemorySpaceInterfaces
MLIRTargetLLVMIRImport
)
diff --git a/clang/lib/CIR/FrontendAction/CMakeLists.txt b/clang/lib/CIR/FrontendAction/CMakeLists.txt
index 9577a907c9334..d221771fd4086 100644
--- a/clang/lib/CIR/FrontendAction/CMakeLists.txt
+++ b/clang/lib/CIR/FrontendAction/CMakeLists.txt
@@ -5,8 +5,6 @@ set(LLVM_LINK_COMPONENTS
Support
)
-get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
-
add_clang_library(clangCIRFrontendAction
CIRGenAction.cpp
CIRDiagnosticHandler.cpp
diff --git a/clang/lib/CIR/Interfaces/CMakeLists.txt b/clang/lib/CIR/Interfaces/CMakeLists.txt
index 33eb169708a4f..8eec8b05aa951 100644
--- a/clang/lib/CIR/Interfaces/CMakeLists.txt
+++ b/clang/lib/CIR/Interfaces/CMakeLists.txt
@@ -15,7 +15,6 @@ add_clang_library(MLIRCIRInterfaces
MLIRCIROpInterfacesIncGen
LINK_LIBS
- ${dialect_libs}
MLIRIR
MLIRSupport
)
diff --git a/clang/lib/CIR/Lowering/CMakeLists.txt b/clang/lib/CIR/Lowering/CMakeLists.txt
index 28ec3c551018c..2713af9ba3d6c 100644
--- a/clang/lib/CIR/Lowering/CMakeLists.txt
+++ b/clang/lib/CIR/Lowering/CMakeLists.txt
@@ -3,15 +3,12 @@ set(LLVM_LINK_COMPONENTS
Support
)
-get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
-
add_clang_library(clangCIRLoweringCommon
CIRPasses.cpp
LoweringHelpers.cpp
LINK_LIBS
clangCIR
- ${dialect_libs}
MLIRCIR
MLIRCIRTransforms
MLIRTransforms
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/CMakeLists.txt b/clang/lib/CIR/Lowering/DirectToLLVM/CMakeLists.txt
index 26d9f65f865be..d3d0805afb4d8 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/CMakeLists.txt
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/CMakeLists.txt
@@ -3,8 +3,6 @@ set(LLVM_LINK_COMPONENTS
Support
)
-get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
-
add_clang_library(clangCIRLoweringDirectToLLVM
LowerToLLVM.cpp
LowerToLLVMIR.cpp
@@ -18,12 +16,16 @@ add_clang_library(clangCIRLoweringDirectToLLVM
LINK_LIBS
clangCIRLoweringCommon
- ${dialect_libs}
MLIRCIR
MLIRCIRTargetLowering
MLIRCIRTransforms
MLIRBuiltinToLLVMIRTranslation
+ MLIRDLTIDialect
+ MLIRFuncDialect
+ MLIRLLVMCommonConversion
+ MLIRLLVMDialect
MLIRLLVMToLLVMIRTranslation
+ MLIROpenMPDialect
MLIROpenMPToLLVM
MLIROpenMPToLLVMIRTranslation
MLIROpenMPTransforms
diff --git a/clang/tools/cir-opt/CMakeLists.txt b/clang/tools/cir-opt/CMakeLists.txt
index 72cfff1800d41..b4ae75cfbb118 100644
--- a/clang/tools/cir-opt/CMakeLists.txt
+++ b/clang/tools/cir-opt/CMakeLists.txt
@@ -1,6 +1,3 @@
-get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
-get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
-
include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include)
include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include)
@@ -39,16 +36,16 @@ clang_target_link_libraries(cir-opt
target_link_libraries(cir-opt
PRIVATE
- ${dialect_libs}
- ${conversion_libs}
MLIRAnalysis
MLIRDialect
MLIRIR
+ MLIRLLVMDialect
MLIRMemRefDialect
MLIROpenMPTransforms
MLIROptLib
MLIRParser
MLIRPass
+ MLIRReconcileUnrealizedCasts
MLIRSideEffectInterfaces
MLIRTransforms
MLIRTransformUtils
``````````
</details>
https://github.com/llvm/llvm-project/pull/221616
More information about the cfe-commits
mailing list