Skip to content

Commit 0c03f5f

Browse files
authored
[sycl-web] Resolve conflict with PR #19401. (#19410)
This includes all of the changes from #19401 and resolves the conflict with 17fe1b5.
1 parent 32b61f3 commit 0c03f5f

File tree

5 files changed

+51
-132
lines changed

5 files changed

+51
-132
lines changed

libclc/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ else()
9292
endif()
9393
endif()
9494

95-
# Setup the paths where libclc runtimes should be stored.
96-
set( LIBCLC_OUTPUT_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
97-
9895
if( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
9996
message( WARNING "Using custom LLVM tools to build libclc: "
10097
"${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}, "
@@ -342,6 +339,10 @@ else(LIBCLC_STANDALONE_BUILD)
342339
endif(LIBCLC_STANDALONE_BUILD)
343340
file( TO_CMAKE_PATH ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/clc LIBCLC_LIBRARY_OUTPUT_INTDIR )
344341

342+
# Setup the paths where libclc runtimes should be stored.
343+
# FIXME: Align with upstream
344+
set( LIBCLC_OUTPUT_LIBRARY_DIR ${LIBCLC_LIBRARY_OUTPUT_INTDIR} )
345+
345346
foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
346347
message( STATUS "libclc target '${t}' is enabled" )
347348
string( REPLACE "-" ";" TRIPLE ${t}-- )

libclc/cmake/modules/AddLibclc.cmake

Lines changed: 44 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ endfunction()
101101
function(link_bc)
102102
cmake_parse_arguments(ARG
103103
"INTERNALIZE"
104-
"TARGET;RSP_DIR"
104+
"TARGET"
105105
"INPUTS;DEPENDENCIES"
106106
${ARGN}
107107
)
@@ -110,7 +110,7 @@ function(link_bc)
110110
if( WIN32 OR CYGWIN )
111111
# Create a response file in case the number of inputs exceeds command-line
112112
# character limits on certain platforms.
113-
file( TO_CMAKE_PATH ${ARG_RSP_DIR}/${ARG_TARGET}.rsp RSP_FILE )
113+
file( TO_CMAKE_PATH ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.rsp RSP_FILE )
114114
# Turn it into a space-separate list of input files
115115
list( JOIN ARG_INPUTS " " RSP_INPUT )
116116
file( GENERATE OUTPUT ${RSP_FILE} CONTENT ${RSP_INPUT} )
@@ -205,78 +205,6 @@ function(get_libclc_device_info)
205205
endif()
206206
endfunction()
207207

208-
function(add_libclc_alias alias target)
209-
cmake_parse_arguments(ARG "" "" PARENT_TARGET "" ${ARGN})
210-
211-
if(CMAKE_HOST_UNIX AND NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
212-
set(LIBCLC_LINK_OR_COPY create_symlink)
213-
else()
214-
set(LIBCLC_LINK_OR_COPY copy)
215-
endif()
216-
217-
add_custom_command(
218-
OUTPUT ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${alias_suffix}
219-
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_LIBRARY_OUTPUT_INTDIR}
220-
COMMAND ${CMAKE_COMMAND} -E
221-
${LIBCLC_LINK_OR_COPY} ${target}.bc
222-
${alias_suffix}
223-
WORKING_DIRECTORY
224-
${LIBCLC_LIBRARY_OUTPUT_INTDIR}
225-
DEPENDS "prepare-${target}"
226-
)
227-
add_custom_target( alias-${alias_suffix} ALL
228-
DEPENDS "${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${alias_suffix}" )
229-
add_dependencies(${ARG_PARENT_TARGET} alias-${alias_suffix})
230-
231-
install( FILES ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${alias_suffix}
232-
DESTINATION ${CMAKE_INSTALL_DATADIR}/clc )
233-
234-
endfunction(add_libclc_alias alias target)
235-
236-
# Runs opt and prepare-builtins on a bitcode file specified by lib_tgt
237-
#
238-
# ARGUMENTS:
239-
# * LIB_TGT string
240-
# Target name that becomes dependent on the out file named LIB_TGT.bc
241-
# * IN_FILE string
242-
# Target name of the input bytecode file
243-
# * OUT_DIR string
244-
# Name of the directory where the output should be placed
245-
# * DEPENDENCIES <string> ...
246-
# List of extra dependencies to inject
247-
function(process_bc out_file)
248-
cmake_parse_arguments(ARG
249-
""
250-
"LIB_TGT;IN_FILE;OUT_DIR"
251-
"OPT_FLAGS;DEPENDENCIES"
252-
${ARGN})
253-
add_custom_command( OUTPUT ${ARG_LIB_TGT}.bc
254-
COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${ARG_LIB_TGT}.bc
255-
${ARG_IN_FILE}
256-
DEPENDS ${opt_target} ${ARG_IN_FILE} ${ARG_DEPENDENCIES}
257-
)
258-
add_custom_target( ${ARG_LIB_TGT}
259-
ALL DEPENDS ${ARG_LIB_TGT}.bc
260-
)
261-
set_target_properties( ${ARG_LIB_TGT}
262-
PROPERTIES TARGET_FILE ${ARG_LIB_TGT}.bc
263-
)
264-
265-
set( builtins_opt_lib $<TARGET_PROPERTY:${ARG_LIB_TGT},TARGET_FILE> )
266-
267-
# Add prepare target
268-
add_custom_command( OUTPUT ${ARG_OUT_DIR}/${out_file}
269-
COMMAND ${prepare_builtins_exe} -o ${ARG_OUT_DIR}/${out_file}
270-
${builtins_opt_lib}
271-
DEPENDS ${builtins_opt_lib} ${ARG_LIB_TGT} ${prepare_builtins_target} )
272-
add_custom_target( prepare-${out_file} ALL
273-
DEPENDS ${ARG_OUT_DIR}/${out_file}
274-
)
275-
set_target_properties( prepare-${out_file}
276-
PROPERTIES TARGET_FILE ${ARG_OUT_DIR}/${out_file}
277-
)
278-
endfunction()
279-
280208
# Compiles a list of library source files (provided by LIB_FILES/GEN_FILES) and
281209
# compiles them to LLVM bytecode (or SPIR-V), links them together and optimizes
282210
# them.
@@ -411,7 +339,6 @@ function(add_libclc_builtin_set)
411339
link_bc(
412340
TARGET ${builtins_link_lib_tgt}
413341
INPUTS ${bytecode_files}
414-
RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR}
415342
DEPENDENCIES ${builtins_comp_lib_tgt}
416343
)
417344
else()
@@ -422,7 +349,6 @@ function(add_libclc_builtin_set)
422349
link_bc(
423350
TARGET ${builtins_link_lib_tmp_tgt}
424351
INPUTS ${bytecode_files}
425-
RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR}
426352
DEPENDENCIES ${builtins_comp_lib_tgt}
427353
)
428354
set( internal_link_depend_files )
@@ -434,7 +360,6 @@ function(add_libclc_builtin_set)
434360
TARGET ${builtins_link_lib_tgt}
435361
INPUTS $<TARGET_PROPERTY:${builtins_link_lib_tmp_tgt},TARGET_FILE>
436362
${internal_link_depend_files}
437-
RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR}
438363
DEPENDENCIES ${builtins_link_lib_tmp_tgt} ${ARG_INTERNAL_LINK_DEPENDENCIES}
439364
)
440365
endif()
@@ -447,9 +372,15 @@ function(add_libclc_builtin_set)
447372

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

