Henry =?utf-8?q?Linjamäki?= <[email protected]>,
Henry =?utf-8?q?Linjamäki?= <[email protected]>,
Henry =?utf-8?q?Linjamäki?= <[email protected]>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/[email protected]>


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Henry Linjamäki (linehill)

<details>
<summary>Changes</summary>

Update HIPSPV toolchain to support `--offload-new-driver`. Additionally,  
tailor `llvm-spirv` invocation for 
[chipStar](https://github.com/CHIP-SPV/chipStar) via `spirv64-*-chipstar` 
offload triple.


---

Patch is 38.98 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/168043.diff


12 Files Affected:

- (modified) clang/include/clang/Options/Options.td (+4) 
- (modified) clang/lib/Driver/Driver.cpp (+14-2) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+9-5) 
- (modified) clang/lib/Driver/ToolChains/HIPSPV.cpp (+59-11) 
- (modified) clang/lib/Driver/ToolChains/HIPSPV.h (+5-2) 
- (added) 
clang/test/Driver/Inputs/hipspv/lib/hip-device-lib/hipspv-spirv64-unknown-hipspv.bc
 () 
- (modified) clang/test/Driver/hipspv-link-static-library.hip (+26-10) 
- (modified) clang/test/Driver/hipspv-pass-plugin.hip (+34-8) 
- (added) clang/test/Driver/hipspv-toolchain-rdc-separate.hip (+66) 
- (modified) clang/test/Driver/hipspv-toolchain-rdc.hip (+100-44) 
- (modified) clang/test/Driver/hipspv-toolchain.hip (+108-16) 
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+21-9) 


``````````diff
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 756d6deed7130..41313439705cf 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -1003,6 +1003,10 @@ def Xthinlto_distributor_EQ : CommaJoined<["-"], 
"Xthinlto-distributor=">,
            "multiple times or with comma-separated values.">,
   MetaVarName<"<arg>">,
   Group<Link_Group>;
+def Xoffload_compiler : JoinedAndSeparate<["-"], "Xoffload-compiler">,
+  Visibility<[ClangOption, FlangOption]>,
+  HelpText<"Pass <arg> to the offload compilers or the ones identified by 
-<triple>">,
+  MetaVarName<"<triple> <arg>">, Group<Link_Group>;
 def Xoffload_linker : JoinedAndSeparate<["-"], "Xoffload-linker">,
   Visibility<[ClangOption, FlangOption]>,
   HelpText<"Pass <arg> to the offload linkers or the ones identified by 
