forked from OSchip/llvm-project
[LTO] Add -flto-jobs=N to control backend parallelism
Summary: Currently, a linker option must be used to control the backend parallelism of ThinLTO. The linker option varies depending on the linker (e.g. gold vs ld64). Add a new clang option -flto-jobs=N to control this. I've added in the wiring to pass this to the gold plugin. I also added in the logic to pass this down in the form I understand that ld64 uses on MacOS, for the darwin target. Reviewers: mehdi_amini, dexonsmith Subscribers: mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D24826 llvm-svn: 282291
This commit is contained in:
parent
896fee2846
commit
12286d22b7
|
@ -812,6 +812,11 @@ def flto : Flag<["-"], "flto">, Flags<[CC1Option]>, Group<f_Group>,
|
|||
HelpText<"Enable LTO in 'full' mode">;
|
||||
def fno_lto : Flag<["-"], "fno-lto">, Group<f_Group>,
|
||||
HelpText<"Disable LTO mode (default)">;
|
||||
def flto_jobs_EQ : Joined<["-"], "flto-jobs=">,
|
||||
Flags<[CC1Option]>, Group<f_Group>,
|
||||
HelpText<"Controls the backend parallelism of -flto=thin (default "
|
||||
"of 0 means the number of threads will be derived from "
|
||||
"the number of CPUs detected)">;
|
||||
def fthinlto_index_EQ : Joined<["-"], "fthinlto-index=">,
|
||||
Flags<[CC1Option]>, Group<f_Group>,
|
||||
HelpText<"Perform ThinLTO importing using provided function summary index">;
|
||||
|
|
|
@ -1998,8 +1998,19 @@ static std::string getCPUName(const ArgList &Args, const llvm::Triple &T,
|
|||
}
|
||||
}
|
||||
|
||||
static unsigned getLTOParallelism(const ArgList &Args, const Driver &D) {
|
||||
unsigned Parallelism = 0;
|
||||
Arg *LtoJobsArg = Args.getLastArg(options::OPT_flto_jobs_EQ);
|
||||
if (LtoJobsArg &&
|
||||
StringRef(LtoJobsArg->getValue()).getAsInteger(10, Parallelism))
|
||||
D.Diag(diag::err_drv_invalid_int_value) << LtoJobsArg->getAsString(Args)
|
||||
<< LtoJobsArg->getValue();
|
||||
return Parallelism;
|
||||
}
|
||||
|
||||
static void AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args,
|
||||
ArgStringList &CmdArgs, bool IsThinLTO) {
|
||||
ArgStringList &CmdArgs, bool IsThinLTO,
|
||||
const Driver &D) {
|
||||
// Tell the linker to load the plugin. This has to come before AddLinkerInputs
|
||||
// as gold requires -plugin to come before any -plugin-opt that -Wl might
|
||||
// forward.
|
||||
|
@ -2032,6 +2043,10 @@ static void AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args,
|
|||
if (IsThinLTO)
|
||||
CmdArgs.push_back("-plugin-opt=thinlto");
|
||||
|
||||
if (unsigned Parallelism = getLTOParallelism(Args, D))
|
||||
CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=jobs=") +
|
||||
std::to_string(Parallelism)));
|
||||
|
||||
// If an explicit debugger tuning argument appeared, pass it along.
|
||||
if (Arg *A = Args.getLastArg(options::OPT_gTune_Group,
|
||||
options::OPT_ggdbN_Group)) {
|
||||
|
@ -7639,7 +7654,7 @@ void cloudabi::Linker::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
options::OPT_t, options::OPT_Z_Flag, options::OPT_r});
|
||||
|
||||
if (D.isUsingLTO())
|
||||
AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin);
|
||||
AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin, D);
|
||||
|
||||
AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs);
|
||||
|
||||
|
@ -8060,6 +8075,13 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
|
||||
getMachOToolChain().addProfileRTLibs(Args, CmdArgs);
|
||||
|
||||
if (unsigned Parallelism =
|
||||
getLTOParallelism(Args, getToolChain().getDriver())) {
|
||||
CmdArgs.push_back("-mllvm");
|
||||
CmdArgs.push_back(
|
||||
Args.MakeArgString(Twine("-threads=") + std::to_string(Parallelism)));
|
||||
}
|
||||
|
||||
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
|
||||
if (getToolChain().getDriver().CCCIsCXX())
|
||||
getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
|
||||
|
@ -8790,7 +8812,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
Args.AddAllArgs(CmdArgs, options::OPT_r);
|
||||
|
||||
if (D.isUsingLTO())
|
||||
AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin);
|
||||
AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin, D);
|
||||
|
||||
bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
|
||||
AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs);
|
||||
|
@ -9623,7 +9645,7 @@ void gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
ToolChain.AddFilePathLibArgs(Args, CmdArgs);
|
||||
|
||||
if (D.isUsingLTO())
|
||||
AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin);
|
||||
AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin, D);
|
||||
|
||||
if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
|
||||
CmdArgs.push_back("--no-demangle");
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
// Confirm that -flto-jobs=N is passed to linker
|
||||
|
||||
// RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -flto-jobs=5 2> %t
|
||||
// RUN: FileCheck -check-prefix=CHECK-LINK-THIN-JOBS-ACTION < %t %s
|
||||
//
|
||||
// CHECK-LINK-THIN-JOBS-ACTION: "-plugin-opt=jobs=5"
|
||||
|
||||
// RUN: %clang -target x86_64-apple-darwin13.3.0 -### %s -flto=thin -flto-jobs=5 2> %t
|
||||
// RUN: FileCheck -check-prefix=CHECK-LINK-THIN-JOBS2-ACTION < %t %s
|
||||
//
|
||||
// CHECK-LINK-THIN-JOBS2-ACTION: "-mllvm" "-threads=5"
|
Loading…
Reference in New Issue