diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h --- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h +++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h @@ -1061,6 +1061,35 @@ return It; } +/// Increment \p It, then continue incrementing it while it points to a debug +/// instruction. A replacement for std::next. +template inline IterT next_nodbg(IterT It, IterT End) { + return skipDebugInstructionsForward(std::next(It), End); +} + +/// Decrement \p It, then continue decrementing it while it points to a debug +/// instruction. A replacement for std::prev. +template inline IterT prev_nodbg(IterT It, IterT Begin) { + return skipDebugInstructionsBackward(std::prev(It), Begin); +} + +/// Construct a range iterator which begins at \p It and moves forwards until +/// \p End is reached, skipping any debug instructions. +template +inline auto instructionsWithoutDebug(IterT It, IterT End) { + return make_filter_range(make_range(It, End), [](const MachineInstr &MI) { + return !MI.isDebugInstr(); + }); +} + +/// Construct a range iterator which begins at \p It and moves backwards until +/// \p Begin is reached, skipping any debug instructions. +template +inline auto reversedInstructionsWithoutDebug(IterT It, IterT Begin) { + return instructionsWithoutDebug(make_reverse_iterator(It), + make_reverse_iterator(Begin)); +} + } // end namespace llvm #endif // LLVM_CODEGEN_MACHINEBASICBLOCK_H