Skip to content

Commit bf21b9d

Browse files
authored
[SYCL][Driver] Base libspirv path on sycl install candidates (#19134)
<!-- start git-machete generated --> # Based on PR #19131 ## Chain of upstream PRs & tree of downstream PRs as of 2025-06-25 * PR #19130 * PR #19131 * **PR #19134 (THIS ONE)** * PR #19135 * PR #19136 <!-- end git-machete generated --> ... instead of the resource directory. This matches the behaviour of SYCL device libraries. The resource directory has nothing to do with libspirv, and it might be changed by the `-resource-dir` option, which would lead us to not find it.
1 parent 6af08fe commit bf21b9d

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,9 @@ const char *SYCLInstallationDetector::findLibspirvPath(
182182
const SmallString<64> Basename =
183183
getLibSpirvBasename(DeviceTriple, HostTriple);
184184
auto searchAt = [&](StringRef Path, const Twine &a = "", const Twine &b = "",
185-
const Twine &c = "", const Twine &d = "",
186-
const Twine &e = "") -> const char * {
185+
const Twine &c = "") -> const char * {
187186
SmallString<128> LibraryPath(Path);
188-
llvm::sys::path::append(LibraryPath, a, b, c, d);
189-
llvm::sys::path::append(LibraryPath, e, Basename);
187+
llvm::sys::path::append(LibraryPath, a, b, c, Basename);
190188

191189
if (Args.hasArgNoClaim(options::OPT__HASH_HASH_HASH) ||
192190
llvm::sys::fs::exists(LibraryPath))
@@ -195,14 +193,15 @@ const char *SYCLInstallationDetector::findLibspirvPath(
195193
return nullptr;
196194
};
197195

198-
// Otherwise, assume libclc is installed at the same prefix as clang
199-
// Expected path w/out install.
200-
if (const char *R = searchAt(D.ResourceDir, "..", "..", "clc"))
201-
return R;
196+
for (const auto &IC : InstallationCandidates) {
197+
// Expected path w/out install.
198+
if (const char *R = searchAt(IC, "lib", "clc"))
199+
return R;
202200

203-
// Expected path w/ install.
204-
if (const char *R = searchAt(D.ResourceDir, "..", "..", "..", "share", "clc"))
205-
return R;
201+
// Expected path w/ install.
202+
if (const char *R = searchAt(IC, "share", "clc"))
203+
return R;
204+
}
206205

207206
return nullptr;
208207
}

clang/test/Driver/Inputs/SYCL/bin/.gitkeep

Whitespace-only changes.

clang/test/Driver/sycl-libspirv-toolchain.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// RUN: | FileCheck %s --check-prefixes=CHECK-LINUX
1616
// CHECK-LINUX: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}remangled-l64-signed_char.libspirv-nvptx64-nvidia-cuda.bc"
1717
//
18-
// RUN: %clang -### -resource-dir %{resource_dir} -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 -nogpulib -target x86_64-unknown-windows-msvc %s 2>&1 \
18+
// RUN: %clang -### -ccc-install-dir %{install_dir} -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 -nogpulib -target x86_64-unknown-windows-msvc %s 2>&1 \
1919
// RUN: | FileCheck %s --check-prefixes=CHECK-AMDGCN-WINDOWS
2020
// CHECK-AMDGCN-WINDOWS: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}remangled-l32-signed_char.libspirv-amdgcn-amd-amdhsa.bc"
2121
//
@@ -30,22 +30,22 @@
3030
// CHECK-CUDA: "-cc1"{{.*}} "-fcuda-is-device"
3131
// CHECK-CUDA-NOT: "-mlink-builtin-bitcode" "{{.*}}.libspirv-{{.*}}.bc"
3232
//
33-
// The path to the remangled libspirv bitcode file is determined by the resource directory.
33+
// The path to the remangled libspirv bitcode file is determined by the installation directory
3434
// RUN: %clang -### -ccc-install-dir %{install_dir} -resource-dir %{resource_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
3535
// RUN: | FileCheck %s -DINSTALL_DIR=%{install_dir} -DRESOURCE_DIR=%{resource_dir} --check-prefixes=CHECK-DIR
36-
// CHECK-DIR: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "[[RESOURCE_DIR]]{{.*[\\/]}}remangled-{{.*}}.libspirv-nvptx64-nvidia-cuda.bc"
36+
// CHECK-DIR: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "[[INSTALL_DIR]]{{.*[\\/]}}remangled-{{.*}}.libspirv-nvptx64-nvidia-cuda.bc"
3737
//
3838
// The `-###` option disables file existence checks
3939
// DEFINE: %{nonexistent_dir} = %/S/Inputs/SYCL/does_not_exist/lib/clang/resource_dir
40-
// RUN: %clang -### -resource-dir %{nonexistent_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
41-
// RUN: | FileCheck %s -DDIR=%{nonexistent_dir} --check-prefixes=CHECK-HHH-NONEXISTENT
40+
// RUN: %clang -### -ccc-install-dir %{nonexistent_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
41+
// RUN: | FileCheck %s -DDIR=%{nonexistent_dir} --check-prefixes=CHECK-HHH-NONEXISTENT
4242
// CHECK-HHH-NONEXISTENT: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "[[DIR]]{{.*[\\/]}}remangled-{{.*}}.libspirv-nvptx64-nvidia-cuda.bc"
4343
//
44-
// RUN: %clang -### -resource-dir %{nonexistent_dir} -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 -nogpulib %s 2>&1 \
45-
// RUN: | FileCheck %s -DDIR=%{nonexistent_dir} --check-prefixes=CHECK-AMDGCN-HHH-NONEXISTENT
44+
// RUN: %clang -### -ccc-install-dir %{nonexistent_dir} -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 -nogpulib %s 2>&1 \
45+
// RUN: | FileCheck %s -DDIR=%{nonexistent_dir} --check-prefixes=CHECK-AMDGCN-HHH-NONEXISTENT
4646
// CHECK-AMDGCN-HHH-NONEXISTENT: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "[[DIR]]{{.*[\\/]}}remangled-{{.*}}.libspirv-amdgcn-amd-amdhsa.bc"
4747
//
4848
// `-fdriver-only` has no such special handling, so it will not find the file
49-
// RUN: not %clang -fdriver-only -resource-dir %{nonexistent_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
50-
// RUN: | FileCheck %s --check-prefixes=CHECK-DO-NONEXISTENT
49+
// RUN: not %clang -fdriver-only -ccc-install-dir %{nonexistent_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
50+
// RUN: | FileCheck %s -DDIR=%{nonexistent_dir} --check-prefixes=CHECK-DO-NONEXISTENT
5151
// CHECK-DO-NONEXISTENT: error: cannot find 'remangled-{{.*}}.libspirv-nvptx64-nvidia-cuda.bc'; provide path to libspirv library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build without linking with libspirv

0 commit comments

Comments
 (0)