Author: Joseph Huber Date: 2026-05-08T08:41:58-05:00 New Revision: 6ef96710068e2fe1d1c4ebaa957ec215ff42c2c2
URL: https://github.com/llvm/llvm-project/commit/6ef96710068e2fe1d1c4ebaa957ec215ff42c2c2 DIFF: https://github.com/llvm/llvm-project/commit/6ef96710068e2fe1d1c4ebaa957ec215ff42c2c2.diff LOG: [libclc] Canonicalize 'clspv' to the 'spirv-unknown-vulkan' triple (#196351) Summary: The libclc project has clspv support for exporting OpenCL standard library utilities to Vulkan consumers. This was previously exposed as a hack into the build system that renamed the triple and relied on macro defines. Recent changes allowed us to use `vulkan` as an OS for the spir-V target. This should make the intention more clear and allow the system to inherit the same triple handling the other targets use. Tested the build, but I will need @rjodinchr and @alan-baker to verify. Added: libclc/clc/lib/vulkan/CMakeLists.txt libclc/clc/lib/vulkan/integer/clc_mul_hi.cl libclc/clc/lib/vulkan/math/clc_sw_fma.cl libclc/opencl/lib/vulkan/CMakeLists.txt libclc/opencl/lib/vulkan/conversion/convert_float.inc libclc/opencl/lib/vulkan/conversion/convert_float2float.cl libclc/opencl/lib/vulkan/conversion/convert_float2int.cl libclc/opencl/lib/vulkan/conversion/convert_int2float.cl libclc/opencl/lib/vulkan/conversion/convert_integer.cl libclc/opencl/lib/vulkan/conversion/convert_integer.inc libclc/opencl/lib/vulkan/math/fma.cl libclc/opencl/lib/vulkan/shared/vstore_half.cl libclc/opencl/lib/vulkan/shared/vstore_half.inc Modified: libclc/CMakeLists.txt libclc/README.md libclc/clc/include/clc/clcfunc.h libclc/clc/lib/generic/atomic/clc_atomic_compare_exchange.inc libclc/clc/lib/generic/atomic/clc_atomic_def.inc libclc/cmake/modules/AddLibclc.cmake libclc/test/CMakeLists.txt Removed: libclc/clc/lib/clspv/CMakeLists.txt libclc/clc/lib/clspv/integer/clc_mul_hi.cl libclc/clc/lib/clspv/math/clc_sw_fma.cl libclc/opencl/lib/clspv/CMakeLists.txt libclc/opencl/lib/clspv/conversion/convert_float.inc libclc/opencl/lib/clspv/conversion/convert_float2float.cl libclc/opencl/lib/clspv/conversion/convert_float2int.cl libclc/opencl/lib/clspv/conversion/convert_int2float.cl libclc/opencl/lib/clspv/conversion/convert_integer.cl libclc/opencl/lib/clspv/conversion/convert_integer.inc libclc/opencl/lib/clspv/math/fma.cl libclc/opencl/lib/clspv/shared/vstore_half.cl libclc/opencl/lib/clspv/shared/vstore_half.inc ################################################################################ diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index cb05fb7b662d8..cf1834a7ece63 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -23,7 +23,7 @@ option( ) # List of all supported architectures. -set( LIBCLC_ARCHS_ALL amdgpu amdgcn clspv clspv64 nvptx64 spirv spirv64 ) +set( LIBCLC_ARCHS_ALL amdgpu amdgcn nvptx64 spirv spirv32 spirv64 ) set(LIBCLC_TARGET ${LLVM_DEFAULT_TARGET_TRIPLE}) @@ -100,8 +100,8 @@ string( REPLACE "-" ";" TRIPLE ${LIBCLC_TARGET} ) list(GET TRIPLE 0 ARCH) list(GET TRIPLE 2 OS) -if(ARCH STREQUAL spirv OR ARCH STREQUAL spirv64) - if(NOT LIBCLC_USE_SPIRV_BACKEND AND NOT llvm-spirv_exe) +if(ARCH STREQUAL spirv OR ARCH STREQUAL spirv32 OR ARCH STREQUAL spirv64) + if(NOT OS STREQUAL vulkan AND NOT LIBCLC_USE_SPIRV_BACKEND AND NOT llvm-spirv_exe) message(FATAL_ERROR "SPIR-V backend or llvm-spirv is required for libclc ${LIBCLC_TARGET}") endif() endif() @@ -120,12 +120,14 @@ if(ARCH STREQUAL amdgcn) add_subdirectory(opencl/lib/amdgpu) elseif(ARCH STREQUAL nvptx64) add_subdirectory(clc/lib/ptx-nvidiacl) -elseif(ARCH STREQUAL spirv OR ARCH STREQUAL spirv64) - add_subdirectory(clc/lib/spirv) - add_subdirectory(opencl/lib/spirv) -elseif(ARCH STREQUAL clspv OR ARCH STREQUAL clspv64) - add_subdirectory(clc/lib/clspv) - add_subdirectory(opencl/lib/clspv) +elseif(ARCH STREQUAL spirv OR ARCH STREQUAL spirv32 OR ARCH STREQUAL spirv64) + if(OS STREQUAL vulkan) + add_subdirectory(clc/lib/vulkan) + add_subdirectory(opencl/lib/vulkan) + else() + add_subdirectory(clc/lib/spirv) + add_subdirectory(opencl/lib/spirv) + endif() endif() add_custom_target( libclc ALL ) @@ -133,30 +135,18 @@ add_custom_target( libclc ALL ) add_custom_target( libclc-opencl-builtins COMMENT "Build libclc OpenCL builtins" ) add_dependencies( libclc libclc-opencl-builtins ) -# Determine the clang target triple. +# Determine the clang target triple. Vulkan and SPIR-V backend targets use the +# triple directly; other SPIR-V targets fall back to the legacy SPIR target. set(clang_triple ${LIBCLC_TARGET}) -if(ARCH STREQUAL spirv AND LIBCLC_USE_SPIRV_BACKEND) - set(clang_triple spirv32--) -elseif(ARCH STREQUAL spirv64 AND LIBCLC_USE_SPIRV_BACKEND) - set(clang_triple spirv64--) -elseif(ARCH STREQUAL spirv OR ARCH STREQUAL clspv) - set(clang_triple spir--) -elseif(ARCH STREQUAL spirv64 OR ARCH STREQUAL clspv64) - set(clang_triple spir64--) -endif() - -# Determine the preprocessor identifier for this target. -set(MACRO_ARCH ${ARCH}) -if(ARCH STREQUAL spirv) - set(MACRO_ARCH SPIRV32) -elseif(ARCH STREQUAL spirv64) - set(MACRO_ARCH SPIRV64) -elseif(ARCH STREQUAL clspv) - set(MACRO_ARCH CLSPV32) -elseif(ARCH STREQUAL clspv64) - set(MACRO_ARCH CLSPV64) +if(ARCH STREQUAL spirv OR ARCH STREQUAL spirv32 OR ARCH STREQUAL spirv64) + if(NOT OS STREQUAL vulkan AND NOT LIBCLC_USE_SPIRV_BACKEND) + if(ARCH STREQUAL spirv) + set(clang_triple spir--) + else() + set(clang_triple spir64--) + endif() + endif() endif() -string(TOUPPER "CLC_${MACRO_ARCH}" target_define) # Address space values. set(private_addrspace_val 0) @@ -164,7 +154,7 @@ set(generic_addrspace_val 0) if(ARCH STREQUAL amdgcn) set(private_addrspace_val 5) endif() -if(ARCH STREQUAL spirv OR ARCH STREQUAL spirv64) +if((ARCH STREQUAL spirv OR ARCH STREQUAL spirv32 OR ARCH STREQUAL spirv64) AND NOT OS STREQUAL vulkan) set(generic_addrspace_val 4) endif() @@ -173,13 +163,14 @@ set(target_compile_flags) set(target_extra_defines) set(opt_flags -O3) -if(ARCH STREQUAL spirv OR ARCH STREQUAL spirv64) - list(APPEND target_compile_flags -O0 -finline-hint-functions) - list(APPEND target_extra_defines CLC_SPIRV) - set(opt_flags) -elseif(ARCH STREQUAL clspv OR ARCH STREQUAL clspv64) - list(APPEND target_compile_flags -Wno-unknown-assumption -U__opencl_c_int64) - list(APPEND target_extra_defines CLC_CLSPV) +if(ARCH STREQUAL spirv OR ARCH STREQUAL spirv32 OR ARCH STREQUAL spirv64) + if(OS STREQUAL vulkan) + list(APPEND target_compile_flags -Wno-unknown-assumption -U__opencl_c_int64) + else() + list(APPEND target_compile_flags -O0 -finline-hint-functions) + list(APPEND target_extra_defines CLC_SPIRV) + set(opt_flags) + endif() elseif(ARCH STREQUAL amdgcn) list(APPEND target_compile_flags "SHELL:-Xclang -mcode-object-version=none") endif() @@ -190,19 +181,23 @@ if(ARCH STREQUAL amdgcn) list(APPEND _clc_overrides ${CLC_AMDGPU_SOURCES}) elseif(ARCH STREQUAL nvptx64 AND (OS STREQUAL nvidiacl OR OS STREQUAL cuda)) list(APPEND _clc_overrides ${CLC_PTX_NVIDIACL_SOURCES}) -elseif(ARCH STREQUAL spirv OR ARCH STREQUAL spirv64) - list(APPEND _clc_overrides ${CLC_SPIRV_SOURCES}) -elseif(ARCH STREQUAL clspv OR ARCH STREQUAL clspv64) - list(APPEND _clc_overrides ${CLC_CLSPV_SOURCES}) +elseif(ARCH STREQUAL spirv OR ARCH STREQUAL spirv32 OR ARCH STREQUAL spirv64) + if(OS STREQUAL vulkan) + list(APPEND _clc_overrides ${CLC_VULKAN_SOURCES}) + else() + list(APPEND _clc_overrides ${CLC_SPIRV_SOURCES}) + endif() endif() libclc_merge_sources(clc_sources ${CLC_GENERIC_SOURCES} ${_clc_overrides}) -# Collect OpenCL sources. SPIR-V and Clspv targets use self-contained +# Collect OpenCL sources. SPIR-V and Vulkan targets use self-contained # subsets while others merge with target-specific overrides. -if(ARCH STREQUAL spirv OR ARCH STREQUAL spirv64) - set(opencl_sources ${OPENCL_SPIRV_SOURCES}) -elseif(ARCH STREQUAL clspv OR ARCH STREQUAL clspv64) - set(opencl_sources ${OPENCL_CLSPV_SOURCES}) +if(ARCH STREQUAL spirv OR ARCH STREQUAL spirv32 OR ARCH STREQUAL spirv64) + if(OS STREQUAL vulkan) + set(opencl_sources ${OPENCL_VULKAN_SOURCES}) + else() + set(opencl_sources ${OPENCL_SPIRV_SOURCES}) + endif() else() set(_opencl_overrides) if(ARCH STREQUAL amdgcn) @@ -231,7 +226,6 @@ set(compile_flags ) set(_common_defs - ${target_define} ${target_extra_defines} __CLC_PRIVATE_ADDRSPACE_VAL=${private_addrspace_val} __CLC_GENERIC_ADDRSPACE_VAL=${generic_addrspace_val} diff --git a/libclc/README.md b/libclc/README.md index e096a070ee878..169d59b75c5c6 100644 --- a/libclc/README.md +++ b/libclc/README.md @@ -50,12 +50,11 @@ cmake ../llvm -G Ninja -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release -DLLVM_RUNTIME_TARGETS="nvptx64-nvidia-cuda" ``` -#### Configure for CLSPV targets +#### Configure for Vulkan (clspv) targets ``` cmake ../llvm -G Ninja -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release \ - -DRUNTIMES_clspv--_LLVM_ENABLE_RUNTIMES=libclc \ - -DRUNTIMES_clspv64--_LLVM_ENABLE_RUNTIMES=libclc \ - -DLLVM_RUNTIME_TARGETS="clspv--;clspv64--" + -DRUNTIMES_spirv64-unknown-vulkan_LLVM_ENABLE_RUNTIMES=libclc \ + -DLLVM_RUNTIME_TARGETS="spirv64-unknown-vulkan" ``` #### Configure for SPIR-V targets diff --git a/libclc/clc/include/clc/clcfunc.h b/libclc/clc/include/clc/clcfunc.h index 5457a1892ac87..79b5f4230fac7 100644 --- a/libclc/clc/include/clc/clcfunc.h +++ b/libclc/clc/include/clc/clcfunc.h @@ -14,7 +14,7 @@ #define _CLC_INLINE inline #define _CLC_CONST __attribute__((const)) -#if defined(CLC_CLSPV) +#if defined(__VULKAN__) #define _CLC_DEF __attribute__((noinline)) __attribute__((clspv_libclc_builtin)) #else #define _CLC_DEF diff --git a/libclc/clc/lib/generic/atomic/clc_atomic_compare_exchange.inc b/libclc/clc/lib/generic/atomic/clc_atomic_compare_exchange.inc index 07ef69d426768..d28e3c72e465e 100644 --- a/libclc/clc/lib/generic/atomic/clc_atomic_compare_exchange.inc +++ b/libclc/clc/lib/generic/atomic/clc_atomic_compare_exchange.inc @@ -8,16 +8,16 @@ #ifdef __CLC_SCALAR -#if defined(__SPIR32__) || defined(CLC_NVPTX) +#if defined(__SPIR32__) || defined(__NVPTX__) #if (defined(__CLC_FPSIZE) && __CLC_FPSIZE <= 32) || \ (defined(__CLC_GENSIZE) && (__CLC_GENSIZE == 32)) #define __CLC_HAS_ATOMIC #endif -#else // defined(__SPIR32__) || defined(CLC_NVPTX) +#else // defined(__SPIR32__) || defined(__NVPTX__) #if defined(__CLC_FPSIZE) || (__CLC_GENSIZE >= 32) #define __CLC_HAS_ATOMIC #endif -#endif // defined(__SPIR32__) || defined(CLC_NVPTX) +#endif // defined(__SPIR32__) || defined(__NVPTX__) #ifdef __CLC_HAS_ATOMIC diff --git a/libclc/clc/lib/generic/atomic/clc_atomic_def.inc b/libclc/clc/lib/generic/atomic/clc_atomic_def.inc index 3a313defe0c03..2af450ffbbe5c 100644 --- a/libclc/clc/lib/generic/atomic/clc_atomic_def.inc +++ b/libclc/clc/lib/generic/atomic/clc_atomic_def.inc @@ -8,16 +8,16 @@ #ifdef __CLC_SCALAR -#if defined(__SPIR32__) || defined(CLC_NVPTX) +#if defined(__SPIR32__) || defined(__NVPTX__) #if (defined(__CLC_FPSIZE) && __CLC_FPSIZE <= 32) || \ (defined(__CLC_GENSIZE) && (__CLC_GENSIZE == 32)) #define __CLC_HAS_ATOMIC #endif -#else // defined(__SPIR32__) || defined(CLC_NVPTX) +#else // defined(__SPIR32__) || defined(__NVPTX__) #if defined(__CLC_FPSIZE) || (__CLC_GENSIZE >= 32) #define __CLC_HAS_ATOMIC #endif -#endif // defined(__SPIR32__) || defined(CLC_NVPTX) +#endif // defined(__SPIR32__) || defined(__NVPTX__) #ifdef __CLC_HAS_ATOMIC diff --git a/libclc/clc/lib/clspv/CMakeLists.txt b/libclc/clc/lib/vulkan/CMakeLists.txt similarity index 61% rename from libclc/clc/lib/clspv/CMakeLists.txt rename to libclc/clc/lib/vulkan/CMakeLists.txt index e54fccb10c3b7..172e3be32d65c 100644 --- a/libclc/clc/lib/clspv/CMakeLists.txt +++ b/libclc/clc/lib/vulkan/CMakeLists.txt @@ -1,4 +1,4 @@ -libclc_configure_source_list(CLC_CLSPV_SOURCES +libclc_configure_source_list(CLC_VULKAN_SOURCES ${CMAKE_CURRENT_SOURCE_DIR} integer/clc_mul_hi.cl math/clc_sw_fma.cl diff --git a/libclc/clc/lib/clspv/integer/clc_mul_hi.cl b/libclc/clc/lib/vulkan/integer/clc_mul_hi.cl similarity index 77% rename from libclc/clc/lib/clspv/integer/clc_mul_hi.cl rename to libclc/clc/lib/vulkan/integer/clc_mul_hi.cl index aab761736fff2..fdf4ac344341f 100644 --- a/libclc/clc/lib/clspv/integer/clc_mul_hi.cl +++ b/libclc/clc/lib/vulkan/integer/clc_mul_hi.cl @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// Opt-out of libclc mul_hi implementation for clspv. -// clspv has an internal implementation that does not required using a bigger +// Opt-out of libclc mul_hi implementation for Vulkan SPIR-V targets. +// clspv has an internal implementation that does not require using a bigger // data size. That implementation is based on OpMulExtended which is SPIR-V // specific, thus it cannot be written in OpenCL-C. diff --git a/libclc/clc/lib/clspv/math/clc_sw_fma.cl b/libclc/clc/lib/vulkan/math/clc_sw_fma.cl similarity index 100% rename from libclc/clc/lib/clspv/math/clc_sw_fma.cl rename to libclc/clc/lib/vulkan/math/clc_sw_fma.cl diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index e1e099d2c9869..41297e8eb1e92 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -111,7 +111,9 @@ function(link_libclc_builtin_library target_name) DEPENDS ${link_deps} ) - if(ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64) + string(REPLACE "-" ";" triple_parts "${ARG_TRIPLE}") + list(GET triple_parts 2 triple_os) + if((ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv32 OR ARG_ARCH STREQUAL spirv64) AND NOT triple_os STREQUAL vulkan) # SPIR-V targets produce a .spv file from the linked bitcode. set(builtins_lib ${library_dir}/${ARG_OUTPUT_FILENAME}.spv) if(LIBCLC_USE_SPIRV_BACKEND) diff --git a/libclc/opencl/lib/clspv/CMakeLists.txt b/libclc/opencl/lib/vulkan/CMakeLists.txt similarity index 88% rename from libclc/opencl/lib/clspv/CMakeLists.txt rename to libclc/opencl/lib/vulkan/CMakeLists.txt index 2b9aa33f6e178..5fa2e7a367678 100644 --- a/libclc/opencl/lib/clspv/CMakeLists.txt +++ b/libclc/opencl/lib/vulkan/CMakeLists.txt @@ -1,8 +1,8 @@ set(_gen ${CMAKE_CURRENT_SOURCE_DIR}/../generic) -# CLSPV uses a curated subset of generic builtins plus its own overrides, +# Vulkan uses a curated subset of generic builtins plus its own overrides, # so this list is self-contained rather than merged with the generic set. -libclc_configure_source_list(_clspv_sources +libclc_configure_source_list(_vulkan_sources ${CMAKE_CURRENT_SOURCE_DIR} conversion/convert_float2float.cl conversion/convert_float2int.cl @@ -85,4 +85,4 @@ libclc_configure_source_list(_gen_sources math/tgamma.cl ) -set(OPENCL_CLSPV_SOURCES ${_clspv_sources} ${_gen_sources} PARENT_SCOPE) +set(OPENCL_VULKAN_SOURCES ${_vulkan_sources} ${_gen_sources} PARENT_SCOPE) diff --git a/libclc/opencl/lib/clspv/conversion/convert_float.inc b/libclc/opencl/lib/vulkan/conversion/convert_float.inc similarity index 100% rename from libclc/opencl/lib/clspv/conversion/convert_float.inc rename to libclc/opencl/lib/vulkan/conversion/convert_float.inc diff --git a/libclc/opencl/lib/clspv/conversion/convert_float2float.cl b/libclc/opencl/lib/vulkan/conversion/convert_float2float.cl similarity index 100% rename from libclc/opencl/lib/clspv/conversion/convert_float2float.cl rename to libclc/opencl/lib/vulkan/conversion/convert_float2float.cl diff --git a/libclc/opencl/lib/clspv/conversion/convert_float2int.cl b/libclc/opencl/lib/vulkan/conversion/convert_float2int.cl similarity index 100% rename from libclc/opencl/lib/clspv/conversion/convert_float2int.cl rename to libclc/opencl/lib/vulkan/conversion/convert_float2int.cl diff --git a/libclc/opencl/lib/clspv/conversion/convert_int2float.cl b/libclc/opencl/lib/vulkan/conversion/convert_int2float.cl similarity index 100% rename from libclc/opencl/lib/clspv/conversion/convert_int2float.cl rename to libclc/opencl/lib/vulkan/conversion/convert_int2float.cl diff --git a/libclc/opencl/lib/clspv/conversion/convert_integer.cl b/libclc/opencl/lib/vulkan/conversion/convert_integer.cl similarity index 100% rename from libclc/opencl/lib/clspv/conversion/convert_integer.cl rename to libclc/opencl/lib/vulkan/conversion/convert_integer.cl diff --git a/libclc/opencl/lib/clspv/conversion/convert_integer.inc b/libclc/opencl/lib/vulkan/conversion/convert_integer.inc similarity index 93% rename from libclc/opencl/lib/clspv/conversion/convert_integer.inc rename to libclc/opencl/lib/vulkan/conversion/convert_integer.inc index dc0dad71ca445..072f36918831a 100644 --- a/libclc/opencl/lib/clspv/conversion/convert_integer.inc +++ b/libclc/opencl/lib/vulkan/conversion/convert_integer.inc @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -// Do not generate user-facing default conversions for clspv as they are handled -// natively. Do not generate user-facing "_rte" conversions for clspv as they +// Do not generate user-facing default conversions for Vulkan targets as they +// are handled natively. Do not generate user-facing "_rte" conversions as they // are handled natively. #define __CLC_DEFINE_FUNCTION_ROUNDING_MODE_SATURATION_IMPL(TYPE_SRC, MODE) \ diff --git a/libclc/opencl/lib/clspv/math/fma.cl b/libclc/opencl/lib/vulkan/math/fma.cl similarity index 100% rename from libclc/opencl/lib/clspv/math/fma.cl rename to libclc/opencl/lib/vulkan/math/fma.cl diff --git a/libclc/opencl/lib/clspv/shared/vstore_half.cl b/libclc/opencl/lib/vulkan/shared/vstore_half.cl similarity index 100% rename from libclc/opencl/lib/clspv/shared/vstore_half.cl rename to libclc/opencl/lib/vulkan/shared/vstore_half.cl diff --git a/libclc/opencl/lib/clspv/shared/vstore_half.inc b/libclc/opencl/lib/vulkan/shared/vstore_half.inc similarity index 100% rename from libclc/opencl/lib/clspv/shared/vstore_half.inc rename to libclc/opencl/lib/vulkan/shared/vstore_half.inc diff --git a/libclc/test/CMakeLists.txt b/libclc/test/CMakeLists.txt index 98566a517f604..4c54d93b26813 100644 --- a/libclc/test/CMakeLists.txt +++ b/libclc/test/CMakeLists.txt @@ -7,7 +7,7 @@ set(LIBCLC_TEST_DEPS umbrella_lit_testsuite_begin(check-libclc) # Testing unresolved symbols. -# Skip nvptx, clspv, spirv targets +# Skip nvptx and spirv targets. if(ARCH MATCHES amdgcn) foreach(tgt IN LISTS LIBCLC_UNRESOLVED_SYMBOL_TEST_TARGETS) set(target_file "$<TARGET_PROPERTY:${tgt},TARGET_FILE>") _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
