Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2d50750
remove dummy bin
jinge90 Nov 24, 2025
9c76946
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Nov 26, 2025
fe628a9
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Nov 27, 2025
7a7e62b
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Nov 28, 2025
4de8fa5
merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Dec 1, 2025
e52bb98
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Dec 4, 2025
4b63322
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Dec 10, 2025
544d912
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Dec 12, 2025
2ad6143
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Dec 17, 2025
cf391d9
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Dec 24, 2025
e0f2a15
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Jan 6, 2026
aa7a97c
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Jan 12, 2026
9244680
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Jan 30, 2026
b4b5793
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Feb 3, 2026
50f8f75
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Feb 4, 2026
ebc7166
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Feb 4, 2026
159748c
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Feb 4, 2026
17362e0
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Mar 3, 2026
9e38387
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Mar 5, 2026
dd1e30b
Merge remote-tracking branch 'origin/sycl' into sycl
jinge90 Mar 5, 2026
01fa557
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Mar 25, 2026
78adbd8
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Mar 26, 2026
c681812
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Apr 9, 2026
0726c0d
Merge remote-tracking branch 'upstream/sycl' into sycl
jinge90 Apr 10, 2026
87bfce5
[SYCL] Enable compiler-rt builtins for spirv device code
jinge90 Apr 10, 2026
6716dd8
fix clang-format
jinge90 Apr 10, 2026
d15bb64
skip C_STANDARD when building for sycl
jinge90 Apr 10, 2026
809d279
integrate libclang_rt.builtins into sycl compiler driver
jinge90 Apr 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions buildbot/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,25 @@ def do_configure(args, passthrough_args):
"-DBUG_REPORT_URL=https://github.com/intel/llvm/issues",
]

