[PATCH] D41299: [PDT] Fix splitBlock for Post Dom Trees

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 15 09:30:41 PST 2017


dmgreen created this revision.

The previous function presumed that the PDT split
would be the split of the DT split, which isn't the
case due to the way split takes some preds from the
old block.

      

This uses the applyUpdates interface to add/remove
the correct edges.


https://reviews.llvm.org/D41299

Files:
  include/llvm/Support/GenericDomTree.h


Index: include/llvm/Support/GenericDomTree.h
===================================================================
--- include/llvm/Support/GenericDomTree.h
+++ include/llvm/Support/GenericDomTree.h
@@ -666,10 +666,30 @@
   /// splitBlock - BB is split and now it has one successor. Update dominator
   /// tree to reflect this change.
   void splitBlock(NodeT *NewBB) {
-    if (IsPostDominator)
-      Split<Inverse<NodeT *>>(NewBB);
-    else
+    if (!IsPostDominator)
       Split<NodeT *>(NewBB);
+    else {
+      // FIXME: Split(NewBB) only works for dominator trees. For post-dominator
+      // trees we just uses applyUpdates and so is potentially less efficient
+      // than it could be.
+      using GraphT = GraphTraits<NodeT *>;
+      assert(std::distance(GraphT::child_begin(NewBB),
+                           GraphT::child_end(NewBB)) == 1 &&
+             "NewBB should have a single successor!");
+      NodeT *OldBB = *GraphT::child_begin(NewBB);
+
+      std::vector<UpdateType> Updates;
+      SmallPtrSet<NodeT *, 4> Visited;
+      for (auto *Pred : children<Inverse<NodeT *>>(NewBB)) {
+        if (!Visited.insert(Pred).second)
+          // Make sure our updates and balanced, even if Pred is a child
+          // multiple times
+          continue;
+        Updates.emplace_back(UpdateKind::Insert, Pred, NewBB);
+        Updates.emplace_back(UpdateKind::Delete, Pred, OldBB);
+      }
+      applyUpdates(Updates);
+    }
   }
 
   /// print - Convert to human readable form


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41299.127149.patch
Type: text/x-patch
Size: 1508 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171215/07adcc07/attachment.bin>


More information about the llvm-commits mailing list