[clang] 2bd77c8 - [SYCL][Driver] Pass path to libsycl.so by default for SYCL compilation. (#174877)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 13 17:15:06 PST 2026
Author: Srividya Sundaram
Date: 2026-02-13T19:15:01-06:00
New Revision: 2bd77c83596a5336608ba7a07810a57686222a23
URL: https://github.com/llvm/llvm-project/commit/2bd77c83596a5336608ba7a07810a57686222a23
DIFF: https://github.com/llvm/llvm-project/commit/2bd77c83596a5336608ba7a07810a57686222a23.diff
LOG: [SYCL][Driver] Pass path to libsycl.so by default for SYCL compilation. (#174877)
This patch updates the default behavior for `SYCL` offload compilations.
Specifically, we now pass the path to the SYCL runtime library,
`libsycl.so`, by default to the `clang-linker-wrapper` tool, which is
responsible for linking the `SYCL` runtime library. We also add the SYCL
header include paths by default to both the SYCL host and device
compilations.
Added:
Modified:
clang/include/clang/Driver/SyclInstallationDetector.h
clang/lib/Driver/ToolChains/Linux.cpp
clang/lib/Driver/ToolChains/SYCL.cpp
clang/test/Driver/sycl-offload-jit.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/SyclInstallationDetector.h b/clang/include/clang/Driver/SyclInstallationDetector.h
index 6925ec24bcd29..f92228817f045 100644
--- a/clang/include/clang/Driver/SyclInstallationDetector.h
+++ b/clang/include/clang/Driver/SyclInstallationDetector.h
@@ -21,6 +21,14 @@ class SYCLInstallationDetector {
void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;
+
+ // Return the filesystem path to the SYCL runtime library (libsycl.so), that
+ // was detected.
+ StringRef getSYCLRTLibPath() const { return SYCLRTLibPath; }
+
+private:
+ const Driver &D;
+ SmallString<0> SYCLRTLibPath;
};
} // namespace driver
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index fb3f531e77ace..a5277dcac1747 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -863,6 +863,8 @@ void Linux::addOffloadRTLibs(unsigned ActiveKinds, const ArgList &Args,
llvm::SmallVector<std::pair<StringRef, StringRef>> Libraries;
if (ActiveKinds & Action::OFK_HIP)
Libraries.emplace_back(RocmInstallation->getLibPath(), "libamdhip64.so");
+ else if (ActiveKinds & Action::OFK_SYCL)
+ Libraries.emplace_back(SYCLInstallation->getSYCLRTLibPath(), "libsycl.so");
for (auto [Path, Library] : Libraries) {
if (Args.hasFlag(options::OPT_frtlib_add_rpath,
diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp
index 85859f344b491..033fd98183737 100644
--- a/clang/lib/Driver/ToolChains/SYCL.cpp
+++ b/clang/lib/Driver/ToolChains/SYCL.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "SYCL.h"
#include "clang/Driver/CommonArgs.h"
+#include "llvm/Support/VirtualFileSystem.h"
using namespace clang::driver;
using namespace clang::driver::toolchains;
@@ -16,16 +17,32 @@ using namespace llvm::opt;
SYCLInstallationDetector::SYCLInstallationDetector(
const Driver &D, const llvm::Triple &HostTriple,
- const llvm::opt::ArgList &Args) {}
+ const llvm::opt::ArgList &Args)
+ : D(D) {
+ // Detect the presence of the SYCL runtime library (libsycl.so) in the
+ // filesystem. This is used to determine whether a usable SYCL installation
+ // is available for the current driver invocation.
+ StringRef SysRoot = D.SysRoot;
+ SmallString<128> DriverDir(D.Dir);
+ if (DriverDir.starts_with(SysRoot) &&
+ (Args.hasArg(options::OPT_fsycl) ||
+ D.getVFS().exists(DriverDir + "/../lib/libsycl.so"))) {
+ llvm::sys::path::append(DriverDir, "..", "lib");
+ SYCLRTLibPath = DriverDir;
+ }
+}
void SYCLInstallationDetector::addSYCLIncludeArgs(
const ArgList &DriverArgs, ArgStringList &CC1Args) const {
if (DriverArgs.hasArg(options::OPT_nobuiltininc))
return;
- // Add the SYCL header search locations in the specified order.
- // FIXME: Add the header file locations once the SYCL library and headers
- // are properly established within the build.
+ // Add the SYCL header search locations.
+ // These are included for both SYCL host and device compilations.
+ SmallString<128> IncludePath(D.Dir);
+ llvm::sys::path::append(IncludePath, "..", "include");
+ CC1Args.push_back("-internal-isystem");
+ CC1Args.push_back(DriverArgs.MakeArgString(IncludePath));
}
// Unsupported options for SYCL device compilation.
diff --git a/clang/test/Driver/sycl-offload-jit.cpp b/clang/test/Driver/sycl-offload-jit.cpp
index 72c2390a3fe4b..5bdb56d935a98 100644
--- a/clang/test/Driver/sycl-offload-jit.cpp
+++ b/clang/test/Driver/sycl-offload-jit.cpp
@@ -29,6 +29,14 @@
// CHK-DEVICE-TRIPLE-SAME: "-O2"
// CHK-DEVICE-TRIPLE: llvm-offload-binary{{.*}} "--image=file={{.*}}.bc,triple=spirv64-unknown-unknown,arch=generic,kind=sycl"
+// Check if path to libsycl.so is passed to clang-linker-wrapper tool by default for SYCL compilation.
+// The test also checks if SYCL header include paths are added to the SYCL host and device compilation.
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl %s 2>&1 \
+// RUN: | FileCheck -check-prefixes=CHECK-LSYCL,CHECK-SYCL-HEADERS-HOST,CHECK-SYCL-HEADERS-DEVICE %s
+// CHECK-SYCL-HEADERS-DEVICE: "-fsycl-is-device"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include"
+// CHECK-SYCL-HEADERS-HOST: "-fsycl-is-host"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include"
+// CHECK-LSYCL: clang-linker-wrapper{{.*}} "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}libsycl.so"
+
/// Check -fsycl-is-device is passed when compiling for the device.
/// Check -fsycl-is-host is passed when compiling for host.
// RUN: %clang -### -fsycl -c %s 2>&1 \
More information about the cfe-commits
mailing list