[llvm] [polly] [BBUtils][nfc] Delete SplitBlockPredecessors with DT (PR #97196)

Joshua Cao via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 30 02:03:41 PDT 2024


https://github.com/caojoshua created https://github.com/llvm/llvm-project/pull/97196

The function is marked for deprecation. Consumers are modified to use the DomTreeUpdater version of SplitBlockPredecessors.

>From 0a0564b6023a9357e301899cd2ddd71ff7118ce5 Mon Sep 17 00:00:00 2001
From: Joshua Cao <cao.joshua at yahoo.com>
Date: Sun, 30 Jun 2024 01:53:35 -0700
Subject: [PATCH] [BBUtils][nfc] Delete SplitBlockPredecessors with DT

The function is marked for deprecation. Consumers are modified to use
the DomTreeUpdater version of SplitBlockPredecessors.
---
 .../llvm/Transforms/Utils/BasicBlockUtils.h   |  22 ----
 .../Target/AMDGPU/SIAnnotateControlFlow.cpp   |   4 +-
 llvm/lib/Transforms/Scalar/LICM.cpp           |   4 +-
 .../Scalar/RewriteStatepointsForGC.cpp        |  13 +-
 llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 113 ++++++++----------
 .../Transforms/Utils/BreakCriticalEdges.cpp   |   7 +-
 llvm/lib/Transforms/Utils/LoopSimplify.cpp    |   9 +-
 .../Transforms/Utils/LoopUnrollRuntime.cpp    |  14 ++-
 llvm/lib/Transforms/Utils/LoopUtils.cpp       |   3 +-
 .../Transforms/Utils/BasicBlockUtilsTest.cpp  |   3 +-
 polly/lib/CodeGen/Utils.cpp                   |  12 +-
 polly/lib/Support/ScopHelper.cpp              |  14 ++-
 12 files changed, 98 insertions(+), 120 deletions(-)

diff --git a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
index c99df6bf94d02..1301becf13b9b 100644
--- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
@@ -324,28 +324,6 @@ inline BasicBlock *splitBlockBefore(BasicBlock *Old, Instruction *SplitPt,
   return splitBlockBefore(Old, SplitPt->getIterator(), DTU, LI, MSSAU, BBName);
 }
 
-/// This method introduces at least one new basic block into the function and
-/// moves some of the predecessors of BB to be predecessors of the new block.
-/// The new predecessors are indicated by the Preds array. The new block is
-/// given a suffix of 'Suffix'. Returns new basic block to which predecessors
-/// from Preds are now pointing.
-///
-/// If BB is a landingpad block then additional basicblock might be introduced.
-/// It will have Suffix+".split_lp". See SplitLandingPadPredecessors for more
-/// details on this case.
-///
-/// This currently updates the LLVM IR, DominatorTree, LoopInfo, and LCCSA but
-/// no other analyses. In particular, it does not preserve LoopSimplify
-/// (because it's complicated to handle the case where one of the edges being
-/// split is an exit of a loop with other exits).
-///
-/// FIXME: deprecated, switch to the DomTreeUpdater-based one.
-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 predecessors of BB to be predecessors of the new block.
 /// The new predecessors are indicated by the Preds array. The new block is
diff --git a/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp b/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
index 08e1d6b87b0df..507d2362c16c7 100644
--- a/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
+++ b/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
@@ -13,6 +13,7 @@
 
 #include "AMDGPU.h"
 #include "GCNSubtarget.h"
+#include "llvm/Analysis/DomTreeUpdater.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/UniformityAnalysis.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
@@ -323,7 +324,8 @@ bool SIAnnotateControlFlow::closeControlFlow(BasicBlock *BB) {
         Preds.push_back(Pred);
     }
 
-    BB = SplitBlockPredecessors(BB, Preds, "endcf.split", DT, LI, nullptr,
+    DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
+    BB = SplitBlockPredecessors(BB, Preds, "endcf.split", &DTU, LI, nullptr,
                                 false);
   }
 
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index 91ef2b4b7c183..285993cc0ad3c 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -44,6 +44,7 @@
 #include "llvm/Analysis/AliasSetTracker.h"
 #include "llvm/Analysis/AssumptionCache.h"
 #include "llvm/Analysis/CaptureTracking.h"
+#include "llvm/Analysis/DomTreeUpdater.h"
 #include "llvm/Analysis/GuardUtils.h"
 #include "llvm/Analysis/LazyBlockFrequencyInfo.h"
 #include "llvm/Analysis/Loads.h"
@@ -1601,13 +1602,14 @@ static void splitPredecessorsOfLoopExit(PHINode *PN, DominatorTree *DT,
   //
   const auto &BlockColors = SafetyInfo->getBlockColors();
   SmallSetVector<BasicBlock *, 8> PredBBs(pred_begin(ExitBB), pred_end(ExitBB));
+  DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
   while (!PredBBs.empty()) {
     BasicBlock *PredBB = *PredBBs.begin();
     assert(CurLoop->contains(PredBB) &&
            "Expect all predecessors are in the loop");
     if (PN->getBasicBlockIndex(PredBB) >= 0) {
       BasicBlock *NewPred = SplitBlockPredecessors(
-          ExitBB, PredBB, ".split.loop.exit", DT, LI, MSSAU, true);
+          ExitBB, PredBB, ".split.loop.exit", &DTU, LI, MSSAU, true);
       // Since we do not allow splitting EH-block with BlockColors in
       // canSplitPredecessors(), we can simply assign predecessor's color to
       // the new block.
diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 2b99e28acb4e9..4dbb7ba39fa25 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1422,12 +1422,12 @@ static Instruction *rematerializeChain(ArrayRef<Instruction *> ChainToBase,
 // starting one of the successor blocks.  We also need to be able to insert the
 // gc.relocates only on the path which goes through the statepoint.  We might
 // need to split an edge to make this possible.
-static BasicBlock *
-normalizeForInvokeSafepoint(BasicBlock *BB, BasicBlock *InvokeParent,
-                            DominatorTree &DT) {
+static BasicBlock *normalizeForInvokeSafepoint(BasicBlock *BB,
+                                               BasicBlock *InvokeParent,
+                                               DomTreeUpdater &DTU) {
   BasicBlock *Ret = BB;
   if (!BB->getUniquePredecessor())
-    Ret = SplitBlockPredecessors(BB, InvokeParent, "", &DT);
+    Ret = SplitBlockPredecessors(BB, InvokeParent, "", &DTU);
 
   // Now that 'Ret' has unique predecessor we can safely remove all phi nodes
   // from it
@@ -2665,12 +2665,13 @@ static bool insertParsePoints(Function &F, DominatorTree &DT,
   // the top of the successor blocks.  See the comment on
   // normalForInvokeSafepoint on exactly what is needed.  Note that this step
   // may restructure the CFG.
+  DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
   for (CallBase *Call : ToUpdate) {
     auto *II = dyn_cast<InvokeInst>(Call);
     if (!II)
       continue;
-    normalizeForInvokeSafepoint(II->getNormalDest(), II->getParent(), DT);
-    normalizeForInvokeSafepoint(II->getUnwindDest(), II->getParent(), DT);
+    normalizeForInvokeSafepoint(II->getNormalDest(), II->getParent(), DTU);
+    normalizeForInvokeSafepoint(II->getUnwindDest(), II->getParent(), DTU);
   }
 
   // A list of dummy calls added to the IR to keep various values obviously
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 79911bf563ea4..76cfdfd7d3a11 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -909,8 +909,8 @@ BasicBlock *llvm::ehAwareSplitEdge(BasicBlock *BB, BasicBlock *Succ,
   if (!DT && !LI)
     return NewBB;
 
+  DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
   if (DT) {
-    DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
     SmallVector<DominatorTree::UpdateType, 3> Updates;
 
     Updates.push_back({DominatorTree::Insert, BB, NewBB});
@@ -966,7 +966,7 @@ BasicBlock *llvm::ehAwareSplitEdge(BasicBlock *BB, BasicBlock *Succ,
 
         if (!LoopPreds.empty()) {
           BasicBlock *NewExitBB = SplitBlockPredecessors(
-              Succ, LoopPreds, "split", DT, LI, MSSAU, Options.PreserveLCSSA);
+              Succ, LoopPreds, "split", &DTU, LI, MSSAU, Options.PreserveLCSSA);
           if (Options.PreserveLCSSA)
             createPHIsForSplitLoopExit(LoopPreds, NewExitBB, Succ);
         }
@@ -1144,52 +1144,41 @@ BasicBlock *llvm::splitBlockBefore(BasicBlock *Old, BasicBlock::iterator SplitPt
 /// Invalidates DFS Numbering when DTU or DT is provided.
 static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB,
                                       ArrayRef<BasicBlock *> Preds,
-                                      DomTreeUpdater *DTU, DominatorTree *DT,
-                                      LoopInfo *LI, MemorySSAUpdater *MSSAU,
+                                      DomTreeUpdater *DTU, LoopInfo *LI,
+                                      MemorySSAUpdater *MSSAU,
                                       bool PreserveLCSSA, bool &HasLoopExit) {
-  // Update dominator tree if available.
-  if (DTU) {
-    // Recalculation of DomTree is needed when updating a forward DomTree and
-    // the Entry BB is replaced.
-    if (NewBB->isEntryBlock() && DTU->hasDomTree()) {
-      // The entry block was removed and there is no external interface for
-      // the dominator tree to be notified of this change. In this corner-case
-      // we recalculate the entire tree.
-      DTU->recalculate(*NewBB->getParent());
-    } else {
-      // Split block expects NewBB to have a non-empty set of predecessors.
-      SmallVector<DominatorTree::UpdateType, 8> Updates;
-      SmallPtrSet<BasicBlock *, 8> UniquePreds;
-      Updates.push_back({DominatorTree::Insert, NewBB, OldBB});
-      Updates.reserve(Updates.size() + 2 * Preds.size());
-      for (auto *Pred : Preds)
-        if (UniquePreds.insert(Pred).second) {
-          Updates.push_back({DominatorTree::Insert, Pred, NewBB});
-          Updates.push_back({DominatorTree::Delete, Pred, OldBB});
-        }
-      DTU->applyUpdates(Updates);
-    }
-  } else if (DT) {
-    if (OldBB == DT->getRootNode()->getBlock()) {
-      assert(NewBB->isEntryBlock());
-      DT->setNewRoot(NewBB);
-    } else {
-      // Split block expects NewBB to have a non-empty set of predecessors.
-      DT->splitBlock(NewBB);
-    }
-  }
-
   // Update MemoryPhis after split if MemorySSA is available
   if (MSSAU)
     MSSAU->wireOldPredecessorsToNewImmediatePredecessor(OldBB, NewBB, Preds);
 
+  if (!DTU)
+    return;
+
+  // Update the dominator tree. Recalculation of DomTree is needed when updating
+  // a forward DomTree and the Entry BB is replaced.
+  if (NewBB->isEntryBlock() && DTU->hasDomTree()) {
+    // The entry block was removed and there is no external interface for
+    // the dominator tree to be notified of this change. In this corner-case
+    // we recalculate the entire tree.
+    DTU->recalculate(*NewBB->getParent());
+  } else {
+    // Split block expects NewBB to have a non-empty set of predecessors.
+    SmallVector<DominatorTree::UpdateType, 8> Updates;
+    SmallPtrSet<BasicBlock *, 8> UniquePreds;
+    Updates.push_back({DominatorTree::Insert, NewBB, OldBB});
+    Updates.reserve(Updates.size() + 2 * Preds.size());
+    for (auto *Pred : Preds)
+      if (UniquePreds.insert(Pred).second) {
+        Updates.push_back({DominatorTree::Insert, Pred, NewBB});
+        Updates.push_back({DominatorTree::Delete, Pred, OldBB});
+      }
+    DTU->applyUpdates(Updates);
+  }
+
   // The rest of the logic is only relevant for updating the loop structures.
   if (!LI)
     return;
 
-  if (DTU && DTU->hasDomTree())
-    DT = &DTU->getDomTree();
-  assert(DT && "DT should be available to update LoopInfo!");
   Loop *L = LI->getLoopFor(OldBB);
 
   // If we need to preserve loop analyses, collect some information about how
@@ -1201,7 +1190,7 @@ static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB,
     // OldBB is a loop entry or if SplitMakesNewLoopHeader. Unreachable blocks
     // are not within any loops, so we incorrectly mark SplitMakesNewLoopHeader
     // as true and make the NewBB the header of some loop. This breaks LI.
-    if (!DT->isReachableFromEntry(Pred))
+    if (!DTU->getDomTree().isReachableFromEntry(Pred))
       continue;
     // If we need to preserve LCSSA, determine if any of the preds is a loop
     // exit.
@@ -1322,14 +1311,15 @@ static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB,
 static void SplitLandingPadPredecessorsImpl(
     BasicBlock *OrigBB, ArrayRef<BasicBlock *> Preds, const char *Suffix1,
     const char *Suffix2, SmallVectorImpl<BasicBlock *> &NewBBs,
-    DomTreeUpdater *DTU, DominatorTree *DT, LoopInfo *LI,
-    MemorySSAUpdater *MSSAU, bool PreserveLCSSA);
-
-static BasicBlock *
-SplitBlockPredecessorsImpl(BasicBlock *BB, ArrayRef<BasicBlock *> Preds,
-                           const char *Suffix, DomTreeUpdater *DTU,
-                           DominatorTree *DT, LoopInfo *LI,
-                           MemorySSAUpdater *MSSAU, bool PreserveLCSSA) {
+    DomTreeUpdater *DTU, LoopInfo *LI, MemorySSAUpdater *MSSAU,
+    bool PreserveLCSSA);
+
+static BasicBlock *SplitBlockPredecessorsImpl(BasicBlock *BB,
+                                              ArrayRef<BasicBlock *> Preds,
+                                              const char *Suffix,
+                                              DomTreeUpdater *DTU, LoopInfo *LI,
+                                              MemorySSAUpdater *MSSAU,
+                                              bool PreserveLCSSA) {
   // Do not attempt to split that which cannot be split.
   if (!BB->canSplitPredecessors())
     return nullptr;
@@ -1341,7 +1331,7 @@ SplitBlockPredecessorsImpl(BasicBlock *BB, ArrayRef<BasicBlock *> Preds,
     std::string NewName = std::string(Suffix) + ".split-lp";
 
     SplitLandingPadPredecessorsImpl(BB, Preds, Suffix, NewName.c_str(), NewBBs,
-                                    DTU, DT, LI, MSSAU, PreserveLCSSA);
+                                    DTU, LI, MSSAU, PreserveLCSSA);
     return NewBBs[0];
   }
 
@@ -1391,7 +1381,7 @@ SplitBlockPredecessorsImpl(BasicBlock *BB, ArrayRef<BasicBlock *> Preds,
 
   // Update DominatorTree, LoopInfo, and LCCSA analysis information.
   bool HasLoopExit = false;
-  UpdateAnalysisInformation(BB, NewBB, Preds, DTU, DT, LI, MSSAU, PreserveLCSSA,
+  UpdateAnalysisInformation(BB, NewBB, Preds, DTU, LI, MSSAU, PreserveLCSSA,
                             HasLoopExit);
 
   if (!Preds.empty()) {
@@ -1415,29 +1405,21 @@ SplitBlockPredecessorsImpl(BasicBlock *BB, ArrayRef<BasicBlock *> Preds,
   return NewBB;
 }
 
-BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
-                                         ArrayRef<BasicBlock *> Preds,
-                                         const char *Suffix, DominatorTree *DT,
-                                         LoopInfo *LI, MemorySSAUpdater *MSSAU,
-                                         bool PreserveLCSSA) {
-  return SplitBlockPredecessorsImpl(BB, Preds, Suffix, /*DTU=*/nullptr, DT, LI,
-                                    MSSAU, PreserveLCSSA);
-}
 BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
                                          ArrayRef<BasicBlock *> Preds,
                                          const char *Suffix,
                                          DomTreeUpdater *DTU, LoopInfo *LI,
                                          MemorySSAUpdater *MSSAU,
                                          bool PreserveLCSSA) {
-  return SplitBlockPredecessorsImpl(BB, Preds, Suffix, DTU,
-                                    /*DT=*/nullptr, LI, MSSAU, PreserveLCSSA);
+  return SplitBlockPredecessorsImpl(BB, Preds, Suffix, DTU, LI, MSSAU,
+                                    PreserveLCSSA);
 }
 
 static void SplitLandingPadPredecessorsImpl(
     BasicBlock *OrigBB, ArrayRef<BasicBlock *> Preds, const char *Suffix1,
     const char *Suffix2, SmallVectorImpl<BasicBlock *> &NewBBs,
-    DomTreeUpdater *DTU, DominatorTree *DT, LoopInfo *LI,
-    MemorySSAUpdater *MSSAU, bool PreserveLCSSA) {
+    DomTreeUpdater *DTU, LoopInfo *LI, MemorySSAUpdater *MSSAU,
+    bool PreserveLCSSA) {
   assert(OrigBB->isLandingPad() && "Trying to split a non-landing pad!");
 
   // Create a new basic block for OrigBB's predecessors listed in Preds. Insert
@@ -1462,7 +1444,7 @@ static void SplitLandingPadPredecessorsImpl(
   }
 
   bool HasLoopExit = false;
-  UpdateAnalysisInformation(OrigBB, NewBB1, Preds, DTU, DT, LI, MSSAU,
+  UpdateAnalysisInformation(OrigBB, NewBB1, Preds, DTU, LI, MSSAU,
                             PreserveLCSSA, HasLoopExit);
 
   // Update the PHI nodes in OrigBB with the values coming from NewBB1.
@@ -1498,7 +1480,7 @@ static void SplitLandingPadPredecessorsImpl(
 
     // Update DominatorTree, LoopInfo, and LCCSA analysis information.
     HasLoopExit = false;
-    UpdateAnalysisInformation(OrigBB, NewBB2, NewBB2Preds, DTU, DT, LI, MSSAU,
+    UpdateAnalysisInformation(OrigBB, NewBB2, NewBB2Preds, DTU, LI, MSSAU,
                               PreserveLCSSA, HasLoopExit);
 
     // Update the PHI nodes in OrigBB with the values coming from NewBB2.
@@ -1543,8 +1525,7 @@ void llvm::SplitLandingPadPredecessors(BasicBlock *OrigBB,
                                        MemorySSAUpdater *MSSAU,
                                        bool PreserveLCSSA) {
   return SplitLandingPadPredecessorsImpl(OrigBB, Preds, Suffix1, Suffix2,
-                                         NewBBs, DTU, /*DT=*/nullptr, LI, MSSAU,
-                                         PreserveLCSSA);
+                                         NewBBs, DTU, LI, MSSAU, PreserveLCSSA);
 }
 
 ReturnInst *llvm::FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB,
diff --git a/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp b/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp
index 4606514cbc717..ad524e7203117 100644
--- a/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp
+++ b/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Analysis/BlockFrequencyInfo.h"
 #include "llvm/Analysis/BranchProbabilityInfo.h"
 #include "llvm/Analysis/CFG.h"
+#include "llvm/Analysis/DomTreeUpdater.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/MemorySSAUpdater.h"
 #include "llvm/Analysis/PostDominators.h"
@@ -293,8 +294,10 @@ llvm::SplitKnownCriticalEdge(Instruction *TI, unsigned SuccNum,
 
         if (!LoopPreds.empty()) {
           assert(!DestBB->isEHPad() && "We don't split edges to EH pads!");
-          BasicBlock *NewExitBB = SplitBlockPredecessors(
-              DestBB, LoopPreds, "split", DT, LI, MSSAU, Options.PreserveLCSSA);
+          DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
+          BasicBlock *NewExitBB =
+              SplitBlockPredecessors(DestBB, LoopPreds, "split", &DTU, LI,
+                                     MSSAU, Options.PreserveLCSSA);
           if (Options.PreserveLCSSA)
             createPHIsForSplitLoopExit(LoopPreds, NewExitBB, DestBB);
         }
diff --git a/llvm/lib/Transforms/Utils/LoopSimplify.cpp b/llvm/lib/Transforms/Utils/LoopSimplify.cpp
index 66b59cdc784d3..3e9d4862146a2 100644
--- a/llvm/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/llvm/lib/Transforms/Utils/LoopSimplify.cpp
@@ -48,6 +48,7 @@
 #include "llvm/Analysis/BasicAliasAnalysis.h"
 #include "llvm/Analysis/BranchProbabilityInfo.h"
 #include "llvm/Analysis/DependenceAnalysis.h"
+#include "llvm/Analysis/DomTreeUpdater.h"
 #include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/InstructionSimplify.h"
 #include "llvm/Analysis/LoopInfo.h"
@@ -137,8 +138,9 @@ BasicBlock *llvm::InsertPreheaderForLoop(Loop *L, DominatorTree *DT,
 
   // Split out the loop pre-header.
   BasicBlock *PreheaderBB;
-  PreheaderBB = SplitBlockPredecessors(Header, OutsideBlocks, ".preheader", DT,
-                                       LI, MSSAU, PreserveLCSSA);
+  DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
+  PreheaderBB = SplitBlockPredecessors(Header, OutsideBlocks, ".preheader",
+                                       &DTU, LI, MSSAU, PreserveLCSSA);
   if (!PreheaderBB)
     return nullptr;
 
@@ -269,8 +271,9 @@ static Loop *separateNestedLoop(Loop *L, BasicBlock *Preheader,
   if (SE)
     SE->forgetLoop(L);
 
+  DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
   BasicBlock *NewBB = SplitBlockPredecessors(Header, OuterLoopPreds, ".outer",
-                                             DT, LI, MSSAU, PreserveLCSSA);
+                                             &DTU, LI, MSSAU, PreserveLCSSA);
 
   // Make sure that NewBB is put someplace intelligent, which doesn't mess up
   // code layout too horribly.
diff --git a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
index 56aa96e550d9c..1e12f6c743233 100644
--- a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
@@ -153,12 +153,13 @@ static void ConnectProlog(Loop *L, Value *BECount, unsigned Count,
   // Make sure that created prolog loop is in simplified form
   SmallVector<BasicBlock *, 4> PrologExitPreds;
   Loop *PrologLoop = LI->getLoopFor(PrologLatch);
+  DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
   if (PrologLoop) {
     for (BasicBlock *PredBB : predecessors(PrologExit))
       if (PrologLoop->contains(PredBB))
         PrologExitPreds.push_back(PredBB);
 
-    SplitBlockPredecessors(PrologExit, PrologExitPreds, ".unr-lcssa", DT, LI,
+    SplitBlockPredecessors(PrologExit, PrologExitPreds, ".unr-lcssa", &DTU, LI,
                            nullptr, PreserveLCSSA);
   }
 
@@ -177,7 +178,7 @@ static void ConnectProlog(Loop *L, Value *BECount, unsigned Count,
       B.CreateICmpULT(BECount, ConstantInt::get(BECount->getType(), Count - 1));
   // Split the exit to maintain loop canonicalization guarantees
   SmallVector<BasicBlock *, 4> Preds(predecessors(OriginalLoopLatchExit));
-  SplitBlockPredecessors(OriginalLoopLatchExit, Preds, ".unr-lcssa", DT, LI,
+  SplitBlockPredecessors(OriginalLoopLatchExit, Preds, ".unr-lcssa", &DTU, LI,
                          nullptr, PreserveLCSSA);
   // Add the branch to the exit block (around the unrolled loop)
   MDNode *BranchWeights = nullptr;
@@ -307,7 +308,8 @@ static void ConnectEpilog(Loop *L, Value *ModVal, BasicBlock *NewExit,
   assert(Exit && "Loop must have a single exit block only");
   // Split the epilogue exit to maintain loop canonicalization guarantees
   SmallVector<BasicBlock*, 4> Preds(predecessors(Exit));
-  SplitBlockPredecessors(Exit, Preds, ".epilog-lcssa", DT, LI, nullptr,
+  DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
+  SplitBlockPredecessors(Exit, Preds, ".epilog-lcssa", &DTU, LI, nullptr,
                          PreserveLCSSA);
   // Add the branch to the exit block (around the unrolling loop)
   MDNode *BranchWeights = nullptr;
@@ -325,7 +327,7 @@ static void ConnectEpilog(Loop *L, Value *ModVal, BasicBlock *NewExit,
 
   // Split the main loop exit to maintain canonicalization guarantees.
   SmallVector<BasicBlock*, 4> NewExitPreds{Latch};
-  SplitBlockPredecessors(NewExit, NewExitPreds, ".loopexit", DT, LI, nullptr,
+  SplitBlockPredecessors(NewExit, NewExitPreds, ".loopexit", &DTU, LI, nullptr,
                          PreserveLCSSA);
 }
 
@@ -702,13 +704,14 @@ bool llvm::UnrollRuntimeLoopRemainder(
   BasicBlock *EpilogPreHeader = nullptr;
   BasicBlock *PrologPreHeader = nullptr;
 
+  DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
   if (UseEpilogRemainder) {
     // If epilog remainder
     // Split PreHeader to insert a branch around loop for unrolling.
     NewPreHeader = SplitBlock(PreHeader, PreHeader->getTerminator(), DT, LI);
     NewPreHeader->setName(PreHeader->getName() + ".new");
     // Split LatchExit to create phi nodes from branch above.
-    NewExit = SplitBlockPredecessors(LatchExit, {Latch}, ".unr-lcssa", DT, LI,
+    NewExit = SplitBlockPredecessors(LatchExit, {Latch}, ".unr-lcssa", &DTU, LI,
                                      nullptr, PreserveLCSSA);
     // NewExit gets its DebugLoc from LatchExit, which is not part of the
     // original Loop.
@@ -996,7 +999,6 @@ bool llvm::UnrollRuntimeLoopRemainder(
     // Merge latch into exit block.
     auto *ExitBB = RemainderLatch->getSingleSuccessor();
     assert(ExitBB && "required after breaking cond br backedge");
-    DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
     MergeBlockIntoPredecessor(ExitBB, &DTU, LI);
   }
 
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index a127a3265758d..64b213db27cd3 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -87,8 +87,9 @@ bool llvm::formDedicatedExitBlocks(Loop *L, DominatorTree *DT, LoopInfo *LI,
     if (IsDedicatedExit)
       return false;
 
+    DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
     auto *NewExitBB = SplitBlockPredecessors(
-        BB, InLoopPredecessors, ".loopexit", DT, LI, MSSAU, PreserveLCSSA);
+        BB, InLoopPredecessors, ".loopexit", &DTU, LI, MSSAU, PreserveLCSSA);
 
     if (!NewExitBB)
       LLVM_DEBUG(
diff --git a/llvm/unittests/Transforms/Utils/BasicBlockUtilsTest.cpp b/llvm/unittests/Transforms/Utils/BasicBlockUtilsTest.cpp
index 56692cf25b797..7e990a1b7e9a2 100644
--- a/llvm/unittests/Transforms/Utils/BasicBlockUtilsTest.cpp
+++ b/llvm/unittests/Transforms/Utils/BasicBlockUtilsTest.cpp
@@ -407,10 +407,11 @@ define i32 @basic_func(i1 %cond) {
 )IR");
   Function *F = M->getFunction("basic_func");
   DominatorTree DT(*F);
+  DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
 
   // Make sure the dominator tree is properly updated if calling this on the
   // entry block.
-  SplitBlockPredecessors(&F->getEntryBlock(), {}, "split.entry", &DT);
+  SplitBlockPredecessors(&F->getEntryBlock(), {}, "split.entry", &DTU);
   EXPECT_TRUE(DT.verify());
 }
 
diff --git a/polly/lib/CodeGen/Utils.cpp b/polly/lib/CodeGen/Utils.cpp
index 3afb2e580889b..259475c29e646 100644
--- a/polly/lib/CodeGen/Utils.cpp
+++ b/polly/lib/CodeGen/Utils.cpp
@@ -13,6 +13,7 @@
 #include "polly/CodeGen/Utils.h"
 #include "polly/CodeGen/IRBuilder.h"
 #include "polly/ScopInfo.h"
+#include "llvm/Analysis/DomTreeUpdater.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/RegionInfo.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
@@ -29,7 +30,7 @@ using namespace llvm;
 // The issue with llvm::SplitEdge is that it does not always create the middle
 // block, but reuses Prev/Succ if it can. We always want a new middle block.
 static BasicBlock *splitEdge(BasicBlock *Prev, BasicBlock *Succ,
-                             const char *Suffix, DominatorTree *DT,
+                             const char *Suffix, DomTreeUpdater *DTU,
                              LoopInfo *LI, RegionInfo *RI) {
   assert(Prev && Succ);
 
@@ -48,7 +49,7 @@ static BasicBlock *splitEdge(BasicBlock *Prev, BasicBlock *Succ,
   // either modify llvm::SplitCriticalEdge to allow skipping the critical edge
   // check; or Copy&Pase it here.
   BasicBlock *MiddleBlock = SplitBlockPredecessors(
-      Succ, ArrayRef<BasicBlock *>(Prev), Suffix, DT, LI);
+      Succ, ArrayRef<BasicBlock *>(Prev), Suffix, DTU, LI);
 
   if (RI) {
     Region *PrevRegion = RI->getRegionFor(Prev);
@@ -96,8 +97,9 @@ polly::executeScopConditionally(Scop &S, Value *RTC, DominatorTree &DT,
   BasicBlock *EnteringBB = S.getEnteringBlock();
   BasicBlock *EntryBB = S.getEntry();
   assert(EnteringBB && "Must be a simple region");
+  DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
   BasicBlock *SplitBlock =
-      splitEdge(EnteringBB, EntryBB, ".split_new_and_old", &DT, &LI, &RI);
+      splitEdge(EnteringBB, EntryBB, ".split_new_and_old", &DTU, &LI, &RI);
   SplitBlock->setName("polly.split_new_and_old");
 
   // If EntryBB is the exit block of the region that includes Prev, exclude
@@ -117,7 +119,7 @@ polly::executeScopConditionally(Scop &S, Value *RTC, DominatorTree &DT,
   BasicBlock *ExitBB = S.getExit();
   assert(ExitingBB && "Must be a simple region");
   BasicBlock *MergeBlock =
-      splitEdge(ExitingBB, ExitBB, ".merge_new_and_old", &DT, &LI, &RI);
+      splitEdge(ExitingBB, ExitBB, ".merge_new_and_old", &DTU, &LI, &RI);
   MergeBlock->setName("polly.merge_new_and_old");
 
   // Exclude the join block from the region.
@@ -197,7 +199,7 @@ polly::executeScopConditionally(Scop &S, Value *RTC, DominatorTree &DT,
   //
 
   // Split the edge between SplitBlock and EntryBB, to avoid a critical edge.
-  splitEdge(SplitBlock, EntryBB, ".pre_entry_bb", &DT, &LI, &RI);
+  splitEdge(SplitBlock, EntryBB, ".pre_entry_bb", &DTU, &LI, &RI);
 
   //      \   /                    //
   //    EnteringBB                 //
diff --git a/polly/lib/Support/ScopHelper.cpp b/polly/lib/Support/ScopHelper.cpp
index 24c7011b06de9..80491a14f582c 100644
--- a/polly/lib/Support/ScopHelper.cpp
+++ b/polly/lib/Support/ScopHelper.cpp
@@ -14,6 +14,7 @@
 #include "polly/Options.h"
 #include "polly/ScopInfo.h"
 #include "polly/Support/SCEVValidator.h"
+#include "llvm/Analysis/DomTreeUpdater.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/RegionInfo.h"
 #include "llvm/Analysis/ScalarEvolution.h"
@@ -38,7 +39,7 @@ static cl::list<std::string> DebugFunctions(
 // Ensures that there is just one predecessor to the entry node from outside the
 // region.
 // The identity of the region entry node is preserved.
-static void simplifyRegionEntry(Region *R, DominatorTree *DT, LoopInfo *LI,
+static void simplifyRegionEntry(Region *R, DomTreeUpdater *DTU, LoopInfo *LI,
                                 RegionInfo *RI) {
   BasicBlock *EnteringBB = R->getEnteringBlock();
   BasicBlock *Entry = R->getEntry();
@@ -61,7 +62,7 @@ static void simplifyRegionEntry(Region *R, DominatorTree *DT, LoopInfo *LI,
         Preds.push_back(P);
 
     BasicBlock *NewEntering =
-        SplitBlockPredecessors(Entry, Preds, ".region_entering", DT, LI);
+        SplitBlockPredecessors(Entry, Preds, ".region_entering", DTU, LI);
 
     if (RI) {
       // The exit block of predecessing regions must be changed to NewEntering
@@ -102,7 +103,7 @@ static void simplifyRegionEntry(Region *R, DominatorTree *DT, LoopInfo *LI,
 }
 
 // Ensure that the region has a single block that branches to the exit node.
-static void simplifyRegionExit(Region *R, DominatorTree *DT, LoopInfo *LI,
+static void simplifyRegionExit(Region *R, DomTreeUpdater *DTU, LoopInfo *LI,
                                RegionInfo *RI) {
   BasicBlock *ExitBB = R->getExit();
   BasicBlock *ExitingBB = R->getExitingBlock();
@@ -125,7 +126,7 @@ static void simplifyRegionExit(Region *R, DominatorTree *DT, LoopInfo *LI,
     //          \ | /                  //
     //           BB                    //
     ExitingBB =
-        SplitBlockPredecessors(ExitBB, Preds, ".region_exiting", DT, LI);
+        SplitBlockPredecessors(ExitBB, Preds, ".region_exiting", DTU, LI);
     // Preds[0] Preds[1]      otherBB  //
     //        \  /           /         //
     // BB.region_exiting    /          //
@@ -157,8 +158,9 @@ void polly::simplifyRegion(Region *R, DominatorTree *DT, LoopInfo *LI,
   assert((!RI || DT) &&
          "RegionInfo requires DominatorTree to be updated as well");
 
-  simplifyRegionEntry(R, DT, LI, RI);
-  simplifyRegionExit(R, DT, LI, RI);
+  DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
+  simplifyRegionEntry(R, &DTU, LI, RI);
+  simplifyRegionExit(R, &DTU, LI, RI);
   assert(R->isSimple());
 }
 



More information about the llvm-commits mailing list