[Mlir-commits] [mlir] c487fe3 - [mlir][IR] Fix memory leak in DominanceInfo

Matthias Springer llvmlistbot at llvm.org
Sun Jul 2 23:40:47 PDT 2023


Author: Matthias Springer
Date: 2023-07-03T08:35:54+02:00
New Revision: c487fe3967b57d0c792c5a3ab9bcf2d6b9463eda

URL: https://github.com/llvm/llvm-project/commit/c487fe3967b57d0c792c5a3ab9bcf2d6b9463eda
DIFF: https://github.com/llvm/llvm-project/commit/c487fe3967b57d0c792c5a3ab9bcf2d6b9463eda.diff

LOG: [mlir][IR] Fix memory leak in DominanceInfo

Differential Revision: https://reviews.llvm.org/D154185

Added: 
    

Modified: 
    mlir/include/mlir/IR/Dominance.h
    mlir/lib/IR/Dominance.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/Dominance.h b/mlir/include/mlir/IR/Dominance.h
index 30f5674ad71d9c..82bf34c1910e86 100644
--- a/mlir/include/mlir/IR/Dominance.h
+++ b/mlir/include/mlir/IR/Dominance.h
@@ -46,8 +46,8 @@ class DominanceInfoBase {
 
   /// Invalidate dominance info. This can be used by clients that make major
   /// changes to the CFG and don't have a good way to update it.
-  void invalidate() { dominanceInfos.clear(); }
-  void invalidate(Region *region) { dominanceInfos.erase(region); }
+  void invalidate();
+  void invalidate(Region *region);
 
   /// Finds the nearest common dominator block for the two given blocks a
   /// and b. If no common dominator can be found, this function will return

diff  --git a/mlir/lib/IR/Dominance.cpp b/mlir/lib/IR/Dominance.cpp
index beb7f7bfeedfac..2b138ae223546e 100644
--- a/mlir/lib/IR/Dominance.cpp
+++ b/mlir/lib/IR/Dominance.cpp
@@ -34,6 +34,21 @@ DominanceInfoBase<IsPostDom>::~DominanceInfoBase() {
     delete entry.second.getPointer();
 }
 
+template <bool IsPostDom> void DominanceInfoBase<IsPostDom>::invalidate() {
+  for (auto entry : dominanceInfos)
+    delete entry.second.getPointer();
+  dominanceInfos.clear();
+}
+
+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);
+  }
+}
+
 /// Return the dom tree and "hasSSADominance" bit for the given region.  The
 /// DomTree will be null for single-block regions.  This lazily constructs the
 /// DomTree on demand when needsDomTree=true.


        


More information about the Mlir-commits mailing list