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 @@ -4144,8 +4144,10 @@ if (Phase == phases::Link) { assert(Phase == PL.back() && "linking must be final compilation step."); // We don't need to generate additional link commands if emitting AMD bitcode + // or compiling only for the offload device if (!(C.getInputArgs().hasArg(options::OPT_hip_link) && - (C.getInputArgs().hasArg(options::OPT_emit_llvm)))) + (C.getInputArgs().hasArg(options::OPT_emit_llvm))) && + !offloadDeviceOnly()) LinkerInputs.push_back(Current); Current = nullptr; break; diff --git a/clang/test/Driver/hip-phases.hip b/clang/test/Driver/hip-phases.hip --- a/clang/test/Driver/hip-phases.hip +++ b/clang/test/Driver/hip-phases.hip @@ -219,6 +219,14 @@ // RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases \ // RUN: --cuda-gpu-arch=gfx803 %s --cuda-device-only 2>&1 \ // RUN: | FileCheck -check-prefixes=DBIN %s +// +// Test single gpu architecture with complete compilation in device-only +// compilation mode with an unused host linker flag. +// +// RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases \ +// RUN: --cuda-gpu-arch=gfx803 %s --cuda-device-only -Wl,--disable-new-dtags 2>&1 \ +// RUN: | FileCheck -check-prefixes=DBIN %s + // DBIN-DAG: [[P0:[0-9]+]]: input, "{{.*}}hip-phases.hip", [[T:hip]], (device-[[T]], [[ARCH:gfx803]]) // DBIN-DAG: [[P1:[0-9]+]]: preprocessor, {[[P0]]}, [[T]]-cpp-output, (device-[[T]], [[ARCH]]) // DBIN-DAG: [[P2:[0-9]+]]: compiler, {[[P1]]}, ir, (device-[[T]], [[ARCH]]) @@ -229,6 +237,7 @@ // DBIN-DAG: [[P7:[0-9]+]]: linker, {[[P6]]}, hip-fatbin, (device-hip, ) // DBIN-DAG: [[P8:[0-9]+]]: offload, "device-[[T]] (amdgcn-amd-amdhsa:)" {[[P7]]}, hip-fatbin // DBIN-NOT: host + // // Test single gpu architecture up to the assemble phase in device-only // compilation mode. @@ -251,6 +260,11 @@ // RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases \ // RUN: --cuda-gpu-arch=gfx803 %s --cuda-device-only -fhip-emit-relocatable 2>&1 \ // RUN: | FileCheck -check-prefixes=RELOC %s +// +// RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases \ +// RUN: --cuda-gpu-arch=gfx803 %s --cuda-device-only -fhip-emit-relocatable -Wl,--disable-new-dtags \ +// RUN: 2>&1 | FileCheck -check-prefixes=RELOC %s +// // RELOC-DAG: [[P0:[0-9]+]]: input, "{{.*}}hip-phases.hip", [[T:hip]], (device-[[T]], [[ARCH:gfx803]]) // RELOC-DAG: [[P1:[0-9]+]]: preprocessor, {[[P0]]}, [[T]]-cpp-output, (device-[[T]], [[ARCH]]) // RELOC-DAG: [[P2:[0-9]+]]: compiler, {[[P1]]}, ir, (device-[[T]], [[ARCH]]) @@ -266,6 +280,11 @@ // RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases \ // RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s --cuda-device-only -fhip-emit-relocatable 2>&1 \ // RUN: | FileCheck -check-prefixes=RELOC2 %s +// +// RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases \ +// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s --cuda-device-only -fhip-emit-relocatable \ +// RUN: -Wl,--disable-new-dtags 2>&1 | FileCheck -check-prefixes=RELOC2 %s +// // RELOC2-DAG: [[P0:[0-9]+]]: input, "{{.*}}hip-phases.hip", [[T:hip]], (device-[[T]], [[ARCH:gfx803]]) // RELOC2-DAG: [[P1:[0-9]+]]: preprocessor, {[[P0]]}, [[T]]-cpp-output, (device-[[T]], [[ARCH]]) // RELOC2-DAG: [[P2:[0-9]+]]: compiler, {[[P1]]}, ir, (device-[[T]], [[ARCH]]) @@ -288,6 +307,14 @@ // RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases \ // RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s --cuda-device-only \ // RUN: 2>&1 | FileCheck -check-prefixes=DBIN2 %s +// +// Test two gpu architectures with complete compilation in device-only +// compilation mode with an unused host linker flag. +// +// RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases \ +// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s --cuda-device-only \ +// RUN: -Wl,--disable-new-dtags 2>&1 | FileCheck -check-prefixes=DBIN2 %s + // DBIN2-DAG: [[P0:[0-9]+]]: input, "{{.*}}hip-phases.hip", [[T:hip]], (device-[[T]], [[ARCH:gfx803]]) // DBIN2-DAG: [[P1:[0-9]+]]: preprocessor, {[[P0]]}, [[T]]-cpp-output, (device-[[T]], [[ARCH]]) // DBIN2-DAG: [[P2:[0-9]+]]: compiler, {[[P1]]}, ir, (device-[[T]], [[ARCH]]) @@ -305,6 +332,7 @@ // DBIN2-DAG: [[P14:[0-9]+]]: linker, {[[P6]], [[P13]]}, hip-fatbin, (device-hip, ) // DBIN2-DAG: [[P15:[0-9]+]]: offload, "device-[[T]] (amdgcn-amd-amdhsa:)" {[[P14]]}, hip-fatbin // DBIN2-NOT: host + // // Test two gpu architectures up to the assemble phase in device-only // compilation mode. @@ -357,11 +385,21 @@ // RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %t/obj1.o %t/obj2.o \ // RUN: -fgpu-rdc --cuda-device-only 2>&1 | FileCheck -check-prefixes=L2,RL2,RL2-DEV %s +// RUN: %clang --target=x86_64-unknown-linux-gnu -ccc-print-phases --hip-link \ +// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %t/obj1.o %t/obj2.o \ +// RUN: -fgpu-rdc --cuda-device-only -Wl,--disable-new-dtags 2>&1 \ +// RUN: | FileCheck -check-prefixes=L2,RL2,RL2-DEV %s + // RUN: %clang --target=x86_64-unknown-linux-gnu -ccc-print-phases --hip-link \ // RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %t/obj1.o %t/obj2.o \ // RUN: -fgpu-rdc --cuda-device-only --no-gpu-bundle-output 2>&1 \ // RUN: | FileCheck -check-prefixes=L2,RL2,RL2-NB %s +// RUN: %clang --target=x86_64-unknown-linux-gnu -ccc-print-phases --hip-link \ +// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %t/obj1.o %t/obj2.o \ +// RUN: -fgpu-rdc --cuda-device-only --no-gpu-bundle-output -Wl,--disable-new-dtags 2>&1 \ +// RUN: | FileCheck -check-prefixes=L2,RL2,RL2-NB %s + // L2-DAG: [[P0:[0-9]+]]: input, "{{.*}}obj1.o", object // RL2-DAG: [[P1:[0-9]+]]: clang-offload-unbundler, {[[P0]]}, object // L2-DAG: [[P2:[0-9]+]]: input, "{{.*}}obj2.o", object