@@ -181,7 +181,7 @@ if( "spirv-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD OR "spirv64-mesa3d-" IN_LIST
181181endif ()
182182
183183add_custom_target (libspirv-builtins COMMENT "Build libspirv builtins" )
184- add_custom_target (libclc -builtins COMMENT "Build libclc builtins" )
184+ add_custom_target (libopencl -builtins COMMENT "Build libclc builtins" )
185185
186186set (LIBCLC_TARGET_TO_TEST)
187187
@@ -329,19 +329,40 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
329329 " configuration, some SYCL programs may fail to build." )
330330 endif ()
331331
332- set ( lib_files )
333- set ( lib_gen_files )
334- libclc_configure_lib_source(lib_files lib_gen_files
335- LIB_DIR lib
332+ set ( opencl_lib_files )
333+ set ( opencl_gen_files )
334+
335+ if ( NOT ARCH STREQUAL spirv AND NOT ARCH STREQUAL spirv64 )
336+ if ( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
337+ list ( APPEND opencl_gen_files clspv-convert.cl )
338+ elseif ( NOT ENABLE_RUNTIME_SUBNORMAL )
339+ list ( APPEND opencl_gen_files convert-clc.cl )
340+ list ( APPEND opencl_lib_files generic/libspirv/subnormal_use_default.ll )
341+ endif ()
342+ endif ()
343+
344+ libclc_configure_lib_source(
345+ opencl_lib_files
336346 DIRS ${dirs} ${DARCH} ${DARCH} -${OS} ${DARCH} -${VENDOR} -${OS}
337- DEPS convert-clc.cl )
347+ )
338348
339- set ( libspirv_files )
349+ set ( libspirv_lib_files )
340350 set ( libspirv_gen_files )
341- libclc_configure_lib_source(libspirv_files libspirv_gen_files
351+
352+ if ( NOT ARCH STREQUAL spirv AND NOT ARCH STREQUAL spirv64 )
353+ if ( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
354+ list ( APPEND libspirv_gen_files clspv-convert.cl )
355+ elseif ( NOT ENABLE_RUNTIME_SUBNORMAL )
356+ list ( APPEND libspirv_gen_files convert-spirv.cl convert-core.cl )
357+ list ( APPEND libspirv_lib_files generic/libspirv/subnormal_use_default.ll )
358+ endif ()
359+ endif ()
360+
361+ libclc_configure_lib_source(
362+ libspirv_lib_files
342363 LIB_DIR libspirv
343364 DIRS ${dirs} ${DARCH} ${DARCH} -${OS} ${DARCH} -${VENDOR} -${OS}
344- DEPS convert-spirv.cl convert-core.cl )
365+ )
345366
346367 foreach ( d ${${t} _devices} )
347368 get_libclc_device_info(
@@ -353,29 +374,25 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
353374 )
354375
355376 # Some targets don't have a specific GPU to target
356- set ( flags )
377+ set ( build_flags )
357378 if ( d STREQUAL none OR ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
358379 # FIXME: Ideally we would not be tied to a specific PTX ISA version
359380 if ( ARCH STREQUAL nvptx OR ARCH STREQUAL nvptx64 )
360381 # Disables NVVM reflection to defer to after linking
361- list ( APPEND flags -Xclang -target -feature -Xclang +ptx72
382+ list ( APPEND build_flags -Xclang -target -feature -Xclang +ptx72
362383 -march=sm_86 -mllvm --nvvm-reflect-enable=false )
363384 elseif ( ARCH STREQUAL amdgcn )
364385 # AMDGCN needs libclc to be compiled to high bc version since all atomic
365386 # clang builtins need to be accessible
366- list ( APPEND flags -mcpu=gfx940 -mllvm --amdgpu-oclc-reflect-enable=false )
387+ list ( APPEND build_flags -mcpu=gfx940 -mllvm --amdgpu-oclc-reflect-enable=false )
367388 elseif ( IS_NATIVE_CPU_ARCH )
368- list ( APPEND flags -Xclang -fsycl-is-native-cpu )
389+ list ( APPEND build_flags -Xclang -fsycl-is-native-cpu )
369390 if ( ARCH STREQUAL x86_64 )
370- list ( APPEND flags ${LIBCLC_NATIVECPU_FLAGS_X86_64} )
391+ list ( APPEND build_flags ${LIBCLC_NATIVECPU_FLAGS_X86_64} )
371392 endif ()
372393 endif ()
373394 endif ()
374395
375- if ( NOT "${cpu} " STREQUAL "" )
376- list ( APPEND flags -mcpu=${cpu} )
377- endif ()
378-
379396 message ( STATUS " device: ${d} ( ${${d} _aliases} )" )
380397
381398 # Note: when declaring builtins, we must consider that even if a target
@@ -410,7 +427,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
410427
411428 # Enable SPIR-V builtin function declarations, so they don't
412429 # have to be explicity declared in the soruce.
413- list ( APPEND flags -Xclang -fdeclare-spirv-builtins)
430+ list ( APPEND build_flags -Xclang -fdeclare-spirv-builtins)
414431 set ( LIBCLC_ARCH_OBJFILE_DIR "${LIBCLC_OBJFILE_DIR} /${arch_suffix} " )
415432 file ( MAKE_DIRECTORY ${LIBCLC_ARCH_OBJFILE_DIR} )
416433
@@ -428,7 +445,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
428445 if ( supports_generic_addrspace )
429446 string ( APPEND CL_3_0_EXTENSIONS ",+__opencl_c_generic_address_space" )
430447 if ( has_distinct_generic_addrspace )
431- list ( APPEND flags -D__CLC_DISTINCT_GENERIC_ADDRSPACE__ )
448+ list ( APPEND build_flags -D__CLC_DISTINCT_GENERIC_ADDRSPACE__ )
432449 endif ()
433450 else ()
434451 # Explictly disable opencl_c_generic_address_space (it may be enabled
@@ -438,42 +455,60 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
438455 string ( APPEND CL_3_0_EXTENSIONS ",-__opencl_c_pipes" )
439456 string ( APPEND CL_3_0_EXTENSIONS ",-__opencl_c_device_enqueue" )
440457 endif ()
441- list ( APPEND flags -cl-std=CL3.0 "-Xclang" ${CL_3_0_EXTENSIONS} )
458+ list ( APPEND build_flags -cl-std=CL3.0 "-Xclang" ${CL_3_0_EXTENSIONS} )
442459
443460 # Add platform specific flags
444461 if (WIN32 )
445- list (APPEND flags -D_WIN32)
462+ list (APPEND build_flags -D_WIN32)
446463 elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
447- list (APPEND flags -D__APPLE__)
464+ list (APPEND build_flags -D__APPLE__)
448465 elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
449- list (APPEND flags -D__unix__ -D__linux__)
466+ list (APPEND build_flags -D__unix__ -D__linux__)
450467 else ()
451468 # Assume some UNIX system otherwise
452- list (APPEND flags -D__unix__)
469+ list (APPEND build_flags -D__unix__)
453470 endif ()
454471
455- add_libclc_builtin_set(libspirv-${arch_suffix}
472+ string ( TOUPPER "CLC_${ARCH} " CLC_TARGET_DEFINE )
473+
474+ list ( APPEND build_flags
475+ -D__CLC_INTERNAL
476+ -D${CLC_TARGET_DEFINE}
477+ -I${CMAKE_CURRENT_SOURCE_DIR} /generic/include
478+ # FIXME: Fix libclc to not require disabling this noisy warning
479+ -Wno-bitwise-conditional-parentheses
480+ )
481+
482+ if ( NOT "${cpu} " STREQUAL "" )
483+ list ( APPEND build_flags -mcpu=${cpu} )
484+ endif ()
485+
486+ add_libclc_builtin_set(
487+ ARCH ${ARCH}
488+ ARCH_SUFFIX libspirv-${arch_suffix}
456489 TRIPLE ${clang_triple}
457- TARGET_ENV libspirv
458- COMPILE_OPT ${flags }
490+ TARGET_ENV libspirv-
491+ COMPILE_FLAGS ${build_flags }
459492 OPT_FLAGS ${opt_flags}
460- FILES ${libspirv_files }
493+ LIB_FILES ${libspirv_lib_files }
461494 GEN_FILES ${libspirv_gen_files}
462495 ALIASES ${${d} _aliases}
463496 GENERATE_TARGET "generate_convert_spirv.cl" "generate_convert_core.cl"
464- PARENT_TARGET libspirv-builtins)
497+ PARENT_TARGET libspirv-builtins
498+ )
465499
466- add_libclc_builtin_set(clc-${arch_suffix}
500+ add_libclc_builtin_set(
501+ ARCH ${ARCH}
502+ ARCH_SUFFIX ${arch_suffix}
467503 TRIPLE ${clang_triple}
468- TARGET_ENV clc
469- COMPILE_OPT ${flags}
504+ COMPILE_FLAGS ${build_flags}
470505 OPT_FLAGS ${opt_flags}
471- FILES ${lib_files}
472- GEN_FILES ${lib_gen_files}
473- LIB_DEP libspirv-${arch_suffix}
506+ LIB_FILES ${opencl_lib_files}
507+ GEN_FILES ${opencl_gen_files}
474508 ALIASES ${${d} _aliases}
475509 GENERATE_TARGET "generate_convert_clc.cl"
476- PARENT_TARGET libclc-builtins)
510+ PARENT_TARGET libopencl-builtins
511+ )
477512 endforeach ( d )
478513endforeach ( t )
479514
0 commit comments