https://github.com/frasercrmck updated https://github.com/llvm/llvm-project/pull/127532
>From 2004d2a93073273cd7e09fbf6da6de7972412e98 Mon Sep 17 00:00:00 2001 From: Fraser Cormack <fra...@codeplay.com> Date: Mon, 17 Feb 2025 18:04:08 +0000 Subject: [PATCH] [libclc] Suppress data-layout warnings during linking libclc uses llvm-link to link together all of the individually built libclc builtins files into one module. Some of these builtins files are compiled from source by clang whilst others are converted from LLVM IR directly to bytecode. When llvm-link links a 'source' module into a 'destination' module, it warns if the two modules have differing data layouts. The LLVM IR files libclc links either have no data layout (shared submodule files) or an explicit data layout in the case of certain amdgcn/r600 files. The warnings are very noisy and largely inconsequential. We can suppress them exploiting a specific behaviours exhibited by llvm-link. When the destination module has no data layout, it is given the source module's data layout. Thus, if we link together all IR files first, followed by the clang-compiled modules, 99% of the warnings are suppressed as they arose from linking an empty data layout into a non-empty one. The remaining warnings came from the amdgcn and r600 targets. Some of these were because the data layouts were out of date compared with what clang currently produced, so those could have been updated. However, even with those changes and by grouping the IR files together, the linker may still link explicit data layouts with empty ones depending on the order the IR files are processed. As it happens, the data layouts aren't essential. With the changes to the link line we can rely on those IR files receiving the correct data layout from the clang-compiled modules later in the link line. This also makes the previously AMDGPU-specific IR files available to be used by all targets in a generic capacity in the future. --- .../minmax_helpers.ll | 6 ------ libclc/cmake/modules/AddLibclc.cmake | 19 +++++++++++++++++-- .../lib/image/get_image_attributes_impl.ll | 2 -- libclc/r600/lib/image/read_image_impl.ll | 2 -- libclc/r600/lib/image/write_image_impl.ll | 2 -- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/libclc/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll b/libclc/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll index 98f1f54718a1f..7f12556c0abbc 100644 --- a/libclc/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll +++ b/libclc/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll @@ -1,9 +1,3 @@ -#if __clang_major__ >= 7 -target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5" -#else -target datalayout = "e-p:32:32-p1:64:64-p2:64:64-p3:32:32-p4:64:64-p5:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64" -#endif - define i64 @__clc__sync_fetch_and_min_global_8(i64 addrspace(1)* nocapture %ptr, i64 %value) nounwind alwaysinline { entry: %0 = atomicrmw volatile min i64 addrspace(1)* %ptr, i64 %value seq_cst diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index 5347b0822477b..b90d15d3185d0 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -225,7 +225,8 @@ function(add_libclc_builtin_set) message( FATAL_ERROR "Must provide ARCH, ARCH_SUFFIX, and TRIPLE" ) endif() - set( bytecode_files "" ) + set( bytecode_files ) + set( bytecode_ir_files ) 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 @@ -263,9 +264,23 @@ function(add_libclc_builtin_set) "${ARG_COMPILE_FLAGS}" -I${CMAKE_CURRENT_SOURCE_DIR}/${file_dir} DEPENDENCIES ${input_file_dep} ) - list( APPEND bytecode_files ${output_file} ) + + # 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} ) + else() + list( APPEND bytecode_files ${output_file} ) + endif() endforeach() + # Prepend all LLVM IR files to the list so they are linked into the final + # bytecode modules first. This helps to suppress unnecessary warnings + # regarding different data layouts while linking. Any LLVM IR files without a + # data layout will (silently) be given the first data layout the linking + # process comes across. + list( PREPEND bytecode_files ${bytecode_ir_files} ) + set( builtins_comp_lib_tgt builtins.comp.${ARG_ARCH_SUFFIX} ) add_custom_target( ${builtins_comp_lib_tgt} DEPENDS ${bytecode_files} diff --git a/libclc/r600/lib/image/get_image_attributes_impl.ll b/libclc/r600/lib/image/get_image_attributes_impl.ll index f867ab6603591..7f1965de7602c 100644 --- a/libclc/r600/lib/image/get_image_attributes_impl.ll +++ b/libclc/r600/lib/image/get_image_attributes_impl.ll @@ -1,5 +1,3 @@ -target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64" - %opencl.image2d_t = type opaque %opencl.image3d_t = type opaque diff --git a/libclc/r600/lib/image/read_image_impl.ll b/libclc/r600/lib/image/read_image_impl.ll index ca2e465b4b5b8..229a2526c3743 100644 --- a/libclc/r600/lib/image/read_image_impl.ll +++ b/libclc/r600/lib/image/read_image_impl.ll @@ -1,5 +1,3 @@ -target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64" - %opencl.image2d_t = type opaque declare <4 x float> @llvm.R600.tex(<4 x float>, i32, i32, i32, i32, i32, i32, diff --git a/libclc/r600/lib/image/write_image_impl.ll b/libclc/r600/lib/image/write_image_impl.ll index 03595ba1db737..265f5d6045e42 100644 --- a/libclc/r600/lib/image/write_image_impl.ll +++ b/libclc/r600/lib/image/write_image_impl.ll @@ -1,5 +1,3 @@ -target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64" - %opencl.image2d_t = type opaque %opencl.image3d_t = type opaque _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits