[libclc] 0c21d6b - [libclc] Fix commands in compile_to_bc are executed sequentially (#130755)

via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 14 06:11:07 PDT 2025


Author: Wenju He
Date: 2025-04-14T14:11:04+01:00
New Revision: 0c21d6b4c8ad7310b0cd81bbefa06b2947b671f9

URL: https://github.com/llvm/llvm-project/commit/0c21d6b4c8ad7310b0cd81bbefa06b2947b671f9
DIFF: https://github.com/llvm/llvm-project/commit/0c21d6b4c8ad7310b0cd81bbefa06b2947b671f9.diff

LOG: [libclc] Fix commands in compile_to_bc are executed sequentially (#130755)

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, enabling parallel builds of
OpenCL source files.
CMake 3.27 has fixed above issue with DEPENDS_EXPLICIT_ONLY. When LLVM
upgrades cmake vertion to 3.7, we can switch to DEPENDS_EXPLICIT_ONLY.

Added: 
    

Modified: 
    libclc/cmake/modules/AddLibclc.cmake

Removed: 
    


################################################################################
diff  --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake
index e88f9e4643356..bd0cfeba97858 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}
   )
@@ -63,6 +65,12 @@ 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 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} )
 
   if( ${FILE_EXT} STREQUAL ".ll" )
     add_custom_command(
@@ -232,6 +240,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
@@ -261,6 +270,9 @@ function(add_libclc_builtin_set)
 
     get_filename_component( file_dir ${file} DIRECTORY )
 
+    string( REPLACE "/" "-" replaced ${file} )
+    set( tgt compile_tgt-${ARG_ARCH_SUFFIX}${replaced})
+
     set( file_specific_compile_options )
     get_source_file_property( compile_opts ${file} COMPILE_OPTIONS)
     if( compile_opts )
@@ -268,6 +280,7 @@ function(add_libclc_builtin_set)
     endif()
 
     compile_to_bc(
+      TARGET ${tgt}
       TRIPLE ${ARG_TRIPLE}
       INPUT ${input_file}
       OUTPUT ${output_file}
@@ -275,6 +288,7 @@ 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 )
@@ -294,7 +308,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 ${bytecode_files} ${compile_tgts}
   )
   set_target_properties( ${builtins_comp_lib_tgt} PROPERTIES FOLDER "libclc/Device IR/Comp" )
 


        


More information about the cfe-commits mailing list