Author: Yaxun (Sam) Liu Date: 2022-03-04T15:34:02-05:00 New Revision: bde13a8102baef4d79723064e6bd27cd39124d91
URL: https://github.com/llvm/llvm-project/commit/bde13a8102baef4d79723064e6bd27cd39124d91 DIFF: https://github.com/llvm/llvm-project/commit/bde13a8102baef4d79723064e6bd27cd39124d91.diff LOG: [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 Added: clang/test/Driver/Inputs/empty.cpp clang/test/Driver/Inputs/empty.hip Modified: clang/lib/Driver/Driver.cpp clang/test/Driver/hip-phases.hip Removed: ################################################################################ diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 3bfddeefc7b2b..00d8f1b3b374e 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -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 diff --git a/clang/test/Driver/Inputs/empty.cpp b/clang/test/Driver/Inputs/empty.cpp new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/empty.hip b/clang/test/Driver/Inputs/empty.hip new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/hip-phases.hip b/clang/test/Driver/hip-phases.hip index 93bf635dab63f..5e4f6fc9373a4 100644 --- a/clang/test/Driver/hip-phases.hip +++ b/clang/test/Driver/hip-phases.hip @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits