Skip to content

Commit d4d1c3d

Browse files
jhuber6github-actions[bot]
authored andcommitted
Automerge: [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.
2 parents 0a2dc2b + 4562b55 commit d4d1c3d

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
@@ -3609,7 +3609,7 @@ class OffloadingActionBuilder final {
36093609
if (!CompileDeviceOnly) {
36103610
C.getDriver().Diag(diag::err_opt_not_valid_without_opt)
36113611
<< "-fhip-emit-relocatable"
3612-
<< "--cuda-device-only";
3612+
<< "--offload-device-only";
36133613
}
36143614
}
36153615
}
@@ -4777,6 +4777,21 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
47774777
C.isOffloadingHostKind(Action::OFK_HIP) &&
47784778
!Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
47794779

4780+
bool HIPRelocatableObj =
4781+
C.isOffloadingHostKind(Action::OFK_HIP) &&
4782+
Args.hasFlag(options::OPT_fhip_emit_relocatable,
4783+
options::OPT_fno_hip_emit_relocatable, false);
4784+
4785+
if (!HIPNoRDC && HIPRelocatableObj)
4786+
C.getDriver().Diag(diag::err_opt_not_valid_with_opt)
4787+
<< "-fhip-emit-relocatable"
4788+
<< "-fgpu-rdc";
4789+
4790+
if (!offloadDeviceOnly() && HIPRelocatableObj)
4791+
C.getDriver().Diag(diag::err_opt_not_valid_without_opt)
4792+
<< "-fhip-emit-relocatable"
4793+
<< "--offload-device-only";
4794+
47804795
// For HIP non-rdc non-device-only compilation, create a linker wrapper
47814796
// action for each host object to link, bundle and wrap device files in
47824797
// it.
@@ -4897,7 +4912,7 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
48974912
A->getOffloadingToolChain()->getTriple().isSPIRV();
48984913
if ((A->getType() != types::TY_Object && !IsAMDGCNSPIRV &&
48994914
A->getType() != types::TY_LTO_BC) ||
4900-
!HIPNoRDC || !offloadDeviceOnly())
4915+
HIPRelocatableObj || !HIPNoRDC || !offloadDeviceOnly())
49014916
continue;
49024917
ActionList LinkerInput = {A};
49034918
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)