llvm.org GIT mirror llvm / 52cfa7b
[Dominators] Move IDoms out of DominatorTreeBase and put them in SNCAInfo Summary: The temporary IDoms map was used only during DomTree calculation. We can move it to SNCAInfo so that it's no longer a DominatorTreeBase member. Reviewers: sanjoy, dberlin, chandlerc Reviewed By: dberlin Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D34317 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306574 91177308-0d34-0410-b5e6-96231b3b80d8 Jakub Kuderski 3 years ago
2 changed file(s) with 22 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
227227 /// assignable and destroyable state, but otherwise invalid.
228228 void wipe() {
229229 DomTreeNodes.clear();
230 IDoms.clear();
231230 RootNode = nullptr;
232231 }
233232
240239 mutable bool DFSInfoValid = false;
241240 mutable unsigned int SlowQueries = 0;
242241
243 DenseMap IDoms;
244
245242 void reset() {
246243 DomTreeNodes.clear();
247 IDoms.clear();
248244 this->Roots.clear();
249245 RootNode = nullptr;
250246 DFSInfoValid = false;
319315 DomTreeNodes(std::move(Arg.DomTreeNodes)),
320316 RootNode(std::move(Arg.RootNode)),
321317 DFSInfoValid(std::move(Arg.DFSInfoValid)),
322 SlowQueries(std::move(Arg.SlowQueries)),
323 IDoms(std::move(Arg.IDoms)) {
318 SlowQueries(std::move(Arg.SlowQueries)) {
324319 Arg.wipe();
325320 }
326321
331326 RootNode = std::move(RHS.RootNode);
332327 DFSInfoValid = std::move(RHS.DFSInfoValid);
333328 SlowQueries = std::move(RHS.SlowQueries);
334 IDoms = std::move(RHS.IDoms);
335329 RHS.wipe();
336330 return *this;
337331 }
661655 unsigned Parent = 0;
662656 unsigned Semi = 0;
663657 NodePtr Label = nullptr;
658 NodePtr IDom = nullptr;
664659 };
665660
666661 std::vector NumToNode;
667662 DenseMap NodeToInfo;
663
664 NodeT *getIDom(NodeT *BB) const {
665 auto InfoIt = NodeToInfo.find(BB);
666 if (InfoIt == NodeToInfo.end()) return nullptr;
667
668 return InfoIt->second.IDom;
669 }
668670 };
669671
670672 template
689691 friend void Calculate(DominatorTreeBaseByGraphTraits> &DT,
690692 FuncT &F);
691693
692 DomTreeNodeBase *getNodeForBlock(NodeT *BB) {
694 DomTreeNodeBase *getNodeForBlock(NodeT *BB,
695 const SemiNCAInfo& SNCAInfo) {
693696 if (DomTreeNodeBase *Node = getNode(BB))
694697 return Node;
695698
696699 // Haven't calculated this node yet? Get or calculate the node for the
697700 // immediate dominator.
698 NodeT *IDom = getIDom(BB);
701 NodeT *IDom = SNCAInfo.getIDom(BB);
699702
700703 assert(IDom || DomTreeNodes[nullptr]);
701 DomTreeNodeBase *IDomNode = getNodeForBlock(IDom);
704 DomTreeNodeBase *IDomNode = getNodeForBlock(IDom, SNCAInfo);
702705
703706 // Add a new tree node for this NodeT, and link it as a child of
704707 // IDomNode
705708 return (DomTreeNodes[BB] = IDomNode->addChild(
706709 llvm::make_unique>(BB, IDomNode))).get();
707710 }
708
709 NodeT *getIDom(NodeT *BB) const { return IDoms.lookup(BB); }
710711
711712 void addRoot(NodeT *BB) { this->Roots.push_back(BB); }
712713
185185 // Initialize IDoms to spanning tree parents.
186186 for (unsigned i = 1; i <= N; ++i) {
187187 const NodePtr V = SNCA.NumToNode[i];
188 DT.IDoms[V] = SNCA.NumToNode[SNCA.NodeToInfo[V].Parent];
188 auto &VInfo = SNCA.NodeToInfo[V];
189 VInfo.IDom = SNCA.NumToNode[VInfo.Parent];
189190 }
190191
191192 // Step #2: Calculate the semidominators of all vertices.
210211 // path compression in Eval.
211212 for (unsigned i = 2; i <= N; ++i) {
212213 const NodePtr W = SNCA.NumToNode[i];
213 const auto &WInfo = SNCA.NodeToInfo[W];
214 auto &WInfo = SNCA.NodeToInfo[W];
214215 const unsigned SDomNum = SNCA.NodeToInfo[SNCA.NumToNode[WInfo.Semi]].DFSNum;
215 NodePtr WIDomCandidate = DT.IDoms[W];
216 NodePtr WIDomCandidate = WInfo.IDom;
216217 while (SNCA.NodeToInfo[WIDomCandidate].DFSNum > SDomNum)
217 WIDomCandidate = DT.IDoms[WIDomCandidate];
218
219 DT.IDoms[W] = WIDomCandidate;
218 WIDomCandidate = SNCA.NodeToInfo[WIDomCandidate].IDom;
219
220 WInfo.IDom = WIDomCandidate;
220221 }
221222
222223 if (DT.Roots.empty()) return;
240241 if (DT.DomTreeNodes[W])
241242 continue; // Haven't calculated this node yet?
242243
243 NodePtr ImmDom = DT.getIDom(W);
244 NodePtr ImmDom = SNCA.getIDom(W);
244245
245246 assert(ImmDom || DT.DomTreeNodes[nullptr]);
246247
247248 // Get or calculate the node for the immediate dominator
248 DomTreeNodeBase *IDomNode = DT.getNodeForBlock(ImmDom);
249 DomTreeNodeBase *IDomNode = DT.getNodeForBlock(ImmDom, SNCA);
249250
250251 // Add a new tree node for this BasicBlock, and link it as a child of
251252 // IDomNode
253254 llvm::make_unique>(W, IDomNode));
254255 }
255256
256 // Free temporary memory used to construct idom's
257 DT.IDoms.clear();
258
259257 DT.updateDFSNumbers();
260258 }
261259 }