Skip to content

Commit d9588e3

Browse files
committed
[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 come 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 were updated. However, even by grouping the IR files together, it may still link explicit ones with empty ones depending on the order the IR files are processed.
1 parent 15c2d1b commit d9588e3

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

libclc/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
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
1+
target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-p9:192:256:256: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-G1-ni:7:8:9"
62

73
define i64 @__clc__sync_fetch_and_min_global_8(i64 addrspace(1)* nocapture %ptr, i64 %value) nounwind alwaysinline {
84
entry:

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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"
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-S32-A5-G1"
22

33
%opencl.image2d_t = type opaque
44
%opencl.image3d_t = type opaque

libclc/r600/lib/image/read_image_impl.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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"
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-S32-A5-G1"
22

33
%opencl.image2d_t = type opaque
44

libclc/r600/lib/image/write_image_impl.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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"
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-S32-A5-G1"
22

33
%opencl.image2d_t = type opaque
44
%opencl.image3d_t = type opaque

0 commit comments

Comments
 (0)