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
NodeT *TheBB;
DomTreeNodeBase<NodeT> *IDom;
std::vector<DomTreeNodeBase<NodeT> *> Children;
NodeT *TheBB;
DomTreeNodeBase<NodeT> *IDom;
std::vector<DomTreeNodeBase<NodeT> *> Children;
- int DFSNumIn, DFSNumOut;
+ mutable int DFSNumIn, DFSNumOut;
template<class N> friend class DominatorTreeBase;
friend struct PostDominatorTree;
template<class N> friend class DominatorTreeBase;
friend struct PostDominatorTree;
DomTreeNodeMapType DomTreeNodes;
DomTreeNodeBase<NodeT> *RootNode;
DomTreeNodeMapType DomTreeNodes;
DomTreeNodeBase<NodeT> *RootNode;
- bool DFSInfoValid;
- unsigned int SlowQueries;
+ mutable bool DFSInfoValid;
+ mutable unsigned int SlowQueries;
// Information record used during immediate dominators computation.
struct InfoRec {
unsigned DFSNum;
// Information record used during immediate dominators computation.
struct InfoRec {
unsigned DFSNum;
/// Note that this is not a constant time operation!
///
bool properlyDominates(const DomTreeNodeBase<NodeT> *A,
/// Note that this is not a constant time operation!
///
bool properlyDominates(const DomTreeNodeBase<NodeT> *A,
- const DomTreeNodeBase<NodeT> *B) {
+ const DomTreeNodeBase<NodeT> *B) const {
if (A == 0 || B == 0)
return false;
if (A == B)
if (A == 0 || B == 0)
return false;
if (A == B)
return dominates(A, B);
}
return dominates(A, B);
}
- bool properlyDominates(const NodeT *A, const NodeT *B);
+ bool properlyDominates(const NodeT *A, const NodeT *B) const;
/// isReachableFromEntry - Return true if A is dominated by the entry
/// block of the function containing it.
/// isReachableFromEntry - Return true if A is dominated by the entry
/// block of the function containing it.
/// constant time operation!
///
inline bool dominates(const DomTreeNodeBase<NodeT> *A,
/// constant time operation!
///
inline bool dominates(const DomTreeNodeBase<NodeT> *A,
- const DomTreeNodeBase<NodeT> *B) {
+ const DomTreeNodeBase<NodeT> *B) const {
// A node trivially dominates itself.
if (B == A)
return true;
// A node trivially dominates itself.
if (B == A)
return true;
return dominatedBySlowTreeWalk(A, B);
}
return dominatedBySlowTreeWalk(A, B);
}
- bool dominates(const NodeT *A, const NodeT *B);
+ bool dominates(const NodeT *A, const NodeT *B) const;
NodeT *getRoot() const {
assert(this->Roots.size() == 1 && "Should always have entry node!");
NodeT *getRoot() const {
assert(this->Roots.size() == 1 && "Should always have entry node!");
/// updateDFSNumbers - Assign In and Out numbers to the nodes while walking
/// dominator tree in dfs order.
/// updateDFSNumbers - Assign In and Out numbers to the nodes while walking
/// dominator tree in dfs order.
- void updateDFSNumbers() {
+ void updateDFSNumbers() const {
- SmallVector<std::pair<DomTreeNodeBase<NodeT>*,
- typename DomTreeNodeBase<NodeT>::iterator>, 32> WorkStack;
+ SmallVector<std::pair<const DomTreeNodeBase<NodeT>*,
+ typename DomTreeNodeBase<NodeT>::const_iterator>, 32> WorkStack;
- DomTreeNodeBase<NodeT> *ThisRoot = getRootNode();
+ const DomTreeNodeBase<NodeT> *ThisRoot = getRootNode();
ThisRoot->DFSNumIn = DFSNum++;
while (!WorkStack.empty()) {
ThisRoot->DFSNumIn = DFSNum++;
while (!WorkStack.empty()) {
- DomTreeNodeBase<NodeT> *Node = WorkStack.back().first;
- typename DomTreeNodeBase<NodeT>::iterator ChildIt =
+ const DomTreeNodeBase<NodeT> *Node = WorkStack.back().first;
+ typename DomTreeNodeBase<NodeT>::const_iterator ChildIt =
WorkStack.back().second;
// If we visited all of the children of this node, "recurse" back up the
WorkStack.back().second;
// If we visited all of the children of this node, "recurse" back up the
WorkStack.pop_back();
} else {
// Otherwise, recursively visit this child.
WorkStack.pop_back();
} else {
// Otherwise, recursively visit this child.
- DomTreeNodeBase<NodeT> *Child = *ChildIt;
+ const DomTreeNodeBase<NodeT> *Child = *ChildIt;
++WorkStack.back().second;
WorkStack.push_back(std::make_pair(Child, Child->begin()));
++WorkStack.back().second;
WorkStack.push_back(std::make_pair(Child, Child->begin()));
// These two functions are declared out of line as a workaround for building
// with old (< r147295) versions of clang because of pr11642.
template<class NodeT>
// These two functions are declared out of line as a workaround for building
// with old (< r147295) versions of clang because of pr11642.
template<class NodeT>
-bool DominatorTreeBase<NodeT>::dominates(const NodeT *A, const NodeT *B) {
+bool DominatorTreeBase<NodeT>::dominates(const NodeT *A, const NodeT *B) const {
}
template<class NodeT>
bool
}
template<class NodeT>
bool
-DominatorTreeBase<NodeT>::properlyDominates(const NodeT *A, const NodeT *B) {
+DominatorTreeBase<NodeT>::properlyDominates(const NodeT *A, const NodeT *B) const {
if (A == B)
return false;
if (A == B)
return false;