forked from OSchip/llvm-project
[Driver][MachineOutliner] Support outlining option with LTO
This patch propagates the -moutline flag when LTO is enabled and avoids passing it explicitly to the linker plugin. Differential Revision: https://reviews.llvm.org/D93385
This commit is contained in:
parent
494db3816b
commit
0c41b1c9f9
|
@ -6396,26 +6396,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
options::OPT_fno_cxx_static_destructors, true))
|
||||
CmdArgs.push_back("-fno-c++-static-destructors");
|
||||
|
||||
if (Arg *A = Args.getLastArg(options::OPT_moutline,
|
||||
options::OPT_mno_outline)) {
|
||||
if (A->getOption().matches(options::OPT_moutline)) {
|
||||
// We only support -moutline in AArch64 and ARM targets right now. If
|
||||
// we're not compiling for these, emit a warning and ignore the flag.
|
||||
// Otherwise, add the proper mllvm flags.
|
||||
if (!(Triple.isARM() || Triple.isThumb() ||
|
||||
Triple.getArch() == llvm::Triple::aarch64 ||
|
||||
Triple.getArch() == llvm::Triple::aarch64_32)) {
|
||||
D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName();
|
||||
} else {
|
||||
CmdArgs.push_back("-mllvm");
|
||||
CmdArgs.push_back("-enable-machine-outliner");
|
||||
}
|
||||
} else {
|
||||
// Disable all outlining behaviour.
|
||||
CmdArgs.push_back("-mllvm");
|
||||
CmdArgs.push_back("-enable-machine-outliner=never");
|
||||
}
|
||||
}
|
||||
addMachineOutlinerArgs(D, Args, CmdArgs, Triple, /*IsLTO=*/false);
|
||||
|
||||
if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
|
||||
options::OPT_mno_outline_atomics)) {
|
||||
|
|
|
@ -624,6 +624,9 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
|
|||
|
||||
// Handle remarks hotness/threshold related options.
|
||||
renderRemarksHotnessOptions(Args, CmdArgs);
|
||||
|
||||
addMachineOutlinerArgs(D, Args, CmdArgs, ToolChain.getEffectiveTriple(),
|
||||
/*IsLTO=*/true);
|
||||
}
|
||||
|
||||
void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
|
||||
|
@ -1586,3 +1589,36 @@ unsigned tools::getOrCheckAMDGPUCodeObjectVersion(
|
|||
}
|
||||
return CodeObjVer;
|
||||
}
|
||||
|
||||
void tools::addMachineOutlinerArgs(const Driver &D,
|
||||
const llvm::opt::ArgList &Args,
|
||||
llvm::opt::ArgStringList &CmdArgs,
|
||||
const llvm::Triple &Triple, bool IsLTO) {
|
||||
auto addArg = [&, IsLTO](const Twine &Arg) {
|
||||
if (IsLTO) {
|
||||
CmdArgs.push_back(Args.MakeArgString("-plugin-opt=" + Arg));
|
||||
} else {
|
||||
CmdArgs.push_back("-mllvm");
|
||||
CmdArgs.push_back(Args.MakeArgString(Arg));
|
||||
}
|
||||
};
|
||||
|
||||
if (Arg *A = Args.getLastArg(options::OPT_moutline,
|
||||
options::OPT_mno_outline)) {
|
||||
if (A->getOption().matches(options::OPT_moutline)) {
|
||||
// We only support -moutline in AArch64 and ARM targets right now. If
|
||||
// we're not compiling for these, emit a warning and ignore the flag.
|
||||
// Otherwise, add the proper mllvm flags.
|
||||
if (!(Triple.isARM() || Triple.isThumb() ||
|
||||
Triple.getArch() == llvm::Triple::aarch64 ||
|
||||
Triple.getArch() == llvm::Triple::aarch64_32)) {
|
||||
D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName();
|
||||
} else {
|
||||
addArg(Twine("-enable-machine-outliner"));
|
||||
}
|
||||
} else {
|
||||
// Disable all outlining behaviour.
|
||||
addArg(Twine("-enable-machine-outliner=never"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,6 +141,10 @@ void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args,
|
|||
unsigned getOrCheckAMDGPUCodeObjectVersion(const Driver &D,
|
||||
const llvm::opt::ArgList &Args,
|
||||
bool Diagnose = false);
|
||||
|
||||
void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
|
||||
llvm::opt::ArgStringList &CmdArgs,
|
||||
const llvm::Triple &Triple, bool IsLTO);
|
||||
} // end namespace tools
|
||||
} // end namespace driver
|
||||
} // end namespace clang
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
// REQUIRES: arm-registered-target
|
||||
// RUN: %clang -target armv7-linux-gnueabihf -moutline -c %s -### 2>&1 | FileCheck %s -check-prefix=ON
|
||||
// ON: "-mllvm" "-enable-machine-outliner"
|
||||
// RUN: %clang -target armv7-linux-gnueabihf -flto -moutline %s -### 2>&1 | FileCheck %s -check-prefix=ON-LTO
|
||||
// ON-LTO: "-plugin-opt=-enable-machine-outliner"
|
||||
// RUN: %clang -target armv7-linux-gnueabihf -moutline -mno-outline -c %s -### 2>&1 | FileCheck %s -check-prefix=OFF
|
||||
// OFF: "-mllvm" "-enable-machine-outliner=never"
|
||||
// RUN: %clang -target armv7-linux-gnueabihf -flto -moutline -mno-outline %s -### 2>&1 | FileCheck %s -check-prefix=OFF-LTO
|
||||
// OFF-LTO: "-plugin-opt=-enable-machine-outliner=never"
|
Loading…
Reference in New Issue