if sys.platform == "linux":
if args.ci_defaults:
llvm_builtin_targets = "default;spirv64-intel-unknown"
cmake_cmd.extend(
[
"-DLLVM_BUILTIN_TARGETS={}".format(llvm_builtin_targets),
]
)
else:
llvm_runtime_targets = "spirv64-intel-unknown"
llvm_spirv64_runtimes = "compiler-rt"
cmake_cmd.extend(
[
"-DRUNTIMES_spirv64-intel-unknown_LLVM_ENABLE_RUNTIMES={}".format(
llvm_spirv64_runtimes
),
"-DLLVM_RUNTIME_TARGETS={}".format(llvm_runtime_targets),
]
)
if llvm_enable_runtimes:
cmake_cmd.extend(
[
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5826,6 +5826,13 @@ class OffloadingActionBuilder final {
int NumOfDeviceLibLinked = 0;
SmallVector<SmallString<128>, 4> LibLocCandidates;
SYCLInstallation.getSYCLDeviceLibPath(LibLocCandidates);
if (TC->getTriple().isSPIROrSPIRV()) {
std::string CompilerRTPath = TC->getCompilerRTPath();
SmallString<128> SPIRVCompilerRTPath(CompilerRTPath);
llvm::sys::path::append(SPIRVCompilerRTPath, "spirv64-intel-unknown");
if (llvm::sys::fs::exists(SPIRVCompilerRTPath))
LibLocCandidates.emplace_back(SPIRVCompilerRTPath);
}

const toolchains::SYCLToolChain &SYCLTC =
static_cast<const toolchains::SYCLToolChain &>(*TC);
Expand Down
13 changes: 12 additions & 1 deletion clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,9 @@ SYCLToolChain::getDeviceLibNames(const Driver &D,
"libsycl-fallback-complex-fp64",
"libsycl-fallback-cmath",
"libsycl-fallback-cmath-fp64",
#if !defined(_WIN32)
"libclang_rt.builtins",
#endif
"libsycl-fallback-imf",
"libsycl-fallback-imf-fp64",
"libsycl-fallback-imf-bf16"};
Expand Down Expand Up @@ -833,6 +836,8 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
InputFilename.contains("libspirv") ||
InputFilename.contains("libdevice")))
return true;
if (InputFilename.starts_with("libclang_rt.builtins"))
return true;
StringRef LibSyclPrefix("libsycl-");
if (!InputFilename.starts_with(LibSyclPrefix) ||
!InputFilename.ends_with(LibPostfix) ||
Expand Down Expand Up @@ -1920,7 +1925,13 @@ SYCLToolChain::getDeviceLibs(

SmallVector<SmallString<128>, 4> LibraryPaths;
SYCLInstallation.getSYCLDeviceLibPath(LibraryPaths);

if (getTriple().isSPIROrSPIRV()) {
std::string CompilerRTPath = getCompilerRTPath();
SmallString<128> SPIRVCompilerRTPath(CompilerRTPath);
llvm::sys::path::append(SPIRVCompilerRTPath, "spirv64-intel-unknown");
if (llvm::sys::fs::exists(SPIRVCompilerRTPath))
LibraryPaths.emplace_back(SPIRVCompilerRTPath);
}
// Formulate all of the device libraries needed for this compilation.
SmallVector<BitCodeLibraryInfo, 8> DeviceLibs =
getDeviceLibNames(getDriver(), DriverArgs, getTriple());
Expand Down
21 changes: 21 additions & 0 deletions compiler-rt/cmake/Modules/AddCompilerRT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,27 @@ function(add_compiler_rt_runtime name type)
set_property(TARGET ${libname} PROPERTY CXX_STANDARD ${LIB_CXX_STANDARD})
endif()
set_target_output_directories(${libname} ${output_dir_${libname}})
if(COMPILER_RT_GPU_BUILD)
find_program(LLVM_LINK_EXE
NAMES llvm-link
PATHS ${LLVM_TOOLS_BINARY_DIR}
NO_DEFAULT_PATH)
file(GENERATE
OUTPUT ${CMAKE_BINARY_DIR}/${libname}.rsp
CONTENT "$<JOIN:$<TARGET_OBJECTS:${libname}>,\n>")
if(LLVM_LINK_EXE)
set(compiler_rt_bc_file ${output_dir_${libname}}/lib${output_name_${libname}}.bc)
add_custom_target(${libname}_bc
COMMAND ${LLVM_LINK_EXE} -o ${compiler_rt_bc_file} @${CMAKE_BINARY_DIR}/${libname}.rsp)
add_dependencies(${libname}_bc ${libname})
if(LIB_PARENT_TARGET)
add_dependencies(${LIB_PARENT_TARGET} ${libname}_bc)
endif()
install(FILES ${compiler_rt_bc_file}
DESTINATION ${install_dir_${libname}}
${COMPONENT_OPTION})
endif()
endif()
install(TARGETS ${libname}
ARCHIVE DESTINATION ${install_dir_${libname}}
${COMPONENT_OPTION}
Expand Down
8 changes: 8 additions & 0 deletions compiler-rt/cmake/Modules/CompilerRTUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ macro(detect_target_arch)
check_symbol_exists(__s390x__ "" __S390X)
check_symbol_exists(__sparc "" __SPARC)
check_symbol_exists(__sparcv9 "" __SPARCV9)
check_symbol_exists(__SPIRV__ "" __SPIRV)
check_symbol_exists(__wasm32__ "" __WEBASSEMBLY32)
check_symbol_exists(__wasm64__ "" __WEBASSEMBLY64)
check_symbol_exists(__ve__ "" __VE)
Expand Down Expand Up @@ -221,6 +222,8 @@ macro(detect_target_arch)
add_default_target_arch(sparcv9)
elseif(__SPARC)
add_default_target_arch(sparc)
elseif(__SPIRV)
add_default_target_arch(spirv64)
elseif(__WEBASSEMBLY32)
add_default_target_arch(wasm32)
elseif(__WEBASSEMBLY64)
Expand Down Expand Up @@ -421,6 +424,9 @@ macro(construct_compiler_rt_default_triple)
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "nvptx")
set(COMPILER_RT_GPU_BUILD ON)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -flto -c")
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "spirv")
set(COMPILER_RT_GPU_BUILD ON)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fsycl -fsycl-device-only -c -emit-llvm")
endif()
endif()

Expand Down Expand Up @@ -506,6 +512,8 @@ function(get_compiler_rt_target arch variable)
set(target "amdgcn-amd-amdhsa")
elseif("${arch}" MATCHES "^nvptx")
set(target "nvptx64-nvidia-cuda")
elseif("${arch}" MATCHES "^spirv64")
set(target "spirv64-intel-unknown")
else()
set(target "${arch}${triple_suffix}")
endif()
Expand Down
3 changes: 3 additions & 0 deletions compiler-rt/cmake/base-config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ macro(test_targets)
test_target_arch(amdgcn "" "--target=amdgcn-amd-amdhsa" "-nogpulib"
"-flto" "-fconvergent-functions"
"-Xclang -mcode-object-version=none")

elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "spirv")
test_target_arch(spirv64 "" "-fsycl" "-fsycl-device-only")
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "hexagon")
test_target_arch(hexagon "" "")
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "loongarch64")
Expand Down
5 changes: 4 additions & 1 deletion compiler-rt/cmake/builtin-config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ builtin_check_c_compiler_flag(-nogpulib COMPILER_RT_HAS_NOGPULIB_FLA
builtin_check_c_compiler_flag(-flto COMPILER_RT_HAS_FLTO_FLAG)
builtin_check_c_compiler_flag(-fconvergent-functions COMPILER_RT_HAS_FCONVERGENT_FUNCTIONS_FLAG)
builtin_check_c_compiler_flag("-Xclang -mcode-object-version=none" COMPILER_RT_HAS_CODE_OBJECT_VERSION_FLAG)
builtin_check_c_compiler_flag(-fsycl COMPILER_RT_HAS_SYCL_FLAG)
builtin_check_c_compiler_flag(-fsycl-device-only COMPILER_RT_HAS_SYCL_DEVICE_ONLY_FLAG)
builtin_check_c_compiler_flag(-Wbuiltin-declaration-mismatch COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG)
builtin_check_c_compiler_flag(/Zl COMPILER_RT_HAS_ZL_FLAG)
builtin_check_c_compiler_flag(-fcf-protection=full COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
Expand Down Expand Up @@ -79,6 +81,7 @@ else()
endif()

set(AMDGPU amdgcn)
set(SPIRV spirv64)
set(ARM64 aarch64 arm64ec aarch64_lfi)
set(ARM32 arm armhf armv4t armv5te armv6 armv6m armv7m armv7em armv7 armv7s armv7k armv8m.base armv8m.main armv8.1m.main)
set(AVR avr)
Expand Down Expand Up @@ -110,7 +113,7 @@ endif()
set(ALL_BUILTIN_SUPPORTED_ARCH
${X86} ${X86_64} ${AMDGPU} ${ARM32} ${ARM64} ${AVR}
${HEXAGON} ${MIPS32} ${MIPS64} ${NVPTX} ${PPC32} ${PPC64}
${RISCV32} ${RISCV64} ${S390X} ${SPARC} ${SPARCV9}
${RISCV32} ${RISCV64} ${S390X} ${SPARC} ${SPARCV9} ${SPIRV}
${WASM32} ${WASM64} ${VE} ${LOONGARCH64} ${M68K})

include(CompilerRTUtils)
Expand Down
50 changes: 39 additions & 11 deletions compiler-rt/lib/builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ set(GENERIC_SOURCES
umodti3.c
)

set(SPIRV64_SOURCES
divdc3.c
divsc3.c
mulsc3.c
muldc3.c
)


# We only build BF16 files when "__bf16" is available.
set(BF16_SOURCES
extendbfsf2.c
Expand Down Expand Up @@ -739,6 +747,7 @@ if (APPLE)
endif()

set(amdgcn_SOURCES ${GENERIC_SOURCES})
set(spirv64_SOURCES ${SPIRV64_SOURCES})

set(armv4t_SOURCES ${arm_min_SOURCES})
set(armv5te_SOURCES ${arm_min_SOURCES})
Expand Down Expand Up @@ -965,6 +974,12 @@ else ()
endif()
endif()

if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "spirv64")
append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding BUILTIN_CFLAGS)
append_list_if(COMPILER_RT_HAS_SYCL_FLAG -fsycl BUILTIN_CFLAGS)
append_list_if(COMPILER_RT_HAS_SYCL_DEVICE_ONLY_FLAG -fsycl-device-only BUILTIN_CFLAGS)
endif()

set(BUILTIN_DEFS "")

if(COMPILER_RT_BUILTINS_HIDE_SYMBOLS)
Expand Down Expand Up @@ -1019,7 +1034,8 @@ else ()
int main(void) { return 0; }"
COMPILER_RT_HAS_${arch}_BFLOAT16)
# Build BF16 files only when "__bf16" is available.
if(COMPILER_RT_HAS_${arch}_BFLOAT16)

