summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2017-03-27 05:46:58 +0000
committerCraig Topper <craig.topper@gmail.com>2017-03-27 05:46:58 +0000
commit1c78f4a0ff6811e9c3d8fe4a827358b9c01dab61 (patch)
treee4bf2f09027d73c0dfdb84fad3e4d6a5b2ded4ca
parent70c8efd03cb5ca69a75983839930ec90bbf51b04 (diff)
downloadbcm5719-llvm-1c78f4a0ff6811e9c3d8fe4a827358b9c01dab61.tar.gz
bcm5719-llvm-1c78f4a0ff6811e9c3d8fe4a827358b9c01dab61.zip
[IR] Share implementation for pairs of const and non-const methods using const_cast. NFCI
llvm-svn: 298830
-rw-r--r--llvm/include/llvm/IR/BasicBlock.h5
-rw-r--r--llvm/include/llvm/IR/Instruction.h10
-rw-r--r--llvm/lib/IR/BasicBlock.cpp3
-rw-r--r--llvm/lib/IR/Instruction.cpp6
4 files changed, 12 insertions, 12 deletions
diff --git a/llvm/include/llvm/IR/BasicBlock.h b/llvm/include/llvm/IR/BasicBlock.h
index c8464c1509f..bd210e1abf3 100644
--- a/llvm/include/llvm/IR/BasicBlock.h
+++ b/llvm/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<LandingPadInst *>(
+ static_cast<const BasicBlock *>(this)->getLandingPadInst());
+ }
private:
/// \brief Increment the internal refcount of the number of BlockAddresses
diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index b0bb81e9de1..c256b53e00a 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/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<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.
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 9047fb0cb7a..90ca21ab91f 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/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<LandingPadInst>(getFirstNonPHI());
-}
const LandingPadInst *BasicBlock::getLandingPadInst() const {
return dyn_cast<LandingPadInst>(getFirstNonPHI());
}
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index 8674342a88a..d2114dc24af 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/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();
}
OpenPOWER on IntegriCloud