14#ifndef LLVM_TRANSFORMS_UTILS_BASICBLOCKUTILS_H
15#define LLVM_TRANSFORMS_UTILS_BASICBLOCKUTILS_H
30template <
typename PtrType>
class SmallPtrSetImpl;
31class BlockFrequencyInfo;
32class BranchProbabilityInfo;
38class MemoryDependenceResults;
39class MemorySSAUpdater;
40class PostDominatorTree;
42class TargetLibraryInfo;
50 SmallVectorImpl<DominatorTree::UpdateType> *Updates,
51 bool KeepOneInputPHIs =
false);
55 bool KeepOneInputPHIs =
false);
64 DomTreeUpdater *DTU =
nullptr,
65 bool KeepOneInputPHIs =
false);
71 bool KeepOneInputPHIs =
false);
78 MemoryDependenceResults *MemDep =
nullptr);
84bool DeleteDeadPHIs(BasicBlock *BB,
const TargetLibraryInfo *TLI =
nullptr,
85 MemorySSAUpdater *MSSAU =
nullptr);
97 LoopInfo *LI =
nullptr,
98 MemorySSAUpdater *MSSAU =
nullptr,
99 MemoryDependenceResults *MemDep =
nullptr,
100 bool PredecessorWithTwoSuccessors =
false,
101 DominatorTree *DT =
nullptr);
111 SmallPtrSetImpl<BasicBlock *> &MergeBlocks, Loop *L =
nullptr,
112 DomTreeUpdater *DTU =
nullptr, LoopInfo *LI =
nullptr);
196 BasicBlock *SplitBB, BasicBlock *DestBB);
215 const CriticalEdgeSplittingOptions &
Options =
216 CriticalEdgeSplittingOptions(),
217 const Twine &BBName =
"");
222 const CriticalEdgeSplittingOptions &
Options =
223 CriticalEdgeSplittingOptions(),
224 const Twine &BBName =
"");
246 const CriticalEdgeSplittingOptions &
Options =
247 CriticalEdgeSplittingOptions());
252 DominatorTree *DT =
nullptr, LoopInfo *LI =
nullptr,
253 MemorySSAUpdater *MSSAU =
nullptr,
254 const Twine &BBName =
"");
262 BasicBlock *NewPred, PHINode *Until =
nullptr);
267 LandingPadInst *OriginalPad =
nullptr,
268 PHINode *LandingPadReplacement =
nullptr,
269 const CriticalEdgeSplittingOptions &
Options =
270 CriticalEdgeSplittingOptions(),
271 const Twine &BBName =
"");
284 LoopInfo *LI =
nullptr,
285 MemorySSAUpdater *MSSAU =
nullptr,
286 const Twine &BBName =
"",
bool Before =
false);
303 DomTreeUpdater *DTU =
nullptr, LoopInfo *LI =
nullptr,
304 MemorySSAUpdater *MSSAU =
nullptr,
305 const Twine &BBName =
"",
bool Before =
false);
319 DomTreeUpdater *DTU, LoopInfo *LI,
320 MemorySSAUpdater *MSSAU,
const Twine &BBName =
"");
344 const char *Suffix, DominatorTree *DT,
345 LoopInfo *LI =
nullptr,
346 MemorySSAUpdater *MSSAU =
nullptr,
347 bool PreserveLCSSA =
false);
365 DomTreeUpdater *DTU =
nullptr,
366 LoopInfo *LI =
nullptr,
367 MemorySSAUpdater *MSSAU =
nullptr,
368 bool PreserveLCSSA =
false);
382 BasicBlock *OrigBB, ArrayRef<BasicBlock *> Preds,
const char *Suffix,
383 const char *Suffix2, SmallVectorImpl<BasicBlock *> &NewBBs,
384 DomTreeUpdater *DTU =
nullptr, LoopInfo *LI =
nullptr,
385 MemorySSAUpdater *MSSAU =
nullptr,
bool PreserveLCSSA =
false);
393 DomTreeUpdater *DTU =
nullptr);
418 MDNode *BranchWeights =
nullptr,
419 DomTreeUpdater *DTU =
nullptr,
420 LoopInfo *LI =
nullptr,
421 BasicBlock *ThenBlock =
nullptr);
425 MDNode *BranchWeights =
nullptr,
430 Unreachable, BranchWeights, DTU, LI,
438 MDNode *BranchWeights =
nullptr,
439 DomTreeUpdater *DTU =
nullptr,
440 LoopInfo *LI =
nullptr,
441 BasicBlock *ElseBlock =
nullptr);
445 MDNode *BranchWeights =
nullptr,
450 Unreachable, BranchWeights, DTU, LI,
472 Instruction **ThenTerm,
473 Instruction **ElseTerm,
474 MDNode *BranchWeights =
nullptr,
475 DomTreeUpdater *DTU =
nullptr,
476 LoopInfo *LI =
nullptr);
481 MDNode *BranchWeights =
nullptr,
486 ElseTerm, BranchWeights, DTU, LI);
518 BasicBlock **ThenBlock,
519 BasicBlock **ElseBlock,
520 bool UnreachableThen =
false,
521 bool UnreachableElse =
false,
522 MDNode *BranchWeights =
nullptr,
523 DomTreeUpdater *DTU =
nullptr,
524 LoopInfo *LI =
nullptr);
529 bool UnreachableThen =
false,
530 bool UnreachableElse =
false,
531 MDNode *BranchWeights =
nullptr,
535 ElseBlock, UnreachableThen, UnreachableElse, BranchWeights, DTU, LI);
542std::pair<Instruction*, Value*>
554 Instruction *InsertBefore,
555 std::function<
void(IRBuilderBase&, Value*)> Func);
566 Value *
End, Instruction *InsertBefore,
567 std::function<
void(IRBuilderBase &, Value *)> Func);
578 BasicBlock *&IfFalse);
602 BranchProbabilityInfo *BPI =
nullptr,
603 BlockFrequencyInfo *BFI =
nullptr);
678 std::optional<unsigned> MaxControlFlowBooleans = std::nullopt);
BlockVerifier::State From
static cl::opt< bool > SplitAllCriticalEdges("phi-elim-split-all-critical-edges", cl::init(false), cl::Hidden, cl::desc("Split all critical edges during " "PHI elimination"))
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
LLVM Basic Block Representation.
InstListType::iterator iterator
Instruction iterators...
Conditional or Unconditional Branch instruction.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Common base class shared among various IRBuilders.
unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
A vector that has set insertion semantics.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
self_iterator getIterator()
This is an optimization pass for GlobalISel generic memory operations.
void ReplaceInstWithInst(BasicBlock *BB, BasicBlock::iterator &BI, Instruction *I)
Replace the instruction specified by BI with the instruction specified by I.
bool RemoveRedundantDbgInstrs(BasicBlock *BB)
Try to remove redundant dbg.value instructions from given basic block.
bool IsBlockFollowedByDeoptOrUnreachable(const BasicBlock *BB)
Check if we can prove that all paths starting from this block converge to a block that either has a @...
BranchInst * GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue, BasicBlock *&IfFalse)
Check whether BB is the merge point of a if-region.
void detachDeadBlocks(ArrayRef< BasicBlock * > BBs, SmallVectorImpl< DominatorTree::UpdateType > *Updates, bool KeepOneInputPHIs=false)
Replace contents of every block in BBs with single unreachable instruction.
bool hasOnlySimpleTerminator(const Function &F)
ReturnInst * FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB, BasicBlock *Pred, DomTreeUpdater *DTU=nullptr)
This method duplicates the specified return instruction into a predecessor which ends in an unconditi...
BasicBlock * splitBlockBefore(BasicBlock *Old, BasicBlock::iterator SplitPt, DomTreeUpdater *DTU, LoopInfo *LI, MemorySSAUpdater *MSSAU, const Twine &BBName="")
Split the specified block at the specified instruction SplitPt.
Instruction * SplitBlockAndInsertIfElse(Value *Cond, BasicBlock::iterator SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BasicBlock *ElseBlock=nullptr)
Similar to SplitBlockAndInsertIfThen, but the inserted block is on the false path of the branch.
void DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified block, which must have no predecessors.
void ReplaceInstWithValue(BasicBlock::iterator &BI, Value *V)
Replace all uses of an instruction (specified by BI) with a value, then remove and delete the origina...
BasicBlock * SplitKnownCriticalEdge(Instruction *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")
If it is known that an edge is critical, SplitKnownCriticalEdge can be called directly,...
bool SplitIndirectBrCriticalEdges(Function &F, bool IgnoreBlocksWithoutPHI, BranchProbabilityInfo *BPI=nullptr, BlockFrequencyInfo *BFI=nullptr)
bool DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Examine each PHI in the given block and delete it if it is dead.
void InvertBranch(BranchInst *PBI, IRBuilderBase &Builder)
bool EliminateUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete all basic blocks from F that are not reachable from its entry node.
bool MergeBlockSuccessorsIntoGivenBlocks(SmallPtrSetImpl< BasicBlock * > &MergeBlocks, Loop *L=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr)
Merge block(s) sucessors, if possible.
void SplitBlockAndInsertIfThenElse(Value *Cond, BasicBlock::iterator SplitBefore, Instruction **ThenTerm, Instruction **ElseTerm, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr)
SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen, but also creates the ElseBlock...
void SplitBlockAndInsertForEachLane(ElementCount EC, Type *IndexTy, Instruction *InsertBefore, std::function< void(IRBuilderBase &, Value *)> Func)
Utility function for performing a given action on each lane of a vector with EC elements.
BasicBlock * ehAwareSplitEdge(BasicBlock *BB, BasicBlock *Succ, LandingPadInst *OriginalPad=nullptr, PHINode *LandingPadReplacement=nullptr, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")
Split the edge connect the specficed blocks in the case that Succ is an Exception Handling Block.
void SplitLandingPadPredecessors(BasicBlock *OrigBB, ArrayRef< BasicBlock * > Preds, const char *Suffix, const char *Suffix2, SmallVectorImpl< BasicBlock * > &NewBBs, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool PreserveLCSSA=false)
This method transforms the landing pad, OrigBB, by introducing two new basic blocks into the function...
BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool PreserveLCSSA=false)
This method introduces at least one new basic block into the function and moves some of the predecess...
void createPHIsForSplitLoopExit(ArrayRef< BasicBlock * > Preds, BasicBlock *SplitBB, BasicBlock *DestBB)
When a loop exit edge is split, LCSSA form may require new PHIs in the new exit block.
bool MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, MemoryDependenceResults *MemDep=nullptr, bool PredecessorWithTwoSuccessors=false, DominatorTree *DT=nullptr)
Attempts to merge a block into its predecessor, if possible.
BasicBlock * CreateControlFlowHub(DomTreeUpdater *DTU, SmallVectorImpl< BasicBlock * > &GuardBlocks, const SetVector< BasicBlock * > &Predecessors, const SetVector< BasicBlock * > &Successors, const StringRef Prefix, std::optional< unsigned > MaxControlFlowBooleans=std::nullopt)
Given a set of incoming and outgoing blocks, create a "hub" such that every edge from an incoming blo...
std::pair< Instruction *, Value * > SplitBlockAndInsertSimpleForLoop(Value *End, Instruction *SplitBefore)
Insert a for (int i = 0; i < End; i++) loop structure (with the exception that End is assumed > 0,...
BasicBlock * SplitCriticalEdge(Instruction *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")
If this edge is a critical edge, insert a new node to split the critical edge.
bool FoldSingleEntryPHINodes(BasicBlock *BB, MemoryDependenceResults *MemDep=nullptr)
We know that BB has one predecessor.
void updatePhiNodes(BasicBlock *DestBB, BasicBlock *OldPred, BasicBlock *NewPred, PHINode *Until=nullptr)
Replaces all uses of OldPred with the NewPred block in all PHINodes in a block.
bool isPresplitCoroSuspendExitEdge(const BasicBlock &Src, const BasicBlock &Dest)
BasicBlock * SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="", bool Before=false)
Split the specified block at the specified instruction.
Instruction * SplitBlockAndInsertIfThen(Value *Cond, BasicBlock::iterator SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
void DeleteDeadBlocks(ArrayRef< BasicBlock * > BBs, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified blocks from BB.
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")
Split the edge connecting the specified blocks, and return the newly created basic block between From...
void setUnwindEdgeTo(Instruction *TI, BasicBlock *Succ)
Sets the unwind edge of an instruction to a particular successor.
Option class for critical edge splitting.
CriticalEdgeSplittingOptions(DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, PostDominatorTree *PDT=nullptr)
CriticalEdgeSplittingOptions & setMergeIdenticalEdges()
bool IgnoreUnreachableDests
CriticalEdgeSplittingOptions & setKeepOneInputPHIs()
bool PreserveLoopSimplify
SplitCriticalEdge is guaranteed to preserve loop-simplify form if LI is provided.
CriticalEdgeSplittingOptions & unsetPreserveLoopSimplify()
CriticalEdgeSplittingOptions & setPreserveLCSSA()
CriticalEdgeSplittingOptions & setIgnoreUnreachableDests()