[mlir][IR] Fix memory leak in DominanceInfo

Differential Revision: https://reviews.llvm.org/D154185
This commit is contained in:
Matthias Springer 2023-07-03 08:35:20 +02:00
parent e4d6860d2d
commit c487fe3967
2 changed files with 17 additions and 2 deletions

View File

@ -46,8 +46,8 @@ public:
/// 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

View File

@ -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.