Skip to content

Commit 73d0679

Browse files
authored
[libclc] Clean up directory search procedure (llvm#127783)
During a recent change, the build system accidentally dropped the (theoretical) support for the CLC builtins library to build target-specific builtins from the 'amdgpu' directory, due to a change in variable names. This functionality wasn't being used but was spotted during another code review. This commit takes the opportunity to clean up and better document the code that manages the list of directories to search for builtin implementations. While fixing this, some references to now-removed SOURCES files were discovered which have been cleaned up.
1 parent 0f472e9 commit 73d0679

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

libclc/CMakeLists.txt

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,12 @@ include( GNUInstallDirs )
2020
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
2121
amdgcn-amdhsa/lib/SOURCES;
2222
amdgcn/lib/SOURCES;
23-
amdgcn-mesa3d/lib/SOURCES;
2423
amdgpu/lib/SOURCES;
2524
clspv/lib/SOURCES;
26-
clspv64/lib/SOURCES;
2725
generic/lib/SOURCES;
28-
ptx/lib/SOURCES;
2926
ptx-nvidiacl/lib/SOURCES;
3027
r600/lib/SOURCES;
3128
spirv/lib/SOURCES;
32-
spirv64/lib/SOURCES;
3329
# CLC internal libraries
3430
clc/lib/generic/SOURCES;
3531
)
@@ -280,11 +276,6 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
280276

281277
set( opencl_dirs )
282278

283-
if ( NOT ${ARCH} STREQUAL spirv AND NOT ${ARCH} STREQUAL spirv64 AND
284-
NOT ${ARCH} STREQUAL clspv AND NOT ${ARCH} STREQUAL clspv64)
285-
LIST( APPEND opencl_dirs generic )
286-
endif()
287-
288279
if( ${ARCH} STREQUAL r600 OR ${ARCH} STREQUAL amdgcn )
289280
list( APPEND opencl_dirs amdgpu )
290281
endif()
@@ -302,8 +293,25 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
302293
set( DARCH ${ARCH} )
303294
endif()
304295

296+
# Append a variety of target- and triple-based directories to search,
297+
# increasing in specificity.
298+
list( APPEND opencl_dirs ${DARCH} ${DARCH}-${OS} ${DARCH}-${VENDOR}-${OS} )
299+
300+
# The 'generic' directory contains all of the generic implementations of the
301+
# builtins. It is included first so it has the lowest search priority,
302+
# allowing targets to override builtins based on file names found later in
303+
# the list of search directories.
304+
# CLC builds all builtins for all targets, so unconditionally prepend the
305+
# 'generic' directory.
306+
set( clc_dirs generic ${opencl_dirs} )
307+
# Some OpenCL targets don't build all builtins, in which case they don't want
308+
# the 'generic' directory. Otherwise, prepend the 'generic' directory.
309+
if ( NOT ARCH STREQUAL spirv AND NOT ARCH STREQUAL spirv64 AND
310+
NOT ARCH STREQUAL clspv AND NOT ARCH STREQUAL clspv64)
311+
list( PREPEND opencl_dirs generic )
312+
endif()
313+
305314
set( clc_lib_files )
306-
set( clc_dirs ${dirs} generic )
307315

308316
if( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
309317
set( clc_gen_files clc-clspv-convert.cl )
@@ -315,7 +323,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
315323
clc_lib_files
316324
CLC_INTERNAL
317325
LIB_ROOT_DIR clc
318-
DIRS ${clc_dirs} ${DARCH} ${DARCH}-${OS} ${DARCH}-${VENDOR}-${OS}
326+
DIRS ${clc_dirs}
319327
)
320328

321329
set( opencl_lib_files )
@@ -334,7 +342,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
334342

335343
libclc_configure_lib_source(
336344
opencl_lib_files
337-
DIRS ${opencl_dirs} ${DARCH} ${DARCH}-${OS} ${DARCH}-${VENDOR}-${OS}
345+
DIRS ${opencl_dirs}
338346
)
339347

340348
foreach( d ${${t}_devices} )

libclc/cmake/modules/AddLibclc.cmake

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ endfunction(add_libclc_builtin_set)
402402
# directory. If not provided, is set to '.'.
403403
# * DIRS <string> ...
404404
# List of directories under LIB_ROOT_DIR to walk over searching for SOURCES
405-
# files
405+
# files. Directories earlier in the list have lower priority than
406+
# subsequent ones.
406407
function(libclc_configure_lib_source LIB_FILE_LIST)
407408
cmake_parse_arguments(ARG
408409
"CLC_INTERNAL"
@@ -417,18 +418,18 @@ function(libclc_configure_lib_source LIB_FILE_LIST)
417418

418419
# Enumerate SOURCES* files
419420
set( source_list )
420-
foreach( l ${ARG_DIRS} )
421+
foreach( l IN LISTS ARG_DIRS )
421422
foreach( s "SOURCES" "SOURCES_${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}" )
422423
if( ARG_CLC_INTERNAL )
423424
file( TO_CMAKE_PATH ${ARG_LIB_ROOT_DIR}/lib/${l}/${s} file_loc )
424425
else()
425426
file( TO_CMAKE_PATH ${ARG_LIB_ROOT_DIR}/${l}/lib/${s} file_loc )
426427
endif()
427428
file( TO_CMAKE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${file_loc} loc )
428-
# Prepend the location to give higher priority to
429-
# specialized implementation
429+
# Prepend the location to give higher priority to the specialized
430+
# implementation
430431
if( EXISTS ${loc} )
431-
set( source_list ${file_loc} ${source_list} )
432+
list( PREPEND source_list ${file_loc} )
432433
endif()
433434
endforeach()
434435
endforeach()

0 commit comments

Comments
 (0)