Go to the documentation of this file.
14 #ifndef LLVM_TRANSFORMS_UTILS_BASICBLOCKUTILS_H
15 #define LLVM_TRANSFORMS_UTILS_BASICBLOCKUTILS_H
30 template <
typename PtrType>
class SmallPtrSetImpl;
31 class BlockFrequencyInfo;
32 class BranchProbabilityInfo;
37 class MemoryDependenceResults;
38 class MemorySSAUpdater;
39 class PostDominatorTree;
41 class TargetLibraryInfo;
49 SmallVectorImpl<DominatorTree::UpdateType> *Updates,
50 bool KeepOneInputPHIs =
false);
54 bool KeepOneInputPHIs =
false);
63 DomTreeUpdater *DTU =
nullptr,
64 bool KeepOneInputPHIs =
false);
70 bool KeepOneInputPHIs =
false);
77 MemoryDependenceResults *MemDep =
nullptr);
84 MemorySSAUpdater *MSSAU =
nullptr);
96 LoopInfo *LI =
nullptr,
97 MemorySSAUpdater *MSSAU =
nullptr,
98 MemoryDependenceResults *MemDep =
nullptr,
99 bool PredecessorWithTwoSuccessors =
false,
100 DominatorTree *DT =
nullptr);
110 SmallPtrSetImpl<BasicBlock *> &MergeBlocks, Loop *L =
nullptr,
111 DomTreeUpdater *DTU =
nullptr, LoopInfo *LI =
nullptr);
214 const CriticalEdgeSplittingOptions &
Options =
215 CriticalEdgeSplittingOptions(),
216 const Twine &BBName =
"");
221 const CriticalEdgeSplittingOptions &
Options =
222 CriticalEdgeSplittingOptions(),
223 const Twine &BBName =
"");
245 const CriticalEdgeSplittingOptions &
Options =
246 CriticalEdgeSplittingOptions());
251 DominatorTree *DT =
nullptr, LoopInfo *LI =
nullptr,
252 MemorySSAUpdater *MSSAU =
nullptr,
253 const Twine &BBName =
"");
261 BasicBlock *NewPred, PHINode *Until =
nullptr);
266 LandingPadInst *OriginalPad =
nullptr,
267 PHINode *LandingPadReplacement =
nullptr,
268 const CriticalEdgeSplittingOptions &
Options =
269 CriticalEdgeSplittingOptions(),
270 const Twine &BBName =
"");
283 LoopInfo *LI =
nullptr,
284 MemorySSAUpdater *MSSAU =
nullptr,
285 const Twine &BBName =
"",
bool Before =
false);
296 DomTreeUpdater *DTU =
nullptr, LoopInfo *LI =
nullptr,
297 MemorySSAUpdater *MSSAU =
nullptr,
298 const Twine &BBName =
"",
bool Before =
false);
306 DomTreeUpdater *DTU, LoopInfo *LI,
307 MemorySSAUpdater *MSSAU,
const Twine &BBName =
"");
326 const char *Suffix, DominatorTree *DT,
327 LoopInfo *LI =
nullptr,
328 MemorySSAUpdater *MSSAU =
nullptr,
329 bool PreserveLCSSA =
false);
347 DomTreeUpdater *DTU =
nullptr,
348 LoopInfo *LI =
nullptr,
349 MemorySSAUpdater *MSSAU =
nullptr,
350 bool PreserveLCSSA =
false);
366 ArrayRef<BasicBlock *> Preds,
367 const char *Suffix,
const char *Suffix2,
368 SmallVectorImpl<BasicBlock *> &NewBBs,
369 DominatorTree *DT, LoopInfo *LI =
nullptr,
370 MemorySSAUpdater *MSSAU =
nullptr,
371 bool PreserveLCSSA =
false);
385 BasicBlock *OrigBB, ArrayRef<BasicBlock *> Preds,
const char *Suffix,
386 const char *Suffix2, SmallVectorImpl<BasicBlock *> &NewBBs,
387 DomTreeUpdater *DTU =
nullptr, LoopInfo *LI =
nullptr,
388 MemorySSAUpdater *MSSAU =
nullptr,
bool PreserveLCSSA =
false);
396 DomTreeUpdater *DTU =
nullptr);
422 bool Unreachable, MDNode *BranchWeights,
424 LoopInfo *LI =
nullptr,
450 MDNode *BranchWeights =
nullptr,
451 DomTreeUpdater *DTU =
nullptr,
452 LoopInfo *LI =
nullptr,
472 Instruction **ThenTerm,
473 Instruction **ElseTerm,
474 MDNode *BranchWeights =
nullptr,
475 DomTreeUpdater *DTU =
nullptr);
510 BranchProbabilityInfo *BPI =
nullptr,
511 BlockFrequencyInfo *
BFI =
nullptr);
583 DomTreeUpdater *DTU, SmallVectorImpl<BasicBlock *> &GuardBlocks,
584 const SetVector<BasicBlock *> &Predecessors,
585 const SetVector<BasicBlock *> &Successors,
const StringRef
Prefix,
586 std::optional<unsigned> MaxControlFlowBooleans = std::nullopt);
590 #endif // LLVM_TRANSFORMS_UTILS_BASICBLOCKUTILS_H
unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
This is an optimization pass for GlobalISel generic memory operations.
void SplitLandingPadPredecessors(BasicBlock *OrigBB, ArrayRef< BasicBlock * > Preds, const char *Suffix, const char *Suffix2, SmallVectorImpl< BasicBlock * > &NewBBs, DominatorTree *DT, 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...
void ReplaceInstWithInst(BasicBlock *BB, BasicBlock::iterator &BI, Instruction *I)
Replace the instruction specified by BI with the instruction specified by I.
InstListType::iterator iterator
Instruction iterators...
void DeleteDeadBlocks(ArrayRef< BasicBlock * > BBs, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified blocks from BB.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
void detachDeadBlocks(ArrayRef< BasicBlock * > BBs, SmallVectorImpl< DominatorTree::UpdateType > *Updates, bool KeepOneInputPHIs=false)
Replace contents of every block in BBs with single unreachable instruction.
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.
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.
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...
bool IgnoreUnreachableDests
LLVM Basic Block Representation.
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.
CriticalEdgeSplittingOptions & setKeepOneInputPHIs()
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,...
Option class for critical edge splitting.
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
void SplitBlockAndInsertIfThenElse(Value *Cond, Instruction *SplitBefore, Instruction **ThenTerm, Instruction **ElseTerm, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr)
SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen, but also creates the ElseBlock...
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...
bool RemoveRedundantDbgInstrs(BasicBlock *BB)
Try to remove redundant dbg.value instructions from given basic block.
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.
bool EliminateUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete all basic blocks from F that are not reachable from its entry node.
BranchInst * GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue, BasicBlock *&IfFalse)
Check whether BB is the merge point of a if-region.
BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
CriticalEdgeSplittingOptions(DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, PostDominatorTree *PDT=nullptr)
CriticalEdgeSplittingOptions & setMergeIdenticalEdges()
CriticalEdgeSplittingOptions & unsetPreserveLoopSimplify()
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool SplitIndirectBrCriticalEdges(Function &F, bool IgnoreBlocksWithoutPHI, BranchProbabilityInfo *BPI=nullptr, BlockFrequencyInfo *BFI=nullptr)
@ BasicBlock
Various leaf nodes.
SmallVector< MachineOperand, 4 > Cond
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
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.
CriticalEdgeSplittingOptions & setPreserveLCSSA()
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 * splitBlockBefore(BasicBlock *Old, Instruction *SplitPt, DomTreeUpdater *DTU, LoopInfo *LI, MemorySSAUpdater *MSSAU, const Twine &BBName="")
Split the specified block at the specified instruction SplitPt.
bool FoldSingleEntryPHINodes(BasicBlock *BB, MemoryDependenceResults *MemDep=nullptr)
We know that BB has one predecessor.
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.
unsigned SplitAllCriticalEdges(Function &F, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
Loop over all of the edges in the CFG, breaking critical edges as they are found.
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 @...
bool MergeBlockSuccessorsIntoGivenBlocks(SmallPtrSetImpl< BasicBlock * > &MergeBlocks, Loop *L=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr)
Merge block(s) sucessors, if possible.
void DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified block, which must have no predecessors.
CriticalEdgeSplittingOptions & setIgnoreUnreachableDests()
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...
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
BlockVerifier::State From
Instruction * SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore, bool Unreachable, MDNode *BranchWeights, DominatorTree *DT, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
BasicBlock * SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="", bool Before=false)
Split the specified block at the specified instruction.
bool PreserveLoopSimplify
SplitCriticalEdge is guaranteed to preserve loop-simplify form if LI is provided.