diff --git a/llvm/include/llvm/IR/BasicBlock.h b/llvm/include/llvm/IR/BasicBlock.h index 2ee17ce8f483e..c9169cb601809 100644 --- a/llvm/include/llvm/IR/BasicBlock.h +++ b/llvm/include/llvm/IR/BasicBlock.h @@ -287,10 +287,7 @@ class BasicBlock final : public Value, // Basic blocks are data objects also const Instruction *getFirstNonPHI() const; LLVM_DEPRECATED("Use iterators as instruction positions instead", "getFirstNonPHIIt") - Instruction *getFirstNonPHI() { - return const_cast( - static_cast(this)->getFirstNonPHI()); - } + Instruction *getFirstNonPHI(); /// Returns an iterator to the first instruction in this block that is not a /// PHINode instruction. diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp index 8eaa6e522f826..dca42a57fa9e3 100644 --- a/llvm/lib/IR/BasicBlock.cpp +++ b/llvm/lib/IR/BasicBlock.cpp @@ -371,6 +371,13 @@ const Instruction* BasicBlock::getFirstNonPHI() const { return nullptr; } +Instruction *BasicBlock::getFirstNonPHI() { + for (Instruction &I : *this) + if (!isa(I)) + return &I; + return nullptr; +} + BasicBlock::const_iterator BasicBlock::getFirstNonPHIIt() const { for (const Instruction &I : *this) { if (isa(I))