diff options
author | Joseph Huber <huberjn@outlook.com> | 2025-07-23 07:55:10 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-23 07:55:10 -0500 |
commit | efa25c4737440887772e6c6ed72029afa0bf05ca (patch) | |
tree | 6b0bdf2a7ea0dd82748d1df51e93151241d63983 | |
parent | 2147e29f641f22822e2b0e10c978b28b06db1aeb (diff) | |
download | llvm-efa25c4737440887772e6c6ed72029afa0bf05ca.zip llvm-efa25c4737440887772e6c6ed72029afa0bf05ca.tar.gz llvm-efa25c4737440887772e6c6ed72029afa0bf05ca.tar.bz2 |
[Clang] Fix new driver device only compilation for `amdgcnspirv` target (#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.
-rw-r--r-- | clang/lib/Driver/Driver.cpp | 13 | ||||
-rw-r--r-- | clang/test/Driver/hip-phases.hip | 23 |
2 files changed, 33 insertions, 3 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index d8038b1..ef5af66 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4886,7 +4886,13 @@ Action *Driver::BuildOffloadingActions(Compilation &C, // Compiling HIP in device-only non-RDC mode requires linking each action // individually. for (Action *&A : DeviceActions) { - if ((A->getType() != types::TY_Object && + // Special handling for the HIP SPIR-V toolchain because it doesn't use + // the SPIR-V backend yet doesn't report the output as an object. + bool IsAMDGCNSPIRV = A->getOffloadingToolChain() && + A->getOffloadingToolChain()->getTriple().getOS() == + llvm::Triple::OSType::AMDHSA && + A->getOffloadingToolChain()->getTriple().isSPIRV(); + if ((A->getType() != types::TY_Object && !IsAMDGCNSPIRV && A->getType() != types::TY_LTO_BC) || !HIPNoRDC || !offloadDeviceOnly()) continue; @@ -4942,8 +4948,9 @@ Action *Driver::BuildOffloadingActions(Compilation &C, // 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); + DDep.add(*FatbinAction, + *C.getOffloadToolChains<Action::OFK_HIP>().first->second, nullptr, + Action::OFK_HIP); } else { // Package all the offloading actions into a single output that can be // embedded in the host and linked. diff --git a/clang/test/Driver/hip-phases.hip b/clang/test/Driver/hip-phases.hip index d8a58b7..f4d3e9d 100644 --- a/clang/test/Driver/hip-phases.hip +++ b/clang/test/Driver/hip-phases.hip @@ -675,3 +675,26 @@ // DEVICE-ONLY-NEXT: 2: compiler, {1}, ir, (device-hip, gfx90a) // DEVICE-ONLY-NEXT: 3: backend, {2}, ir, (device-hip, gfx90a) // DEVICE-ONLY-NEXT: 4: offload, "device-hip (amdgcn-amd-amdhsa:gfx90a)" {3}, none + +// +// Test the new driver when not bundling +// +// RUN: %clang -### --target=x86_64-linux-gnu --offload-new-driver -ccc-print-phases \ +// RUN: --offload-device-only --offload-arch=amdgcnspirv,gfx1030 %s 2>&1 \ +// RUN: | FileCheck -check-prefix=SPIRV-ONLY %s +// SPIRV-ONLY: 0: input, "[[INPUT:.+]]", hip, (device-hip, gfx1030) +// SPIRV-ONLY-NEXT: 1: preprocessor, {0}, hip-cpp-output, (device-hip, gfx1030) +// SPIRV-ONLY-NEXT: 2: compiler, {1}, ir, (device-hip, gfx1030) +// SPIRV-ONLY-NEXT: 3: backend, {2}, assembler, (device-hip, gfx1030) +// SPIRV-ONLY-NEXT: 4: assembler, {3}, object, (device-hip, gfx1030) +// SPIRV-ONLY-NEXT: 5: linker, {4}, image, (device-hip, gfx1030) +// SPIRV-ONLY-NEXT: 6: offload, "device-hip (amdgcn-amd-amdhsa:gfx1030)" {5}, image +// SPIRV-ONLY-NEXT: 7: input, "[[INPUT]]", hip, (device-hip, amdgcnspirv) +// SPIRV-ONLY-NEXT: 8: preprocessor, {7}, hip-cpp-output, (device-hip, amdgcnspirv) +// SPIRV-ONLY-NEXT: 9: compiler, {8}, ir, (device-hip, amdgcnspirv) +// SPIRV-ONLY-NEXT: 10: backend, {9}, assembler, (device-hip, amdgcnspirv) +// SPIRV-ONLY-NEXT: 11: assembler, {10}, object, (device-hip, amdgcnspirv) +// SPIRV-ONLY-NEXT: 12: linker, {11}, image, (device-hip, amdgcnspirv) +// SPIRV-ONLY-NEXT: 13: offload, "device-hip (spirv64-amd-amdhsa:amdgcnspirv)" {12}, image +// SPIRV-ONLY-NEXT: 14: linker, {6, 13}, hip-fatbin, (device-hip) +// SPIRV-ONLY-NEXT: 15: offload, "device-hip (amdgcn-amd-amdhsa)" {14}, none |