Skip to content

Commit aa964f1

Browse files
committed
[HIP] Fix -mllvm option for device lld linker
currently clang passes -mllvm options to the device lld linker plugin when compiling HIP. This is against default clang behavior which is only passing -mllvm options to linker plugin specified through -Wl options. This patch lets clang only pass -Xoffload-linker -mllvm= options to device lld linker plugin. Fixes: #63604 Reviewed by: Joseph Huber, Matt Arsenault Differential Revision: https://reviews.llvm.org/D154145
1 parent 40bb302 commit aa964f1

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,6 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA,
142142
if (IsThinLTO)
143143
LldArgs.push_back(Args.MakeArgString("-plugin-opt=-force-import-all"));
144144

145-
for (const Arg *A : Args.filtered(options::OPT_mllvm)) {
146-
LldArgs.push_back(
147-
Args.MakeArgString(Twine("-plugin-opt=") + A->getValue(0)));
148-
}
149-
150145
if (C.getDriver().isSaveTempsEnabled())
151146
LldArgs.push_back("-save-temps");
152147

@@ -165,7 +160,14 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA,
165160
LldArgs.push_back("--whole-archive");
166161

167162
for (auto *Arg : Args.filtered(options::OPT_Xoffload_linker)) {
168-
LldArgs.push_back(Arg->getValue(1));
163+
StringRef ArgVal = Arg->getValue(1);
164+
auto SplitArg = ArgVal.split("-mllvm=");
165+
if (!SplitArg.second.empty()) {
166+
LldArgs.push_back(
167+
Args.MakeArgString(Twine("-plugin-opt=") + SplitArg.second));
168+
} else {
169+
LldArgs.push_back(Args.MakeArgString(ArgVal));
170+
}
169171
Arg->claim();
170172
}
171173

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,47 @@
11
// REQUIRES: x86-registered-target
22
// REQUIRES: amdgpu-registered-target
33

4+
// Check only -Xoffload-linker -mllvm=* options are passed
5+
// to device lld linker.
6+
// -mllvm options are passed to clang only.
7+
48
// RUN: %clang -### --target=x86_64-linux-gnu \
59
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
6-
// RUN: -mllvm -amdgpu-function-calls=0 \
10+
// RUN: -mllvm -unroll-count=10 \
11+
// RUN: -Xoffload-linker -mllvm=-inline-threshold=100 \
712
// RUN: %s 2>&1 | FileCheck %s
813

914
// RUN: %clang -### --target=x86_64-linux-gnu \
1015
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
11-
// RUN: -fgpu-rdc -mllvm -amdgpu-function-calls=0 \
12-
// RUN: %s 2>&1 | FileCheck -check-prefixes=CHECK,RDC %s
16+
// RUN: -mllvm -unroll-count=10 \
17+
// RUN: -Xoffload-linker -mllvm=-inline-threshold=100 \
18+
// RUN: %s 2>&1 | FileCheck -check-prefix=NEG %s
19+
20+
// RUN: %clang -### --target=x86_64-linux-gnu \
21+
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
22+
// RUN: -fgpu-rdc -mllvm -unroll-count=10 \
23+
// RUN: -Xoffload-linker -mllvm=-inline-threshold=100 \
24+
// RUN: %s 2>&1 | FileCheck %s
25+
26+
// RUN: %clang -### --target=x86_64-linux-gnu \
27+
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
28+
// RUN: -fgpu-rdc -mllvm -unroll-count=10 \
29+
// RUN: -Xoffload-linker -mllvm=-inline-threshold=100 \
30+
// RUN: %s 2>&1 | FileCheck -check-prefix=NEG %s
1331

1432
// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
1533
// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
1634
// CHECK-SAME: {{.*}} "-target-cpu" "gfx803"
17-
// CHECK-SAME: {{.*}} "-mllvm" "-amdgpu-function-calls=0" {{.*}}
18-
19-
// CHECK-NOT: {{".*opt"}}
20-
// CHECK-NOT: {{".*llc"}}
21-
// RDC: [[LLD:".*lld.*"]] {{.*}} "-plugin-opt=-amdgpu-function-calls=0"
35+
// CHECK-SAME: {{.*}} "-mllvm" "-unroll-count=10" {{.*}}
36+
// CHECK: [[LLD:".*lld.*"]] {{.*}}"-m" "elf64_amdgpu"{{.*}} "-plugin-opt=-inline-threshold=100"
2237

2338
// CHECK: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
2439
// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
2540
// CHECK-SAME: {{.*}} "-target-cpu" "gfx900"
26-
// CHECK-SAME: {{.*}} "-mllvm" "-amdgpu-function-calls=0" {{.*}}
41+
// CHECK-SAME: {{.*}} "-mllvm" "-unroll-count=10" {{.*}}
42+
// CHECK: [[LLD:".*lld.*"]] {{.*}} "-plugin-opt=-inline-threshold=100"
2743

28-
// CHECK-NOT: {{".*opt"}}
29-
// CHECK-NOT: {{".*llc"}}
30-
// RDC: [[LLD:".*lld.*"]] {{.*}} "-plugin-opt=-amdgpu-function-calls=0"
44+
// NEG-NOT: {{".*opt"}}
45+
// NEG-NOT: {{".*llc"}}
46+
// NEG-NOT: "-plugin-opt=-unroll-count=10"
47+
// NEG-NOT: "-m" "elf_x86_64"{{.*}} "-plugin-opt=-inline-threshold=100"

0 commit comments

Comments
 (0)