https://github.com/wenju-he updated https://github.com/llvm/llvm-project/pull/130882
>From 1727cb49ebbee324ecad0a766ec341eb1aed082b Mon Sep 17 00:00:00 2001 From: Wenju He <wenju...@intel.com> Date: Tue, 11 Mar 2025 19:05:25 -0700 Subject: [PATCH 1/4] [libclc] Skip opt command if opt_flags is empty When the flag is empty, the opt command won't modify the bitcode; however, the command is slow for large bitcode files in debug mode. --- libclc/cmake/modules/AddLibclc.cmake | 42 +++++++++++++++++----------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index 911559ff4bfa9..de24848256d72 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -340,29 +340,37 @@ function(add_libclc_builtin_set) return() endif() - set( builtins_opt_lib_tgt builtins.opt.${ARG_ARCH_SUFFIX} ) + if( ${ARG_OPT_FLAGS} ) + set( builtins_opt_lib_tgt builtins.opt.${ARG_ARCH_SUFFIX} ) + + # Add opt target + add_custom_command( OUTPUT ${builtins_opt_lib_tgt}.bc + COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${builtins_opt_lib_tgt}.bc + ${builtins_link_lib} + DEPENDS ${opt_target} ${builtins_link_lib} ${builtins_link_lib_tgt} + ) + add_custom_target( ${builtins_opt_lib_tgt} + ALL DEPENDS ${builtins_opt_lib_tgt}.bc + ) + set_target_properties( ${builtins_opt_lib_tgt} PROPERTIES + TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${builtins_opt_lib_tgt}.bc + FOLDER "libclc/Device IR/Opt" + ) - # Add opt target - add_custom_command( OUTPUT ${builtins_opt_lib_tgt}.bc - COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${builtins_opt_lib_tgt}.bc - ${builtins_link_lib} - DEPENDS ${opt_target} ${builtins_link_lib} ${builtins_link_lib_tgt} - ) - add_custom_target( ${builtins_opt_lib_tgt} - ALL DEPENDS ${builtins_opt_lib_tgt}.bc - ) - set_target_properties( ${builtins_opt_lib_tgt} PROPERTIES - TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${builtins_opt_lib_tgt}.bc - FOLDER "libclc/Device IR/Opt" - ) + set( builtins_opt_lib $<TARGET_PROPERTY:${builtins_opt_lib_tgt},TARGET_FILE> ) - set( builtins_opt_lib $<TARGET_PROPERTY:${builtins_opt_lib_tgt},TARGET_FILE> ) + set( builtins_link_opt_lib ${builtins_opt_lib} ) + set( builtins_link_opt_lib_tgt ${builtins_opt_lib_tgt} ) + else() + set( builtins_link_opt_lib ${builtins_link_lib} ) + set( builtins_link_opt_lib_tgt ${builtins_link_lib_tgt} ) + endif() # Add prepare target set( obj_suffix ${ARG_ARCH_SUFFIX}.bc ) add_custom_command( OUTPUT ${obj_suffix} - COMMAND ${prepare_builtins_exe} -o ${obj_suffix} ${builtins_opt_lib} - DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target} ) + COMMAND ${prepare_builtins_exe} -o ${obj_suffix} ${builtins_link_opt_lib} + DEPENDS ${builtins_link_opt_lib} ${builtins_link_opt_lib_tgt} ${prepare_builtins_target} ) add_custom_target( prepare-${obj_suffix} ALL DEPENDS ${obj_suffix} ) set_target_properties( "prepare-${obj_suffix}" PROPERTIES FOLDER "libclc/Device IR/Prepare" ) >From d3543f3601469b2e2b51f3fa275019f06c8378e6 Mon Sep 17 00:00:00 2001 From: Wenju He <wenju...@intel.com> Date: Tue, 18 Mar 2025 04:04:34 -0700 Subject: [PATCH 2/4] unconditionally add builtins_opt_lib_tgt, which is empty if OPT_FLAGS is empty --- libclc/cmake/modules/AddLibclc.cmake | 30 +++++++++++++--------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index de24848256d72..14f28a0b525b0 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -340,37 +340,35 @@ function(add_libclc_builtin_set) return() endif() - if( ${ARG_OPT_FLAGS} ) - set( builtins_opt_lib_tgt builtins.opt.${ARG_ARCH_SUFFIX} ) + set( builtins_opt_lib_tgt builtins.opt.${ARG_ARCH_SUFFIX} ) + add_custom_target( ${builtins_opt_lib_tgt} ALL ) + set_target_properties( ${builtins_opt_lib_tgt} PROPERTIES + FOLDER "libclc/Device IR/Opt" + ) + add_dependencies( ${builtins_opt_lib_tgt} ${builtins_link_lib_tgt} ) - # Add opt target + # Add opt target + if( ${ARG_OPT_FLAGS} STREQUAL "" ) + # no-op + set( builtins_opt_lib ${builtins_link_lib} ) + else() add_custom_command( OUTPUT ${builtins_opt_lib_tgt}.bc COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${builtins_opt_lib_tgt}.bc ${builtins_link_lib} DEPENDS ${opt_target} ${builtins_link_lib} ${builtins_link_lib_tgt} ) - add_custom_target( ${builtins_opt_lib_tgt} - ALL DEPENDS ${builtins_opt_lib_tgt}.bc - ) set_target_properties( ${builtins_opt_lib_tgt} PROPERTIES TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${builtins_opt_lib_tgt}.bc - FOLDER "libclc/Device IR/Opt" + DEPENDS ${builtins_opt_lib_tgt}.bc ) - set( builtins_opt_lib $<TARGET_PROPERTY:${builtins_opt_lib_tgt},TARGET_FILE> ) - - set( builtins_link_opt_lib ${builtins_opt_lib} ) - set( builtins_link_opt_lib_tgt ${builtins_opt_lib_tgt} ) - else() - set( builtins_link_opt_lib ${builtins_link_lib} ) - set( builtins_link_opt_lib_tgt ${builtins_link_lib_tgt} ) endif() # Add prepare target set( obj_suffix ${ARG_ARCH_SUFFIX}.bc ) add_custom_command( OUTPUT ${obj_suffix} - COMMAND ${prepare_builtins_exe} -o ${obj_suffix} ${builtins_link_opt_lib} - DEPENDS ${builtins_link_opt_lib} ${builtins_link_opt_lib_tgt} ${prepare_builtins_target} ) + COMMAND ${prepare_builtins_exe} -o ${obj_suffix} ${builtins_opt_lib} + DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target} ) add_custom_target( prepare-${obj_suffix} ALL DEPENDS ${obj_suffix} ) set_target_properties( "prepare-${obj_suffix}" PROPERTIES FOLDER "libclc/Device IR/Prepare" ) >From e02feedae736bf3a59e774c1b64e9f876c258db7 Mon Sep 17 00:00:00 2001 From: Wenju He <wenju...@intel.com> Date: Tue, 18 Mar 2025 04:06:07 -0700 Subject: [PATCH 3/4] update comment --- libclc/cmake/modules/AddLibclc.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index 14f28a0b525b0..e3c157cdea704 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -340,6 +340,7 @@ function(add_libclc_builtin_set) return() endif() + # Add opt target. It is empty if ARG_OPT_FLAGS is empty. set( builtins_opt_lib_tgt builtins.opt.${ARG_ARCH_SUFFIX} ) add_custom_target( ${builtins_opt_lib_tgt} ALL ) set_target_properties( ${builtins_opt_lib_tgt} PROPERTIES @@ -347,7 +348,6 @@ function(add_libclc_builtin_set) ) add_dependencies( ${builtins_opt_lib_tgt} ${builtins_link_lib_tgt} ) - # Add opt target if( ${ARG_OPT_FLAGS} STREQUAL "" ) # no-op set( builtins_opt_lib ${builtins_link_lib} ) >From cb61d085ccc488f26b4cfa28991cc777ac63a6db Mon Sep 17 00:00:00 2001 From: Wenju He <wenju...@intel.com> Date: Tue, 18 Mar 2025 04:13:58 -0700 Subject: [PATCH 4/4] refine --- libclc/cmake/modules/AddLibclc.cmake | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index e3c157cdea704..6c11b75278ae2 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -340,27 +340,32 @@ function(add_libclc_builtin_set) return() endif() - # Add opt target. It is empty if ARG_OPT_FLAGS is empty. set( builtins_opt_lib_tgt builtins.opt.${ARG_ARCH_SUFFIX} ) - add_custom_target( ${builtins_opt_lib_tgt} ALL ) - set_target_properties( ${builtins_opt_lib_tgt} PROPERTIES - FOLDER "libclc/Device IR/Opt" - ) - add_dependencies( ${builtins_opt_lib_tgt} ${builtins_link_lib_tgt} ) if( ${ARG_OPT_FLAGS} STREQUAL "" ) - # no-op + # Add empty opt target. + add_custom_target( ${builtins_opt_lib_tgt} ALL ) + set_target_properties( ${builtins_opt_lib_tgt} PROPERTIES + FOLDER "libclc/Device IR/Opt" + ) + add_dependencies( ${builtins_opt_lib_tgt} ${builtins_link_lib_tgt} ) + set( builtins_opt_lib ${builtins_link_lib} ) else() + # Add opt target add_custom_command( OUTPUT ${builtins_opt_lib_tgt}.bc COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${builtins_opt_lib_tgt}.bc ${builtins_link_lib} DEPENDS ${opt_target} ${builtins_link_lib} ${builtins_link_lib_tgt} ) + add_custom_target( ${builtins_opt_lib_tgt} + ALL DEPENDS ${builtins_opt_lib_tgt}.bc + ) set_target_properties( ${builtins_opt_lib_tgt} PROPERTIES TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${builtins_opt_lib_tgt}.bc - DEPENDS ${builtins_opt_lib_tgt}.bc + FOLDER "libclc/Device IR/Opt" ) + set( builtins_opt_lib $<TARGET_PROPERTY:${builtins_opt_lib_tgt},TARGET_FILE> ) endif() _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits