Index: include/llvm/Target/TargetMachine.h =================================================================== --- include/llvm/Target/TargetMachine.h +++ include/llvm/Target/TargetMachine.h @@ -210,6 +210,9 @@ bool getO0WantsFastISel() { return O0WantsFastISel; } void setO0WantsFastISel(bool Enable) { O0WantsFastISel = Enable; } void setGlobalISel(bool Enable) { Options.EnableGlobalISel = Enable; } + void setMachineOutliner(bool Enable) { + Options.EnableMachineOutliner = Enable; + } bool shouldPrintMachineCode() const { return Options.PrintMachineCode; } Index: include/llvm/Target/TargetOptions.h =================================================================== --- include/llvm/Target/TargetOptions.h +++ include/llvm/Target/TargetOptions.h @@ -107,9 +107,9 @@ EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false), DisableIntegratedAS(false), RelaxELFRelocations(false), FunctionSections(false), DataSections(false), - UniqueSectionNames(true), TrapUnreachable(false), - EmulatedTLS(false), ExplicitEmulatedTLS(false), - EnableIPRA(false), EmitStackSizeSection(false) {} + UniqueSectionNames(true), TrapUnreachable(false), EmulatedTLS(false), + ExplicitEmulatedTLS(false), EnableIPRA(false), + EmitStackSizeSection(false), EnableMachineOutliner(false) {} /// PrintMachineCode - This flag is enabled when the -print-machineinstrs /// option is specified on the command line, and should enable debugging @@ -226,6 +226,9 @@ /// Emit section containing metadata on function stack sizes. unsigned EmitStackSizeSection : 1; + /// Enable outlining. + unsigned EnableMachineOutliner: 1; + /// FloatABIType - This setting is set by -float-abi=xxx option is specfied /// on the command line. This setting may either be Default, Soft, or Hard. /// Default selects the target's default behavior. Soft selects the ABI for Index: lib/CodeGen/TargetPassConfig.cpp =================================================================== --- lib/CodeGen/TargetPassConfig.cpp +++ lib/CodeGen/TargetPassConfig.cpp @@ -114,6 +114,10 @@ static cl::opt EnableMachineOutliner("enable-machine-outliner", cl::Hidden, cl::desc("Enable machine outliner")); +static cl::opt DisableMachineOutliner("disable-machine-outliner", + cl::Hidden, + cl::init(false), + cl::desc("Disable machine outliner")); // Enable or disable FastISel. Both options are needed, because // FastISel is enabled by default with -fast, and we wish to be // able to enable or disable fast-isel independently from -O0. @@ -905,7 +909,13 @@ addPass(&XRayInstrumentationID, false); addPass(&PatchableFunctionID, false); - if (EnableMachineOutliner) + // If the user passes in -enable-machine-outliner we should add the outliner. + // If the target specifies that they want the outliner on by default, we + // should add it. + // If the user passes in -disable-machine-outliner, then that should override + // the previous two cases. + if (!DisableMachineOutliner && + (EnableMachineOutliner || TM->Options.EnableMachineOutliner)) addPass(createMachineOutlinerPass()); // Add passes that directly emit MI after all other MI passes. Index: lib/Target/AArch64/AArch64TargetMachine.cpp =================================================================== --- lib/Target/AArch64/AArch64TargetMachine.cpp +++ lib/Target/AArch64/AArch64TargetMachine.cpp @@ -268,6 +268,9 @@ // Enable GlobalISel at or below EnableGlobalISelAt0. if (getOptLevel() <= EnableGlobalISelAtO) setGlobalISel(true); + + if (getSizeOptLevel() == CodeGenSizeOpt::MinSize) + setMachineOutliner(true); } AArch64TargetMachine::~AArch64TargetMachine() = default; Index: test/CodeGen/AArch64/machine-outliner-flags.ll =================================================================== --- /dev/null +++ test/CodeGen/AArch64/machine-outliner-flags.ll @@ -0,0 +1,15 @@ +; Ensure the MachineOutliner is enabled by default in AArch64 at Oz, +; but not otherwise. +; RUN: llc %s -O=z -debug-pass=Structure -mtriple arm64---- -o /dev/null 2>&1 | FileCheck %s -check-prefix=DEFAULT +; DEFAULT: Machine Outliner +; RUN: llc %s -O=2 -debug-pass=Structure -mtriple arm64---- -o /dev/null 2>&1 | FileCheck %s -check-prefix=NOTOZ +; NOTOZ-NOT: Machine Outliner +; RUN: llc %s -O=z -disable-machine-outliner -debug-pass=Structure -mtriple arm64---- -o /dev/null 2>&1 | FileCheck %s -check-prefix=DISABLED +; DISABLED-NOT: Machine Outliner +; RUN: llc %s -O=z -debug-pass=Structure -mtriple=x86_64---- -o /dev/null 2>&1 | FileCheck %s -check-prefix=NOTON +; NOTON-NOT: Machine Outliner +; RUN: llc %s -enable-machine-outliner -disable-machine-outliner -debug-pass=Structure -mtriple=x86_64---- -o /dev/null 2>&1 | FileCheck %s -check-prefix=DISABLED2 +; DISABLED2-NOT: Machine Outliner +define void @foo() { + ret void +}