From 1f7330b16239f50daee57dbf53b20fbacd028ee4 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Fri, 1 Mar 2013 00:26:14 +0000 Subject: [PATCH] [mips] Define helper function searchRange No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@176318 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/Mips/MipsDelaySlotFiller.cpp | 38 +++++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/lib/Target/Mips/MipsDelaySlotFiller.cpp b/lib/Target/Mips/MipsDelaySlotFiller.cpp index 2762e2542dc..0d6b00915f5 100644 --- a/lib/Target/Mips/MipsDelaySlotFiller.cpp +++ b/lib/Target/Mips/MipsDelaySlotFiller.cpp @@ -129,6 +129,12 @@ namespace { bool delayHasHazard(const MachineInstr &Candidate, RegDefsUses &RegDU, MemDefsUses &MemDU) const; + /// This function searches range [Begin, End) for an instruction that can be + /// moved to the delay slot. Returns true on success. + template + bool searchRange(MachineBasicBlock &MBB, IterTy Begin, IterTy End, + RegDefsUses &RegDU, MemDefsUses &MemDU, IterTy &Filler) const; + bool searchBackward(MachineBasicBlock &MBB, Iter Slot, Iter &Filler) const; bool terminateSearch(const MachineInstr &Candidate) const; @@ -312,14 +318,11 @@ FunctionPass *llvm::createMipsDelaySlotFillerPass(MipsTargetMachine &tm) { return new Filler(tm); } -bool Filler::searchBackward(MachineBasicBlock &MBB, Iter Slot, - Iter &Filler) const { - RegDefsUses RegDU(TM); - MemDefsUses MemDU(MBB.getParent()->getFrameInfo()); - - RegDU.init(*Slot); - - for (ReverseIter I(Slot); I != MBB.rend(); ++I) { +template +bool Filler::searchRange(MachineBasicBlock &MBB, IterTy Begin, IterTy End, + RegDefsUses &RegDU, MemDefsUses &MemDU, + IterTy &Filler) const { + for (IterTy I = Begin; I != End; ++I) { // skip debug value if (I->isDebugValue()) continue; @@ -333,7 +336,24 @@ bool Filler::searchBackward(MachineBasicBlock &MBB, Iter Slot, if (delayHasHazard(*I, RegDU, MemDU)) continue; - Filler = llvm::next(I).base(); + Filler = I; + return true; + } + + return false; +} + +bool Filler::searchBackward(MachineBasicBlock &MBB, Iter Slot, + Iter &Filler) const { + RegDefsUses RegDU(TM); + MemDefsUses MemDU(MBB.getParent()->getFrameInfo()); + ReverseIter FillerReverse; + + RegDU.init(*Slot); + + if (searchRange(MBB, ReverseIter(Slot), MBB.rend(), RegDU, MemDU, + FillerReverse)) { + Filler = llvm::next(FillerReverse).base(); return true; }