llvm.org GIT mirror llvm / ed0b9ad
[PM] Fix the const-correctness of the generic DominatorTreeBase to support notionally const queries even though they may trigger DFS numbering updates. The updating of DFS numbers and tracking of slow queries do not mutate the observable state of the domtree. They should be const to differentiate them from the APIs which mutate the tree directly to do incremental updates. This will make it possible in a world where the DominatorTree is not a pass but merely the result of running a pass to derive DominatorTree from the base class as it was originally designed, removing a huge duplication of API in DominatorTree. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199101 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 6 years ago
1 changed file(s) with 17 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
6464 NodeT *TheBB;
6565 DomTreeNodeBase *IDom;
6666 std::vector *> Children;
67 int DFSNumIn, DFSNumOut;
67 mutable int DFSNumIn, DFSNumOut;
6868
6969 template friend class DominatorTreeBase;
7070 friend struct PostDominatorTree;
196196 DomTreeNodeMapType DomTreeNodes;
197197 DomTreeNodeBase *RootNode;
198198
199 bool DFSInfoValid;
200 unsigned int SlowQueries;
199 mutable bool DFSInfoValid;
200 mutable unsigned int SlowQueries;
201201 // Information record used during immediate dominators computation.
202202 struct InfoRec {
203203 unsigned DFSNum;
360360 /// Note that this is not a constant time operation!
361361 ///
362362 bool properlyDominates(const DomTreeNodeBase *A,
363 const DomTreeNodeBase *B) {
363 const DomTreeNodeBase *B) const {
364364 if (A == 0 || B == 0)
365365 return false;
366366 if (A == B)
368368 return dominates(A, B);
369369 }
370370
371 bool properlyDominates(const NodeT *A, const NodeT *B);
371 bool properlyDominates(const NodeT *A, const NodeT *B) const;
372372
373373 /// isReachableFromEntry - Return true if A is dominated by the entry
374374 /// block of the function containing it.
386386 /// constant time operation!
387387 ///
388388 inline bool dominates(const DomTreeNodeBase *A,
389 const DomTreeNodeBase *B) {
389 const DomTreeNodeBase *B) const {
390390 // A node trivially dominates itself.
391391 if (B == A)
392392 return true;
421421 return dominatedBySlowTreeWalk(A, B);
422422 }
423423
424 bool dominates(const NodeT *A, const NodeT *B);
424 bool dominates(const NodeT *A, const NodeT *B) const;
425425
426426 NodeT *getRoot() const {
427427 assert(this->Roots.size() == 1 && "Should always have entry node!");
586586
587587 /// updateDFSNumbers - Assign In and Out numbers to the nodes while walking
588588 /// dominator tree in dfs order.
589 void updateDFSNumbers() {
589 void updateDFSNumbers() const {
590590 unsigned DFSNum = 0;
591591
592 SmallVector*,
593 typename DomTreeNodeBase::iterator>, 32> WorkStack;
594
595 DomTreeNodeBase *ThisRoot = getRootNode();
592 SmallVector*,
593 typename DomTreeNodeBase::const_iterator>, 32> WorkStack;
594
595 const DomTreeNodeBase *ThisRoot = getRootNode();
596596
597597 if (!ThisRoot)
598598 return;
605605 ThisRoot->DFSNumIn = DFSNum++;
606606
607607 while (!WorkStack.empty()) {
608 DomTreeNodeBase *Node = WorkStack.back().first;
609 typename DomTreeNodeBase::iterator ChildIt =
608 const DomTreeNodeBase *Node = WorkStack.back().first;
609 typename DomTreeNodeBase::const_iterator ChildIt =
610610 WorkStack.back().second;
611611
612612 // If we visited all of the children of this node, "recurse" back up the
616616 WorkStack.pop_back();
617617 } else {
618618 // Otherwise, recursively visit this child.
619 DomTreeNodeBase *Child = *ChildIt;
619 const DomTreeNodeBase *Child = *ChildIt;
620620 ++WorkStack.back().second;
621621
622622 WorkStack.push_back(std::make_pair(Child, Child->begin()));
689689 // These two functions are declared out of line as a workaround for building
690690 // with old (< r147295) versions of clang because of pr11642.
691691 template
692 bool DominatorTreeBase::dominates(const NodeT *A, const NodeT *B) {
692 bool DominatorTreeBase::dominates(const NodeT *A, const NodeT *B) const {
693693 if (A == B)
694694 return true;
695695
701701 }
702702 template
703703 bool
704 DominatorTreeBase::properlyDominates(const NodeT *A, const NodeT *B) {
704 DominatorTreeBase::properlyDominates(const NodeT *A, const NodeT *B) const {
705705 if (A == B)
706706 return false;
707707