https://github.com/mgorny created https://github.com/llvm/llvm-project/pull/149711
Revert the recent batch of changes to the CMake build of libclc that introduced significant breakage, notably: - standalone builds no longer working - broken symlinks being installed These changes are nontrivial and were made shortly prior to the branching point, so it's better to defer them to 22.x and fix properly than attempt to apply more ad hoc fixes. Fixes #149659 Fixes #149437 From 92b937eb336d235b981b4beaae2c9cabe02914be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgo...@gentoo.org> Date: Sun, 20 Jul 2025 16:07:23 +0200 Subject: [PATCH 1/5] Revert "[libclc] Move CMake for prepare_builtins to a subdirectory (#148815)" This reverts commit 8a7a64873b13e6fd931b748fbf50b3da26fe7fca. It broke standalone builds since the necessary variables are now limited in scope to `libclc/utils` while they are used in the top-level CMakeLists. --- libclc/CMakeLists.txt | 24 ++++++++++++++++++++++-- libclc/utils/CMakeLists.txt | 24 ------------------------ 2 files changed, 22 insertions(+), 26 deletions(-) delete mode 100644 libclc/utils/CMakeLists.txt diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 2570d1a106d21..e2871d1b01a16 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -164,14 +164,34 @@ endif() list( SORT LIBCLC_TARGETS_TO_BUILD ) +# Construct LLVM version define +set( LLVM_VERSION_DEFINE "-DHAVE_LLVM=0x${LLVM_VERSION_MAJOR}0${LLVM_VERSION_MINOR}" ) + # This needs to be set before any target that needs it # We need to use LLVM_INCLUDE_DIRS here, because if we are linking to an # llvm build directory, this includes $src/llvm/include which is where all the # headers are not $build/include/ which is what LLVM_INCLUDE_DIR is set to. include_directories( ${LLVM_INCLUDE_DIRS} ) -# Configure prepare_builtins -add_subdirectory( utils ) +# Setup prepare_builtins tools +set(LLVM_LINK_COMPONENTS + BitReader + BitWriter + Core + IRReader + Support +) +if( LIBCLC_STANDALONE_BUILD ) + add_llvm_executable( prepare_builtins utils/prepare-builtins.cpp ) + set( prepare_builtins_exe prepare_builtins ) + set( prepare_builtins_target prepare_builtins ) +else() + add_llvm_utility( prepare_builtins utils/prepare-builtins.cpp ) + setup_host_tool( prepare_builtins PREPARE_BUILTINS prepare_builtins_exe prepare_builtins_target ) +endif() +target_compile_definitions( prepare_builtins PRIVATE ${LLVM_VERSION_DEFINE} ) +# These were not properly reported in early LLVM and we don't need them +target_compile_options( prepare_builtins PRIVATE -fno-rtti -fno-exceptions ) # Setup arch devices set( r600--_devices cedar cypress barts cayman ) diff --git a/libclc/utils/CMakeLists.txt b/libclc/utils/CMakeLists.txt deleted file mode 100644 index ea1d9e9c8ef5f..0000000000000 --- a/libclc/utils/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# Construct LLVM version define -set( LLVM_VERSION_DEFINE "-DHAVE_LLVM=0x${LLVM_VERSION_MAJOR}0${LLVM_VERSION_MINOR}" ) - -# Setup prepare_builtins tools -set( LLVM_LINK_COMPONENTS - BitReader - BitWriter - Core - IRReader - Support -) - -if( LIBCLC_STANDALONE_BUILD ) - add_llvm_executable( prepare_builtins prepare-builtins.cpp ) - set( prepare_builtins_exe prepare_builtins ) - set( prepare_builtins_target prepare_builtins ) -else() - add_llvm_utility( prepare_builtins prepare-builtins.cpp ) - setup_host_tool( prepare_builtins PREPARE_BUILTINS prepare_builtins_exe prepare_builtins_target ) -endif() - -target_compile_definitions( prepare_builtins PRIVATE ${LLVM_VERSION_DEFINE} ) -# These were not properly reported in early LLVM and we don't need them -target_compile_options( prepare_builtins PRIVATE -fno-rtti -fno-exceptions ) From 3f12831601fcbdc1c610c2d7131661b9990de1b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgo...@gentoo.org> Date: Sun, 20 Jul 2025 16:07:59 +0200 Subject: [PATCH 2/5] Revert "[libclc] Change symlinks to copies on Windows (#147759)" This reverts commit 9b5959dd9a0eb0fc005b92be7ef7f3a5e3377b81. --- libclc/cmake/modules/AddLibclc.cmake | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index 056706ee629cd..a8160e04d46a0 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -425,17 +425,11 @@ function(add_libclc_builtin_set) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) endif() - if(CMAKE_HOST_UNIX OR LLVM_USE_SYMLINKS) - set(LIBCLC_LINK_OR_COPY create_symlink) - else() - set(LIBCLC_LINK_OR_COPY copy) - endif() - - foreach( a IN LISTS ARG_ALIASES ) + foreach( a ${ARG_ALIASES} ) set( alias_suffix "${a}-${ARG_TRIPLE}.bc" ) add_custom_command( OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} - COMMAND ${CMAKE_COMMAND} -E ${LIBCLC_LINK_OR_COPY} ${libclc_builtins_lib} ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} + COMMAND ${CMAKE_COMMAND} -E create_symlink ${libclc_builtins_lib} ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} DEPENDS prepare-${obj_suffix} ) add_custom_target( alias-${alias_suffix} ALL From 508b1043353a0a6762ccff16d6acc1d39a34f150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgo...@gentoo.org> Date: Sun, 20 Jul 2025 16:08:10 +0200 Subject: [PATCH 3/5] Revert "[libclc] Fix target dependency" This reverts commit 222e795347c14afce49df1540926f3a1ae493de4. --- libclc/cmake/modules/AddLibclc.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index a8160e04d46a0..2634f178da8c5 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -393,7 +393,7 @@ function(add_libclc_builtin_set) endif() # Add a 'prepare' target - add_custom_target( prepare-${obj_suffix} ALL DEPENDS ${libclc_builtins_lib} ) + add_custom_target( prepare-${obj_suffix} ALL DEPENDS ${obj_suffix} ) set_target_properties( "prepare-${obj_suffix}" PROPERTIES FOLDER "libclc/Device IR/Prepare" ) # Also add a 'prepare' target for the triple. Since a triple may have From ecfe3c9fbb0ed40286ec9953445ab4a6513852cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgo...@gentoo.org> Date: Sun, 20 Jul 2025 16:08:21 +0200 Subject: [PATCH 4/5] Revert "[libclc] Make library output directories explicit (#146833)" This reverts commit 81e6552a3d6835c4e10eb981402febfac9df6156. This change caused libclc to start installing broken symlinks that contain absolute paths to the build directory rather than relative paths within the install directory. --- libclc/CMakeLists.txt | 3 -- libclc/cmake/modules/AddLibclc.cmake | 54 ++++++++++++---------------- 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index e2871d1b01a16..c98e2043464d9 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -84,9 +84,6 @@ else() endif() endif() -# Setup the paths where libclc runtimes should be stored. -set( LIBCLC_OUTPUT_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) - if( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} ) message( WARNING "Using custom LLVM tools to build libclc: " "${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}, " diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index 2634f178da8c5..c521ea1589484 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -120,14 +120,14 @@ function(link_bc) endif() add_custom_command( - OUTPUT ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc - COMMAND ${llvm-link_exe} ${link_flags} -o ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc ${LINK_INPUT_ARG} + OUTPUT ${ARG_TARGET}.bc + COMMAND ${llvm-link_exe} ${link_flags} -o ${ARG_TARGET}.bc ${LINK_INPUT_ARG} DEPENDS ${llvm-link_target} ${ARG_DEPENDENCIES} ${ARG_INPUTS} ${RSP_FILE} ) - add_custom_target( ${ARG_TARGET} ALL DEPENDS ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc ) + add_custom_target( ${ARG_TARGET} ALL DEPENDS ${ARG_TARGET}.bc ) set_target_properties( ${ARG_TARGET} PROPERTIES - TARGET_FILE ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc + TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.bc FOLDER "libclc/Device IR/Linking" ) endfunction() @@ -360,36 +360,33 @@ function(add_libclc_builtin_set) # llvm-spirv tool. if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 ) set( obj_suffix ${ARG_ARCH_SUFFIX}.spv ) - set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} ) - add_custom_command( OUTPUT ${libclc_builtins_lib} - COMMAND ${llvm-spirv_exe} ${spvflags} -o ${libclc_builtins_lib} ${builtins_link_lib} + add_custom_command( OUTPUT ${obj_suffix} + COMMAND ${llvm-spirv_exe} ${spvflags} -o ${obj_suffix} ${builtins_link_lib} DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt} ) else() # Non-SPIR-V targets add an extra step to optimize the bytecode set( builtins_opt_lib_tgt builtins.opt.${ARG_ARCH_SUFFIX} ) - add_custom_command( OUTPUT ${LIBCLC_ARCH_OBJFILE_DIR}/${builtins_opt_lib_tgt}.bc - COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${LIBCLC_ARCH_OBJFILE_DIR}/${builtins_opt_lib_tgt}.bc + add_custom_command( OUTPUT ${builtins_opt_lib_tgt}.bc + COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${builtins_opt_lib_tgt}.bc ${builtins_link_lib} DEPENDS ${opt_target} ${builtins_link_lib} ${builtins_link_lib_tgt} ) add_custom_target( ${builtins_opt_lib_tgt} - ALL DEPENDS ${LIBCLC_ARCH_OBJFILE_DIR}/${builtins_opt_lib_tgt}.bc + ALL DEPENDS ${builtins_opt_lib_tgt}.bc ) set_target_properties( ${builtins_opt_lib_tgt} PROPERTIES - TARGET_FILE ${LIBCLC_ARCH_OBJFILE_DIR}/${builtins_opt_lib_tgt}.bc + TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${builtins_opt_lib_tgt}.bc FOLDER "libclc/Device IR/Opt" ) set( builtins_opt_lib $<TARGET_PROPERTY:${builtins_opt_lib_tgt},TARGET_FILE> ) set( obj_suffix ${ARG_ARCH_SUFFIX}.bc ) - set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} ) - add_custom_command( OUTPUT ${libclc_builtins_lib} - COMMAND ${prepare_builtins_exe} -o ${libclc_builtins_lib} ${builtins_opt_lib} - DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target} - ) + add_custom_command( OUTPUT ${obj_suffix} + COMMAND ${prepare_builtins_exe} -o ${obj_suffix} ${builtins_opt_lib} + DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target} ) endif() # Add a 'prepare' target @@ -405,7 +402,7 @@ function(add_libclc_builtin_set) add_dependencies( prepare-${ARG_TRIPLE} prepare-${obj_suffix} ) install( - FILES ${libclc_builtins_lib} + FILES ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) @@ -421,27 +418,20 @@ function(add_libclc_builtin_set) # * clspv targets don't include all OpenCL builtins if( NOT ARG_ARCH MATCHES "^(nvptx|clspv)(64)?$" ) add_test( NAME external-calls-${obj_suffix} - COMMAND ./check_external_calls.sh ${libclc_builtins_lib} ${LLVM_TOOLS_BINARY_DIR} + COMMAND ./check_external_calls.sh ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} ${LLVM_TOOLS_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) endif() foreach( a ${ARG_ALIASES} ) set( alias_suffix "${a}-${ARG_TRIPLE}.bc" ) add_custom_command( - OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} - COMMAND ${CMAKE_COMMAND} -E create_symlink ${libclc_builtins_lib} ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} - DEPENDS prepare-${obj_suffix} - ) - add_custom_target( alias-${alias_suffix} ALL - DEPENDS ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} - ) - set_target_properties( alias-${alias_suffix} - PROPERTIES FOLDER "libclc/Device IR/Aliases" - ) - install( - FILES ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} - DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" - ) + OUTPUT ${alias_suffix} + COMMAND ${CMAKE_COMMAND} -E create_symlink ${obj_suffix} ${alias_suffix} + DEPENDS prepare-${obj_suffix} ) + add_custom_target( alias-${alias_suffix} ALL DEPENDS ${alias_suffix} ) + set_target_properties( alias-${alias_suffix} PROPERTIES FOLDER "libclc/Device IR/Aliases" ) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${alias_suffix} + DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) endforeach( a ) endfunction(add_libclc_builtin_set) From 2d36289809c17737f4e1c54bb15dd9ff30d3e447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgo...@gentoo.org> Date: Sun, 20 Jul 2025 16:09:00 +0200 Subject: [PATCH 5/5] Revert "[libclc] Add prepare-<triple> targets (#146700)" This reverts commit 85d09de5fa19a32bbcc400928d55f9d633077640. This change caused broken symlinks in the build directory, and the subsequent commits fixing that introduced other issues. --- libclc/cmake/modules/AddLibclc.cmake | 83 +++++++++++----------------- 1 file changed, 33 insertions(+), 50 deletions(-) diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index c521ea1589484..597bb642655e4 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -356,72 +356,55 @@ function(add_libclc_builtin_set) set( builtins_link_lib $<TARGET_PROPERTY:${builtins_link_lib_tgt},TARGET_FILE> ) - # For SPIR-V targets we diverage at this point and generate SPIR-V using the - # llvm-spirv tool. if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 ) - set( obj_suffix ${ARG_ARCH_SUFFIX}.spv ) - add_custom_command( OUTPUT ${obj_suffix} - COMMAND ${llvm-spirv_exe} ${spvflags} -o ${obj_suffix} ${builtins_link_lib} + set( spv_suffix ${ARG_ARCH_SUFFIX}.spv ) + add_custom_command( OUTPUT ${spv_suffix} + COMMAND ${llvm-spirv_exe} ${spvflags} -o ${spv_suffix} ${builtins_link_lib} DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt} ) - else() - # Non-SPIR-V targets add an extra step to optimize the bytecode - set( builtins_opt_lib_tgt builtins.opt.${ARG_ARCH_SUFFIX} ) - - add_custom_command( OUTPUT ${builtins_opt_lib_tgt}.bc - COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${builtins_opt_lib_tgt}.bc - ${builtins_link_lib} - DEPENDS ${opt_target} ${builtins_link_lib} ${builtins_link_lib_tgt} - ) - add_custom_target( ${builtins_opt_lib_tgt} - ALL DEPENDS ${builtins_opt_lib_tgt}.bc - ) - set_target_properties( ${builtins_opt_lib_tgt} PROPERTIES - TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${builtins_opt_lib_tgt}.bc - FOLDER "libclc/Device IR/Opt" - ) + add_custom_target( "prepare-${spv_suffix}" ALL DEPENDS "${spv_suffix}" ) + set_target_properties( "prepare-${spv_suffix}" PROPERTIES FOLDER "libclc/Device IR/Prepare" ) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${spv_suffix} + DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) - set( builtins_opt_lib $<TARGET_PROPERTY:${builtins_opt_lib_tgt},TARGET_FILE> ) - - set( obj_suffix ${ARG_ARCH_SUFFIX}.bc ) - add_custom_command( OUTPUT ${obj_suffix} - COMMAND ${prepare_builtins_exe} -o ${obj_suffix} ${builtins_opt_lib} - DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target} ) + return() endif() - # Add a 'prepare' target - add_custom_target( prepare-${obj_suffix} ALL DEPENDS ${obj_suffix} ) - set_target_properties( "prepare-${obj_suffix}" PROPERTIES FOLDER "libclc/Device IR/Prepare" ) + set( builtins_opt_lib_tgt builtins.opt.${ARG_ARCH_SUFFIX} ) - # Also add a 'prepare' target for the triple. Since a triple may have - # multiple devices, ensure we only try to create the triple target once. The - # triple's target will build all of the bytecode for its constituent devices. - if( NOT TARGET prepare-${ARG_TRIPLE} ) - add_custom_target( prepare-${ARG_TRIPLE} ALL ) - endif() - add_dependencies( prepare-${ARG_TRIPLE} prepare-${obj_suffix} ) - - install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} - DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" + # Add opt target + add_custom_command( OUTPUT ${builtins_opt_lib_tgt}.bc + COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${builtins_opt_lib_tgt}.bc + ${builtins_link_lib} + DEPENDS ${opt_target} ${builtins_link_lib} ${builtins_link_lib_tgt} + ) + add_custom_target( ${builtins_opt_lib_tgt} + ALL DEPENDS ${builtins_opt_lib_tgt}.bc + ) + set_target_properties( ${builtins_opt_lib_tgt} PROPERTIES + TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${builtins_opt_lib_tgt}.bc + FOLDER "libclc/Device IR/Opt" ) - # SPIR-V targets can exit early here - if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 ) - return() - endif() + set( builtins_opt_lib $<TARGET_PROPERTY:${builtins_opt_lib_tgt},TARGET_FILE> ) + + # Add prepare target + set( obj_suffix ${ARG_ARCH_SUFFIX}.bc ) + add_custom_command( OUTPUT ${obj_suffix} + COMMAND ${prepare_builtins_exe} -o ${obj_suffix} ${builtins_opt_lib} + DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target} ) + add_custom_target( prepare-${obj_suffix} ALL DEPENDS ${obj_suffix} ) + set_target_properties( "prepare-${obj_suffix}" PROPERTIES FOLDER "libclc/Device IR/Prepare" ) - # Add a test for whether or not the libraries contain unresolved calls which - # would usually indicate a build problem. Note that we don't perform this - # test for all libclc targets: - # * nvptx-- targets don't include workitem builtins - # * clspv targets don't include all OpenCL builtins + # nvptx-- targets don't include workitem builtins, and clspv targets don't + # include all OpenCL builtins if( NOT ARG_ARCH MATCHES "^(nvptx|clspv)(64)?$" ) add_test( NAME external-calls-${obj_suffix} COMMAND ./check_external_calls.sh ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} ${LLVM_TOOLS_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) endif() + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) foreach( a ${ARG_ALIASES} ) set( alias_suffix "${a}-${ARG_TRIPLE}.bc" ) add_custom_command( _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits