Skip to content

Commit 15c2d1b

Browse files
authored
[libclc] Fix dependencies on generated convert builtins (#127515)
In #127378 it was reported that builds without clspv targets enabled were failing after #124727, as all targets had a dependency on a file that only clspv targets generated. A quick fix was merged in #127315 which wasn't correct. It moved the dependency on those generated files to the spirv targets, instead of onto the clspv targets. This means a build with spirv targets and without clspv targets would see the same problems as #127378 reported. I tried simply removing the requirement to explicitly add dependencies to the custom command, relying instead on the file-level dependencies. This didn't seem reliable enough; in some cases on a Makefiles build, the clang command compiling (e.g.,) convert.cl would begin before the file was fully written. Instead, we keep the target-level dependency but automatically infer it based on the generated file name, to avoid manual book-keeping of pairs of files and targets. This commit also fixes what looks like an unintended bug where, when ENABLE_RUNTIME_SUBNORMAL was enabled, the OpenCL conversions weren't being compiled.
1 parent 6d86a8a commit 15c2d1b

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

libclc/CMakeLists.txt

+12-10
Original file line numberDiff line numberDiff line change
@@ -243,30 +243,30 @@ add_custom_command(
243243
OUTPUT convert.cl
244244
COMMAND ${Python3_EXECUTABLE} ${script_loc} > convert.cl
245245
DEPENDS ${script_loc} )
246-
add_custom_target( "generate_convert.cl" DEPENDS convert.cl )
247-
set_target_properties( "generate_convert.cl" PROPERTIES FOLDER "libclc/Sourcegenning" )
246+
add_custom_target( generate-convert.cl DEPENDS convert.cl )
247+
set_target_properties( generate-convert.cl PROPERTIES FOLDER "libclc/Sourcegenning" )
248248

249249
add_custom_command(
250250
OUTPUT clc-convert.cl
251251
COMMAND ${Python3_EXECUTABLE} ${script_loc} --clc > clc-convert.cl
252252
DEPENDS ${script_loc} )
253-
add_custom_target( "clc-generate_convert.cl" DEPENDS clc-convert.cl )
254-
set_target_properties( "clc-generate_convert.cl" PROPERTIES FOLDER "libclc/Sourcegenning" )
253+
add_custom_target( generate-clc-convert.cl DEPENDS clc-convert.cl )
254+
set_target_properties( generate-clc-convert.cl PROPERTIES FOLDER "libclc/Sourcegenning" )
255255

256256
if ( clspv-- IN_LIST LIBCLC_TARGETS_TO_BUILD OR clspv64-- IN_LIST LIBCLC_TARGETS_TO_BUILD )
257257
add_custom_command(
258258
OUTPUT clspv-convert.cl
259259
COMMAND ${Python3_EXECUTABLE} ${script_loc} --clspv > clspv-convert.cl
260260
DEPENDS ${script_loc} )
261-
add_custom_target( "clspv-generate_convert.cl" DEPENDS clspv-convert.cl )
262-
set_target_properties( "clspv-generate_convert.cl" PROPERTIES FOLDER "libclc/Sourcegenning" )
261+
add_custom_target( generate-clspv-convert.cl DEPENDS clspv-convert.cl )
262+
set_target_properties( generate-clspv-convert.cl PROPERTIES FOLDER "libclc/Sourcegenning" )
263263

264264
add_custom_command(
265265
OUTPUT clc-clspv-convert.cl
266266
COMMAND ${Python3_EXECUTABLE} ${script_loc} --clc --clspv > clc-clspv-convert.cl
267267
DEPENDS ${script_loc} )
268-
add_custom_target( "clc-clspv-generate_convert.cl" DEPENDS clc-clspv-convert.cl )
269-
set_target_properties( "clc-clspv-generate_convert.cl" PROPERTIES FOLDER "libclc/Sourcegenning" )
268+
add_custom_target( generate-clc-clspv-convert.cl DEPENDS clc-clspv-convert.cl )
269+
set_target_properties( generate-clc-clspv-convert.cl PROPERTIES FOLDER "libclc/Sourcegenning" )
270270
endif()
271271

272272
enable_testing()
@@ -324,9 +324,11 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
324324
if( NOT ARCH STREQUAL spirv AND NOT ARCH STREQUAL spirv64 )
325325
if( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
326326
list( APPEND opencl_gen_files clspv-convert.cl )
327-
elseif ( NOT ENABLE_RUNTIME_SUBNORMAL )
327+
else()
328328
list( APPEND opencl_gen_files convert.cl )
329-
list( APPEND opencl_lib_files generic/lib/subnormal_use_default.ll )
329+
if ( NOT ENABLE_RUNTIME_SUBNORMAL )
330+
list( APPEND opencl_lib_files generic/lib/subnormal_use_default.ll )
331+
endif()
330332
endif()
331333
endif()
332334

libclc/cmake/modules/AddLibclc.cmake

+7-7
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,17 @@ function(add_libclc_builtin_set)
230230
# We need to take each file and produce an absolute input file, as well
231231
# as a unique architecture-specific output file. We deal with a mix of
232232
# different input files, which makes this trickier.
233+
set( input_file_dep )
233234
if( ${file} IN_LIST ARG_GEN_FILES )
234235
# Generated files are given just as file names, which we must make
235236
# absolute to the binary directory.
236237
set( input_file ${CMAKE_CURRENT_BINARY_DIR}/${file} )
237238
set( output_file "${LIBCLC_ARCH_OBJFILE_DIR}/${file}.bc" )
239+
# If a target exists that generates this file, add that as a dependency
240+
# of the custom command.
241+
if( TARGET generate-${file} )
242+
set( input_file_dep generate-${file} )
243+
endif()
238244
else()
239245
# Other files are originally relative to each SOURCE file, which are
240246
# then make relative to the libclc root directory. We must normalize
@@ -249,19 +255,13 @@ function(add_libclc_builtin_set)
249255

250256
get_filename_component( file_dir ${file} DIRECTORY )
251257

252-
if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
253-
set(CONVERT_DEP clspv-generate_convert.cl)
254-
else()
255-
set(CONVERT_DEP generate_convert.cl)
256-
endif()
257-
258258
compile_to_bc(
259259
TRIPLE ${ARG_TRIPLE}
260260
INPUT ${input_file}
261261
OUTPUT ${output_file}
262262
EXTRA_OPTS -fno-builtin -nostdlib
263263
"${ARG_COMPILE_FLAGS}" -I${CMAKE_CURRENT_SOURCE_DIR}/${file_dir}
264-
DEPENDENCIES ${CONVERT_DEP}
264+
DEPENDENCIES ${input_file_dep}
265265
)
266266
list( APPEND bytecode_files ${output_file} )
267267
endforeach()

0 commit comments

Comments
 (0)