]> granicus.if.org Git - llvm/commitdiff
[IR] Use const_cast to reuse the const version of two BasicBlock methods that are...
authorCraig Topper <craig.topper@gmail.com>
Sun, 22 Jan 2017 06:53:04 +0000 (06:53 +0000)
committerCraig Topper <craig.topper@gmail.com>
Sun, 22 Jan 2017 06:53:04 +0000 (06:53 +0000)
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
lib/IR/BasicBlock.cpp

index 93dbd573ee16dd9add8657e40c47756c4dff056b..ae40e710e1e161eb5fae09ad9b97e49a3afbd42e 100644 (file)
@@ -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
index 19e784923658392a583ce62d9f6f81f40f87ffec..8187ee93f17fa994acc1a2d7c64b84d51102536f 100644 (file)
@@ -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<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())
     return nullptr;