diff options
author | Shuxin Yang <shuxin.llvm@gmail.com> | 2013-09-19 17:18:35 +0000 |
---|---|---|
committer | Shuxin Yang <shuxin.llvm@gmail.com> | 2013-09-19 17:18:35 +0000 |
commit | 4f77a21d6ca2d560a7508fd54581b12dfc01630b (patch) | |
tree | e133ac1cd46b1dd88b83db799ef6621d133d560b /include/llvm/Analysis | |
parent | a22ff961db47ffff4f1e795d810aa102edb9b79b (diff) | |
download | llvm-4f77a21d6ca2d560a7508fd54581b12dfc01630b.tar.gz llvm-4f77a21d6ca2d560a7508fd54581b12dfc01630b.tar.bz2 llvm-4f77a21d6ca2d560a7508fd54581b12dfc01630b.tar.xz |
Add function DominatorTree::getDescendants().
As its name suggests, this function will return all basic blocks
dominated by a given block.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191014 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Analysis')
-rw-r--r-- | include/llvm/Analysis/Dominators.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/include/llvm/Analysis/Dominators.h b/include/llvm/Analysis/Dominators.h index 81c04bb6b0..3aa0beb6bb 100644 --- a/include/llvm/Analysis/Dominators.h +++ b/include/llvm/Analysis/Dominators.h @@ -346,6 +346,20 @@ public: DomTreeNodeBase<NodeT> *getRootNode() { return RootNode; } const DomTreeNodeBase<NodeT> *getRootNode() const { return RootNode; } + /// Get all nodes dominated by R, including R itself. Return true on success. + void getDescendants(NodeT *R, SmallVectorImpl<NodeT *> &Result) const { + const DomTreeNodeBase<NodeT> *RN = getNode(R); + SmallVector<const DomTreeNodeBase<NodeT> *, 8> WL; + WL.push_back(RN); + Result.clear(); + + while (!WL.empty()) { + const DomTreeNodeBase<NodeT> *N = WL.pop_back_val(); + Result.push_back(N->getBlock()); + WL.append(N->begin(), N->end()); + } + } + /// properlyDominates - Returns true iff A dominates B and A != B. /// Note that this is not a constant time operation! /// @@ -755,6 +769,12 @@ public: return DT->getRootNode(); } + /// Get all nodes dominated by R, including R itself. Return true on success. + void getDescendants(BasicBlock *R, + SmallVectorImpl<BasicBlock *> &Result) const { + DT->getDescendants(R, Result); + } + /// compare - Return false if the other dominator tree matches this /// dominator tree. Otherwise return true. inline bool compare(DominatorTree &Other) const { |