Skip to content

Commit 2c9efd0

Browse files
Revert "[libclc] Rework libclc naming convention to use the triple (llvm#177465)"
This reverts commit c5cb48c. 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
1 parent a150e80 commit 2c9efd0

6 files changed

Lines changed: 71 additions & 91 deletions

File tree

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,55 +3049,38 @@ void tools::addOpenMPDeviceRTL(const Driver &D,
30493049
void tools::addOpenCLBuiltinsLib(const Driver &D,
30503050
const llvm::opt::ArgList &DriverArgs,
30513051
llvm::opt::ArgStringList &CC1Args) {
3052+
// Check whether user specifies a libclc bytecode library
30523053
const Arg *A = DriverArgs.getLastArg(options::OPT_libclc_lib_EQ);
30533054
if (!A)
30543055
return;
30553056

3056-
// If the namespec is of the form :filename we use it exactly.
3057+
// Find device libraries in <LLVM_DIR>/lib/clang/<ver>/lib/libclc/
3058+
SmallString<128> LibclcPath(D.ResourceDir);
3059+
llvm::sys::path::append(LibclcPath, "lib", "libclc");
3060+
3061+
// If the namespec is of the form :filename, search for that file.
30573062
StringRef LibclcNamespec(A->getValue());
30583063
bool FilenameSearch = LibclcNamespec.consume_front(":");
3059-
if (FilenameSearch) {
3060-
SmallString<128> LibclcFile(LibclcNamespec);
3061-
if (llvm::sys::fs::exists(LibclcFile)) {
3062-
CC1Args.push_back("-mlink-builtin-bitcode");
3063-
CC1Args.push_back(DriverArgs.MakeArgString(LibclcFile));
3064-
return;
3065-
}
3066-
D.Diag(diag::err_drv_libclc_not_found) << LibclcFile;
3067-
return;
3068-
}
3064+
SmallString<128> LibclcTargetFile(LibclcNamespec);
30693065

3070-
// The OpenCL libraries are stored in <ResourceDir>/lib/<triple>.
3071-
SmallString<128> BasePath(D.ResourceDir);
3072-
llvm::sys::path::append(BasePath, "lib");
3073-
llvm::sys::path::append(BasePath, D.getTargetTriple());
3074-
3075-
// First check for a CPU-specific library in <ResourceDir>/lib/<triple>/<CPU>.
3076-
// TODO: Factor this into common logic that checks for valid subtargets.
3077-
if (const Arg *CPUArg =
3078-
DriverArgs.getLastArg(options::OPT_mcpu_EQ, options::OPT_march_EQ)) {
3079-
StringRef CPU = CPUArg->getValue();
3080-
if (!CPU.empty()) {
3081-
SmallString<128> CPUPath(BasePath);
3082-
llvm::sys::path::append(CPUPath, CPU, "libclc.bc");
3083-
if (llvm::sys::fs::exists(CPUPath)) {
3084-
CC1Args.push_back("-mlink-builtin-bitcode");
3085-
CC1Args.push_back(DriverArgs.MakeArgString(CPUPath));
3086-
return;
3087-
}
3088-
}
3089-
}
3090-
3091-
// Fall back to the generic library for the triple.
3092-
SmallString<128> GenericPath(BasePath);
3093-
llvm::sys::path::append(GenericPath, "libclc.bc");
3094-
if (llvm::sys::fs::exists(GenericPath)) {
3066+
if (FilenameSearch && llvm::sys::fs::exists(LibclcTargetFile)) {
30953067
CC1Args.push_back("-mlink-builtin-bitcode");
3096-
CC1Args.push_back(DriverArgs.MakeArgString(GenericPath));
3097-
return;
3098-
}
3068+
CC1Args.push_back(DriverArgs.MakeArgString(LibclcTargetFile));
3069+
} else {
3070+
// Search the library paths for the file
3071+
if (!FilenameSearch)
3072+
LibclcTargetFile += ".bc";
30993073

3100-
D.Diag(diag::err_drv_libclc_not_found) << "libclc.bc";
3074+
llvm::sys::path::append(LibclcPath, LibclcTargetFile);
3075+
if (llvm::sys::fs::exists(LibclcPath)) {
3076+
CC1Args.push_back("-mlink-builtin-bitcode");
3077+
CC1Args.push_back(DriverArgs.MakeArgString(LibclcPath));
3078+
} else {
3079+
// Since the user requested a library, if we haven't one then report an
3080+
// error.
3081+
D.Diag(diag::err_drv_libclc_not_found) << LibclcTargetFile;
3082+
}
3083+
}
31013084
}
31023085

31033086
void tools::addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC,

clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/amdgcn-amd-amdhsa/gfx90a/libclc.bc

Whitespace-only changes.

clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/amdgcn-amd-amdhsa/libclc.bc

Whitespace-only changes.

clang/test/Driver/opencl-libclc.cl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,3 @@
77
// CHECK-SUBDIR: -mlink-builtin-bitcode{{.*}}Inputs{{/|\\\\}}libclc{{/|\\\\}}subdir{{/|\\\\}}libclc.bc
88

99
// CHECK-ERROR: no libclc library{{.*}}not-here.bc' found in the clang resource directory
10-
11-
// RUN: %clang -### -target amdgcn-amd-amdhsa --no-offloadlib \
12-
// RUN: --libclc-lib= \
13-
// RUN: -resource-dir %S/Inputs/resource_dir_with_per_target_subdir \
14-
// RUN: -march=gfx90a %s 2>&1 | FileCheck %s --check-prefix=CHECK-GFX90A
15-
// CHECK-GFX90A: -mlink-builtin-bitcode{{.*}}resource_dir_with_per_target_subdir{{/|\\\\}}lib{{/|\\\\}}amdgcn-amd-amdhsa{{/|\\\\}}gfx90a{{/|\\\\}}libclc.bc
16-
17-
// RUN: %clang -### -target amdgcn-amd-amdhsa --no-offloadlib \
18-
// RUN: --libclc-lib= \
19-
// RUN: -resource-dir %S/Inputs/resource_dir_with_per_target_subdir \
20-
// RUN: %s 2>&1 | FileCheck %s --check-prefix=CHECK-GENERIC
21-
// CHECK-GENERIC: -mlink-builtin-bitcode{{.*}}resource_dir_with_per_target_subdir{{/|\\\\}}lib{{/|\\\\}}amdgcn-amd-amdhsa{{/|\\\\}}libclc.bc

libclc/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ else()
110110
# in-tree build we place the libraries in clang's resource driectory.
111111
include(GetClangResourceDir)
112112
get_clang_resource_dir( LIBCLC_INSTALL_DIR )
113-
cmake_path( APPEND LIBCLC_INSTALL_DIR "lib" )
113+
cmake_path( APPEND LIBCLC_INSTALL_DIR "lib" "libclc" )
114114

115+
# Note we do not adhere to LLVM_ENABLE_PER_TARGET_RUNTIME_DIR.
115116
cmake_path( GET LLVM_LIBRARY_OUTPUT_INTDIR PARENT_PATH LIBCLC_OUTPUT_LIBRARY_DIR )
116117
cmake_path( APPEND LIBCLC_OUTPUT_LIBRARY_DIR ${LIBCLC_INSTALL_DIR} )
118+
file( MAKE_DIRECTORY ${LIBCLC_OUTPUT_LIBRARY_DIR} )
117119
endif()
118120

119121
if( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
@@ -444,7 +446,6 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
444446
add_libclc_builtin_set(
445447
CLC_INTERNAL
446448
ARCH ${ARCH}
447-
CPU ${cpu}
448449
ARCH_SUFFIX clc-${arch_suffix}
449450
TRIPLE ${clang_triple}
450451
COMPILE_FLAGS ${build_flags}

libclc/cmake/modules/AddLibclc.cmake

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,33 @@ function(get_libclc_device_info)
226226
endif()
227227
endfunction()
228228

229+
# Install libclc artifacts.
230+
#
231+
# Arguments:
232+
# * FILES <string> ...
233+
# List of libclc artifact files to be installed.
234+
function(libclc_install)
235+
cmake_parse_arguments(ARG "" "" "FILES" ${ARGN})
236+
237+
if( NOT ARG_FILES )
238+
message( FATAL_ERROR "Must provide FILES" )
239+
endif()
240+
241+
if( NOT CMAKE_CFG_INTDIR STREQUAL "." )
242+
# Replace CMAKE_CFG_INTDIR with CMAKE_INSTALL_CONFIG_NAME for multiple-
243+
# configuration generators.
244+
string( REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}"
245+
files ${ARG_FILES} )
246+
else()
247+
set( files ${ARG_FILES} )
248+
endif()
249+
250+
install(
251+
FILES ${files}
252+
DESTINATION ${LIBCLC_INSTALL_DIR}
253+
)
254+
endfunction()
255+
229256
# Compiles a list of library source files (provided by LIB_FILES) and compiles
230257
# them to LLVM bytecode (or SPIR-V), links them together and optimizes them.
231258
#
@@ -235,8 +262,6 @@ endfunction()
235262
# Arguments:
236263
# * ARCH <string>
237264
# libclc architecture being built
238-
# * CPU <string>
239-
# libclc microarchitecture being built
240265
# * ARCH_SUFFIX <string>
241266
# libclc architecture/triple suffix
242267
# * TRIPLE <string>
@@ -374,21 +399,13 @@ function(add_libclc_builtin_set)
374399
return()
375400
endif()
376401

377-
set( LIBCLC_OUTPUT_FILENAME libclc )
378402
set( builtins_link_lib $<TARGET_PROPERTY:${builtins_link_lib_tgt},TARGET_FILE> )
379403

380-
# We store the library according to its triple and cpu if present.
381-
if (ARG_CPU)
382-
set (library_dir ${LIBCLC_OUTPUT_LIBRARY_DIR}/${ARG_TRIPLE}/${ARG_CPU})
383-
else()
384-
set (library_dir ${LIBCLC_OUTPUT_LIBRARY_DIR}/${ARG_TRIPLE})
385-
endif()
386-
file( MAKE_DIRECTORY ${library_dir} )
387-
388404
# For SPIR-V targets we diverage at this point and generate SPIR-V using the
389405
# llvm-spirv tool.
390406
if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
391-
set( libclc_builtins_lib ${library_dir}/${LIBCLC_OUTPUT_FILENAME}.spv )
407+
set( obj_suffix ${ARG_ARCH_SUFFIX}.spv )
408+
set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} )
392409
if ( LIBCLC_USE_SPIRV_BACKEND )
393410
add_custom_command( OUTPUT ${libclc_builtins_lib}
394411
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)
402419
endif()
403420
else()
404421
# Non-SPIR-V targets add an extra step to optimize the bytecode
405-
set( libclc_builtins_lib ${library_dir}/${LIBCLC_OUTPUT_FILENAME}.bc )
422+
set( obj_suffix ${ARG_ARCH_SUFFIX}.bc )
423+
set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} )
406424

407425
add_custom_command( OUTPUT ${libclc_builtins_lib}
408426
COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${libclc_builtins_lib}
@@ -412,8 +430,8 @@ function(add_libclc_builtin_set)
412430
endif()
413431

414432
# Add a 'library' target
415-
add_custom_target( library-${ARG_ARCH_SUFFIX} ALL DEPENDS ${libclc_builtins_lib} )
416-
set_target_properties( "library-${ARG_ARCH_SUFFIX}" PROPERTIES
433+
add_custom_target( library-${obj_suffix} ALL DEPENDS ${libclc_builtins_lib} )
434+
set_target_properties( "library-${obj_suffix}" PROPERTIES
417435
TARGET_FILE ${libclc_builtins_lib}
418436
FOLDER "libclc/Device IR/Library"
419437
)
@@ -424,16 +442,12 @@ function(add_libclc_builtin_set)
424442
if( NOT TARGET library-${ARG_TRIPLE} )
425443
add_custom_target( library-${ARG_TRIPLE} ALL )
426444
endif()
427-
add_dependencies( library-${ARG_TRIPLE} library-${ARG_ARCH_SUFFIX} )
445+
add_dependencies( library-${ARG_TRIPLE} library-${obj_suffix} )
428446
# Add dependency to top-level pseudo target to ease making other
429447
# targets dependent on libclc.
430448
add_dependencies( ${ARG_PARENT_TARGET} library-${ARG_TRIPLE} )
431449

432-
# Install the created library.
433-
install(
434-
FILES ${libclc_builtins_lib}
435-
DESTINATION ${LIBCLC_INSTALL_DIR}/${ARG_TRIPLE}
436-
)
450+
libclc_install(FILES ${libclc_builtins_lib})
437451

438452
# SPIR-V targets can exit early here
439453
if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
@@ -446,7 +460,7 @@ function(add_libclc_builtin_set)
446460
# * nvptx64-- targets don't include workitem builtins
447461
# * clspv targets don't include all OpenCL builtins
448462
if( NOT ARG_ARCH MATCHES "^(nvptx|clspv)(64)?$" )
449-
add_test( NAME external-funcs-${ARG_ARCH_SUFFIX}
463+
add_test( NAME external-funcs-${obj_suffix}
450464
COMMAND ./check_external_funcs.sh ${libclc_builtins_lib} ${LLVM_TOOLS_BINARY_DIR}
451465
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
452466
endif()
@@ -462,26 +476,20 @@ function(add_libclc_builtin_set)
462476
set(LIBCLC_LINK_OR_COPY copy)
463477
endif()
464478

465-
file( MAKE_DIRECTORY ${LIBCLC_OUTPUT_LIBRARY_DIR}/${ARG_TRIPLE}/${a} )
466-
set( libclc_alias_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${ARG_TRIPLE}/${a}/${LIBCLC_OUTPUT_FILENAME}.bc )
479+
set( alias_suffix "${a}-${ARG_TRIPLE}.bc" )
467480
add_custom_command(
468-
OUTPUT ${libclc_alias_lib}
469-
COMMAND ${CMAKE_COMMAND} -E ${LIBCLC_LINK_OR_COPY} ${LIBCLC_LINK_OR_COPY_SOURCE} ${libclc_alias_lib}
470-
DEPENDS library-${ARG_ARCH_SUFFIX}
481+
OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
482+
COMMAND ${CMAKE_COMMAND} -E ${LIBCLC_LINK_OR_COPY} ${LIBCLC_LINK_OR_COPY_SOURCE} ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
483+
DEPENDS library-${obj_suffix}
471484
)
472-
add_custom_target( alias-${a}-${ARG_TRIPLE} ALL
473-
DEPENDS ${libclc_alias_lib}
485+
add_custom_target( alias-${alias_suffix} ALL
486+
DEPENDS ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
474487
)
475-
add_dependencies( ${ARG_PARENT_TARGET} alias-${a}-${ARG_TRIPLE} )
476-
set_target_properties( alias-${a}-${ARG_TRIPLE}
488+
add_dependencies( ${ARG_PARENT_TARGET} alias-${alias_suffix} )
489+
set_target_properties( alias-${alias_suffix}
477490
PROPERTIES FOLDER "libclc/Device IR/Aliases"
478491
)
479-
480-
# Install the library
481-
install(
482-
FILES ${libclc_alias_lib}
483-
DESTINATION ${LIBCLC_INSTALL_DIR}/${ARG_TRIPLE}/${a}
484-
)
492+
libclc_install(FILES ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix})
485493
endforeach( a )
486494
endfunction(add_libclc_builtin_set)
487495

0 commit comments

Comments
 (0)