Skip to content

Commit 0cc4b95

Browse files
committed
Add debug output to MipsDelaySlotFiller pass
Summary: I was tracking down a code-generation bug in this pass and found that the added output was useful. It is also helpful to find out why a delay slot could not be filled even though there is clearly a valid instruction (which appears to mostly be caused by CFI instructions). Reviewers: atanasyan Reviewed By: atanasyan Subscribers: merge_guards_bot, sdardis, hiraditya, jrtc27, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70940
1 parent ba71e84 commit 0cc4b95

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -612,12 +612,18 @@ bool MipsDelaySlotFiller::runOnMachineBasicBlock(MachineBasicBlock &MBB) {
612612
if (MipsCompactBranchPolicy.getValue() != CB_Always ||
613613
!TII->getEquivalentCompactForm(I)) {
614614
if (searchBackward(MBB, *I)) {
615+
LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot"
616+
" in backwards search.\n");
615617
Filled = true;
616618
} else if (I->isTerminator()) {
617619
if (searchSuccBBs(MBB, I)) {
618620
Filled = true;
621+
LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot"
622+
" in successor BB search.\n");
619623
}
620624
} else if (searchForward(MBB, I)) {
625+
LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot"
626+
" in forwards search.\n");
621627
Filled = true;
622628
}
623629
}
@@ -662,6 +668,8 @@ bool MipsDelaySlotFiller::runOnMachineBasicBlock(MachineBasicBlock &MBB) {
662668
}
663669

664670
// Bundle the NOP to the instruction with the delay slot.
671+
LLVM_DEBUG(dbgs() << DEBUG_TYPE << ": could not fill delay slot for ";
672+
I->dump());
665673
BuildMI(MBB, std::next(I), I->getDebugLoc(), TII->get(Mips::NOP));
666674
MIBundleBuilder(MBB, I, std::next(I, 2));
667675
++FilledSlots;
@@ -679,13 +687,19 @@ bool MipsDelaySlotFiller::searchRange(MachineBasicBlock &MBB, IterTy Begin,
679687
for (IterTy I = Begin; I != End;) {
680688
IterTy CurrI = I;
681689
++I;
682-
690+
LLVM_DEBUG(dbgs() << DEBUG_TYPE ": checking instruction: "; CurrI->dump());
683691
// skip debug value
684-
if (CurrI->isDebugInstr())
692+
if (CurrI->isDebugInstr()) {
693+
LLVM_DEBUG(dbgs() << DEBUG_TYPE ": ignoring debug instruction: ";
694+
CurrI->dump());
685695
continue;
696+
}
686697

687-
if (terminateSearch(*CurrI))
698+
if (terminateSearch(*CurrI)) {
699+
LLVM_DEBUG(dbgs() << DEBUG_TYPE ": should terminate search: ";
700+
CurrI->dump());
688701
break;
702+
}
689703

690704
assert((!CurrI->isCall() && !CurrI->isReturn() && !CurrI->isBranch()) &&
691705
"Cannot put calls, returns or branches in delay slot.");
@@ -731,6 +745,9 @@ bool MipsDelaySlotFiller::searchRange(MachineBasicBlock &MBB, IterTy Begin,
731745
continue;
732746

733747
Filler = CurrI;
748+
LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot: ";
749+
CurrI->dump());
750+
734751
return true;
735752
}
736753

@@ -751,8 +768,11 @@ bool MipsDelaySlotFiller::searchBackward(MachineBasicBlock &MBB,
751768

752769
MachineBasicBlock::iterator SlotI = Slot;
753770
if (!searchRange(MBB, ++SlotI.getReverse(), MBB.rend(), RegDU, MemDU, Slot,
754-
Filler))
771+
Filler)) {
772+
LLVM_DEBUG(dbgs() << DEBUG_TYPE ": could not find instruction for delay "
773+
"slot using backwards search.\n");
755774
return false;
775+
}
756776

757777
MBB.splice(std::next(SlotI), &MBB, Filler.getReverse());
758778
MIBundleBuilder(MBB, SlotI, std::next(SlotI, 2));
@@ -772,8 +792,11 @@ bool MipsDelaySlotFiller::searchForward(MachineBasicBlock &MBB,
772792

773793
RegDU.setCallerSaved(*Slot);
774794

775-
if (!searchRange(MBB, std::next(Slot), MBB.end(), RegDU, NM, Slot, Filler))
795+
if (!searchRange(MBB, std::next(Slot), MBB.end(), RegDU, NM, Slot, Filler)) {
796+
LLVM_DEBUG(dbgs() << DEBUG_TYPE ": could not find instruction for delay "
797+
"slot using forwards search.\n");
776798
return false;
799+
}
777800

778801
MBB.splice(std::next(Slot), &MBB, Filler);
779802
MIBundleBuilder(MBB, Slot, std::next(Slot, 2));

0 commit comments

Comments
 (0)