From ab34afdff2fb43ef21c5ae2b76c85732fa407b08 Mon Sep 17 00:00:00 2001 From: Ian Wood Date: Sat, 4 Jan 2025 05:54:03 -0800 Subject: [PATCH] [NFC] Use map of maps to erase in constant time Signed-off-by: Ian Wood --- .../include/mlir/Analysis/DataFlowFramework.h | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/mlir/include/mlir/Analysis/DataFlowFramework.h b/mlir/include/mlir/Analysis/DataFlowFramework.h index dfd358e7017a4e..b6d10ba0bea2d8 100644 --- a/mlir/include/mlir/Analysis/DataFlowFramework.h +++ b/mlir/include/mlir/Analysis/DataFlowFramework.h @@ -332,9 +332,11 @@ class DataFlowSolver { /// does not exist. template const StateT *lookupState(AnchorT anchor) const { - auto it = - analysisStates.find({LatticeAnchor(anchor), TypeID::get()}); - if (it == analysisStates.end()) + const auto &mapIt = analysisStates.find(LatticeAnchor(anchor)); + if (mapIt == analysisStates.end()) + return nullptr; + auto it = mapIt->second.find(TypeID::get()); + if (it == mapIt->second.end()) return nullptr; return static_cast(it->second.get()); } @@ -343,11 +345,7 @@ class DataFlowSolver { template void eraseState(AnchorT anchor) { LatticeAnchor la(anchor); - - for (auto it = analysisStates.begin(); it != analysisStates.end(); ++it) { - if (it->first.first == la) - analysisStates.erase(it); - } + analysisStates.erase(LatticeAnchor(anchor)); } // Erase all analysis states @@ -426,7 +424,8 @@ class DataFlowSolver { /// A type-erased map of lattice anchors to associated analysis states for /// first-class lattice anchors. - DenseMap, std::unique_ptr> + DenseMap>, + DenseMapInfo> analysisStates; /// Allow the base child analysis class to access the internals of the solver. @@ -643,7 +642,7 @@ AnalysisT *DataFlowSolver::load(Args &&...args) { template StateT *DataFlowSolver::getOrCreateState(AnchorT anchor) { std::unique_ptr &state = - analysisStates[{LatticeAnchor(anchor), TypeID::get()}]; + analysisStates[LatticeAnchor(anchor)][TypeID::get()]; if (!state) { state = std::unique_ptr(new StateT(anchor)); #if LLVM_ENABLE_ABI_BREAKING_CHECKS @@ -689,10 +688,6 @@ struct DenseMapInfo { } }; -template <> -struct DenseMapInfo - : public DenseMapInfo {}; - // Allow llvm::cast style functions. template struct CastInfo