14#ifndef LLVM_TRANSFORMS_UTILS_BASICBLOCKUTILS_H
15#define LLVM_TRANSFORMS_UTILS_BASICBLOCKUTILS_H
59 bool KeepOneInputPHIs =
false);
63 bool KeepOneInputPHIs =
false);
73 bool KeepOneInputPHIs =
false);
80 bool KeepOneInputPHIs =
false);
112 bool PredecessorWithTwoSuccessors =
false,
DominatorTree *DT =
nullptr);
228 const CriticalEdgeSplittingOptions &
Options =
229 CriticalEdgeSplittingOptions(),
230 const Twine &BBName =
"");
236 const CriticalEdgeSplittingOptions &
Options =
237 CriticalEdgeSplittingOptions(),
238 const Twine &BBName =
"");
261 CriticalEdgeSplittingOptions());
266 DominatorTree *DT =
nullptr,
267 LoopInfo *LI =
nullptr,
268 MemorySSAUpdater *MSSAU =
nullptr,
269 const Twine &BBName =
"");
297SplitCallBrEdge(BasicBlock *CallBrBlock, BasicBlock *Succ,
unsigned SuccIdx,
298 BasicBlock *CallBrTarget =
nullptr,
299 DomTreeUpdater *DTU =
nullptr, CycleInfo *CI =
nullptr,
300 LoopInfo *LI =
nullptr,
bool *UpdatedLI =
nullptr);
308 BasicBlock *NewPred, PHINode *Until =
nullptr);
314 LandingPadInst *OriginalPad =
nullptr,
315 PHINode *LandingPadReplacement =
nullptr,
316 const CriticalEdgeSplittingOptions &
Options =
317 CriticalEdgeSplittingOptions(),
318 const Twine &BBName =
"");
328 DominatorTree *DT, LoopInfo *LI =
nullptr,
329 MemorySSAUpdater *MSSAU =
nullptr,
330 const Twine &BBName =
"");
334 const Twine &BBName =
"") {
344 DomTreeUpdater *DTU =
nullptr,
345 LoopInfo *LI =
nullptr,
346 MemorySSAUpdater *MSSAU =
nullptr,
347 const Twine &BBName =
"");
352 const Twine &BBName =
"") {
363 DomTreeUpdater *DTU, LoopInfo *LI,
364 MemorySSAUpdater *MSSAU,
365 const Twine &BBName =
"");
390 DominatorTree *DT, LoopInfo *LI =
nullptr,
391 MemorySSAUpdater *MSSAU =
nullptr,
bool PreserveLCSSA =
false);
409 DomTreeUpdater *DTU =
nullptr, LoopInfo *LI =
nullptr,
410 MemorySSAUpdater *MSSAU =
nullptr,
bool PreserveLCSSA =
false);
425 const char *Suffix2, SmallVectorImpl<BasicBlock *> &NewBBs,
426 DomTreeUpdater *DTU =
nullptr, LoopInfo *LI =
nullptr,
427 MemorySSAUpdater *MSSAU =
nullptr,
bool PreserveLCSSA =
false);
435 DomTreeUpdater *DTU =
nullptr);
460 bool Unreachable, MDNode *BranchWeights =
nullptr,
461 DomTreeUpdater *DTU =
nullptr, LoopInfo *LI =
nullptr,
462 BasicBlock *ThenBlock =
nullptr);
466 MDNode *BranchWeights =
nullptr,
471 Unreachable, BranchWeights, DTU, LI,
479 bool Unreachable, MDNode *BranchWeights =
nullptr,
480 DomTreeUpdater *DTU =
nullptr, LoopInfo *LI =
nullptr,
481 BasicBlock *ElseBlock =
nullptr);
485 MDNode *BranchWeights =
nullptr,
490 Unreachable, BranchWeights, DTU, LI,
512 Instruction **ElseTerm, MDNode *BranchWeights =
nullptr,
513 DomTreeUpdater *DTU =
nullptr, LoopInfo *LI =
nullptr);
518 MDNode *BranchWeights =
nullptr,
523 ElseTerm, BranchWeights, DTU, LI);
555 BasicBlock **ElseBlock,
bool UnreachableThen =
false,
556 bool UnreachableElse =
false, MDNode *BranchWeights =
nullptr,
557 DomTreeUpdater *DTU =
nullptr, LoopInfo *LI =
nullptr);
562 bool UnreachableThen =
false,
563 bool UnreachableElse =
false,
564 MDNode *BranchWeights =
nullptr,
568 ElseBlock, UnreachableThen, UnreachableElse, BranchWeights, DTU, LI);
575LLVM_ABI std::pair<Instruction *, Value *>
588 std::function<
void(IRBuilderBase &, Value *)> Func);
600 std::function<
void(IRBuilderBase &, Value *)> Func);
611 BasicBlock *&IfFalse);
635 bool IgnoreBlocksWithoutPHI,
636 BranchProbabilityInfo *BPI =
nullptr,
637 BlockFrequencyInfo *BFI =
nullptr,
638 DomTreeUpdater *DTU =
nullptr);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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
This file implements a set that has insertion order iteration characteristics.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
InstListType::iterator iterator
Instruction iterators...
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Analysis providing branch probability information.
Conditional Branch instruction.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Common base class shared among various IRBuilders.
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
LLVM_ABI BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
Represents a single loop in the control flow graph.
Provides a lazy, caching interface for making common memory aliasing information queries,...
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
Return a value (possibly void), from a function.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Provides information about what library functions are available for the current target.
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.
LLVM_ABI void ReplaceInstWithInst(BasicBlock *BB, BasicBlock::iterator &BI, Instruction *I)
Replace the instruction specified by BI with the instruction specified by I.
LLVM_ABI bool RemoveRedundantDbgInstrs(BasicBlock *BB)
Try to remove redundant dbg.value instructions from given basic block.
LLVM_ABI 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 @...
LLVM_ABI void detachDeadBlocks(ArrayRef< BasicBlock * > BBs, SmallVectorImpl< DominatorTree::UpdateType > *Updates, bool KeepOneInputPHIs=false)
Replace contents of every block in BBs with single unreachable instruction.
LLVM_ABI bool hasOnlySimpleTerminator(const Function &F)
LLVM_ABI 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...
LLVM_ABI std::pair< Instruction *, Value * > SplitBlockAndInsertSimpleForLoop(Value *End, BasicBlock::iterator SplitBefore)
Insert a for (int i = 0; i < End; i++) loop structure (with the exception that End is assumed > 0,...
LLVM_ABI 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.
LLVM_ABI 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.
LLVM_ABI bool SplitIndirectBrCriticalEdges(Function &F, bool IgnoreBlocksWithoutPHI, BranchProbabilityInfo *BPI=nullptr, BlockFrequencyInfo *BFI=nullptr, DomTreeUpdater *DTU=nullptr)
LLVM_ABI bool DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, SmallPtrSetImpl< PHINode * > *KnownNonDeadPHIs=nullptr)
Examine each PHI in the given block and delete it if it is dead.
LLVM_ABI void DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified block, which must have no predecessors.
LLVM_ABI 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...
LLVM_ABI 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,...
LLVM_ABI CondBrInst * GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue, BasicBlock *&IfFalse)
Check whether BB is the merge point of a if-region.
LLVM_ABI bool HasLoopOrEntryConvergenceToken(const BasicBlock *BB)
Check if the given basic block contains any loop or entry convergent intrinsic instructions.
LLVM_ABI void InvertBranch(CondBrInst *PBI, IRBuilderBase &Builder)
LLVM_ABI bool EliminateUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete all basic blocks from F that are not reachable from its entry node.
LLVM_ABI bool MergeBlockSuccessorsIntoGivenBlocks(SmallPtrSetImpl< BasicBlock * > &MergeBlocks, Loop *L=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr)
Merge block(s) sucessors, if possible.
LLVM_ABI 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...
LLVM_ABI 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.
LLVM_ABI 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...
LLVM_ABI 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...
LLVM_ABI 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.
LLVM_ABI 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.
LLVM_ABI BasicBlock * SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")
Split the specified block at the specified instruction.
LLVM_ABI 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.
LLVM_ABI bool FoldSingleEntryPHINodes(BasicBlock *BB, MemoryDependenceResults *MemDep=nullptr)
We know that BB has one predecessor.
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI 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.
LLVM_ABI Printable printBasicBlock(const BasicBlock *BB)
Print BasicBlock BB as an operand or print "<nullptr>" if BB is a nullptr.
LLVM_ABI 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 ...
LLVM_ABI void DeleteDeadBlocks(ArrayRef< BasicBlock * > BBs, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified blocks from BB.
LLVM_ABI 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...
LLVM_ABI void setUnwindEdgeTo(Instruction *TI, BasicBlock *Succ)
Sets the unwind edge of an instruction to a particular successor.
LLVM_ABI void SplitBlockAndInsertForEachLane(ElementCount EC, Type *IndexTy, BasicBlock::iterator InsertBefore, std::function< void(IRBuilderBase &, Value *)> Func)
Utility function for performing a given action on each lane of a vector with EC elements.
LLVM_ABI BasicBlock * SplitCallBrEdge(BasicBlock *CallBrBlock, BasicBlock *Succ, unsigned SuccIdx, BasicBlock *CallBrTarget=nullptr, DomTreeUpdater *DTU=nullptr, CycleInfo *CI=nullptr, LoopInfo *LI=nullptr, bool *UpdatedLI=nullptr)
Create a new intermediate target block for a callbr edge.
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()