From 0649caa187d1a15ab63a78fd2f15ad4662699355 Mon Sep 17 00:00:00 2001 From: Shoaib Meenai Date: Wed, 13 Nov 2024 23:23:20 -0800 Subject: [PATCH 1/2] [CIR] Fix tests with LLVM_LINK_LLVM_DYLIB This option creates and links all tools against a single libLLVM shared library (and the corresponding CLANG_LINK_CLANG_DYLIB option also gets turned on by default). In order for this to work, we need to use LINK_COMPONENTS instead of LINK_LIBS for all LLVM dependencies, and clang_target_link_libraries for all Clang dependencies, so that they get rewritten to use the dylib. Remove llvm_update_compile_flags while I'm here, since the build macros handle that internally. Before this change, we'd link against certain LLVM libraries both statically and dynamically, leading to test failures from duplicate singletons. The way this works for MLIR is fragile right now: MLIR can create its own dylib as well but doesn't have build system support for linking against that dylib. We end up folding the MLIR libraries into libclang-cpp.so (because all Clang dependencies get pulled into it), but MLIR tools still link the MLIR libraries statically. It'll still work, but BUILD_SHARED_LIBS is possibly a better alternative for development. Distributions like Fedora build their LLVM packages with LLVM_LINK_LLVM_DYLIB, so we'll want to eventually have good MLIR support for that setup too. --- .../Transforms/TargetLowering/CMakeLists.txt | 4 ++- clang/tools/cir-opt/CMakeLists.txt | 28 +++++++++--------- clang/tools/cir-translate/CMakeLists.txt | 29 +++++++++---------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt index d3cb9fc96f1a..21bfa30a111a 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt @@ -22,10 +22,12 @@ add_clang_library(TargetLowering DEPENDS clangBasic + LINK_COMPONENTS + TargetParser + LINK_LIBS PUBLIC clangBasic - LLVMTargetParser MLIRIR MLIRPass MLIRDLTIDialect diff --git a/clang/tools/cir-opt/CMakeLists.txt b/clang/tools/cir-opt/CMakeLists.txt index 741cdfa5950d..68f0ea1f19db 100644 --- a/clang/tools/cir-opt/CMakeLists.txt +++ b/clang/tools/cir-opt/CMakeLists.txt @@ -4,15 +4,25 @@ 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) -set(LIBS - ${dialect_libs} - ${conversion_libs} +add_clang_tool(cir-opt + cir-opt.cpp + ${LIBS} +) + +clang_target_link_libraries(cir-opt + PRIVATE clangCIR clangCIRLoweringThroughMLIR clangCIRLoweringDirectToLLVM - MLIRAnalysis MLIRCIR MLIRCIRTransforms +) + +target_link_libraries(cir-opt + PRIVATE + ${dialect_libs} + ${conversion_libs} + MLIRAnalysis MLIRDialect MLIRIR MLIRMemRefDialect @@ -23,13 +33,3 @@ set(LIBS MLIRTransforms MLIRTransformUtils ) - -add_clang_tool(cir-opt - cir-opt.cpp - - DEPENDS - ${LIBS} -) - -target_link_libraries(cir-opt PRIVATE ${LIBS}) -llvm_update_compile_flags(cir-opt) diff --git a/clang/tools/cir-translate/CMakeLists.txt b/clang/tools/cir-translate/CMakeLists.txt index a5e22b02e505..21834799ea82 100644 --- a/clang/tools/cir-translate/CMakeLists.txt +++ b/clang/tools/cir-translate/CMakeLists.txt @@ -5,15 +5,24 @@ get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include) include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include) -set(LIBS - ${dialect_libs} - ${conversion_libs} - ${translation_libs} +add_clang_tool(cir-translate + cir-translate.cpp +) + +clang_target_link_libraries(cir-translate + PRIVATE clangCIR clangCIRLoweringDirectToLLVM - MLIRAnalysis MLIRCIR MLIRCIRTransforms +) + +target_link_libraries(cir-translate + PRIVATE + ${dialect_libs} + ${conversion_libs} + ${translation_libs} + MLIRAnalysis MLIRDialect MLIRIR MLIROptLib @@ -24,13 +33,3 @@ set(LIBS MLIRTranslateLib MLIRSupport ) - -add_clang_tool(cir-translate - cir-translate.cpp - - DEPENDS - ${LIBS} -) - -target_link_libraries(cir-translate PRIVATE ${LIBS}) -llvm_update_compile_flags(cir-translate) From ece614af28f3454b96f06b368240c07db2d362df Mon Sep 17 00:00:00 2001 From: Shoaib Meenai Date: Wed, 11 Dec 2024 09:43:42 -0800 Subject: [PATCH 2/2] Fix leftover variable --- clang/tools/cir-opt/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/tools/cir-opt/CMakeLists.txt b/clang/tools/cir-opt/CMakeLists.txt index 68f0ea1f19db..900697ffe8e4 100644 --- a/clang/tools/cir-opt/CMakeLists.txt +++ b/clang/tools/cir-opt/CMakeLists.txt @@ -6,7 +6,6 @@ include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include) add_clang_tool(cir-opt cir-opt.cpp - ${LIBS} ) clang_target_link_libraries(cir-opt