Author: Aiden Grossman Date: 2026-01-26T16:17:57Z New Revision: 2c9efd0177910753008767a8c50e62f676721443
URL: https://github.com/llvm/llvm-project/commit/2c9efd0177910753008767a8c50e62f676721443 DIFF: https://github.com/llvm/llvm-project/commit/2c9efd0177910753008767a8c50e62f676721443.diff LOG: Revert "[libclc] Rework libclc naming convention to use the triple (#177465)" This reverts commit c5cb48c39701086393d1177929a328868849fc72. This was causing CMake configuration failures for the postsubmit buildbot checking the premerge configuration: ``` 2026-01-26T13:46:47.849060051Z CMake Error at /home/gha/llvm-project/libclc/cmake/modules/AddLibclc.cmake:407 (add_custom_command): 2026-01-26T13:46:47.849086795Z Attempt to add a custom rule to output 2026-01-26T13:46:47.849088339Z 2026-01-26T13:46:47.849090228Z /home/gha/llvm-project/build/lib/clang/23/lib/r600--/libclc.bc.rule 2026-01-26T13:46:47.849101045Z 2026-01-26T13:46:47.849103110Z which already has a custom rule. 2026-01-26T13:46:47.849104522Z Call Stack (most recent call first): 2026-01-26T13:46:47.849106013Z /home/gha/llvm-project/libclc/CMakeLists.txt:460 (add_libclc_builtin_set) 2026-01-26T13:46:47.849107043Z 2026-01-26T13:46:47.849108005Z 2026-01-26T13:46:47.851329201Z CMake Error at /home/gha/llvm-project/libclc/cmake/modules/AddLibclc.cmake:407 (add_custom_command): 2026-01-26T13:46:47.851341592Z Attempt to add a custom rule to output 2026-01-26T13:46:47.851343793Z 2026-01-26T13:46:47.851346484Z /home/gha/llvm-project/build/lib/clang/23/lib/r600--/libclc.bc.rule 2026-01-26T13:46:47.851348290Z 2026-01-26T13:46:47.851350814Z which already has a custom rule. 2026-01-26T13:46:47.851352774Z Call Stack (most recent call first): 2026-01-26T13:46:47.851354795Z /home/gha/llvm-project/libclc/CMakeLists.txt:460 (add_libclc_builtin_set) 2026-01-26T13:46:47.851356284Z 2026-01-26T13:46:47.851357807Z 2026-01-26T13:46:47.853361832Z CMake Error at /home/gha/llvm-project/libclc/cmake/modules/AddLibclc.cmake:407 (add_custom_command): 2026-01-26T13:46:47.853368044Z Attempt to add a custom rule to output 2026-01-26T13:46:47.853369290Z 2026-01-26T13:46:47.853370974Z /home/gha/llvm-project/build/lib/clang/23/lib/r600--/libclc.bc.rule 2026-01-26T13:46:47.853372068Z 2026-01-26T13:46:47.853373338Z which already has a custom rule. 2026-01-26T13:46:47.853374637Z Call Stack (most recent call first): 2026-01-26T13:46:47.853376034Z /home/gha/llvm-project/libclc/CMakeLists.txt:460 (add_libclc_builtin_set) 2026-01-26T13:46:47.853377158Z 2026-01-26T13:46:47.853378154Z 2026-01-26T13:47:02.534691197Z -- Generating done (11.9s) ``` https://lab.llvm.org/staging/#/builders/192 Added: Modified: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/opencl-libclc.cl libclc/CMakeLists.txt libclc/cmake/modules/AddLibclc.cmake Removed: clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/amdgcn-amd-amdhsa/gfx90a/libclc.bc clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/amdgcn-amd-amdhsa/libclc.bc ################################################################################ diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 57d19a73c5d2b..157c0675815da 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -3049,55 +3049,38 @@ void tools::addOpenMPDeviceRTL(const Driver &D, void tools::addOpenCLBuiltinsLib(const Driver &D, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) { + // Check whether user specifies a libclc bytecode library const Arg *A = DriverArgs.getLastArg(options::OPT_libclc_lib_EQ); if (!A) return; - // If the namespec is of the form :filename we use it exactly. + // Find device libraries in <LLVM_DIR>/lib/clang/<ver>/lib/libclc/ + SmallString<128> LibclcPath(D.ResourceDir); + llvm::sys::path::append(LibclcPath, "lib", "libclc"); + + // If the namespec is of the form :filename, search for that file. StringRef LibclcNamespec(A->getValue()); bool FilenameSearch = LibclcNamespec.consume_front(":"); - if (FilenameSearch) { - SmallString<128> LibclcFile(LibclcNamespec); - if (llvm::sys::fs::exists(LibclcFile)) { - CC1Args.push_back("-mlink-builtin-bitcode"); - CC1Args.push_back(DriverArgs.MakeArgString(LibclcFile)); - return; - } - D.Diag(diag::err_drv_libclc_not_found) << LibclcFile; - return; - } + SmallString<128> LibclcTargetFile(LibclcNamespec); - // The OpenCL libraries are stored in <ResourceDir>/lib/<triple>. - SmallString<128> BasePath(D.ResourceDir); - llvm::sys::path::append(BasePath, "lib"); - llvm::sys::path::append(BasePath, D.getTargetTriple()); - - // First check for a CPU-specific library in <ResourceDir>/lib/<triple>/<CPU>. - // TODO: Factor this into common logic that checks for valid subtargets. - if (const Arg *CPUArg = - DriverArgs.getLastArg(options::OPT_mcpu_EQ, options::OPT_march_EQ)) { - StringRef CPU = CPUArg->getValue(); - if (!CPU.empty()) { - SmallString<128> CPUPath(BasePath); - llvm::sys::path::append(CPUPath, CPU, "libclc.bc"); - if (llvm::sys::fs::exists(CPUPath)) { - CC1Args.push_back("-mlink-builtin-bitcode"); - CC1Args.push_back(DriverArgs.MakeArgString(CPUPath)); - return; - } - } - } - - // Fall back to the generic library for the triple. - SmallString<128> GenericPath(BasePath); - llvm::sys::path::append(GenericPath, "libclc.bc"); - if (llvm::sys::fs::exists(GenericPath)) { + if (FilenameSearch && llvm::sys::fs::exists(LibclcTargetFile)) { CC1Args.push_back("-mlink-builtin-bitcode"); - CC1Args.push_back(DriverArgs.MakeArgString(GenericPath)); - return; - } + CC1Args.push_back(DriverArgs.MakeArgString(LibclcTargetFile)); + } else { + // Search the library paths for the file + if (!FilenameSearch) + LibclcTargetFile += ".bc"; - D.Diag(diag::err_drv_libclc_not_found) << "libclc.bc"; + llvm::sys::path::append(LibclcPath, LibclcTargetFile); + if (llvm::sys::fs::exists(LibclcPath)) { + CC1Args.push_back("-mlink-builtin-bitcode"); + CC1Args.push_back(DriverArgs.MakeArgString(LibclcPath)); + } else { + // Since the user requested a library, if we haven't one then report an + // error. + D.Diag(diag::err_drv_libclc_not_found) << LibclcTargetFile; + } + } } void tools::addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC, diff --git a/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/amdgcn-amd-amdhsa/gfx90a/libclc.bc b/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/amdgcn-amd-amdhsa/gfx90a/libclc.bc deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/amdgcn-amd-amdhsa/libclc.bc b/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/amdgcn-amd-amdhsa/libclc.bc deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/clang/test/Driver/opencl-libclc.cl b/clang/test/Driver/opencl-libclc.cl index f7428aeb9f922..185690768c75b 100644 --- a/clang/test/Driver/opencl-libclc.cl +++ b/clang/test/Driver/opencl-libclc.cl @@ -7,15 +7,3 @@ // CHECK-SUBDIR: -mlink-builtin-bitcode{{.*}}Inputs{{/|\\\\}}libclc{{/|\\\\}}subdir{{/|\\\\}}libclc.bc // CHECK-ERROR: no libclc library{{.*}}not-here.bc' found in the clang resource directory - -// RUN: %clang -### -target amdgcn-amd-amdhsa --no-offloadlib \ -// RUN: --libclc-lib= \ -// RUN: -resource-dir %S/Inputs/resource_dir_with_per_target_subdir \ -// RUN: -march=gfx90a %s 2>&1 | FileCheck %s --check-prefix=CHECK-GFX90A -// CHECK-GFX90A: -mlink-builtin-bitcode{{.*}}resource_dir_with_per_target_subdir{{/|\\\\}}lib{{/|\\\\}}amdgcn-amd-amdhsa{{/|\\\\}}gfx90a{{/|\\\\}}libclc.bc - -// RUN: %clang -### -target amdgcn-amd-amdhsa --no-offloadlib \ -// RUN: --libclc-lib= \ -// RUN: -resource-dir %S/Inputs/resource_dir_with_per_target_subdir \ -// RUN: %s 2>&1 | FileCheck %s --check-prefix=CHECK-GENERIC -// CHECK-GENERIC: -mlink-builtin-bitcode{{.*}}resource_dir_with_per_target_subdir{{/|\\\\}}lib{{/|\\\\}}amdgcn-amd-amdhsa{{/|\\\\}}libclc.bc diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 09a1d6ef4feb7..88a32797d5915 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -110,10 +110,12 @@ else() # in-tree build we place the libraries in clang's resource driectory. include(GetClangResourceDir) get_clang_resource_dir( LIBCLC_INSTALL_DIR ) - cmake_path( APPEND LIBCLC_INSTALL_DIR "lib" ) + cmake_path( APPEND LIBCLC_INSTALL_DIR "lib" "libclc" ) + # Note we do not adhere to LLVM_ENABLE_PER_TARGET_RUNTIME_DIR. cmake_path( GET LLVM_LIBRARY_OUTPUT_INTDIR PARENT_PATH LIBCLC_OUTPUT_LIBRARY_DIR ) cmake_path( APPEND LIBCLC_OUTPUT_LIBRARY_DIR ${LIBCLC_INSTALL_DIR} ) + file( MAKE_DIRECTORY ${LIBCLC_OUTPUT_LIBRARY_DIR} ) endif() if( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} ) @@ -444,7 +446,6 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) add_libclc_builtin_set( CLC_INTERNAL ARCH ${ARCH} - CPU ${cpu} ARCH_SUFFIX clc-${arch_suffix} TRIPLE ${clang_triple} COMPILE_FLAGS ${build_flags} diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index ef72243c91845..1ba53a9528f82 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -226,6 +226,33 @@ function(get_libclc_device_info) endif() endfunction() +# Install libclc artifacts. +# +# Arguments: +# * FILES <string> ... +# List of libclc artifact files to be installed. +function(libclc_install) + cmake_parse_arguments(ARG "" "" "FILES" ${ARGN}) + + if( NOT ARG_FILES ) + message( FATAL_ERROR "Must provide FILES" ) + endif() + + if( NOT CMAKE_CFG_INTDIR STREQUAL "." ) + # Replace CMAKE_CFG_INTDIR with CMAKE_INSTALL_CONFIG_NAME for multiple- + # configuration generators. + string( REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" + files ${ARG_FILES} ) + else() + set( files ${ARG_FILES} ) + endif() + + install( + FILES ${files} + DESTINATION ${LIBCLC_INSTALL_DIR} + ) +endfunction() + # Compiles a list of library source files (provided by LIB_FILES) and compiles # them to LLVM bytecode (or SPIR-V), links them together and optimizes them. # @@ -235,8 +262,6 @@ endfunction() # Arguments: # * ARCH <string> # libclc architecture being built -# * CPU <string> -# libclc microarchitecture being built # * ARCH_SUFFIX <string> # libclc architecture/triple suffix # * TRIPLE <string> @@ -374,21 +399,13 @@ function(add_libclc_builtin_set) return() endif() - set( LIBCLC_OUTPUT_FILENAME libclc ) set( builtins_link_lib $<TARGET_PROPERTY:${builtins_link_lib_tgt},TARGET_FILE> ) - # We store the library according to its triple and cpu if present. - if (ARG_CPU) - set (library_dir ${LIBCLC_OUTPUT_LIBRARY_DIR}/${ARG_TRIPLE}/${ARG_CPU}) - else() - set (library_dir ${LIBCLC_OUTPUT_LIBRARY_DIR}/${ARG_TRIPLE}) - endif() - file( MAKE_DIRECTORY ${library_dir} ) - # 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( libclc_builtins_lib ${library_dir}/${LIBCLC_OUTPUT_FILENAME}.spv ) + set( obj_suffix ${ARG_ARCH_SUFFIX}.spv ) + set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} ) if ( LIBCLC_USE_SPIRV_BACKEND ) add_custom_command( OUTPUT ${libclc_builtins_lib} COMMAND ${clang_exe} -c --target=${ARG_TRIPLE} -x ir -o ${libclc_builtins_lib} ${builtins_link_lib} @@ -402,7 +419,8 @@ function(add_libclc_builtin_set) endif() else() # Non-SPIR-V targets add an extra step to optimize the bytecode - set( libclc_builtins_lib ${library_dir}/${LIBCLC_OUTPUT_FILENAME}.bc ) + 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 ${opt_exe} ${ARG_OPT_FLAGS} -o ${libclc_builtins_lib} @@ -412,8 +430,8 @@ function(add_libclc_builtin_set) endif() # Add a 'library' target - add_custom_target( library-${ARG_ARCH_SUFFIX} ALL DEPENDS ${libclc_builtins_lib} ) - set_target_properties( "library-${ARG_ARCH_SUFFIX}" PROPERTIES + add_custom_target( library-${obj_suffix} ALL DEPENDS ${libclc_builtins_lib} ) + set_target_properties( "library-${obj_suffix}" PROPERTIES TARGET_FILE ${libclc_builtins_lib} FOLDER "libclc/Device IR/Library" ) @@ -424,16 +442,12 @@ function(add_libclc_builtin_set) if( NOT TARGET library-${ARG_TRIPLE} ) add_custom_target( library-${ARG_TRIPLE} ALL ) endif() - add_dependencies( library-${ARG_TRIPLE} library-${ARG_ARCH_SUFFIX} ) + add_dependencies( library-${ARG_TRIPLE} library-${obj_suffix} ) # Add dependency to top-level pseudo target to ease making other # targets dependent on libclc. add_dependencies( ${ARG_PARENT_TARGET} library-${ARG_TRIPLE} ) - # Install the created library. - install( - FILES ${libclc_builtins_lib} - DESTINATION ${LIBCLC_INSTALL_DIR}/${ARG_TRIPLE} - ) + libclc_install(FILES ${libclc_builtins_lib}) # SPIR-V targets can exit early here if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 ) @@ -446,7 +460,7 @@ function(add_libclc_builtin_set) # * nvptx64-- targets don't include workitem builtins # * clspv targets don't include all OpenCL builtins if( NOT ARG_ARCH MATCHES "^(nvptx|clspv)(64)?$" ) - add_test( NAME external-funcs-${ARG_ARCH_SUFFIX} + add_test( NAME external-funcs-${obj_suffix} COMMAND ./check_external_funcs.sh ${libclc_builtins_lib} ${LLVM_TOOLS_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) endif() @@ -462,26 +476,20 @@ function(add_libclc_builtin_set) set(LIBCLC_LINK_OR_COPY copy) endif() - file( MAKE_DIRECTORY ${LIBCLC_OUTPUT_LIBRARY_DIR}/${ARG_TRIPLE}/${a} ) - set( libclc_alias_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${ARG_TRIPLE}/${a}/${LIBCLC_OUTPUT_FILENAME}.bc ) + set( alias_suffix "${a}-${ARG_TRIPLE}.bc" ) add_custom_command( - OUTPUT ${libclc_alias_lib} - COMMAND ${CMAKE_COMMAND} -E ${LIBCLC_LINK_OR_COPY} ${LIBCLC_LINK_OR_COPY_SOURCE} ${libclc_alias_lib} - DEPENDS library-${ARG_ARCH_SUFFIX} + OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} + COMMAND ${CMAKE_COMMAND} -E ${LIBCLC_LINK_OR_COPY} ${LIBCLC_LINK_OR_COPY_SOURCE} ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} + DEPENDS library-${obj_suffix} ) - add_custom_target( alias-${a}-${ARG_TRIPLE} ALL - DEPENDS ${libclc_alias_lib} + add_custom_target( alias-${alias_suffix} ALL + DEPENDS ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} ) - add_dependencies( ${ARG_PARENT_TARGET} alias-${a}-${ARG_TRIPLE} ) - set_target_properties( alias-${a}-${ARG_TRIPLE} + add_dependencies( ${ARG_PARENT_TARGET} alias-${alias_suffix} ) + set_target_properties( alias-${alias_suffix} PROPERTIES FOLDER "libclc/Device IR/Aliases" ) - - # Install the library - install( - FILES ${libclc_alias_lib} - DESTINATION ${LIBCLC_INSTALL_DIR}/${ARG_TRIPLE}/${a} - ) + libclc_install(FILES ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}) endforeach( a ) endfunction(add_libclc_builtin_set) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
