llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-backend-amdgpu Author: Wenju He (wenju-he) <details> <summary>Changes</summary> When LLVM_TARGETS_TO_BUILD contains host target, runtime build sets CMAKE_C_COMPILER to clang-cl on Windows. We should switch to clang and llvm-ar/llvm-ranlib for libclc because: - libclc struggles to pass specific flags to clang-cl MSVC-like interface. - compile flag handling will be consistent across all host systems. - libclc build is cross-compilation for offloading targets. --- Full diff: https://github.com/llvm/llvm-project/pull/186726.diff 6 Files Affected: - (modified) libclc/CMakeLists.txt (+22-16) - (modified) libclc/clc/lib/amdgpu/CMakeLists.txt (+1-1) - (modified) libclc/clc/lib/generic/CMakeLists.txt (+2-2) - (modified) libclc/cmake/modules/CMakeCLCInformation.cmake (+28-5) - (modified) libclc/opencl/lib/generic/CMakeLists.txt (+1-1) - (modified) llvm/runtimes/CMakeLists.txt (+1-1) ``````````diff diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 1103711298ce3..137a07f26f7eb 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -122,6 +122,13 @@ foreach( tool IN ITEMS opt llvm-link ) endif() endforeach() +# Determine prefix based on compiler type +if (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") + set(flag_prefix "/clang:") +else() + set(flag_prefix "") +endif() + add_subdirectory(clc/lib/generic) add_subdirectory(clc/lib/amdgpu) add_subdirectory(clc/lib/ptx-nvidiacl) @@ -186,11 +193,11 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) set(opt_flags -O3) if(ARCH STREQUAL spirv OR ARCH STREQUAL spirv64) - list(APPEND target_compile_flags -O0 -finline-hint-functions) + list(APPEND target_compile_flags "${flag_prefix}-O0" "${flag_prefix}-finline-hint-functions") list(APPEND target_extra_defines CLC_SPIRV) set(opt_flags) elseif(ARCH STREQUAL clspv OR ARCH STREQUAL clspv64) - list(APPEND target_compile_flags -Wno-unknown-assumption) + list(APPEND target_compile_flags "${flag_prefix}-Wno-unknown-assumption") list(APPEND target_extra_defines CLC_CLSPV) elseif(ARCH STREQUAL amdgcn) list(APPEND target_compile_flags "SHELL:-Xclang -mcode-object-version=none") @@ -224,21 +231,20 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) ${OPENCL_GENERIC_SOURCES} ${_opencl_overrides}) endif() - # Common compile options shared by CLC and OpenCL libraries. set(compile_flags - -flto - --target=${clang_triple} - -nostdlib - -nostdlibinc - -cl-no-stdinc - -cl-std=CL3.0 - -include opencl-c-base.h - -Werror=undef - -Wall - -Wextra - -fdiscard-value-names - -ffp-contract=fast-honor-pragmas - -fdenormal-fp-math=dynamic + "${flag_prefix}-flto" + "${flag_prefix}--target=${clang_triple}" + "${flag_prefix}-nostdlib" + "${flag_prefix}-nostdlibinc" + "${flag_prefix}-cl-no-stdinc" + "${flag_prefix}-cl-std=CL3.0" + "${flag_prefix}-include" "${flag_prefix}opencl-c-base.h" + "${flag_prefix}-Werror=undef" + "${flag_prefix}-Wall" + "${flag_prefix}-Wextra" + "${flag_prefix}-fdiscard-value-names" + "${flag_prefix}-ffp-contract=fast-honor-pragmas" + "${flag_prefix}-fdenormal-fp-math=dynamic" ${target_compile_flags} ) diff --git a/libclc/clc/lib/amdgpu/CMakeLists.txt b/libclc/clc/lib/amdgpu/CMakeLists.txt index 9b6c9a231ade0..a5e2349df9fc9 100644 --- a/libclc/clc/lib/amdgpu/CMakeLists.txt +++ b/libclc/clc/lib/amdgpu/CMakeLists.txt @@ -37,7 +37,7 @@ libclc_configure_source_list(CLC_AMDGPU_SOURCES workitem/clc_get_sub_group_size.cl workitem/clc_get_work_dim.cl) -libclc_configure_source_options(${CMAKE_CURRENT_SOURCE_DIR} -fapprox-func +libclc_configure_source_options(${CMAKE_CURRENT_SOURCE_DIR} "${flag_prefix}-fapprox-func" math/clc_native_exp.cl math/clc_native_exp2.cl math/clc_native_log10.cl diff --git a/libclc/clc/lib/generic/CMakeLists.txt b/libclc/clc/lib/generic/CMakeLists.txt index 07200536328f3..9afa014b6b41f 100644 --- a/libclc/clc/lib/generic/CMakeLists.txt +++ b/libclc/clc/lib/generic/CMakeLists.txt @@ -199,7 +199,7 @@ libclc_configure_source_list(CLC_GENERIC_SOURCES workitem/clc_get_sub_group_size.cl ) -libclc_configure_source_options(${CMAKE_CURRENT_SOURCE_DIR} -fapprox-func +libclc_configure_source_options(${CMAKE_CURRENT_SOURCE_DIR} "${flag_prefix}-fapprox-func" math/clc_native_cos.cl math/clc_native_divide.cl math/clc_native_exp.cl @@ -218,6 +218,6 @@ libclc_configure_source_options(${CMAKE_CURRENT_SOURCE_DIR} -fapprox-func math/clc_recip_fast.cl math/clc_sqrt_fast.cl) -libclc_configure_source_options(${CMAKE_CURRENT_SOURCE_DIR} -cl-fp32-correctly-rounded-divide-sqrt +libclc_configure_source_options(${CMAKE_CURRENT_SOURCE_DIR} "${flag_prefix}-cl-fp32-correctly-rounded-divide-sqrt" math/clc_div_cr.cl math/clc_sqrt_cr.cl) diff --git a/libclc/cmake/modules/CMakeCLCInformation.cmake b/libclc/cmake/modules/CMakeCLCInformation.cmake index f92592221f034..7dd62b29e086d 100644 --- a/libclc/cmake/modules/CMakeCLCInformation.cmake +++ b/libclc/cmake/modules/CMakeCLCInformation.cmake @@ -1,8 +1,13 @@ set(CMAKE_CLC_OUTPUT_EXTENSION .o) set(CMAKE_INCLUDE_FLAG_CLC "-I") -set(CMAKE_CLC_DEPFILE_FORMAT gcc) -set(CMAKE_DEPFILE_FLAGS_CLC "-MD -MT <DEP_TARGET> -MF <DEP_FILE>") +if (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") + set(CMAKE_CLC_DEPFILE_FORMAT msvc) + set(CMAKE_DEPFILE_FLAGS_CLC "/showIncludes") +else() + set(CMAKE_CLC_DEPFILE_FORMAT gcc) + set(CMAKE_DEPFILE_FLAGS_CLC "-MD -MT <DEP_TARGET> -MF <DEP_FILE>") +endif() cmake_initialize_per_config_variable(CMAKE_CLC_FLAGS "Flags used by the CLC compiler") @@ -11,14 +16,32 @@ if(NOT CMAKE_CLC_COMPILE_OBJECT) "<CMAKE_CLC_COMPILER> -x cl <DEFINES> <INCLUDES> <FLAGS> -c -o <OBJECT> <SOURCE>") endif() +# Finds a required LLVM tool by searching the CLC compiler directory first. +function(find_llvm_tool name out_var) + cmake_path(GET CMAKE_CLC_COMPILER PARENT_PATH llvm_bin_dir) + find_program(${out_var} + NAMES ${name} + HINTS "${llvm_bin_dir}" + DOC "libclc: path to the ${name} tool" + ) + if(NOT ${out_var}) + message(FATAL_ERROR "${name} not found for libclc build.") + endif() +endfunction() + +find_llvm_tool(llvm-ar CLC_AR) +find_llvm_tool(llvm-ranlib CLC_RANLIB) + if(NOT DEFINED CMAKE_CLC_ARCHIVE_CREATE) - set(CMAKE_CLC_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>") + set(CMAKE_CLC_ARCHIVE_CREATE "${CLC_AR} qc <TARGET> <OBJECTS>") endif() + if(NOT DEFINED CMAKE_CLC_ARCHIVE_APPEND) - set(CMAKE_CLC_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") + set(CMAKE_CLC_ARCHIVE_APPEND "${CLC_AR} q <TARGET> <OBJECTS>") endif() + if(NOT DEFINED CMAKE_CLC_ARCHIVE_FINISH) - set(CMAKE_CLC_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>") + set(CMAKE_CLC_ARCHIVE_FINISH "${CLC_RANLIB} <TARGET>") endif() set(CMAKE_CLC_USE_LINKER_INFORMATION FALSE) diff --git a/libclc/opencl/lib/generic/CMakeLists.txt b/libclc/opencl/lib/generic/CMakeLists.txt index ca95e6d5cfe23..1fcaa8c10c316 100644 --- a/libclc/opencl/lib/generic/CMakeLists.txt +++ b/libclc/opencl/lib/generic/CMakeLists.txt @@ -224,7 +224,7 @@ libclc_configure_source_list(OPENCL_GENERIC_SOURCES workitem/get_work_dim.cl ) -libclc_configure_source_options(${CMAKE_CURRENT_SOURCE_DIR} -fapprox-func +libclc_configure_source_options(${CMAKE_CURRENT_SOURCE_DIR} "${flag_prefix}-fapprox-func" math/native_cos.cl math/native_divide.cl math/native_exp.cl diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt index fba0c7a01f972..a2ca2aba1f1eb 100644 --- a/llvm/runtimes/CMakeLists.txt +++ b/llvm/runtimes/CMakeLists.txt @@ -554,7 +554,7 @@ if(build_runtimes) # TODO: We need to consider passing it as '-DRUNTIMES_x86_64_LLVM_ENABLE_RUNTIMES'. if("libclc" IN_LIST LLVM_ENABLE_RUNTIMES) - foreach(dep clang llvm-as llvm-link opt) + foreach(dep clang llvm-as llvm-link opt llvm-ar llvm-ranlib) if(TARGET ${dep}) list(APPEND extra_deps ${dep}) endif() `````````` </details> https://github.com/llvm/llvm-project/pull/186726 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
