Skip to content

Commit 4562b55

Browse files
authored
[HIP] Handle -fhip-emit-reloctable in the new driver (#151237)
Summary: Support for this was missing, here it pretty much overrides the normal bundling behavior and also requires a few errors to be emitted.
1 parent 4fdf07f commit 4562b55

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3606,7 +3606,7 @@ class OffloadingActionBuilder final {
36063606
if (!CompileDeviceOnly) {
36073607
C.getDriver().Diag(diag::err_opt_not_valid_without_opt)
36083608
<< "-fhip-emit-relocatable"
3609-
<< "--cuda-device-only";
3609+
<< "--offload-device-only";
36103610
}
36113611
}
36123612
}
@@ -4774,6 +4774,21 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
47744774
C.isOffloadingHostKind(Action::OFK_HIP) &&
47754775
!Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
47764776

4777+
bool HIPRelocatableObj =
4778+
C.isOffloadingHostKind(Action::OFK_HIP) &&
4779+
Args.hasFlag(options::OPT_fhip_emit_relocatable,
4780+
options::OPT_fno_hip_emit_relocatable, false);
4781+
4782+
if (!HIPNoRDC && HIPRelocatableObj)
4783+
C.getDriver().Diag(diag::err_opt_not_valid_with_opt)
4784+
<< "-fhip-emit-relocatable"
4785+
<< "-fgpu-rdc";
4786+
4787+
if (!offloadDeviceOnly() && HIPRelocatableObj)
4788+
C.getDriver().Diag(diag::err_opt_not_valid_without_opt)
4789+
<< "-fhip-emit-relocatable"
4790+
<< "--offload-device-only";
4791+
47774792
// For HIP non-rdc non-device-only compilation, create a linker wrapper
47784793
// action for each host object to link, bundle and wrap device files in
47794794
// it.
@@ -4894,7 +4909,7 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
48944909
A->getOffloadingToolChain()->getTriple().isSPIRV();
48954910
if ((A->getType() != types::TY_Object && !IsAMDGCNSPIRV &&
48964911
A->getType() != types::TY_LTO_BC) ||
4897-
!HIPNoRDC || !offloadDeviceOnly())
4912+
HIPRelocatableObj || !HIPNoRDC || !offloadDeviceOnly())
48984913
continue;
48994914
ActionList LinkerInput = {A};
49004915
A = C.MakeAction<LinkJobAction>(LinkerInput, types::TY_Image);

clang/test/Driver/hip-dependent-options.hip

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
// RUN: %S/Inputs/hip_multiple_inputs/a.cu \
55
// RUN: %S/Inputs/hip_multiple_inputs/b.hip --gpu-bundle-output \
66
// RUN: 2>&1 | FileCheck -check-prefixes=RELOCRDC %s
7+
// RUN: not %clang -### --target=x86_64-linux-gnu --offload-new-driver \
8+
// RUN: -x hip --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
9+
// RUN: -c -fhip-emit-relocatable -nogpuinc -nogpulib --cuda-device-only -fgpu-rdc \
10+
// RUN: %S/Inputs/hip_multiple_inputs/a.cu \
11+
// RUN: %S/Inputs/hip_multiple_inputs/b.hip --gpu-bundle-output \
12+
// RUN: 2>&1 | FileCheck -check-prefixes=RELOCRDC %s
713

814
// RELOCRDC: error: option '-fhip-emit-relocatable' cannot be specified with '-fgpu-rdc'
915

@@ -13,5 +19,11 @@
1319
// RUN: %S/Inputs/hip_multiple_inputs/a.cu \
1420
// RUN: %S/Inputs/hip_multiple_inputs/b.hip --gpu-bundle-output \
1521
// RUN: 2>&1 | FileCheck -check-prefixes=RELOCHOST %s
22+
// RUN: not %clang -### --target=x86_64-linux-gnu --offload-new-driver \
23+
// RUN: -x hip --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
24+
// RUN: -c -fhip-emit-relocatable -nogpuinc -nogpulib \
25+
// RUN: %S/Inputs/hip_multiple_inputs/a.cu \
26+
// RUN: %S/Inputs/hip_multiple_inputs/b.hip --gpu-bundle-output \
27+
// RUN: 2>&1 | FileCheck -check-prefixes=RELOCHOST %s
1628

17-
// RELOCHOST: error: option '-fhip-emit-relocatable' cannot be specified without '--cuda-device-only'
29+
// RELOCHOST: error: option '-fhip-emit-relocatable' cannot be specified without '--offload-device-only'

clang/test/Driver/hip-phases.hip

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,24 @@
275275
// RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases --no-offload-new-driver \
276276
// RUN: --cuda-gpu-arch=gfx803 %s --cuda-device-only -fhip-emit-relocatable 2>&1 \
277277
// RUN: | FileCheck -check-prefixes=RELOC %s
278+
// RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases --offload-new-driver \
279+
// RUN: --cuda-gpu-arch=gfx803 %s --cuda-device-only -fhip-emit-relocatable 2>&1 \
280+
// RUN: | FileCheck -check-prefixes=RELOC %s
278281
//
279282
// RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases --no-offload-new-driver \
280283
// RUN: --cuda-gpu-arch=gfx803 %s --cuda-device-only -fhip-emit-relocatable -Wl,--disable-new-dtags \
281284
// RUN: 2>&1 | FileCheck -check-prefixes=RELOC %s
285+
// RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases --offload-new-driver \
286+
// RUN: --cuda-gpu-arch=gfx803 %s --cuda-device-only -fhip-emit-relocatable -Wl,--disable-new-dtags \
287+
// RUN: 2>&1 | FileCheck -check-prefixes=RELOC %s
282288
//
283289
// RELOC-DAG: [[P0:[0-9]+]]: input, "{{.*}}hip-phases.hip", [[T:hip]], (device-[[T]], [[ARCH:gfx803]])
284290
// RELOC-DAG: [[P1:[0-9]+]]: preprocessor, {[[P0]]}, [[T]]-cpp-output, (device-[[T]], [[ARCH]])
285291
// RELOC-DAG: [[P2:[0-9]+]]: compiler, {[[P1]]}, ir, (device-[[T]], [[ARCH]])
286292
// RELOC-DAG: [[P3:[0-9]+]]: backend, {[[P2]]}, assembler, (device-[[T]], [[ARCH]])
287293
// RELOC-DAG: [[P4:[0-9]+]]: assembler, {[[P3]]}, object, (device-[[T]], [[ARCH]])
288294
// RELOC-NOT: linker
289-
// RELOC-DAG: [[P5:[0-9]+]]: offload, "device-[[T]] (amdgcn-amd-amdhsa:[[ARCH]])" {[[P4]]}, object
295+
// RELOC-DAG: [[P5:[0-9]+]]: offload, "device-[[T]] (amdgcn-amd-amdhsa:[[ARCH]])" {[[P4]]}
290296
// RELOC-NOT: host
291297

292298
//

0 commit comments

Comments
 (0)