From f931f143cb4e76872bb50393480830ec96df05b1 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sun, 22 Jan 2017 06:53:04 +0000 Subject: [PATCH] [IR] Use const_cast to reuse the const version of two BasicBlock methods that are duplicated for both const and non-const. NFC Similar is already done for other methods in BasicBlock. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292753 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/BasicBlock.h | 8 ++++++-- lib/IR/BasicBlock.cpp | 9 --------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/include/llvm/IR/BasicBlock.h b/include/llvm/IR/BasicBlock.h index 93dbd573ee1..ae40e710e1e 100644 --- a/include/llvm/IR/BasicBlock.h +++ b/include/llvm/IR/BasicBlock.h @@ -104,13 +104,17 @@ public: /// or nullptr it the function does not have a module. /// /// Note: this is undefined behavior if the block does not have a parent. - const Module *getModule() const; Module *getModule(); + const Module *getModule() const { + return const_cast(this)->getModule(); + } /// \brief Returns the terminator instruction if the block is well formed or /// null if the block is not well formed. TerminatorInst *getTerminator(); - const TerminatorInst *getTerminator() const; + const TerminatorInst *getTerminator() const { + return const_cast(this)->getTerminator(); + } /// \brief Returns the call instruction calling @llvm.experimental.deoptimize /// prior to the terminating return instruction of this basic block, if such a diff --git a/lib/IR/BasicBlock.cpp b/lib/IR/BasicBlock.cpp index 19e78492365..8187ee93f17 100644 --- a/lib/IR/BasicBlock.cpp +++ b/lib/IR/BasicBlock.cpp @@ -113,10 +113,6 @@ void BasicBlock::moveAfter(BasicBlock *MovePos) { getIterator()); } -const Module *BasicBlock::getModule() const { - return getParent()->getParent(); -} - Module *BasicBlock::getModule() { return getParent()->getParent(); } @@ -126,11 +122,6 @@ TerminatorInst *BasicBlock::getTerminator() { return dyn_cast(&InstList.back()); } -const TerminatorInst *BasicBlock::getTerminator() const { - if (InstList.empty()) return nullptr; - return dyn_cast(&InstList.back()); -} - CallInst *BasicBlock::getTerminatingMustTailCall() { if (InstList.empty()) return nullptr; -- 2.40.0