43 Succ->removePredecessor(BB);
46 while (!BB->
empty()) {
64 if (!isa<PHINode>(BB->
begin()))
return;
67 if (PN->getIncomingValue(0) != PN)
68 PN->replaceAllUsesWith(PN->getIncomingValue(0));
75 PN->eraseFromParent();
88 for (
unsigned i = 0, e = PHIs.
size(); i != e; ++i)
89 if (
PHINode *PN = dyn_cast_or_null<PHINode>(PHIs[i].
operator Value*()))
103 if (!PredBB)
return false;
106 if (PredBB == BB)
return false;
113 for (;
SI != SE; ++
SI)
114 if (*
SI != OnlySucc) {
120 if (!OnlySucc)
return false;
124 if (
PHINode *PN = dyn_cast<PHINode>(BI)) {
125 for (
Value *IncValue : PN->incoming_values())
133 if (isa<PHINode>(BB->
front()))
188 "ReplaceInstWithInst: Instruction already inserted into basic block!");
217 .setPreserveLCSSA()))
225 assert(SP == BB &&
"CFG broken");
233 "Should have a single succ!");
240 unsigned NumBroken = 0;
254 while (isa<PHINode>(SplitIt) || SplitIt->isEHPad())
267 std::vector<DomTreeNode *> Children(OldNode->begin(), OldNode->end());
281 bool PreserveLCSSA,
bool &HasLoopExit) {
294 bool IsLoopEntry = !!
L;
295 bool SplitMakesNewLoopHeader =
false;
301 if (!
PL->contains(OldBB))
311 SplitMakesNewLoopHeader =
true;
323 Loop *InnermostPredLoop =
nullptr;
328 while (PredLoop && !PredLoop->contains(OldBB))
332 if (PredLoop && PredLoop->contains(OldBB) &&
333 (!InnermostPredLoop ||
334 InnermostPredLoop->
getLoopDepth() < PredLoop->getLoopDepth()))
335 InnermostPredLoop = PredLoop;
339 if (InnermostPredLoop)
343 if (SplitMakesNewLoopHeader)
360 Value *InVal =
nullptr;
406 if (PredSet.count(IncomingBB)) {
428 std::string NewName = std::string(Suffix) +
".split-lp";
444 for (
unsigned i = 0, e = Preds.
size(); i != e; ++i) {
448 assert(!isa<IndirectBrInst>(Preds[i]->getTerminator()) &&
449 "Cannot split an edge from an IndirectBrInst");
450 Preds[i]->getTerminator()->replaceUsesOfWith(BB, NewBB);
457 if (Preds.
size() == 0) {
465 bool HasLoopExit =
false;
476 const char *Suffix1,
const char *Suffix2,
479 bool PreserveLCSSA) {
494 for (
unsigned i = 0, e = Preds.
size(); i != e; ++i) {
498 assert(!isa<IndirectBrInst>(Preds[i]->getTerminator()) &&
499 "Cannot split an edge from an IndirectBrInst");
500 Preds[i]->getTerminator()->replaceUsesOfWith(OrigBB, NewBB1);
503 bool HasLoopExit =
false;
515 if (Pred == NewBB1)
continue;
517 "Cannot split an edge from an IndirectBrInst");
523 if (!NewBB2Preds.
empty()) {
536 NewBB2Pred->getTerminator()->replaceUsesOfWith(OrigBB, NewBB2);
541 PreserveLCSSA, HasLoopExit);
550 NewBB1->getInstList().insert(NewBB1->getFirstInsertionPt(), Clone1);
561 "Split cannot be applied if LPad is token type. Otherwise an "
562 "invalid PHINode of token type would be created.");
565 PN->addIncoming(Clone2, NewBB2);
593 V = BCI->getOperand(0);
594 NewBC = BCI->
clone();
598 if (
PHINode *PN = dyn_cast<PHINode>(V)) {
599 if (PN->getParent() == BB) {
601 NewBC->
setOperand(0, PN->getIncomingValueForBlock(Pred));
603 *i = PN->getIncomingValueForBlock(Pred);
612 return cast<ReturnInst>(NewRet);
617 bool Unreachable,
MDNode *BranchWeights,
629 CheckTerm->setDebugLoc(SplitBefore->
getDebugLoc());
637 std::vector<DomTreeNode *> Children(OldNode->begin(), OldNode->end());
669 (*ThenTerm)->setDebugLoc(SplitBefore->
getDebugLoc());
671 (*ElseTerm)->setDebugLoc(SplitBefore->
getDebugLoc());
706 if (!Pred1Br || !Pred2Br)
711 if (Pred2Br->isConditional()) {
758 if (!BI)
return nullptr;
Return a value (possibly void), from a function.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
void invalidateCachedPredecessors()
Clears the PredIteratorCache info.
void ReplaceInstWithInst(BasicBlock::InstListType &BIL, BasicBlock::iterator &BI, Instruction *I)
Replace the instruction specified by BI with the instruction specified by I.
void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs=false)
Notify the BasicBlock that the predecessor Pred is no longer able to reach it.
Provides a lazy, caching interface for making common memory aliasing information queries, backed by LLVM's alias analysis passes.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
void SplitBlockAndInsertIfThenElse(Value *Cond, Instruction *SplitBefore, TerminatorInst **ThenTerm, TerminatorInst **ElseTerm, MDNode *BranchWeights=nullptr)
SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen, but also creates the ElseBlock...
void removeBlock(BlockT *BB)
This method completely removes BB from all data structures, including all of the Loop objects it is n...
const Instruction & back() const
iterator erase(iterator where)
BasicBlock * SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
Split the specified block at the specified instruction - everything before SplitPt stays in Old and e...
void DeleteDeadBlock(BasicBlock *BB)
Delete the specified block, which must have no predecessors.
std::pair< std::string, std::string > SplitBefore(std::string X, std::string S)
static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB, ArrayRef< BasicBlock * > Preds, DominatorTree *DT, LoopInfo *LI, bool PreserveLCSSA, bool &HasLoopExit)
Update DominatorTree, LoopInfo, and LCCSA analysis information.
bool isTokenTy() const
Return true if this is 'token'.
LoopT * getParentLoop() const
const Function * getParent() const
Return the enclosing method, or null if none.
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
const Instruction & front() const
unsigned SplitAllCriticalEdges(Function &F, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
Loop over all of the edges in the CFG, breaking critical edges as they are found. ...
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
void eraseNode(NodeT *BB)
eraseNode - Removes a node from the dominator tree.
StringRef getName() const
Return a constant reference to the value's name.
iterator begin()
Instruction iterator methods.
void splitBlock(NodeT *NewBB)
splitBlock - BB is split and now it has one successor.
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
Option class for critical edge splitting.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A Use represents the edge between a Value definition and its users.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)
Add a new node to the dominator tree information.
void setName(const Twine &Name)
Change the name of the value.
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
LLVM_NODISCARD bool empty() const
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
This method is used by other analyses to update loop information.
BasicBlock * getSuccessor(unsigned i) const
bool DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr)
Examine each PHI in the given block and delete it if it is dead.
This class represents a no-op cast from one type to another.
Base class for the actual dominator tree node.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
bool canSplitPredecessors() const
void ReplaceInstWithValue(BasicBlock::InstListType &BIL, BasicBlock::iterator &BI, Value *V)
Replace all uses of an instruction (specified by BI) with a value, then remove and delete the origina...
void takeName(Value *V)
Transfer the name from V to this value.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
size_t size() const
size - Get the array size.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
Interval::succ_iterator succ_end(Interval *I)
BasicBlock * SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
If this edge is a critical edge, insert a new node to split the critical edge.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
Subclasses of this class are all able to terminate a basic block.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
LLVM Basic Block Representation.
This is an important class for using LLVM in a threaded context.
void SplitLandingPadPredecessors(BasicBlock *OrigBB, ArrayRef< BasicBlock * > Preds, const char *Suffix, const char *Suffix2, SmallVectorImpl< BasicBlock * > &NewBBs, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, bool PreserveLCSSA=false)
This method transforms the landing pad, OrigBB, by introducing two new basic blocks into the function...
Conditional or Unconditional Branch instruction.
This function has undefined behavior.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
void splice(iterator where, iplist_impl &L2)
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
const InstListType & getInstList() const
Return the underlying instruction list container.
Interval::pred_iterator pred_end(Interval *I)
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
self_iterator getIterator()
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
bool isConditional() const
static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB, ArrayRef< BasicBlock * > Preds, BranchInst *BI, bool HasLoopExit)
Update the PHI nodes in OrigBB to include the values coming from NewBB.
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
bool RecursivelyDeleteDeadPHINode(PHINode *PN, const TargetLibraryInfo *TLI=nullptr)
If the specified value is an effectively dead PHI node, due to being a def-use chain of single-use no...
Value * GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue, BasicBlock *&IfFalse)
Check whether BB is the merge point of a if-region.
TerminatorInst * SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
void setOperand(unsigned i, Value *Val)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
void push_back(pointer val)
Value * getIncomingValueForBlock(const BasicBlock *BB) const
DomTreeNodeBase< NodeT > * getNode(NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
void FoldSingleEntryPHINodes(BasicBlock *BB, MemoryDependenceResults *MemDep=nullptr)
We know that BB has one predecessor.
Value * getCondition() const
unsigned GetSuccessorNumber(const BasicBlock *BB, const BasicBlock *Succ)
Search for the specified successor of basic block BB and return its position in the terminator instru...
iterator insert(iterator where, pointer New)
bool MergeBlockIntoPredecessor(BasicBlock *BB, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemoryDependenceResults *MemDep=nullptr)
Attempts to merge a block into its predecessor, if possible.
void moveToHeader(BlockT *BB)
This method is used to move BB (which must be part of this loop) to be the loop header of the loop (t...
Represents a single loop in the control flow graph.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
bool isLandingPad() const
Return true if this basic block is a landing pad.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
ReturnInst * FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB, BasicBlock *Pred)
This method duplicates the specified return instruction into a predecessor which ends in an unconditi...
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, bool PreserveLCSSA=false)
This method introduces at least one new basic block into the function and moves some of the predecess...
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVMContext & getContext() const
Get the context in which this basic block lives.
LLVM Value Representation.
void removeInstruction(Instruction *InstToRemove)
Removes an instruction from the dependence analysis, updating the dependence of instructions that pre...
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
Split the edge connecting specified block.
const Instruction * getFirstNonPHIOrDbg() const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic...
bool isExceptional() const
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)
changeImmediateDominator - This method is used to update the dominator tree information when a node's...
unsigned getLoopDepth() const
Return the nesting level of this loop.
const BasicBlock * getParent() const