375+
add_custom_command( OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR}
376+
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_OUTPUT_LIBRARY_DIR}
377+
DEPENDS ${builtins_link_lib} prepare_builtins )
378+
379+
# For SPIR-V targets we diverage at this point and generate SPIR-V using the
380+
# llvm-spirv tool.
450381
if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
451382
set( obj_suffix ${ARG_ARCH_SUFFIX}.spv )
452-
set( libclc_builtins_lib ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${obj_suffix} )
383+
set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} )
453384
add_custom_command( OUTPUT ${libclc_builtins_lib}
454385
COMMAND ${llvm-spirv_exe} ${spvflags} -o ${libclc_builtins_lib} ${builtins_link_lib}
455386
DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
@@ -474,7 +405,7 @@ function(add_libclc_builtin_set)
474405
set( builtins_opt_lib $<TARGET_PROPERTY:${builtins_opt_lib_tgt},TARGET_FILE> )
475406

476407
set( obj_suffix ${ARG_ARCH_SUFFIX}.bc )
477-
set( libclc_builtins_lib ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${obj_suffix} )
408+
set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} )
478409
add_custom_command( OUTPUT ${libclc_builtins_lib}
479410
COMMAND ${prepare_builtins_exe} -o ${libclc_builtins_lib} ${builtins_opt_lib}
480411
DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target}
@@ -489,11 +420,6 @@ function(add_libclc_builtin_set)
489420
# targets dependent on libclc.
490421
add_dependencies(${ARG_PARENT_TARGET} prepare-${obj_suffix})
491422

