[Mlir-commits] [mlir] [mlir] Add erase sub-region dominate tree logic in DominanceInfoBase::invalidate method (PR #192469)

lonely eagle llvmlistbot at llvm.org
Mon Apr 20 06:00:02 PDT 2026


https://github.com/linuxlonelyeagle updated https://github.com/llvm/llvm-project/pull/192469

>From c0e7e202afecc8bac390ec88b7dc0791bdda3acc Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Thu, 16 Apr 2026 14:39:15 +0000
Subject: [PATCH 1/4] add erase sub region dominate tree logic in
 DominanceInfoBase::invalidate.

---
 mlir/lib/IR/Dominance.cpp | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/mlir/lib/IR/Dominance.cpp b/mlir/lib/IR/Dominance.cpp
index 0e53b431b5d31..f9782a86f07cd 100644
--- a/mlir/lib/IR/Dominance.cpp
+++ b/mlir/lib/IR/Dominance.cpp
@@ -42,10 +42,17 @@ void DominanceInfoBase<IsPostDom>::invalidate() {
 
 template <bool IsPostDom>
 void DominanceInfoBase<IsPostDom>::invalidate(Region *region) {
-  auto it = dominanceInfos.find(region);
-  if (it != dominanceInfos.end()) {
-    delete it->second.getPointer();
-    dominanceInfos.erase(it);
+  SmallVector<Region*> regions = {region};
+  region->walk([&](Operation *op) {
+    for (Region &r : op->getRegions()) 
+      regions.push_back(&r);
+  });
+  for (Region* region : regions) {
+    auto it = dominanceInfos.find(region);
+    if (it != dominanceInfos.end()) {
+      delete it->second.getPointer();
+      dominanceInfos.erase(it);
+    }
   }
 }
 

>From 4e6cdb1b84d9a3faffd46c353e00d27fa95e6ad9 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Thu, 16 Apr 2026 14:47:10 +0000
Subject: [PATCH 2/4] fix clang-format.

---
 mlir/lib/IR/Dominance.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mlir/lib/IR/Dominance.cpp b/mlir/lib/IR/Dominance.cpp
index f9782a86f07cd..2ef0c35a13536 100644
--- a/mlir/lib/IR/Dominance.cpp
+++ b/mlir/lib/IR/Dominance.cpp
@@ -42,12 +42,12 @@ void DominanceInfoBase<IsPostDom>::invalidate() {
 
 template <bool IsPostDom>
 void DominanceInfoBase<IsPostDom>::invalidate(Region *region) {
-  SmallVector<Region*> regions = {region};
+  SmallVector<Region *> regions = {region};
   region->walk([&](Operation *op) {
-    for (Region &r : op->getRegions()) 
+    for (Region &r : op->getRegions())
       regions.push_back(&r);
   });
-  for (Region* region : regions) {
+  for (Region *region : regions) {
     auto it = dominanceInfos.find(region);
     if (it != dominanceInfos.end()) {
       delete it->second.getPointer();

>From 7a770565c430d5f4ace4e026d9b61a63969e1e72 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Fri, 17 Apr 2026 01:48:44 +0000
Subject: [PATCH 3/4] add erase sub region dominate tree logic in
 DominanceInfoBase::invalidate.

---
 mlir/lib/IR/Dominance.cpp | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/mlir/lib/IR/Dominance.cpp b/mlir/lib/IR/Dominance.cpp
index 2ef0c35a13536..f030e6e61b2fd 100644
--- a/mlir/lib/IR/Dominance.cpp
+++ b/mlir/lib/IR/Dominance.cpp
@@ -42,17 +42,23 @@ void DominanceInfoBase<IsPostDom>::invalidate() {
 
 template <bool IsPostDom>
 void DominanceInfoBase<IsPostDom>::invalidate(Region *region) {
-  SmallVector<Region *> regions = {region};
-  region->walk([&](Operation *op) {
-    for (Region &r : op->getRegions())
-      regions.push_back(&r);
-  });
-  for (Region *region : regions) {
-    auto it = dominanceInfos.find(region);
-    if (it != dominanceInfos.end()) {
-      delete it->second.getPointer();
-      dominanceInfos.erase(it);
-    }
+  auto it = dominanceInfos.find(region);
+  if (it != dominanceInfos.end()) {
+    delete it->second.getPointer();
+    dominanceInfos.erase(it);
+  }
+
+  // Invalidate dominator trees of nested sub-regions.
+  if (region) {
+    region->walk([&](Operation *op) {
+      for (Region &region : op->getRegions()) {
+        auto it = dominanceInfos.find(&region);
+        if (it != dominanceInfos.end()) {
+          delete it->second.getPointer();
+          dominanceInfos.erase(it);
+        }
+      }
+    });
   }
 }
 

>From 9f8a43237d1b8f1461d46d245a137c5196a77342 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Mon, 20 Apr 2026 12:59:45 +0000
Subject: [PATCH 4/4] update code.

---
 mlir/lib/IR/Dominance.cpp | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/mlir/lib/IR/Dominance.cpp b/mlir/lib/IR/Dominance.cpp
index f030e6e61b2fd..ed130f4ec7c35 100644
--- a/mlir/lib/IR/Dominance.cpp
+++ b/mlir/lib/IR/Dominance.cpp
@@ -47,19 +47,13 @@ void DominanceInfoBase<IsPostDom>::invalidate(Region *region) {
     delete it->second.getPointer();
     dominanceInfos.erase(it);
   }
-
-  // Invalidate dominator trees of nested sub-regions.
-  if (region) {
-    region->walk([&](Operation *op) {
-      for (Region &region : op->getRegions()) {
-        auto it = dominanceInfos.find(&region);
-        if (it != dominanceInfos.end()) {
-          delete it->second.getPointer();
-          dominanceInfos.erase(it);
-        }
-      }
-    });
-  }
+  region->walk([&](Region *op) {
+    auto it = dominanceInfos.find(region);
+    if (it != dominanceInfos.end()) {
+      delete it->second.getPointer();
+      dominanceInfos.erase(it);
+    }
+  });
 }
 
 /// Return the dom tree and "hasSSADominance" bit for the given region.  The



More information about the Mlir-commits mailing list