[mips] Define helper function searchRange

No functionality change.

llvm-svn: 176318
This commit is contained in:
Akira Hatanaka 2013-03-01 00:26:14 +00:00
parent 99e76c0e98
commit a433f695dd

View File

@ -129,6 +129,12 @@ namespace {
bool delayHasHazard(const MachineInstr &Candidate, RegDefsUses &RegDU, bool delayHasHazard(const MachineInstr &Candidate, RegDefsUses &RegDU,
MemDefsUses &MemDU) const; 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<typename IterTy>
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 searchBackward(MachineBasicBlock &MBB, Iter Slot, Iter &Filler) const;
bool terminateSearch(const MachineInstr &Candidate) const; bool terminateSearch(const MachineInstr &Candidate) const;
@ -312,14 +318,11 @@ FunctionPass *llvm::createMipsDelaySlotFillerPass(MipsTargetMachine &tm) {
return new Filler(tm); return new Filler(tm);
} }
bool Filler::searchBackward(MachineBasicBlock &MBB, Iter Slot, template<typename IterTy>
Iter &Filler) const { bool Filler::searchRange(MachineBasicBlock &MBB, IterTy Begin, IterTy End,
RegDefsUses RegDU(TM); RegDefsUses &RegDU, MemDefsUses &MemDU,
MemDefsUses MemDU(MBB.getParent()->getFrameInfo()); IterTy &Filler) const {
for (IterTy I = Begin; I != End; ++I) {
RegDU.init(*Slot);
for (ReverseIter I(Slot); I != MBB.rend(); ++I) {
// skip debug value // skip debug value
if (I->isDebugValue()) if (I->isDebugValue())
continue; continue;
@ -333,7 +336,24 @@ bool Filler::searchBackward(MachineBasicBlock &MBB, Iter Slot,
if (delayHasHazard(*I, RegDU, MemDU)) if (delayHasHazard(*I, RegDU, MemDU))
continue; 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; return true;
} }