[MachineOutliner] Properly pass -moutline along to the toolchain

This moves the LTO-specific code for outlining from ToolChains/Clang.cpp to
ToolChains/Darwin.cpp. Passing -mllvm flags isn't sufficient for making sure
that the specified pass will actually run in LTO. This makes sure that when
-moutline is passed, the MachineOutliner will actually be added to the LTO
pass pipeline as expected.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336471 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jessica Paquette 2018-07-06 22:24:56 +00:00
parent 4ad65cd262
commit f3ac792d41
4 changed files with 19 additions and 13 deletions

View File

@ -4759,14 +4759,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
} else {
CmdArgs.push_back("-mllvm");
CmdArgs.push_back("-enable-machine-outliner");
// The outliner shouldn't compete with linkers that dedupe linkonceodr
// functions in LTO. Enable that behaviour by default when compiling with
// LTO.
if (getToolChain().getDriver().isUsingLTO()) {
CmdArgs.push_back("-mllvm");
CmdArgs.push_back("-enable-linkonceodr-outlining");
}
}
} else {
// Disable all outlining behaviour.

View File

@ -479,6 +479,18 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
}
}
// Propagate the -moutline flag to the linker in LTO.
if (Args.hasFlag(options::OPT_moutline, options::OPT_mno_outline, false)) {
if (getMachOToolChain().getMachOArchName(Args) == "arm64") {
CmdArgs.push_back("-mllvm");
CmdArgs.push_back("-enable-machine-outliner");
// Outline from linkonceodr functions by default in LTO.
CmdArgs.push_back("-mllvm");
CmdArgs.push_back("-enable-linkonceodr-outlining");
}
}
// It seems that the 'e' option is completely ignored for dynamic executables
// (the default), and with static executables, the last one wins, as expected.
Args.AddAllArgs(CmdArgs, {options::OPT_d_Flag, options::OPT_s, options::OPT_t,

View File

@ -3,10 +3,6 @@
// ON: "-mllvm" "-enable-machine-outliner"
// RUN: %clang -target aarch64 -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF
// OFF: "-mllvm" "-enable-machine-outliner=never"
// RUN: %clang -target aarch64 -moutline -flto=thin -S %s -### 2>&1 | FileCheck %s -check-prefix=FLTO
// FLTO: "-mllvm" "-enable-linkonceodr-outlining"
// RUN: %clang -target aarch64 -moutline -flto=full -S %s -### 2>&1 | FileCheck %s -check-prefix=TLTO
// TLTO: "-mllvm" "-enable-linkonceodr-outlining"
// RUN: %clang -target x86_64 -moutline -S %s -### 2>&1 | FileCheck %s -check-prefix=WARN
// WARN: warning: The 'x86_64' architecture does not support -moutline; flag ignored [-Woption-ignored]
// WARN-NOT: "-mllvm" "-enable-machine-outliner"

View File

@ -371,3 +371,9 @@
// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -### %t.o 2> %t.log
// RUN: FileCheck -check-prefix=NO_PROFILE_EXPORT %s < %t.log
// NO_PROFILE_EXPORT-NOT: "-exported_symbol"
//
// Check that we can pass the outliner down to the linker.
// RUN: env IPHONEOS_DEPLOYMENT_TARGET=7.0 \
// RUN: %clang -target arm64-apple-darwin -moutline -### %t.o 2> %t.log
// MOUTLINE: ld
// MOUTLINE-SAME: "-mllvm" "-enable-machine-outliner" "-mllvm" "-enable-linkonceodr-outlining"