if(COMPILER_RT_HAS_${arch}_BFLOAT16 AND NOT COMPILER_RT_HAS_SYCL_FLAG)
list(APPEND ${arch}_SOURCES ${BF16_SOURCES})
endif()

Expand All @@ -1039,16 +1055,28 @@ else ()
list(APPEND BUILTIN_CFLAGS_${arch} -fforce-enable-int128)
endif()

add_compiler_rt_runtime(clang_rt.builtins
STATIC
ARCHS ${arch}
DEPS ${deps_${arch}}
SOURCES ${${arch}_SOURCES}
DEFS ${BUILTIN_DEFS}
CFLAGS ${BUILTIN_CFLAGS_${arch}}
C_STANDARD 11
CXX_STANDARD 17
PARENT_TARGET builtins)
if("${LLVM_BUILTINS_TARGET}" MATCHES "spirv64")
add_compiler_rt_runtime(clang_rt.builtins
STATIC
ARCHS ${arch}
DEPS ${deps_${arch}}
SOURCES ${${arch}_SOURCES}
DEFS ${BUILTIN_DEFS}
CFLAGS ${BUILTIN_CFLAGS_${arch}}
CXX_STANDARD 17
PARENT_TARGET builtins)
else()
add_compiler_rt_runtime(clang_rt.builtins
STATIC
ARCHS ${arch}
DEPS ${deps_${arch}}
SOURCES ${${arch}_SOURCES}
DEFS ${BUILTIN_DEFS}
CFLAGS ${BUILTIN_CFLAGS_${arch}}
C_STANDARD 11
CXX_STANDARD 17
PARENT_TARGET builtins)
endif()

# Write out the sources that were used to compile the builtins so that tests can be run in
# an independent compiler-rt build (see: compiler-rt/test/builtins/CMakeLists.txt)
Expand Down
16 changes: 16 additions & 0 deletions compiler-rt/lib/builtins/fp_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,35 @@ static __inline fp_t __compiler_rt_fmaxX(fp_t x, fp_t y) {
#if defined(SINGLE_PRECISION)

static __inline fp_t __compiler_rt_logbf(fp_t x) {
#ifdef __SPIRV__
return __spirv_ocl_logb(x);
#else
return __compiler_rt_logbX(x);
#endif
}
static __inline fp_t __compiler_rt_scalbnf(fp_t x, int y) {
#ifdef __SPIRV__
return __spirv_ocl_ldexp(x, y);
#else
return __compiler_rt_scalbnX(x, y);
#endif
}

#elif defined(DOUBLE_PRECISION)

static __inline fp_t __compiler_rt_logb(fp_t x) {
#ifdef __SPIRV__
return __spirv_ocl_logb(x);
#else
return __compiler_rt_logbX(x);
#endif
}
static __inline fp_t __compiler_rt_scalbn(fp_t x, int y) {
#ifdef __SPIRV__
return __spirv_ocl_ldexp(x, y);
#else
return __compiler_rt_scalbnX(x, y);
#endif
}
static __inline fp_t __compiler_rt_fmax(fp_t x, fp_t y) {
#if defined(__aarch64__) || defined(__arm64ec__)
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/builtins/int_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#else
#define COMPILER_RT_ABI __attribute__((__pcs__("aapcs")))
#endif
#elif defined(__SPIRV__)
#define COMPILER_RT_ABI SYCL_EXTERNAL extern "C"
#else
#define COMPILER_RT_ABI
#endif
Expand Down
11 changes: 11 additions & 0 deletions compiler-rt/lib/builtins/int_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@
#if defined(_MSC_VER) && !defined(__clang__)
#define CRT_INFINITY INFINITY
#else
#if defined(DOUBLE_PRECISION)
#define CRT_INFINITY __builtin_huge_val()
#else
#define CRT_INFINITY __builtin_huge_valf()
#endif
#endif

#if defined(_MSC_VER) && !defined(__clang__)
#define crt_isfinite(x) _finite((x))
#define crt_isinf(x) !_finite((x))
#define crt_isnan(x) _isnan((x))
#elif defined(__SPIRV__)
#define crt_isinf(x) __spirv_IsInf((x))
#define crt_isnan(x) __spirv_IsNan((x))
#define crt_isfinite(x) __spirv_IsFinite((x))
#else
// Define crt_isfinite in terms of the builtin if available, otherwise provide
// an alternate version in terms of our other functions. This supports some
Expand All @@ -61,6 +69,9 @@
#define crt_copysign(x, y) copysign((x), (y))
#define crt_copysignf(x, y) copysignf((x), (y))
#define crt_copysignl(x, y) copysignl((x), (y))
#elif defined(__SPIRV__)
#define crt_copysign(x, y) __spirv_ocl_copysign((x), (y))
#define crt_copysignf(x, y) __spirv_ocl_copysign((x), (y))
#else
#define crt_copysign(x, y) __builtin_copysign((x), (y))
#define crt_copysignf(x, y) __builtin_copysignf((x), (y))
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/lib/builtins/muldc3.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
//===----------------------------------------------------------------------===//

#define DOUBLE_PRECISION
#include "int_lib.h"
#include "int_math.h"

Expand Down
13 changes: 0 additions & 13 deletions libdevice/complex_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,4 @@ float __complex__ catanhf(float __complex__ z) {
DEVICE_EXTERN_C_INLINE
float __complex__ catanf(float __complex__ z) { return __devicelib_catanf(z); }

// __mulsc3
// Returns: the product of a + ib and c + id
DEVICE_EXTERN_C_INLINE
float __complex__ __mulsc3(float __a, float __b, float __c, float __d) {
return __devicelib___mulsc3(__a, __b, __c, __d);
}

// __divsc3
// Returns: the quotient of (a + ib) / (c + id)
DEVICE_EXTERN_C_INLINE
float __complex__ __divsc3(float __a, float __b, float __c, float __d) {
return __devicelib___divsc3(__a, __b, __c, __d);
}
#endif // __SPIR__ || __SPIRV__
13 changes: 0 additions & 13 deletions libdevice/complex_wrapper_fp64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,4 @@ double __complex__ catanh(double __complex__ z) {
DEVICE_EXTERN_C_INLINE
double __complex__ catan(double __complex__ z) { return __devicelib_catan(z); }

// __muldc3
// Returns: the product of a + ib and c + id
DEVICE_EXTERN_C_INLINE
double __complex__ __muldc3(double __a, double __b, double __c, double __d) {
return __devicelib___muldc3(__a, __b, __c, __d);
}

// __divdc3
// Returns: the quotient of (a + ib) / (c + id)
DEVICE_EXTERN_C_INLINE
double __complex__ __divdc3(double __a, double __b, double __c, double __d) {
return __devicelib___divdc3(__a, __b, __c, __d);
}
#endif // __SPIR__ || __SPIRV__
12 changes: 0 additions & 12 deletions libdevice/device_complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,5 @@ double __complex__ __devicelib_catan(double __complex__ z);

DEVICE_EXTERN_C
float __complex__ __devicelib_catanf(float __complex__ z);

DEVICE_EXTERN_C
double __complex__ __devicelib___muldc3(double a, double b, double c, double d);

DEVICE_EXTERN_C
float __complex__ __devicelib___mulsc3(float a, float b, float c, float d);

DEVICE_EXTERN_C
double __complex__ __devicelib___divdc3(double a, double b, double c, double d);

DEVICE_EXTERN_C
float __complex__ __devicelib___divsc3(float a, float b, float c, float d);
#endif // __SPIR__ || __SPIRV__
#endif // __LIBDEVICE_DEVICE_COMPLEX_H_
Loading
Loading