Skip to content

Commit 17fe1b5

Browse files
authored
[sycl-web] Correct conflict resolutions and output path. (#19407)
The builtins need to be written to the LIBCLC_LIBRARY_OUTPUT_INTDIR in order for the tests to pass. This also cleans up the conflict resolutions.
1 parent fb04b56 commit 17fe1b5

File tree

1 file changed

+61
-62
lines changed

1 file changed

+61
-62
lines changed

libclc/cmake/modules/AddLibclc.cmake

Lines changed: 61 additions & 62 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"
104+
"TARGET;RSP_DIR"
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 ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.rsp RSP_FILE )
113+
file( TO_CMAKE_PATH ${ARG_RSP_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} )
@@ -126,14 +126,14 @@ function(link_bc)
126126
endif()
127127

128128
add_custom_command(
129-
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.bc
130-
COMMAND ${llvm-link_exe} ${link_flags} -o ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.bc ${LINK_INPUT_ARG}
129+
OUTPUT ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc
130+
COMMAND ${llvm-link_exe} ${link_flags} -o ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc ${LINK_INPUT_ARG}
131131
DEPENDS ${llvm-link_target} ${ARG_DEPENDENCIES} ${ARG_INPUTS} ${RSP_FILE}
132132
)
133133

134-
add_custom_target( ${ARG_TARGET} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.bc )
134+
add_custom_target( ${ARG_TARGET} ALL DEPENDS ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc )
135135
set_target_properties( ${ARG_TARGET} PROPERTIES
136-
TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.bc
136+
TARGET_FILE ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc
137137
FOLDER "libclc/Device IR/Linking"
138138
)
139139
endfunction()
@@ -250,21 +250,17 @@ function(process_bc out_file)
250250
"LIB_TGT;IN_FILE;OUT_DIR"
251251
"OPT_FLAGS;DEPENDENCIES"
252252
${ARGN})
253-
254-
# Check if the target already exists
255-
if(NOT TARGET ${ARG_LIB_TGT})
256-
add_custom_command(OUTPUT ${ARG_LIB_TGT}.bc
257-
COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${ARG_LIB_TGT}.bc
258-
${ARG_IN_FILE}
259-
DEPENDS ${opt_target} ${ARG_IN_FILE} ${ARG_DEPENDENCIES}
260-
)
261-
add_custom_target(${ARG_LIB_TGT}
262-
ALL DEPENDS ${ARG_LIB_TGT}.bc
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
263260
)
264-
set_target_properties(${ARG_LIB_TGT}
265-
PROPERTIES TARGET_FILE ${ARG_LIB_TGT}.bc
261+
set_target_properties( ${ARG_LIB_TGT}
262+
PROPERTIES TARGET_FILE ${ARG_LIB_TGT}.bc
266263
)
267-
endif()
268264

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

@@ -415,6 +411,7 @@ function(add_libclc_builtin_set)
415411
link_bc(
416412
TARGET ${builtins_link_lib_tgt}
417413
INPUTS ${bytecode_files}
414+
RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR}
418415
DEPENDENCIES ${builtins_comp_lib_tgt}
419416
)
420417
else()
@@ -425,6 +422,7 @@ function(add_libclc_builtin_set)
425422
link_bc(
426423
TARGET ${builtins_link_lib_tmp_tgt}
427424
INPUTS ${bytecode_files}
425+
RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR}
428426
DEPENDENCIES ${builtins_comp_lib_tgt}
429427
)
430428
set( internal_link_depend_files )
@@ -436,6 +434,7 @@ function(add_libclc_builtin_set)
436434
TARGET ${builtins_link_lib_tgt}
437435
INPUTS $<TARGET_PROPERTY:${builtins_link_lib_tmp_tgt},TARGET_FILE>
438436
${internal_link_depend_files}
437+
RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR}
439438
DEPENDENCIES ${builtins_link_lib_tmp_tgt} ${ARG_INTERNAL_LINK_DEPENDENCIES}
440439
)
441440
endif()
@@ -448,15 +447,9 @@ function(add_libclc_builtin_set)
448447

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

451-
add_custom_command( OUTPUT ${LIBCLC_LIBRARY_OUTPUT_INTDIR}
452-
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_LIBRARY_OUTPUT_INTDIR}
453-
DEPENDS ${builtins_link_lib} prepare_builtins )
454-
455-
# For SPIR-V targets we diverage at this point and generate SPIR-V using the
456-
# llvm-spirv tool.
457450
if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
458451
set( obj_suffix ${ARG_ARCH_SUFFIX}.spv )
459-
set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} )
452+
set( libclc_builtins_lib ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${obj_suffix} )
460453
add_custom_command( OUTPUT ${libclc_builtins_lib}
461454
COMMAND ${llvm-spirv_exe} ${spvflags} -o ${libclc_builtins_lib} ${builtins_link_lib}
462455
DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
@@ -481,7 +474,7 @@ function(add_libclc_builtin_set)
481474
set( builtins_opt_lib $<TARGET_PROPERTY:${builtins_opt_lib_tgt},TARGET_FILE> )
482475

483476
set( obj_suffix ${ARG_ARCH_SUFFIX}.bc )
484-
set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} )
477+
set( libclc_builtins_lib ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${obj_suffix} )
485478
add_custom_command( OUTPUT ${libclc_builtins_lib}
486479
COMMAND ${prepare_builtins_exe} -o ${libclc_builtins_lib} ${builtins_opt_lib}
487480
DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target}
@@ -495,7 +488,11 @@ function(add_libclc_builtin_set)
495488
# Add dependency to top-level pseudo target to ease making other
496489
# targets dependent on libclc.
497490
add_dependencies(${ARG_PARENT_TARGET} prepare-${obj_suffix})
498-
set( builtins_lib ${obj_suffix} )
491+
492+
# SPIR-V targets can exit early here
493+
if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
494+
return()
495+
endif()
499496

