Fix an error in the MBlaze delay slot filler where instructions that already

fill a delay slot are moved to fill a different delay slot.

llvm-svn: 119949
This commit is contained in:
Wesley Peck 2010-11-21 21:36:12 +00:00
parent fc9aead6fd
commit 7493e30d42
1 changed files with 29 additions and 16 deletions

View File

@ -77,7 +77,6 @@ static bool hasImmInstruction(MachineBasicBlock::iterator &candidate) {
static bool delayHasHazard(MachineBasicBlock::iterator &candidate, static bool delayHasHazard(MachineBasicBlock::iterator &candidate,
MachineBasicBlock::iterator &slot) { MachineBasicBlock::iterator &slot) {
// Loop over all of the operands in the branch instruction // Loop over all of the operands in the branch instruction
// and make sure that none of them are defined by the // and make sure that none of them are defined by the
// candidate instruction. // candidate instruction.
@ -125,20 +124,35 @@ static bool usedBeforeDelaySlot(MachineBasicBlock::iterator &candidate,
return false; return false;
} }
static MachineBasicBlock::iterator static bool isDelayFiller(MachineBasicBlock &MBB,
findDelayInstr(MachineBasicBlock &MBB,MachineBasicBlock::iterator &slot) { MachineBasicBlock::iterator candidate) {
MachineBasicBlock::iterator found = MBB.end(); if (candidate == MBB.begin())
for (MachineBasicBlock::iterator I = MBB.begin(); I != slot; ++I) { return false;
TargetInstrDesc desc = I->getDesc();
if (desc.hasDelaySlot() || desc.isBranch() ||
desc.mayLoad() || desc. mayStore() ||
hasImmInstruction(I) || delayHasHazard(I,slot) ||
usedBeforeDelaySlot(I,slot)) continue;
found = I; TargetInstrDesc brdesc = (--candidate)->getDesc();
return (brdesc.hasDelaySlot());
}
static MachineBasicBlock::iterator
findDelayInstr(MachineBasicBlock &MBB,MachineBasicBlock::iterator slot) {
MachineBasicBlock::iterator I = slot;
while (true) {
if (I == MBB.begin())
break;
--I;
TargetInstrDesc desc = I->getDesc();
if (desc.hasDelaySlot() || desc.isBranch() || isDelayFiller(MBB,I))
break;
if (desc.mayLoad() || desc.mayStore() || hasImmInstruction(I) ||
delayHasHazard(I,slot) || usedBeforeDelaySlot(I,slot))
continue;
return I;
} }
return found; return MBB.end();
} }
/// runOnMachineBasicBlock - Fill in delay slots for the given basic block. /// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
@ -148,17 +162,16 @@ bool Filler::runOnMachineBasicBlock(MachineBasicBlock &MBB) {
bool Changed = false; bool Changed = false;
for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I)
if (I->getDesc().hasDelaySlot()) { if (I->getDesc().hasDelaySlot()) {
MachineBasicBlock::iterator J = I;
MachineBasicBlock::iterator D = findDelayInstr(MBB,I); MachineBasicBlock::iterator D = findDelayInstr(MBB,I);
MachineBasicBlock::iterator J = I;
++J;
++FilledSlots; ++FilledSlots;
Changed = true; Changed = true;
if (D == MBB.end()) if (D == MBB.end())
BuildMI(MBB, J, I->getDebugLoc(), TII->get(MBlaze::NOP)); BuildMI(MBB, ++J, I->getDebugLoc(), TII->get(MBlaze::NOP));
else else
MBB.splice(J, &MBB, D); MBB.splice(++J, &MBB, D);
} }
return Changed; return Changed;
} }