[MachineOutliner] Properly pass -moutline along to the toolchain
authorJessica Paquette <jpaquette@apple.com>
Fri, 6 Jul 2018 22:24:56 +0000 (22:24 +0000)
committerJessica Paquette <jpaquette@apple.com>
Fri, 6 Jul 2018 22:24:56 +0000 (22:24 +0000)
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.

llvm-svn: 336471

clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/aarch64-outliner.c
clang/test/Driver/darwin-ld.c

index d709280..4129139 100644 (file)
@@ -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.
index 11f7709..9205dd5 100644 (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,
index 82f02ff..eaf4e8a 100644 (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"
index 14f84bb..c98d1ab 100644 (file)
 // 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"