Skip to content

Commit 4f14b80

Browse files
committed
[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
1 parent 1f6e155 commit 4f14b80

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,8 +2460,9 @@ class OffloadingActionBuilder final {
24602460

24612461
// If the host input is not CUDA or HIP, we don't need to bother about
24622462
// this input.
2463-
if (IA->getType() != types::TY_CUDA &&
2464-
IA->getType() != types::TY_HIP) {
2463+
if (!(IA->getType() == types::TY_CUDA ||
2464+
IA->getType() == types::TY_HIP ||
2465+
IA->getType() == types::TY_PP_HIP)) {
24652466
// The builder will ignore this input.
24662467
IsActive = false;
24672468
return ABRT_Inactive;
@@ -2489,7 +2490,7 @@ class OffloadingActionBuilder final {
24892490

24902491
// If -fgpu-rdc is disabled, should not unbundle since there is no
24912492
// device code to link.
2492-
if (!Relocatable)
2493+
if (UA->getType() == types::TY_Object && !Relocatable)
24932494
return ABRT_Inactive;
24942495

24952496
CudaDeviceActions.clear();
@@ -3250,7 +3251,8 @@ class OffloadingActionBuilder final {
32503251
// the input is not a bundle.
32513252
if (CanUseBundler && isa<InputAction>(HostAction) &&
32523253
InputArg->getOption().getKind() == llvm::opt::Option::InputClass &&
3253-
!types::isSrcFile(HostAction->getType())) {
3254+
(!types::isSrcFile(HostAction->getType()) ||
3255+
HostAction->getType() == types::TY_PP_HIP)) {
32543256
auto UnbundlingHostAction =
32553257
C.MakeAction<OffloadUnbundlingJobAction>(HostAction);
32563258
UnbundlingHostAction->registerDependentActionInfo(
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// REQUIRES: clang-driver, amdgpu-registered-target
2+
3+
// RUN: %clang -### -target x86_64-unknown-linux-gnu \
4+
// RUN: --offload-arch=gfx803 -nogpulib \
5+
// RUN: -x hip-cpp-output %s 2>&1 | FileCheck %s
6+
7+
// CHECK: {{".*clang-offload-bundler.*"}} {{.*}}"-outputs=[[HOST_PP:.*cui]],[[DEV_PP:.*cui]]" "-unbundle"
8+
// CHECK: {{".*clang.*"}} "-cc1" {{.*}}"-target-cpu" "gfx803" {{.*}}"-o" "[[DEV_O:.*o]]" {{.*}}"[[DEV_PP]]"
9+
// CHECK: {{".*lld.*"}} {{.*}}"-o" "[[DEV_ISA:.*]]" "[[DEV_O]]"
10+
// CHECK: {{".*clang-offload-bundler.*"}} {{.*}}"-inputs={{.*}},[[DEV_ISA]]" "-outputs=[[FATBIN:.*]]"
11+
// CHECK: {{".*clang.*"}} {{.*}}"-triple" "x86_64-unknown-linux-gnu"{{.*}} "-fcuda-include-gpubinary" "[[FATBIN]]" {{.*}}"-o" "[[HOST_O:.*o]]" {{.*}}"[[HOST_PP]]"
12+
// CHECK: {{".*ld.*"}} {{.*}}"[[HOST_O]]"
13+
14+
// RUN: %clang -### -target x86_64-unknown-linux-gnu \
15+
// RUN: --offload-arch=gfx803 -nogpulib -fgpu-rdc \
16+
// RUN: -x hip-cpp-output %s 2>&1 | FileCheck -check-prefix=RDC %s
17+
18+
// RDC: {{".*clang-offload-bundler.*"}} {{.*}}"-outputs=[[HOST_PP:.*cui]],[[DEV_PP:.*cui]]" "-unbundle"
19+
// RDC: {{".*clang.*"}} {{.*}}"-triple" "x86_64-unknown-linux-gnu"{{.*}} "-o" "[[HOST_O:.*o]]" {{.*}}"[[HOST_PP]]"
20+
// RDC: {{".*clang-offload-bundler.*"}} {{.*}}"-outputs=[[HOST_PP:.*cui]],[[DEV_PP:.*cui]]" "-unbundle"
21+
// RDC: {{".*clang.*"}} "-cc1" {{.*}}"-target-cpu" "gfx803" {{.*}}"-o" "[[DEV_BC:.*bc]]" {{.*}}"[[DEV_PP]]"
22+
// RDC: {{".*lld.*"}} {{.*}}"-o" "[[DEV_ISA:.*]]" "[[DEV_BC]]"
23+
// RDC: {{".*clang-offload-bundler.*"}} {{.*}}"-inputs={{.*}},[[DEV_ISA]]" "-outputs=[[FATBIN:.*]]"
24+
// RDC: {{".*llvm-mc.*"}} "-o" "[[FATBIN_O:.*o]]"
25+
// RDC: {{".*ld.*"}} {{.*}}"[[HOST_O]]" "[[FATBIN_O]]"

0 commit comments

Comments
 (0)