[HIP] Let clang-offload-bundler support HIP
authorYaxun Liu <Yaxun.Liu@amd.com>
Fri, 11 May 2018 19:02:18 +0000 (19:02 +0000)
committerYaxun Liu <Yaxun.Liu@amd.com>
Fri, 11 May 2018 19:02:18 +0000 (19:02 +0000)
When bundle/unbundle intermediate files for HIP, there may be multiple
sub archs, therefore BoundArch needs to be included in the target
and output file names for clang-offload-bundler.

Differential Revision: https://reviews.llvm.org/D46473

llvm-svn: 332121

clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

index f84decf..6bedfbf 100644 (file)
@@ -3736,9 +3736,12 @@ InputInfo Driver::BuildJobsForActionNoCache(
           UI.DependentToolChain->getTriple().normalize(),
           /*CreatePrefixForHost=*/true);
       auto CurI = InputInfo(
-          UA, GetNamedOutputPath(C, *UA, BaseInput, UI.DependentBoundArch,
-                                 /*AtTopLevel=*/false, MultipleArchs,
-                                 OffloadingPrefix),
+          UA,
+          GetNamedOutputPath(C, *UA, BaseInput, UI.DependentBoundArch,
+                             /*AtTopLevel=*/false,
+                             MultipleArchs ||
+                                 UI.DependentOffloadKind == Action::OFK_HIP,
+                             OffloadingPrefix),
           BaseInput);
       // Save the unbundling result.
       UnbundlingResults.push_back(CurI);
index cc26b5e..2b4bdfa 100644 (file)
@@ -5542,6 +5542,10 @@ void OffloadBundler::ConstructJob(Compilation &C, const JobAction &JA,
     Triples += Action::GetOffloadKindName(CurKind);
     Triples += '-';
     Triples += CurTC->getTriple().normalize();
+    if (CurKind == Action::OFK_HIP && CurDep->getOffloadingArch()) {
+      Triples += '-';
+      Triples += CurDep->getOffloadingArch();
+    }
   }
   CmdArgs.push_back(TCArgs.MakeArgString(Triples));
 
@@ -5611,6 +5615,11 @@ void OffloadBundler::ConstructJobMultipleOutputs(
     Triples += Action::GetOffloadKindName(Dep.DependentOffloadKind);
     Triples += '-';
     Triples += Dep.DependentToolChain->getTriple().normalize();
+    if (Dep.DependentOffloadKind == Action::OFK_HIP &&
+        !Dep.DependentBoundArch.empty()) {
+      Triples += '-';
+      Triples += Dep.DependentBoundArch;
+    }
   }
 
   CmdArgs.push_back(TCArgs.MakeArgString(Triples));
index 259a3e8..d9fb389 100644 (file)
@@ -969,11 +969,11 @@ int main(int argc, const char **argv) {
     getOffloadKindAndTriple(Target, Kind, Triple);
 
     bool KindIsValid = !Kind.empty();
-    KindIsValid = KindIsValid &&
-                  StringSwitch<bool>(Kind)
-                      .Case("host", true)
-                      .Case("openmp", true)
-                      .Default(false);
+    KindIsValid = KindIsValid && StringSwitch<bool>(Kind)
+                                     .Case("host", true)
+                                     .Case("openmp", true)
+                                     .Case("hip", true)
+                                     .Default(false);
 
     bool TripleIsValid = !Triple.empty();
     llvm::Triple T(Triple);