500497
# Also add a 'prepare' target for the triple. Since a triple may have
501498
# multiple devices, ensure we only try to create the triple target once. The
@@ -515,6 +512,38 @@ function(add_libclc_builtin_set)
515512
return()
516513
endif()
517514

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+
foreach( a ${ARG_ALIASES} )
529+
set( alias_suffix "${a}-${ARG_TRIPLE}.bc" )
530+
add_custom_command(
531+
OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
532+
COMMAND ${CMAKE_COMMAND} -E create_symlink ${libclc_builtins_lib} ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
533+
DEPENDS prepare-${obj_suffix}
534+
)
535+
add_custom_target( alias-${alias_suffix} ALL
536+
DEPENDS ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
537+
)
538+
set_target_properties( alias-${alias_suffix}
539+
PROPERTIES FOLDER "libclc/Device IR/Aliases"
540+
)
541+
install(
542+
FILES ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
543+
DESTINATION "${CMAKE_INSTALL_DATADIR}/clc"
544+
)
545+
endforeach( a )
546+
518547
# Generate remangled variants if requested
519548
if( ARG_REMANGLE )
520549
set( dummy_in ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/libclc_dummy_in.cc )
@@ -544,9 +573,9 @@ function(add_libclc_builtin_set)
544573
--triple=${ARG_TRIPLE}
545574
--long-width=${long_width}
546575
--char-signedness=${signedness}
547-
--input-ir=${builtins_lib}
576+
--input-ir=${libclc_builtins_lib}
548577
${dummy_in}
549-
DEPENDS ${builtins_lib} ${libclc-remangler_target} ${dummy_in})
578+
DEPENDS ${libclc_builtins_lib} ${libclc-remangler_target} ${dummy_in})
550579
add_custom_target( "remangled-${long_width}-${signedness}_char.${obj_suffix_mangled}" ALL
551580
DEPENDS "${builtins_remangle_path}" "${dummy_in}")
552581
set_target_properties("remangled-${long_width}-${signedness}_char.${obj_suffix_mangled}"
@@ -569,7 +598,7 @@ function(add_libclc_builtin_set)
569598
# dependency against check-libclc.
570599
set(libclc-remangler-tests)
571600
set(libclc-remangler-test-no 0)
572-
foreach(target-ir ${builtins_opt_lib} ${builtins_link_lib} ${builtins_lib})
601+
foreach(target-ir ${builtins_opt_lib} ${builtins_link_lib} ${libclc_builtins_lib})
573602
math(EXPR libclc-remangler-test-no "${libclc-remangler-test-no}+1")
574603
set(current-test "libclc-remangler-test-${obj_suffix}-${libclc-remangler-test-no}")
575604
add_custom_target(${current-test}
@@ -578,41 +607,11 @@ function(add_libclc_builtin_set)
578607
--char-signedness=signed
579608
--input-ir=${target-ir}
580609
${dummy_in} -t -o -
581-
DEPENDS ${builtins_lib} "${dummy_in}" ${libclc-remangler_target})
610+
DEPENDS ${libclc_builtins_lib} "${dummy_in}" ${libclc-remangler_target})
582611
list(APPEND libclc-remangler-tests ${current-test})
583612
endforeach()
584613
endif()
585614

586-
# Add a test for whether or not the libraries contain unresolved calls which
587-
# would usually indicate a build problem. Note that we don't perform this
588-
# test for all libclc targets:
589-
# * nvptx-- targets don't include workitem builtins
590-
# * clspv targets don't include all OpenCL builtins
591-
if( NOT ARG_ARCH MATCHES "^(nvptx|clspv)(64)?$" )
592-
add_test( NAME external-calls-${obj_suffix}
593-
COMMAND ./check_external_calls.sh ${libclc_builtins_lib} ${LLVM_TOOLS_BINARY_DIR}
594-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
595-
endif()
596-
597-
foreach( a ${ARG_ALIASES} )
598-
set( alias_suffix "${a}-${ARG_TRIPLE}.bc" )
599-
add_custom_command(
600-
OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
601-
COMMAND ${CMAKE_COMMAND} -E create_symlink ${libclc_builtins_lib} ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
602-
DEPENDS prepare-${obj_suffix}
603-
)
604-
add_custom_target( alias-${alias_suffix} ALL
605-
DEPENDS ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
606-
)
607-
set_target_properties( alias-${alias_suffix}
608-
PROPERTIES FOLDER "libclc/Device IR/Aliases"
609-
)
610-
install(
611-
FILES ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
612-
DESTINATION "${CMAKE_INSTALL_DATADIR}/clc"
613-
)
614-
endforeach( a )
615-
616615
endfunction(add_libclc_builtin_set)
617616

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

0 commit comments

Comments
 (0)