492-
# SPIR-V targets can exit early here
493-
if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
494-
return()
495-
endif()
496-
497423
# Also add a 'prepare' target for the triple. Since a triple may have
498424
# multiple devices, ensure we only try to create the triple target once. The
499425
# triple's target will build all of the bytecode for its constituent devices.
@@ -512,49 +438,11 @@ function(add_libclc_builtin_set)
512438
return()
513439
endif()
514440

515-
# Add a test for whether or not the libraries contain unresolved calls which
516-
# would usually indicate a build problem. Note that we don't perform this
517-
# test for all libclc targets:
518-
# * nvptx-- targets don't include workitem builtins
519-
# * clspv targets don't include all OpenCL builtins
520-
if( NOT ARG_ARCH MATCHES "^(nvptx|clspv)(64)?$" )
521-
add_test( NAME external-calls-${obj_suffix}
522-
COMMAND ./check_external_calls.sh ${libclc_builtins_lib} ${LLVM_TOOLS_BINARY_DIR}
523-
WORKING_DIRECTORY ${LIBCLC_LIBRARY_OUTPUT_INTDIR} )
524-
set_tests_properties( external-calls-${obj_suffix}
525-
PROPERTIES ENVIRONMENT "LLVM_CONFIG=${LLVM_CONFIG}" )
526-
endif()
527-
528-
if(CMAKE_HOST_UNIX OR LLVM_USE_SYMLINKS)
529-
set(LIBCLC_LINK_OR_COPY create_symlink)
530-
else()
531-
set(LIBCLC_LINK_OR_COPY copy)
532-
endif()
533-
534-
foreach( a IN LISTS ARG_ALIASES )
535-
set( alias_suffix "${a}-${ARG_TRIPLE}.bc" )
536-
add_custom_command(
537-
OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
538-
COMMAND ${CMAKE_COMMAND} -E ${LIBCLC_LINK_OR_COPY} ${libclc_builtins_lib} ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
539-
DEPENDS prepare-${obj_suffix}
540-
)
541-
add_custom_target( alias-${alias_suffix} ALL
542-
DEPENDS ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
543-
)
544-
set_target_properties( alias-${alias_suffix}
545-
PROPERTIES FOLDER "libclc/Device IR/Aliases"
546-
)
547-
install(
548-
FILES ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
549-
DESTINATION "${CMAKE_INSTALL_DATADIR}/clc"
550-
)
551-
endforeach( a )
552-
553441
# Generate remangled variants if requested
554442
if( ARG_REMANGLE )
555-
set( dummy_in ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/libclc_dummy_in.cc )
443+
set( dummy_in ${LIBCLC_OUTPUT_LIBRARY_DIR}/libclc_dummy_in.cc )
556444
add_custom_command( OUTPUT ${dummy_in}
557-
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_LIBRARY_OUTPUT_INTDIR}
445+
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_OUTPUT_LIBRARY_DIR}
558446
COMMAND ${CMAKE_COMMAND} -E touch ${dummy_in}
559447
)
560448
set(long_widths l32 l64)
@@ -571,9 +459,9 @@ function(add_libclc_builtin_set)
571459
foreach(signedness ${char_signedness})
572460
# Remangle
573461
set( builtins_remangle_path
574-
"${LIBCLC_LIBRARY_OUTPUT_INTDIR}/remangled-${long_width}-${signedness}_char.${obj_suffix_mangled}" )
462+
"${LIBCLC_OUTPUT_LIBRARY_DIR}/remangled-${long_width}-${signedness}_char.${obj_suffix_mangled}" )
575463
add_custom_command( OUTPUT "${builtins_remangle_path}"
576-
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_LIBRARY_OUTPUT_INTDIR}
464+
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_OUTPUT_LIBRARY_DIR}
577465
COMMAND ${libclc-remangler_exe}
578466
-o "${builtins_remangle_path}"
579467
--triple=${ARG_TRIPLE}
@@ -618,6 +506,36 @@ function(add_libclc_builtin_set)
618506
endforeach()
619507
endif()
620508

