Skip to content

Commit efa25c4

Browse files
authored
[Clang] Fix new driver device only compilation for amdgcnspirv target (llvm#150110)
Summary: This is broken with the current target because it was not bundling the output as HIP likes and this would fail if targeting both at the same time.
1 parent 2147e29 commit efa25c4

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4886,7 +4886,13 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
48864886
// Compiling HIP in device-only non-RDC mode requires linking each action
48874887
// individually.
48884888
for (Action *&A : DeviceActions) {
4889-
if ((A->getType() != types::TY_Object &&
4889+
// Special handling for the HIP SPIR-V toolchain because it doesn't use
4890+
// the SPIR-V backend yet doesn't report the output as an object.
4891+
bool IsAMDGCNSPIRV = A->getOffloadingToolChain() &&
4892+
A->getOffloadingToolChain()->getTriple().getOS() ==
4893+
llvm::Triple::OSType::AMDHSA &&
4894+
A->getOffloadingToolChain()->getTriple().isSPIRV();
4895+
if ((A->getType() != types::TY_Object && !IsAMDGCNSPIRV &&
48904896
A->getType() != types::TY_LTO_BC) ||
48914897
!HIPNoRDC || !offloadDeviceOnly())
48924898
continue;
@@ -4942,8 +4948,9 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
49424948
// fatbinary for each translation unit, linking each input individually.
49434949
Action *FatbinAction =
49444950
C.MakeAction<LinkJobAction>(OffloadActions, types::TY_HIP_FATBIN);
4945-
DDep.add(*FatbinAction, *C.getSingleOffloadToolChain<Action::OFK_HIP>(),
4946-
nullptr, Action::OFK_HIP);
4951+
DDep.add(*FatbinAction,
4952+
*C.getOffloadToolChains<Action::OFK_HIP>().first->second, nullptr,
4953+
Action::OFK_HIP);
49474954
} else {
49484955
// Package all the offloading actions into a single output that can be
49494956
// embedded in the host and linked.

clang/test/Driver/hip-phases.hip

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,3 +675,26 @@
675675
// DEVICE-ONLY-NEXT: 2: compiler, {1}, ir, (device-hip, gfx90a)
676676
// DEVICE-ONLY-NEXT: 3: backend, {2}, ir, (device-hip, gfx90a)
677677
// DEVICE-ONLY-NEXT: 4: offload, "device-hip (amdgcn-amd-amdhsa:gfx90a)" {3}, none
678+
679+
//
680+
// Test the new driver when not bundling
681+
//
682+
// RUN: %clang -### --target=x86_64-linux-gnu --offload-new-driver -ccc-print-phases \
683+
// RUN: --offload-device-only --offload-arch=amdgcnspirv,gfx1030 %s 2>&1 \
684+
// RUN: | FileCheck -check-prefix=SPIRV-ONLY %s
685+
// SPIRV-ONLY: 0: input, "[[INPUT:.+]]", hip, (device-hip, gfx1030)
686+
// SPIRV-ONLY-NEXT: 1: preprocessor, {0}, hip-cpp-output, (device-hip, gfx1030)
687+
// SPIRV-ONLY-NEXT: 2: compiler, {1}, ir, (device-hip, gfx1030)
688+
// SPIRV-ONLY-NEXT: 3: backend, {2}, assembler, (device-hip, gfx1030)
689+
// SPIRV-ONLY-NEXT: 4: assembler, {3}, object, (device-hip, gfx1030)
690+
// SPIRV-ONLY-NEXT: 5: linker, {4}, image, (device-hip, gfx1030)
691+
// SPIRV-ONLY-NEXT: 6: offload, "device-hip (amdgcn-amd-amdhsa:gfx1030)" {5}, image
692+
// SPIRV-ONLY-NEXT: 7: input, "[[INPUT]]", hip, (device-hip, amdgcnspirv)
693+
// SPIRV-ONLY-NEXT: 8: preprocessor, {7}, hip-cpp-output, (device-hip, amdgcnspirv)
694+
// SPIRV-ONLY-NEXT: 9: compiler, {8}, ir, (device-hip, amdgcnspirv)
695+
// SPIRV-ONLY-NEXT: 10: backend, {9}, assembler, (device-hip, amdgcnspirv)
696+
// SPIRV-ONLY-NEXT: 11: assembler, {10}, object, (device-hip, amdgcnspirv)
697+
// SPIRV-ONLY-NEXT: 12: linker, {11}, image, (device-hip, amdgcnspirv)
698+
// SPIRV-ONLY-NEXT: 13: offload, "device-hip (spirv64-amd-amdhsa:amdgcnspirv)" {12}, image
699+
// SPIRV-ONLY-NEXT: 14: linker, {6, 13}, hip-fatbin, (device-hip)
700+
// SPIRV-ONLY-NEXT: 15: offload, "device-hip (amdgcn-amd-amdhsa)" {14}, none

0 commit comments

Comments
 (0)