-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang] Forward -Xarch_<arch> -Wl,foo
for GPU toolchains
#126248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary: This patch handles the use of `-Xarch_<arch> -Wl,foo` to send an argument to the linker for the embedded offloading jobs in the linker wrapper. This makes it equivalent to `-Xoffload-linker foo`.
@llvm/pr-subscribers-clang-driver Author: Joseph Huber (jhuber6) ChangesSummary: Full diff: https://github.com/llvm/llvm-project/pull/126248.diff 2 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index c0891d46b0a62cd..55d2936fc5bbb53 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9184,8 +9184,9 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
OPT_load,
OPT_fno_lto,
OPT_flto,
+ OPT_Zlinker_input,
OPT_flto_EQ};
- const llvm::DenseSet<unsigned> LinkerOptions{OPT_mllvm};
+ const llvm::DenseSet<unsigned> LinkerOptions{OPT_mllvm, OPT_Zlinker_input};
auto ShouldForward = [&](const llvm::DenseSet<unsigned> &Set, Arg *A) {
return Set.contains(A->getOption().getID()) ||
(A->getOption().getGroup().isValid() &&
@@ -9203,7 +9204,9 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
ArgStringList CompilerArgs;
ArgStringList LinkerArgs;
for (Arg *A : C.getArgsForToolChain(TC, /*BoundArch=*/"", Kind)) {
- if (ShouldForward(CompilerOptions, A))
+ if (A->getOption().matches(OPT_Zlinker_input))
+ LinkerArgs.emplace_back(A->getValue());
+ else if (ShouldForward(CompilerOptions, A))
A->render(Args, CompilerArgs);
else if (ShouldForward(LinkerOptions, A))
A->render(Args, LinkerArgs);
diff --git a/clang/test/Driver/offload-Xarch.c b/clang/test/Driver/offload-Xarch.c
index 17db891b068340b..18c68f2acc884bc 100644
--- a/clang/test/Driver/offload-Xarch.c
+++ b/clang/test/Driver/offload-Xarch.c
@@ -14,7 +14,7 @@
// RUN: --target=x86_64-unknown-linux-gnu -Xopenmp-target=nvptx64-nvidia-cuda --offload-arch=sm_52,sm_60 -nogpuinc \
// RUN: -Xopenmp-target=amdgcn-amd-amdhsa --offload-arch=gfx90a,gfx1030 -ccc-print-bindings -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=OPENMP %s
-//
+
// OPENMP: # "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[HOST_BC:.+]]"
// OPENMP: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]", "[[HOST_BC]]"], output: "[[GFX1030_BC:.+]]"
// OPENMP: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]", "[[HOST_BC]]"], output: "[[GFX90A_BC:.+]]"
@@ -32,3 +32,12 @@
// CUDA: "-cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}}"-target-cpu" "sm_52" {{.*}}"-O3"
// CUDA: "-cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}}"-target-cpu" "sm_60" {{.*}}"-O0"
// CUDA: "-cc1" "-triple" "x86_64-unknown-linux-gnu" {{.*}}"-O3"
+
+// Make sure that `-Xarch_amdgcn` forwards libraries to the device linker.
+// RUN: %clang -fopenmp=libomp --offload-arch=gfx90a -nogpulib -nogpuinc \
+// RUN: -Xarch_amdgcn -Wl,-lfoo -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=LIBS %s
+// RUN: %clang -fopenmp=libomp --offload-arch=gfx90a -nogpulib -nogpuinc \
+// RUN: -Xoffload-linker-amdgcn-amd-amdhsa -lfoo -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=LIBS %s
+// LIBS: "--device-linker=amdgcn-amd-amdhsa=-lfoo"
|
@llvm/pr-subscribers-clang Author: Joseph Huber (jhuber6) ChangesSummary: Full diff: https://github.com/llvm/llvm-project/pull/126248.diff 2 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index c0891d46b0a62cd..55d2936fc5bbb53 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9184,8 +9184,9 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
OPT_load,
OPT_fno_lto,
OPT_flto,
+ OPT_Zlinker_input,
OPT_flto_EQ};
- const llvm::DenseSet<unsigned> LinkerOptions{OPT_mllvm};
+ const llvm::DenseSet<unsigned> LinkerOptions{OPT_mllvm, OPT_Zlinker_input};
auto ShouldForward = [&](const llvm::DenseSet<unsigned> &Set, Arg *A) {
return Set.contains(A->getOption().getID()) ||
(A->getOption().getGroup().isValid() &&
@@ -9203,7 +9204,9 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
ArgStringList CompilerArgs;
ArgStringList LinkerArgs;
for (Arg *A : C.getArgsForToolChain(TC, /*BoundArch=*/"", Kind)) {
- if (ShouldForward(CompilerOptions, A))
+ if (A->getOption().matches(OPT_Zlinker_input))
+ LinkerArgs.emplace_back(A->getValue());
+ else if (ShouldForward(CompilerOptions, A))
A->render(Args, CompilerArgs);
else if (ShouldForward(LinkerOptions, A))
A->render(Args, LinkerArgs);
diff --git a/clang/test/Driver/offload-Xarch.c b/clang/test/Driver/offload-Xarch.c
index 17db891b068340b..18c68f2acc884bc 100644
--- a/clang/test/Driver/offload-Xarch.c
+++ b/clang/test/Driver/offload-Xarch.c
@@ -14,7 +14,7 @@
// RUN: --target=x86_64-unknown-linux-gnu -Xopenmp-target=nvptx64-nvidia-cuda --offload-arch=sm_52,sm_60 -nogpuinc \
// RUN: -Xopenmp-target=amdgcn-amd-amdhsa --offload-arch=gfx90a,gfx1030 -ccc-print-bindings -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=OPENMP %s
-//
+
// OPENMP: # "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[HOST_BC:.+]]"
// OPENMP: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]", "[[HOST_BC]]"], output: "[[GFX1030_BC:.+]]"
// OPENMP: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]", "[[HOST_BC]]"], output: "[[GFX90A_BC:.+]]"
@@ -32,3 +32,12 @@
// CUDA: "-cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}}"-target-cpu" "sm_52" {{.*}}"-O3"
// CUDA: "-cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}}"-target-cpu" "sm_60" {{.*}}"-O0"
// CUDA: "-cc1" "-triple" "x86_64-unknown-linux-gnu" {{.*}}"-O3"
+
+// Make sure that `-Xarch_amdgcn` forwards libraries to the device linker.
+// RUN: %clang -fopenmp=libomp --offload-arch=gfx90a -nogpulib -nogpuinc \
+// RUN: -Xarch_amdgcn -Wl,-lfoo -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=LIBS %s
+// RUN: %clang -fopenmp=libomp --offload-arch=gfx90a -nogpulib -nogpuinc \
+// RUN: -Xoffload-linker-amdgcn-amd-amdhsa -lfoo -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=LIBS %s
+// LIBS: "--device-linker=amdgcn-amd-amdhsa=-lfoo"
|
@jhuber6 I've seen 2 seemingly random failures of the offload-Xarch.c test on my mac buildbots lately. Any idea why this might be happening? https://lab.llvm.org/buildbot/#/builders/190/builds/14302 The test generally seems to pass, but two of the bots hit the same failure in this test. |
And just now another failure: https://lab.llvm.org/buildbot/#/builders/190/builds/14342 |
Honestly, I don't know. I'd say that it's because we don't support offloading on Darwin, but the triple is supposed to be x64. I could probably just set the test to unsupported for darwin since GPU offloading isn't supported there. Hopefully a32efd8 resolved it. |
I'm seeing our internal downstream builder hit the exact same error in this test, but that is building a Windows hosted compiler targeting Windows. Looking at our runs, it seems to have started appearing after your change 479ffe8 oddly enough. |
Maybe there's some weird implicit behavior here? Why isn't it failing on the public build bots then. I honestly don't have a good guess why. |
Summary: This patch handles the use of `-Xarch_<arch> -Wl,foo` to send an argument to the linker for the embedded offloading jobs in the linker wrapper. This makes it equivalent to `-Xoffload-linker foo`.
I just saw it failed on our public Windows bot: |
Summary:
This patch handles the use of
-Xarch_<arch> -Wl,foo
to send anargument to the linker for the embedded offloading jobs in the linker
wrapper. This makes it equivalent to
-Xoffload-linker foo
.