LLVM 20.0.0git
|
This pass performs 'jump threading', which looks at blocks that have multiple predecessors and multiple successors. More...
#include "llvm/Transforms/Scalar/JumpThreading.h"
Public Member Functions | |
JumpThreadingPass (int T=-1) | |
bool | runImpl (Function &F, FunctionAnalysisManager *FAM, TargetLibraryInfo *TLI, TargetTransformInfo *TTI, LazyValueInfo *LVI, AAResults *AA, std::unique_ptr< DomTreeUpdater > DTU, std::optional< BlockFrequencyInfo * > BFI, std::optional< BranchProbabilityInfo * > BPI) |
PreservedAnalyses | run (Function &F, FunctionAnalysisManager &AM) |
DomTreeUpdater * | getDomTreeUpdater () const |
void | findLoopHeaders (Function &F) |
findLoopHeaders - We do not want jump threading to turn proper loop structures into irreducible loops. | |
bool | processBlock (BasicBlock *BB) |
processBlock - If there are any predecessors whose control can be threaded through to a successor, transform them now. | |
bool | maybeMergeBasicBlockIntoOnlyPred (BasicBlock *BB) |
Merge basic block BB into its sole predecessor if possible. | |
void | updateSSA (BasicBlock *BB, BasicBlock *NewBB, ValueToValueMapTy &ValueMapping) |
Update the SSA form. | |
void | cloneInstructions (ValueToValueMapTy &ValueMapping, BasicBlock::iterator BI, BasicBlock::iterator BE, BasicBlock *NewBB, BasicBlock *PredBB) |
Clone instructions in range [BI, BE) to NewBB. | |
bool | tryThreadEdge (BasicBlock *BB, const SmallVectorImpl< BasicBlock * > &PredBBs, BasicBlock *SuccBB) |
tryThreadEdge - Thread an edge if it's safe and profitable to do so. | |
void | threadEdge (BasicBlock *BB, const SmallVectorImpl< BasicBlock * > &PredBBs, BasicBlock *SuccBB) |
threadEdge - We have decided that it is safe and profitable to factor the blocks in PredBBs to one predecessor, then thread an edge from it to SuccBB across BB. | |
bool | duplicateCondBranchOnPHIIntoPred (BasicBlock *BB, const SmallVectorImpl< BasicBlock * > &PredBBs) |
duplicateCondBranchOnPHIIntoPred - PredBB contains an unconditional branch to BB which contains an i1 PHI node and a conditional branch on that PHI. | |
bool | computeValueKnownInPredecessorsImpl (Value *V, BasicBlock *BB, jumpthreading::PredValueInfo &Result, jumpthreading::ConstantPreference Preference, SmallPtrSet< Value *, 4 > &RecursionSet, Instruction *CxtI=nullptr) |
computeValueKnownInPredecessors - Given a basic block BB and a value V, see if we can infer that the value is a known ConstantInt/BlockAddress or undef in any of our predecessors. | |
bool | computeValueKnownInPredecessors (Value *V, BasicBlock *BB, jumpthreading::PredValueInfo &Result, jumpthreading::ConstantPreference Preference, Instruction *CxtI=nullptr) |
Constant * | evaluateOnPredecessorEdge (BasicBlock *BB, BasicBlock *PredPredBB, Value *cond, const DataLayout &DL) |
bool | maybethreadThroughTwoBasicBlocks (BasicBlock *BB, Value *Cond) |
Attempt to thread through two successive basic blocks. | |
void | threadThroughTwoBasicBlocks (BasicBlock *PredPredBB, BasicBlock *PredBB, BasicBlock *BB, BasicBlock *SuccBB) |
bool | processThreadableEdges (Value *Cond, BasicBlock *BB, jumpthreading::ConstantPreference Preference, Instruction *CxtI=nullptr) |
bool | processBranchOnPHI (PHINode *PN) |
processBranchOnPHI - We have an otherwise unthreadable conditional branch on a PHI node (or freeze PHI) in the current block. | |
bool | processBranchOnXOR (BinaryOperator *BO) |
processBranchOnXOR - We have an otherwise unthreadable conditional branch on a xor instruction in the current block. | |
bool | processImpliedCondition (BasicBlock *BB) |
bool | simplifyPartiallyRedundantLoad (LoadInst *LI) |
simplifyPartiallyRedundantLoad - If LoadI is an obviously partially redundant load instruction, eliminate it by replacing it with a PHI node. | |
void | unfoldSelectInstr (BasicBlock *Pred, BasicBlock *BB, SelectInst *SI, PHINode *SIUse, unsigned Idx) |
bool | tryToUnfoldSelect (CmpInst *CondCmp, BasicBlock *BB) |
tryToUnfoldSelect - Look for blocks of the form bb1: a = select br bb2 | |
bool | tryToUnfoldSelect (SwitchInst *SI, BasicBlock *BB) |
bool | tryToUnfoldSelectInCurrBB (BasicBlock *BB) |
tryToUnfoldSelectInCurrBB - Look for PHI/Select or PHI/CMP/Select in the same BB in the form bb: p = phi [false, bb1], [true, bb2], [false, bb3], [true, bb4], ... s = select p, trueval, falseval | |
bool | processGuards (BasicBlock *BB) |
Try to propagate a guard from the current BB into one of its predecessors in case if another branch of execution implies that the condition of this guard is always true. | |
bool | threadGuard (BasicBlock *BB, IntrinsicInst *Guard, BranchInst *BI) |
Try to propagate the guard from BB which is the lower block of a diamond to one of its branches, in case if diamond's condition implies guard's condition. | |
Public Member Functions inherited from llvm::PassInfoMixin< JumpThreadingPass > | |
void | printPipeline (raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName) |
Additional Inherited Members | |
Static Public Member Functions inherited from llvm::PassInfoMixin< JumpThreadingPass > | |
static StringRef | name () |
Gets the name of the pass we are mixed into. | |
This pass performs 'jump threading', which looks at blocks that have multiple predecessors and multiple successors.
If one or more of the predecessors of the block can be proven to always jump to one of the successors, we forward the edge from the predecessor to the successor by duplicating the contents of this block.
An example of when this can occur is code like this:
if () { ... X = 4; } if (X < 3) {
In this case, the unconditional branch at the end of the first if can be revectored to the false side of the second if.
Definition at line 79 of file JumpThreading.h.
JumpThreadingPass::JumpThreadingPass | ( | int | T = -1 | ) |
Definition at line 110 of file JumpThreading.cpp.
References BBDuplicateThreshold.
void JumpThreadingPass::cloneInstructions | ( | ValueToValueMapTy & | ValueMapping, |
BasicBlock::iterator | BI, | ||
BasicBlock::iterator | BE, | ||
BasicBlock * | NewBB, | ||
BasicBlock * | PredBB | ||
) |
Clone instructions in range [BI, BE) to NewBB.
For PHI nodes, we only clone arguments that come from PredBB. Return the map from the variables in the source basic block to the variables in the newly created basic block.
Definition at line 2003 of file JumpThreading.cpp.
References llvm::adaptNoAliasScopes(), llvm::PHINode::addIncoming(), llvm::Instruction::cloneDebugInfoFrom(), llvm::DbgMarker::cloneDebugInfoFrom(), llvm::cloneNoAliasScopes(), llvm::PHINode::Create(), llvm::BasicBlock::createMarker(), llvm::BasicBlock::end(), llvm::ValueMap< KeyT, ValueT, Config >::end(), llvm::filterDbgVars(), llvm::ValueMap< KeyT, ValueT, Config >::find(), From, llvm::BasicBlock::getContext(), llvm::PHINode::getIncomingValueForBlock(), llvm::BasicBlock::getMarker(), llvm::Value::getName(), llvm::BasicBlock::getParent(), llvm::Value::getType(), I, llvm::identifyNoAliasScopesToClone(), and llvm::SmallSet< T, N, C >::insert().
Referenced by threadEdge(), and threadThroughTwoBasicBlocks().
|
inline |
Definition at line 135 of file JumpThreading.h.
References computeValueKnownInPredecessorsImpl().
Referenced by processBranchOnXOR(), and processThreadableEdges().
bool JumpThreadingPass::computeValueKnownInPredecessorsImpl | ( | Value * | V, |
BasicBlock * | BB, | ||
jumpthreading::PredValueInfo & | Result, | ||
jumpthreading::ConstantPreference | Preference, | ||
SmallPtrSet< Value *, 4 > & | RecursionSet, | ||
Instruction * | CxtI = nullptr |
||
) |
computeValueKnownInPredecessors - Given a basic block BB and a value V, see if we can infer that the value is a known ConstantInt/BlockAddress or undef in any of our predecessors.
If so, return the known list of value and pred BB in the result vector.
This returns true if there were any known values.
If I is a PHI node, then we know the incoming values for any constants.
Definition at line 559 of file JumpThreading.cpp.
References llvm::ConstantRange::add(), assert(), llvm::CallingConv::C, computeValueKnownInPredecessorsImpl(), Cond, llvm::ConstantFoldBinaryOpOperands(), llvm::ConstantFoldCastOperand(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantRange::contains(), llvm::SmallPtrSetImpl< PtrType >::count(), DL, llvm::Value::DoPHITranslation(), llvm::SmallVectorBase< Size_T >::empty(), llvm::erase_if(), llvm::LazyValueInfo::getConstant(), llvm::LazyValueInfo::getConstantOnEdge(), llvm::LazyValueInfo::getConstantRangeOnEdge(), llvm::BasicBlock::getDataLayout(), llvm::Instruction::getDataLayout(), llvm::ConstantInt::getFalse(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), getKnownConstant(), llvm::ConstantExpr::getNot(), llvm::PHINode::getNumIncomingValues(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), getParent(), llvm::LazyValueInfo::getPredicateOnEdge(), llvm::ConstantInt::getTrue(), llvm::ConstantInt::getValue(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::ConstantRange::inverse(), llvm::isGuaranteedNotToBeUndefOrPoison(), llvm::Type::isVectorTy(), LHS, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_Cmp(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_LogicalOr(), llvm::PatternMatch::m_Value(), llvm::ConstantRange::makeExactICmpRegion(), llvm::PatternMatch::match(), P, llvm::predecessors(), RHS, llvm::simplifyCmpInst(), and llvm::jumpthreading::WantInteger.
Referenced by computeValueKnownInPredecessors(), and computeValueKnownInPredecessorsImpl().
bool JumpThreadingPass::duplicateCondBranchOnPHIIntoPred | ( | BasicBlock * | BB, |
const SmallVectorImpl< BasicBlock * > & | PredBBs | ||
) |
duplicateCondBranchOnPHIIntoPred - PredBB contains an unconditional branch to BB which contains an i1 PHI node and a conditional branch on that PHI.
If we can duplicate the contents of BB up into PredBB do so now, this improves the odds that the branch will be on an analyzable instruction like a compare.
Definition at line 2617 of file JumpThreading.cpp.
References addPHINodeEntriesForMappedBlock(), assert(), llvm::BasicBlock::begin(), llvm::Instruction::cloneDebugInfoFrom(), llvm::BranchProbabilityInfo::copyEdgeProbabilities(), llvm::dbgs(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::SmallVectorBase< Size_T >::empty(), llvm::BasicBlock::end(), llvm::ValueMap< KeyT, ValueT, Config >::end(), llvm::Instruction::eraseFromParent(), llvm::ValueMap< KeyT, ValueT, Config >::find(), llvm::BasicBlock::getDataLayout(), llvm::PHINode::getIncomingValueForBlock(), llvm::ilist_node_impl< OptionsT >::getIterator(), getJumpThreadDuplicationCost(), llvm::Value::getName(), llvm::BranchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), I, llvm::DominatorTreeBase< BasicBlock, false >::Insert, llvm::BranchInst::isUnconditional(), IV, LLVM_DEBUG, llvm::remapDebugVariable(), llvm::BasicBlock::removePredecessor(), llvm::simplifyInstruction(), llvm::SmallVectorBase< Size_T >::size(), llvm::SplitEdge(), and updateSSA().
Referenced by processBranchOnPHI(), and processBranchOnXOR().
Constant * JumpThreadingPass::evaluateOnPredecessorEdge | ( | BasicBlock * | BB, |
BasicBlock * | PredPredBB, | ||
Value * | cond, | ||
const DataLayout & | DL | ||
) |
Definition at line 1499 of file JumpThreading.cpp.
References assert(), llvm::ConstantFoldCompareInstOperands(), DL, evaluateOnPredecessorEdge(), llvm::LazyValueInfo::getConstantOnEdge(), llvm::BasicBlock::getSinglePredecessor(), I, and PHI.
Referenced by evaluateOnPredecessorEdge(), and maybethreadThroughTwoBasicBlocks().
void JumpThreadingPass::findLoopHeaders | ( | Function & | F | ) |
findLoopHeaders - We do not want jump threading to turn proper loop structures into irreducible loops.
Doing this breaks up the loop nesting hierarchy and pessimizes later transformations. To prevent this from happening, we first have to find the loop headers. Here we approximate this by finding targets of backedges in the CFG.
Note that there definitely are cases when we want to allow threading of edges across a loop header. For example, threading a jump from outside the loop (the preheader) to an exit block of the loop is definitely profitable. It is also almost always profitable to thread backedges from within the loop to exit blocks, and is often profitable to thread backedges to other blocks within the loop (forming a nested loop). This simple analysis is not rich enough to track all of these properties and keep it up-to-date as the CFG mutates, so we don't allow any of these transformations.
Definition at line 526 of file JumpThreading.cpp.
References F, and llvm::FindFunctionBackedges().
Referenced by runImpl().
|
inline |
Definition at line 113 of file JumpThreading.h.
Referenced by run().
bool JumpThreadingPass::maybeMergeBasicBlockIntoOnlyPred | ( | BasicBlock * | BB | ) |
Merge basic block BB into its sole predecessor if possible.
Definition at line 1889 of file JumpThreading.cpp.
References llvm::LazyValueInfo::eraseBlock(), llvm::Instruction::getNumSuccessors(), llvm::BasicBlock::getSinglePredecessor(), llvm::BasicBlock::getTerminator(), hasAddressTakenAndUsed(), llvm::isGuaranteedToTransferExecutionToSuccessor(), llvm::Instruction::isSpecialTerminator(), and llvm::MergeBasicBlockIntoOnlyPred().
Referenced by processBlock().
bool JumpThreadingPass::maybethreadThroughTwoBasicBlocks | ( | BasicBlock * | BB, |
Value * | Cond | ||
) |
Attempt to thread through two successive basic blocks.
Definition at line 2119 of file JumpThreading.cpp.
References Cond, llvm::dbgs(), DL, evaluateOnPredecessorEdge(), llvm::BasicBlock::getDataLayout(), getJumpThreadDuplicationCost(), llvm::Value::getName(), llvm::BasicBlock::getSinglePredecessor(), llvm::BranchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::is_contained(), llvm::BasicBlock::isEHPad(), llvm::BranchInst::isUnconditional(), LLVM_DEBUG, P, llvm::predecessors(), llvm::successors(), and threadThroughTwoBasicBlocks().
Referenced by processThreadableEdges().
bool JumpThreadingPass::processBlock | ( | BasicBlock * | BB | ) |
processBlock - If there are any predecessors whose control can be threaded through to a successor, transform them now.
Definition at line 949 of file JumpThreading.cpp.
References llvm::ConstantFoldInstruction(), llvm::ConstantFoldTerminator(), llvm::BranchInst::Create(), llvm::dbgs(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::Instruction::eraseFromParent(), getBestDestForJumpOnUndef(), llvm::BasicBlock::getDataLayout(), llvm::Instruction::getDebugLoc(), llvm::Function::getEntryBlock(), llvm::ilist_node_impl< OptionsT >::getIterator(), getKnownConstant(), llvm::Value::getName(), llvm::Instruction::getNumSuccessors(), llvm::Instruction::getOpcode(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BasicBlock::getParent(), llvm::LazyValueInfo::getPredicateAt(), llvm::Instruction::getSuccessor(), llvm::BasicBlock::getTerminator(), I, llvm::isInstructionTriviallyDead(), LLVM_DEBUG, maybeMergeBasicBlockIntoOnlyPred(), llvm::pred_empty(), processBranchOnPHI(), processBranchOnXOR(), processGuards(), processImpliedCondition(), processThreadableEdges(), llvm::BasicBlock::removePredecessor(), replaceFoldableUses(), llvm::Instruction::setDebugLoc(), simplifyPartiallyRedundantLoad(), tryToUnfoldSelect(), tryToUnfoldSelectInCurrBB(), updatePredecessorProfileMetadata(), llvm::jumpthreading::WantBlockAddress, and llvm::jumpthreading::WantInteger.
Referenced by runImpl().
processBranchOnPHI - We have an otherwise unthreadable conditional branch on a PHI node (or freeze PHI) in the current block.
See if there are any simplifications we can do based on inputs to the phi node.
Definition at line 1722 of file JumpThreading.cpp.
References duplicateCondBranchOnPHIIntoPred(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getNumIncomingValues(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BasicBlock::getTerminator(), and llvm::SmallVectorImpl< T >::resize().
Referenced by processBlock().
bool JumpThreadingPass::processBranchOnXOR | ( | BinaryOperator * | BO | ) |
processBranchOnXOR - We have an otherwise unthreadable conditional branch on a xor instruction in the current block.
See if there are any simplifications we can do based on inputs to the xor.
Definition at line 1754 of file JumpThreading.cpp.
References llvm::any_of(), assert(), computeValueKnownInPredecessors(), duplicateCondBranchOnPHIIntoPred(), llvm::SmallVectorBase< Size_T >::empty(), llvm::Instruction::eraseFromParent(), llvm::BasicBlock::front(), llvm::UndefValue::get(), llvm::BasicBlock::getContext(), llvm::ConstantInt::getFalse(), llvm::User::getOperand(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BasicBlock::getTerminator(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::BasicBlock::isEHPad(), llvm::ConstantInt::isZero(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::Value::replaceAllUsesWith(), llvm::User::setOperand(), llvm::SmallVectorBase< Size_T >::size(), and llvm::jumpthreading::WantInteger.
Referenced by processBlock().
bool JumpThreadingPass::processGuards | ( | BasicBlock * | BB | ) |
Try to propagate a guard from the current BB into one of its predecessors in case if another branch of execution implies that the condition of this guard is always true.
Currently we only process the simplest case that looks like:
Start: cond = ... br i1 cond, label T1, label F1 T1: br label Merge F1: br label Merge Merge: condGuard = ... call void(i1, ...) @llvm.experimental.guard( i1 condGuard )[ "deopt"() ]
And cond either implies condGuard or !condGuard. In this case all the instructions before the guard can be duplicated in both branches, and the guard is then threaded to one of them.
Definition at line 3016 of file JumpThreading.cpp.
References llvm::BasicBlock::getSinglePredecessor(), I, llvm::isGuard(), llvm::pred_begin(), llvm::pred_end(), and threadGuard().
Referenced by processBlock().
bool JumpThreadingPass::processImpliedCondition | ( | BasicBlock * | BB | ) |
Definition at line 1146 of file JumpThreading.cpp.
References Cond, llvm::BranchInst::Create(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, DL, llvm::BasicBlock::getDataLayout(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::BasicBlock::getSinglePredecessor(), llvm::BasicBlock::getTerminator(), ImplicationSearchThreshold, llvm::isImpliedCondition(), llvm::BasicBlock::removePredecessor(), and llvm::Instruction::setDebugLoc().
Referenced by processBlock().
bool JumpThreadingPass::processThreadableEdges | ( | Value * | Cond, |
BasicBlock * | BB, | ||
jumpthreading::ConstantPreference | Preference, | ||
Instruction * | CxtI = nullptr |
||
) |
Definition at line 1541 of file JumpThreading.cpp.
References assert(), computeValueKnownInPredecessors(), Cond, llvm::BranchInst::Create(), llvm::dbgs(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::SmallVectorImpl< T >::emplace_back(), llvm::SmallVectorBase< Size_T >::empty(), llvm::erase_if(), findMostPopularDest(), getBestDestForJumpOnUndef(), llvm::Value::getName(), llvm::Instruction::getNumSuccessors(), llvm::BasicBlock::getTerminator(), llvm::BasicBlock::hasNPredecessors(), isZero(), LLVM_DEBUG, maybethreadThroughTwoBasicBlocks(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), replaceFoldableUses(), llvm::Instruction::setDebugLoc(), llvm::SmallVectorBase< Size_T >::size(), llvm::successors(), and tryThreadEdge().
Referenced by processBlock().
PreservedAnalyses JumpThreadingPass::run | ( | Function & | F, |
FunctionAnalysisManager & | AM | ||
) |
Definition at line 238 of file JumpThreading.cpp.
References llvm::PreservedAnalyses::all(), assert(), F, llvm::DominatorTreeBase< NodeT, IsPostDom >::Fast, llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::flush(), llvm::DominatorTreeBase< NodeT, IsPostDom >::Full, getDomTreeUpdater(), llvm::AnalysisManager< IRUnitT, ExtraArgTs >::getResult(), llvm::TargetTransformInfo::hasBranchDivergence(), runImpl(), and verify.
bool JumpThreadingPass::runImpl | ( | Function & | F, |
FunctionAnalysisManager * | FAM, | ||
TargetLibraryInfo * | TLI, | ||
TargetTransformInfo * | TTI, | ||
LazyValueInfo * | LVI, | ||
AAResults * | AA, | ||
std::unique_ptr< DomTreeUpdater > | DTU, | ||
std::optional< BlockFrequencyInfo * > | BFI, | ||
std::optional< BranchProbabilityInfo * > | BPI | ||
) |
Definition at line 282 of file JumpThreading.cpp.
References assert(), BBDuplicateThreshold, llvm::SmallPtrSetImpl< PtrType >::count(), llvm::dbgs(), llvm::DeleteDeadBlock(), llvm::LazyValueInfo::eraseBlock(), F, findLoopHeaders(), llvm::Module::getFunction(), llvm::Value::getName(), llvm::Intrinsic::getName(), llvm::GlobalValue::getParent(), llvm::Function::hasFnAttribute(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::DominatorTree::isReachableFromEntry(), LLVM_DEBUG, llvm::pred_empty(), processBlock(), llvm::RemoveRedundantDbgInstrs(), ThreadAcrossLoopHeaders, and llvm::TryToSimplifyUncondBranchFromEmptyBlock().
Referenced by run().
simplifyPartiallyRedundantLoad - If LoadI is an obviously partially redundant load instruction, eliminate it by replacing it with a PHI node.
This is an important optimization that encourages jump threading, and needs to be run interlaced with other jump threading tasks.
Definition at line 1223 of file JumpThreading.cpp.
References llvm::PHINode::addIncoming(), llvm::array_pod_sort(), assert(), llvm::BasicBlock::begin(), llvm::combineMetadataForCSE(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::PHINode::Create(), llvm::CastInst::CreateBitOrPointerCast(), llvm::DefMaxInstsToScan, llvm::BatchAAResults::disableDominatorTree(), DL, llvm::Value::DoPHITranslation(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::BasicBlock::end(), llvm::Instruction::eraseFromParent(), llvm::FindAvailableLoadedValue(), llvm::findAvailablePtrLoadStore(), llvm::LazyValueInfo::forgetValue(), llvm::PoisonValue::get(), llvm::Instruction::getAAMetadata(), llvm::LoadInst::getAlign(), llvm::Instruction::getDataLayout(), llvm::Instruction::getDebugLoc(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Value::getName(), llvm::Instruction::getNumSuccessors(), llvm::User::getOperand(), llvm::LoadInst::getOrdering(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BasicBlock::getSinglePredecessor(), llvm::LoadInst::getSyncScopeID(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::Instruction::insertBefore(), llvm::Instruction::isAtomic(), llvm::BasicBlock::isEHPad(), llvm::isGuaranteedToTransferExecutionToSuccessor(), isOpDefinedInBlock(), llvm::isSafeToSpeculativelyExecute(), llvm::LoadInst::isUnordered(), llvm::lower_bound(), P, llvm::LocationSize::precise(), llvm::pred_size(), llvm::predecessors(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::Value::replaceAllUsesWith(), llvm::Instruction::setAAMetadata(), llvm::Instruction::setDebugLoc(), llvm::SmallPtrSetImplBase::size(), and llvm::Value::takeName().
Referenced by processBlock().
void JumpThreadingPass::threadEdge | ( | BasicBlock * | BB, |
const SmallVectorImpl< BasicBlock * > & | PredBBs, | ||
BasicBlock * | SuccBB | ||
) |
threadEdge - We have decided that it is safe and profitable to factor the blocks in PredBBs to one predecessor, then thread an edge from it to SuccBB across BB.
Transform the IR to reflect this change.
Definition at line 2372 of file JumpThreading.cpp.
References addPHINodeEntriesForMappedBlock(), assert(), llvm::BasicBlock::begin(), cloneInstructions(), llvm::BranchInst::Create(), llvm::BasicBlock::Create(), llvm::dbgs(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::BasicBlock::end(), llvm::BasicBlock::getContext(), llvm::Instruction::getDebugLoc(), llvm::Value::getName(), llvm::Instruction::getNumSuccessors(), llvm::BasicBlock::getParent(), llvm::Instruction::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::DominatorTreeBase< BasicBlock, false >::Insert, LLVM_DEBUG, llvm::BasicBlock::moveAfter(), llvm::BasicBlock::removePredecessor(), llvm::Instruction::setDebugLoc(), llvm::Instruction::setSuccessor(), llvm::SimplifyInstructionsInBlock(), llvm::SmallVectorBase< Size_T >::size(), llvm::LazyValueInfo::threadEdge(), and updateSSA().
Referenced by threadThroughTwoBasicBlocks(), and tryThreadEdge().
bool JumpThreadingPass::threadGuard | ( | BasicBlock * | BB, |
IntrinsicInst * | Guard, | ||
BranchInst * | BI | ||
) |
Try to propagate the guard from BB which is the lower block of a diamond to one of its branches, in case if diamond's condition implies guard's condition.
Definition at line 3050 of file JumpThreading.cpp.
References llvm::PHINode::addIncoming(), assert(), llvm::BasicBlock::begin(), llvm::PHINode::Create(), llvm::dbgs(), DL, llvm::DuplicateInstructionsInSplitBetween(), llvm::BasicBlock::end(), llvm::CallBase::getArgOperand(), llvm::BranchInst::getCondition(), llvm::BasicBlock::getDataLayout(), llvm::BasicBlock::getFirstInsertionPt(), getJumpThreadDuplicationCost(), llvm::Value::getName(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(), llvm::BranchInst::getNumSuccessors(), llvm::BranchInst::getSuccessor(), llvm::Instruction::insertBefore(), llvm::BranchInst::isConditional(), llvm::isImpliedCondition(), LLVM_DEBUG, llvm::reverse(), llvm::Instruction::setDebugLoc(), and ToRemove.
Referenced by processGuards().
void JumpThreadingPass::threadThroughTwoBasicBlocks | ( | BasicBlock * | PredPredBB, |
BasicBlock * | PredBB, | ||
BasicBlock * | BB, | ||
BasicBlock * | SuccBB | ||
) |
Definition at line 2260 of file JumpThreading.cpp.
References addPHINodeEntriesForMappedBlock(), assert(), llvm::BasicBlock::begin(), cloneInstructions(), llvm::BasicBlock::Create(), llvm::dbgs(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::BasicBlock::end(), llvm::BasicBlock::getContext(), llvm::Value::getName(), llvm::Instruction::getNumSuccessors(), llvm::BasicBlock::getParent(), llvm::BranchInst::getSuccessor(), llvm::Instruction::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::DominatorTreeBase< BasicBlock, false >::Insert, LLVM_DEBUG, llvm::BasicBlock::moveAfter(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::BasicBlock::removePredecessor(), llvm::Instruction::setSuccessor(), llvm::SimplifyInstructionsInBlock(), threadEdge(), and updateSSA().
Referenced by maybethreadThroughTwoBasicBlocks().
bool JumpThreadingPass::tryThreadEdge | ( | BasicBlock * | BB, |
const SmallVectorImpl< BasicBlock * > & | PredBBs, | ||
BasicBlock * | SuccBB | ||
) |
tryThreadEdge - Thread an edge if it's safe and profitable to do so.
Definition at line 2333 of file JumpThreading.cpp.
References llvm::dbgs(), getJumpThreadDuplicationCost(), llvm::Value::getName(), llvm::BasicBlock::getTerminator(), LLVM_DEBUG, and threadEdge().
Referenced by processThreadableEdges().
bool JumpThreadingPass::tryToUnfoldSelect | ( | CmpInst * | CondCmp, |
BasicBlock * | BB | ||
) |
tryToUnfoldSelect - Look for blocks of the form bb1: a = select br bb2
bb2: p = phi [a, bb1] ... c = icmp p br i1 c
And expand the select into a branch structure if one of its arms allows c to be folded. This later enables threading from bb1 over bb2.
Definition at line 2854 of file JumpThreading.cpp.
References llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::User::getOperand(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::CmpInst::getPredicate(), llvm::LazyValueInfo::getPredicateOnEdge(), llvm::BasicBlock::getTerminator(), I, llvm::BranchInst::isConditional(), llvm::BranchInst::isUnconditional(), and unfoldSelectInstr().
Referenced by processBlock().
bool JumpThreadingPass::tryToUnfoldSelect | ( | SwitchInst * | SI, |
BasicBlock * | BB | ||
) |
Definition at line 2816 of file JumpThreading.cpp.
References llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BasicBlock::getTerminator(), llvm::Value::hasOneUse(), I, llvm::BranchInst::isUnconditional(), and unfoldSelectInstr().
bool JumpThreadingPass::tryToUnfoldSelectInCurrBB | ( | BasicBlock * | BB | ) |
tryToUnfoldSelectInCurrBB - Look for PHI/Select or PHI/CMP/Select in the same BB in the form bb: p = phi [false, bb1], [true, bb2], [false, bb3], [true, bb4], ... s = select p, trueval, falseval
or
bb: p = phi [0, bb1], [1, bb2], [0, bb3], [1, bb4], ... c = cmp p, 0 s = select c, trueval, falseval
And expand the select into a branch structure. This later enables jump-threading over bb in this pass.
Using the similar approach of SimplifyCFG::FoldCondBranchOnPHI(), unfold select if the associated PHI has at least one constant. If the unfolded select is not jump-threaded, it will be folded again in the later optimizations.
Definition at line 2913 of file JumpThreading.cpp.
References llvm::PHINode::addIncoming(), llvm::all_of(), llvm::BasicBlock::begin(), Cond, llvm::PHINode::Create(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::getBranchWeightMDNode(), llvm::Instruction::getNumSuccessors(), llvm::BasicBlock::getParent(), llvm::BasicBlock::getTerminator(), llvm::Function::hasFnAttribute(), llvm::DominatorTreeBase< BasicBlock, false >::Insert, llvm::isGuaranteedNotToBeUndefOrPoison(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_LogicalOr(), llvm::PatternMatch::match(), llvm::Instruction::setDebugLoc(), llvm::SplitBlockAndInsertIfThen(), and llvm::successors().
Referenced by processBlock().
void JumpThreadingPass::unfoldSelectInstr | ( | BasicBlock * | Pred, |
BasicBlock * | BB, | ||
SelectInst * | SI, | ||
PHINode * | SIUse, | ||
unsigned | Idx | ||
) |
Definition at line 2753 of file JumpThreading.cpp.
References llvm::PHINode::addIncoming(), llvm::BasicBlock::begin(), llvm::BranchInst::Create(), llvm::BasicBlock::Create(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::BasicBlock::end(), llvm::extractBranchWeights(), llvm::BranchProbability::getBranchProbability(), llvm::BasicBlock::getContext(), llvm::Instruction::getDebugLoc(), llvm::BasicBlock::getParent(), llvm::BasicBlock::getTerminator(), Idx, llvm::DominatorTreeBase< BasicBlock, false >::Insert, llvm::Instruction::insertInto(), llvm::Instruction::removeFromParent(), llvm::BranchProbabilityInfo::setEdgeProbability(), and llvm::PHINode::setIncomingValue().
Referenced by tryToUnfoldSelect().
void JumpThreadingPass::updateSSA | ( | BasicBlock * | BB, |
BasicBlock * | NewBB, | ||
ValueToValueMapTy & | ValueMapping | ||
) |
Update the SSA form.
NewBB contains instructions that are copied from BB. ValueMapping maps old values in BB to new ones in NewBB.
Definition at line 1940 of file JumpThreading.cpp.
References llvm::SSAUpdater::AddAvailableValue(), llvm::SmallVectorImpl< T >::clear(), llvm::dbgs(), llvm::SmallVectorBase< Size_T >::empty(), llvm::erase_if(), llvm::findDbgValues(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::DbgRecord::getParent(), I, llvm::SSAUpdater::Initialize(), LLVM_DEBUG, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SSAUpdater::RewriteUse(), and llvm::SSAUpdater::UpdateDebugValues().
Referenced by duplicateCondBranchOnPHIIntoPred(), threadEdge(), and threadThroughTwoBasicBlocks().