Skip to content

[sycl-web] Resolve conflict with PR #19401. #19410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions libclc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,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}, "
Expand Down Expand Up @@ -342,6 +339,10 @@ else(LIBCLC_STANDALONE_BUILD)
endif(LIBCLC_STANDALONE_BUILD)
file( TO_CMAKE_PATH ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/clc LIBCLC_LIBRARY_OUTPUT_INTDIR )

# Setup the paths where libclc runtimes should be stored.
# FIXME: Align with upstream
set( LIBCLC_OUTPUT_LIBRARY_DIR ${LIBCLC_LIBRARY_OUTPUT_INTDIR} )

foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
message( STATUS "libclc target '${t}' is enabled" )
string( REPLACE "-" ";" TRIPLE ${t}-- )
Expand Down
170 changes: 44 additions & 126 deletions libclc/cmake/modules/AddLibclc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ endfunction()
function(link_bc)
cmake_parse_arguments(ARG
"INTERNALIZE"
"TARGET;RSP_DIR"
"TARGET"
"INPUTS;DEPENDENCIES"
${ARGN}
)
Expand All @@ -110,7 +110,7 @@ function(link_bc)
if( WIN32 OR CYGWIN )
# Create a response file in case the number of inputs exceeds command-line
# character limits on certain platforms.
file( TO_CMAKE_PATH ${ARG_RSP_DIR}/${ARG_TARGET}.rsp RSP_FILE )
file( TO_CMAKE_PATH ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.rsp RSP_FILE )
# Turn it into a space-separate list of input files
list( JOIN ARG_INPUTS " " RSP_INPUT )
file( GENERATE OUTPUT ${RSP_FILE} CONTENT ${RSP_INPUT} )
Expand Down Expand Up @@ -205,78 +205,6 @@ function(get_libclc_device_info)
endif()
endfunction()

function(add_libclc_alias alias target)
cmake_parse_arguments(ARG "" "" PARENT_TARGET "" ${ARGN})

if(CMAKE_HOST_UNIX AND NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
set(LIBCLC_LINK_OR_COPY create_symlink)
else()
set(LIBCLC_LINK_OR_COPY copy)
endif()

add_custom_command(
OUTPUT ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${alias_suffix}
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_LIBRARY_OUTPUT_INTDIR}
COMMAND ${CMAKE_COMMAND} -E
${LIBCLC_LINK_OR_COPY} ${target}.bc
${alias_suffix}
WORKING_DIRECTORY
${LIBCLC_LIBRARY_OUTPUT_INTDIR}
DEPENDS "prepare-${target}"
)
add_custom_target( alias-${alias_suffix} ALL
DEPENDS "${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${alias_suffix}" )
add_dependencies(${ARG_PARENT_TARGET} alias-${alias_suffix})

install( FILES ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${alias_suffix}
DESTINATION ${CMAKE_INSTALL_DATADIR}/clc )

endfunction(add_libclc_alias alias target)

# Runs opt and prepare-builtins on a bitcode file specified by lib_tgt
#
# ARGUMENTS:
# * LIB_TGT string
# Target name that becomes dependent on the out file named LIB_TGT.bc
# * IN_FILE string
# Target name of the input bytecode file
# * OUT_DIR string
# Name of the directory where the output should be placed
# * DEPENDENCIES <string> ...
# List of extra dependencies to inject
function(process_bc out_file)
cmake_parse_arguments(ARG
""
"LIB_TGT;IN_FILE;OUT_DIR"
"OPT_FLAGS;DEPENDENCIES"
${ARGN})
add_custom_command( OUTPUT ${ARG_LIB_TGT}.bc
COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${ARG_LIB_TGT}.bc
${ARG_IN_FILE}
DEPENDS ${opt_target} ${ARG_IN_FILE} ${ARG_DEPENDENCIES}
)
add_custom_target( ${ARG_LIB_TGT}
ALL DEPENDS ${ARG_LIB_TGT}.bc
)
set_target_properties( ${ARG_LIB_TGT}
PROPERTIES TARGET_FILE ${ARG_LIB_TGT}.bc
)

set( builtins_opt_lib $<TARGET_PROPERTY:${ARG_LIB_TGT},TARGET_FILE> )

# Add prepare target
add_custom_command( OUTPUT ${ARG_OUT_DIR}/${out_file}
COMMAND ${prepare_builtins_exe} -o ${ARG_OUT_DIR}/${out_file}
${builtins_opt_lib}
DEPENDS ${builtins_opt_lib} ${ARG_LIB_TGT} ${prepare_builtins_target} )
add_custom_target( prepare-${out_file} ALL
DEPENDS ${ARG_OUT_DIR}/${out_file}
)
set_target_properties( prepare-${out_file}
PROPERTIES TARGET_FILE ${ARG_OUT_DIR}/${out_file}
)
endfunction()