509+
# Add a test for whether or not the libraries contain unresolved calls which
510+
# would usually indicate a build problem. Note that we don't perform this
511+
# test for all libclc targets:
512+
# * nvptx-- targets don't include workitem builtins
513+
# * clspv targets don't include all OpenCL builtins
514+
if( NOT ARG_ARCH MATCHES "^(nvptx|clspv)(64)?$" )
515+
add_test( NAME external-calls-${obj_suffix}
516+
COMMAND ./check_external_calls.sh ${libclc_builtins_lib} ${LLVM_TOOLS_BINARY_DIR}
517+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
518+
endif()
519+
520+
foreach( a ${ARG_ALIASES} )
521+
set( alias_suffix "${a}-${ARG_TRIPLE}.bc" )
522+
add_custom_command(
523+
OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
524+
COMMAND ${CMAKE_COMMAND} -E create_symlink ${libclc_builtins_lib} ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
525+
DEPENDS prepare-${obj_suffix}
526+
)
527+
add_custom_target( alias-${alias_suffix} ALL
528+
DEPENDS ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
529+
)
530+
set_target_properties( alias-${alias_suffix}
531+
PROPERTIES FOLDER "libclc/Device IR/Aliases"
532+
)
533+
add_dependencies(${ARG_PARENT_TARGET} alias-${alias_suffix})
534+
install(
535+
FILES ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
536+
DESTINATION "${CMAKE_INSTALL_DATADIR}/clc"
537+
)
538+
endforeach( a )
621539
endfunction(add_libclc_builtin_set)
622540

623541
# Produces a list of libclc source files by walking over SOURCES files in a

libclc/libspirv/lib/generic/math/acos.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
#include <libspirv/spirv.h>
1111

1212
#define FUNCTION __spirv_ocl_acos
13-
#define __CLC_FUNCTION(x) __clc_acos
13+
#define __IMPL_FUNCTION(x) __clc_acos
1414
#define __CLC_BODY <clc/shared/unary_def.inc>
1515
#include <clc/math/gentype.inc>

libclc/libspirv/lib/generic/math/asin.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
#include <libspirv/spirv.h>
1111

1212
#define FUNCTION __spirv_ocl_asin
13-
#define __CLC_FUNCTION(x) __clc_asin
13+
#define __IMPL_FUNCTION(x) __clc_asin
1414
#define __CLC_BODY <clc/shared/unary_def.inc>
1515
#include <clc/math/gentype.inc>

libclc/libspirv/lib/generic/math/modf.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
#include <libspirv/spirv.h>
1111

1212
#define FUNCTION __spirv_ocl_modf
13-
#define __CLC_FUNCTION(x) __clc_modf
13+
#define __IMPL_FUNCTION(x) __clc_modf
1414
#define __CLC_BODY <clc/math/unary_def_with_ptr.inc>
1515
#include <clc/math/gentype.inc>

0 commit comments

Comments
 (0)