[clang] 7653011 - [AMDGPU] Always pass `-mcpu` to the `lld` linker
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 28 06:52:43 PDT 2023
Author: Joseph Huber
Date: 2023-06-28T08:52:37-05:00
New Revision: 765301183f58a28af65b112db44218dc224b9fec
URL: https://github.com/llvm/llvm-project/commit/765301183f58a28af65b112db44218dc224b9fec
DIFF: https://github.com/llvm/llvm-project/commit/765301183f58a28af65b112db44218dc224b9fec.diff
LOG: [AMDGPU] Always pass `-mcpu` to the `lld` linker
Currently, AMDGPU more or less only supports linking with LTO. If the
user does not either pass `-flto` or `-Wl,-plugin-opt=mcpu=` manually
linking will fail because the architecture's aren't compatible. THis
patch simply passes `-mcpu` by default if it was specified. Should be a
no-op if it's not actually used.
Reviewed By: yaxunl
Differential Revision: https://reviews.llvm.org/D153909
Added:
Modified:
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/test/Driver/amdgpu-toolchain.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 7d1dda5529768c..b3fb7477c793c6 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -545,6 +545,9 @@ void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (C.getDriver().isUsingLTO())
addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
C.getDriver().getLTOMode() == LTOK_Thin);
+ else if (Args.hasArg(options::OPT_mcpu_EQ))
+ CmdArgs.push_back(Args.MakeArgString(
+ "-plugin-opt=mcpu=" + Args.getLastArgValue(options::OPT_mcpu_EQ)));
CmdArgs.push_back("--no-undefined");
CmdArgs.push_back("-shared");
CmdArgs.push_back("-o");
diff --git a/clang/test/Driver/amdgpu-toolchain.c b/clang/test/Driver/amdgpu-toolchain.c
index 288dbbedd49d50..1aa4775e7d9192 100644
--- a/clang/test/Driver/amdgpu-toolchain.c
+++ b/clang/test/Driver/amdgpu-toolchain.c
@@ -11,6 +11,8 @@
// DWARF_VER: "-dwarf-version=5"
// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
-// RUN: -L. -flto -fconvergent-functions %s 2>&1 | FileCheck -check-prefix=LTO %s
+// RUN: -L. -flto -fconvergent-functions %s 2>&1 | FileCheck -check-prefixes=LTO,MCPU %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
+// RUN: -L. -fconvergent-functions %s 2>&1 | FileCheck -check-prefix=MCPU %s
// LTO: clang{{.*}} "-flto=full"{{.*}}"-fconvergent-functions"
-// LTO: ld.lld{{.*}}"-L."{{.*}}"-plugin-opt=mcpu=gfx906"
+// MCPU: ld.lld{{.*}}"-L."{{.*}}"-plugin-opt=mcpu=gfx906"
More information about the cfe-commits
mailing list