# Compiles a list of library source files (provided by LIB_FILES/GEN_FILES) and
# compiles them to LLVM bytecode (or SPIR-V), links them together and optimizes
# them.
Expand Down Expand Up @@ -411,7 +339,6 @@ function(add_libclc_builtin_set)
link_bc(
TARGET ${builtins_link_lib_tgt}
INPUTS ${bytecode_files}
RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR}
DEPENDENCIES ${builtins_comp_lib_tgt}
)
else()
Expand All @@ -422,7 +349,6 @@ function(add_libclc_builtin_set)
link_bc(
TARGET ${builtins_link_lib_tmp_tgt}
INPUTS ${bytecode_files}
RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR}
DEPENDENCIES ${builtins_comp_lib_tgt}
)
set( internal_link_depend_files )
Expand All @@ -434,7 +360,6 @@ function(add_libclc_builtin_set)
TARGET ${builtins_link_lib_tgt}
INPUTS $<TARGET_PROPERTY:${builtins_link_lib_tmp_tgt},TARGET_FILE>
${internal_link_depend_files}
RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR}
DEPENDENCIES ${builtins_link_lib_tmp_tgt} ${ARG_INTERNAL_LINK_DEPENDENCIES}
)
endif()
Expand All @@ -447,9 +372,15 @@ function(add_libclc_builtin_set)

set( builtins_link_lib $<TARGET_PROPERTY:${builtins_link_lib_tgt},TARGET_FILE> )

add_custom_command( OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_OUTPUT_LIBRARY_DIR}
DEPENDS ${builtins_link_lib} prepare_builtins )

# 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 )
set( libclc_builtins_lib ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${obj_suffix} )
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}
DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
Expand All @@ -474,7 +405,7 @@ function(add_libclc_builtin_set)
set( builtins_opt_lib $<TARGET_PROPERTY:${builtins_opt_lib_tgt},TARGET_FILE> )

set( obj_suffix ${ARG_ARCH_SUFFIX}.bc )
set( libclc_builtins_lib ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${obj_suffix} )
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}
Expand All @@ -489,11 +420,6 @@ function(add_libclc_builtin_set)
# targets dependent on libclc.
add_dependencies(${ARG_PARENT_TARGET} prepare-${obj_suffix})

# SPIR-V targets can exit early here
if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
return()
endif()

# 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.
Expand All @@ -512,49 +438,11 @@ function(add_libclc_builtin_set)
return()
endif()

# 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
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}
WORKING_DIRECTORY ${LIBCLC_LIBRARY_OUTPUT_INTDIR} )
set_tests_properties( external-calls-${obj_suffix}
PROPERTIES ENVIRONMENT "LLVM_CONFIG=${LLVM_CONFIG}" )
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 )
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}
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"
)
endforeach( a )

# Generate remangled variants if requested
if( ARG_REMANGLE )
set( dummy_in ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/libclc_dummy_in.cc )
set( dummy_in ${LIBCLC_OUTPUT_LIBRARY_DIR}/libclc_dummy_in.cc )
add_custom_command( OUTPUT ${dummy_in}
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_LIBRARY_OUTPUT_INTDIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_OUTPUT_LIBRARY_DIR}
COMMAND ${CMAKE_COMMAND} -E touch ${dummy_in}
)
set(long_widths l32 l64)
Expand All @@ -571,9 +459,9 @@ function(add_libclc_builtin_set)
foreach(signedness ${char_signedness})
# Remangle
set( builtins_remangle_path
"${LIBCLC_LIBRARY_OUTPUT_INTDIR}/remangled-${long_width}-${signedness}_char.${obj_suffix_mangled}" )
"${LIBCLC_OUTPUT_LIBRARY_DIR}/remangled-${long_width}-${signedness}_char.${obj_suffix_mangled}" )
add_custom_command( OUTPUT "${builtins_remangle_path}"
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_LIBRARY_OUTPUT_INTDIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_OUTPUT_LIBRARY_DIR}
COMMAND ${libclc-remangler_exe}
-o "${builtins_remangle_path}"
--triple=${ARG_TRIPLE}
Expand Down Expand Up @@ -618,6 +506,36 @@ function(add_libclc_builtin_set)
endforeach()
endif()

# 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
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}
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"
)
add_dependencies(${ARG_PARENT_TARGET} alias-${alias_suffix})
install(
FILES ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
DESTINATION "${CMAKE_INSTALL_DATADIR}/clc"
)
endforeach( a )
endfunction(add_libclc_builtin_set)

# Produces a list of libclc source files by walking over SOURCES files in a
Expand Down
2 changes: 1 addition & 1 deletion libclc/libspirv/lib/generic/math/acos.cl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
#include <libspirv/spirv.h>

#define FUNCTION __spirv_ocl_acos
#define __CLC_FUNCTION(x) __clc_acos
#define __IMPL_FUNCTION(x) __clc_acos
#define __CLC_BODY <clc/shared/unary_def.inc>
#include <clc/math/gentype.inc>
2 changes: 1 addition & 1 deletion libclc/libspirv/lib/generic/math/asin.cl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
#include <libspirv/spirv.h>

#define FUNCTION __spirv_ocl_asin
#define __CLC_FUNCTION(x) __clc_asin
#define __IMPL_FUNCTION(x) __clc_asin
#define __CLC_BODY <clc/shared/unary_def.inc>
#include <clc/math/gentype.inc>
2 changes: 1 addition & 1 deletion libclc/libspirv/lib/generic/math/modf.cl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
#include <libspirv/spirv.h>

#define FUNCTION __spirv_ocl_modf
#define __CLC_FUNCTION(x) __clc_modf
#define __IMPL_FUNCTION(x) __clc_modf
#define __CLC_BODY <clc/math/unary_def_with_ptr.inc>
#include <clc/math/gentype.inc>