@@ -4413,10 +4413,6 @@ void Driver::BuildDefaultActions(Compilation &C, DerivedArgList &Args,
44134413 options::OPT_no_offload_new_driver,
44144414 C.isOffloadingHostKind (Action::OFK_Cuda));
44154415
4416- bool HIPNoRDC =
4417- C.isOffloadingHostKind (Action::OFK_HIP) &&
4418- !Args.hasFlag (options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false );
4419-
44204416 // Builder to be used to build offloading actions.
44214417 std::unique_ptr<OffloadingActionBuilder> OffloadBuilder =
44224418 !UseNewOffloadingDriver
@@ -4550,7 +4546,7 @@ void Driver::BuildDefaultActions(Compilation &C, DerivedArgList &Args,
45504546 // Check if this Linker Job should emit a static library.
45514547 if (ShouldEmitStaticLibrary (Args)) {
45524548 LA = C.MakeAction <StaticLibJobAction>(LinkerInputs, types::TY_Image);
4553- } else if (( UseNewOffloadingDriver && !HIPNoRDC) ||
4549+ } else if (UseNewOffloadingDriver ||
45544550 Args.hasArg (options::OPT_offload_link)) {
45554551 LA = C.MakeAction <LinkerWrapperJobAction>(LinkerInputs, types::TY_Image);
45564552 LA->propagateHostOffloadInfo (C.getActiveOffloadKinds (),
@@ -4887,20 +4883,6 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
48874883 << " -fhip-emit-relocatable"
48884884 << " --offload-device-only" ;
48894885
4890- // For HIP non-rdc non-device-only compilation, create a linker wrapper
4891- // action for each host object to link, bundle and wrap device files in
4892- // it.
4893- if ((isa<AssembleJobAction>(HostAction) ||
4894- (isa<BackendJobAction>(HostAction) &&
4895- HostAction->getType () == types::TY_LTO_BC)) &&
4896- HIPNoRDC && !offloadDeviceOnly ()) {
4897- ActionList AL{HostAction};
4898- HostAction = C.MakeAction <LinkerWrapperJobAction>(AL, types::TY_Object);
4899- HostAction->propagateHostOffloadInfo (C.getActiveOffloadKinds (),
4900- /* BoundArch=*/ nullptr );
4901- return HostAction;
4902- }
4903-
49044886 // Don't build offloading actions if we do not have a compile action. If
49054887 // preprocessing only ignore embedding.
49064888 if (!(isa<CompileJobAction>(HostAction) ||
@@ -5065,6 +5047,21 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
50655047 DDep.add (*FatbinAction,
50665048 *C.getOffloadToolChains <Action::OFK_HIP>().first ->second , nullptr ,
50675049 Action::OFK_HIP);
5050+ } else if (HIPNoRDC) {
5051+ // Package all the offloading actions into a single output that can be
5052+ // embedded in the host and linked.
5053+ Action *PackagerAction =
5054+ C.MakeAction <OffloadPackagerJobAction>(OffloadActions, types::TY_Image);
5055+
5056+ // For HIP non-RDC compilation, wrap the device binary with linker wrapper
5057+ // before bundling with host code. Do not bind a specific GPU arch here,
5058+ // as the packaged image may contain entries for multiple GPUs.
5059+ ActionList AL{PackagerAction};
5060+ PackagerAction =
5061+ C.MakeAction <LinkerWrapperJobAction>(AL, types::TY_HIP_FATBIN);
5062+ DDep.add (*PackagerAction,
5063+ *C.getOffloadToolChains <Action::OFK_HIP>().first ->second ,
5064+ /* BoundArch=*/ nullptr , Action::OFK_HIP);
50685065 } else {
50695066 // Package all the offloading actions into a single output that can be
50705067 // embedded in the host and linked.
@@ -5194,6 +5191,14 @@ Action *Driver::ConstructPhaseAction(
51945191 return C.MakeAction <CompileJobAction>(Input, types::TY_LLVM_BC);
51955192 }
51965193 case phases::Backend: {
5194+ // Skip a redundant Backend phase for HIP device code when using the new
5195+ // offload driver, where mid-end is done in linker wrapper.
5196+ if (TargetDeviceOffloadKind == Action::OFK_HIP &&
5197+ Args.hasFlag (options::OPT_offload_new_driver,
5198+ options::OPT_no_offload_new_driver, false ) &&
5199+ !offloadDeviceOnly ())
5200+ return Input;
5201+
51975202 if (isUsingLTO () && TargetDeviceOffloadKind == Action::OFK_None) {
51985203 types::ID Output;
51995204 if (Args.hasArg (options::OPT_ffat_lto_objects) &&
@@ -5213,7 +5218,8 @@ Action *Driver::ConstructPhaseAction(
52135218 if (Args.hasArg (options::OPT_emit_llvm) ||
52145219 TargetDeviceOffloadKind == Action::OFK_SYCL ||
52155220 (((Input->getOffloadingToolChain () &&
5216- Input->getOffloadingToolChain ()->getTriple ().isAMDGPU ()) ||
5221+ Input->getOffloadingToolChain ()->getTriple ().isAMDGPU () &&
5222+ TargetDeviceOffloadKind != Action::OFK_None) ||
52175223 TargetDeviceOffloadKind == Action::OFK_HIP) &&
52185224 ((Args.hasFlag (options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
52195225 false ) ||
0 commit comments