diff options
| author | Mingjie Xu <xumingjie.enna1@bytedance.com> | 2026-02-03 09:23:17 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-03 09:23:17 +0800 |
| commit | ad8d5349d46734826aaeae4a2ebdc6f427a5bad8 (patch) | |
| tree | cc618b9dde4607b8cff8e289990c350255072a53 /llvm/lib/Transforms/Utils | |
| parent | a084deff3bd3882df12367ff5209a046e3eec9df (diff) | |
| download | llvm-main.zip llvm-main.tar.gz llvm-main.tar.bz2 | |
06dfbb50d70eea4ae38d655842626a0b9b224d5c fixed dominator update for
entry block in `SplitBlockPredecessors()`, this patch fixes dominator
tree update for entry block in `splitBlockBefore()` with
`UpdateAnalysisInformation()`.
Diffstat (limited to 'llvm/lib/Transforms/Utils')
| -rw-r--r-- | llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 63 |
1 files changed, 19 insertions, 44 deletions
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index 68d1fd8..6472e17 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -1054,50 +1054,6 @@ BasicBlock *llvm::SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt, return SplitBlockImpl(Old, SplitPt, DTU, /*DT=*/nullptr, LI, MSSAU, BBName); } -BasicBlock *llvm::splitBlockBefore(BasicBlock *Old, BasicBlock::iterator SplitPt, - DomTreeUpdater *DTU, LoopInfo *LI, - MemorySSAUpdater *MSSAU, - const Twine &BBName) { - - BasicBlock::iterator SplitIt = SplitPt; - while (isa<PHINode>(SplitIt) || SplitIt->isEHPad()) - ++SplitIt; - std::string Name = BBName.str(); - BasicBlock *New = Old->splitBasicBlockBefore( - SplitIt, Name.empty() ? Old->getName() + ".split" : Name); - - // The new block lives in whichever loop the old one did. This preserves - // LCSSA as well, because we force the split point to be after any PHI nodes. - if (LI) - if (Loop *L = LI->getLoopFor(Old)) - L->addBasicBlockToLoop(New, *LI); - - if (DTU) { - SmallVector<DominatorTree::UpdateType, 8> DTUpdates; - // New dominates Old. The predecessor nodes of the Old node dominate - // New node. - SmallPtrSet<BasicBlock *, 8> UniquePredecessorsOfOld; - DTUpdates.push_back({DominatorTree::Insert, New, Old}); - DTUpdates.reserve(DTUpdates.size() + 2 * pred_size(New)); - for (BasicBlock *PredecessorOfOld : predecessors(New)) - if (UniquePredecessorsOfOld.insert(PredecessorOfOld).second) { - DTUpdates.push_back({DominatorTree::Insert, PredecessorOfOld, New}); - DTUpdates.push_back({DominatorTree::Delete, PredecessorOfOld, Old}); - } - - DTU->applyUpdates(DTUpdates); - - // Move MemoryAccesses still tracked in Old, but part of New now. - // Update accesses in successor blocks accordingly. - if (MSSAU) { - MSSAU->applyUpdates(DTUpdates, DTU->getDomTree()); - if (VerifyMemorySSA) - MSSAU->getMemorySSA()->verifyMemorySSA(); - } - } - return New; -} - /// Update DominatorTree, LoopInfo, and LCCSA analysis information. /// Invalidates DFS Numbering when DTU or DT is provided. static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB, @@ -1212,6 +1168,25 @@ static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB, } } +BasicBlock *llvm::splitBlockBefore(BasicBlock *Old, + BasicBlock::iterator SplitPt, + DomTreeUpdater *DTU, LoopInfo *LI, + MemorySSAUpdater *MSSAU, + const Twine &BBName) { + BasicBlock::iterator SplitIt = SplitPt; + while (isa<PHINode>(SplitIt) || SplitIt->isEHPad()) + ++SplitIt; + SmallVector<BasicBlock *, 4> Preds(predecessors(Old)); + BasicBlock *New = Old->splitBasicBlockBefore( + SplitIt, BBName.isTriviallyEmpty() ? Old->getName() + ".split" : BBName); + + bool HasLoopExit = false; + UpdateAnalysisInformation(Old, New, Preds, DTU, nullptr, LI, MSSAU, false, + HasLoopExit); + + return New; +} + /// Update the PHI nodes in OrigBB to include the values coming from NewBB. /// This also updates AliasAnalysis, if available. static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB, |
