Skip to content

Commit 63704bf

Browse files
committed
[SYCL][Driver] Base libspirv path on sycl install candidates
... 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 f08825e commit 63704bf

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
@@ -177,11 +177,9 @@ const char *SYCLInstallationDetector::findLibspirvPath(
177177

178178
const SmallString<64> Basename = getLibSpirvBasename(DeviceTriple, HostTriple);
179179
auto searchAt = [&](StringRef Path, const Twine &a = "", const Twine &b = "",
180-
const Twine &c = "", const Twine &d = "",
181-
const Twine &e = "") -> const char * {
180+
const Twine &c = "") -> const char * {
182181
SmallString<128> LibraryPath(Path);
183-
llvm::sys::path::append(LibraryPath, a, b, c, d);
184-
llvm::sys::path::append(LibraryPath, e, Basename);
182+
llvm::sys::path::append(LibraryPath, a, b, c, Basename);
185183

186184
if (Args.hasArgNoClaim(options::OPT__HASH_HASH_HASH) ||
187185
llvm::sys::fs::exists(LibraryPath))
@@ -190,14 +188,15 @@ const char *SYCLInstallationDetector::findLibspirvPath(
190188
return nullptr;
191189
};
192190

193-
// Otherwise, assume libclc is installed at the same prefix as clang
194-
// Expected path w/out install.
195-
if (const char *R = searchAt(D.ResourceDir, "..", "..", "clc"))
196-
return R;
191+
for (const auto &IC : InstallationCandidates) {
192+
// Expected path w/out install.
193+
if (const char *R = searchAt(IC, "lib", "clc"))
194+
return R;
197195

198-
// Expected path w/ install.
199-
if (const char *R = searchAt(D.ResourceDir, "..", "..", "..", "share", "clc"))
200-
return R;
196+
// Expected path w/ install.
197+
if (const char *R = searchAt(IC, "share", "clc"))
198+
return R;
199+
}
201200

202201
return nullptr;
203202
}

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
@@ -11,7 +11,7 @@
1111
// RUN: | FileCheck %s --check-prefixes=CHECK-LINUX
1212
// CHECK-LINUX: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}remangled-l64-signed_char.libspirv-nvptx64-nvidia-cuda.bc"
1313
//
14-
// 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 \
14+
// 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 \
1515
// RUN: | FileCheck %s --check-prefixes=CHECK-AMDGCN-WINDOWS
1616
// CHECK-AMDGCN-WINDOWS: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}remangled-l32-signed_char.libspirv-amdgcn-amd-amdhsa.bc"
1717
//
@@ -26,22 +26,22 @@
2626
// CHECK-CUDA: "-cc1"{{.*}} "-fcuda-is-device"
2727
// CHECK-CUDA-NOT: "-mlink-builtin-bitcode" "{{.*}}.libspirv-{{.*}}.bc"
2828
//
29-
// The path to the remangled libspirv bitcode file is determined by the resource directory.
29+
// The path to the remangled libspirv bitcode file is determined by the installation directory
3030
// RUN: %clang -### -ccc-install-dir %{install_dir} -resource-dir %{resource_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
3131
// RUN: | FileCheck %s -DINSTALL_DIR=%{install_dir} -DRESOURCE_DIR=%{resource_dir} --check-prefixes=CHECK-DIR
32-
// CHECK-DIR: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "[[RESOURCE_DIR]]{{.*[\\/]}}remangled-{{.*}}.libspirv-nvptx64-nvidia-cuda.bc"
32+
// CHECK-DIR: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "[[INSTALL_DIR]]{{.*[\\/]}}remangled-{{.*}}.libspirv-nvptx64-nvidia-cuda.bc"
3333
//
3434
// The `-###` option disables file existence checks
3535
// DEFINE: %{nonexistent_dir} = %/S/Inputs/SYCL/does_not_exist/lib/clang/resource_dir
36-
// RUN: %clang -### -resource-dir %{nonexistent_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
37-
// RUN: | FileCheck %s -DDIR=%{nonexistent_dir} --check-prefixes=CHECK-HHH-NONEXISTENT
36+
// RUN: %clang -### -ccc-install-dir %{nonexistent_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
37+
// RUN: | FileCheck %s -DDIR=%{nonexistent_dir} --check-prefixes=CHECK-HHH-NONEXISTENT
3838
// CHECK-HHH-NONEXISTENT: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "[[DIR]]{{.*[\\/]}}remangled-{{.*}}.libspirv-nvptx64-nvidia-cuda.bc"
3939
//
40-
// RUN: %clang -### -resource-dir %{nonexistent_dir} -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 -nogpulib %s 2>&1 \
41-
// RUN: | FileCheck %s -DDIR=%{nonexistent_dir} --check-prefixes=CHECK-AMDGCN-HHH-NONEXISTENT
40+
// RUN: %clang -### -ccc-install-dir %{nonexistent_dir} -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 -nogpulib %s 2>&1 \
41+
// RUN: | FileCheck %s -DDIR=%{nonexistent_dir} --check-prefixes=CHECK-AMDGCN-HHH-NONEXISTENT
4242
// CHECK-AMDGCN-HHH-NONEXISTENT: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "[[DIR]]{{.*[\\/]}}remangled-{{.*}}.libspirv-amdgcn-amd-amdhsa.bc"
4343
//
4444
// `-fdriver-only` has no such special handling, so it will not find the file
45-
// RUN: not %clang -fdriver-only -resource-dir %{nonexistent_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
46-
// RUN: | FileCheck %s --check-prefixes=CHECK-DO-NONEXISTENT
45+
// RUN: not %clang -fdriver-only -ccc-install-dir %{nonexistent_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
46+
// RUN: | FileCheck %s -DDIR=%{nonexistent_dir} --check-prefixes=CHECK-DO-NONEXISTENT
4747
// 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)