[PATCH] D108881: [clang][driver] Honor the last -flto= flag even if an earlier -flto is present
Usman Nadeem via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 30 11:25:19 PDT 2021
mnadeem updated this revision to Diff 369498.
mnadeem marked 3 inline comments as done.
mnadeem edited the summary of this revision.
mnadeem added a subscriber: apazos.
mnadeem added a comment.
Herald added subscribers: kerbowa, nhaehnle, jvesely.
Address comments.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D108881/new/
https://reviews.llvm.org/D108881
Files:
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/amdgpu-toolchain.c
clang/test/Driver/lto.c
Index: clang/test/Driver/lto.c
===================================================================
--- clang/test/Driver/lto.c
+++ clang/test/Driver/lto.c
@@ -85,3 +85,21 @@
// FLTO-AUTO: -flto=full
// FLTO-JOBSERVER: -flto=full
//
+
+// Pass the last -flto argument.
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -flto 2>&1 | \
+// RUN: FileCheck --check-prefix=FLTO-FULL %s
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -flto=full 2>&1 | \
+// RUN: FileCheck --check-prefix=FLTO-FULL %s
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto -flto=thin 2>&1 | \
+// RUN: FileCheck --check-prefix=FLTO-THIN %s
+//
+// FLTO-FULL-NOT: -flto=thin
+// FLTO-FULL: -flto=full
+// FLTO-FULL-NOT: -flto=thin
+//
+// FLTO-THIN-NOT: -flto=full
+// FLTO-THIN-NOT: "-flto"
+// FLTO-THIN: -flto=thin
+// FLTO-THIN-NOT: "-flto"
+// FLTO-THIN-NOT: -flto=full
Index: clang/test/Driver/amdgpu-toolchain.c
===================================================================
--- clang/test/Driver/amdgpu-toolchain.c
+++ clang/test/Driver/amdgpu-toolchain.c
@@ -12,5 +12,5 @@
// RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
// RUN: -flto %s 2>&1 | FileCheck -check-prefix=LTO %s
-// LTO: clang{{.*}} "-flto"
+// LTO: clang{{.*}} "-flto=full"
// LTO: ld.lld{{.*}}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4491,18 +4491,8 @@
CmdArgs.push_back("-emit-llvm-uselists");
if (IsUsingLTO) {
- if (!IsDeviceOffloadAction) {
- if (Args.hasArg(options::OPT_flto))
- CmdArgs.push_back("-flto");
- else {
- if (D.getLTOMode() == LTOK_Thin)
- CmdArgs.push_back("-flto=thin");
- else
- CmdArgs.push_back("-flto=full");
- }
- CmdArgs.push_back("-flto-unit");
- } else if (Triple.isAMDGPU()) {
- // Only AMDGPU supports device-side LTO
+ // Only AMDGPU supports device-side LTO.
+ if (!IsDeviceOffloadAction || Triple.isAMDGPU()) {
assert(LTOMode == LTOK_Full || LTOMode == LTOK_Thin);
CmdArgs.push_back(Args.MakeArgString(
Twine("-flto=") + (LTOMode == LTOK_Thin ? "thin" : "full")));
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -600,8 +600,9 @@
StringRef LTOName("full");
- const Arg *A = Args.getLastArg(OptEq);
- if (A)
+ const Arg *A = Args.getLastArg(OptEq, OptPos);
+ // Use the OptEq only if it is after the -flto option.
+ if (A && A->getOption().matches(OptEq))
LTOName = A->getValue();
LTOMode = llvm::StringSwitch<LTOKind>(LTOName)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108881.369498.patch
Type: text/x-patch
Size: 2838 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210830/bb791976/attachment-0001.bin>
More information about the cfe-commits
mailing list