[llvm] r292753 - [IR] Use const_cast to reuse the const version of two BasicBlock methods that are duplicated for both const and non-const. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 21 22:53:04 PST 2017
Author: ctopper
Date: Sun Jan 22 00:53:04 2017
New Revision: 292753
URL: http://llvm.org/viewvc/llvm-project?rev=292753&view=rev
Log:
[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.
Modified:
llvm/trunk/include/llvm/IR/BasicBlock.h
llvm/trunk/lib/IR/BasicBlock.cpp
Modified: llvm/trunk/include/llvm/IR/BasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/BasicBlock.h?rev=292753&r1=292752&r2=292753&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/BasicBlock.h (original)
+++ llvm/trunk/include/llvm/IR/BasicBlock.h Sun Jan 22 00:53:04 2017
@@ -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<BasicBlock *>(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<BasicBlock *>(this)->getTerminator();
+ }
/// \brief Returns the call instruction calling @llvm.experimental.deoptimize
/// prior to the terminating return instruction of this basic block, if such a
Modified: llvm/trunk/lib/IR/BasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/BasicBlock.cpp?rev=292753&r1=292752&r2=292753&view=diff
==============================================================================
--- llvm/trunk/lib/IR/BasicBlock.cpp (original)
+++ llvm/trunk/lib/IR/BasicBlock.cpp Sun Jan 22 00:53:04 2017
@@ -113,10 +113,6 @@ void BasicBlock::moveAfter(BasicBlock *M
getIterator());
}
-const Module *BasicBlock::getModule() const {
- return getParent()->getParent();
-}
-
Module *BasicBlock::getModule() {
return getParent()->getParent();
}
@@ -125,11 +121,6 @@ TerminatorInst *BasicBlock::getTerminato
if (InstList.empty()) return nullptr;
return dyn_cast<TerminatorInst>(&InstList.back());
}
-
-const TerminatorInst *BasicBlock::getTerminator() const {
- if (InstList.empty()) return nullptr;
- return dyn_cast<TerminatorInst>(&InstList.back());
-}
CallInst *BasicBlock::getTerminatingMustTailCall() {
if (InstList.empty())
More information about the llvm-commits
mailing list