From 6fbad9040701e84ede8fc33293aa24e2f0ecf34c Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sat, 16 Jun 2018 14:47:05 +0000 Subject: [PATCH] [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 --- llvm/include/llvm/Support/GenericDomTree.h | 6 ++++-- llvm/unittests/IR/DominatorTreeTest.cpp | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/Support/GenericDomTree.h b/llvm/include/llvm/Support/GenericDomTree.h index 5119a65..115abc2 100644 --- a/llvm/include/llvm/Support/GenericDomTree.h +++ b/llvm/include/llvm/Support/GenericDomTree.h @@ -351,7 +351,7 @@ protected: /// 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 *getNode(NodeT *BB) const { + DomTreeNodeBase *getNode(const NodeT *BB) const { auto I = DomTreeNodes.find(BB); if (I != DomTreeNodes.end()) return I->second.get(); @@ -359,7 +359,9 @@ protected: } /// See getNode. - DomTreeNodeBase *operator[](NodeT *BB) const { return getNode(BB); } + DomTreeNodeBase *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, diff --git a/llvm/unittests/IR/DominatorTreeTest.cpp b/llvm/unittests/IR/DominatorTreeTest.cpp index 475b5b2..cf81623 100644 --- a/llvm/unittests/IR/DominatorTreeTest.cpp +++ b/llvm/unittests/IR/DominatorTreeTest.cpp @@ -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) { -- 2.7.4