Index: include/llvm/Support/GenericDomTree.h =================================================================== --- include/llvm/Support/GenericDomTree.h +++ include/llvm/Support/GenericDomTree.h @@ -228,7 +228,6 @@ /// assignable and destroyable state, but otherwise invalid. void wipe() { DomTreeNodes.clear(); - IDoms.clear(); RootNode = nullptr; } @@ -241,11 +240,8 @@ mutable bool DFSInfoValid = false; mutable unsigned int SlowQueries = 0; - DenseMap IDoms; - void reset() { DomTreeNodes.clear(); - IDoms.clear(); this->Roots.clear(); RootNode = nullptr; DFSInfoValid = false; @@ -320,8 +316,7 @@ DomTreeNodes(std::move(Arg.DomTreeNodes)), RootNode(std::move(Arg.RootNode)), DFSInfoValid(std::move(Arg.DFSInfoValid)), - SlowQueries(std::move(Arg.SlowQueries)), - IDoms(std::move(Arg.IDoms)) { + SlowQueries(std::move(Arg.SlowQueries)) { Arg.wipe(); } @@ -332,7 +327,6 @@ RootNode = std::move(RHS.RootNode); DFSInfoValid = std::move(RHS.DFSInfoValid); SlowQueries = std::move(RHS.SlowQueries); - IDoms = std::move(RHS.IDoms); RHS.wipe(); return *this; } @@ -662,10 +656,18 @@ unsigned Parent = 0; unsigned Semi = 0; NodePtr Label = nullptr; + NodePtr IDom = nullptr; }; std::vector NumToNode; DenseMap NodeToInfo; + + NodeT *getIDom(NodeT *BB) const { + auto InfoIt = NodeToInfo.find(BB); + if (InfoIt == NodeToInfo.end()) return nullptr; + + return InfoIt->second.IDom; + } }; template @@ -690,16 +692,17 @@ friend void Calculate(DominatorTreeBaseByGraphTraits> &DT, FuncT &F); - DomTreeNodeBase *getNodeForBlock(NodeT *BB) { + DomTreeNodeBase *getNodeForBlock(NodeT *BB, + const SemiNCAInfo& SNCAInfo) { if (DomTreeNodeBase *Node = getNode(BB)) return Node; // Haven't calculated this node yet? Get or calculate the node for the // immediate dominator. - NodeT *IDom = getIDom(BB); + NodeT *IDom = SNCAInfo.getIDom(BB); assert(IDom || DomTreeNodes[nullptr]); - DomTreeNodeBase *IDomNode = getNodeForBlock(IDom); + DomTreeNodeBase *IDomNode = getNodeForBlock(IDom, SNCAInfo); // Add a new tree node for this NodeT, and link it as a child of // IDomNode @@ -707,8 +710,6 @@ llvm::make_unique>(BB, IDomNode))).get(); } - NodeT *getIDom(NodeT *BB) const { return IDoms.lookup(BB); } - void addRoot(NodeT *BB) { this->Roots.push_back(BB); } public: Index: include/llvm/Support/GenericDomTreeConstruction.h =================================================================== --- include/llvm/Support/GenericDomTreeConstruction.h +++ include/llvm/Support/GenericDomTreeConstruction.h @@ -186,7 +186,8 @@ // Initialize IDoms to spanning tree parents. for (unsigned i = 1; i <= N; ++i) { const NodePtr V = SNCA.NumToNode[i]; - DT.IDoms[V] = SNCA.NumToNode[SNCA.NodeToInfo[V].Parent]; + auto &VInfo = SNCA.NodeToInfo[V]; + VInfo.IDom = SNCA.NumToNode[VInfo.Parent]; } // Step #2: Calculate the semidominators of all vertices. @@ -211,13 +212,13 @@ // path compression in Eval. for (unsigned i = 2; i <= N; ++i) { const NodePtr W = SNCA.NumToNode[i]; - const auto &WInfo = SNCA.NodeToInfo[W]; + auto &WInfo = SNCA.NodeToInfo[W]; const unsigned SDomNum = SNCA.NodeToInfo[SNCA.NumToNode[WInfo.Semi]].DFSNum; - NodePtr WIDomCandidate = DT.IDoms[W]; + NodePtr WIDomCandidate = WInfo.IDom; while (SNCA.NodeToInfo[WIDomCandidate].DFSNum > SDomNum) - WIDomCandidate = DT.IDoms[WIDomCandidate]; + WIDomCandidate = SNCA.NodeToInfo[WIDomCandidate].IDom; - DT.IDoms[W] = WIDomCandidate; + WInfo.IDom = WIDomCandidate; } if (DT.Roots.empty()) return; @@ -241,12 +242,12 @@ if (DT.DomTreeNodes[W]) continue; // Haven't calculated this node yet? - NodePtr ImmDom = DT.getIDom(W); + NodePtr ImmDom = SNCA.getIDom(W); assert(ImmDom || DT.DomTreeNodes[nullptr]); // Get or calculate the node for the immediate dominator - DomTreeNodeBase *IDomNode = DT.getNodeForBlock(ImmDom); + DomTreeNodeBase *IDomNode = DT.getNodeForBlock(ImmDom, SNCA); // Add a new tree node for this BasicBlock, and link it as a child of // IDomNode @@ -254,9 +255,6 @@ llvm::make_unique>(W, IDomNode)); } - // Free temporary memory used to construct idom's - DT.IDoms.clear(); - DT.updateDFSNumbers(); } }