Skip to content

Commit 357f00d

Browse files
authored
[HIP] Correctly omit bundling with the new driver (#85842)
Summary: The HIP phases do not emit the offload bundler output when we do not invoke the final linker phase in device only mode. Check this propery.
1 parent 81ec95f commit 357f00d

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4645,13 +4645,17 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
46454645
}
46464646
}
46474647

4648+
// HIP code in non-RDC mode will bundle the output if it invoked the linker.
4649+
bool ShouldBundleHIP =
4650+
C.isOffloadingHostKind(Action::OFK_HIP) &&
4651+
Args.hasFlag(options::OPT_gpu_bundle_output,
4652+
options::OPT_no_gpu_bundle_output, true) &&
4653+
!Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false) &&
4654+
!llvm::any_of(OffloadActions,
4655+
[](Action *A) { return A->getType() != types::TY_Image; });
4656+
46484657
// All kinds exit now in device-only mode except for non-RDC mode HIP.
4649-
if (offloadDeviceOnly() &&
4650-
(getFinalPhase(Args) == phases::Preprocess ||
4651-
!C.isOffloadingHostKind(Action::OFK_HIP) ||
4652-
!Args.hasFlag(options::OPT_gpu_bundle_output,
4653-
options::OPT_no_gpu_bundle_output, true) ||
4654-
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false)))
4658+
if (offloadDeviceOnly() && !ShouldBundleHIP)
46554659
return C.MakeAction<OffloadAction>(DDeps, types::TY_Nothing);
46564660

46574661
if (OffloadActions.empty())

clang/test/Driver/hip-phases.hip

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,3 +648,15 @@
648648
// LTO-NEXT: 14: offload, "host-hip (x86_64-unknown-linux-gnu)" {2}, "device-hip (x86_64-unknown-linux-gnu)" {13}, ir
649649
// LTO-NEXT: 15: backend, {14}, assembler, (host-hip)
650650
// LTO-NEXT: 16: assembler, {15}, object, (host-hip)
651+
652+
//
653+
// Test the new driver when not bundling
654+
//
655+
// RUN: %clang -### --target=x86_64-linux-gnu --offload-new-driver -ccc-print-phases \
656+
// RUN: --offload-device-only --offload-arch=gfx90a -emit-llvm -c %s 2>&1 \
657+
// RUN: | FileCheck -check-prefix=DEVICE-ONLY %s
658+
// DEVICE-ONLY: 0: input, "[[INPUT:.+]]", hip, (device-hip, gfx90a)
659+
// DEVICE-ONLY-NEXT: 1: preprocessor, {0}, hip-cpp-output, (device-hip, gfx90a)
660+
// DEVICE-ONLY-NEXT: 2: compiler, {1}, ir, (device-hip, gfx90a)
661+
// DEVICE-ONLY-NEXT: 3: backend, {2}, ir, (device-hip, gfx90a)
662+
// DEVICE-ONLY-NEXT: 4: offload, "device-hip (amdgcn-amd-amdhsa:gfx90a)" {3}, none

0 commit comments

Comments
 (0)