class BranchFolder

Declaration

class BranchFolder { /* full declaration omitted */ };

Declared at: llvm/lib/CodeGen/BranchFolding.h:31

Member Variables

private std::vector<MergePotentialsElt> MergePotentials
private SmallPtrSet<const llvm::MachineBasicBlock*, 2> TriedMerging
private DenseMap<const llvm::MachineBasicBlock*, int> EHScopeMembership
private std::vector<SameTailElt> SameTails
private bool AfterBlockPlacement
private bool EnableTailMerge
private bool EnableHoistCommonCode
private bool UpdateLiveIns
private unsigned int MinCommonTailLength
private const llvm::TargetInstrInfo* TII
private const llvm::MachineRegisterInfo* MRI
private const llvm::TargetRegisterInfo* TRI
private llvm::MachineLoopInfo* MLI
private llvm::LivePhysRegs LiveRegs
private llvm::MBFIWrapper& MBBFreqInfo
private const llvm::MachineBranchProbabilityInfo& MBPI
private llvm::ProfileSummaryInfo* PSI

Method Overview

  • public BranchFolder(bool DefaultEnableTailMerge, bool CommonHoist, llvm::MBFIWrapper & FreqInfo, const llvm::MachineBranchProbabilityInfo & ProbInfo, llvm::ProfileSummaryInfo * PSI, unsigned int MinTailLength = 0)
  • private unsigned int ComputeSameTails(unsigned int CurHash, unsigned int minCommonTailLength, llvm::MachineBasicBlock * SuccBB, llvm::MachineBasicBlock * PredBB)
  • private bool CreateCommonTailOnlyBlock(llvm::MachineBasicBlock *& PredBB, llvm::MachineBasicBlock * SuccBB, unsigned int maxCommonTailLength, unsigned int & commonTailIndex)
  • private bool HoistCommonCode(llvm::MachineFunction & MF)
  • private bool HoistCommonCodeInSuccs(llvm::MachineBasicBlock * MBB)
  • private bool OptimizeBlock(llvm::MachineBasicBlock * MBB)
  • private bool OptimizeBranches(llvm::MachineFunction & MF)
  • public bool OptimizeFunction(llvm::MachineFunction & MF, const llvm::TargetInstrInfo * tii, const llvm::TargetRegisterInfo * tri, llvm::MachineLoopInfo * mli = nullptr, bool AfterPlacement = false)
  • private void RemoveBlocksWithHash(unsigned int CurHash, llvm::MachineBasicBlock * SuccBB, llvm::MachineBasicBlock * PredBB)
  • private void RemoveDeadBlock(llvm::MachineBasicBlock * MBB)
  • private llvm::MachineBasicBlock * SplitMBBAt(llvm::MachineBasicBlock & CurMBB, MachineBasicBlock::iterator BBI1, const llvm::BasicBlock * BB)
  • private bool TailMergeBlocks(llvm::MachineFunction & MF)
  • private bool TryTailMergeBlocks(llvm::MachineBasicBlock * SuccBB, llvm::MachineBasicBlock * PredBB, unsigned int MinCommonTailLength)
  • private void mergeCommonTails(unsigned int commonTailIndex)
  • private void replaceTailWithBranchTo(MachineBasicBlock::iterator OldInst, llvm::MachineBasicBlock & NewDest)
  • private void setCommonTailEdgeWeights(llvm::MachineBasicBlock & TailMBB)

Methods

BranchFolder(
    bool DefaultEnableTailMerge,
    bool CommonHoist,
    llvm::MBFIWrapper& FreqInfo,
    const llvm::MachineBranchProbabilityInfo&
        ProbInfo,
    llvm::ProfileSummaryInfo* PSI,
    unsigned int MinTailLength = 0)

Declared at: llvm/lib/CodeGen/BranchFolding.h:33

Parameters

bool DefaultEnableTailMerge
bool CommonHoist
llvm::MBFIWrapper& FreqInfo
const llvm::MachineBranchProbabilityInfo& ProbInfo
llvm::ProfileSummaryInfo* PSI
unsigned int MinTailLength = 0

unsigned int ComputeSameTails(
    unsigned int CurHash,
    unsigned int minCommonTailLength,
    llvm::MachineBasicBlock* SuccBB,
    llvm::MachineBasicBlock* PredBB)

Description

Look through all the blocks in MergePotentials that have hash CurHash (guaranteed to match the last element). Build the vector SameTails of all those that have the (same) largest number of instructions in common of any pair of these blocks. SameTails entries contain an iterator into MergePotentials (from which the MachineBasicBlock can be found) and a MachineBasicBlock::iterator into that MBB indicating the instruction where the matching code sequence begins. Order of elements in SameTails is the reverse of the order in which those blocks appear in MergePotentials (where they are not necessarily consecutive).

Declared at: llvm/lib/CodeGen/BranchFolding.h:159

Parameters

unsigned int CurHash
unsigned int minCommonTailLength
llvm::MachineBasicBlock* SuccBB
llvm::MachineBasicBlock* PredBB

bool CreateCommonTailOnlyBlock(
    llvm::MachineBasicBlock*& PredBB,
    llvm::MachineBasicBlock* SuccBB,
    unsigned int maxCommonTailLength,
    unsigned int& commonTailIndex)

