[clang] 95423c7 - [clang][driver] Treat -flto=[auto, jobserver] as -flto
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Thu May 20 23:39:11 PDT 2021
Author: Timm Bäder
Date: 2021-05-21T08:38:41+02:00
New Revision: 95423c7c990d9100deb0056bd9738717cb2bcf2d
URL: https://github.com/llvm/llvm-project/commit/95423c7c990d9100deb0056bd9738717cb2bcf2d
DIFF: https://github.com/llvm/llvm-project/commit/95423c7c990d9100deb0056bd9738717cb2bcf2d.diff
LOG: [clang][driver] Treat -flto=[auto,jobserver] as -flto
Instead of ignoring flto=auto and -flto=jobserver, treat them as -flto
and pass -flto=full along.
Differential Revision: https://reviews.llvm.org/D102479
Added:
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/lto.c
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index d45798c1d4043..128aa7251bb7d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1958,6 +1958,8 @@ def fapple_link_rtlib : Flag<["-"], "fapple-link-rtlib">, Group<f_Group>,
HelpText<"Force linking the clang builtins runtime library">;
def flto_EQ : Joined<["-"], "flto=">, Flags<[CoreOption, CC1Option]>, Group<f_Group>,
HelpText<"Set LTO mode to either 'full' or 'thin'">, Values<"thin,full">;
+def flto_EQ_jobserver : Flag<["-"], "flto=jobserver">, Group<f_Group>;
+def flto_EQ_auto : Flag<["-"], "flto=auto">, Group<f_Group>;
def flto : Flag<["-"], "flto">, Flags<[CoreOption, CC1Option]>, Group<f_Group>,
HelpText<"Enable LTO in 'full' mode">;
def fno_lto : Flag<["-"], "fno-lto">, Flags<[CoreOption, CC1Option]>, Group<f_Group>,
@@ -4259,8 +4261,6 @@ defm reorder_blocks : BooleanFFlag<"reorder-blocks">, Group<clang_ignored_gcc_op
defm branch_count_reg : BooleanFFlag<"branch-count-reg">, Group<clang_ignored_gcc_optimization_f_Group>;
defm default_inline : BooleanFFlag<"default-inline">, Group<clang_ignored_gcc_optimization_f_Group>;
defm fat_lto_objects : BooleanFFlag<"fat-lto-objects">, Group<clang_ignored_gcc_optimization_f_Group>;
-def : Flag<["-"], "flto=auto">, Group<clang_ignored_gcc_optimization_f_Group>;
-def : Flag<["-"], "flto=jobserver">, Group<clang_ignored_gcc_optimization_f_Group>;
defm float_store : BooleanFFlag<"float-store">, Group<clang_ignored_gcc_optimization_f_Group>;
defm friend_injection : BooleanFFlag<"friend-injection">, Group<clang_ignored_f_Group>;
defm function_attribute_list : BooleanFFlag<"function-attribute-list">, Group<clang_ignored_f_Group>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 25af909d9bd22..6a133771f8fd8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -598,7 +598,10 @@ static llvm::Triple computeTargetTriple(const Driver &D,
void Driver::setLTOMode(const llvm::opt::ArgList &Args) {
LTOMode = LTOK_None;
if (!Args.hasFlag(options::OPT_flto, options::OPT_flto_EQ,
- options::OPT_fno_lto, false))
+ options::OPT_fno_lto, false) &&
+ !Args.hasFlag(options::OPT_flto_EQ_auto, options::OPT_fno_lto, false) &&
+ !Args.hasFlag(options::OPT_flto_EQ_jobserver, options::OPT_fno_lto,
+ false))
return;
StringRef LTOName("full");
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 2ef635469df00..d30195b558816 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4454,7 +4454,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
JA.isDeviceOffloading(Action::OFK_Host));
if (D.isUsingLTO() && !isDeviceOffloadAction) {
- Args.AddLastArg(CmdArgs, options::OPT_flto, options::OPT_flto_EQ);
+ 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");
}
}
diff --git a/clang/test/Driver/lto.c b/clang/test/Driver/lto.c
index f6734c7649170..342dd25412740 100644
--- a/clang/test/Driver/lto.c
+++ b/clang/test/Driver/lto.c
@@ -77,3 +77,11 @@
//
// CHECK-TUNING-LLDB: "-plugin-opt=-debugger-tune=lldb"
// CHECK-NO-TUNING-NOT: "-plugin-opt=-debugger-tune
+//
+// -flto=auto and -flto=jobserver pass along -flto=full
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=auto 2>&1 | FileCheck --check-prefix=FLTO-AUTO %s
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=jobserver 2>&1 | FileCheck --check-prefix=FLTO-JOBSERVER %s
+//
+// FLTO-AUTO: -flto=full
+// FLTO-JOBSERVER: -flto=full
+//
More information about the cfe-commits
mailing list