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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 2 11:32:01 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;
----------------
nikic wrote:

`return NumNodes != NumOtherNodes;`

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


More information about the llvm-commits mailing list