OSDN Git Service

[Utils] splitBlockBefore() always operates on DomTreeUpdater, so take it, not DomTree
authorRoman Lebedev <lebedev.ri@gmail.com>
Tue, 12 Jan 2021 16:43:16 +0000 (19:43 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Fri, 15 Jan 2021 20:35:56 +0000 (23:35 +0300)
Even though not all it's users operate on DomTreeUpdater,
it itself internally operates on DomTreeUpdater,
so it must mean everything is fine with that,
so just do that globally.

llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

index a1d5ee8..a838098 100644 (file)
@@ -271,7 +271,7 @@ BasicBlock *SplitBlock(BasicBlock *Old, Instruction *SplitPt,
 /// old block are joined by inserting an unconditional branch to the end of the
 /// new block. The new block with name \p BBName is returned.
 BasicBlock *splitBlockBefore(BasicBlock *Old, Instruction *SplitPt,
-                             DominatorTree *DT, LoopInfo *LI,
+                             DomTreeUpdater *DTU, LoopInfo *LI,
                              MemorySSAUpdater *MSSAU, const Twine &BBName = "");
 
 /// This method introduces at least one new basic block into the function and
index bfad88f..f89a1fa 100644 (file)
@@ -546,8 +546,10 @@ BasicBlock *llvm::SplitBlock(BasicBlock *Old, Instruction *SplitPt,
                              DominatorTree *DT, LoopInfo *LI,
                              MemorySSAUpdater *MSSAU, const Twine &BBName,
                              bool Before) {
-  if (Before)
-    return splitBlockBefore(Old, SplitPt, DT, LI, MSSAU, BBName);
+  if (Before) {
+    DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
+    return splitBlockBefore(Old, SplitPt, &DTU, LI, MSSAU, BBName);
+  }
   BasicBlock::iterator SplitIt = SplitPt->getIterator();
   while (isa<PHINode>(SplitIt) || SplitIt->isEHPad())
     ++SplitIt;
@@ -580,7 +582,7 @@ BasicBlock *llvm::SplitBlock(BasicBlock *Old, Instruction *SplitPt,
 }
 
 BasicBlock *llvm::splitBlockBefore(BasicBlock *Old, Instruction *SplitPt,
-                                   DominatorTree *DT, LoopInfo *LI,
+                                   DomTreeUpdater *DTU, LoopInfo *LI,
                                    MemorySSAUpdater *MSSAU,
                                    const Twine &BBName) {
 
@@ -598,25 +600,25 @@ BasicBlock *llvm::splitBlockBefore(BasicBlock *Old, Instruction *SplitPt,
     if (Loop *L = LI->getLoopFor(Old))
       L->addBasicBlockToLoop(New, *LI);
 
-  if (DT) {
-    DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
+  if (DTU) {
     SmallVector<DominatorTree::UpdateType, 8> DTUpdates;
     // New dominates Old. The predecessor nodes of the Old node dominate
     // New node.
+    SmallSetVector<BasicBlock *, 8> UniquePredecessorsOfOld(pred_begin(New),
+                                                            pred_end(New));
     DTUpdates.push_back({DominatorTree::Insert, New, Old});
-    for (BasicBlock *Pred : predecessors(New))
-      if (DT->getNode(Pred)) {
-        DTUpdates.push_back({DominatorTree::Insert, Pred, New});
-        DTUpdates.push_back({DominatorTree::Delete, Pred, Old});
-      }
+    DTUpdates.reserve(DTUpdates.size() + 2 * UniquePredecessorsOfOld.size());
+    for (BasicBlock *UniquePredecessorOfOld : UniquePredecessorsOfOld) {
+      DTUpdates.push_back({DominatorTree::Insert, UniquePredecessorOfOld, New});
+      DTUpdates.push_back({DominatorTree::Delete, UniquePredecessorOfOld, Old});
+    }
 
-    DTU.applyUpdates(DTUpdates);
-    DTU.flush();
+    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, *DT);
+      MSSAU->applyUpdates(DTUpdates, DTU->getDomTree());
       if (VerifyMemorySSA)
         MSSAU->getMemorySSA()->verifyMemorySSA();
     }