Index: include/llvm/CodeGen/TargetInstrInfo.h =================================================================== --- include/llvm/CodeGen/TargetInstrInfo.h +++ include/llvm/CodeGen/TargetInstrInfo.h @@ -1602,9 +1602,6 @@ return false; } - /// Returns true if the target implements the MachineOutliner. - virtual bool useMachineOutliner() const { return false; } - /// Returns a \p outliner::TargetCostInfo struct containing target-specific /// information for a set of outlining candidates. virtual outliner::TargetCostInfo getOutlininingCandidateInfo( Index: include/llvm/Target/TargetMachine.h =================================================================== --- include/llvm/Target/TargetMachine.h +++ include/llvm/Target/TargetMachine.h @@ -202,6 +202,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 @@ -109,7 +109,8 @@ FunctionSections(false), DataSections(false), UniqueSectionNames(true), TrapUnreachable(false), EmulatedTLS(false), ExplicitEmulatedTLS(false), - EnableIPRA(false), EmitStackSizeSection(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 +227,9 @@ /// Emit section containing metadata on function stack sizes. unsigned EmitStackSizeSection : 1; + /// Enables the MachineOutliner pass. + 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/MachineOutliner.cpp =================================================================== --- lib/CodeGen/MachineOutliner.cpp +++ lib/CodeGen/MachineOutliner.cpp @@ -1331,15 +1331,6 @@ const TargetRegisterInfo *TRI = STI.getRegisterInfo(); const TargetInstrInfo *TII = STI.getInstrInfo(); - // Does the target implement the MachineOutliner? If it doesn't, quit here. - if (!TII->useMachineOutliner()) { - // No. So we're done. - LLVM_DEBUG( - dbgs() - << "Skipping pass: Target does not support the MachineOutliner.\n"); - return false; - } - // If the user specifies that they want to outline from linkonceodrs, set // it here. OutlineFromLinkOnceODRs = EnableLinkOnceODROutlining; Index: lib/CodeGen/TargetPassConfig.cpp =================================================================== --- lib/CodeGen/TargetPassConfig.cpp +++ lib/CodeGen/TargetPassConfig.cpp @@ -914,7 +914,9 @@ addPass(&XRayInstrumentationID, false); addPass(&PatchableFunctionID, false); - if (EnableMachineOutliner == AlwaysOutline) + if (TM->Options.EnableMachineOutliner && + getOptLevel() != CodeGenOpt::None && + EnableMachineOutliner == AlwaysOutline) addPass(createMachineOutlinerPass()); // Add passes that directly emit MI after all other MI passes. Index: lib/Target/AArch64/AArch64InstrInfo.h =================================================================== --- lib/Target/AArch64/AArch64InstrInfo.h +++ lib/Target/AArch64/AArch64InstrInfo.h @@ -236,8 +236,6 @@ ArrayRef> getSerializableMachineMemOperandTargetFlags() const override; - /// AArch64 supports the MachineOutliner. - bool useMachineOutliner() const override { return true; } bool isFunctionSafeToOutlineFrom(MachineFunction &MF, bool OutlineFromLinkOnceODRs) const override; outliner::TargetCostInfo getOutlininingCandidateInfo( Index: lib/Target/AArch64/AArch64TargetMachine.cpp =================================================================== --- lib/Target/AArch64/AArch64TargetMachine.cpp +++ lib/Target/AArch64/AArch64TargetMachine.cpp @@ -250,6 +250,9 @@ // Enable GlobalISel at or below EnableGlobalISelAt0. if (getOptLevel() <= EnableGlobalISelAtO) setGlobalISel(true); + + // AArch64 supports the MachineOutliner. + setMachineOutliner(true); } AArch64TargetMachine::~AArch64TargetMachine() = default; Index: lib/Target/X86/X86InstrInfo.h =================================================================== --- lib/Target/X86/X86InstrInfo.h +++ lib/Target/X86/X86InstrInfo.h @@ -553,9 +553,6 @@ ArrayRef> getSerializableDirectMachineOperandTargetFlags() const override; - /// X86 supports the MachineOutliner. - bool useMachineOutliner() const override { return true; } - virtual outliner::TargetCostInfo getOutlininingCandidateInfo( std::vector &RepeatedSequenceLocs) const override; Index: lib/Target/X86/X86TargetMachine.cpp =================================================================== --- lib/Target/X86/X86TargetMachine.cpp +++ lib/Target/X86/X86TargetMachine.cpp @@ -232,6 +232,10 @@ TT.isOSBinFormatMachO()) this->Options.TrapUnreachable = true; + // Outlining is available for x86-64. + if (TT.getArch() == Triple::x86_64) + setMachineOutliner(true); + initAsmInfo(); }