[HIP] Fix job action offloading kind for mixed HIP/C++ compilation

When both HIP and C++ programs are input files to clang
with -c, clang treats C++ programs as HIP programs,
which is incorrect.

This is due to action builder does not set correct
offloading kind for job actions for C++ programs.

Reviewed by: Artem Belevich

Differential Revision: https://reviews.llvm.org/D120910
This commit is contained in:
Yaxun (Sam) Liu 2022-03-02 09:09:16 -05:00
parent e7c7b16a84
commit bde13a8102
4 changed files with 23 additions and 1 deletions

View File

@ -2692,6 +2692,7 @@ class OffloadingActionBuilder final {
UA->registerDependentActionInfo(ToolChains[0], Arch,
AssociatedOffloadKind);
}
IsActive = true;
return ABRT_Success;
}
@ -3038,6 +3039,9 @@ class OffloadingActionBuilder final {
getDeviceDependences(OffloadAction::DeviceDependences &DA,
phases::ID CurPhase, phases::ID FinalPhase,
PhasesTy &Phases) override {
if (!IsActive)
return ABRT_Inactive;
// amdgcn does not support linking of object files, therefore we skip
// backend and assemble phases to output LLVM IR. Except for generating
// non-relocatable device coee, where we generate fat binary for device

View File

View File

View File

@ -338,7 +338,7 @@
// RL2-NB-NOT: linker
// RL2-NB-NOT: offload
// NL2-DAG: [[P4:[0-9]+]]: linker, {[[P0]], [[P2]]}, image, (host-[[T:hip]])
// NL2-DAG: [[P4:[0-9]+]]: linker, {[[P0]], [[P2]]}, image
// RL2-EM-DAG: [[P4:[0-9]+]]: linker, {[[P1]], [[P3]], [[P9]]}, image, (host-[[T]])
// RL2-DEV-NOT: linker
@ -455,3 +455,21 @@
// PPELLVM2-DAG: [[P9:[0-9]+]]: offload, "device-[[T]] (amdgcn-amd-amdhsa:[[ARCH2]])" {[[P8]]}, ir
// PPELLVM2-DAG: [[P10:[0-9]+]]: clang-offload-bundler, {[[P4]], [[P9]]}, ir, (device-hip, )
// PPELLVM2-NOT: host
// Test mixed HIP and C++ compilation. HIP program should have HIP offload kind.
// C++ program should have no offload kind.
// RUN: %clang -target x86_64-unknown-linux-gnu \
// RUN: -ccc-print-phases --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
// RUN: -c %S/Inputs/empty.hip %S/Inputs/empty.cpp 2>&1 | FileCheck -check-prefixes=MIXED %s
// RUN: %clang -target x86_64-unknown-linux-gnu \
// RUN: -ccc-print-phases --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
// RUN: -c %S/Inputs/empty.hip %S/Inputs/empty.cpp 2>&1 | FileCheck -check-prefixes=MIXED-NEG %s
// MIXED-DAG: input, "{{.*}}empty.hip", hip, (host-hip)
// MIXED-DAG: input, "{{.*}}empty.hip", hip, (device-hip, gfx803)
// MIXED-DAG: input, "{{.*}}empty.hip", hip, (device-hip, gfx900)
// MIXED-DAG: input, "{{.*}}empty.cpp", c++
// MIXED-NEG-NOT: input, "{{.*}}empty.cpp", c++, (host-hip)
// MIXED-NEG-NOT: input, "{{.*}}empty.cpp", c++, (device-hip