Skip to content

Commit a62f3ce

Browse files
authored
Cherry-pick #15914 (#15918)
1 parent 5074318 commit a62f3ce

File tree

3 files changed

+167
-94
lines changed

3 files changed

+167
-94
lines changed

libclc/CMakeLists.txt

Lines changed: 72 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ if( "spirv-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD OR "spirv64-mesa3d-" IN_LIST
169169
endif()
170170

171171
add_custom_target(libspirv-builtins COMMENT "Build libspirv builtins")
172-
add_custom_target(libclc-builtins COMMENT "Build libclc builtins")
172+
add_custom_target(libopencl-builtins COMMENT "Build libclc builtins")
173173

174174
if( LIBCLC_TARGETS_TO_BUILD STREQUAL "all" )
175175
set( LIBCLC_TARGETS_TO_BUILD ${LIBCLC_TARGETS_ALL} )
@@ -341,19 +341,40 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
341341
" configuration, some SYCL programs may fail to build.")
342342
endif()
343343

344-
set( lib_files )
345-
set( lib_gen_files )
346-
libclc_configure_lib_source(lib_files lib_gen_files
347-
LIB_DIR lib
344+
set( opencl_lib_files )
345+
set( opencl_gen_files )
346+
347+
if( NOT ARCH STREQUAL spirv AND NOT ARCH STREQUAL spirv64 )
348+
if( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
349+
list( APPEND opencl_gen_files clspv-convert.cl )
350+
elseif ( NOT ENABLE_RUNTIME_SUBNORMAL )
351+
list( APPEND opencl_gen_files convert-clc.cl )
352+
list( APPEND opencl_lib_files generic/libspirv/subnormal_use_default.ll )
353+
endif()
354+
endif()
355+
356+
libclc_configure_lib_source(
357+
opencl_lib_files
348358
DIRS ${dirs} ${DARCH} ${DARCH}-${OS} ${DARCH}-${VENDOR}-${OS}
349-
DEPS convert-clc.cl )
359+
)
350360

351-
set( libspirv_files )
361+
set( libspirv_lib_files )
352362
set( libspirv_gen_files )
353-
libclc_configure_lib_source(libspirv_files libspirv_gen_files
363+
364+
if( NOT ARCH STREQUAL spirv AND NOT ARCH STREQUAL spirv64 )
365+
if( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
366+
list( APPEND libspirv_gen_files clspv-convert.cl )
367+
elseif ( NOT ENABLE_RUNTIME_SUBNORMAL )
368+
list( APPEND libspirv_gen_files convert-spirv.cl convert-core.cl )
369+
list( APPEND libspirv_lib_files generic/libspirv/subnormal_use_default.ll )
370+
endif()
371+
endif()
372+
373+
libclc_configure_lib_source(
374+
libspirv_lib_files
354375
LIB_DIR libspirv
355376
DIRS ${dirs} ${DARCH} ${DARCH}-${OS} ${DARCH}-${VENDOR}-${OS}
356-
DEPS convert-spirv.cl convert-core.cl)
377+
)
357378

358379
foreach( d ${${t}_devices} )
359380
get_libclc_device_info(
@@ -365,29 +386,25 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
365386
)
366387

367388
# Some targets don't have a specific GPU to target
368-
set( flags )
389+
set( build_flags )
369390
if( d STREQUAL none OR ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
370391
# FIXME: Ideally we would not be tied to a specific PTX ISA version
371392
if( ARCH STREQUAL nvptx OR ARCH STREQUAL nvptx64 )
372393
# Disables NVVM reflection to defer to after linking
373-
list( APPEND flags -Xclang -target-feature -Xclang +ptx72
394+
list( APPEND build_flags -Xclang -target-feature -Xclang +ptx72
374395
-march=sm_86 -mllvm --nvvm-reflect-enable=false)
375396
elseif( ARCH STREQUAL amdgcn )
376397
# AMDGCN needs libclc to be compiled to high bc version since all atomic
377398
# clang builtins need to be accessible
378-
list( APPEND flags -mcpu=gfx940 -mllvm --amdgpu-oclc-reflect-enable=false )
399+
list( APPEND build_flags -mcpu=gfx940 -mllvm --amdgpu-oclc-reflect-enable=false )
379400
elseif( IS_NATIVE_CPU_ARCH )
380-
list( APPEND flags -Xclang -fsycl-is-native-cpu )
401+
list( APPEND build_flags -Xclang -fsycl-is-native-cpu )
381402
if( ARCH STREQUAL x86_64 )
382-
list( APPEND flags ${LIBCLC_NATIVECPU_FLAGS_X86_64})
403+
list( APPEND build_flags ${LIBCLC_NATIVECPU_FLAGS_X86_64})
383404
endif()
384405
endif()
385406
endif()
386407

387-
if( NOT "${cpu}" STREQUAL "" )
388-
list( APPEND flags -mcpu=${cpu} )
389-
endif()
390-
391408
message( STATUS " device: ${d} ( ${${d}_aliases} )" )
392409

393410
# Note: when declaring builtins, we must consider that even if a target
@@ -422,7 +439,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
422439

423440
# Enable SPIR-V builtin function declarations, so they don't
424441
# have to be explicity declared in the soruce.
425-
list( APPEND flags -Xclang -fdeclare-spirv-builtins)
442+
list( APPEND build_flags -Xclang -fdeclare-spirv-builtins)
426443
set( LIBCLC_ARCH_OBJFILE_DIR "${LIBCLC_OBJFILE_DIR}/${arch_suffix}" )
427444
file( MAKE_DIRECTORY ${LIBCLC_ARCH_OBJFILE_DIR} )
428445

@@ -440,7 +457,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
440457
if( supports_generic_addrspace )
441458
string( APPEND CL_3_0_EXTENSIONS ",+__opencl_c_generic_address_space" )
442459
if( has_distinct_generic_addrspace )
443-
list( APPEND flags -D__CLC_DISTINCT_GENERIC_ADDRSPACE__ )
460+
list( APPEND build_flags -D__CLC_DISTINCT_GENERIC_ADDRSPACE__ )
444461
endif()
445462
else()
446463
# Explictly disable opencl_c_generic_address_space (it may be enabled
@@ -450,42 +467,60 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
450467
string( APPEND CL_3_0_EXTENSIONS ",-__opencl_c_pipes" )
451468
string( APPEND CL_3_0_EXTENSIONS ",-__opencl_c_device_enqueue" )
452469
endif()
453-
list( APPEND flags -cl-std=CL3.0 "-Xclang" ${CL_3_0_EXTENSIONS} )
470+
list( APPEND build_flags -cl-std=CL3.0 "-Xclang" ${CL_3_0_EXTENSIONS} )
454471

455472
# Add platform specific flags
456473
if(WIN32)
457-
list(APPEND flags -D_WIN32)
474+
list(APPEND build_flags -D_WIN32)
458475
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
459-
list(APPEND flags -D__APPLE__)
476+
list(APPEND build_flags -D__APPLE__)
460477
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
461-
list(APPEND flags -D__unix__ -D__linux__)
478+
list(APPEND build_flags -D__unix__ -D__linux__)
462479
else()
463480
# Assume some UNIX system otherwise
464-
list(APPEND flags -D__unix__)
481+
list(APPEND build_flags -D__unix__)
465482
endif()
466483

467-
add_libclc_builtin_set(libspirv-${arch_suffix}
484+
string( TOUPPER "CLC_${ARCH}" CLC_TARGET_DEFINE )
485+
486+
list( APPEND build_flags
487+
-D__CLC_INTERNAL
488+
-D${CLC_TARGET_DEFINE}
489+
-I${CMAKE_CURRENT_SOURCE_DIR}/generic/include
490+
# FIXME: Fix libclc to not require disabling this noisy warning
491+
-Wno-bitwise-conditional-parentheses
492+
)
493+
494+
if( NOT "${cpu}" STREQUAL "" )
495+
list( APPEND build_flags -mcpu=${cpu} )
496+
endif()
497+
498+
add_libclc_builtin_set(
499+
ARCH ${ARCH}
500+
ARCH_SUFFIX libspirv-${arch_suffix}
468501
TRIPLE ${clang_triple}
469-
TARGET_ENV libspirv
470-
COMPILE_OPT ${flags}
502+
TARGET_ENV libspirv-
503+
COMPILE_FLAGS ${build_flags}
471504
OPT_FLAGS ${opt_flags}
472-
FILES ${libspirv_files}
505+
LIB_FILES ${libspirv_lib_files}
473506
GEN_FILES ${libspirv_gen_files}
474507
ALIASES ${${d}_aliases}
475508
GENERATE_TARGET "generate_convert_spirv.cl" "generate_convert_core.cl"
476-
PARENT_TARGET libspirv-builtins)
509+
PARENT_TARGET libspirv-builtins
510+
)
477511

478-
add_libclc_builtin_set(clc-${arch_suffix}
512+
add_libclc_builtin_set(
513+
ARCH ${ARCH}
514+
ARCH_SUFFIX ${arch_suffix}
479515
TRIPLE ${clang_triple}
480-
TARGET_ENV clc
481-
COMPILE_OPT ${flags}
516+
COMPILE_FLAGS ${build_flags}
482517
OPT_FLAGS ${opt_flags}
483-
FILES ${lib_files}
484-
GEN_FILES ${lib_gen_files}
485-
LIB_DEP libspirv-${arch_suffix}
518+
LIB_FILES ${opencl_lib_files}
519+
GEN_FILES ${opencl_gen_files}
486520
ALIASES ${${d}_aliases}
487521
GENERATE_TARGET "generate_convert_clc.cl"
488-
PARENT_TARGET libclc-builtins)
522+
PARENT_TARGET libopencl-builtins
523+
)
489524
endforeach( d )
490525
endforeach( t )
491526

0 commit comments

Comments
 (0)