Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 21 additions & 6 deletions buildbot/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ def do_configure(args, passthrough_args):
"-DBUG_REPORT_URL=https://github.com/intel/llvm/issues",
]

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(
[
Expand All @@ -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(
[
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5961,6 +5961,7 @@ class OffloadingActionBuilder final {
int NumOfDeviceLibLinked = 0;
SmallVector<SmallString<128>, 4> LibLocCandidates;
SYCLInstallation.getSYCLDeviceLibPath(LibLocCandidates);
tools::SYCL::addSPIRVCompilerRTPath(*TC, LibLocCandidates);

const toolchains::SYCLToolChain &SYCLTC =
static_cast<const toolchains::SYCLToolChain &>(*TC);
Expand Down
16 changes: 15 additions & 1 deletion clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,16 @@ bool SYCL::shouldDoPerObjectFileLinking(const Compilation &C) {
/*default=*/true);
}

void SYCL::addSPIRVCompilerRTPath(
const ToolChain &TC, SmallVectorImpl<SmallString<128>> &LibraryPaths) {
if (!TC.getTriple().isSPIROrSPIRV())
return;
SmallString<128> SPIRVCompilerRTPath(TC.getCompilerRTPath());
llvm::sys::path::append(SPIRVCompilerRTPath, "spirv64-unknown-unknown");
Comment on lines +311 to +314

@jinge90 jinge90 Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, all device libraries only provide spir64 versions, we don't support 32-bit.

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,
Expand Down Expand Up @@ -668,7 +678,8 @@ SYCLToolChain::getDeviceLibNames(const Driver &D,
#if defined(_WIN32)
"libsycl-msvc-math",
#endif
"libsycl-imf"};
"libsycl-imf",
"libclang_rt.builtins"};
Comment on lines +681 to +682
auto addLibraries = [&](const SYCLDeviceLibsList &LibsList) {
for (const StringRef &Lib : LibsList)
addLibToList(Args.MakeArgString(Lib + ".bc"));
Expand Down Expand Up @@ -884,6 +895,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 @@ -2005,6 +2018,7 @@ SYCLToolChain::getDeviceLibs(
SmallVector<SmallString<128>, 4> LibraryPaths;
SYCLInstallation.getSYCLDeviceLibPath(LibraryPaths);

SYCL::addSPIRVCompilerRTPath(*this, LibraryPaths);
// Formulate all of the device libraries needed for this compilation.
SmallVector<BitCodeLibraryInfo, 8> DeviceLibs =
getDeviceLibNames(getDriver(), DriverArgs, getTriple());
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Driver/ToolChains/SYCL.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ void populateSYCLDeviceTraitsMacrosArgs(
const SmallVectorImpl<std::pair<const ToolChain *, StringRef>> &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<SmallString<128>> &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
Expand Down
30 changes: 15 additions & 15 deletions clang/test/Driver/sycl-no-rdc-fat-archive-old-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
30 changes: 15 additions & 15 deletions clang/test/Driver/sycl-no-rdc-fat-archive-win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
32 changes: 16 additions & 16 deletions clang/test/Driver/sycl-no-rdc-old-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
33 changes: 16 additions & 17 deletions clang/test/Driver/sycl-no-rdc-win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{{.*}}
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/cmake/builtin-config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions compiler-rt/lib/builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")
Expand Down
5 changes: 4 additions & 1 deletion libdevice/cmake/modules/SYCLLibdevice.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,13 @@ add_devicelibs(libsycl-crt
DEPENDENCIES ${crt_obj_deps}
EXTRA_OPTS $<$<BOOL:${HAS_NO_INVALID_NORETURN_WARN_FLAG}>:-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
Expand Down
27 changes: 0 additions & 27 deletions libdevice/complex_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }

Expand Down Expand Up @@ -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__
Loading
Loading