-<triple>">,
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 8644a271a04b5..28c402d2cf6c8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4991,6 +4991,12 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
     // Compiling HIP in device-only non-RDC mode requires linking each action
     // individually.
     for (Action *&A : DeviceActions) {
+      auto OsName = A->getOffloadingToolChain()
+                        ? A->getOffloadingToolChain()->getTriple().getOSName()
+                        : StringRef();
+      bool IsHIPSPV = A->getOffloadingToolChain() &&
+                      A->getOffloadingToolChain()->getTriple().isSPIRV() &&
+                      (OsName == "hipspv" || OsName == "chipstar");
       bool IsAMDGCNSPIRV = A->getOffloadingToolChain() &&
                            A->getOffloadingToolChain()->getTriple().getOS() ==
                                llvm::Triple::OSType::AMDHSA &&
@@ -4999,13 +5005,13 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
                                           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;
 
-      if ((A->getType() != types::TY_Object && !IsAMDGCNSPIRV &&
+      if ((A->getType() != types::TY_Object && !IsAMDGCNSPIRV && !IsHIPSPV &&
            A->getType() != types::TY_LTO_BC) ||
           HIPRelocatableObj || !HIPNoRDC || !offloadDeviceOnly() ||
           (IsAMDGCNSPIRVWithBackend && offloadDeviceOnly()))
@@ -7039,6 +7045,12 @@ const ToolChain &Driver::getToolChain(const ArgList 
&Args,
         break;
       case llvm::Triple::spirv32:
       case llvm::Triple::spirv64:
+        if (Target.getOSName() == "hipspv" ||
+            Target.getOSName() == "chipstar") {
+          TC = std::make_unique<toolchains::HIPSPVToolChain>(*this, Target,
+                                                             Args);
+          break;
+        }
         TC = std::make_unique<toolchains::SPIRVToolChain>(*this, Target, Args);
         break;
       case llvm::Triple::csky:
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 0380568412e62..feb28e380ee2b 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9069,6 +9069,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,
@@ -9198,18 +9199,21 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
   Linker->ConstructJob(C, JA, Output, Inputs, Args, LinkingOutput);
   const auto &LinkCommand = C.getJobs().getJobs().back();
 
-  // Forward -Xoffload-linker<-triple> arguments to the device link job.
-  for (Arg *A : Args.filtered(options::OPT_Xoffload_linker)) {
+  for (Arg *A :
+       Args.filtered(options::OPT_Xoffload_compiler, OPT_Xoffload_linker)) {
     StringRef Val = A->getValue(0);
+    bool IsLinkJob = A->getOption().getID() == OPT_Xoffload_linker;
+    auto WrapperOption =
+        IsLinkJob ? Twine("--device-linker=") : Twine("--device-compiler=");
     if (Val.empty())
-      CmdArgs.push_back(
-          Args.MakeArgString(Twine("--device-linker=") + A->getValue(1)));
+      CmdArgs.push_back(Args.MakeArgString(WrapperOption + A->getValue(1)));
     else
       CmdArgs.push_back(Args.MakeArgString(
-          "--device-linker=" +
+          WrapperOption +
           ToolChain::getOpenMPTriple(Val.drop_front()).getTriple() + "=" +
           A->getValue(1)));
   }
+  Args.ClaimAllArgs(options::OPT_Xoffload_compiler);
   Args.ClaimAllArgs(options::OPT_Xoffload_linker);
 
   // Embed bitcode instead of an object in JIT mode.
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp 
b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index be0f49d8e1497..d16778d45af86 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -93,9 +93,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.getOSName() == "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);
 }
@@ -119,7 +137,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);
@@ -128,7 +155,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.");
@@ -159,27 +193,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,
@@ -273,12 +317,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-hipspv.bc
 
b/clang/test/Driver/Inputs/hipspv/lib/hip-device-lib/hipspv-spirv64-unknown-hipspv.bc
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/hipspv-link-static-library.hip 
b/clang/test/Driver/hipspv-link-static-library.hip
index 03126ae589a09..41895f3c936c1 100644
--- a/clang/test/Driver/hipspv-link-static-library.hip
+++ b/clang/test/Driver/hipspv-link-static-library.hip
@@ -4,25 +4,41 @@
 
 // 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=ALL,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=ALL,SDL %s
+
+// RUN: %clang --offload-new-driver -fgpu-rdc --offload=spirv64-unknown-hipspv 
\
+// RUN:   -nogpuinc -nogpulib %s -c -o %t/tu0.o
+// RUN: %clang --offload-new-driver -fgpu-rdc --offload=spirv64-unknown-hipspv 
\
+// RUN:   -nogpuinc -nogpulib %s -c -o %t/tu1.o
+// RUN: llvm-ar cr %t/libSDL2.a %t/tu1.o
+
+// RUN: %clang --offload-new-driver -fgpu-rdc \
+// RUN:   -Xoffload-compiler-spirv64-unknown-hipspv \
+// RUN:   --hip-path=%S/Inputs/hipspv -no-hip-rt %t/tu0.o %t/libSDL2.a \
+// A hacky trick to print clang commands invoked by clang-linker-wrapper
+// RUN:   -v -Xlinker --emit-fatbin-only -Xoffload-compiler '-###' \
+// RUN: 2>&1 | FileCheck -check-prefixes=ALL,SDL-NEW %s
 
 // 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" "{{.*}}.bc" "[[SDL_A]]" "-o"
+// 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" "{{.*}}.bc" "[[SDL_A]]" "-o"
+// SDL-NEW: "{{.*}}clang-linker-wrapper"
+// SDL-NEW: "{{.*}}llvm-link" "{{.*}}.o" "{{.*}}.o"
 
-// 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" "{{.*}}.bc" "[[SDL_A]]" "-o"
+// ALL: "{{.*}}opt"
+// ALL-SAME: "-load-pass-plugin" {{".*/hipspv/lib/libLLVMHipSpvPasses.so"}}
+// ALL-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..c348fce15fa5e 100644
--- a/clang/test/Driver/hipspv-pass-plugin.hip
+++ b/clang/test/Driver/hipspv-pass-plugin.hip
@@ -1,20 +1,45 @@
 // 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: %clang --offload-new-driver -nogpuinc -nogpulib \
+// RUN:   --offload=spirv64-unknown-hipspv \
+// RUN:   --hip-path=%S/Inputs/hipspv -Xoffload-compiler \
+// RUN:   '-###' -c %s -o /dev/null 2>&1 \
+// RUN: | FileCheck %s --check-prefixes=ALL,FROM-HIP-PATH
+
+// RUN: %clang --offload-new-driver -nogpuinc -nogpulib \
+// RUN:   --offload=spirv64-unknown-hipspv \
+// RUN:   -Xoffload-compiler-spirv64-unknown-hipspv \
+// RUN:   --hipspv-pass-plugin=%S/Inputs/pass-plugin.so -Xoffload-compiler \
+// RUN:   '-###' -c %s -o /dev/null 2>&1 \
+// RUN: | FileCheck %s --check-prefixes=ALL,FROM-OPTION
+
+// RUN: not %clang --offload-new-driver -nogpuinc -nogpulib \
+// RUN:   --offload=spirv64-unknown-hipspv \
+// RUN:   -Xoffload-compiler-spirv64-unknown-hipspv \
+// RUN:   --hipspv-pass-plugin=foo.so -Xoffload-compiler \
+// RUN:   '-###' -c %s -o /dev/null 2>&1 \
+// RUN: | FileCheck %s --check-prefixes=ALL,FROM-OPTION-INVALID
+
+// RUN: %clang --offload-new-driver -nogpuinc -nogpulib \
+// RUN:   --offload=spirv64-unknown-hipspv -Xoffload-compiler \
+// RUN:   '-###' -c %s -o /dev/null 2>&1 \
+// RUN: | 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 +48,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..1d269bec7d7a4
--- /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-hipspv --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-hipspv"
+// CHECK-SAME: "-aux-triple" "[[HOST_TRIPLE:[^ ]*]]"
+// CHECK-SAME: "-emit-llvm-bc"
+// CHECK-SAME: "-fcuda-is-device" "-fcuda-allow-variadic-functions"
+// CHECK-SAME: "-fvisibility=hidden" "-fapply-global-visibility-to-externs"
+// CHECK-SAME: "-mlink-builtin-bitcode" 
"[[HIP_PATH]]/lib/hip-device-lib/hipspv-spirv64-unknown-hipspv.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-hipspv,arch=generic,kind=hip"
+
+// CHECK: [[CLANG]] "-cc1" "-triple" "[[HOST_TRIPLE]]"
+// CHECK-SAME: "-aux-triple" "spirv64-unknown-hipspv"
+// 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-hipspv"
+// CHECK-SAME: "-aux-triple" "[[HOST_TRIPLE]]"
+// CHECK-SAME: "-emit-llvm-bc"
+// CHECK-SAME: "-fcuda-is-device" "-fcuda-allow-variadic-functions"
+// CHECK-SAME: "-fvisibility=hidden" "-fapply-global-visibility-to-externs"
+// CHECK-SAME: "-mlink-builtin-bitcode" 
"[[HIP_PATH]]/lib/hip-device-lib/hipspv-spirv64-unknown-hipspv.bc"
+// CHECK-SAME: "-fgpu-rdc"
+// CHECK-SAME: "-o" "[[B_DEV_BC:.*bc]]" "-x" "hip"
+// CHECK-SAME: "[[B_SRC:.*b.hip]]"
+
+...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/168043
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to