LLVM 20.0.0git
|
Utility class to perform tail duplication. More...
#include "llvm/CodeGen/TailDuplicator.h"
Public Member Functions | |
void | initMF (MachineFunction &MF, bool PreRegAlloc, const MachineBranchProbabilityInfo *MBPI, MBFIWrapper *MBFI, ProfileSummaryInfo *PSI, bool LayoutMode, unsigned TailDupSize=0) |
Prepare to run on a specific machine function. | |
bool | tailDuplicateBlocks () |
Look for small blocks that are unconditionally branched to and do not fall through. | |
bool | shouldTailDuplicate (bool IsSimple, MachineBasicBlock &TailBB) |
Determine if it is profitable to duplicate this block. | |
bool | canTailDuplicate (MachineBasicBlock *TailBB, MachineBasicBlock *PredBB) |
Returns true if TailBB can successfully be duplicated into PredBB. | |
bool | tailDuplicateAndUpdate (bool IsSimple, MachineBasicBlock *MBB, MachineBasicBlock *ForcedLayoutPred, SmallVectorImpl< MachineBasicBlock * > *DuplicatedPreds=nullptr, function_ref< void(MachineBasicBlock *)> *RemovalCallback=nullptr, SmallVectorImpl< MachineBasicBlock * > *CandidatePtr=nullptr) |
Tail duplicate a single basic block into its predecessors, and then clean up. | |
Static Public Member Functions | |
static bool | isSimpleBB (MachineBasicBlock *TailBB) |
True if this BB has only one unconditional jump. | |
Utility class to perform tail duplication.
Definition at line 39 of file TailDuplicator.h.
bool TailDuplicator::canTailDuplicate | ( | MachineBasicBlock * | TailBB, |
MachineBasicBlock * | PredBB | ||
) |
Returns true if TailBB can successfully be duplicated into PredBB.
Definition at line 808 of file TailDuplicator.cpp.
References llvm::TargetInstrInfo::analyzeBranch(), llvm::SmallVectorBase< Size_T >::empty(), llvm::MachineBasicBlock::isInlineAsmBrIndirectTarget(), and llvm::MachineBasicBlock::succ_size().
void TailDuplicator::initMF | ( | MachineFunction & | MF, |
bool | PreRegAlloc, | ||
const MachineBranchProbabilityInfo * | MBPI, | ||
MBFIWrapper * | MBFI, | ||
ProfileSummaryInfo * | PSI, | ||
bool | LayoutMode, | ||
unsigned | TailDupSize = 0 |
||
) |
Prepare to run on a specific machine function.
MF | - Function that will be processed |
PreRegAlloc | - true if used before register allocation |
MBPI | - Branch Probability Info. Used to propagate correct probabilities when modifying the CFG. |
LayoutMode | - When true, don't use the existing layout to make decisions. |
TailDupSize | - Maxmimum size of blocks to tail-duplicate. Zero default implies using the command line value TailDupSize. |
Definition at line 90 of file TailDuplicator.cpp.
References assert(), llvm::TargetSubtargetInfo::getInstrInfo(), llvm::MachineFunction::getRegInfo(), llvm::TargetSubtargetInfo::getRegisterInfo(), and llvm::MachineFunction::getSubtarget().
Referenced by llvm::TailDuplicatePassBase< DerivedT, PreRegAlloc >::run().
|
static |
True if this BB has only one unconditional jump.
Definition at line 700 of file TailDuplicator.cpp.
References llvm::MachineBasicBlock::end(), llvm::MachineBasicBlock::getFirstNonDebugInstr(), I, llvm::MachineBasicBlock::pred_empty(), and llvm::MachineBasicBlock::succ_size().
Referenced by tailDuplicateBlocks().
bool TailDuplicator::shouldTailDuplicate | ( | bool | IsSimple, |
MachineBasicBlock & | TailBB | ||
) |
Determine if it is profitable to duplicate this block.
Definition at line 564 of file TailDuplicator.cpp.
References llvm::TargetInstrInfo::analyzeBranch(), assert(), llvm::MachineBasicBlock::back(), llvm::MachineBasicBlock::canFallThrough(), llvm::MachineBasicBlock::empty(), llvm::MachineBasicBlock::getParent(), getPHISrcRegOpIdx(), llvm::MachineOperand::getSubReg(), llvm::MachineFunction::getTarget(), llvm::TargetMachine::getTargetTriple(), I, Idx, InstrCount, llvm::MachineInstr::isIndirectBranch(), llvm::Triple::isOSDarwin(), llvm::MachineBasicBlock::isSuccessor(), MI, llvm::MachineBasicBlock::pred_size(), llvm::shouldOptimizeForSize(), llvm::MachineBasicBlock::succ_size(), llvm::MachineBasicBlock::successors(), TailDupIndirectBranchSize, TailDuplicateSize, TailDupPredSize, and TailDupSuccSize.
Referenced by tailDuplicateBlocks().
bool TailDuplicator::tailDuplicateAndUpdate | ( | bool | IsSimple, |
MachineBasicBlock * | MBB, | ||
MachineBasicBlock * | ForcedLayoutPred, | ||
SmallVectorImpl< MachineBasicBlock * > * | DuplicatedPreds = nullptr , |
||
function_ref< void(MachineBasicBlock *)> * | RemovalCallback = nullptr , |
||
SmallVectorImpl< MachineBasicBlock * > * | CandidatePtr = nullptr |
||
) |
Tail duplicate a single basic block into its predecessors, and then clean up.
Tail duplicate the block and cleanup.
If DuplicatePreds
is not null, it will be updated to contain the list of predecessors that received a copy of MBB
. If RemovalCallback
is non-null. It will be called before MBB is deleted. If CandidatePtr
is not null, duplicate into these blocks only.
IsSimple
- return value of isSimpleBB MBB
- block to be duplicated ForcedLayoutPred
- If non-null, treat this block as the layout predecessor, instead of using the ordering in MF DuplicatedPreds
- if non-null, DuplicatedPreds
will contain a list of all Preds that received a copy of MBB
. RemovalCallback
- if non-null, called just before MBB is deleted.
Definition at line 165 of file TailDuplicator.cpp.
References llvm::MachineSSAUpdater::AddAvailableValue(), llvm::MachineBasicBlock::clear(), llvm::MachineRegisterInfo::constrainRegClass(), Copies, DefMI, llvm::MachineInstr::getParent(), llvm::MachineRegisterInfo::getRegClass(), llvm::MachineSSAUpdater::GetValueInMiddleOfBlock(), llvm::MachineRegisterInfo::getVRegDef(), llvm::MachineBasicBlock::hasAddressTaken(), llvm::MachineRegisterInfo::hasOneNonDBGUse(), llvm::MachineSSAUpdater::Initialize(), isDead(), llvm::MachineInstr::isDebugValue(), llvm::MachineInstr::isPHI(), llvm::make_early_inc_range(), MBB, llvm::MachineBasicBlock::pred_empty(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::MachineRegisterInfo::replaceRegWith(), llvm::MachineSSAUpdater::RewriteUse(), llvm::SmallVectorBase< Size_T >::size(), llvm::MachineBasicBlock::size(), llvm::MachineBasicBlock::succ_begin(), llvm::MachineBasicBlock::succ_end(), llvm::MachineRegisterInfo::use_operands(), and UseMI.
Referenced by tailDuplicateBlocks().
bool TailDuplicator::tailDuplicateBlocks | ( | ) |
Look for small blocks that are unconditionally branched to and do not fall through.
Tail-duplicate their instructions into their predecessors to eliminate (dynamic) branches.
Definition at line 278 of file TailDuplicator.cpp.
References llvm::dbgs(), llvm::drop_begin(), isSimpleBB(), LLVM_DEBUG, llvm::make_early_inc_range(), MBB, shouldTailDuplicate(), tailDuplicateAndUpdate(), TailDupLimit, TailDupVerify, and VerifyPHIs().
Referenced by llvm::TailDuplicatePassBase< DerivedT, PreRegAlloc >::run().