diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2460,8 +2460,9 @@ // 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 @@ // 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 @@ // 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 --- /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]]"