From 1d8913bfcfa36b4ca86382b480c944c4e9e735d3 Mon Sep 17 00:00:00 2001 From: jinge90 Date: Mon, 7 Sep 2026 13:21:03 +0800 Subject: [PATCH 1/7] [SYCL] Use compiler-rt builtin in SYCL for SPIRV targets Signed-off-by: jinge90 --- buildbot/configure.py | 27 ++++- clang/lib/Driver/Driver.cpp | 7 ++ clang/lib/Driver/ToolChains/SYCL.cpp | 12 +- .../libclang_rt.builtins.bc | 0 .../sycl-no-rdc-fat-archive-old-model.cpp | 30 ++--- .../Driver/sycl-no-rdc-fat-archive-win.cpp | 30 ++--- clang/test/Driver/sycl-no-rdc-old-model.cpp | 32 +++--- clang/test/Driver/sycl-no-rdc-win.cpp | 33 +++--- compiler-rt/cmake/builtin-config-ix.cmake | 1 + compiler-rt/lib/builtins/CMakeLists.txt | 4 + libdevice/cmake/modules/SYCLLibdevice.cmake | 5 +- libdevice/complex_wrapper.hpp | 27 ----- libdevice/fallback-complex-fp64.hpp | 102 +---------------- libdevice/fallback-complex.hpp | 104 +----------------- sycl-jit/jit-compiler/CMakeLists.txt | 6 +- .../lib/rtc/DeviceCompilation.cpp | 32 ++++-- sycl/CMakeLists.txt | 7 ++ 17 files changed, 150 insertions(+), 309 deletions(-) create mode 100644 clang/test/Driver/Inputs/SYCL/lib/clang/resource_dir/lib/spirv64-unknown-unknown/libclang_rt.builtins.bc diff --git a/buildbot/configure.py b/buildbot/configure.py index 4874c0a44557a..5b2a7bf233d26 100644 --- a/buildbot/configure.py +++ b/buildbot/configure.py @@ -200,6 +200,21 @@ def do_configure(args, passthrough_args): "-DBUG_REPORT_URL=https://github.com/intel/llvm/issues", ] + llvm_spirv64_runtimes = "compiler-rt" + llvm_spirv64_sanitizers = "" + runtime_targets += ";spirv64-unknown-unknown" + cmake_cmd.extend( + [ + "-DRUNTIMES_spirv64-unknown-unknown_LLVM_ENABLE_RUNTIMES={}".format( + llvm_spirv64_runtimes + ), + + "-DRUNTIMES_spirv64-unknown-unknown_COMPILER_RT_SANITIZERS_TO_BUILD={}".format( + llvm_spirv64_sanitizers + ), + ] + ) + if llvm_enable_runtimes: cmake_cmd.extend( [ @@ -225,19 +240,19 @@ def do_configure(args, passthrough_args): if libclc_enabled: for target in runtime_targets.split(";"): - if target == "default": + if target == "default" or target == "spirv64-unknown-unknown": continue cmake_cmd.extend( [ f"-DRUNTIMES_{target}_LLVM_ENABLE_RUNTIMES=libclc", ] ) - cmake_cmd.extend( - [ - "-DLLVM_RUNTIME_TARGETS={}".format(runtime_targets), - ] - ) + cmake_cmd.extend( + [ + "-DLLVM_RUNTIME_TARGETS={}".format(runtime_targets), + ] + ) if args.l0_headers and args.l0_loader: cmake_cmd.extend( [ diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 6546e611d11e6..9b4f6cfb562f0 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5961,6 +5961,13 @@ class OffloadingActionBuilder final { int NumOfDeviceLibLinked = 0; SmallVector, 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(*TC); diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp index 5df5a8d60bed0..d62ccb09391de 100644 --- a/clang/lib/Driver/ToolChains/SYCL.cpp +++ b/clang/lib/Driver/ToolChains/SYCL.cpp @@ -668,7 +668,8 @@ SYCLToolChain::getDeviceLibNames(const Driver &D, #if defined(_WIN32) "libsycl-msvc-math", #endif - "libsycl-imf"}; + "libsycl-imf", + "libclang_rt.builtins"}; auto addLibraries = [&](const SYCLDeviceLibsList &LibsList) { for (const StringRef &Lib : LibsList) addLibToList(Args.MakeArgString(Lib + ".bc")); @@ -884,6 +885,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)) @@ -2005,6 +2008,13 @@ SYCLToolChain::getDeviceLibs( SmallVector, 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 DeviceLibs = getDeviceLibNames(getDriver(), DriverArgs, getTriple()); diff --git a/clang/test/Driver/Inputs/SYCL/lib/clang/resource_dir/lib/spirv64-unknown-unknown/libclang_rt.builtins.bc b/clang/test/Driver/Inputs/SYCL/lib/clang/resource_dir/lib/spirv64-unknown-unknown/libclang_rt.builtins.bc new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/sycl-no-rdc-fat-archive-old-model.cpp b/clang/test/Driver/sycl-no-rdc-fat-archive-old-model.cpp index c81bf19e2f61e..02057ff538157 100644 --- a/clang/test/Driver/sycl-no-rdc-fat-archive-old-model.cpp +++ b/clang/test/Driver/sycl-no-rdc-fat-archive-old-model.cpp @@ -13,18 +13,18 @@ // CHECK: 2: clang-offload-unbundler, {1}, tempfilelist // CHECK: 3: spirv-to-ir-wrapper, {2}, tempfilelist, (device-sycl) // CHECK: 4: input, "{{.*}}libsycl-crt.bc", ir, (device-sycl) -// CHECK: 10: linker, {4, {{.*}}}, ir, (device-sycl) -// CHECK: 11: linker, {3, 10}, ir, (device-sycl) -// CHECK: 12: foreach, {3, 11}, ir, (device-sycl) -// CHECK: 13: file-table-tform, {3, 12}, tempfilelist, (device-sycl) -// CHECK: 14: sycl-post-link, {13}, tempfiletable, (device-sycl) -// CHECK: 15: foreach, {13, 14}, tempfiletable, (device-sycl) -// CHECK: 16: file-table-tform, {15}, tempfilelist, (device-sycl) -// CHECK: 17: file-table-tform, {15}, tempfilelist, (device-sycl) -// CHECK: 18: foreach, {13, 17}, tempfilelist, (device-sycl) -// CHECK: 19: file-table-tform, {18}, tempfilelist, (device-sycl) -// CHECK: 20: llvm-spirv, {19}, tempfilelist, (device-sycl) -// CHECK: 21: file-table-tform, {16, 20}, tempfiletable, (device-sycl) -// CHECK: 22: clang-offload-wrapper, {21}, object, (device-sycl) -// CHECK: 23: offload, "device-sycl (spir64-unknown-unknown)" {22}, object -// CHECK: 24: linker, {0, 23}, image, (host-sycl) +// CHECK: 11: linker, {4, {{.*}}}, ir, (device-sycl) +// CHECK: 12: linker, {3, 11}, ir, (device-sycl) +// CHECK: 13: foreach, {3, 12}, ir, (device-sycl) +// CHECK: 14: file-table-tform, {3, 13}, tempfilelist, (device-sycl) +// CHECK: 15: sycl-post-link, {14}, tempfiletable, (device-sycl) +// CHECK: 16: foreach, {14, 15}, tempfiletable, (device-sycl) +// CHECK: 17: file-table-tform, {16}, tempfilelist, (device-sycl) +// CHECK: 18: file-table-tform, {16}, tempfilelist, (device-sycl) +// CHECK: 19: foreach, {14, 18}, tempfilelist, (device-sycl) +// CHECK: 20: file-table-tform, {19}, tempfilelist, (device-sycl) +// CHECK: 21: llvm-spirv, {20}, tempfilelist, (device-sycl) +// CHECK: 22: file-table-tform, {17, 21}, tempfiletable, (device-sycl) +// CHECK: 23: clang-offload-wrapper, {22}, object, (device-sycl) +// CHECK: 24: offload, "device-sycl (spir64-unknown-unknown)" {23}, object +// CHECK: 25: linker, {0, 24}, image, (host-sycl) diff --git a/clang/test/Driver/sycl-no-rdc-fat-archive-win.cpp b/clang/test/Driver/sycl-no-rdc-fat-archive-win.cpp index 6391b8c421369..cf366d69aeae7 100644 --- a/clang/test/Driver/sycl-no-rdc-fat-archive-win.cpp +++ b/clang/test/Driver/sycl-no-rdc-fat-archive-win.cpp @@ -18,18 +18,18 @@ // CHECK: 2: clang-offload-unbundler, {1}, tempfilelist // CHECK: 3: spirv-to-ir-wrapper, {2}, tempfilelist, (device-sycl) // CHECK: 4: input, "{{.*}}libsycl-crt{{.*}}", ir, (device-sycl) -// CHECK: 11: linker, {4, {{.*}}}, ir, (device-sycl) -// CHECK: 12: linker, {3, 11}, ir, (device-sycl) -// CHECK: 13: foreach, {3, 12}, ir, (device-sycl) -// CHECK: 14: file-table-tform, {3, 13}, tempfilelist, (device-sycl) -// CHECK: 15: sycl-post-link, {14}, tempfiletable, (device-sycl) -// CHECK: 16: foreach, {14, 15}, tempfiletable, (device-sycl) -// CHECK: 17: file-table-tform, {16}, tempfilelist, (device-sycl) -// CHECK: 18: file-table-tform, {16}, tempfilelist, (device-sycl) -// CHECK: 19: foreach, {14, 18}, tempfilelist, (device-sycl) -// CHECK: 20: file-table-tform, {19}, tempfilelist, (device-sycl) -// CHECK: 21: llvm-spirv, {20}, tempfilelist, (device-sycl) -// CHECK: 22: file-table-tform, {17, 21}, tempfiletable, (device-sycl) -// CHECK: 23: clang-offload-wrapper, {22}, object, (device-sycl) -// CHECK: 24: offload, "device-sycl (spir64-unknown-unknown)" {23}, object -// CHECK: 25: linker, {0, 24}, image, (host-sycl) +// CHECK: 12: linker, {4, {{.*}}}, ir, (device-sycl) +// CHECK: 13: linker, {3, 12}, ir, (device-sycl) +// CHECK: 14: foreach, {3, 13}, ir, (device-sycl) +// CHECK: 15: file-table-tform, {3, 14}, tempfilelist, (device-sycl) +// CHECK: 16: sycl-post-link, {15}, tempfiletable, (device-sycl) +// CHECK: 17: foreach, {15, 16}, tempfiletable, (device-sycl) +// CHECK: 18: file-table-tform, {17}, tempfilelist, (device-sycl) +// CHECK: 19: file-table-tform, {17}, tempfilelist, (device-sycl) +// CHECK: 20: foreach, {15, 19}, tempfilelist, (device-sycl) +// CHECK: 21: file-table-tform, {20}, tempfilelist, (device-sycl) +// CHECK: 22: llvm-spirv, {21}, tempfilelist, (device-sycl) +// CHECK: 23: file-table-tform, {18, 22}, tempfiletable, (device-sycl) +// CHECK: 24: clang-offload-wrapper, {23}, object, (device-sycl) +// CHECK: 25: offload, "device-sycl (spir64-unknown-unknown)" {24}, object +// CHECK: 26: linker, {0, 25}, image, (host-sycl) diff --git a/clang/test/Driver/sycl-no-rdc-old-model.cpp b/clang/test/Driver/sycl-no-rdc-old-model.cpp index 52d770582cba5..d791eb06048a5 100644 --- a/clang/test/Driver/sycl-no-rdc-old-model.cpp +++ b/clang/test/Driver/sycl-no-rdc-old-model.cpp @@ -12,19 +12,19 @@ // CHECK: 12: preprocessor, {11}, c++-cpp-output, (device-sycl) // CHECK: 13: compiler, {12}, ir, (device-sycl) // CHECK: 18: input, "{{.*}}libsycl-crt.bc", ir, (device-sycl) -// CHECK: 24: linker, {18, {{.*}}}, ir, (device-sycl) -// CHECK: 25: linker, {4, 24}, ir, (device-sycl) -// CHECK: 26: sycl-post-link, {25}, tempfiletable, (device-sycl) -// CHECK: 27: file-table-tform, {26}, tempfilelist, (device-sycl) -// CHECK: 28: llvm-spirv, {27}, tempfilelist, (device-sycl) -// CHECK: 29: file-table-tform, {26, 28}, tempfiletable, (device-sycl) -// CHECK: 30: clang-offload-wrapper, {29}, object, (device-sycl) -// CHECK: 31: offload, "device-sycl (spir64-unknown-unknown)" {30}, object -// CHECK: 32: linker, {13, 24}, ir, (device-sycl) -// CHECK: 33: sycl-post-link, {32}, tempfiletable, (device-sycl) -// CHECK: 34: file-table-tform, {33}, tempfilelist, (device-sycl) -// CHECK: 35: llvm-spirv, {34}, tempfilelist, (device-sycl) -// CHECK: 36: file-table-tform, {33, 35}, tempfiletable, (device-sycl) -// CHECK: 37: clang-offload-wrapper, {36}, object, (device-sycl) -// CHECK: 38: offload, "device-sycl (spir64-unknown-unknown)" {37}, object -// CHECK: 39: linker, {8, 17, 31, 38}, image, (host-sycl) +// CHECK: 25: linker, {18, {{.*}}}, ir, (device-sycl) +// CHECK: 26: linker, {4, 25}, ir, (device-sycl) +// CHECK: 27: sycl-post-link, {26}, tempfiletable, (device-sycl) +// CHECK: 28: file-table-tform, {27}, tempfilelist, (device-sycl) +// CHECK: 29: llvm-spirv, {28}, tempfilelist, (device-sycl) +// CHECK: 30: file-table-tform, {27, 29}, tempfiletable, (device-sycl) +// CHECK: 31: clang-offload-wrapper, {30}, object, (device-sycl) +// CHECK: 32: offload, "device-sycl (spir64-unknown-unknown)" {31}, object +// CHECK: 33: linker, {13, 25}, ir, (device-sycl) +// CHECK: 34: sycl-post-link, {33}, tempfiletable, (device-sycl) +// CHECK: 35: file-table-tform, {34}, tempfilelist, (device-sycl) +// CHECK: 36: llvm-spirv, {35}, tempfilelist, (device-sycl) +// CHECK: 37: file-table-tform, {34, 36}, tempfiletable, (device-sycl) +// CHECK: 38: clang-offload-wrapper, {37}, object, (device-sycl) +// CHECK: 39: offload, "device-sycl (spir64-unknown-unknown)" {38}, object +// CHECK: 40: linker, {8, 17, 32, 39}, image, (host-sycl) diff --git a/clang/test/Driver/sycl-no-rdc-win.cpp b/clang/test/Driver/sycl-no-rdc-win.cpp index a986f23b10f26..09dbc9d774aee 100644 --- a/clang/test/Driver/sycl-no-rdc-win.cpp +++ b/clang/test/Driver/sycl-no-rdc-win.cpp @@ -15,23 +15,22 @@ // CHECK: 13: compiler, {12}, ir, (device-sycl) // CHECK: 14: offload, "host-sycl (x86_64-pc-windows-msvc)" {10}, "device-sycl (spir64-unknown-unknown)" {13}, c++-cpp-output // CHECK: 18: input, "{{.*}}libsycl-crt{{.*}}", ir, (device-sycl) -// CHECK: 25: linker, {18, {{.*}}}, ir, (device-sycl) -// CHECK: 26: linker, {4, 25}, ir, (device-sycl) -// CHECK: 27: sycl-post-link, {26}, tempfiletable, (device-sycl) -// CHECK: 28: file-table-tform, {27}, tempfilelist, (device-sycl) -// CHECK: 29: llvm-spirv, {28}, tempfilelist, (device-sycl) -// CHECK: 30: file-table-tform, {27, 29}, tempfiletable, (device-sycl) -// CHECK: 31: clang-offload-wrapper, {30}, object, (device-sycl) -// CHECK: 32: offload, "device-sycl (spir64-unknown-unknown)" {31}, object -// CHECK: 33: linker, {13, 25}, ir, (device-sycl) -// CHECK: 34: sycl-post-link, {33}, tempfiletable, (device-sycl) -// CHECK: 35: file-table-tform, {34}, tempfilelist, (device-sycl) -// CHECK: 36: llvm-spirv, {35}, tempfilelist, (device-sycl) -// CHECK: 37: file-table-tform, {34, 36}, tempfiletable, (device-sycl) -// CHECK: 38: clang-offload-wrapper, {37}, object, (device-sycl) -// CHECK: 39: offload, "device-sycl (spir64-unknown-unknown)" {38}, object -// CHECK: 40: linker, {8, 17, 32, 39}, image, (host-sycl) - +// CHECK: 26: linker, {18, {{.*}}}, ir, (device-sycl) +// CHECK: 27: linker, {4, 26}, ir, (device-sycl) +// CHECK: 28: sycl-post-link, {27}, tempfiletable, (device-sycl) +// CHECK: 29: file-table-tform, {28}, tempfilelist, (device-sycl) +// CHECK: 30: llvm-spirv, {29}, tempfilelist, (device-sycl) +// CHECK: 31: file-table-tform, {28, 30}, tempfiletable, (device-sycl) +// CHECK: 32: clang-offload-wrapper, {31}, object, (device-sycl) +// CHECK: 33: offload, "device-sycl (spir64-unknown-unknown)" {32}, object +// CHECK: 34: linker, {13, 26}, ir, (device-sycl) +// CHECK: 35: sycl-post-link, {34}, tempfiletable, (device-sycl) +// CHECK: 36: file-table-tform, {35}, tempfilelist, (device-sycl) +// CHECK: 37: llvm-spirv, {36}, tempfilelist, (device-sycl) +// CHECK: 38: file-table-tform, {35, 37}, tempfiletable, (device-sycl) +// CHECK: 39: clang-offload-wrapper, {38}, object, (device-sycl) +// CHECK: 40: offload, "device-sycl (spir64-unknown-unknown)" {39}, object +// CHECK: 41: linker, {8, 17, 33, 40}, image, (host-sycl) // RUN: %clang -### -fsycl -fno-sycl-rdc -c -fsycl-targets=spir64_gen --sysroot=%S/Inputs/SYCL %t1.cpp 2>&1 | FileCheck -check-prefix=CHECK-EARLY %s // RUN: %clang_cl -### -fsycl -fno-sycl-rdc -c -fsycl-targets=spir64_gen /clang:--sysroot=%S/Inputs/SYCL %t1.cpp 2>&1 | FileCheck -check-prefix=CHECK-EARLY %s // CHECK-EARLY: llvm-link{{.*}} diff --git a/compiler-rt/cmake/builtin-config-ix.cmake b/compiler-rt/cmake/builtin-config-ix.cmake index 4d560e48acacf..ae8b4ba58dbc0 100644 --- a/compiler-rt/cmake/builtin-config-ix.cmake +++ b/compiler-rt/cmake/builtin-config-ix.cmake @@ -23,6 +23,7 @@ builtin_check_c_compiler_flag(-Wno-pedantic COMPILER_RT_HAS_WNO_PEDANTIC builtin_check_c_compiler_flag(-nogpulib COMPILER_RT_HAS_NOGPULIB_FLAG) builtin_check_c_compiler_flag(-flto COMPILER_RT_HAS_FLTO_FLAG) builtin_check_c_compiler_flag("-Xclang -mcode-object-version=none" COMPILER_RT_HAS_CODE_OBJECT_VERSION_FLAG) +builtin_check_c_compiler_flag("-Xclang -fspirv-default-addr-space-is-generic" COMPILER_RT_HAS_SPIRV_DEFAULT_ADDR_SPACE_IS_GENERIC) 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) diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt index 79c4fbdfcbe1c..026fb3ea5717e 100644 --- a/compiler-rt/lib/builtins/CMakeLists.txt +++ b/compiler-rt/lib/builtins/CMakeLists.txt @@ -1076,6 +1076,10 @@ else () append_list_if(COMPILER_RT_HAS_CODE_OBJECT_VERSION_FLAG "SHELL:-Xclang -mcode-object-version=none" BUILTIN_CFLAGS) endif() + if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "spirv64") + append_list_if(COMPILER_RT_HAS_SPIRV_DEFAULT_ADDR_SPACE_IS_GENERIC + "SHELL:-Xclang -fspirv-default-addr-space-is-generic" BUILTIN_CFLAGS) + endif() endif() set(BUILTIN_DEFS "") diff --git a/libdevice/cmake/modules/SYCLLibdevice.cmake b/libdevice/cmake/modules/SYCLLibdevice.cmake index 648e4da85ca7a..f512919aa8d9e 100644 --- a/libdevice/cmake/modules/SYCLLibdevice.cmake +++ b/libdevice/cmake/modules/SYCLLibdevice.cmake @@ -442,10 +442,13 @@ add_devicelibs(libsycl-crt DEPENDENCIES ${crt_obj_deps} EXTRA_OPTS $<$:-Wno-invalid-noreturn>) +# Applying no-fast-math, clang will emit __mulsc3/__muldc3/__divsc3/__divdc3 +# when doing complex number multiplication and division add_devicelibs(libsycl-cmath SRC cmath_wrapper.cpp BUILD_ARCHS ${full_build_archs} - DEPENDENCIES ${cmath_obj_deps}) + DEPENDENCIES ${cmath_obj_deps} + EXTRA_OPTS -fno-fast-math) if(MSVC) add_devicelibs(libsycl-msvc-math SRC msvc_math.cpp diff --git a/libdevice/complex_wrapper.hpp b/libdevice/complex_wrapper.hpp index 2ea7ef9f8f1a9..04370a3101337 100644 --- a/libdevice/complex_wrapper.hpp +++ b/libdevice/complex_wrapper.hpp @@ -88,20 +88,6 @@ 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); -} - DEVICE_EXTERN_C_INLINE double cimag(double __complex__ z) { return __devicelib_cimag(z); } @@ -178,17 +164,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__ diff --git a/libdevice/fallback-complex-fp64.hpp b/libdevice/fallback-complex-fp64.hpp index a40325e5c7adf..e2d80b30dd3a1 100644 --- a/libdevice/fallback-complex-fp64.hpp +++ b/libdevice/fallback-complex-fp64.hpp @@ -21,100 +21,6 @@ static inline double __devicelib_cimag(double __complex__ z) { return __imag__(z); } -// __muldc3 -// Returns: the product of a + ib and c + id -static inline double __complex__ __devicelib___muldc3(double __a, double __b, - double __c, double __d) { - double __ac = __a * __c; - double __bd = __b * __d; - double __ad = __a * __d; - double __bc = __b * __c; - double __complex__ z; - z = CMPLX((__ac - __bd), (__ad + __bc)); - if (__spirv_IsNan(__devicelib_creal(z)) && - __spirv_IsNan(__devicelib_cimag(z))) { - int __recalc = 0; - if (__spirv_IsInf(__a) || __spirv_IsInf(__b)) { - __a = __spirv_ocl_copysign(__spirv_IsInf(__a) ? 1.0 : 0.0, __a); - __b = __spirv_ocl_copysign(__spirv_IsInf(__b) ? 1.0 : 0.0, __b); - if (__spirv_IsNan(__c)) - __c = __spirv_ocl_copysign(0.0, __c); - if (__spirv_IsNan(__d)) - __d = __spirv_ocl_copysign(0.0, __d); - __recalc = 1; - } - if (__spirv_IsInf(__c) || __spirv_IsInf(__d)) { - __c = __spirv_ocl_copysign(__spirv_IsInf(__c) ? 1.0 : 0.0, __c); - __d = __spirv_ocl_copysign(__spirv_IsInf(__d) ? 1.0 : 0.0, __d); - if (__spirv_IsNan(__a)) - __a = __spirv_ocl_copysign(0.0, __a); - if (__spirv_IsNan(__b)) - __b = __spirv_ocl_copysign(0.0, __b); - __recalc = 1; - } - if (!__recalc && (__spirv_IsInf(__ac) || __spirv_IsInf(__bd) || - __spirv_IsInf(__ad) || __spirv_IsInf(__bc))) { - if (__spirv_IsNan(__a)) - __a = __spirv_ocl_copysign(0.0, __a); - if (__spirv_IsNan(__b)) - __b = __spirv_ocl_copysign(0.0, __b); - if (__spirv_IsNan(__c)) - __c = __spirv_ocl_copysign(0.0, __c); - if (__spirv_IsNan(__d)) - __d = __spirv_ocl_copysign(0.0, __d); - __recalc = 1.0; - } - if (__recalc) { - z = CMPLX((INFINITY * (__a * __c - __b * __d)), - (INFINITY * (__a * __d + __b * __c))); - } - } - return z; -} - -// __divdc3 -// Returns: the quotient of (a + ib) / (c + id) -static inline double __complex__ __devicelib___divdc3(double __a, double __b, - double __c, double __d) { - int __ilogbw = 0; - double __logbw = __spirv_ocl_logb( - __spirv_ocl_fmax(__spirv_ocl_fabs(__c), __spirv_ocl_fabs(__d))); - if (__spirv_IsFinite(__logbw)) { - __ilogbw = (int)__logbw; - __c = __spirv_ocl_ldexp(__c, -__ilogbw); - __d = __spirv_ocl_ldexp(__d, -__ilogbw); - } - double __denom = __c * __c + __d * __d; - double __complex__ z; - double z_real = - __spirv_ocl_ldexp((__a * __c + __b * __d) / __denom, -__ilogbw); - double z_imag = - __spirv_ocl_ldexp((__b * __c - __a * __d) / __denom, -__ilogbw); - z = CMPLX(z_real, z_imag); - if (__spirv_IsNan(z_real) && __spirv_IsNan(z_imag)) { - if ((__denom == 0.0) && (!__spirv_IsNan(__a) || !__spirv_IsNan(__b))) { - z_real = __spirv_ocl_copysign((double)INFINITY, __c) * __a; - z_imag = __spirv_ocl_copysign((double)INFINITY, __c) * __b; - z = CMPLX(z_real, z_imag); - } else if ((__spirv_IsInf(__a) || __spirv_IsInf(__b)) && - __spirv_IsFinite(__c) && __spirv_IsFinite(__d)) { - __a = __spirv_ocl_copysign(__spirv_IsInf(__a) ? 1.0 : 0.0, __a); - __b = __spirv_ocl_copysign(__spirv_IsInf(__b) ? 1.0 : 0.0, __b); - z_real = INFINITY * (__a * __c + __b * __d); - z_imag = INFINITY * (__b * __c - __a * __d); - z = CMPLX(z_real, z_imag); - } else if (__spirv_IsInf(__logbw) && __logbw > 0.0 && - __spirv_IsFinite(__a) && __spirv_IsFinite(__b)) { - __c = __spirv_ocl_copysign(__spirv_IsInf(__c) ? 1.0 : 0.0, __c); - __d = __spirv_ocl_copysign(__spirv_IsInf(__d) ? 1.0 : 0.0, __d); - z_real = 0.0 * (__a * __c + __b * __d); - z_imag = 0.0 * (__b * __c - __a * __d); - z = CMPLX(z_real, z_imag); - } - } - return z; -} - static inline double __devicelib_cabs(double __complex__ z) { return __spirv_ocl_hypot(__devicelib_creal(z), __devicelib_cimag(z)); } @@ -169,9 +75,7 @@ static inline double __complex__ __devicelib_clog(double __complex__ z) { static inline double __complex__ __devicelib_cpow(double __complex__ x, double __complex__ y) { double __complex__ t = __devicelib_clog(x); - double __complex__ w = - __devicelib___muldc3(__devicelib_creal(y), __devicelib_cimag(y), - __devicelib_creal(t), __devicelib_cimag(t)); + double __complex__ w = y * t; return __devicelib_cexp(w); } @@ -404,9 +308,7 @@ static inline double __complex__ __devicelib_catanh(double __complex__ z) { __spirv_ocl_copysign(0.0, z_imag)); double __complex__ t1 = 1.0 + z; double __complex__ t2 = 1.0 - z; - double __complex__ t3 = - __devicelib___divdc3(__devicelib_creal(t1), __devicelib_cimag(t1), - __devicelib_creal(t2), __devicelib_cimag(t2)); + double __complex__ t3 = t1 / t2; double __complex__ w = __devicelib_clog(t3) / 2.0; return CMPLX(__spirv_ocl_copysign(__devicelib_creal(w), z_real), __spirv_ocl_copysign(__devicelib_cimag(w), z_imag)); diff --git a/libdevice/fallback-complex.hpp b/libdevice/fallback-complex.hpp index 3952eae2a58b1..6b9961aa94c05 100644 --- a/libdevice/fallback-complex.hpp +++ b/libdevice/fallback-complex.hpp @@ -20,102 +20,6 @@ static inline float __devicelib_cimagf(float __complex__ z) { return __imag__(z); } -// __mulsc3 -// Returns: the product of a + ib and c + id -static inline float __complex__ __devicelib___mulsc3(float __a, float __b, - float __c, float __d) { - float __ac = __a * __c; - float __bd = __b * __d; - float __ad = __a * __d; - float __bc = __b * __c; - float __complex__ z; - z = CMPLXF((__ac - __bd), (__ad + __bc)); - if (__spirv_IsNan(__devicelib_crealf(z)) && - __spirv_IsNan(__devicelib_cimagf(z))) { - int __recalc = 0; - if (__spirv_IsInf(__a) || __spirv_IsInf(__b)) { - __a = __spirv_ocl_copysign(__spirv_IsInf(__a) ? 1.0f : 0.0f, __a); - __b = __spirv_ocl_copysign(__spirv_IsInf(__b) ? 1.0f : 0.0f, __b); - if (__spirv_IsNan(__c)) - __c = __spirv_ocl_copysign(0.0f, __c); - if (__spirv_IsNan(__d)) - __d = __spirv_ocl_copysign(0.0f, __d); - __recalc = 1; - } - if (__spirv_IsInf(__c) || __spirv_IsInf(__d)) { - __c = __spirv_ocl_copysign(__spirv_IsInf(__c) ? 1.0f : 0.0f, __c); - __d = __spirv_ocl_copysign(__spirv_IsInf(__d) ? 1.0f : 0.0f, __d); - if (__spirv_IsNan(__a)) - __a = __spirv_ocl_copysign(0.0f, __a); - if (__spirv_IsNan(__b)) - __b = __spirv_ocl_copysign(0.0f, __b); - __recalc = 1; - } - if (!__recalc && (__spirv_IsInf(__ac) || __spirv_IsInf(__bd) || - __spirv_IsInf(__ad) || __spirv_IsInf(__bc))) { - if (__spirv_IsNan(__a)) - __a = __spirv_ocl_copysign(0.0f, __a); - if (__spirv_IsNan(__b)) - __b = __spirv_ocl_copysign(0.0f, __b); - if (__spirv_IsNan(__c)) - __c = __spirv_ocl_copysign(0.0f, __c); - if (__spirv_IsNan(__d)) - __d = __spirv_ocl_copysign(0.0f, __d); - __recalc = 1.0f; - } - if (__recalc) { - z = CMPLXF((INFINITY * (__a * __c - __b * __d)), - (INFINITY * (__a * __d + __b * __c))); - } - } - return z; -} - -// __divsc3 -// Returns: the quotient of (a + ib) / (c + id) -// FIXME: divsc3/divdc3 have overflow issue when dealing with large number. -// And this overflow issue is from libc++/compiler-rt's implementation. -static inline float __complex__ __devicelib___divsc3(float __a, float __b, - float __c, float __d) { - int __ilogbw = 0; - float __logbw = __spirv_ocl_logb( - __spirv_ocl_fmax(__spirv_ocl_fabs(__c), __spirv_ocl_fabs(__d))); - if (__spirv_IsFinite(__logbw)) { - __ilogbw = (int)__logbw; - __c = __spirv_ocl_ldexp(__c, -__ilogbw); - __d = __spirv_ocl_ldexp(__d, -__ilogbw); - } - float __denom = __c * __c + __d * __d; - float __complex__ z; - float z_real = - __spirv_ocl_ldexp((__a * __c + __b * __d) / __denom, -__ilogbw); - float z_imag = - __spirv_ocl_ldexp((__b * __c - __a * __d) / __denom, -__ilogbw); - z = CMPLXF(z_real, z_imag); - if (__spirv_IsNan(z_real) && __spirv_IsNan(z_imag)) { - if ((__denom == 0.0f) && (!__spirv_IsNan(__a) || !__spirv_IsNan(__b))) { - z_real = __spirv_ocl_copysign(INFINITY, __c) * __a; - z_imag = __spirv_ocl_copysign(INFINITY, __c) * __b; - z = CMPLXF(z_real, z_imag); - } else if ((__spirv_IsInf(__a) || __spirv_IsInf(__b)) && - __spirv_IsFinite(__c) && __spirv_IsFinite(__d)) { - __a = __spirv_ocl_copysign(__spirv_IsInf(__a) ? 1.0f : 0.0f, __a); - __b = __spirv_ocl_copysign(__spirv_IsInf(__b) ? 1.0f : 0.0f, __b); - z_real = INFINITY * (__a * __c + __b * __d); - z_imag = INFINITY * (__b * __c - __a * __d); - z = CMPLXF(z_real, z_imag); - } else if (__spirv_IsInf(__logbw) && __logbw > 0.0f && - __spirv_IsFinite(__a) && __spirv_IsFinite(__b)) { - __c = __spirv_ocl_copysign(__spirv_IsInf(__c) ? 1.0f : 0.0f, __c); - __d = __spirv_ocl_copysign(__spirv_IsInf(__d) ? 1.0f : 0.0f, __d); - z_real = 0.0f * (__a * __c + __b * __d); - z_imag = 0.0f * (__b * __c - __a * __d); - z = CMPLXF(z_real, z_imag); - } - } - return z; -} - static inline float __devicelib_cargf(float __complex__ z) { return __spirv_ocl_atan2(__devicelib_cimagf(z), __devicelib_crealf(z)); } @@ -162,9 +66,7 @@ static inline float __complex__ __devicelib_clogf(float __complex__ z) { static inline float __complex__ __devicelib_cpowf(float __complex__ x, float __complex__ y) { float __complex__ t = __devicelib_clogf(x); - float __complex__ w = - __devicelib___mulsc3(__devicelib_crealf(y), __devicelib_cimagf(y), - __devicelib_crealf(t), __devicelib_cimagf(t)); + float __complex__ w = y * t; return __devicelib_cexpf(w); } @@ -399,9 +301,7 @@ static inline float __complex__ __devicelib_catanhf(float __complex__ z) { __spirv_ocl_copysign(0.0f, z_imag)); float __complex__ t1 = 1.0f + z; float __complex__ t2 = 1.0f - z; - float __complex__ t3 = - __devicelib___divsc3(__devicelib_crealf(t1), __devicelib_cimagf(t1), - __devicelib_crealf(t2), __devicelib_cimagf(t2)); + float __complex__ t3 = t1 / t2; float __complex__ w = __devicelib_clogf(t3) / 2.0f; return CMPLXF(__spirv_ocl_copysign(__devicelib_crealf(w), z_real), __spirv_ocl_copysign(__devicelib_cimagf(w), z_imag)); diff --git a/sycl-jit/jit-compiler/CMakeLists.txt b/sycl-jit/jit-compiler/CMakeLists.txt index 4193e3c961a9c..9d3915a96726c 100644 --- a/sycl-jit/jit-compiler/CMakeLists.txt +++ b/sycl-jit/jit-compiler/CMakeLists.txt @@ -27,7 +27,8 @@ set(SYCL_JIT_RESOURCE_INSTALL_COMPONENTS sycl-headers OpenCL-Headers clang-resource-headers - libsycldevice) + libsycldevice + builtins-spirv64-unknown-unknown) set(libclc_enabled FALSE) foreach(target IN LISTS LLVM_RUNTIME_TARGETS) @@ -62,6 +63,9 @@ foreach(component IN LISTS SYCL_JIT_RESOURCE_INSTALL_COMPONENTS) sycl_jit_add_install_command("${component}" "${CMAKE_BINARY_DIR}/runtimes/runtimes-${tgt}-bins/libclc") endif() endforeach() + elseif("${component}" STREQUAL "builtins-spirv64-unknown-unknown") + list(APPEND SYCL_JIT_RESOURCE_DEPS builtins-spirv64-unknwon-unknown) + sycl_jit_add_install_command("clang_rt.builtins-spirv64" "${CMAKE_BINARY_DIR}/runtimes/builtins-spirv64-unknwon-unknown-bins/") else() list(APPEND SYCL_JIT_RESOURCE_DEPS ${component}) sycl_jit_add_install_command("${component}" "${CMAKE_BINARY_DIR}") diff --git a/sycl-jit/jit-compiler/lib/rtc/DeviceCompilation.cpp b/sycl-jit/jit-compiler/lib/rtc/DeviceCompilation.cpp index 7290917868a68..f78c4013fd245 100644 --- a/sycl-jit/jit-compiler/lib/rtc/DeviceCompilation.cpp +++ b/sycl-jit/jit-compiler/lib/rtc/DeviceCompilation.cpp @@ -179,6 +179,12 @@ std::string getLibPathSuffix() { DPCPP_VERSION_MAJOR); #endif } + +std::string getCompilerRTSuffix() { + return llvm::formatv("/{0}/clang/{1}/lib/", CLANG_INSTALL_LIBDIR_BASENAME, + CLANG_VERSION_MAJOR); +} + class SYCLToolchain { static auto &getToolchainFS() { // TODO: For some reason, removing `thread_local` results in data races @@ -799,7 +805,8 @@ static void getDeviceLibraries(const ArgList &Args, #if defined(_WIN32) "libsycl-msvc-math", #endif - "libsycl-imf"}; + "libsycl-imf", + "libclang_rt.builtins"}; StringRef LibSuffix = ".bc"; auto AddLibraries = [&](const SYCLDeviceLibsList &LibsList) { @@ -846,16 +853,25 @@ Error jit_compiler::linkDeviceLibraries(llvm::Module &Module, LibNames.push_back(Libclc); } - std::string TripleName = (Format == BinaryFormat::PTX) ? "nvptx64-nvidia-cuda" - : "amdgcn-amd-amdhsa"; - LLVMContext &Context = Module.getContext(); SYCLToolchain &TC = SYCLToolchain::instance(); + std::string TripleName; + if (Format == BinaryFormat::PTX) + TripleName = "nvptx64-nvidia-cuda"; + else if (Format == BinaryFormat::AMDGCN) + TripleName = "amdgcn-amd-amdhsa"; + else + TripleName = "spirv64-unknown-unknown"; for (const std::string &LibName : LibNames) { - std::string LibPath = - (LibName.find("libspirv") != std::string::npos) - ? (TC.getLibclcDir() + TripleName + "/" + LibName).str() - : (TC.getPrefix() + getLibPathSuffix() + LibName).str(); + std::string LibPath; + if (LibName.find("libspirv") != std::string::npos) + LibPath = (TC.getLibclcDir() + TripleName + "/" + LibName).str(); + else if (LibName == "libclang_rt.builtins.bc") + LibPath = + (TC.getPrefix() + getCompilerRTSuffix() + TripleName + "/" + LibName) + .str(); + else + LibPath = (TC.getPrefix() + getLibPathSuffix() + LibName).str(); ModuleUPtr LibModule; if (auto Error = diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txt index 5a2490d7ed554..598f70a05ef91 100644 --- a/sycl/CMakeLists.txt +++ b/sycl/CMakeLists.txt @@ -584,6 +584,13 @@ if("lld" IN_LIST LLVM_ENABLE_PROJECTS) list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS lld) endif() +if ("compiler-rt" IN_LIST RUNTIMES_spirv64-unknown-unknown_LLVM_ENABLE_RUNTIMES OR + ("compiler-rt" IN_LIST LLVM_ENABLE_RUNTIMES AND + "spirv64-unknown-unknown" IN_LIST LLVM_BUILTIN_TARGETS)) + add_dependencies(sycl-toolchain builtins-spirv64-unknown-unknown) + list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS builtins-spirv64-unknown-unknown) +endif() + set(libclc_enabled FALSE) foreach(target IN LISTS LLVM_RUNTIME_TARGETS) if("libclc" IN_LIST RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES) From d438064f19660c000b596bcd0398a164804a9dd3 Mon Sep 17 00:00:00 2001 From: jinge90 Date: Mon, 7 Sep 2026 13:42:45 +0800 Subject: [PATCH 2/7] fix typo Signed-off-by: jinge90 --- sycl-jit/jit-compiler/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl-jit/jit-compiler/CMakeLists.txt b/sycl-jit/jit-compiler/CMakeLists.txt index 9d3915a96726c..c2c233b6b798b 100644 --- a/sycl-jit/jit-compiler/CMakeLists.txt +++ b/sycl-jit/jit-compiler/CMakeLists.txt @@ -64,8 +64,8 @@ foreach(component IN LISTS SYCL_JIT_RESOURCE_INSTALL_COMPONENTS) endif() endforeach() elseif("${component}" STREQUAL "builtins-spirv64-unknown-unknown") - list(APPEND SYCL_JIT_RESOURCE_DEPS builtins-spirv64-unknwon-unknown) - sycl_jit_add_install_command("clang_rt.builtins-spirv64" "${CMAKE_BINARY_DIR}/runtimes/builtins-spirv64-unknwon-unknown-bins/") + list(APPEND SYCL_JIT_RESOURCE_DEPS builtins-spirv64-unknown-unknown) + sycl_jit_add_install_command("clang_rt.builtins-spirv64" "${CMAKE_BINARY_DIR}/runtimes/builtins-spirv64-unknown-unknown-bins/") else() list(APPEND SYCL_JIT_RESOURCE_DEPS ${component}) sycl_jit_add_install_command("${component}" "${CMAKE_BINARY_DIR}") From b5356ed1b27ee913ce16fa1c6db31632e38ea845 Mon Sep 17 00:00:00 2001 From: jinge90 Date: Mon, 7 Sep 2026 16:06:23 +0800 Subject: [PATCH 3/7] fix spirv64 triple Signed-off-by: jinge90 --- clang/lib/Driver/Driver.cpp | 2 +- clang/lib/Driver/ToolChains/SYCL.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 9b4f6cfb562f0..4044f6c0ccd37 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5964,7 +5964,7 @@ class OffloadingActionBuilder final { if (TC->getTriple().isSPIROrSPIRV()) { std::string CompilerRTPath = TC->getCompilerRTPath(); SmallString<128> SPIRVCompilerRTPath(CompilerRTPath); - llvm::sys::path::append(SPIRVCompilerRTPath, "spirv64-intel-unknown"); + llvm::sys::path::append(SPIRVCompilerRTPath, "spirv64-unknown-unknown"); if (llvm::sys::fs::exists(SPIRVCompilerRTPath)) LibLocCandidates.emplace_back(SPIRVCompilerRTPath); } diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp index d62ccb09391de..a57c55294dd98 100644 --- a/clang/lib/Driver/ToolChains/SYCL.cpp +++ b/clang/lib/Driver/ToolChains/SYCL.cpp @@ -2011,7 +2011,7 @@ SYCLToolChain::getDeviceLibs( if (getTriple().isSPIROrSPIRV()) { std::string CompilerRTPath = getCompilerRTPath(); SmallString<128> SPIRVCompilerRTPath(CompilerRTPath); - llvm::sys::path::append(SPIRVCompilerRTPath, "spirv64-intel-unknown"); + llvm::sys::path::append(SPIRVCompilerRTPath, "spirv64-unknown-unknown"); if (llvm::sys::fs::exists(SPIRVCompilerRTPath)) LibraryPaths.emplace_back(SPIRVCompilerRTPath); } From 2e173dec938ec636dd8f279c27c1ea1d07d7db42 Mon Sep 17 00:00:00 2001 From: jinge90 Date: Mon, 7 Sep 2026 16:13:38 +0800 Subject: [PATCH 4/7] fix clang-format Signed-off-by: jinge90 --- buildbot/configure.py | 1 - 1 file changed, 1 deletion(-) diff --git a/buildbot/configure.py b/buildbot/configure.py index 5b2a7bf233d26..4e79c21c68042 100644 --- a/buildbot/configure.py +++ b/buildbot/configure.py @@ -208,7 +208,6 @@ def do_configure(args, passthrough_args): "-DRUNTIMES_spirv64-unknown-unknown_LLVM_ENABLE_RUNTIMES={}".format( llvm_spirv64_runtimes ), - "-DRUNTIMES_spirv64-unknown-unknown_COMPILER_RT_SANITIZERS_TO_BUILD={}".format( llvm_spirv64_sanitizers ), From e3430cbb3f31536e91303e65abf6e7270bb633bc Mon Sep 17 00:00:00 2001 From: jinge90 Date: Tue, 8 Sep 2026 11:12:32 +0800 Subject: [PATCH 5/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- buildbot/configure.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/buildbot/configure.py b/buildbot/configure.py index 4e79c21c68042..42d25c2bb7526 100644 --- a/buildbot/configure.py +++ b/buildbot/configure.py @@ -200,19 +200,20 @@ def do_configure(args, passthrough_args): "-DBUG_REPORT_URL=https://github.com/intel/llvm/issues", ] - llvm_spirv64_runtimes = "compiler-rt" - llvm_spirv64_sanitizers = "" - runtime_targets += ";spirv64-unknown-unknown" - cmake_cmd.extend( - [ - "-DRUNTIMES_spirv64-unknown-unknown_LLVM_ENABLE_RUNTIMES={}".format( - llvm_spirv64_runtimes - ), - "-DRUNTIMES_spirv64-unknown-unknown_COMPILER_RT_SANITIZERS_TO_BUILD={}".format( - llvm_spirv64_sanitizers - ), - ] - ) + if sys.platform != "darwin": + llvm_spirv64_runtimes = "compiler-rt" + llvm_spirv64_sanitizers = "" + runtime_targets += ";spirv64-unknown-unknown" + cmake_cmd.extend( + [ + "-DRUNTIMES_spirv64-unknown-unknown_LLVM_ENABLE_RUNTIMES={}".format( + llvm_spirv64_runtimes + ), + "-DRUNTIMES_spirv64-unknown-unknown_COMPILER_RT_SANITIZERS_TO_BUILD={}".format( + llvm_spirv64_sanitizers + ), + ] + ) if llvm_enable_runtimes: cmake_cmd.extend( From 985878f9c4622509e4458c25d2ba424029a44e1a Mon Sep 17 00:00:00 2001 From: jinge90 Date: Tue, 8 Sep 2026 13:42:52 +0800 Subject: [PATCH 6/7] remove code duplicate in driver Signed-off-by: jinge90 --- clang/lib/Driver/Driver.cpp | 8 +------- clang/lib/Driver/ToolChains/SYCL.cpp | 18 +++++++++++------- clang/lib/Driver/ToolChains/SYCL.h | 6 ++++++ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 4044f6c0ccd37..69e17b0af9703 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5961,13 +5961,7 @@ class OffloadingActionBuilder final { int NumOfDeviceLibLinked = 0; SmallVector, 4> LibLocCandidates; SYCLInstallation.getSYCLDeviceLibPath(LibLocCandidates); - if (TC->getTriple().isSPIROrSPIRV()) { - std::string CompilerRTPath = TC->getCompilerRTPath(); - SmallString<128> SPIRVCompilerRTPath(CompilerRTPath); - llvm::sys::path::append(SPIRVCompilerRTPath, "spirv64-unknown-unknown"); - if (llvm::sys::fs::exists(SPIRVCompilerRTPath)) - LibLocCandidates.emplace_back(SPIRVCompilerRTPath); - } + tools::SYCL::addSPIRVCompilerRTPath(*TC, LibLocCandidates); const toolchains::SYCLToolChain &SYCLTC = static_cast(*TC); diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp index a57c55294dd98..eeb6c095dbfe3 100644 --- a/clang/lib/Driver/ToolChains/SYCL.cpp +++ b/clang/lib/Driver/ToolChains/SYCL.cpp @@ -306,6 +306,16 @@ bool SYCL::shouldDoPerObjectFileLinking(const Compilation &C) { /*default=*/true); } +void SYCL::addSPIRVCompilerRTPath( + const ToolChain &TC, SmallVectorImpl> &LibraryPaths) { + if (!TC.getTriple().isSPIROrSPIRV()) + return; + SmallString<128> SPIRVCompilerRTPath(TC.getCompilerRTPath()); + llvm::sys::path::append(SPIRVCompilerRTPath, "spirv64-unknown-unknown"); + if (llvm::sys::fs::exists(SPIRVCompilerRTPath)) + LibraryPaths.emplace_back(SPIRVCompilerRTPath); +} + // Return whether to use native bfloat16 library. static bool selectBfloatLibs(const llvm::opt::ArgList &Args, const llvm::Triple &Triple, const ToolChain &TC, @@ -2008,13 +2018,7 @@ SYCLToolChain::getDeviceLibs( SmallVector, 4> LibraryPaths; SYCLInstallation.getSYCLDeviceLibPath(LibraryPaths); - if (getTriple().isSPIROrSPIRV()) { - std::string CompilerRTPath = getCompilerRTPath(); - SmallString<128> SPIRVCompilerRTPath(CompilerRTPath); - llvm::sys::path::append(SPIRVCompilerRTPath, "spirv64-unknown-unknown"); - if (llvm::sys::fs::exists(SPIRVCompilerRTPath)) - LibraryPaths.emplace_back(SPIRVCompilerRTPath); - } + SYCL::addSPIRVCompilerRTPath(*this, LibraryPaths); // Formulate all of the device libraries needed for this compilation. SmallVector DeviceLibs = getDeviceLibNames(getDriver(), DriverArgs, getTriple()); diff --git a/clang/lib/Driver/ToolChains/SYCL.h b/clang/lib/Driver/ToolChains/SYCL.h index 7b38ba8c61e6f..604fe5f9062bc 100644 --- a/clang/lib/Driver/ToolChains/SYCL.h +++ b/clang/lib/Driver/ToolChains/SYCL.h @@ -39,6 +39,12 @@ void populateSYCLDeviceTraitsMacrosArgs( const SmallVectorImpl> &Targets); bool shouldDoPerObjectFileLinking(const Compilation &C); + +// If TC targets SPIR/SPIR-V, appends the spirv64 compiler-rt directory +// (where libclang_rt.builtins.bc is installed) to LibraryPaths. +void addSPIRVCompilerRTPath(const ToolChain &TC, + SmallVectorImpl> &LibraryPaths); + // Runs llvm-spirv to convert spirv to bc, llvm-link, which links multiple LLVM // bitcode. Converts generated bc back to spirv using llvm-spirv, wraps with // offloading information. Finally compiles to object using llc From 0307271ed6e7e3cc5e7abda65d952058df468f87 Mon Sep 17 00:00:00 2001 From: jinge90 Date: Tue, 8 Sep 2026 14:01:09 +0800 Subject: [PATCH 7/7] address AI review comments Signed-off-by: jinge90 --- sycl-jit/jit-compiler/CMakeLists.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sycl-jit/jit-compiler/CMakeLists.txt b/sycl-jit/jit-compiler/CMakeLists.txt index c2c233b6b798b..bc559263baa54 100644 --- a/sycl-jit/jit-compiler/CMakeLists.txt +++ b/sycl-jit/jit-compiler/CMakeLists.txt @@ -27,8 +27,13 @@ set(SYCL_JIT_RESOURCE_INSTALL_COMPONENTS sycl-headers OpenCL-Headers clang-resource-headers - libsycldevice - builtins-spirv64-unknown-unknown) + libsycldevice) + +if ("compiler-rt" IN_LIST RUNTIMES_spirv64-unknown-unknown_LLVM_ENABLE_RUNTIMES OR + ("compiler-rt" IN_LIST LLVM_ENABLE_RUNTIMES AND + "spirv64-unknown-unknown" IN_LIST LLVM_BUILTIN_TARGETS)) + list(APPEND SYCL_JIT_RESOURCE_INSTALL_COMPONENTS builtins-spirv64-unknown-unknown) +endif() set(libclc_enabled FALSE) foreach(target IN LISTS LLVM_RUNTIME_TARGETS)