Skip to content

Commit 1c78f4a

Browse files
committed
[IR] Share implementation for pairs of const and non-const methods using const_cast. NFCI
llvm-svn: 298830
1 parent 70c8efd commit 1c78f4a

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

llvm/include/llvm/IR/BasicBlock.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,11 @@ class BasicBlock : public Value, // Basic blocks are data objects also
337337
bool isLandingPad() const;
338338

339339
/// \brief Return the landingpad instruction associated with the landing pad.
340-
LandingPadInst *getLandingPadInst();
341340
const LandingPadInst *getLandingPadInst() const;
341+
LandingPadInst *getLandingPadInst() {
342+
return const_cast<LandingPadInst *>(
343+
static_cast<const BasicBlock *>(this)->getLandingPadInst());
344+
}
342345

343346
private:
344347
/// \brief Increment the internal refcount of the number of BlockAddresses

llvm/include/llvm/IR/Instruction.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,20 @@ class Instruction : public User,
6868
/// Note: this is undefined behavior if the instruction does not have a
6969
/// parent, or the parent basic block does not have a parent function.
7070
const Module *getModule() const;
71-
Module *getModule();
71+
Module *getModule() {
72+
return const_cast<Module *>(
73+
static_cast<const Instruction *>(this)->getModule());
74+
}
7275

7376
/// Return the function this instruction belongs to.
7477
///
7578
/// Note: it is undefined behavior to call this on an instruction not
7679
/// currently inserted into a function.
7780
const Function *getFunction() const;
78-
Function *getFunction();
81+
Function *getFunction() {
82+
return const_cast<Function *>(
83+
static_cast<const Instruction *>(this)->getFunction());
84+
}
7985

8086
/// This method unlinks 'this' from the containing basic block, but does not
8187
/// delete it.

llvm/lib/IR/BasicBlock.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,6 @@ bool BasicBlock::isLandingPad() const {
429429
}
430430

431431
/// Return the landingpad instruction associated with the landing pad.
432-
LandingPadInst *BasicBlock::getLandingPadInst() {
433-
return dyn_cast<LandingPadInst>(getFirstNonPHI());
434-
}
435432
const LandingPadInst *BasicBlock::getLandingPadInst() const {
436433
return dyn_cast<LandingPadInst>(getFirstNonPHI());
437434
}

llvm/lib/IR/Instruction.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ const Module *Instruction::getModule() const {
6060
return getParent()->getModule();
6161
}
6262

63-
Module *Instruction::getModule() {
64-
return getParent()->getModule();
65-
}
66-
67-
Function *Instruction::getFunction() { return getParent()->getParent(); }
68-
6963
const Function *Instruction::getFunction() const {
7064
return getParent()->getParent();
7165
}

0 commit comments

Comments
 (0)