https://github.com/wenju-he updated https://github.com/llvm/llvm-project/pull/130755
>From 1f8b5bfbfea6b562e9cae088256e8e5dddf0a335 Mon Sep 17 00:00:00 2001 From: Wenju He <wenju...@intel.com> Date: Tue, 11 Mar 2025 04:24:36 -0700 Subject: [PATCH 1/4] [libclc] Fix commands in compile_to_bc are executed sequentially In libclc, we observe that compiling OpenCL source files to bitcode is executed sequentially on Windows, which increases debug build time by about an hour. add_custom_command may introduce additional implicit dependencies, see https://gitlab.kitware.com/cmake/cmake/-/issues/17097 This PR adds a target for each command and enables parallel builds of OpenCL source files. --- libclc/cmake/modules/AddLibclc.cmake | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index 911559ff4bfa9..9dc328fcd489c 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -1,6 +1,8 @@ # Compiles an OpenCL C - or assembles an LL file - to bytecode # # Arguments: +# * TARGET <string> +# Custom target to create # * TRIPLE <string> # Target triple for which to compile the bytecode file. # * INPUT <string> @@ -17,7 +19,7 @@ function(compile_to_bc) cmake_parse_arguments(ARG "" - "TRIPLE;INPUT;OUTPUT" + "TARGET;TRIPLE;INPUT;OUTPUT" "EXTRA_OPTS;DEPENDENCIES" ${ARGN} ) @@ -60,9 +62,11 @@ function(compile_to_bc) DEPENDS ${clang_target} ${ARG_INPUT} - ${ARG_DEPENDENCIES} DEPFILE ${ARG_OUTPUT}.d ) + add_custom_target( ${ARG_TARGET} + DEPENDS ${ARG_OUTPUT}${TMP_SUFFIX} ${ARG_DEPENDENCIES} + ) if( ${FILE_EXT} STREQUAL ".ll" ) add_custom_command( @@ -70,6 +74,7 @@ function(compile_to_bc) COMMAND ${llvm-as_exe} -o ${ARG_OUTPUT} ${ARG_OUTPUT}${TMP_SUFFIX} DEPENDS ${llvm-as_target} ${ARG_OUTPUT}${TMP_SUFFIX} ) + add_custom_target( ${ARG_TARGET}-as DEPENDS ${ARG_OUTPUT} ) endif() endfunction() @@ -227,6 +232,7 @@ function(add_libclc_builtin_set) set( bytecode_files ) set( bytecode_ir_files ) + set( compile_tgts ) foreach( file IN LISTS ARG_GEN_FILES ARG_LIB_FILES ) # We need to take each file and produce an absolute input file, as well # as a unique architecture-specific output file. We deal with a mix of @@ -256,7 +262,11 @@ function(add_libclc_builtin_set) get_filename_component( file_dir ${file} DIRECTORY ) + string( REPLACE "/" "-" replaced ${file} ) + set( tgt compile_tgt-${ARG_ARCH_SUFFIX}${replaced}) + compile_to_bc( + TARGET ${tgt} TRIPLE ${ARG_TRIPLE} INPUT ${input_file} OUTPUT ${output_file} @@ -264,11 +274,13 @@ function(add_libclc_builtin_set) "${ARG_COMPILE_FLAGS}" -I${CMAKE_CURRENT_SOURCE_DIR}/${file_dir} DEPENDENCIES ${input_file_dep} ) + list( APPEND compile_tgts ${tgt} ) # Collect all files originating in LLVM IR separately get_filename_component( file_ext ${file} EXT ) if( ${file_ext} STREQUAL ".ll" ) list( APPEND bytecode_ir_files ${output_file} ) + list( APPEND compile_tgts ${tgt}-as ) else() list( APPEND bytecode_files ${output_file} ) endif() @@ -283,7 +295,7 @@ function(add_libclc_builtin_set) set( builtins_comp_lib_tgt builtins.comp.${ARG_ARCH_SUFFIX} ) add_custom_target( ${builtins_comp_lib_tgt} - DEPENDS ${bytecode_files} + DEPENDS ${compile_tgts} ) set_target_properties( ${builtins_comp_lib_tgt} PROPERTIES FOLDER "libclc/Device IR/Comp" ) >From 318148023265ea8e71d7c1d65e932748bacd417a Mon Sep 17 00:00:00 2001 From: Wenju He <wenju...@intel.com> Date: Tue, 11 Mar 2025 06:04:41 -0700 Subject: [PATCH 2/4] revert ARG_DEPENDENCIES change --- libclc/cmake/modules/AddLibclc.cmake | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index 9dc328fcd489c..fba3b0110aaec 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -62,11 +62,10 @@ function(compile_to_bc) DEPENDS ${clang_target} ${ARG_INPUT} + ${ARG_DEPENDENCIES} DEPFILE ${ARG_OUTPUT}.d ) - add_custom_target( ${ARG_TARGET} - DEPENDS ${ARG_OUTPUT}${TMP_SUFFIX} ${ARG_DEPENDENCIES} - ) + add_custom_target( ${ARG_TARGET} DEPENDS ${ARG_OUTPUT}${TMP_SUFFIX} ) if( ${FILE_EXT} STREQUAL ".ll" ) add_custom_command( >From ea2f503e3c8ea76de06dccf125f985a862535ae8 Mon Sep 17 00:00:00 2001 From: Wenju He <wenju...@intel.com> Date: Tue, 18 Mar 2025 03:14:41 -0700 Subject: [PATCH 3/4] add FIXME about DEPENDS_EXPLICIT_ONLY --- libclc/cmake/modules/AddLibclc.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index fba3b0110aaec..5d03acc73b3d0 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -65,6 +65,11 @@ function(compile_to_bc) ${ARG_DEPENDENCIES} DEPFILE ${ARG_OUTPUT}.d ) + # FIXME: The target is added to ensure the parallel build of source files. + # However, this may result in an large number of targets. + # Since CMake 3.27, DEPENDS_EXPLICIT_ONLY can be used with add_custom_command + # to enable parallel build. + # Refer to https://gitlab.kitware.com/cmake/cmake/-/issues/17097 for details. add_custom_target( ${ARG_TARGET} DEPENDS ${ARG_OUTPUT}${TMP_SUFFIX} ) if( ${FILE_EXT} STREQUAL ".ll" ) >From 603255c952ea9efd1adc386ab34178e6d8c66165 Mon Sep 17 00:00:00 2001 From: Wenju He <wenju...@intel.com> Date: Tue, 18 Mar 2025 03:20:56 -0700 Subject: [PATCH 4/4] update comment --- libclc/cmake/modules/AddLibclc.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index 5d03acc73b3d0..dace33a567fea 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -66,9 +66,9 @@ function(compile_to_bc) DEPFILE ${ARG_OUTPUT}.d ) # FIXME: The target is added to ensure the parallel build of source files. - # However, this may result in an large number of targets. - # Since CMake 3.27, DEPENDS_EXPLICIT_ONLY can be used with add_custom_command - # to enable parallel build. + # However, this may result in a large number of targets. + # Starting with CMake 3.27, DEPENDS_EXPLICIT_ONLY can be used with + # add_custom_command to enable parallel build. # Refer to https://gitlab.kitware.com/cmake/cmake/-/issues/17097 for details. add_custom_target( ${ARG_TARGET} DEPENDS ${ARG_OUTPUT}${TMP_SUFFIX} ) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits