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

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 4 02:56:28 PDT 2024


================
@@ -333,35 +336,80 @@ 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())
+    size_t NumNodes = 0;
+    for (const auto &Node : DomTreeNodes) {
+      if (!Node)
+        continue;
+      if (Node->compare(Other.getNode(Node->getBlock())))
+        return true;
+      NumNodes++;
+    }
+
+    size_t NumOtherNodes = 0;
+    for (const auto &OtherNode : Other.DomTreeNodes)
+      if (OtherNode)
+        NumOtherNodes++;
+    if (NumNodes != NumOtherNodes)
       return true;
 
-    for (const auto &DomTreeNode : DomTreeNodes) {
-      NodeT *BB = DomTreeNode.first;
-      typename DomTreeNodeMapType::const_iterator OI =
-          OtherDomTreeNodes.find(BB);
-      if (OI == OtherDomTreeNodes.end())
-        return true;
+    return false;
+  }
 
-      DomTreeNodeBase<NodeT> &MyNd = *DomTreeNode.second;
-      DomTreeNodeBase<NodeT> &OtherNd = *OI->second;
+private:
+  template <typename T>
+  using has_number_t =
+      decltype(GraphTraits<T *>::getNumber(std::declval<T *>()));
+
+  template <class T_ = NodeT>
+  std::enable_if_t<is_detected<has_number_t, T_>::value,
+                   std::optional<unsigned>>
----------------
aengelke wrote:

Good point, changed.

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


More information about the llvm-commits mailing list