Description

None of the blocks to be tail-merged consist only of the common tail. Create a block that does by splitting one.

Declared at: llvm/lib/CodeGen/BranchFolding.h:170

Parameters

llvm::MachineBasicBlock*& PredBB
llvm::MachineBasicBlock* SuccBB
unsigned int maxCommonTailLength
unsigned int& commonTailIndex

bool HoistCommonCode(llvm::MachineFunction& MF)

Description

Hoist common instruction sequences at the start of basic blocks to their common predecessor.

Declared at: llvm/lib/CodeGen/BranchFolding.h:191

Parameters

llvm::MachineFunction& MF

bool HoistCommonCodeInSuccs(
    llvm::MachineBasicBlock* MBB)

Description

If the successors of MBB has common instruction sequence at the start of the function, move the instructions before MBB terminator if it's legal.

Declared at: llvm/lib/CodeGen/BranchFolding.h:195

Parameters

llvm::MachineBasicBlock* MBB

bool OptimizeBlock(llvm::MachineBasicBlock* MBB)

Description

Analyze and optimize control flow related to the specified block. This is never called on the entry block.

Declared at: llvm/lib/CodeGen/BranchFolding.h:183

Parameters

llvm::MachineBasicBlock* MBB

bool OptimizeBranches(llvm::MachineFunction& MF)

Declared at: llvm/lib/CodeGen/BranchFolding.h:179

Parameters

llvm::MachineFunction& MF

bool OptimizeFunction(
    llvm::MachineFunction& MF,
    const llvm::TargetInstrInfo* tii,
    const llvm::TargetRegisterInfo* tri,
    llvm::MachineLoopInfo* mli = nullptr,
    bool AfterPlacement = false)

Description

Perhaps branch folding, tail merging and other CFG optimizations on the given function. Block placement changes the layout and may create new tail merging opportunities.

Declared at: llvm/lib/CodeGen/BranchFolding.h:44

Parameters

llvm::MachineFunction& MF
const llvm::TargetInstrInfo* tii
const llvm::TargetRegisterInfo* tri
llvm::MachineLoopInfo* mli = nullptr
bool AfterPlacement = false

void RemoveBlocksWithHash(
    unsigned int CurHash,
    llvm::MachineBasicBlock* SuccBB,
    llvm::MachineBasicBlock* PredBB)

Description

Remove all blocks with hash CurHash from MergePotentials, restoring branches at ends of blocks as appropriate.

Declared at: llvm/lib/CodeGen/BranchFolding.h:165

Parameters

unsigned int CurHash
llvm::MachineBasicBlock* SuccBB
llvm::MachineBasicBlock* PredBB

void RemoveDeadBlock(llvm::MachineBasicBlock* MBB)

Description

Remove the specified dead machine basic block from the function, updating the CFG.

Declared at: llvm/lib/CodeGen/BranchFolding.h:187

Parameters

llvm::MachineBasicBlock* MBB

llvm::MachineBasicBlock* SplitMBBAt(
    llvm::MachineBasicBlock& CurMBB,
    MachineBasicBlock::iterator BBI1,
    const llvm::BasicBlock* BB)

Description

Given a machine basic block and an iterator into it, split the MBB so that the part before the iterator falls into the part starting at the iterator. This returns the new MBB.

Declared at: llvm/lib/CodeGen/BranchFolding.h:146

Parameters

llvm::MachineBasicBlock& CurMBB
MachineBasicBlock::iterator BBI1
const llvm::BasicBlock* BB

bool TailMergeBlocks(llvm::MachineFunction& MF)

Declared at: llvm/lib/CodeGen/BranchFolding.h:132

Parameters

llvm::MachineFunction& MF

bool TryTailMergeBlocks(
    llvm::MachineBasicBlock* SuccBB,
    llvm::MachineBasicBlock* PredBB,
    unsigned int MinCommonTailLength)

Declared at: llvm/lib/CodeGen/BranchFolding.h:133

Parameters

llvm::MachineBasicBlock* SuccBB
llvm::MachineBasicBlock* PredBB
unsigned int MinCommonTailLength

void mergeCommonTails(
    unsigned int commonTailIndex)

Description

Create merged DebugLocs of identical instructions across SameTails and assign it to the instruction in common tail; merge MMOs and undef flags.

Declared at: llvm/lib/CodeGen/BranchFolding.h:177

Parameters

unsigned int commonTailIndex

void replaceTailWithBranchTo(
    MachineBasicBlock::iterator OldInst,
    llvm::MachineBasicBlock& NewDest)

Description

Delete the instruction OldInst and everything after it, replacing it with an unconditional branch to NewDest.

Declared at: llvm/lib/CodeGen/BranchFolding.h:140

Parameters

MachineBasicBlock::iterator OldInst
llvm::MachineBasicBlock& NewDest

void setCommonTailEdgeWeights(
    llvm::MachineBasicBlock& TailMBB)

Declared at: llvm/lib/CodeGen/BranchFolding.h:136

Parameters

llvm::MachineBasicBlock& TailMBB