diff options
Diffstat (limited to 'llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp')
-rw-r--r-- | llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp | 72 |
1 files changed, 55 insertions, 17 deletions
diff --git a/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp b/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp index aa07dac86828..84ff674569cd 100644 --- a/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp +++ b/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp @@ -91,15 +91,14 @@ enum CompactBranchPolicy { }; static cl::opt<CompactBranchPolicy> MipsCompactBranchPolicy( - "mips-compact-branches",cl::Optional, - cl::init(CB_Optimal), - cl::desc("MIPS Specific: Compact branch policy."), - cl::values( - clEnumValN(CB_Never, "never", "Do not use compact branches if possible."), - clEnumValN(CB_Optimal, "optimal", "Use compact branches where appropiate (default)."), - clEnumValN(CB_Always, "always", "Always use compact branches if possible.") - ) -); + "mips-compact-branches", cl::Optional, cl::init(CB_Optimal), + cl::desc("MIPS Specific: Compact branch policy."), + cl::values(clEnumValN(CB_Never, "never", + "Do not use compact branches if possible."), + clEnumValN(CB_Optimal, "optimal", + "Use compact branches where appropiate (default)."), + clEnumValN(CB_Always, "always", + "Always use compact branches if possible."))); namespace { @@ -417,8 +416,14 @@ bool RegDefsUses::update(const MachineInstr &MI, unsigned Begin, unsigned End) { for (unsigned I = Begin; I != End; ++I) { const MachineOperand &MO = MI.getOperand(I); - if (MO.isReg() && MO.getReg()) - HasHazard |= checkRegDefsUses(NewDefs, NewUses, MO.getReg(), MO.isDef()); + if (MO.isReg() && MO.getReg()) { + if (checkRegDefsUses(NewDefs, NewUses, MO.getReg(), MO.isDef())) { + LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found register hazard for operand " + << I << ": "; + MO.dump()); + HasHazard = true; + } + } } Defs |= NewDefs; @@ -613,12 +618,18 @@ bool MipsDelaySlotFiller::runOnMachineBasicBlock(MachineBasicBlock &MBB) { if (MipsCompactBranchPolicy.getValue() != CB_Always || !TII->getEquivalentCompactForm(I)) { if (searchBackward(MBB, *I)) { + LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot" + " in backwards search.\n"); Filled = true; } else if (I->isTerminator()) { if (searchSuccBBs(MBB, I)) { Filled = true; + LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot" + " in successor BB search.\n"); } } else if (searchForward(MBB, I)) { + LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot" + " in forwards search.\n"); Filled = true; } } @@ -663,6 +674,8 @@ bool MipsDelaySlotFiller::runOnMachineBasicBlock(MachineBasicBlock &MBB) { } // Bundle the NOP to the instruction with the delay slot. + LLVM_DEBUG(dbgs() << DEBUG_TYPE << ": could not fill delay slot for "; + I->dump()); BuildMI(MBB, std::next(I), I->getDebugLoc(), TII->get(Mips::NOP)); MIBundleBuilder(MBB, I, std::next(I, 2)); ++FilledSlots; @@ -680,13 +693,27 @@ bool MipsDelaySlotFiller::searchRange(MachineBasicBlock &MBB, IterTy Begin, for (IterTy I = Begin; I != End;) { IterTy CurrI = I; ++I; - + LLVM_DEBUG(dbgs() << DEBUG_TYPE ": checking instruction: "; CurrI->dump()); // skip debug value - if (CurrI->isDebugInstr()) + if (CurrI->isDebugInstr()) { + LLVM_DEBUG(dbgs() << DEBUG_TYPE ": ignoring debug instruction: "; + CurrI->dump()); continue; + } + + if (CurrI->isBundle()) { + LLVM_DEBUG(dbgs() << DEBUG_TYPE ": ignoring BUNDLE instruction: "; + CurrI->dump()); + // However, we still need to update the register def-use information. + RegDU.update(*CurrI, 0, CurrI->getNumOperands()); + continue; + } - if (terminateSearch(*CurrI)) + if (terminateSearch(*CurrI)) { + LLVM_DEBUG(dbgs() << DEBUG_TYPE ": should terminate search: "; + CurrI->dump()); break; + } assert((!CurrI->isCall() && !CurrI->isReturn() && !CurrI->isBranch()) && "Cannot put calls, returns or branches in delay slot."); @@ -732,6 +759,9 @@ bool MipsDelaySlotFiller::searchRange(MachineBasicBlock &MBB, IterTy Begin, continue; Filler = CurrI; + LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot: "; + CurrI->dump()); + return true; } @@ -752,8 +782,11 @@ bool MipsDelaySlotFiller::searchBackward(MachineBasicBlock &MBB, MachineBasicBlock::iterator SlotI = Slot; if (!searchRange(MBB, ++SlotI.getReverse(), MBB.rend(), RegDU, MemDU, Slot, - Filler)) + Filler)) { + LLVM_DEBUG(dbgs() << DEBUG_TYPE ": could not find instruction for delay " + "slot using backwards search.\n"); return false; + } MBB.splice(std::next(SlotI), &MBB, Filler.getReverse()); MIBundleBuilder(MBB, SlotI, std::next(SlotI, 2)); @@ -773,8 +806,11 @@ bool MipsDelaySlotFiller::searchForward(MachineBasicBlock &MBB, RegDU.setCallerSaved(*Slot); - if (!searchRange(MBB, std::next(Slot), MBB.end(), RegDU, NM, Slot, Filler)) + if (!searchRange(MBB, std::next(Slot), MBB.end(), RegDU, NM, Slot, Filler)) { + LLVM_DEBUG(dbgs() << DEBUG_TYPE ": could not find instruction for delay " + "slot using forwards search.\n"); return false; + } MBB.splice(std::next(Slot), &MBB, Filler); MIBundleBuilder(MBB, Slot, std::next(Slot, 2)); @@ -927,4 +963,6 @@ bool MipsDelaySlotFiller::terminateSearch(const MachineInstr &Candidate) const { /// createMipsDelaySlotFillerPass - Returns a pass that fills in delay /// slots in Mips MachineFunctions -FunctionPass *llvm::createMipsDelaySlotFillerPass() { return new MipsDelaySlotFiller(); } +FunctionPass *llvm::createMipsDelaySlotFillerPass() { + return new MipsDelaySlotFiller(); +} |