[PATCH] D56135: Allow reverse iterators for `MachineBasicBlock::findDebugLoc` and `MachineBasicBlock::findPrevDebugLoc`

Artyom Goncharov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 6 12:49:40 PST 2019


m4yers updated this revision to Diff 180412.
m4yers marked an inline comment as done.
m4yers added a comment.

Change std::prev to std::next


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56135/new/

https://reviews.llvm.org/D56135

Files:
  include/llvm/CodeGen/MachineBasicBlock.h
  lib/CodeGen/MachineBasicBlock.cpp


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.
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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56135.180412.patch
Type: text/x-patch
Size: 2593 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190106/a134c557/attachment.bin>


More information about the llvm-commits mailing list