LLVM: lib/CodeGen/BranchFolding.cpp File Reference (original) (raw)
Go to the source code of this file.
| Macros | |
|---|---|
| #define | DEBUG_TYPE "branch-folder" |
| Functions | |
|---|---|
| STATISTIC (NumDeadBlocks, "Number of dead blocks removed") | |
| STATISTIC (NumBranchOpts, "Number of branches optimized") | |
| STATISTIC (NumTailMerge, "Number of block tails merged") | |
| STATISTIC (NumHoist, "Number of times common instructions are hoisted") | |
| STATISTIC (NumTailCalls, "Number of tail calls optimized") | |
| INITIALIZE_PASS (BranchFolderLegacy, DEBUG_TYPE, "Control Flow Optimizer", false, false) PreservedAnalyses BranchFolderPass | |
| static unsigned | HashMachineInstr (const MachineInstr &MI) |
| HashMachineInstr - Compute a hash value for MI and its operands. | |
| static unsigned | HashEndOfMBB (const MachineBasicBlock &MBB) |
| HashEndOfMBB - Hash the last instruction in the MBB. | |
| static bool | countsAsInstruction (const MachineInstr &MI) |
| Whether MI should be counted as an instruction when calculating common tail. | |
| static MachineBasicBlock::iterator | skipBackwardPastNonInstructions (MachineBasicBlock::iterator I, MachineBasicBlock *MBB) |
| Iterate backwards from the given iterator I, towards the beginning of the block. | |
| static unsigned | ComputeCommonTailLength (MachineBasicBlock *MBB1, MachineBasicBlock *MBB2, MachineBasicBlock::iterator &I1, MachineBasicBlock::iterator &I2) |
| Given two machine basic blocks, return the number of instructions they actually have in common together at their end. | |
| static unsigned | EstimateRuntime (MachineBasicBlock::iterator I, MachineBasicBlock::iterator E) |
| EstimateRuntime - Make a rough estimate for how long it will take to run the specified code. | |
| static void | FixTail (MachineBasicBlock *CurMBB, MachineBasicBlock *SuccBB, const TargetInstrInfo *TII, const DebugLoc &BranchDL) |
| static unsigned | CountTerminators (MachineBasicBlock *MBB, MachineBasicBlock::iterator &I) |
| CountTerminators - Count the number of terminators in the given block and set I to the position of the first non-terminator, if there is one, or MBB->end() otherwise. | |
| static bool | blockEndsInUnreachable (const MachineBasicBlock *MBB) |
| A no successor, non-return block probably ends in unreachable and is cold. | |
| static bool | ProfitableToMerge (MachineBasicBlock *MBB1, MachineBasicBlock *MBB2, unsigned MinCommonTailLength, unsigned &CommonTailLen, MachineBasicBlock::iterator &I1, MachineBasicBlock::iterator &I2, MachineBasicBlock *SuccBB, MachineBasicBlock *PredBB, DenseMap< const MachineBasicBlock *, int > &EHScopeMembership, bool AfterPlacement, MBFIWrapper &MBBFreqInfo, ProfileSummaryInfo *PSI) |
| ProfitableToMerge - Check if two machine basic blocks have a common tail and decide if it would be profitable to merge those tails. | |
| static void | mergeOperations (MachineBasicBlock::iterator MBBIStartPos, MachineBasicBlock &MBBCommon) |
| static bool | IsEmptyBlock (MachineBasicBlock *MBB) |
| static bool | IsBranchOnlyBlock (MachineBasicBlock *MBB) |
| static bool | IsBetterFallthrough (MachineBasicBlock *MBB1, MachineBasicBlock *MBB2) |
| IsBetterFallthrough - Return true if it would be clearly better to fall-through to MBB1 than to fall through into MBB2. | |
| static void | copyDebugInfoToPredecessor (const TargetInstrInfo *TII, MachineBasicBlock &MBB, MachineBasicBlock &PredMBB) |
| static void | copyDebugInfoToSuccessor (const TargetInstrInfo *TII, MachineBasicBlock &MBB, MachineBasicBlock &SuccMBB) |
| static void | salvageDebugInfoFromEmptyBlock (const TargetInstrInfo *TII, MachineBasicBlock &MBB) |
| static MachineBasicBlock * | findFalseBlock (MachineBasicBlock *BB, MachineBasicBlock *TrueBB) |
| findFalseBlock - BB has a fallthrough. | |
| template | |
| static void | addRegAndItsAliases (Register Reg, const TargetRegisterInfo *TRI, Container &Set) |
| static MachineBasicBlock::iterator | findHoistingInsertPosAndDeps (MachineBasicBlock *MBB, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI, SmallSet< Register, 4 > &Uses, SmallSet< Register, 4 > &Defs) |
| findHoistingInsertPosAndDeps - Find the location to move common instructions in successors to. |
◆ DEBUG_TYPE
#define DEBUG_TYPE "branch-folder"
◆ addRegAndItsAliases()
template
◆ blockEndsInUnreachable()
A no successor, non-return block probably ends in unreachable and is cold.
Also consider a block that ends in an indirect branch to be a return block, since many targets use plain indirect branches to return.
Definition at line 544 of file BranchFolding.cpp.
References MBB.
Referenced by ProfitableToMerge().
◆ ComputeCommonTailLength()
◆ copyDebugInfoToPredecessor()
◆ copyDebugInfoToSuccessor()
◆ countsAsInstruction()
◆ CountTerminators()
CountTerminators - Count the number of terminators in the given block and set I to the position of the first non-terminator, if there is one, or MBB->end() otherwise.
Definition at line 525 of file BranchFolding.cpp.
Referenced by ProfitableToMerge().
◆ EstimateRuntime()
◆ findFalseBlock()
◆ findHoistingInsertPosAndDeps()
findHoistingInsertPosAndDeps - Find the location to move common instructions in successors to.
The location is usually just before the terminator, however if the terminator is a conditional branch and its previous instruction is the flag setting instruction, the previous instruction is the preferred location. This function also gathers uses and defs of the instructions from the insertion point to the end of the block. The data is used by HoistCommonCodeInSuccs to ensure safety.
Definition at line 1855 of file BranchFolding.cpp.
References addRegAndItsAliases(), MBB, llvm::prev_nodbg(), Reg, SubReg, TII, TRI, and Uses.
◆ FixTail()
◆ HashEndOfMBB()
◆ HashMachineInstr()
◆ INITIALIZE_PASS()
| INITIALIZE_PASS | ( | BranchFolderLegacy | , |
|---|---|---|---|
| DEBUG_TYPE | , | ||
| "Control Flow Optimizer" | , | ||
| false | , | ||
| false | ) |
◆ IsBetterFallthrough()
◆ IsBranchOnlyBlock()
◆ IsEmptyBlock()
◆ mergeOperations()
Definition at line 786 of file BranchFolding.cpp.
References assert(), countsAsInstruction(), E(), I, llvm::MachineOperand::isReg(), llvm::MachineOperand::isUndef(), MBB, MBBI, llvm::MachineBasicBlock::rbegin(), llvm::MachineBasicBlock::rend(), and llvm::MachineOperand::setIsUndef().
◆ ProfitableToMerge()
| bool ProfitableToMerge ( MachineBasicBlock * MBB1, MachineBasicBlock * MBB2, unsigned MinCommonTailLength, unsigned & CommonTailLen, MachineBasicBlock::iterator & I1, MachineBasicBlock::iterator & I2, MachineBasicBlock * SuccBB, MachineBasicBlock * PredBB, DenseMap< const MachineBasicBlock *, int > & EHScopeMembership, bool AfterPlacement, MBFIWrapper & MBBFreqInfo, ProfileSummaryInfo * PSI ) | static |
|---|
ProfitableToMerge - Check if two machine basic blocks have a common tail and decide if it would be profitable to merge those tails.
Return the length of the common tail and iterators to the first common instruction in each block. MBB1, MBB2 The blocks to check MinCommonTailLength Minimum size of tail block to be merged. CommonTailLen Out parameter to record the size of the shared tail between MBB1 and MBB2 I1, I2 Iterator references that will be changed to point to the first instruction in the common tail shared by MBB1,MBB2 SuccBB A common successor of MBB1, MBB2 which are in a canonical form relative to SuccBB PredBB The layout predecessor of SuccBB, if any. EHScopeMembership map from block to EH scope #. AfterPlacement True if we are merging blocks after layout. Stricter thresholds apply to prevent undoing tail-duplication.
Definition at line 569 of file BranchFolding.cpp.
References assert(), llvm::MachineBasicBlock::back(), llvm::MachineBasicBlock::begin(), llvm::MachineFunction::begin(), blockEndsInUnreachable(), ComputeCommonTailLength(), CountTerminators(), llvm::dbgs(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::empty(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::MachineBasicBlock::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), I, llvm::MachineInstr::isBarrier(), llvm::MachineBasicBlock::isLayoutSuccessor(), LLVM_DEBUG, MBB, llvm::printMBBReference(), llvm::shouldOptimizeForSize(), llvm::skipDebugInstructionsForward(), and llvm::MachineBasicBlock::succ_size().
◆ salvageDebugInfoFromEmptyBlock()
◆ skipBackwardPastNonInstructions()
Iterate backwards from the given iterator I, towards the beginning of the block.
If a MI satisfying 'countsAsInstruction' is found, return an iterator pointing to that MI. If no such MI is found, return the end iterator.
Definition at line 338 of file BranchFolding.cpp.
References countsAsInstruction(), I, and MBB.
Referenced by ComputeCommonTailLength().
◆ STATISTIC() [1/5]
| STATISTIC | ( | NumBranchOpts | , |
|---|---|---|---|
| "Number of branches optimized" | ) |
◆ STATISTIC() [2/5]
| STATISTIC | ( | NumDeadBlocks | , |
|---|---|---|---|
| "Number of dead blocks removed" | ) |
◆ STATISTIC() [3/5]
| STATISTIC | ( | NumHoist | , |
|---|---|---|---|
| "Number of times common instructions are hoisted" | ) |
◆ STATISTIC() [4/5]
| STATISTIC | ( | NumTailCalls | , |
|---|---|---|---|
| "Number of tail calls optimized" | ) |
◆ STATISTIC() [5/5]
| STATISTIC | ( | NumTailMerge | , |
|---|---|---|---|
| "Number of block tails merged" | ) |
◆ FlagEnableTailMerge
| cl::opt< cl::boolOrDefault > FlagEnableTailMerge("enable-tail-merge", cl::init(cl::BOU_UNSET), cl::Hidden) ( "enable-tail-merge" , cl::init(cl::BOU_UNSET) , cl::Hidden ) | static |
|---|
◆ TailMergeSize
◆ TailMergeThreshold
| cl::opt< unsigned > TailMergeThreshold("tail-merge-threshold", cl::desc("Max number of predecessors to consider tail merging"), cl::init(150), cl::Hidden) ( "tail-merge-threshold" , cl::desc("Max number of predecessors to consider tail merging") , cl::init(150) , cl::Hidden ) | static |
|---|