Skip to content

Commit 6fbad90

Browse files
committed
[Dominators] Change getNode parameter type to const NodeT * (NFC).
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
1 parent e7f7038 commit 6fbad90

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

llvm/include/llvm/Support/GenericDomTree.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,17 @@ class DominatorTreeBase {
351351
/// block. This is the same as using operator[] on this class. The result
352352
/// may (but is not required to) be null for a forward (backwards)
353353
/// statically unreachable block.
354-
DomTreeNodeBase<NodeT> *getNode(NodeT *BB) const {
354+
DomTreeNodeBase<NodeT> *getNode(const NodeT *BB) const {
355355
auto I = DomTreeNodes.find(BB);
356356
if (I != DomTreeNodes.end())
357357
return I->second.get();
358358
return nullptr;
359359
}
360360

361361
/// See getNode.
362-
DomTreeNodeBase<NodeT> *operator[](NodeT *BB) const { return getNode(BB); }
362+
DomTreeNodeBase<NodeT> *operator[](const NodeT *BB) const {
363+
return getNode(BB);
364+
}
363365

364366
/// getRootNode - This returns the entry node for the CFG of the function. If
365367
/// this tree represents the post-dominance relations for a function, however,

llvm/unittests/IR/DominatorTreeTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,9 @@ TEST(DominatorTree, InsertFromUnreachable) {
776776
PDT.insertEdge(From, To);
777777
EXPECT_TRUE(PDT.verify());
778778
EXPECT_TRUE(PDT.getRoots().size() == 2);
779-
EXPECT_NE(PDT.getNode(B.getOrAddBlock("5")), nullptr);
779+
// Make sure we can use a const pointer with getNode.
780+
const BasicBlock *BB5 = B.getOrAddBlock("5");
781+
EXPECT_NE(PDT.getNode(BB5), nullptr);
780782
}
781783

782784
TEST(DominatorTree, InsertMixed) {

0 commit comments

Comments
 (0)