Skip to content

Commit 1c6cecd

Browse files
authored
[libclc] Suppress data-layout warnings during linking (llvm#127532)
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.
1 parent 91ef371 commit 1c6cecd

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

libclc/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
#if __clang_major__ >= 7
2-
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"
3-
#else
4-
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"
5-
#endif
6-
71
define i64 @__clc__sync_fetch_and_min_global_8(i64 addrspace(1)* nocapture %ptr, i64 %value) nounwind alwaysinline {
82
entry:
93
%0 = atomicrmw volatile min i64 addrspace(1)* %ptr, i64 %value seq_cst

libclc/cmake/modules/AddLibclc.cmake

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ function(add_libclc_builtin_set)
225225
message( FATAL_ERROR "Must provide ARCH, ARCH_SUFFIX, and TRIPLE" )
226226
endif()
227227

228-
set( bytecode_files "" )
228+
set( bytecode_files )
229+
set( bytecode_ir_files )
229230
foreach( file IN LISTS ARG_GEN_FILES ARG_LIB_FILES )
230231
# We need to take each file and produce an absolute input file, as well
231232
# as a unique architecture-specific output file. We deal with a mix of
@@ -263,9 +264,23 @@ function(add_libclc_builtin_set)
263264
"${ARG_COMPILE_FLAGS}" -I${CMAKE_CURRENT_SOURCE_DIR}/${file_dir}
264265
DEPENDENCIES ${input_file_dep}
265266
)
266-
list( APPEND bytecode_files ${output_file} )
267+
268+
# Collect all files originating in LLVM IR separately
269+
get_filename_component( file_ext ${file} EXT )
270+
if( ${file_ext} STREQUAL ".ll" )
271+
list( APPEND bytecode_ir_files ${output_file} )
272+
else()
273+
list( APPEND bytecode_files ${output_file} )
274+
endif()
267275
endforeach()
268276

277+
# Prepend all LLVM IR files to the list so they are linked into the final
278+
# bytecode modules first. This helps to suppress unnecessary warnings
279+
# regarding different data layouts while linking. Any LLVM IR files without a
280+
# data layout will (silently) be given the first data layout the linking
281+
# process comes across.
282+
list( PREPEND bytecode_files ${bytecode_ir_files} )
283+
269284
set( builtins_comp_lib_tgt builtins.comp.${ARG_ARCH_SUFFIX} )
270285
add_custom_target( ${builtins_comp_lib_tgt}
271286
DEPENDS ${bytecode_files}

libclc/r600/lib/image/get_image_attributes_impl.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
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"
2-
31
%opencl.image2d_t = type opaque
42
%opencl.image3d_t = type opaque
53

libclc/r600/lib/image/read_image_impl.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
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"
2-
31
%opencl.image2d_t = type opaque
42

53
declare <4 x float> @llvm.R600.tex(<4 x float>, i32, i32, i32, i32, i32, i32,

libclc/r600/lib/image/write_image_impl.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
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"
2-
31
%opencl.image2d_t = type opaque
42
%opencl.image3d_t = type opaque
53

0 commit comments

Comments
 (0)