[llvm] [Support] Store dominator tree nodes in a vector (PR #101705)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 4 06:07:08 PDT 2024


================
@@ -333,35 +336,71 @@ class DominatorTreeBase {
     if (!std::is_permutation(Roots.begin(), Roots.end(), Other.Roots.begin()))
       return true;
 
-    const DomTreeNodeMapType &OtherDomTreeNodes = Other.DomTreeNodes;
-    if (DomTreeNodes.size() != OtherDomTreeNodes.size())
-      return true;
-
-    for (const auto &DomTreeNode : DomTreeNodes) {
-      NodeT *BB = DomTreeNode.first;
-      typename DomTreeNodeMapType::const_iterator OI =
-          OtherDomTreeNodes.find(BB);
-      if (OI == OtherDomTreeNodes.end())
+    size_t NumNodes = 0;
+    // All node we have must exist and be equal in the other tree
+    for (const auto &Node : DomTreeNodes) {
+      if (!Node)
+        continue;
+      if (Node->compare(Other.getNode(Node->getBlock())))
         return true;
+      NumNodes++;
+    }
 
-      DomTreeNodeBase<NodeT> &MyNd = *DomTreeNode.second;
-      DomTreeNodeBase<NodeT> &OtherNd = *OI->second;
+    // If we the other tree has more nodes than we have, they're not equal
+    size_t NumOtherNodes = 0;
+    for (const auto &OtherNode : Other.DomTreeNodes)
+      if (OtherNode)
+        NumOtherNodes++;
+    return NumNodes != NumOtherNodes;
+  }
 
-      if (MyNd.compare(&OtherNd))
-        return true;
+private:
+  template <typename T>
+  using has_number_t =
+      decltype(GraphTraits<T *>::getNumber(std::declval<T *>()));
+
+  template <class T_ = NodeT>
----------------
nikic wrote:

I don't think the dummy template is needed anymore?

https://github.com/llvm/llvm-project/pull/101705


More information about the llvm-commits mailing list