[clang] [compiler-rt] [Driver][SYCL] Add compile-time device library linking for SPIR-V targets (PR #196656)
Alexey Bader via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 27 13:54:52 PDT 2026
================
@@ -200,3 +209,26 @@ void SYCLToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &Args,
ArgStringList &CC1Args) const {
HostTC.AddClangCXXStdlibIncludeArgs(Args, CC1Args);
}
+
+llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12>
+SYCLToolChain::getDeviceLibs(
+ const llvm::opt::ArgList &DriverArgs, BoundArch /*BA*/,
+ const Action::OffloadKind /*DeviceOffloadingKind*/) const {
+ if (!getTriple().isSPIROrSPIRV())
+ return {};
+ if (!DriverArgs.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib,
+ true))
+ return {};
+ // -nolibsycl suppresses all SYCL library injection including device libs.
----------------
bader wrote:
I'm not sure if we should do that.
`libclang_rt.builtins.bc` provides functionality specific to SPIR-V target (in the current context), which is useful for other GPU offloading programming models (e.g. OpenMP offload). I suggest we don't disable compiler-rt for `-nolibsycl` flag.
I think it's worth considering a new function in `clang\lib\Driver\ToolChains\CommonArgs.cpp` similar to `tools::addOpenMPDeviceRTL` and `tools::addOpenCLBuiltinsLib` which can be invoked from here and other toolchains targeting SPIR-V.
A couple of other issues with this check:
- this code is not tested
- the error message for missing device library mentions only `--no-offloadlib` flag as a mean to disable the linking with `libclang_rt.builtins.bc`.
https://github.com/llvm/llvm-project/pull/196656
More information about the cfe-commits
mailing list