aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Driver/Driver.cpp
diff options
context:
space:
mode:
authorJoseph Huber <jhuber6@vols.utk.edu>2022-07-14 11:46:43 -0400
committerJoseph Huber <jhuber6@vols.utk.edu>2022-07-20 16:52:23 -0400
commit0c1b32717bcffcf8edf95294e98933bd4c1e76ed (patch)
tree15f27b5320d1f569facae379fe02af4dfea2cdd7 /clang/lib/Driver/Driver.cpp
parentbc4d2e70518476f0a445761d43fee8b9e6670368 (diff)
downloadllvm-0c1b32717bcffcf8edf95294e98933bd4c1e76ed.zip
llvm-0c1b32717bcffcf8edf95294e98933bd4c1e76ed.tar.gz
llvm-0c1b32717bcffcf8edf95294e98933bd4c1e76ed.tar.bz2
[HIP] Allow the new driver to compile HIP in non-RDC mode
The new driver primarily allows us to support RDC-mode compilations with proper linking. This is not needed for non-RDC mode compilation, but we still would like the new driver to be able to handle this mode so we can transition away from the old driver in the future. This patch adds the necessary code to support creating a fatbinary for HIP code generation. Reviewed By: yaxunl Differential Revision: https://reviews.llvm.org/D129784
Diffstat (limited to 'clang/lib/Driver/Driver.cpp')
-rw-r--r--clang/lib/Driver/Driver.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e50fdd6..3f29afd 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4478,6 +4478,15 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
}
}
+ // Compiling HIP in non-RDC mode requires linking each action individually.
+ for (Action *&A : DeviceActions) {
+ if (A->getType() != types::TY_Object || Kind != Action::OFK_HIP ||
+ Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false))
+ continue;
+ ActionList LinkerInput = {A};
+ A = C.MakeAction<LinkJobAction>(LinkerInput, types::TY_Image);
+ }
+
auto TCAndArch = TCAndArchs.begin();
for (Action *A : DeviceActions) {
DDeps.add(*A, *TCAndArch->first, TCAndArch->second.data(), Kind);
@@ -4497,12 +4506,21 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
OffloadAction::DeviceDependences DDep;
if (C.isOffloadingHostKind(Action::OFK_Cuda) &&
!Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false)) {
- // If we are not in RDC-mode we just emit the final CUDA fatbinary for each
- // translation unit without requiring any linking.
+ // If we are not in RDC-mode we just emit the final CUDA fatbinary for
+ // each translation unit without requiring any linking.
Action *FatbinAction =
C.MakeAction<LinkJobAction>(OffloadActions, types::TY_CUDA_FATBIN);
DDep.add(*FatbinAction, *C.getSingleOffloadToolChain<Action::OFK_Cuda>(),
nullptr, Action::OFK_Cuda);
+ } else if (C.isOffloadingHostKind(Action::OFK_HIP) &&
+ !Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
+ false)) {
+ // If we are not in RDC-mode we just emit the final HIP fatbinary for each
+ // translation unit, linking each input individually.
+ Action *FatbinAction =
+ C.MakeAction<LinkJobAction>(OffloadActions, types::TY_HIP_FATBIN);
+ DDep.add(*FatbinAction, *C.getSingleOffloadToolChain<Action::OFK_HIP>(),
+ nullptr, Action::OFK_HIP);
} else {
// Package all the offloading actions into a single output that can be
// embedded in the host and linked.
@@ -4511,6 +4529,7 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
DDep.add(*PackagerAction, *C.getSingleOffloadToolChain<Action::OFK_Host>(),
nullptr, Action::OFK_None);
}
+
OffloadAction::HostDependence HDep(
*HostAction, *C.getSingleOffloadToolChain<Action::OFK_Host>(),
/*BoundArch=*/nullptr, isa<CompileJobAction>(HostAction) ? DDep : DDeps);