[codegen] Add generic functions to skip debug values.
Summary:
This commits moves skipDebugInstructionsForward and
skipDebugInstructionsBackward from lib/CodeGen/IfConversion.cpp
to include/llvm/CodeGen/MachineBasicBlock.h and updates
some codgen files to use them.
This refactoring was suggested in https://reviews.llvm.org/D27688
and I thought it's best to do the refactoring in a separate
review, but I could also put both changes in a single review
if that's preferred.
Also, the names for the functions aren't the snappiest and
I would be happy to rename them if anybody has suggestions.
Reviewers: eli.friedman, iteratee, aprantl, MatzeB
Subscribers: MatzeB, llvm-commits
Differential Revision: https://reviews.llvm.org/D27782
llvm-svn: 289933
diff --git a/llvm/lib/CodeGen/IfConversion.cpp b/llvm/lib/CodeGen/IfConversion.cpp
index 56a25e0..0cac7b7 100644
--- a/llvm/lib/CodeGen/IfConversion.cpp
+++ b/llvm/lib/CodeGen/IfConversion.cpp
@@ -588,18 +588,6 @@
return TExit && TExit == FalseBBI.BB;
}
-/// Increment \p It until it points to a non-debug instruction or to \p End.
-/// @param It Iterator to increment
-/// @param End Iterator that points to end. Will be compared to It
-/// @returns true if It == End, false otherwise.
-static inline bool skipDebugInstructionsForward(
- MachineBasicBlock::iterator &It,
- MachineBasicBlock::iterator &End) {
- while (It != End && It->isDebugValue())
- It++;
- return It == End;
-}
-
/// Shrink the provided inclusive range by one instruction.
/// If the range was one instruction (\p It == \p Begin), It is not modified,
/// but \p Empty is set to true.
@@ -613,21 +601,6 @@
It--;
}
-/// Decrement \p It until it points to a non-debug instruction or the range is
-/// empty.
-/// @param It Iterator to decrement.
-/// @param Begin Iterator that points to beginning. Will be compared to It
-/// @param Empty Set to true if the resulting range is Empty
-/// @returns the value of Empty as a convenience.
-static inline bool skipDebugInstructionsBackward(
- MachineBasicBlock::iterator &Begin,
- MachineBasicBlock::iterator &It,
- bool &Empty) {
- while (!Empty && It->isDebugValue())
- shrinkInclusiveRange(Begin, It, Empty);
- return Empty;
-}
-
/// Count duplicated instructions and move the iterators to show where they
/// are.
/// @param TIB True Iterator Begin
@@ -659,9 +632,11 @@
while (TIB != TIE && FIB != FIE) {
// Skip dbg_value instructions. These do not count.
- if(skipDebugInstructionsForward(TIB, TIE))
+ TIB = skipDebugInstructionsForward(TIB, TIE);
+ if(TIB == TIE)
break;
- if(skipDebugInstructionsForward(FIB, FIE))
+ FIB = skipDebugInstructionsForward(FIB, FIE);
+ if(FIB == FIE)
break;
if (!TIB->isIdenticalTo(*FIB))
break;
@@ -718,9 +693,11 @@
// Count duplicate instructions at the ends of the blocks.
while (!TEmpty && !FEmpty) {
// Skip dbg_value instructions. These do not count.
- if (skipDebugInstructionsBackward(TIB, TIE, TEmpty))
- break;
- if (skipDebugInstructionsBackward(FIB, FIE, FEmpty))
+ TIE = skipDebugInstructionsBackward(TIE, TIB);
+ FIE = skipDebugInstructionsBackward(FIE, FIB);
+ TEmpty = TIE == TIB && TIE->isDebugValue();
+ FEmpty = FIE == FIB && FIE->isDebugValue();
+ if (TEmpty || FEmpty)
break;
if (!TIE->isIdenticalTo(*FIE))
break;
@@ -770,8 +747,11 @@
MachineBasicBlock::iterator E2 = std::prev(MBB2->end());
bool Empty1 = false, Empty2 = false;
while (!Empty1 && !Empty2) {
- skipDebugInstructionsBackward(B1, E1, Empty1);
- skipDebugInstructionsBackward(B2, E2, Empty2);
+ E1 = skipDebugInstructionsBackward(E1, B1);
+ E2 = skipDebugInstructionsBackward(E2, B2);
+ Empty1 = E1 == B1 && E1->isDebugValue();
+ Empty2 = E2 == B2 && E2->isDebugValue();
+
if (Empty1 && Empty2)
break;