53 std::vector<DominatorTree::UpdateType> Updates;
60 Succ->removePredecessor(BB);
66 while (!BB->
empty()) {
88 if (!isa<PHINode>(BB->
begin()))
return;
91 if (PN->getIncomingValue(0) != PN)
92 PN->replaceAllUsesWith(PN->getIncomingValue(0));
99 PN->eraseFromParent();
110 bool Changed =
false;
111 for (
unsigned i = 0, e = PHIs.
size(); i != e; ++i)
112 if (
PHINode *PN = dyn_cast_or_null<PHINode>(PHIs[i].
operator Value*()))
122 assert(!(DT && DDT) &&
"Cannot call with both DT and DDT.");
129 if (!PredBB)
return false;
132 if (PredBB == BB)
return false;
143 for (
Value *IncValue : PN.incoming_values())
149 if (isa<PHINode>(BB->
front())) {
151 if (!isa<PHINode>(PN.getIncomingValue(0)) ||
152 cast<PHINode>(PN.getIncomingValue(0))->
getParent() != BB)
153 IncomingValues.
push_back(PN.getIncomingValue(0));
159 std::vector<DominatorTree::UpdateType> Updates;
161 Updates.reserve(1 + (2 *
succ_size(BB)));
180 for (
auto Incoming : IncomingValues) {
181 if (isa<Instruction>(*Incoming)) {
186 for (
auto &DVI : DbgValues) {
187 auto R = DbgValueSet.
insert({DVI->getVariable(), DVI->getExpression()});
189 DVI->eraseFromParent();
241 "ReplaceInstWithInst: Instruction already inserted into basic block!");
270 .setPreserveLCSSA()))
286 "Should have a single succ!");
293 unsigned NumBroken = 0;
307 while (isa<PHINode>(SplitIt) || SplitIt->isEHPad())
315 L->addBasicBlockToLoop(New, *LI);
320 std::vector<DomTreeNode *> Children(OldNode->begin(), OldNode->end());
334 bool PreserveLCSSA,
bool &HasLoopExit) {
350 assert(DT &&
"DT should be available to update LoopInfo!");
355 bool IsLoopEntry = !!L;
356 bool SplitMakesNewLoopHeader =
false;
368 if (!
PL->contains(OldBB))
378 SplitMakesNewLoopHeader =
true;
390 Loop *InnermostPredLoop =
nullptr;
395 while (PredLoop && !PredLoop->contains(OldBB))
399 if (PredLoop && PredLoop->contains(OldBB) &&
400 (!InnermostPredLoop ||
401 InnermostPredLoop->
getLoopDepth() < PredLoop->getLoopDepth()))
402 InnermostPredLoop = PredLoop;
406 if (InnermostPredLoop)
410 if (SplitMakesNewLoopHeader)
427 Value *InVal =
nullptr;
473 if (PredSet.count(IncomingBB)) {
495 std::string NewName = std::string(Suffix) +
".split-lp";
511 for (
unsigned i = 0, e = Preds.
size(); i != e; ++i) {
515 assert(!isa<IndirectBrInst>(Preds[i]->getTerminator()) &&
516 "Cannot split an edge from an IndirectBrInst");
517 Preds[i]->getTerminator()->replaceUsesOfWith(BB, NewBB);
531 bool HasLoopExit =
false;
535 if (!Preds.
empty()) {
545 const char *Suffix1,
const char *Suffix2,
548 bool PreserveLCSSA) {
563 for (
unsigned i = 0, e = Preds.
size(); i != e; ++i) {
567 assert(!isa<IndirectBrInst>(Preds[i]->getTerminator()) &&
568 "Cannot split an edge from an IndirectBrInst");
569 Preds[i]->getTerminator()->replaceUsesOfWith(OrigBB, NewBB1);
572 bool HasLoopExit =
false;
584 if (Pred == NewBB1)
continue;
586 "Cannot split an edge from an IndirectBrInst");
592 if (!NewBB2Preds.
empty()) {
605 NewBB2Pred->getTerminator()->replaceUsesOfWith(OrigBB, NewBB2);
610 PreserveLCSSA, HasLoopExit);
619 NewBB1->getInstList().insert(NewBB1->getFirstInsertionPt(), Clone1);
630 "Split cannot be applied if LPad is token type. Otherwise an " 631 "invalid PHINode of token type would be created.");
634 PN->addIncoming(Clone2, NewBB2);
662 V = BCI->getOperand(0);
663 NewBC = BCI->
clone();
667 if (
PHINode *PN = dyn_cast<PHINode>(V)) {
668 if (PN->getParent() == BB) {
670 NewBC->
setOperand(0, PN->getIncomingValueForBlock(Pred));
672 *i = PN->getIncomingValueForBlock(Pred);
681 return cast<ReturnInst>(NewRet);
686 bool Unreachable,
MDNode *BranchWeights,
698 CheckTerm->setDebugLoc(SplitBefore->
getDebugLoc());
706 std::vector<DomTreeNode *> Children(OldNode->begin(), OldNode->end());
719 L->addBasicBlockToLoop(ThenBlock, *LI);
720 L->addBasicBlockToLoop(Tail, *LI);
738 (*ThenTerm)->setDebugLoc(SplitBefore->
getDebugLoc());
740 (*ElseTerm)->setDebugLoc(SplitBefore->
getDebugLoc());
774 if (!Pred1Br || !Pred2Br)
779 if (Pred2Br->isConditional()) {
826 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)
bool canSplitPredecessors() const
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.
bool MergeBlockIntoPredecessor(BasicBlock *BB, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemoryDependenceResults *MemDep=nullptr, DeferredDominance *DDT=nullptr)
Attempts to merge a block into its predecessor, if possible.
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 splitBlock(NodeT *NewBB)
splitBlock - BB is split and now it has one successor.
iterator erase(iterator where)
Compute iterated dominance frontiers using a linear time algorithm.
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...
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
unsigned getLoopDepth() const
Return the nesting level of this loop.
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...
unsigned succ_size(const BasicBlock *BB)
BasicBlock * getSuccessor(unsigned i) 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. ...
Value * getCondition() const
LLVMContext & getContext() const
Get the context in which this basic block lives.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
void eraseNode(NodeT *BB)
eraseNode - Removes a node from the dominator tree.
iterator begin()
Instruction iterator methods.
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...
static constexpr UpdateKind Delete
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
A Use represents the edge between a Value definition and its users.
void setName(const Twine &Name)
Change the name of the value.
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...
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
void findDbgValues(SmallVectorImpl< DbgValueInst *> &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
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.
Type * getType() const
All values are typed, get the type of this value.
void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
This method is used by other analyses to update loop information.
void deleteBB(BasicBlock *DelBB)
Delays the deletion of a basic block until a flush() event.
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
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.
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.
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...
DomTreeNodeBase< NodeT > * setNewRoot(NodeT *BB)
Add a new node to the forward dominator tree and make it a new root.
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...
void applyUpdates(ArrayRef< DominatorTree::UpdateType > Updates)
Queues multiple updates and discards duplicates.
Interval::succ_iterator succ_end(Interval *I)
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.
const BasicBlock & getEntryBlock() const
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...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Subclasses of this class are all able to terminate a basic block.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
static constexpr UpdateKind Insert
LLVM Basic Block Representation.
This is an important class for using LLVM in a threaded context.
Conditional or Unconditional Branch instruction.
void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)
changeImmediateDominator - This method is used to update the dominator tree information when a node's...
size_t size() const
size - Get the array size.
This function has undefined behavior.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Value * getIncomingValueForBlock(const BasicBlock *BB) const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const Instruction & front() const
std::pair< iterator, bool > insert(const ValueT &V)
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...
void splice(iterator where, iplist_impl &L2)
const Instruction & back() const
Interval::pred_iterator pred_end(Interval *I)
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...
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
self_iterator getIterator()
DomTreeNodeBase< NodeT > * getRootNode()
getRootNode - This returns the entry node for the CFG of the function.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
bool isLandingPad() const
Return true if this basic block is a landing pad.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
const InstListType & getInstList() const
Return the underlying instruction list container.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
bool isExceptional() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
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)
bool isConditional() const
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...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
void setOperand(unsigned i, Value *Val)
Implements a dense probed hash-table based set with some number of buckets stored inline...
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
void push_back(pointer val)
Class to defer updates to a DominatorTree.
void FoldSingleEntryPHINodes(BasicBlock *BB, MemoryDependenceResults *MemDep=nullptr)
We know that BB has one predecessor.
LoopT * getParentLoop() 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)
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_NODISCARD bool empty() const
Represents a single loop in the control flow graph.
bool isTokenTy() const
Return true if this is 'token'.
StringRef getName() const
Return a constant reference to the value's name.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
const Function * getParent() const
Return the enclosing method, or null if none.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)
Add a new node to the dominator tree information.
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...
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
void DeleteDeadBlock(BasicBlock *BB, DeferredDominance *DDT=nullptr)
Delete the specified block, which must have no predecessors.
LLVM Value Representation.
void removeInstruction(Instruction *InstToRemove)
Removes an instruction from the dependence analysis, updating the dependence of instructions that pre...
static const Function * getParent(const Value *V)
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
Split the edge connecting specified block.
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
const Instruction * getFirstNonPHIOrDbg() const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic...
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...
void removeBlock(BlockT *BB)
This method completely removes BB from all data structures, including all of the Loop objects it is n...
bool empty() const
empty - Check if the array is empty.
const BasicBlock * getParent() const
const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.