diff --git a/llvm/include/llvm/IR/DebugProgramInstruction.h b/llvm/include/llvm/IR/DebugProgramInstruction.h index 737417fb9b9a5..0524a657bce4b 100644 --- a/llvm/include/llvm/IR/DebugProgramInstruction.h +++ b/llvm/include/llvm/IR/DebugProgramInstruction.h @@ -453,6 +453,17 @@ inline raw_ostream &operator<<(raw_ostream &OS, const DPValue &Value) { return OS; } +/// Inline helper to return a range of DPValues attached to a marker. It needs +/// to be inlined as it's frequently called, but also come after the declaration +/// of DPMarker. Thus: it's pre-declared by users like Instruction, then an +/// inlineable body defined here. +inline iterator_range::iterator> +getDbgValueRange(DPMarker *DbgMarker) { + if (!DbgMarker) + return DPMarker::getEmptyDPValueRange(); + return DbgMarker->getDbgValueRange(); +} + } // namespace llvm #endif // LLVM_IR_DEBUGPROGRAMINSTRUCTION_H diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h index fcd2ba838e7fd..a785a43a0f11a 100644 --- a/llvm/include/llvm/IR/Instruction.h +++ b/llvm/include/llvm/IR/Instruction.h @@ -40,6 +40,8 @@ template <> struct ilist_alloc_traits { static inline void deleteNode(Instruction *V); }; +iterator_range::iterator> getDbgValueRange(DPMarker *); + class Instruction : public User, public ilist_node_with_parent> { @@ -76,7 +78,9 @@ class Instruction : public User, bool InsertAtHead = false); /// Return a range over the DPValues attached to this instruction. - iterator_range::iterator> getDbgValueRange() const; + iterator_range::iterator> getDbgValueRange() const { + return llvm::getDbgValueRange(DbgMarker); + } /// Return an iterator to the position of the "Next" DPValue after this /// instruction, or std::nullopt. This is the position to pass to diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp index d7bf1447921fe..f9a38e48166c9 100644 --- a/llvm/lib/IR/Instruction.cpp +++ b/llvm/lib/IR/Instruction.cpp @@ -243,18 +243,6 @@ Instruction::cloneDebugInfoFrom(const Instruction *From, return DbgMarker->cloneDebugInfoFrom(From->DbgMarker, FromHere, InsertAtHead); } -iterator_range -Instruction::getDbgValueRange() const { - BasicBlock *Parent = const_cast(getParent()); - assert(Parent && "Instruction must be inserted to have DPValues"); - (void)Parent; - - if (!DbgMarker) - return DPMarker::getEmptyDPValueRange(); - - return DbgMarker->getDbgValueRange(); -} - std::optional Instruction::getDbgReinsertionPosition() { // Is there a marker on the next instruction? DPMarker *NextMarker = getParent()->getNextMarker(this);