From 6f818abbe3dce0bee8257ea7d7dd4cb951f4dc7c Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Wed, 5 Oct 2011 01:23:39 +0000 Subject: [PATCH] Clean up Filler::runOnMachineBasicBlock. Change interface of Filler::findDelayInstr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141150 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/Mips/MipsDelaySlotFiller.cpp | 37 +++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/Target/Mips/MipsDelaySlotFiller.cpp b/lib/Target/Mips/MipsDelaySlotFiller.cpp index 6cc6a4d0de1..3c5f4314e56 100644 --- a/lib/Target/Mips/MipsDelaySlotFiller.cpp +++ b/lib/Target/Mips/MipsDelaySlotFiller.cpp @@ -78,8 +78,9 @@ namespace { SmallSet &RegDefs, SmallSet &RegUses); - MachineBasicBlock::iterator - findDelayInstr(MachineBasicBlock &MBB, MachineBasicBlock::iterator slot); + bool + findDelayInstr(MachineBasicBlock &MBB, MachineBasicBlock::iterator slot, + MachineBasicBlock::iterator &Filler); }; @@ -93,19 +94,19 @@ runOnMachineBasicBlock(MachineBasicBlock &MBB) { bool Changed = false; for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) if (I->getDesc().hasDelaySlot()) { - MachineBasicBlock::iterator D = MBB.end(); - MachineBasicBlock::iterator J = I; - - if (EnableDelaySlotFiller) - D = findDelayInstr(MBB, I); - ++FilledSlots; Changed = true; - if (D == MBB.end()) - BuildMI(MBB, ++J, I->getDebugLoc(), TII->get(Mips::NOP)); - else - MBB.splice(++J, &MBB, D); + MachineBasicBlock::iterator D; + + if (EnableDelaySlotFiller && findDelayInstr(MBB, I, D)) { + MBB.splice(llvm::next(I), &MBB, D); + ++UsefulSlots; + } + else + BuildMI(MBB, llvm::next(I), I->getDebugLoc(), TII->get(Mips::NOP)); + + ++I; // Skip instruction that has just been moved to delay slot. } return Changed; @@ -117,9 +118,9 @@ FunctionPass *llvm::createMipsDelaySlotFillerPass(MipsTargetMachine &tm) { return new Filler(tm); } -MachineBasicBlock::iterator -Filler::findDelayInstr(MachineBasicBlock &MBB, - MachineBasicBlock::iterator slot) { +bool Filler::findDelayInstr(MachineBasicBlock &MBB, + MachineBasicBlock::iterator slot, + MachineBasicBlock::iterator &Filler) { SmallSet RegDefs; SmallSet RegUses; bool sawLoad = false; @@ -162,9 +163,11 @@ Filler::findDelayInstr(MachineBasicBlock &MBB, continue; } - return I; + Filler = I; + return true; } - return MBB.end(); + + return false; } bool Filler::delayHasHazard(MachineBasicBlock::iterator candidate, -- 2.34.1