Index: llvm/trunk/include/llvm/Support/GenericDomTree.h =================================================================== --- llvm/trunk/include/llvm/Support/GenericDomTree.h +++ llvm/trunk/include/llvm/Support/GenericDomTree.h @@ -229,7 +229,6 @@ void wipe() { DomTreeNodes.clear(); IDoms.clear(); - Vertex.clear(); Info.clear(); RootNode = nullptr; } @@ -254,9 +253,6 @@ DenseMap IDoms; - // Vertex - Map the DFS number to the NodeT* - std::vector Vertex; - // Info - Collection of information used during the computation of idoms. DenseMap Info; @@ -264,7 +260,6 @@ DomTreeNodes.clear(); IDoms.clear(); this->Roots.clear(); - Vertex.clear(); RootNode = nullptr; DFSInfoValid = false; SlowQueries = 0; @@ -338,8 +333,9 @@ 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)), - Vertex(std::move(Arg.Vertex)), Info(std::move(Arg.Info)) { + SlowQueries(std::move(Arg.SlowQueries)), + IDoms(std::move(Arg.IDoms)), + Info(std::move(Arg.Info)) { Arg.wipe(); } @@ -351,7 +347,6 @@ DFSInfoValid = std::move(RHS.DFSInfoValid); SlowQueries = std::move(RHS.SlowQueries); IDoms = std::move(RHS.IDoms); - Vertex = std::move(RHS.Vertex); Info = std::move(RHS.Info); RHS.wipe(); return *this; @@ -675,21 +670,25 @@ protected: template - friend typename GraphT::NodeRef - Eval(DominatorTreeBaseByGraphTraits &DT, typename GraphT::NodeRef V, - unsigned LastLinked); + friend typename GraphT::NodeRef Eval( + DominatorTreeBaseByGraphTraits &DT, typename GraphT::NodeRef V, + const std::vector &NumToNode, + unsigned LastLinked); template - friend unsigned ReverseDFSPass(DominatorTreeBaseByGraphTraits &DT, - typename GraphT::NodeRef V, unsigned N); + friend unsigned ReverseDFSPass( + DominatorTreeBaseByGraphTraits &DT, typename GraphT::NodeRef V, + std::vector &NumToNode, unsigned N); template friend unsigned DFSPass(DominatorTreeBaseByGraphTraits &DT, - typename GraphT::NodeRef V, unsigned N); + typename GraphT::NodeRef V, + std::vector &NumToNode, + unsigned N); template friend void Calculate(DominatorTreeBaseByGraphTraits> &DT, - FuncT &F); + FuncT &F); DomTreeNodeBase *getNodeForBlock(NodeT *BB) { if (DomTreeNodeBase *Node = getNode(BB)) @@ -767,7 +766,6 @@ template void recalculate(FT &F) { using TraitsTy = GraphTraits; reset(); - Vertex.push_back(nullptr); if (!this->IsPostDominators) { // Initialize root Index: llvm/trunk/include/llvm/Support/GenericDomTreeConstruction.h =================================================================== --- llvm/trunk/include/llvm/Support/GenericDomTreeConstruction.h +++ llvm/trunk/include/llvm/Support/GenericDomTreeConstruction.h @@ -51,7 +51,9 @@ template unsigned ReverseDFSPass(DominatorTreeBaseByGraphTraits &DT, - typename GraphT::NodeRef V, unsigned N) { + typename GraphT::NodeRef V, + std::vector &NumToNode, + unsigned N) { df_iterator_dom_storage< typename GraphT::NodeRef, typename DominatorTreeBaseByGraphTraits::InfoRec> @@ -67,7 +69,7 @@ // and is 1 based, so we subtract to account for both of these. if (I.getPathLength() > 1) BBInfo.Parent = DT.Info[I.getPath(I.getPathLength() - 2)].DFSNum; - DT.Vertex.push_back(BB); // Vertex[n] = V; + NumToNode.push_back(BB); // NumToNode[n] = V; if (IsChildOfArtificialExit) BBInfo.Parent = 1; @@ -78,7 +80,8 @@ } template unsigned DFSPass(DominatorTreeBaseByGraphTraits &DT, - typename GraphT::NodeRef V, unsigned N) { + typename GraphT::NodeRef V, + std::vector &NumToNode, unsigned N) { df_iterator_dom_storage< typename GraphT::NodeRef, typename DominatorTreeBaseByGraphTraits::InfoRec> @@ -93,15 +96,16 @@ // and is 1 based, so we subtract to account for both of these. if (I.getPathLength() > 1) BBInfo.Parent = DT.Info[I.getPath(I.getPathLength() - 2)].DFSNum; - DT.Vertex.push_back(BB); // Vertex[n] = V; + NumToNode.push_back(BB); // NumToNode[n] = V; } return N; } template -typename GraphT::NodeRef Eval(DominatorTreeBaseByGraphTraits &DT, - typename GraphT::NodeRef VIn, - unsigned LastLinked) { +typename GraphT::NodeRef Eval( + DominatorTreeBaseByGraphTraits &DT, typename GraphT::NodeRef VIn, + const std::vector &NumToNode, + unsigned LastLinked) { using NodePtr = typename GraphT::NodeRef; auto &VInInfo = DT.Info[VIn]; @@ -117,7 +121,7 @@ while (!Work.empty()) { NodePtr V = Work.back(); auto &VInfo = DT.Info[V]; - NodePtr VAncestor = DT.Vertex[VInfo.Parent]; + NodePtr VAncestor = NumToNode[VInfo.Parent]; // Process Ancestor first if (Visited.insert(VAncestor).second && VInfo.Parent >= LastLinked) { @@ -151,13 +155,15 @@ using NodeType = typename std::remove_pointer::type; unsigned N = 0; + std::vector NumToNode = {nullptr}; + bool MultipleRoots = (DT.Roots.size() > 1); if (MultipleRoots) { auto &BBInfo = DT.Info[nullptr]; BBInfo.DFSNum = BBInfo.Semi = ++N; BBInfo.Label = nullptr; - DT.Vertex.push_back(nullptr); // Vertex[n] = V; + NumToNode.push_back(nullptr); // NumToNode[n] = V; } // Step #1: Number blocks in depth-first order and initialize variables used @@ -165,9 +171,9 @@ if (DT.isPostDominator()){ for (unsigned i = 0, e = static_cast(DT.Roots.size()); i != e; ++i) - N = ReverseDFSPass(DT, DT.Roots[i], N); + N = ReverseDFSPass(DT, DT.Roots[i], NumToNode, N); } else { - N = DFSPass(DT, DT.Roots[0], N); + N = DFSPass(DT, DT.Roots[0], NumToNode, N); } // It might be that some blocks did not get a DFS number (e.g., blocks of @@ -176,20 +182,20 @@ // Initialize IDoms to spanning tree parents. for (unsigned i = 1; i <= N; ++i) { - const NodePtr V = DT.Vertex[i]; - DT.IDoms[V] = DT.Vertex[DT.Info[V].Parent]; + const NodePtr V = NumToNode[i]; + DT.IDoms[V] = NumToNode[DT.Info[V].Parent]; } // Step #2: Calculate the semidominators of all vertices. for (unsigned i = N; i >= 2; --i) { - NodePtr W = DT.Vertex[i]; + NodePtr W = NumToNode[i]; auto &WInfo = DT.Info[W]; // Initialize the semi dominator to point to the parent node. WInfo.Semi = WInfo.Parent; for (const auto &N : inverse_children(W)) if (DT.Info.count(N)) { // Only if this predecessor is reachable! - unsigned SemiU = DT.Info[Eval(DT, N, i + 1)].Semi; + unsigned SemiU = DT.Info[Eval(DT, N, NumToNode, i + 1)].Semi; if (SemiU < WInfo.Semi) WInfo.Semi = SemiU; } @@ -201,9 +207,9 @@ // Note that the parents were stored in IDoms and later got invalidated during // path compression in Eval. for (unsigned i = 2; i <= N; ++i) { - const NodePtr W = DT.Vertex[i]; + const NodePtr W = NumToNode[i]; const auto &WInfo = DT.Info[W]; - const unsigned SDomNum = DT.Info[DT.Vertex[WInfo.Semi]].DFSNum; + const unsigned SDomNum = DT.Info[NumToNode[WInfo.Semi]].DFSNum; NodePtr WIDomCandidate = DT.IDoms[W]; while (DT.Info[WIDomCandidate].DFSNum > SDomNum) WIDomCandidate = DT.IDoms[WIDomCandidate]; @@ -226,7 +232,7 @@ // Loop over all of the reachable blocks in the function... for (unsigned i = 2; i <= N; ++i) { - NodePtr W = DT.Vertex[i]; + NodePtr W = NumToNode[i]; // Don't replace this with 'count', the insertion side effect is important if (DT.DomTreeNodes[W]) @@ -248,8 +254,6 @@ // Free temporary memory used to construct idom's DT.IDoms.clear(); DT.Info.clear(); - DT.Vertex.clear(); - DT.Vertex.shrink_to_fit(); DT.updateDFSNumbers(); }