@@ -4405,6 +4405,10 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
44054405 options::OPT_no_offload_new_driver,
44064406 C.isOffloadingHostKind (Action::OFK_Cuda));
44074407
4408+ bool HIPNoRDC =
4409+ C.isOffloadingHostKind (Action::OFK_HIP) &&
4410+ !Args.hasFlag (options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false );
4411+
44084412 // Builder to be used to build offloading actions.
44094413 std::unique_ptr<OffloadingActionBuilder> OffloadBuilder =
44104414 !UseNewOffloadingDriver
@@ -4538,7 +4542,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
45384542 // Check if this Linker Job should emit a static library.
45394543 if (ShouldEmitStaticLibrary (Args)) {
45404544 LA = C.MakeAction <StaticLibJobAction>(LinkerInputs, types::TY_Image);
4541- } else if (UseNewOffloadingDriver ||
4545+ } else if (( UseNewOffloadingDriver && !HIPNoRDC) ||
45424546 Args.hasArg (options::OPT_offload_link)) {
45434547 LA = C.MakeAction <LinkerWrapperJobAction>(LinkerInputs, types::TY_Image);
45444548 LA->propagateHostOffloadInfo (C.getActiveOffloadKinds (),
@@ -4849,10 +4853,28 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
48494853 const InputTy &Input, StringRef CUID,
48504854 Action *HostAction) const {
48514855 // Don't build offloading actions if explicitly disabled or we do not have a
4852- // valid source input and compile action to embed it in. If preprocessing only
4853- // ignore embedding.
4854- if (offloadHostOnly () || !types::isSrcFile (Input.first ) ||
4855- !(isa<CompileJobAction>(HostAction) ||
4856+ // valid source input.
4857+ if (offloadHostOnly () || !types::isSrcFile (Input.first ))
4858+ return HostAction;
4859+
4860+ bool HIPNoRDC =
4861+ C.isOffloadingHostKind (Action::OFK_HIP) &&
4862+ !Args.hasFlag (options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false );
4863+
4864+ // For HIP non-rdc non-device-only compilation, create a linker wrapper
4865+ // action for each host object to link, bundle and wrap device files in
4866+ // it.
4867+ if (isa<AssembleJobAction>(HostAction) && HIPNoRDC && !offloadDeviceOnly ()) {
4868+ ActionList AL{HostAction};
4869+ HostAction = C.MakeAction <LinkerWrapperJobAction>(AL, types::TY_Object);
4870+ HostAction->propagateHostOffloadInfo (C.getActiveOffloadKinds (),
4871+ /* BoundArch=*/ nullptr );
4872+ return HostAction;
4873+ }
4874+
4875+ // Don't build offloading actions if we do not have a compile action. If
4876+ // preprocessing only ignore embedding.
4877+ if (!(isa<CompileJobAction>(HostAction) ||
48564878 getFinalPhase (Args) == phases::Preprocess))
48574879 return HostAction;
48584880
@@ -4948,12 +4970,12 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
49484970 }
49494971 }
49504972
4951- // Compiling HIP in non-RDC mode requires linking each action individually.
4973+ // Compiling HIP in device-only non-RDC mode requires linking each action
4974+ // individually.
49524975 for (Action *&A : DeviceActions) {
49534976 if ((A->getType () != types::TY_Object &&
49544977 A->getType () != types::TY_LTO_BC) ||
4955- Kind != Action::OFK_HIP ||
4956- Args.hasFlag (options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false ))
4978+ !HIPNoRDC || !offloadDeviceOnly ())
49574979 continue ;
49584980 ActionList LinkerInput = {A};
49594981 A = C.MakeAction <LinkJobAction>(LinkerInput, types::TY_Image);
@@ -4977,12 +4999,12 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
49774999 }
49785000 }
49795001
4980- // HIP code in non-RDC mode will bundle the output if it invoked the linker.
5002+ // HIP code in device-only non-RDC mode will bundle the output if it invoked
5003+ // the linker.
49815004 bool ShouldBundleHIP =
4982- C. isOffloadingHostKind (Action::OFK_HIP ) &&
5005+ HIPNoRDC && offloadDeviceOnly ( ) &&
49835006 Args.hasFlag (options::OPT_gpu_bundle_output,
49845007 options::OPT_no_gpu_bundle_output, true ) &&
4985- !Args.hasFlag (options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false ) &&
49865008 !llvm::any_of (OffloadActions,
49875009 [](Action *A) { return A->getType () != types::TY_Image; });
49885010
@@ -5002,11 +5024,9 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
50025024 C.MakeAction <LinkJobAction>(OffloadActions, types::TY_CUDA_FATBIN);
50035025 DDep.add (*FatbinAction, *C.getSingleOffloadToolChain <Action::OFK_Cuda>(),
50045026 nullptr , Action::OFK_Cuda);
5005- } else if (C.isOffloadingHostKind (Action::OFK_HIP) &&
5006- !Args.hasFlag (options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
5007- false )) {
5008- // If we are not in RDC-mode we just emit the final HIP fatbinary for each
5009- // translation unit, linking each input individually.
5027+ } else if (HIPNoRDC && offloadDeviceOnly ()) {
5028+ // If we are in device-only non-RDC-mode we just emit the final HIP
5029+ // fatbinary for each translation unit, linking each input individually.
50105030 Action *FatbinAction =
50115031 C.MakeAction <LinkJobAction>(OffloadActions, types::TY_HIP_FATBIN);
50125032 DDep.add (*FatbinAction, *C.getSingleOffloadToolChain <Action::OFK_HIP>(),
@@ -5159,8 +5179,11 @@ Action *Driver::ConstructPhaseAction(
51595179 (((Input->getOffloadingToolChain () &&
51605180 Input->getOffloadingToolChain ()->getTriple ().isAMDGPU ()) ||
51615181 TargetDeviceOffloadKind == Action::OFK_HIP) &&
5162- (Args.hasFlag (options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
5163- false ) ||
5182+ ((Args.hasFlag (options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
5183+ false ) ||
5184+ (Args.hasFlag (options::OPT_offload_new_driver,
5185+ options::OPT_no_offload_new_driver, false ) &&
5186+ !offloadDeviceOnly ())) ||
51645187 TargetDeviceOffloadKind == Action::OFK_OpenMP))) {
51655188 types::ID Output =
51665189 Args.hasArg (options::OPT_S) &&
0 commit comments