Skip to content

Commit

Permalink
[Dominators] Change getNode parameter type to const NodeT * (NFC).
Browse files Browse the repository at this point in the history
DominatorTreeBase::getNode does not modify its parameter and this change
allows callers that only have access to const pointers to use it without
casting.

Reviewers: kuhar, dblaikie, chandlerc

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D48231

llvm-svn: 334892
  • Loading branch information
fhahn committed Jun 16, 2018
1 parent e7f7038 commit 6fbad90
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions llvm/include/llvm/Support/GenericDomTree.h
Expand Up @@ -351,15 +351,17 @@ class DominatorTreeBase {
/// block. This is the same as using operator[] on this class. The result
/// may (but is not required to) be null for a forward (backwards)
/// statically unreachable block.
DomTreeNodeBase<NodeT> *getNode(NodeT *BB) const {
DomTreeNodeBase<NodeT> *getNode(const NodeT *BB) const {
auto I = DomTreeNodes.find(BB);
if (I != DomTreeNodes.end())
return I->second.get();
return nullptr;
}

/// See getNode.
DomTreeNodeBase<NodeT> *operator[](NodeT *BB) const { return getNode(BB); }
DomTreeNodeBase<NodeT> *operator[](const NodeT *BB) const {
return getNode(BB);
}

/// getRootNode - This returns the entry node for the CFG of the function. If
/// this tree represents the post-dominance relations for a function, however,
Expand Down
4 changes: 3 additions & 1 deletion llvm/unittests/IR/DominatorTreeTest.cpp
Expand Up @@ -776,7 +776,9 @@ TEST(DominatorTree, InsertFromUnreachable) {
PDT.insertEdge(From, To);
EXPECT_TRUE(PDT.verify());
EXPECT_TRUE(PDT.getRoots().size() == 2);
EXPECT_NE(PDT.getNode(B.getOrAddBlock("5")), nullptr);
// Make sure we can use a const pointer with getNode.
const BasicBlock *BB5 = B.getOrAddBlock("5");
EXPECT_NE(PDT.getNode(BB5), nullptr);
}

TEST(DominatorTree, InsertMixed) {
Expand Down

0 comments on commit 6fbad90

Please sign in to comment.