[clang] 0c8b435 - [Clang][retry 2] Lift HIPSPV onto the new offload driver (#179902)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 5 07:52:09 PST 2026
Author: Henry Linjamäki
Date: 2026-02-05T09:52:04-06:00
New Revision: 0c8b435c57f6079aa9fd2554859a305a77eb8c36
URL: https://github.com/llvm/llvm-project/commit/0c8b435c57f6079aa9fd2554859a305a77eb8c36
DIFF: https://github.com/llvm/llvm-project/commit/0c8b435c57f6079aa9fd2554859a305a77eb8c36.diff
LOG: [Clang][retry 2] Lift HIPSPV onto the new offload driver (#179902)
Update HIPSPV toolchain to support `--offload-new-driver`. Additionally,
tailor llvm-spirv invocation for
[chipStar](github.com/CHIP-SPV/chipStar) via `spirv64-*-chipstar`
offload triple.
AFAICT, all the relevant test failures in the previous PR (#178664) came
from tests involving `-Xoffload-compiler ‘-###’` in their RUN
directives. I have reworked those tests in this PR.
Added:
clang/test/Driver/Inputs/hipspv/lib/hip-device-lib/hipspv-spirv64-unknown-chipstar.bc
clang/test/Driver/hipspv-toolchain-rdc-separate.hip
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Basic/Targets.cpp
clang/lib/Basic/Targets/SPIR.h
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/HIPSPV.cpp
clang/lib/Driver/ToolChains/HIPSPV.h
clang/test/Driver/hipspv-device-libs.hip
clang/test/Driver/hipspv-link-static-library.hip
clang/test/Driver/hipspv-pass-plugin.hip
clang/test/Driver/hipspv-toolchain-rdc.hip
clang/test/Driver/hipspv-toolchain.hip
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7dc6881ed43e6..24d4e07ca68b3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -52,6 +52,13 @@ AST Dumping Potentially Breaking Changes
Clang Frontend Potentially Breaking Changes
-------------------------------------------
+- HIPSPV toolchain: `--offload-targets=spirv{32,64}` option is
+ deprecated and will be removed when the new offload driver becomes
+ default. The replacement for the option is
+ `--offload-targets=spirv{32,64}-unknown-chipstar` when using the new
+ offload driver (`--offload-new-driver`).
+
+
Clang Python Bindings Potentially Breaking Changes
--------------------------------------------------
- Remove ``CompletionString.Availability``. No libclang interfaces returned instances of it.
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 72b545961de4c..cd5b29db07a9f 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -682,13 +682,13 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
return std::make_unique<SPIRVTargetInfo>(Triple, Opts);
}
case llvm::Triple::spirv32: {
- if (os != llvm::Triple::UnknownOS ||
+ if ((os != llvm::Triple::UnknownOS && os != llvm::Triple::ChipStar) ||
Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
return nullptr;
return std::make_unique<SPIRV32TargetInfo>(Triple, Opts);
}
case llvm::Triple::spirv64: {
- if (os != llvm::Triple::UnknownOS ||
+ if ((os != llvm::Triple::UnknownOS && os != llvm::Triple::ChipStar) ||
Triple.getEnvironment() != llvm::Triple::UnknownEnvironment) {
if (os == llvm::Triple::OSType::AMDHSA)
return std::make_unique<SPIRV64AMDGCNTargetInfo>(Triple, Opts);
diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h
index ea992b0e01dbe..eef9521c7434a 100644
--- a/clang/lib/Basic/Targets/SPIR.h
+++ b/clang/lib/Basic/Targets/SPIR.h
@@ -362,8 +362,9 @@ class LLVM_LIBRARY_VISIBILITY SPIRV32TargetInfo : public BaseSPIRVTargetInfo {
: BaseSPIRVTargetInfo(Triple, Opts) {
assert(Triple.getArch() == llvm::Triple::spirv32 &&
"Invalid architecture for 32-bit SPIR-V.");
- assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
- "32-bit SPIR-V target must use unknown OS");
+ assert((getTriple().getOS() == llvm::Triple::UnknownOS ||
+ getTriple().getOS() == llvm::Triple::ChipStar) &&
+ "32-bit SPIR-V target must use unknown or chipstar OS");
assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
"32-bit SPIR-V target must use unknown environment type");
PointerWidth = PointerAlign = 32;
@@ -385,8 +386,9 @@ class LLVM_LIBRARY_VISIBILITY SPIRV64TargetInfo : public BaseSPIRVTargetInfo {
: BaseSPIRVTargetInfo(Triple, Opts) {
assert(Triple.getArch() == llvm::Triple::spirv64 &&
"Invalid architecture for 64-bit SPIR-V.");
- assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
- "64-bit SPIR-V target must use unknown OS");
+ assert((getTriple().getOS() == llvm::Triple::UnknownOS ||
+ getTriple().getOS() == llvm::Triple::ChipStar) &&
+ "64-bit SPIR-V target must use unknown or chipstar OS");
assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
"64-bit SPIR-V target must use unknown environment type");
PointerWidth = PointerAlign = 64;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index df498868b83c9..63e3b3640891c 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4954,21 +4954,26 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
// Compiling HIP in device-only non-RDC mode requires linking each action
// individually.
for (Action *&A : DeviceActions) {
- bool IsAMDGCNSPIRV = A->getOffloadingToolChain() &&
- A->getOffloadingToolChain()->getTriple().getOS() ==
- llvm::Triple::OSType::AMDHSA &&
- A->getOffloadingToolChain()->getTriple().isSPIRV();
+ auto *OffloadTriple = A->getOffloadingToolChain()
+ ? &A->getOffloadingToolChain()->getTriple()
+ : nullptr;
+ bool IsHIPSPV =
+ OffloadTriple && OffloadTriple->isSPIRV() &&
+ (OffloadTriple->getOS() == llvm::Triple::OSType::AMDHSA ||
+ OffloadTriple->getOS() == llvm::Triple::OSType::ChipStar);
bool UseSPIRVBackend = Args.hasFlag(options::OPT_use_spirv_backend,
options::OPT_no_use_spirv_backend,
/*Default=*/false);
- // Special handling for the HIP SPIR-V toolchain in device-only.
+ // Special handling for the HIP SPIR-V toolchains in device-only.
// The translator path has a linking step, whereas the SPIR-V backend path
// does not to avoid any external dependency such as spirv-link. The
// linking step is skipped for the SPIR-V backend path.
- bool IsAMDGCNSPIRVWithBackend = IsAMDGCNSPIRV && UseSPIRVBackend;
+ bool IsAMDGCNSPIRVWithBackend =
+ IsHIPSPV && OffloadTriple->getOS() == llvm::Triple::OSType::AMDHSA &&
+ UseSPIRVBackend;
- if ((A->getType() != types::TY_Object && !IsAMDGCNSPIRV &&
+ if ((A->getType() != types::TY_Object && !IsHIPSPV &&
A->getType() != types::TY_LTO_BC) ||
HIPRelocatableObj || !HIPNoRDC || !offloadDeviceOnly() ||
(IsAMDGCNSPIRVWithBackend && offloadDeviceOnly()))
@@ -6977,6 +6982,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
case llvm::Triple::ShaderModel:
TC = std::make_unique<toolchains::HLSLToolChain>(*this, Target, Args);
break;
+ case llvm::Triple::ChipStar:
+ TC = std::make_unique<toolchains::HIPSPVToolChain>(*this, Target, Args);
+ break;
default:
// Of these targets, Hexagon is the only one that might have
// an OS of Linux, in which case it got handled above already.
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 67241ead991dc..5575b644c6814 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9208,6 +9208,7 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
OPT_v,
OPT_cuda_path_EQ,
OPT_rocm_path_EQ,
+ OPT_hip_path_EQ,
OPT_O_Group,
OPT_g_Group,
OPT_g_flags_Group,
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index 0d7311f2b569c..8bdb7ab042b2b 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -90,9 +90,27 @@ void HIPSPV::Linker::constructLinkAndEmitSpirvCommand(
}
// Emit SPIR-V binary.
+ llvm::opt::ArgStringList TrArgs;
+ auto T = getToolChain().getTriple();
+ bool HasNoSubArch = T.getSubArch() == llvm::Triple::NoSubArch;
+ if (T.getOS() == llvm::Triple::ChipStar) {
+ // chipStar needs 1.2 for supporting warp-level primitivies via sub-group
+ // extensions. Strictly put we'd need 1.3 for the standard non-extension
+ // shuffle operations, but it's not supported by any backend driver of the
+ // chipStar.
+ if (HasNoSubArch)
+ TrArgs.push_back("--spirv-max-version=1.2");
+ TrArgs.push_back("--spirv-ext=-all"
+ // Needed for experimental indirect call support.
+ ",+SPV_INTEL_function_pointers"
+ // Needed for shuffles below SPIR-V 1.3
+ ",+SPV_INTEL_subgroups");
+ } else {
+ if (HasNoSubArch)
+ TrArgs.push_back("--spirv-max-version=1.1");
+ TrArgs.push_back("--spirv-ext=+all");
+ }
- llvm::opt::ArgStringList TrArgs{"--spirv-max-version=1.1",
- "--spirv-ext=+all"};
InputInfo TrInput = InputInfo(types::TY_LLVM_BC, TempFile, "");
SPIRV::constructTranslateCommand(C, *this, JA, Output, TrInput, TrArgs);
}
@@ -116,7 +134,16 @@ void HIPSPV::Linker::ConstructJob(Compilation &C, const JobAction &JA,
HIPSPVToolChain::HIPSPVToolChain(const Driver &D, const llvm::Triple &Triple,
const ToolChain &HostTC, const ArgList &Args)
- : ToolChain(D, Triple, Args), HostTC(HostTC) {
+ : ToolChain(D, Triple, Args), HostTC(&HostTC) {
+ // Lookup binaries into the driver directory, this is used to
+ // discover the clang-offload-bundler executable.
+ getProgramPaths().push_back(getDriver().Dir);
+}
+
+// Non-offloading toolchain. Primaly used by clang-offload-linker.
+HIPSPVToolChain::HIPSPVToolChain(const Driver &D, const llvm::Triple &Triple,
+ const ArgList &Args)
+ : ToolChain(D, Triple, Args), HostTC(nullptr) {
// Lookup binaries into the driver directory, this is used to
// discover the clang-offload-bundler executable.
getProgramPaths().push_back(getDriver().Dir);
@@ -125,7 +152,14 @@ HIPSPVToolChain::HIPSPVToolChain(const Driver &D, const llvm::Triple &Triple,
void HIPSPVToolChain::addClangTargetOptions(
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
Action::OffloadKind DeviceOffloadingKind) const {
- HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
+
+ if (!HostTC) {
+ assert(DeviceOffloadingKind == Action::OFK_None &&
+ "Need host toolchain for offloading!");
+ return;
+ }
+
+ HostTC->addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
assert(DeviceOffloadingKind == Action::OFK_HIP &&
"Only HIP offloading kinds are supported for GPUs.");
@@ -156,27 +190,37 @@ Tool *HIPSPVToolChain::buildLinker() const {
}
void HIPSPVToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {
- HostTC.addClangWarningOptions(CC1Args);
+ if (HostTC)
+ HostTC->addClangWarningOptions(CC1Args);
+ ToolChain::addClangWarningOptions(CC1Args);
}
ToolChain::CXXStdlibType
HIPSPVToolChain::GetCXXStdlibType(const ArgList &Args) const {
- return HostTC.GetCXXStdlibType(Args);
+ if (HostTC)
+ return HostTC->GetCXXStdlibType(Args);
+ return ToolChain::GetCXXStdlibType(Args);
}
void HIPSPVToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
- HostTC.AddClangSystemIncludeArgs(DriverArgs, CC1Args);
+ if (HostTC)
+ HostTC->AddClangSystemIncludeArgs(DriverArgs, CC1Args);
+ ToolChain::AddClangSystemIncludeArgs(DriverArgs, CC1Args);
}
void HIPSPVToolChain::AddClangCXXStdlibIncludeArgs(
const ArgList &Args, ArgStringList &CC1Args) const {
- HostTC.AddClangCXXStdlibIncludeArgs(Args, CC1Args);
+ if (HostTC)
+ HostTC->AddClangCXXStdlibIncludeArgs(Args, CC1Args);
+ ToolChain::AddClangCXXStdlibIncludeArgs(Args, CC1Args);
}
void HIPSPVToolChain::AddIAMCUIncludeArgs(const ArgList &Args,
ArgStringList &CC1Args) const {
- HostTC.AddIAMCUIncludeArgs(Args, CC1Args);
+ if (HostTC)
+ HostTC->AddIAMCUIncludeArgs(Args, CC1Args);
+ ToolChain::AddIAMCUIncludeArgs(Args, CC1Args);
}
void HIPSPVToolChain::AddHIPIncludeArgs(const ArgList &DriverArgs,
@@ -270,12 +314,16 @@ SanitizerMask HIPSPVToolChain::getSupportedSanitizers() const {
// This behavior is necessary because the host and device toolchains
// invocations often share the command line, so the device toolchain must
// tolerate flags meant only for the host toolchain.
- return HostTC.getSupportedSanitizers();
+ if (HostTC)
+ return HostTC->getSupportedSanitizers();
+ return ToolChain::getSupportedSanitizers();
}
VersionTuple HIPSPVToolChain::computeMSVCVersion(const Driver *D,
const ArgList &Args) const {
- return HostTC.computeMSVCVersion(D, Args);
+ if (HostTC)
+ return HostTC->computeMSVCVersion(D, Args);
+ return ToolChain::computeMSVCVersion(D, Args);
}
void HIPSPVToolChain::adjustDebugInfoKind(
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.h b/clang/lib/Driver/ToolChains/HIPSPV.h
index caf6924151446..068040ee4f491 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.h
+++ b/clang/lib/Driver/ToolChains/HIPSPV.h
@@ -47,9 +47,12 @@ class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
public:
HIPSPVToolChain(const Driver &D, const llvm::Triple &Triple,
const ToolChain &HostTC, const llvm::opt::ArgList &Args);
+ HIPSPVToolChain(const Driver &D, const llvm::Triple &Triple,
+ const llvm::opt::ArgList &Args);
const llvm::Triple *getAuxTriple() const override {
- return &HostTC.getTriple();
+ assert(HostTC);
+ return &HostTC->getTriple();
}
void
@@ -90,7 +93,7 @@ class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
bool isPICDefaultForced() const override { return false; }
bool SupportsProfiling() const override { return false; }
- const ToolChain &HostTC;
+ const ToolChain *HostTC = nullptr;
protected:
Tool *buildLinker() const override;
diff --git a/clang/test/Driver/Inputs/hipspv/lib/hip-device-lib/hipspv-spirv64-unknown-chipstar.bc b/clang/test/Driver/Inputs/hipspv/lib/hip-device-lib/hipspv-spirv64-unknown-chipstar.bc
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/hipspv-device-libs.hip b/clang/test/Driver/hipspv-device-libs.hip
index 9d6af54b10255..71bf0897e39dd 100644
--- a/clang/test/Driver/hipspv-device-libs.hip
+++ b/clang/test/Driver/hipspv-device-libs.hip
@@ -6,7 +6,7 @@
// Test --hip-device-lib-path
// RUN: %clang -### -target x86_64-linux-gnu --offload=spirv64 \
-// RUN: --hip-path=%S/Inputs/hipspv \
+// RUN: --hip-path=%S/Inputs/hipspv \
// RUN: --hip-device-lib-path=%S/Inputs/hipspv-dev-lib %s \
// RUN: 2>&1 | FileCheck --check-prefixes=ALL,HIP-DEV-LIB-PATH %s
diff --git a/clang/test/Driver/hipspv-link-static-library.hip b/clang/test/Driver/hipspv-link-static-library.hip
index cf16236738c12..eb114ada49020 100644
--- a/clang/test/Driver/hipspv-link-static-library.hip
+++ b/clang/test/Driver/hipspv-link-static-library.hip
@@ -1,28 +1,57 @@
// Test HIPSPV static device library linking
// REQUIRES: system-linux
+// REQUIRES: x86-registered-target
+// REQUIRES: spirv-registered-target
// UNSUPPORTED: system-windows
// Create a dummy archive to test SDL linking
// RUN: rm -rf %t && mkdir %t
-// RUN: touch %t/dummy.bc
+// RUN: touch %t/dummy.bc
// RUN: llvm-ar cr %t/libSDL.a %t/dummy.bc
// Test that -l options are passed to llvm-link for --offload=spirv64
// RUN: %clang -### --target=x86_64-linux-gnu --offload=spirv64 \
// RUN: --hip-path=%S/Inputs/hipspv -nohipwrapperinc %s \
-// RUN: -L%t -lSDL \
-// RUN: 2>&1 | FileCheck -check-prefix=SDL-LINK %s
+// RUN: --no-offload-new-driver -L%t -lSDL \
+// RUN: 2>&1 | FileCheck -check-prefixes=SDL %s
-// Test that .a files are properly unbundled and passed to llvm-link
+// Test that .a files are properly unbundled and passed to llvm-link
// RUN: %clang -### --target=x86_64-linux-gnu --offload=spirv64 \
// RUN: --hip-path=%S/Inputs/hipspv -nohipwrapperinc %s \
-// RUN: %t/libSDL.a \
-// RUN: 2>&1 | FileCheck -check-prefix=SDL-ARCHIVE %s
+// RUN: --no-offload-new-driver %t/libSDL.a \
+// RUN: 2>&1 | FileCheck -check-prefixes=SDL %s
+
+// RUN: %clang -cc1 %s -triple spirv64-unknown-chipstar -emit-llvm-bc -o %t/dev.bc
+// RUN: llvm-offload-binary -o %t/dev.out \
+// RUN: --image=file=%t/dev.bc,kind=hip,triple=spirv64-unknown-chipstar,arch=generic
+// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t/tu0.o \
+// RUN: -fembed-offload-object=%t/dev.out
+// RUN: cp %t/tu0.o %t/tu1.o
+// RUN: llvm-ar cr %t/libSDL2.a %t/tu1.o
+
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-new-driver -fgpu-rdc \
+// RUN: -Xoffload-compiler-spirv64-unknown-chipstar \
+// RUN: --hip-path=%S/Inputs/hipspv -no-hip-rt %t/tu0.o %t/libSDL2.a \
+// RUN: 2>&1 | FileCheck -check-prefixes=SDL-NEW %s -DHIP_PATH=%S/Inputs/hipspv
+
+// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu \
+// RUN: --device-compiler=spirv64-unknown-chipstar=--hip-path=%S/Inputs/hipspv \
+// RUN: --linker-path=/usr/bin/ld -o a.out %t/tu0.o %t/libSDL2.a \
+// RUN: 2>&1 | FileCheck -check-prefixes=SDL-NEW-WRAPPER %s -DHIP_PATH=%S/Inputs/hipspv
// Verify that the input files are added before the SDL files in llvm-link command
// This tests the ordering fix to match HIPAMD behavior
-// SDL-LINK: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libSDL.a" "-targets=hip-spirv64-unknown-unknown-unknown-generic" "-output=[[SDL_A:.*\.a]]" "-allow-missing-bundles"
-// SDL-LINK: "{{.*}}llvm-link" "-o" "{{.*}}.bc" "{{.*}}.bc" "[[SDL_A]]"
+// SDL: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libSDL.a" "-targets=hip-spirv64-unknown-unknown-unknown-generic" "-output=[[SDL_A:.*\.a]]" "-allow-missing-bundles"
+// SDL: "{{.*}}llvm-link" "-o" "{{.*}}.bc" "{{.*}}.bc" "[[SDL_A]]"
+// SDL-NEW: "{{.*}}clang-linker-wrapper"
+// SDL-NEW-SAME: "--device-compiler=spirv64-unknown-chipstar=--hip-path=[[HIP_PATH]]"
+// SDL-NEW-SAME: "{{.*}}/tu0.o" "{{.*}}/libSDL2.a"
+// DELETE-SDL-NEW: "{{.*}}llvm-link" "-o" "{{.*}}.bc" "{{.*}}.o" "{{.*}}.o"
+
+// SDL-NEW-WRAPPER: clang{{.*}}" --no-default-config -o {{[^ ]*.img}}
+// SDL-NEW-WRAPPER-SAME: {{[^ ]*.o}} {{[^ ]*.o}}
+// SDL-NEW-WRAPPER-SAME: --hip-path=[[HIP_PATH]]
-// SDL-ARCHIVE: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libSDL.a" "-targets=hip-spirv64-unknown-unknown-unknown-generic" "-output=[[SDL_A:.*\.a]]" "-allow-missing-bundles"
-// SDL-ARCHIVE: "{{.*}}llvm-link" "-o" "{{.*}}.bc" "{{.*}}.bc" "[[SDL_A]]"
+// SDL: "{{.*}}opt"
+// SDL-SAME: "-load-pass-plugin" {{".*/hipspv/lib/libLLVMHipSpvPasses.so"}}
+// SDL-SAME: "-passes=hip-post-link-passes"
diff --git a/clang/test/Driver/hipspv-pass-plugin.hip b/clang/test/Driver/hipspv-pass-plugin.hip
index fc3c64b057352..3a0979ad6df01 100644
--- a/clang/test/Driver/hipspv-pass-plugin.hip
+++ b/clang/test/Driver/hipspv-pass-plugin.hip
@@ -1,20 +1,38 @@
// UNSUPPORTED: system-windows
// RUN: %clang -### -target x86_64-linux-gnu --offload=spirv64 \
-// RUN: --hip-path=%S/Inputs/hipspv -nogpuinc %s \
-// RUN: 2>&1 | FileCheck --check-prefixes=FROM-HIP-PATH %s
+// RUN: --no-offload-new-driver --hip-path=%S/Inputs/hipspv -nogpuinc %s \
+// RUN: 2>&1 | FileCheck --check-prefixes=ALL,FROM-HIP-PATH %s
// RUN: %clang -### -target x86_64-linux-gnu --offload=spirv64 \
-// RUN: -nogpuinc -nogpulib --hipspv-pass-plugin=%S/Inputs/pass-plugin.so %s \
-// RUN: 2>&1 | FileCheck --check-prefixes=FROM-OPTION %s
+// RUN: --no-offload-new-driver -nogpuinc -nogpulib --hipspv-pass-plugin=%S/Inputs/pass-plugin.so %s \
+// RUN: 2>&1 | FileCheck --check-prefixes=ALL,FROM-OPTION %s
// RUN: not %clang -### --target=x86_64-linux-gnu --offload=spirv64 \
-// RUN: -nogpuinc -nogpulib --hipspv-pass-plugin=foo.so %s \
-// RUN: 2>&1 | FileCheck --check-prefixes=FROM-OPTION-INVALID %s
+// RUN: --no-offload-new-driver -nogpuinc -nogpulib --hipspv-pass-plugin=foo.so %s \
+// RUN: 2>&1 | FileCheck --check-prefixes=ALL,FROM-OPTION-INVALID %s
// RUN: %clang -### -target x86_64-linux-gnu --offload=spirv64 \
-// RUN: -nogpuinc -nogpulib %s \
-// RUN: 2>&1 | FileCheck --check-prefixes=NO-PLUGIN %s
+// RUN: --no-offload-new-driver -nogpuinc -nogpulib %s \
+// RUN: 2>&1 | FileCheck --check-prefixes=ALL,NO-PLUGIN %s
+
+// Run commands for the new offload driver:
+
+// RUN: touch %t.dummy.o
+// RUN: %clang -### --no-default-config -o /dev/null --target=spirv64-unknown-chipstar \
+// RUN: %t.dummy.o --hip-path=%S/Inputs/hipspv \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=ALL,FROM-HIP-PATH
+
+// RUN: %clang -### --no-default-config -o /dev/null --target=spirv64-unknown-chipstar \
+// RUN: %t.dummy.o --hipspv-pass-plugin=%S/Inputs/pass-plugin.so \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=ALL,FROM-OPTION
+
+// RUN: not %clang -### --no-default-config -o /dev/null --target=spirv64-unknown-chipstar \
+// RUN: %t.dummy.o --hipspv-pass-plugin=foo.so \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=ALL,FROM-OPTION-INVALID
+
+// RUN: %clang -### --no-default-config -o /dev/null --target=spirv64-unknown-chipstar \
+// RUN: %t.dummy.o 2>&1 | FileCheck %s --check-prefixes=ALL,NO-PLUGIN
// FROM-HIP-PATH: {{".*opt"}} {{".*.bc"}} "-load-pass-plugin"
// FROM-HIP-PATH-SAME: {{".*/Inputs/hipspv/lib/libLLVMHipSpvPasses.so"}}
@@ -23,3 +41,4 @@
// FROM-OPTION-INVALID: error: no such file or directory: 'foo.so'
// NO-PLUGIN-NOT: {{".*opt"}} {{".*.bc"}} "-load-pass-plugin"
// NO-PLUGIN-NOT: {{".*/Inputs/hipspv/lib/libLLVMHipSpvPasses.so"}}
+// ALL: {{".*llvm-spirv[^ ]*"}}
diff --git a/clang/test/Driver/hipspv-toolchain-rdc-separate.hip b/clang/test/Driver/hipspv-toolchain-rdc-separate.hip
new file mode 100644
index 0000000000000..6e597d69223a4
--- /dev/null
+++ b/clang/test/Driver/hipspv-toolchain-rdc-separate.hip
@@ -0,0 +1,66 @@
+// UNSUPPORTED: system-windows
+
+// RUN: %clang -### -x hip -target x86_64-linux-gnu \
+// RUN: --offload=spirv64-unknown-chipstar --offload-new-driver -fgpu-rdc -c \
+// RUN: --hip-path=%S/Inputs/hipspv -nohipwrapperinc \
+// RUN: %S/Inputs/hip_multiple_inputs/a.cu \
+// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck \
+// RUN: -DHIP_PATH=%S/Inputs/hipspv %s
+
+// CHECK: [[CLANG:".*clang[^ ]*"]] "-cc1" "-triple" "spirv64-unknown-chipstar"
+// CHECK-SAME: "-aux-triple" "[[HOST_TRIPLE:[^ ]*]]"
+// CHECK-SAME: "-emit-llvm-bc"
+// CHECK-SAME: "-fcuda-is-device"
+// CHECK-SAME: "-fvisibility=hidden" "-fapply-global-visibility-to-externs"
+// CHECK-SAME: "-mlink-builtin-bitcode" "[[HIP_PATH]]/lib/hip-device-lib/hipspv-spirv64-unknown-chipstar.bc"
+// CHECK-SAME: "-fgpu-rdc"
+// CHECK-SAME: "-o" "[[A_DEV_BC:.*bc]]" "-x" "hip"
+// CHECK-SAME: "[[A_SRC:.*a.cu]]"
+
+// CHECK: "{{.*llvm-offload-binary[^ ]*}}" "-o" "[[A_BIN_PACKAGE:.*.out]]"
+// CHECK-SAME: "--image=file=[[A_DEV_BC]],triple=spirv64-unknown-chipstar,arch=generic,kind=hip"
+
+// CHECK: [[CLANG]] "-cc1" "-triple" "[[HOST_TRIPLE]]"
+// CHECK-SAME: "-aux-triple" "spirv64-unknown-chipstar"
+// CHECK-SAME: "-emit-obj"
+// CHECK-SAME: "-fgpu-rdc"
+// CHECK-SAME: "-fembed-offload-object=[[A_BIN_PACKAGE]]"
+// CHECK-SAME: "-o" "[[A_HOST_OBJ:.*o]]" "-x" "hip" "[[A_SRC]]"
+
+// CHECK: [[CLANG]] "-cc1" "-triple" "spirv64-unknown-chipstar"
+// CHECK-SAME: "-aux-triple" "[[HOST_TRIPLE]]"
+// CHECK-SAME: "-emit-llvm-bc"
+// CHECK-SAME: "-fcuda-is-device"
+// CHECK-SAME: "-fvisibility=hidden" "-fapply-global-visibility-to-externs"
+// CHECK-SAME: "-mlink-builtin-bitcode" "[[HIP_PATH]]/lib/hip-device-lib/hipspv-spirv64-unknown-chipstar.bc"
+// CHECK-SAME: "-fgpu-rdc"
+// CHECK-SAME: "-o" "[[B_DEV_BC:.*bc]]" "-x" "hip"
+// CHECK-SAME: "[[B_SRC:.*b.hip]]"
+
+// CHECK: "{{.*llvm-offload-binary[^ ]*}}" "-o" "[[B_BIN_PACKAGE:.*.out]]"
+// CHECK-SAME: "--image=file=[[B_DEV_BC]],triple=spirv64-unknown-chipstar,arch=generic,kind=hip"
+
+// CHECK: [[CLANG]] "-cc1" "-triple" "[[HOST_TRIPLE]]"
+// CHECK-SAME: "-aux-triple" "spirv64-unknown-chipstar"
+// CHECK-SAME: "-emit-obj"
+// CHECK-SAME: "-fgpu-rdc"
+// CHECK-SAME: "-fembed-offload-object=[[B_BIN_PACKAGE]]"
+// CHECK-SAME: "-o" "[[B_HOST_OBJ:.*o]]" "-x" "hip"
+// CHECK-SAME: "[[B_SRC]]"
+
+// RUN: rm -rf %t && mkdir %t
+// RUN: touch %t/a.o %t/b.o
+// RUN: %clang -### -target x86_64-linux-gnu --offload-new-driver -fgpu-rdc \
+// RUN: -Xoffload-compiler-spirv64-unknown-chipstar \
+// RUN: --hip-path=%S/Inputs/hipspv \
+// RUN: -no-hip-rt %t/a.o %t/b.o \
+// RUN: 2>&1 | FileCheck -check-prefixes=LINK \
+// RUN: -DHIP_PATH=%S/Inputs/hipspv %s
+
+// LINK: "{{.*clang-linker-wrapper[^ ]*}}"
+// LINK-SAME: "--host-triple=x86_64-unknown-linux-gnu"
+// LINK-SAME: "--device-compiler=spirv64-unknown-chipstar=--hip-path=[[HIP_PATH]]"
+// LINK-SAME: "-o" "a.out"
+// LINK-SAME: "{{.*a[.]o}}" "{{.*b[.]o}}"
+// LINK-NOT: -lamdhip64
diff --git a/clang/test/Driver/hipspv-toolchain-rdc.hip b/clang/test/Driver/hipspv-toolchain-rdc.hip
index 1015ce27007ef..5a3f59a6287b2 100644
--- a/clang/test/Driver/hipspv-toolchain-rdc.hip
+++ b/clang/test/Driver/hipspv-toolchain-rdc.hip
@@ -4,57 +4,113 @@
// RUN: --no-offload-new-driver -fgpu-rdc --hip-path=%S/Inputs/hipspv -nohipwrapperinc \
// RUN: %S/Inputs/hip_multiple_inputs/a.cu \
// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
-// RUN: 2>&1 | FileCheck %s
+// RUN: 2>&1 | FileCheck --check-prefix=OLD %s
+
+// RUN: %clang -### -x hip -target x86_64-linux-gnu \
+// RUN: --offload=spirv64-unknown-chipstar --offload-new-driver -fgpu-rdc \
+// RUN: --hip-path=%S/Inputs/hipspv -nohipwrapperinc -no-hip-rt \
+// RUN: %S/Inputs/hip_multiple_inputs/a.cu \
+// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck --check-prefix=NEW \
+// RUN: -DOFFLOAD_TRIPLE=spirv64-unknown-chipstar -DHIP_PATH=%S/Inputs/hipspv %s
// Emit objects for host side path
-// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "x86_64-unknown-linux-gnu"
-// CHECK-SAME: "-aux-triple" "spirv64"
-// CHECK-SAME: "-emit-obj"
-// CHECK-SAME: "-fgpu-rdc"
-// CHECK-SAME: {{.*}} "-o" [[A_OBJ_HOST:".*o"]] "-x" "hip"
-// CHECK-SAME: {{.*}} [[A_SRC:".*a.cu"]]
-
-// CHECK: [[CLANG]] "-cc1" "-triple" "x86_64-unknown-linux-gnu"
-// CHECK-SAME: "-aux-triple" "spirv64"
-// CHECK-SAME: "-emit-obj"
-// CHECK-SAME: "-fgpu-rdc"
-// CHECK-SAME: {{.*}} "-o" [[B_OBJ_HOST:".*o"]] "-x" "hip"
-// CHECK-SAME: {{.*}} [[B_SRC:".*b.hip"]]
+// OLD: [[CLANG:".*clang.*"]] "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// OLD-SAME: "-aux-triple" "spirv64"
+// OLD-SAME: "-emit-obj"
+// OLD-SAME: "-fgpu-rdc"
+// OLD-SAME: {{.*}} "-o" [[A_OBJ_HOST:".*o"]] "-x" "hip"
+// OLD-SAME: {{.*}} [[A_SRC:".*a.cu"]]
+
+// OLD: [[CLANG]] "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// OLD-SAME: "-aux-triple" "spirv64"
+// OLD-SAME: "-emit-obj"
+// OLD-SAME: "-fgpu-rdc"
+// OLD-SAME: {{.*}} "-o" [[B_OBJ_HOST:".*o"]] "-x" "hip"
+// OLD-SAME: {{.*}} [[B_SRC:".*b.hip"]]
// Emit code (LLVM BC) for device side path.
-// CHECK: [[CLANG]] "-cc1" "-triple" "spirv64"
-// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
-// CHECK-SAME: "-emit-llvm-bc"
-// CHECK-SAME: "-fcuda-is-device"
-// CHECK-SAME: "-fvisibility=hidden" "-fapply-global-visibility-to-externs"
-// CHECK-SAME: "-fgpu-rdc"
-// CHECK-SAME: {{.*}} "-o" [[A_BC1:".*bc"]] "-x" "hip"
-// CHECK-SAME: {{.*}} [[A_SRC]]
-
-// CHECK: [[CLANG]] "-cc1" "-triple" "spirv64"
-// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
-// CHECK-SAME: "-emit-llvm-bc"
-// CHECK-SAME: "-fcuda-is-device"
-// CHECK-SAME: "-fvisibility=hidden" "-fapply-global-visibility-to-externs"
-// CHECK-SAME: "-fgpu-rdc"
-// CHECK-SAME: {{.*}} "-o" [[B_BC1:".*bc"]] "-x" "hip"
-// CHECK-SAME: {{.*}} [[B_SRC]]
+// OLD: [[CLANG]] "-cc1" "-triple" "spirv64"
+// OLD-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
+// OLD-SAME: "-emit-llvm-bc"
+// OLD-SAME: "-fcuda-is-device"
+// OLD-SAME: "-fvisibility=hidden" "-fapply-global-visibility-to-externs"
+// OLD-SAME: "-fgpu-rdc"
+// OLD-SAME: {{.*}} "-o" [[A_BC1:".*bc"]] "-x" "hip"
+// OLD-SAME: {{.*}} [[A_SRC]]
+
+// OLD: [[CLANG]] "-cc1" "-triple" "spirv64"
+// OLD-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
+// OLD-SAME: "-emit-llvm-bc"
+// OLD-SAME: "-fcuda-is-device"
+// OLD-SAME: "-fvisibility=hidden" "-fapply-global-visibility-to-externs"
+// OLD-SAME: "-fgpu-rdc"
+// OLD-SAME: {{.*}} "-o" [[B_BC1:".*bc"]] "-x" "hip"
+// OLD-SAME: {{.*}} [[B_SRC]]
// Link device code, lower it with HIPSPV passes and emit SPIR-V binary.
-// CHECK: {{".*llvm-link.*"}} "-o" [[AB_LINK:".*bc"]] [[A_BC1]] [[B_BC1]]
-// CHECK: {{".*opt.*"}} [[AB_LINK]] "-load-pass-plugin"
-// CHECK-SAME: "{{.*}}/Inputs/hipspv/lib/libLLVMHipSpvPasses.so"
-// CHECK-SAME: "-o" [[AB_LOWER:".*bc"]]
-// CHECK: {{".*llvm-spirv"}} "--spirv-max-version=1.1" "--spirv-ext=+all"
-// CHECK-SAME: [[AB_LOWER]] "-o" "[[AB_SPIRV:.*out]]"
+// OLD: {{".*llvm-link.*"}} "-o" [[AB_LINK:".*bc"]] [[A_BC1]] [[B_BC1]]
+// OLD: {{".*opt.*"}} [[AB_LINK]] "-load-pass-plugin"
+// OLD-SAME: "{{.*}}/Inputs/hipspv/lib/libLLVMHipSpvPasses.so"
+// OLD-SAME: "-o" [[AB_LOWER:".*bc"]]
+// OLD: {{".*llvm-spirv"}} "--spirv-max-version=1.1" "--spirv-ext=+all"
+// OLD-SAME: [[AB_LOWER]] "-o" "[[AB_SPIRV:.*out]]"
// Construct fat binary object.
-// CHECK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o" "-bundle-align=4096"
-// CHECK-SAME: "-targets={{.*}},hip-spirv64----generic"
-// CHECK-SAME: "-input=/dev/null" "-input=[[AB_SPIRV]]"
-// CHECK-SAME: "-output=[[AB_FATBIN:.*hipfb]]"
-// CHECK: {{".*clang.*"}} "-o" [[OBJBUNDLE:".*o"]] "{{.*}}.mcin"
+// OLD: [[BUNDLER:".*clang-offload-bundler"]] "-type=o" "-bundle-align=4096"
+// OLD-SAME: "-targets={{.*}},hip-spirv64----generic"
+// OLD-SAME: "-input=/dev/null" "-input=[[AB_SPIRV]]"
+// OLD-SAME: "-output=[[AB_FATBIN:.*hipfb]]"
+// OLD: {{".*clang.*"}} "-o" [[OBJBUNDLE:".*o"]] "{{.*}}.mcin"
// Output the executable
-// CHECK: {{".*ld.*"}} {{.*}}"-o" "a.out" {{.*}} [[A_OBJ_HOST]] [[B_OBJ_HOST]]
-// CHECK-SAME: [[OBJBUNDLE]]
+// OLD: {{".*ld.*"}} {{.*}}"-o" "a.out" {{.*}} [[A_OBJ_HOST]] [[B_OBJ_HOST]]
+// OLD-SAME: [[OBJBUNDLE]]
+
+// NEW: [[CLANG:".*clang[^ ]*"]] "-cc1" "-triple" "[[OFFLOAD_TRIPLE]]"
+// NEW-SAME: "-aux-triple" "[[HOST_TRIPLE:[^ ]*]]"
+// NEW-SAME: "-emit-llvm-bc"
+// NEW-SAME: "-fcuda-is-device"
+// NEW-SAME: "-fvisibility=hidden" "-fapply-global-visibility-to-externs"
+// NEW-SAME: "-mlink-builtin-bitcode" "[[HIP_PATH]]/lib/hip-device-lib/hipspv-spirv64-unknown-chipstar.bc"
+// NEW-SAME: "-fgpu-rdc"
+// NEW-SAME: "-o" "[[A_DEV_BC:.*bc]]" "-x" "hip"
+// NEW-SAME: "[[A_SRC:.*a.cu]]"
+
+// NEW: "{{.*llvm-offload-binary[^ ]*}}" "-o" "[[A_BIN_PACKAGE:.*.out]]"
+// NEW-SAME: "--image=file=[[A_DEV_BC]],triple=[[OFFLOAD_TRIPLE]],arch=generic,kind=hip"
+
+// NEW: [[CLANG]] "-cc1" "-triple" "[[HOST_TRIPLE]]"
+// NEW-SAME: "-aux-triple" "[[OFFLOAD_TRIPLE]]"
+// NEW-SAME: "-emit-obj"
+// NEW-SAME: "-fgpu-rdc"
+// NEW-SAME: "-fembed-offload-object=[[A_BIN_PACKAGE]]"
+// NEW-SAME: "-o" "[[A_HOST_OBJ:.*o]]" "-x" "hip" "[[A_SRC]]"
+
+// NEW: [[CLANG]] "-cc1" "-triple" "[[OFFLOAD_TRIPLE]]"
+// NEW-SAME: "-aux-triple" "[[HOST_TRIPLE]]"
+// NEW-SAME: "-emit-llvm-bc"
+// NEW-SAME: "-fcuda-is-device"
+// NEW-SAME: "-fvisibility=hidden" "-fapply-global-visibility-to-externs"
+// NEW-SAME: "-mlink-builtin-bitcode" "[[HIP_PATH]]/lib/hip-device-lib/hipspv-spirv64-unknown-chipstar.bc"
+// NEW-SAME: "-fgpu-rdc"
+// NEW-SAME: "-o" "[[B_DEV_BC:.*bc]]" "-x" "hip"
+// NEW-SAME: "[[B_SRC:.*b.hip]]"
+
+// NEW: "{{.*llvm-offload-binary[^ ]*}}" "-o" "[[B_BIN_PACKAGE:.*.out]]"
+// NEW-SAME: "--image=file=[[B_DEV_BC]],triple=[[OFFLOAD_TRIPLE]],arch=generic,kind=hip"
+
+// NEW: [[CLANG]] "-cc1" "-triple" "[[HOST_TRIPLE]]"
+// NEW-SAME: "-aux-triple" "[[OFFLOAD_TRIPLE]]"
+// NEW-SAME: "-emit-obj"
+// NEW-SAME: "-fgpu-rdc"
+// NEW-SAME: "-fembed-offload-object=[[B_BIN_PACKAGE]]"
+// NEW-SAME: "-o" "[[B_HOST_OBJ:.*o]]" "-x" "hip"
+// NEW-SAME: "[[B_SRC]]"
+
+// NEW: "{{.*clang-linker-wrapper[^ ]*}}"
+// NEW-SAME: "--device-compiler=[[OFFLOAD_TRIPLE]]=--hip-path=[[HIP_PATH]]"
+// NEW-SAME: "--host-triple=[[HOST_TRIPLE]]"
+// NEW-SAME: "-o" "a.out"
+// NEW-SAME: "[[A_HOST_OBJ]]" "[[B_HOST_OBJ]]"
+// NEW-NOT: -lamdhip64
diff --git a/clang/test/Driver/hipspv-toolchain.hip b/clang/test/Driver/hipspv-toolchain.hip
index 0c98db84c6e23..ae8d65313abfb 100644
--- a/clang/test/Driver/hipspv-toolchain.hip
+++ b/clang/test/Driver/hipspv-toolchain.hip
@@ -1,37 +1,108 @@
+// REQUIRES: spirv-registered-target
// UNSUPPORTED: system-windows, system-cygwin
// RUN: %clang -### -target x86_64-linux-gnu --offload=spirv64 \
// RUN: --no-offload-new-driver --hip-path=%S/Inputs/hipspv -nohipwrapperinc %s \
-// RUN: 2>&1 | FileCheck %s
+// RUN: 2>&1 | FileCheck --check-prefixes=CHECK,OLD \
+// RUN: -DTRIPLE=spirv64 %s
-// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "spirv64"
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN: --offload=spirv64-unknown-chipstar \
+// RUN: --offload-new-driver --hip-path=%S/Inputs/hipspv -nohipwrapperinc %s \
+// RUN: 2>&1 | FileCheck --check-prefixes=CHECK,NEW \
+// RUN: -DTRIPLE=spirv64-unknown-chipstar -DHIP_PATH=%S/Inputs/hipspv %s
+
+// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "[[TRIPLE]]"
// CHECK-SAME: "-aux-triple" "{{.*}}" "-emit-llvm-bc"
// CHECK-SAME: "-fcuda-is-device"
-// CHECK-SAME: "-mlink-builtin-bitcode" {{".*/hipspv/lib/hip-device-lib/hipspv-spirv64.bc"}}
+// CHECK-SAME: "-mlink-builtin-bitcode" {{".*/hipspv/lib/hip-device-lib/hipspv-}}[[TRIPLE]].bc"
// CHECK-SAME: "-isystem" {{".*/hipspv/include"}}
// CHECK-SAME: "-fhip-new-launch-api"
-// CHECK-SAME: "-o" [[DEV_BC:".*bc"]]
+// CHECK-SAME: "-o" "[[OBJ_DEV:.*(o|bc)]]"
// CHECK-SAME: "-x" "hip"
-// CHECK: {{".*llvm-link"}} "-o" [[LINK_BC:".*bc"]] [[DEV_BC]]
+// OLD: {{".*llvm-link"}} "-o" [[LINK_BC:".*bc"]] "[[OBJ_DEV]]"
+
+// OLD: {{".*opt"}} [[LINK_BC]] "-load-pass-plugin"
+// OLD-SAME: {{".*/hipspv/lib/libLLVMHipSpvPasses.so"}}
+// OLD-SAME: "-passes=hip-post-link-passes" "-o" [[LOWER_BC:".*bc"]]
+
+// OLD: {{".*llvm-spirv"}} "--spirv-max-version=1.1" "--spirv-ext=+all"
+// OLD-SAME: [[LOWER_BC]] "-o" "[[SPIRV_OUT:.*out]]"
-// CHECK: {{".*opt"}} [[LINK_BC]] "-load-pass-plugin"
-// CHECK-SAME: {{".*/hipspv/lib/libLLVMHipSpvPasses.so"}}
-// CHECK-SAME: "-passes=hip-post-link-passes" "-o" [[LOWER_BC:".*bc"]]
+// OLD: {{".*clang-offload-bundler"}} "-type=o" "-bundle-align=4096"
+// OLD-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-spirv64----generic"
+// OLD-SAME: "-input={{.*}}" "-input=[[SPIRV_OUT]]" "-output=[[BUNDLE:.*hipfb]]"
-// CHECK: {{".*llvm-spirv"}} "--spirv-max-version=1.1" "--spirv-ext=+all"
-// CHECK-SAME: [[LOWER_BC]] "-o" "[[SPIRV_OUT:.*out]]"
+// NEW: {{".*llvm-offload-binary"}} "-o" "[[PACKAGE:.*.out]]"
+// NEW-SAME: "--image=file=[[OBJ_DEV]],triple=[[TRIPLE]],arch=generic,kind=hip"
-// CHECK: {{".*clang-offload-bundler"}} "-type=o" "-bundle-align=4096"
-// CHECK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-spirv64----generic"
-// CHECK-SAME: "-input={{.*}}" "-input=[[SPIRV_OUT]]" "-output=[[BUNDLE:.*hipfb]]"
+// NEW: {{".*clang-linker-wrapper"}} "--device-compiler=[[TRIPLE]]=--hip-path=[[HIP_PATH]]"
+// NEW-SAME: "--emit-fatbin-only" "-o" "[[BUNDLE:.*hipfb]]"
-// CHECK: [[CLANG]] "-cc1" "-triple" {{".*"}} "-aux-triple" "spirv64"
+// CHECK: [[CLANG]] "-cc1" "-triple" {{".*"}} "-aux-triple" "[[TRIPLE]]"
// CHECK-SAME: "-emit-obj"
// CHECK-SAME: "-fcuda-include-gpubinary" "[[BUNDLE]]"
// CHECK-SAME: "-o" [[OBJ_HOST:".*o"]] "-x" "hip"
-// CHECK: {{".*ld.*"}} {{.*}}[[OBJ_HOST]]
+// OLD: {{".*ld.*"}} {{.*}}[[OBJ_HOST]]
+
+// NEW: {{".*clang-linker-wrapper"}}
+// NEW-SAME: "--linker-path={{.*ld.*}}" "-o" "a.out"
+// NEW-SAME: [[OBJ_HOST]]
+
+//------------------------------------------------------------------------------
+// Check the clang command, invoked by the linker wrapper, selects the HIPSPV
+// toolchain for the new offload driver.
+
+// RUN: %clang -cc1 %s -triple spirv64-unknown-chipstar -emit-llvm-bc -o %t.dev.bc
+// RUN: llvm-offload-binary -o %t.dev.out \
+// RUN: --image=file=%t.dev.bc,kind=hip,triple=spirv64-unknown-chipstar,arch=generic
+
+// RUN: clang-linker-wrapper --dry-run \
+// RUN: --device-compiler=spirv64-unknown-chipstar=--hip-path="%S/Inputs/hipspv" \
+// RUN: --host-triple=spirv64-unknown-chipstar \
+// RUN: --linker-path=clang-offload-bundler \
+// RUN: --emit-fatbin-only -o /dev/null %t.dev.out \
+// RUN: 2>&1 | FileCheck %s --check-prefix=WRAPPER -DHIP_PATH=%S/Inputs/hipspv
+
+// WRAPPER: clang{{.*}}" --no-default-config -o {{[^ ]*.img}}
+// WRAPPER-SAME: --target=spirv64-unknown-chipstar
+// WRAPPER-SAME: {{[^ ]*.o}}
+// WRAPPER-SAME: --hip-path=[[HIP_PATH]]
+
+// RUN: touch %t.dummy.o
+// RUN: %clang -### --no-default-config -o %t.dummy.img \
+// RUN: --target=spirv64-unknown-chipstar %t.dummy.o \
+// RUN: --hip-path="%S/Inputs/hipspv" \
+// RUN: 2>&1 | FileCheck %s --check-prefix=CHIPSTAR -DHIP_PATH=%S/Inputs/hipspv
+
+// CHIPSTAR: {{".*llvm-link"}}
+// CHIPSTAR-SAME: "-o" [[LINK_BC:".*bc"]] "{{[^ ]*.o}}"
+
+// CHIPSTAR: {{".*opt"}} [[LINK_BC]] "-load-pass-plugin"
+// CHIPSTAR-SAME: "[[HIP_PATH]]/lib/libLLVMHipSpvPasses.so"
+// CHIPSTAR-SAME: "-passes=hip-post-link-passes" "-o" [[LOWER_BC:".*bc"]]
+
+// CHIPSTAR: {{".*llvm-spirv"}} "--spirv-max-version=1.2"
+// CHIPSTAR-SAME: "--spirv-ext=-all,+SPV_INTEL_function_pointers,+SPV_INTEL_subgroups"
+// CHIPSTAR-SAME: [[LOWER_BC]] "-o" "[[SPIRV_OUT:.*img]]"
+
+// RUN: %clang -### --no-default-config -o %t.dummy.img \
+// RUN: --target=spirv64v1.3-unknown-chipstar \
+// RUN: %t.dummy.o --hip-path="%S/Inputs/hipspv" \
+// RUN: 2>&1 | FileCheck %s --check-prefix=CHIPSTAR-SUBARCH -DHIP_PATH=%S/Inputs/hipspv
+
+// CHIPSTAR-SUBARCH: {{".*llvm-link"}}
+// CHIPSTAR-SUBARCH-SAME: "-o" [[LINK_BC:".*bc"]] "{{[^ ]*.o}}"
+
+// CHIPSTAR-SUBARCH: {{".*opt"}} [[LINK_BC]] "-load-pass-plugin"
+// CHIPSTAR-SUBARCH-SAME: "[[HIP_PATH]]/lib/libLLVMHipSpvPasses.so"
+// CHIPSTAR-SUBARCH-SAME: "-passes=hip-post-link-passes" "-o" [[LOWER_BC:".*bc"]]
+
+// CHIPSTAR-SUBARCH: {{".*llvm-spirv"}}
+// CHIPSTAR-SUBARCH-SAME: "--spirv-ext=-all,+SPV_INTEL_function_pointers,+SPV_INTEL_subgroups"
+// CHIPSTAR-SUBARCH-SAME: [[LOWER_BC]] "-o" "[[SPIRV_OUT:.*img]]"
//-----------------------------------------------------------------------------
// Check llvm-spirv-<LLVM_VERSION_MAJOR> is used if it is found in PATH.
@@ -40,8 +111,13 @@
// RUN: && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
// RUN: env "PATH=%t/versioned" %clang -### -target x86_64-linux-gnu \
// RUN: --offload=spirv64 --hip-path=%S/Inputs/hipspv -nohipwrapperinc \
-// RUN: %s 2>&1 \
+// RUN: --no-offload-new-driver %s 2>&1 \
// RUN: | FileCheck -DVERSION=%llvm-version-major \
// RUN: --check-prefix=VERSIONED %s
+// RUN: env "PATH=%t/versioned" %clang -### --no-default-config \
+// RUN: -o %t.dummy.img --target=spirv64-unknown-chipstar %t.dummy.o \
+// RUN: --hip-path="%S/Inputs/hipspv" -o /dev/null 2>&1 \
+// RUN: | FileCheck -DVERSION=%llvm-version-major --check-prefix=VERSIONED %s
+
// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 48a3c5f97e375..619e539857fc6 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -409,8 +409,19 @@ fatbinary(ArrayRef<std::pair<StringRef, StringRef>> InputFiles,
} // namespace nvptx
namespace amdgcn {
+
+// Constructs a triple string for clang offload bundler.
+// NOTE: copied from HIPUtility.cpp.
+static std::string normalizeForBundler(const llvm::Triple &T,
+ bool HasTargetID) {
+ return HasTargetID ? (T.getArchName() + "-" + T.getVendorName() + "-" +
+ T.getOSName() + "-" + T.getEnvironmentName())
+ .str()
+ : T.normalize(llvm::Triple::CanonicalForm::FOUR_IDENT);
+}
+
Expected<StringRef>
-fatbinary(ArrayRef<std::pair<StringRef, StringRef>> InputFiles,
+fatbinary(ArrayRef<std::tuple<StringRef, StringRef, StringRef>> InputFiles,
const ArgList &Args) {
llvm::TimeTraceScope TimeScope("AMDGPU Fatbinary");
@@ -441,10 +452,10 @@ fatbinary(ArrayRef<std::pair<StringRef, StringRef>> InputFiles,
Args.MakeArgString(Twine("-compression-level=") + Arg->getValue()));
SmallVector<StringRef> Targets = {"-targets=host-x86_64-unknown-linux-gnu"};
- for (const auto &[File, Arch] : InputFiles) {
- Targets.push_back(Saver.save(Arch == "amdgcnspirv"
- ? "hip-spirv64-amd-amdhsa--" + Arch
- : "hip-amdgcn-amd-amdhsa--" + Arch));
+ for (const auto &[File, TripleRef, Arch] : InputFiles) {
+ std::string NormalizedTriple =
+ normalizeForBundler(Triple(TripleRef), !Arch.empty());
+ Targets.push_back(Saver.save("hip-" + NormalizedTriple + "-" + Arch));
}
CmdArgs.push_back(Saver.save(llvm::join(Targets, ",")));
@@ -453,7 +464,7 @@ fatbinary(ArrayRef<std::pair<StringRef, StringRef>> InputFiles,
#else
CmdArgs.push_back("-input=/dev/null");
#endif
- for (const auto &[File, Arch] : InputFiles)
+ for (const auto &[File, Triple, Arch] : InputFiles)
CmdArgs.push_back(Saver.save("-input=" + File));
CmdArgs.push_back(Saver.save("-output=" + *TempFileOrErr));
@@ -816,10 +827,11 @@ bundleCuda(ArrayRef<OffloadingImage> Images, const ArgList &Args) {
Expected<SmallVector<std::unique_ptr<MemoryBuffer>>>
bundleHIP(ArrayRef<OffloadingImage> Images, const ArgList &Args) {
- SmallVector<std::pair<StringRef, StringRef>, 4> InputFiles;
+ SmallVector<std::tuple<StringRef, StringRef, StringRef>, 4> InputFiles;
for (const OffloadingImage &Image : Images)
- InputFiles.emplace_back(std::make_pair(Image.Image->getBufferIdentifier(),
- Image.StringData.lookup("arch")));
+ InputFiles.emplace_back(std::make_tuple(Image.Image->getBufferIdentifier(),
+ Image.StringData.lookup("triple"),
+ Image.StringData.lookup("arch")));
auto FileOrErr = amdgcn::fatbinary(InputFiles, Args);
if (!FileOrErr)
More information about the cfe-commits
mailing list