diff --git a/mlir/include/mlir/IR/Dominance.h b/mlir/include/mlir/IR/Dominance.h --- a/mlir/include/mlir/IR/Dominance.h +++ b/mlir/include/mlir/IR/Dominance.h @@ -46,8 +46,8 @@ /// 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 --- a/mlir/lib/IR/Dominance.cpp +++ b/mlir/lib/IR/Dominance.cpp @@ -34,6 +34,21 @@ delete entry.second.getPointer(); } +template void DominanceInfoBase::invalidate() { + for (auto entry : dominanceInfos) + delete entry.second.getPointer(); + dominanceInfos.clear(); +} + +template +void DominanceInfoBase::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.