diff options
author | Jessica Paquette <jpaquette@apple.com> | 2018-07-06 22:24:56 +0000 |
---|---|---|
committer | Jessica Paquette <jpaquette@apple.com> | 2018-07-06 22:24:56 +0000 |
commit | f3ac792d41b6b98ea71ee4b433dcee005be7922e (patch) | |
tree | 8faa3a59a8c607ff356005b80677fc21ab0b3b75 | |
parent | 4ad65cd262150f7e5930824cc68afb528cff515f (diff) |
[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
-rw-r--r-- | lib/Driver/ToolChains/Clang.cpp | 10 | ||||
-rw-r--r-- | lib/Driver/ToolChains/Darwin.cpp | 12 | ||||
-rw-r--r-- | test/Driver/aarch64-outliner.c | 4 | ||||
-rw-r--r-- | test/Driver/darwin-ld.c | 6 |
4 files changed, 19 insertions, 13 deletions
diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index d7092801df..4129139718 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -4757,16 +4757,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (Triple.getArch() != llvm::Triple::aarch64) { D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName(); } 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"); - } + CmdArgs.push_back("-enable-machine-outliner"); } } else { // Disable all outlining behaviour. diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp index 11f77096ae..9205dd52de 100644 --- a/lib/Driver/ToolChains/Darwin.cpp +++ b/lib/Driver/ToolChains/Darwin.cpp @@ -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, diff --git a/test/Driver/aarch64-outliner.c b/test/Driver/aarch64-outliner.c index 82f02ff99f..eaf4e8ad96 100644 --- a/test/Driver/aarch64-outliner.c +++ b/test/Driver/aarch64-outliner.c @@ -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" diff --git a/test/Driver/darwin-ld.c b/test/Driver/darwin-ld.c index 14f84bb053..c98d1abcab 100644 --- a/test/Driver/darwin-ld.c +++ b/test/Driver/darwin-ld.c @@ -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" |