https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/150110
>From 0ecf210da52497e070433120f47724232dbd36a3 Mon Sep 17 00:00:00 2001 From: Joseph Huber <hube...@outlook.com> Date: Tue, 22 Jul 2025 16:07:04 -0500 Subject: [PATCH] [Clang] Fix new driver device only compilation for `amdgcnspirv` target 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. --- clang/lib/Driver/Driver.cpp | 13 ++++++++++--- 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 ff2f92d1a94c8..bca2810c8b3fd 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4885,7 +4885,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; @@ -4941,8 +4947,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 d8a58b78d6d5c..f4d3e9d6043d9 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits