From 4f14b80803a458209b6b11daa3ec05076b8c4973 Mon Sep 17 00:00:00 2001 From: "Yaxun (Sam) Liu" Date: Fri, 4 Dec 2020 17:38:57 -0500 Subject: [PATCH] [HIP] unbundle bundled preprocessor output There is a use case that users want to emit preprocessor output as file and compile the preprocessor output later with -x hip-cpp-output. Clang emits bundled preprocessor output when users compile with -E for combined host/device compilations. Clang should be able to compile the bundled preprocessor output with -x hip-cpp-output. Basically clang should unbundle the bundled preprocessor output and launch device and host compilation actions. Currently there is a bug in clang driver causing bundled preprocessor output not unbundled. This patch fixes that. Differential Revision: https://reviews.llvm.org/D92720 --- clang/lib/Driver/Driver.cpp | 10 ++++++---- clang/test/Driver/hip-unbundle-preproc.hip | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 clang/test/Driver/hip-unbundle-preproc.hip diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index dc9ec1b..62fba30 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2460,8 +2460,9 @@ class OffloadingActionBuilder final { // If the host input is not CUDA or HIP, we don't need to bother about // this input. - if (IA->getType() != types::TY_CUDA && - IA->getType() != types::TY_HIP) { + if (!(IA->getType() == types::TY_CUDA || + IA->getType() == types::TY_HIP || + IA->getType() == types::TY_PP_HIP)) { // The builder will ignore this input. IsActive = false; return ABRT_Inactive; @@ -2489,7 +2490,7 @@ class OffloadingActionBuilder final { // If -fgpu-rdc is disabled, should not unbundle since there is no // device code to link. - if (!Relocatable) + if (UA->getType() == types::TY_Object && !Relocatable) return ABRT_Inactive; CudaDeviceActions.clear(); @@ -3250,7 +3251,8 @@ public: // the input is not a bundle. if (CanUseBundler && isa(HostAction) && InputArg->getOption().getKind() == llvm::opt::Option::InputClass && - !types::isSrcFile(HostAction->getType())) { + (!types::isSrcFile(HostAction->getType()) || + HostAction->getType() == types::TY_PP_HIP)) { auto UnbundlingHostAction = C.MakeAction(HostAction); UnbundlingHostAction->registerDependentActionInfo( diff --git a/clang/test/Driver/hip-unbundle-preproc.hip b/clang/test/Driver/hip-unbundle-preproc.hip new file mode 100644 index 0000000..1903c72 --- /dev/null +++ b/clang/test/Driver/hip-unbundle-preproc.hip @@ -0,0 +1,25 @@ +// REQUIRES: clang-driver, amdgpu-registered-target + +// RUN: %clang -### -target x86_64-unknown-linux-gnu \ +// RUN: --offload-arch=gfx803 -nogpulib \ +// RUN: -x hip-cpp-output %s 2>&1 | FileCheck %s + +// CHECK: {{".*clang-offload-bundler.*"}} {{.*}}"-outputs=[[HOST_PP:.*cui]],[[DEV_PP:.*cui]]" "-unbundle" +// CHECK: {{".*clang.*"}} "-cc1" {{.*}}"-target-cpu" "gfx803" {{.*}}"-o" "[[DEV_O:.*o]]" {{.*}}"[[DEV_PP]]" +// CHECK: {{".*lld.*"}} {{.*}}"-o" "[[DEV_ISA:.*]]" "[[DEV_O]]" +// CHECK: {{".*clang-offload-bundler.*"}} {{.*}}"-inputs={{.*}},[[DEV_ISA]]" "-outputs=[[FATBIN:.*]]" +// CHECK: {{".*clang.*"}} {{.*}}"-triple" "x86_64-unknown-linux-gnu"{{.*}} "-fcuda-include-gpubinary" "[[FATBIN]]" {{.*}}"-o" "[[HOST_O:.*o]]" {{.*}}"[[HOST_PP]]" +// CHECK: {{".*ld.*"}} {{.*}}"[[HOST_O]]" + +// RUN: %clang -### -target x86_64-unknown-linux-gnu \ +// RUN: --offload-arch=gfx803 -nogpulib -fgpu-rdc \ +// RUN: -x hip-cpp-output %s 2>&1 | FileCheck -check-prefix=RDC %s + +// RDC: {{".*clang-offload-bundler.*"}} {{.*}}"-outputs=[[HOST_PP:.*cui]],[[DEV_PP:.*cui]]" "-unbundle" +// RDC: {{".*clang.*"}} {{.*}}"-triple" "x86_64-unknown-linux-gnu"{{.*}} "-o" "[[HOST_O:.*o]]" {{.*}}"[[HOST_PP]]" +// RDC: {{".*clang-offload-bundler.*"}} {{.*}}"-outputs=[[HOST_PP:.*cui]],[[DEV_PP:.*cui]]" "-unbundle" +// RDC: {{".*clang.*"}} "-cc1" {{.*}}"-target-cpu" "gfx803" {{.*}}"-o" "[[DEV_BC:.*bc]]" {{.*}}"[[DEV_PP]]" +// RDC: {{".*lld.*"}} {{.*}}"-o" "[[DEV_ISA:.*]]" "[[DEV_BC]]" +// RDC: {{".*clang-offload-bundler.*"}} {{.*}}"-inputs={{.*}},[[DEV_ISA]]" "-outputs=[[FATBIN:.*]]" +// RDC: {{".*llvm-mc.*"}} "-o" "[[FATBIN_O:.*o]]" +// RDC: {{".*ld.*"}} {{.*}}"[[HOST_O]]" "[[FATBIN_O]]" -- 2.7.4