https://github.com/srividya-sundaram updated https://github.com/llvm/llvm-project/pull/174877
>From bcaab110a073894c44ab47889aa4fe41b95dde42 Mon Sep 17 00:00:00 2001 From: srividya sundaram <[email protected]> Date: Wed, 7 Jan 2026 14:42:11 -0800 Subject: [PATCH 1/5] [SYCL][Driver] Pass -lsycl by default for SYCL compilation. --- clang/include/clang/Options/Options.td | 4 ++++ clang/lib/Driver/ToolChains/Gnu.cpp | 7 +++++++ clang/test/Driver/sycl-offload-jit.cpp | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index f336542992993..aa3cd218fc199 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -7276,6 +7276,10 @@ def fsycl : Flag<["-"], "fsycl">, HelpText<"Enable SYCL C++ extensions">; def fno_sycl : Flag<["-"], "fno-sycl">, HelpText<"Disable SYCL C++ extensions">; +def nolibsycl : Flag<["-"], "nolibsycl">, + Flags<[NoXarchOption]>, + Visibility<[ClangOption, CLOption, ]>, + HelpText<"Do not link SYCL runtime library">; def fsycl_device_only : Flag<["-"], "fsycl-device-only">, Alias<offload_device_only>, HelpText<"Compile SYCL code for device only">; def fsycl_host_only : Flag<["-"], "fsycl-host-only">, diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 7ecdbe7c57650..943a3250e94f0 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -514,6 +514,13 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, AddRunTimeLibs(ToolChain, D, CmdArgs, Args); + // For SYCL compilations, pass the linker option '-lsycl' by default to + // the clang-linker-wrapper tool which links the SYCL runtime library. + if (Args.hasArg(options::OPT_fsycl) && + !Args.hasArg(options::OPT_nolibsycl)) { + CmdArgs.push_back("-lsycl"); + } + // LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so // forcibly link with libatomic as a workaround. // TODO: Issue #41880 and D118021. diff --git a/clang/test/Driver/sycl-offload-jit.cpp b/clang/test/Driver/sycl-offload-jit.cpp index 72c2390a3fe4b..7f8fe64866882 100644 --- a/clang/test/Driver/sycl-offload-jit.cpp +++ b/clang/test/Driver/sycl-offload-jit.cpp @@ -29,6 +29,11 @@ // CHK-DEVICE-TRIPLE-SAME: "-O2" // CHK-DEVICE-TRIPLE: llvm-offload-binary{{.*}} "--image=file={{.*}}.bc,triple=spirv64-unknown-unknown,arch=generic,kind=sycl" +// Check if -lsycl is passed to clang-linker-wrapper tool by default for SYCL compilation. +// RUN: %clang -### -fsycl %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-LSYCL %s +// CHECK-LSYCL: clang-linker-wrapper{{.*}} "-L/lib"{{.*}} "-lsycl" + /// 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 \ >From e1c86868c00dca67957abefcfec500e997b0ce38 Mon Sep 17 00:00:00 2001 From: srividya sundaram <[email protected]> Date: Wed, 7 Jan 2026 14:57:11 -0800 Subject: [PATCH 2/5] Remove extra colon. --- clang/include/clang/Options/Options.td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index aa3cd218fc199..188e34b513e25 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -7278,7 +7278,7 @@ def fno_sycl : Flag<["-"], "fno-sycl">, HelpText<"Disable SYCL C++ extensions">; def nolibsycl : Flag<["-"], "nolibsycl">, Flags<[NoXarchOption]>, - Visibility<[ClangOption, CLOption, ]>, + Visibility<[ClangOption, CLOption]>, HelpText<"Do not link SYCL runtime library">; def fsycl_device_only : Flag<["-"], "fsycl-device-only">, Alias<offload_device_only>, HelpText<"Compile SYCL code for device only">; >From e74bbcdcbf5e671bca0d4852be8d47141d12cd26 Mon Sep 17 00:00:00 2001 From: srividya sundaram <[email protected]> Date: Thu, 8 Jan 2026 14:55:17 -0800 Subject: [PATCH 3/5] Remove redundant visibility code. --- clang/include/clang/Options/Options.td | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index 188e34b513e25..2c9c7ce36e15b 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -7278,7 +7278,6 @@ def fno_sycl : Flag<["-"], "fno-sycl">, HelpText<"Disable SYCL C++ extensions">; def nolibsycl : Flag<["-"], "nolibsycl">, Flags<[NoXarchOption]>, - Visibility<[ClangOption, CLOption]>, HelpText<"Do not link SYCL runtime library">; def fsycl_device_only : Flag<["-"], "fsycl-device-only">, Alias<offload_device_only>, HelpText<"Compile SYCL code for device only">; >From a5ca0dd55ee27ba1ac14faa8683dd1103743b527 Mon Sep 17 00:00:00 2001 From: srividya sundaram <[email protected]> Date: Fri, 9 Jan 2026 16:38:13 -0800 Subject: [PATCH 4/5] Add -L/path/to/sycl/lib along with -lsycl for SYCL offload. --- clang/lib/Driver/ToolChains/Linux.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index cdbf21fb90263..226c609ab8dcf 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -357,6 +357,15 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) Generic_GCC::AddMultiarchPaths(D, SysRoot, OSLibDir, Paths); + // Add -L/path/to/sycl/lib when -fsycl is specified or when libsycl.so is + // available. The -lsycl option is added implicitly by -fsycl and links + // against the SYCL runtime library (libsycl.so), which is located in this + // directory. + if (StringRef(D.Dir).starts_with(SysRoot) && + (Args.hasArg(options::OPT_fsycl) || + D.getVFS().exists(D.Dir + "/../lib/libsycl.so"))) + addPathIfExists(D, D.Dir + "/../lib", Paths); + addPathIfExists(D, concat(SysRoot, "/lib"), Paths); addPathIfExists(D, concat(SysRoot, "/usr/lib"), Paths); } >From 9e87341d6eecb4662daa6b5abad4c05790f5b31e Mon Sep 17 00:00:00 2001 From: srividya sundaram <[email protected]> Date: Mon, 12 Jan 2026 11:43:03 -0800 Subject: [PATCH 5/5] Include SYCL header search locations by default for SYCL compilation. --- .../clang/Driver/SyclInstallationDetector.h | 5 +++++ clang/lib/Driver/ToolChains/SYCL.cpp | 19 +++++++++++++++---- clang/test/Driver/sycl-offload-jit.cpp | 6 ++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/Driver/SyclInstallationDetector.h b/clang/include/clang/Driver/SyclInstallationDetector.h index 6925ec24bcd29..e2526bb4b3517 100644 --- a/clang/include/clang/Driver/SyclInstallationDetector.h +++ b/clang/include/clang/Driver/SyclInstallationDetector.h @@ -16,11 +16,16 @@ namespace driver { class SYCLInstallationDetector { public: + SYCLInstallationDetector(const Driver &D); SYCLInstallationDetector(const Driver &D, const llvm::Triple &HostTriple, const llvm::opt::ArgList &Args); void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const; + +private: + const Driver &D; + llvm::SmallVector<llvm::SmallString<128>, 4> InstallationCandidates; }; } // namespace driver diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp index 85859f344b491..fa73f808cb090 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; @@ -14,18 +15,28 @@ using namespace clang::driver::tools; using namespace clang; using namespace llvm::opt; +SYCLInstallationDetector::SYCLInstallationDetector(const Driver &D) + : D(D), InstallationCandidates() { + InstallationCandidates.emplace_back(D.Dir + "/.."); +} + SYCLInstallationDetector::SYCLInstallationDetector( const Driver &D, const llvm::Triple &HostTriple, - const llvm::opt::ArgList &Args) {} + const llvm::opt::ArgList &Args) + : SYCLInstallationDetector(D) {} 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 icluded for both SYCL host and device compilations. + SmallString<128> IncludePath(D.Dir); + llvm::sys::path::append(IncludePath, ".."); + 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 7f8fe64866882..dca4297ee3c34 100644 --- a/clang/test/Driver/sycl-offload-jit.cpp +++ b/clang/test/Driver/sycl-offload-jit.cpp @@ -31,8 +31,10 @@ // Check if -lsycl is passed to clang-linker-wrapper tool by default for SYCL compilation. // RUN: %clang -### -fsycl %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-LSYCL %s -// CHECK-LSYCL: clang-linker-wrapper{{.*}} "-L/lib"{{.*}} "-lsycl" +// RUN: | FileCheck -check-prefixes=CHECK-LSYCL,CHECK-SYCL-HEADERS-HOST,CHECK-SYCL-HEADERS-DEVICE %s +// CHECK-SYCL-HEADERS-DEVICE: "-fsycl-is-device"{{.*}} "-internal-isystem" "{{.*}}build/bin/../include" +// CHECK-SYCL-HEADERS-HOST: "-fsycl-is-host"{{.*}} "-internal-isystem" "{{.*}}build/bin/../include" +// CHECK-LSYCL: clang-linker-wrapper{{.*}} "-L{{.*}}build/bin/../lib"{{.*}} "-lsycl" /// Check -fsycl-is-device is passed when compiling for the device. /// Check -fsycl-is-host is passed when compiling for host. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
