diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 21318b620a3ba..38d8b0007257e 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -91,9 +91,8 @@ def warn_drv_partially_supported_cuda_version: Warning< def err_drv_cuda_host_arch : Error< "unsupported architecture '%0' for host compilation">; def err_drv_no_sycl_libspirv : Error< - "cannot find 'libspirv-nvptx64--nvidiacl.bc'; provide path to libspirv " - "library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build " - "without linking with libspirv">; + "cannot find '%0'; provide path to libspirv library via '-fsycl-libspirv-path' or " + "pass '-fno-sycl-libspirv' to build without linking with libspirv.">; def err_drv_mix_cuda_hip : Error< "mixed CUDA and HIP compilation is not supported">; def err_drv_bad_target_id : Error< diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp index 8e0fff163ecb8..537cf914148b7 100644 --- a/clang/lib/Driver/ToolChains/Cuda.cpp +++ b/clang/lib/Driver/ToolChains/Cuda.cpp @@ -667,6 +667,14 @@ std::string CudaToolChain::getInputFilename(const InputInfo &Input) const { return std::string(Filename.str()); } +// Select remangled libclc variant. 64-bit longs default, 32-bit longs on +// Windows +static const char *getLibSpirvTargetName(const ToolChain &HostTC) { + if (HostTC.getTriple().isOSWindows()) + return "remangled-l32-signed_char.libspirv-nvptx64--nvidiacl.bc"; + return "remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc"; +} + void CudaToolChain::addClangTargetOptions( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, @@ -717,13 +725,8 @@ void CudaToolChain::addClangTargetOptions( llvm::sys::path::append(WithInstallPath, Twine("../../../share/clc")); LibraryPaths.emplace_back(WithInstallPath.c_str()); - // Select remangled libclc variant. 64-bit longs default, 32-bit longs on - // Windows - std::string LibSpirvTargetName = - "remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc"; - if (HostTC.getTriple().isOSWindows()) - LibSpirvTargetName = - "remangled-l32-signed_char.libspirv-nvptx64--nvidiacl.bc"; + // Select remangled libclc variant + std::string LibSpirvTargetName = getLibSpirvTargetName(HostTC); for (StringRef LibraryPath : LibraryPaths) { SmallString<128> LibSpirvTargetFile(LibraryPath); @@ -737,7 +740,8 @@ void CudaToolChain::addClangTargetOptions( } if (LibSpirvFile.empty()) { - getDriver().Diag(diag::err_drv_no_sycl_libspirv); + getDriver().Diag(diag::err_drv_no_sycl_libspirv) + << getLibSpirvTargetName(HostTC); return; } diff --git a/clang/lib/Driver/ToolChains/HIP.cpp b/clang/lib/Driver/ToolChains/HIP.cpp index 15bcb2cb01c6c..20cda65c884b6 100644 --- a/clang/lib/Driver/ToolChains/HIP.cpp +++ b/clang/lib/Driver/ToolChains/HIP.cpp @@ -240,6 +240,10 @@ HIPToolChain::HIPToolChain(const Driver &D, const llvm::Triple &Triple, getProgramPaths().push_back(getDriver().Dir); } +static const char *getLibSpirvTargetName(const ToolChain &HostTC) { + return "remangled-l64-signed_char.libspirv-amdgcn--amdhsa.bc"; +} + void HIPToolChain::addClangTargetOptions( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, @@ -309,8 +313,7 @@ void HIPToolChain::addClangTargetOptions( llvm::sys::path::append(WithInstallPath, Twine("../../../share/clc")); LibraryPaths.emplace_back(WithInstallPath.c_str()); - std::string LibSpirvTargetName = - "remangled-l64-signed_char.libspirv-amdgcn--amdhsa.bc"; + std::string LibSpirvTargetName = getLibSpirvTargetName(HostTC); for (StringRef LibraryPath : LibraryPaths) { SmallString<128> LibSpirvTargetFile(LibraryPath); llvm::sys::path::append(LibSpirvTargetFile, LibSpirvTargetName); @@ -322,7 +325,8 @@ void HIPToolChain::addClangTargetOptions( } if (LibSpirvFile.empty()) { - getDriver().Diag(diag::err_drv_no_sycl_libspirv); + getDriver().Diag(diag::err_drv_no_sycl_libspirv) + << getLibSpirvTargetName(HostTC); return; } diff --git a/clang/test/Driver/sycl-libspirv-invalid.cpp b/clang/test/Driver/sycl-libspirv-invalid.cpp index c79375500a513..2ef2ce35c34ee 100644 --- a/clang/test/Driver/sycl-libspirv-invalid.cpp +++ b/clang/test/Driver/sycl-libspirv-invalid.cpp @@ -3,13 +3,31 @@ // UNSUPPORTED: system-windows // RUN: %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \ -// RUN: -fsycl-targets=nvptx64-nvidia-nvcl --cuda-path=%S/Inputs/CUDA/usr/local/cuda \ +// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/CUDA/usr/local/cuda \ // RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc %s 2>&1 \ -// RUN: | FileCheck --check-prefix=ERR %s -// ERR: cannot find 'libspirv-nvptx64--nvidiacl.bc' +// RUN: | FileCheck --check-prefix=ERR-CUDA %s +// ERR-CUDA: cannot find 'remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc' + +// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-windows-msvc -fsycl \ +// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/CUDA/usr/local/cuda \ +// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc %s 2>&1 \ +// RUN: | FileCheck --check-prefix=ERR-CUDA-WIN %s +// ERR-CUDA-WIN: cannot find 'remangled-l32-signed_char.libspirv-nvptx64--nvidiacl.bc' + +// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \ +// RUN: -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 \ +// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc %s 2>&1 \ +// RUN: | FileCheck --check-prefix=ERR-HIP %s +// ERR-HIP: cannot find 'remangled-l64-signed_char.libspirv-amdgcn--amdhsa.bc' + +// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \ +// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/CUDA/usr/local/cuda \ +// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc -fno-sycl-libspirv %s 2>&1 \ +// RUN: | FileCheck --check-prefix=OK-CUDA %s +// OK-CUDA-NOT: cannot find suitable 'remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc' // RUN: %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \ -// RUN: -fsycl-targets=nvptx64-nvidia-nvcl --cuda-path=%S/Inputs/CUDA/usr/local/cuda \ +// RUN: -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 \ // RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc -fno-sycl-libspirv %s 2>&1 \ -// RUN: | FileCheck --check-prefix=OK %s -// OK-NOT: cannot find 'libspirv-nvptx64--nvidiacl.bc' +// RUN: | FileCheck --check-prefix=OK-HIP %s +// OK-HIP-NOT: cannot find 'remangled-l64-signed_char.libspirv-amdgcn--amdhsa.bc'