[PATCH] D29243: Cache reverse graph edges during dominator construction to avoidhaving to look them up later.

Daniel Berlin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 27 22:37:44 PST 2017


dberlin created this revision.

We already visit every single successor of the graph, so we don't
actually need to find the inverse edges, we can just store what they
are.  This removes the need for inverse traits to compute dominators.

It's also a very slight speedup on large graphs, i'm leaving it here
while I test it on non-x86 platforms.


https://reviews.llvm.org/D29243

Files:
  include/llvm/Support/GenericDomTree.h
  include/llvm/Support/GenericDomTreeConstruction.h


Index: include/llvm/Support/GenericDomTreeConstruction.h
===================================================================
--- include/llvm/Support/GenericDomTreeConstruction.h
+++ include/llvm/Support/GenericDomTreeConstruction.h
@@ -93,6 +93,8 @@
     typename GraphT::NodeRef Succ = *NextSucc;
 
     auto &SuccVInfo = DT.Info[Succ];
+    SuccVInfo.ReverseChildren.push_back(BB);
+
     if (SuccVInfo.Semi == 0) {
       SuccVInfo.Parent = BBDFSNum;
       Worklist.push_back(std::make_pair(Succ, GraphT::child_begin(Succ)));
@@ -201,16 +203,10 @@
 
     // initialize the semi dominator to point to the parent node
     WInfo.Semi = WInfo.Parent;
-    typedef GraphTraits<Inverse<NodeT> > InvTraits;
-    for (typename InvTraits::ChildIteratorType CI =
-         InvTraits::child_begin(W),
-         E = InvTraits::child_end(W); CI != E; ++CI) {
-      typename InvTraits::NodeRef N = *CI;
-      if (DT.Info.count(N)) {  // Only if this predecessor is reachable!
+    for (auto *N : WInfo.ReverseChildren) {
         unsigned SemiU = DT.Info[Eval<GraphT>(DT, N, i + 1)].Semi;
         if (SemiU < WInfo.Semi)
           WInfo.Semi = SemiU;
-      }
     }
 
     // If V is a non-root vertex and sdom(V) = parent(V), then idom(V) is
Index: include/llvm/Support/GenericDomTree.h
===================================================================
--- include/llvm/Support/GenericDomTree.h
+++ include/llvm/Support/GenericDomTree.h
@@ -247,7 +247,7 @@
     unsigned Parent;
     unsigned Semi;
     NodeT *Label;
-
+    SmallVector<NodeT *, 2> ReverseChildren;
     InfoRec() : DFSNum(0), Parent(0), Semi(0), Label(nullptr) {}
   };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29243.86164.patch
Type: text/x-patch
Size: 1640 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170128/49629614/attachment.bin>


More information about the llvm-commits mailing list