From 4f2f5a394ae8aafc89bfcdb6185b784d8fb5f5da Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 27 Mar 2017 05:46:58 +0000 Subject: [PATCH] [IR] Share implementation for pairs of const and non-const methods using const_cast. NFCI git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298830 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/BasicBlock.h | 5 ++++- include/llvm/IR/Instruction.h | 10 ++++++++-- lib/IR/BasicBlock.cpp | 3 --- lib/IR/Instruction.cpp | 6 ------ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/llvm/IR/BasicBlock.h b/include/llvm/IR/BasicBlock.h index c8464c1509f..bd210e1abf3 100644 --- a/include/llvm/IR/BasicBlock.h +++ b/include/llvm/IR/BasicBlock.h @@ -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( + static_cast(this)->getLandingPadInst()); + } private: /// \brief Increment the internal refcount of the number of BlockAddresses diff --git a/include/llvm/IR/Instruction.h b/include/llvm/IR/Instruction.h index b0bb81e9de1..c256b53e00a 100644 --- a/include/llvm/IR/Instruction.h +++ b/include/llvm/IR/Instruction.h @@ -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( + static_cast(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( + static_cast(this)->getFunction()); + } /// This method unlinks 'this' from the containing basic block, but does not /// delete it. diff --git a/lib/IR/BasicBlock.cpp b/lib/IR/BasicBlock.cpp index 9047fb0cb7a..90ca21ab91f 100644 --- a/lib/IR/BasicBlock.cpp +++ b/lib/IR/BasicBlock.cpp @@ -429,9 +429,6 @@ bool BasicBlock::isLandingPad() const { } /// Return the landingpad instruction associated with the landing pad. -LandingPadInst *BasicBlock::getLandingPadInst() { - return dyn_cast(getFirstNonPHI()); -} const LandingPadInst *BasicBlock::getLandingPadInst() const { return dyn_cast(getFirstNonPHI()); } diff --git a/lib/IR/Instruction.cpp b/lib/IR/Instruction.cpp index 8674342a88a..d2114dc24af 100644 --- a/lib/IR/Instruction.cpp +++ b/lib/IR/Instruction.cpp @@ -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(); } -- 2.40.0