Index: include/llvm/CodeGen/MachineBasicBlock.h =================================================================== --- include/llvm/CodeGen/MachineBasicBlock.h +++ include/llvm/CodeGen/MachineBasicBlock.h @@ -729,6 +729,10 @@ DebugLoc findDebugLoc(iterator MBBI) { return findDebugLoc(MBBI.getInstrIterator()); } + DebugLoc findDebugLoc(reverse_instr_iterator MBBI); + DebugLoc findDebugLoc(reverse_iterator MBBI) { + return findDebugLoc(MBBI.getInstrIterator()); + } /// Find the previous valid DebugLoc preceding MBBI, skipping and DBG_VALUE /// instructions. Return UnknownLoc if there is none. @@ -736,6 +740,10 @@ DebugLoc findPrevDebugLoc(iterator MBBI) { return findPrevDebugLoc(MBBI.getInstrIterator()); } + DebugLoc findPrevDebugLoc(reverse_instr_iterator MBBI); + DebugLoc findPrevDebugLoc(reverse_iterator MBBI) { + return findPrevDebugLoc(MBBI.getInstrIterator()); + } /// Find and return the merged DebugLoc of the branch instructions of the /// block. Return UnknownLoc if there is none. Index: lib/CodeGen/MachineBasicBlock.cpp =================================================================== --- lib/CodeGen/MachineBasicBlock.cpp +++ lib/CodeGen/MachineBasicBlock.cpp @@ -1277,7 +1277,7 @@ } /// Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE -/// instructions. Return UnknownLoc if there is none. +/// instructions. Return UnknownLoc if there is none. DebugLoc MachineBasicBlock::findDebugLoc(instr_iterator MBBI) { // Skip debug declarations, we don't want a DebugLoc from them. @@ -1286,6 +1286,14 @@ return MBBI->getDebugLoc(); return {}; } +DebugLoc +MachineBasicBlock::findDebugLoc(reverse_instr_iterator MBBI) { + // Skip debug declarations, we don't want a DebugLoc from them. + MBBI = skipDebugInstructionsBackward(MBBI, instr_rbegin()); + if (!MBBI->isDebugInstr()) return MBBI->getDebugLoc(); + + return {}; +} /// Find the previous valid DebugLoc preceding MBBI, skipping and DBG_VALUE /// instructions. Return UnknownLoc if there is none. @@ -1296,6 +1304,14 @@ if (!MBBI->isDebugInstr()) return MBBI->getDebugLoc(); return {}; } +DebugLoc MachineBasicBlock::findPrevDebugLoc(reverse_instr_iterator MBBI) { + // Skip debug declarations, we don't want a DebugLoc from them. + MBBI = skipDebugInstructionsForward(std::next(MBBI), instr_rend()); + if (MBBI != instr_rend()) + return MBBI->getDebugLoc(); + + return {}; +} /// Find and return the merged DebugLoc of the branch instructions of the block. /// Return UnknownLoc if there is none.