]> granicus.if.org Git - llvm/commitdiff
[IR] Share implementation for pairs of const and non-const methods using const_cast...
authorCraig Topper <craig.topper@gmail.com>
Mon, 27 Mar 2017 05:46:58 +0000 (05:46 +0000)
committerCraig Topper <craig.topper@gmail.com>
Mon, 27 Mar 2017 05:46:58 +0000 (05:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298830 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/BasicBlock.h
include/llvm/IR/Instruction.h
lib/IR/BasicBlock.cpp
lib/IR/Instruction.cpp

index c8464c1509fb45efe4d41a884f71c473de73727f..bd210e1abf31dd476c3b85d3a67a415424df9555 100644 (file)
@@ -337,8 +337,11 @@ public:
   bool isLandingPad() const;
 
   /// \brief Return the landingpad instruction associated with the landing pad.
-  LandingPadInst *getLandingPadInst();
   const LandingPadInst *getLandingPadInst() const;
+  LandingPadInst *getLandingPadInst() {
+    return const_cast<LandingPadInst *>(
+                    static_cast<const BasicBlock *>(this)->getLandingPadInst());
+  }
 
 private:
   /// \brief Increment the internal refcount of the number of BlockAddresses
index b0bb81e9de156fc9ea1bfe9e836e74a8c9bbd42c..c256b53e00a2a93fff24c5157b4d0982c2c151dd 100644 (file)
@@ -68,14 +68,20 @@ public:
   /// Note: this is undefined behavior if the instruction does not have a
   /// parent, or the parent basic block does not have a parent function.
   const Module *getModule() const;
-  Module *getModule();
+  Module *getModule() {
+    return const_cast<Module *>(
+                           static_cast<const Instruction *>(this)->getModule());
+  }
 
   /// Return the function this instruction belongs to.
   ///
   /// Note: it is undefined behavior to call this on an instruction not
   /// currently inserted into a function.
   const Function *getFunction() const;
-  Function *getFunction();
+  Function *getFunction() {
+    return const_cast<Function *>(
+                         static_cast<const Instruction *>(this)->getFunction());
+  }
 
   /// This method unlinks 'this' from the containing basic block, but does not
   /// delete it.
index 9047fb0cb7a0f1725a7e116846a34880d64344fc..90ca21ab91f8fcfcaf3ae1e8f0a8ea509dcb91da 100644 (file)
@@ -429,9 +429,6 @@ bool BasicBlock::isLandingPad() const {
 }
 
 /// Return the landingpad instruction associated with the landing pad.
-LandingPadInst *BasicBlock::getLandingPadInst() {
-  return dyn_cast<LandingPadInst>(getFirstNonPHI());
-}
 const LandingPadInst *BasicBlock::getLandingPadInst() const {
   return dyn_cast<LandingPadInst>(getFirstNonPHI());
 }
index 8674342a88ae2d96f8c26a9ea1a5b21dee64a2dd..d2114dc24af7ab43defdca88a9bc47566f4d9d4d 100644 (file)
@@ -60,12 +60,6 @@ const Module *Instruction::getModule() const {
   return getParent()->getModule();
 }
 
-Module *Instruction::getModule() {
-  return getParent()->getModule();
-}
-
-Function *Instruction::getFunction() { return getParent()->getParent(); }
-
 const Function *Instruction::getFunction() const {
   return getParent()->getParent();
 }