LLVM 24.0.0git
MachineOutliner.cpp File Reference

Replaces repeated sequences of instructions with function calls. More...

Go to the source code of this file.

Classes

struct  MatchedEntry

Macros

#define DEBUG_TYPE   "machine-outliner"

Functions

 STATISTIC (NumOutlined, "Number of candidates outlined")
 STATISTIC (FunctionsCreated, "Number of functions created")
 STATISTIC (NumLegalInUnsignedVec, "Outlinable instructions mapped")
 STATISTIC (NumIllegalInUnsignedVec, "Unoutlinable instructions mapped + number of sentinel values")
 STATISTIC (NumSentinels, "Sentinel values inserted during mapping")
 STATISTIC (NumInvisible, "Non-debug invisible instructions skipped during mapping")
 STATISTIC (UnsignedVecSize, "Total number of instructions mapped and saved to mapping vector")
 STATISTIC (StableHashAttempts, "Count of hashing attempts made for outlined functions")
 STATISTIC (StableHashDropped, "Count of unsuccessful hashing attempts for outlined functions")
 STATISTIC (UnprofitableCandidateGroupsPublished, "Number of locally unprofitable candidate groups published")
 STATISTIC (UnprofitableCandidateSitesPublished, "Number of locally unprofitable candidate sites published")
 STATISTIC (NumRemovedLOHs, "Total number of Linker Optimization Hints removed")
 STATISTIC (NumPGOBlockedOutlined, "Number of times outlining was blocked by PGO")
 STATISTIC (NumPGOAllowedCold, "Number of times outlining was allowed from cold functions")
 STATISTIC (NumPGOConservativeBlockedOutlined, "Number of times outlining was blocked conservatively when profile " "counts were missing")
 STATISTIC (NumPGOOptimisticOutlined, "Number of times outlining was allowed optimistically when profile " "counts were missing")
 INITIALIZE_PASS (MachineOutliner, DEBUG_TYPE, "Machine Function Outliner", false, false) void MachineOutliner
static stable_hash hashInstruction (const MachineInstr &MI)
static SmallVector< MatchedEntry > getMatchedEntries (InstructionMapper &Mapper, const OutlinedHashTree &HashTree)
static StringRef getCandidateInputSection (const Candidate &C)
static SmallVector< std::vector< Candidate > > partitionCandidatesByInputSection (std::vector< Candidate > &Candidates)
static bool allowPGOOutlining (RunOutliner RunOutlinerMode, const ProfileSummaryInfo *PSI, const BlockFrequencyInfo *BFI, MachineBasicBlock &MBB)

Detailed Description

Replaces repeated sequences of instructions with function calls.

This works by placing every instruction from every basic block in a suffix tree, and repeatedly querying that tree for repeated sequences of instructions. If a sequence of instructions appears often, then it ought to be beneficial to pull out into a function.

The MachineOutliner communicates with a given target using hooks defined in TargetInstrInfo.h. The target supplies the outliner with information on how a specific sequence of instructions should be outlined. This information is used to deduce the number of instructions necessary to

  • Create an outlined function
  • Call that outlined function

Targets must implement

  • getOutliningCandidateInfo
  • buildOutlinedFrame
  • insertOutlinedCall
  • isFunctionSafeToOutlineFrom

in order to make use of the MachineOutliner.

This was originally presented at the 2016 LLVM Developers' Meeting in the talk "Reducing Code Size Using Outlining". For a high-level overview of how this pass works, the talk is available on YouTube at

https://www.youtube.com/watch?v=yorld-WSOeU

The slides for the talk are available at

http://www.llvm.org/devmtg/2016-11/Slides/Paquette-Outliner.pdf

The talk provides an overview of how the outliner finds candidates and ultimately outlines them. It describes how the main data structure for this pass, the suffix tree, is queried and purged for candidates. It also gives a simplified suffix tree construction algorithm for suffix trees based off of the algorithm actually used here, Ukkonen's algorithm.

For the original RFC for this pass, please see

http://lists.llvm.org/pipermail/llvm-dev/2016-August/104170.html

For more information on the suffix tree data structure, please see https://www.cs.helsinki.fi/u/ukkonen/SuffixT1withFigs.pdf

Definition in file MachineOutliner.cpp.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "machine-outliner"

Definition at line 91 of file MachineOutliner.cpp.

Function Documentation

◆ allowPGOOutlining()

◆ getCandidateInputSection()

StringRef getCandidateInputSection ( const Candidate & C)
static

Definition at line 746 of file MachineOutliner.cpp.

References C(), and F.

Referenced by partitionCandidatesByInputSection().

◆ getMatchedEntries()

◆ hashInstruction()

stable_hash hashInstruction ( const MachineInstr & MI)
static

Definition at line 636 of file MachineOutliner.cpp.

References MI, and llvm::stableHashValue().

Referenced by getMatchedEntries().

◆ INITIALIZE_PASS()

INITIALIZE_PASS ( MachineOutliner ,
DEBUG_TYPE ,
"Machine Function Outliner" ,
false ,
false  )

Definition at line 574 of file MachineOutliner.cpp.

References C(), DEBUG_TYPE, getDebugLoc(), and MORE.

◆ partitionCandidatesByInputSection()

◆ STATISTIC() [1/16]

STATISTIC ( FunctionsCreated ,
"Number of functions created"  )

◆ STATISTIC() [2/16]

STATISTIC ( NumIllegalInUnsignedVec ,
"Unoutlinable instructions mapped + number of sentinel values"  )

◆ STATISTIC() [3/16]

STATISTIC ( NumInvisible ,
"Non-debug invisible instructions skipped during mapping"  )

◆ STATISTIC() [4/16]

STATISTIC ( NumLegalInUnsignedVec ,
"Outlinable instructions mapped"  )

◆ STATISTIC() [5/16]

STATISTIC ( NumOutlined ,
"Number of candidates outlined"  )

◆ STATISTIC() [6/16]

STATISTIC ( NumPGOAllowedCold ,
"Number of times outlining was allowed from cold functions"  )

◆ STATISTIC() [7/16]

STATISTIC ( NumPGOBlockedOutlined ,
"Number of times outlining was blocked by PGO"  )

◆ STATISTIC() [8/16]

STATISTIC ( NumPGOConservativeBlockedOutlined ,
"Number of times outlining was blocked conservatively when profile " "counts were missing"  )

◆ STATISTIC() [9/16]

STATISTIC ( NumPGOOptimisticOutlined ,
"Number of times outlining was allowed optimistically when profile " "counts were missing"  )

References MI.

◆ STATISTIC() [10/16]

STATISTIC ( NumRemovedLOHs ,
"Total number of Linker Optimization Hints removed"  )

◆ STATISTIC() [11/16]

STATISTIC ( NumSentinels ,
"Sentinel values inserted during mapping"  )

◆ STATISTIC() [12/16]

STATISTIC ( StableHashAttempts ,
"Count of hashing attempts made for outlined functions"  )

◆ STATISTIC() [13/16]

STATISTIC ( StableHashDropped ,
"Count of unsuccessful hashing attempts for outlined functions"  )

◆ STATISTIC() [14/16]

STATISTIC ( UnprofitableCandidateGroupsPublished ,
"Number of locally unprofitable candidate groups published"  )

◆ STATISTIC() [15/16]

STATISTIC ( UnprofitableCandidateSitesPublished ,
"Number of locally unprofitable candidate sites published"  )

◆ STATISTIC() [16/16]

STATISTIC ( UnsignedVecSize ,
"Total number of instructions mapped and saved to mapping vector"  )