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);
94 LoopInfo *LI =
nullptr,
95 MemorySSAUpdater *MSSAU =
nullptr,
96 MemoryDependenceResults *MemDep =
nullptr,
97 bool PredecessorWithTwoSuccessors =
false);
107 SmallPtrSetImpl<BasicBlock *> &MergeBlocks, Loop *L =
nullptr,
108 DomTreeUpdater *DTU =
nullptr, LoopInfo *LI =
nullptr);
212 const CriticalEdgeSplittingOptions &
Options =
213 CriticalEdgeSplittingOptions(),
214 const Twine &BBName =
"");
219 const CriticalEdgeSplittingOptions &
Options =
220 CriticalEdgeSplittingOptions(),
221 const Twine &BBName =
"");
243 const CriticalEdgeSplittingOptions &
Options =
244 CriticalEdgeSplittingOptions());
249 DominatorTree *DT =
nullptr, LoopInfo *LI =
nullptr,
250 MemorySSAUpdater *MSSAU =
nullptr,
251 const Twine &BBName =
"");
259 BasicBlock *NewPred, PHINode *Until =
nullptr);
264 LandingPadInst *OriginalPad =
nullptr,
265 PHINode *LandingPadReplacement =
nullptr,
266 const CriticalEdgeSplittingOptions &
Options =
267 CriticalEdgeSplittingOptions(),
268 const Twine &BBName =
"");
281 LoopInfo *LI =
nullptr,
282 MemorySSAUpdater *MSSAU =
nullptr,
283 const Twine &BBName =
"",
bool Before =
false);
294 DomTreeUpdater *DTU =
nullptr, LoopInfo *LI =
nullptr,
295 MemorySSAUpdater *MSSAU =
nullptr,
296 const Twine &BBName =
"",
bool Before =
false);
304 DomTreeUpdater *DTU, LoopInfo *LI,
305 MemorySSAUpdater *MSSAU,
const Twine &BBName =
"");
324 const char *Suffix, DominatorTree *DT,
325 LoopInfo *LI =
nullptr,
326 MemorySSAUpdater *MSSAU =
nullptr,
327 bool PreserveLCSSA =
false);
345 DomTreeUpdater *DTU =
nullptr,
346 LoopInfo *LI =
nullptr,
347 MemorySSAUpdater *MSSAU =
nullptr,
348 bool PreserveLCSSA =
false);
364 ArrayRef<BasicBlock *> Preds,
365 const char *Suffix,
const char *Suffix2,
366 SmallVectorImpl<BasicBlock *> &NewBBs,
367 DominatorTree *DT, LoopInfo *LI =
nullptr,
368 MemorySSAUpdater *MSSAU =
nullptr,
369 bool PreserveLCSSA =
false);
383 BasicBlock *OrigBB, ArrayRef<BasicBlock *> Preds,
const char *Suffix,
384 const char *Suffix2, SmallVectorImpl<BasicBlock *> &NewBBs,
385 DomTreeUpdater *DTU =
nullptr, LoopInfo *LI =
nullptr,
386 MemorySSAUpdater *MSSAU =
nullptr,
bool PreserveLCSSA =
false);
394 DomTreeUpdater *DTU =
nullptr);
420 bool Unreachable, MDNode *BranchWeights,
422 LoopInfo *LI =
nullptr,
448 MDNode *BranchWeights =
nullptr,
449 DomTreeUpdater *DTU =
nullptr,
450 LoopInfo *LI =
nullptr,
468 Instruction **ThenTerm,
469 Instruction **ElseTerm,
470 MDNode *BranchWeights =
nullptr);
505 BranchProbabilityInfo *BPI =
nullptr,
506 BlockFrequencyInfo *
BFI =
nullptr);
578 SmallVectorImpl<BasicBlock *> &GuardBlocks,
579 const SetVector<BasicBlock *> &Predecessors,
580 const SetVector<BasicBlock *> &Successors,
585 #endif // LLVM_TRANSFORMS_UTILS_BASICBLOCKUTILS_H
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...
SymbolTableList< Instruction > InstListType
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.
unsigned getNumSuccessors() const
Return the number of successors that this instruction has.
CriticalEdgeSplittingOptions & setKeepOneInputPHIs()
BasicBlock * CreateControlFlowHub(DomTreeUpdater *DTU, SmallVectorImpl< BasicBlock * > &GuardBlocks, const SetVector< BasicBlock * > &Predecessors, const SetVector< BasicBlock * > &Successors, const StringRef Prefix)
Given a set of incoming and outgoing blocks, create a "hub" such that every edge from an incoming blo...
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,...
void ReplaceInstWithInst(BasicBlock::InstListType &BIL, BasicBlock::iterator &BI, Instruction *I)
Replace the instruction specified by BI with the instruction specified by I.
Option class for critical edge splitting.
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
BasicBlock * getSuccessor(unsigned Idx) const
Return the specified successor. This instruction must be a terminator.
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.
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.
void SplitBlockAndInsertIfThenElse(Value *Cond, Instruction *SplitBefore, Instruction **ThenTerm, Instruction **ElseTerm, MDNode *BranchWeights=nullptr)
SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen, but also creates the ElseBlock...
bool MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, MemoryDependenceResults *MemDep=nullptr, bool PredecessorWithTwoSuccessors=false)
Attempts to merge a block into its predecessor, if possible.
SmallVector< MachineOperand, 4 > Cond
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
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...
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()
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()
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.