Skip to content

Commit 1a7402d

Browse files
authored
[NFC][Driver][HIP] Fix mixing amdgcnspirv and gfxXXX via --offload-arch (#133024)
Due to `amdgcnspirv` piggybacking on the HIPAMDToolchain, it loses its immediately apparent SPIR-Vness, which makes the Driver want to go all the way to Assembly emmission. This was problematic as we were trying to `llvm-link` SPIR-V, before trying to translate it. This patch ensures that we do the right thing and stop at bitcode emission if we are mixing `amdgcnspirv` and concrete targets.
1 parent 96925fa commit 1a7402d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3750,9 +3750,12 @@ class OffloadingActionBuilder final {
37503750
// compiler phases, including backend and assemble phases.
37513751
ActionList AL;
37523752
Action *BackendAction = nullptr;
3753-
if (ToolChains.front()->getTriple().isSPIRV()) {
3753+
if (ToolChains.front()->getTriple().isSPIRV() ||
3754+
(ToolChains.front()->getTriple().isAMDGCN() &&
3755+
GpuArchList[I] == StringRef("amdgcnspirv"))) {
37543756
// Emit LLVM bitcode for SPIR-V targets. SPIR-V device tool chain
3755-
// (HIPSPVToolChain) runs post-link LLVM IR passes.
3757+
// (HIPSPVToolChain or HIPAMDToolChain) runs post-link LLVM IR
3758+
// passes.
37563759
types::ID Output = Args.hasArg(options::OPT_S)
37573760
? types::TY_LLVM_IR
37583761
: types::TY_LLVM_BC;

clang/test/Driver/hip-toolchain-no-rdc.hip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@
187187
// Check mixed AMDGCNSPIRV and concrete GPU arch.
188188
//
189189

190-
// AMDGCNSPIRV: "-cc1" "-triple" "spirv64-amd-amdhsa" {{.*}}"-emit-obj" {{.*}} "-o" "[[AMDGCNSPV_OBJ:.*o]]"
191-
// AMDGCNSPIRV: {{".*llvm-link.*"}} "-o" "[[AMDGCNSPV_TMP:.*out]]" "[[AMDGCNSPV_OBJ]]"
190+
// AMDGCNSPIRV: "-cc1" "-triple" "spirv64-amd-amdhsa" {{.*}}"-emit-llvm-bc" {{.*}} "-o" "[[AMDGCNSPV_BC:.*bc]]"
191+
// AMDGCNSPIRV: {{".*llvm-link.*"}} "-o" "[[AMDGCNSPV_TMP:.*out]]" "[[AMDGCNSPV_BC]]"
192192
// AMDGCNSPIRV: {{".*llvm-spirv.*"}} "--spirv-max-version=1.6" "--spirv-ext=+all" {{.*}} "[[AMDGCNSPV_TMP]]" {{.*}}"-o" "[[AMDGCNSPV_CO:.*out]]"
193193
// AMDGCNSPIRV: "-cc1" "-triple" "amdgcn-amd-amdhsa" {{.*}}"-emit-obj" {{.*}}"-target-cpu" "gfx900"{{.*}} "-o" "[[GFX900_OBJ:.*o]]"
194194
// AMDGCNSPIRV: {{".*lld.*"}} {{.*}}"-plugin-opt=mcpu=gfx900" {{.*}} "-o" "[[GFX900_CO:.*out]]" {{.*}}"[[GFX900_OBJ]]"

0 commit comments

Comments
 (0)