summaryrefslogtreecommitdiff
path: root/lib/Target/Mips/MipsDelaySlotFiller.cpp
diff options
context:
space:
mode:
authorAkira Hatanaka <ahatanaka@mips.com>2013-02-14 23:11:24 +0000
committerAkira Hatanaka <ahatanaka@mips.com>2013-02-14 23:11:24 +0000
commiteba97c573f08332c9c9d1875c304cce1bea2e28e (patch)
treee0ca31ab69483c2c3f3174495ec9813514ee0e39 /lib/Target/Mips/MipsDelaySlotFiller.cpp
parente2e00dffdf4512d948daf74257d6f012362b44c9 (diff)
downloadllvm-eba97c573f08332c9c9d1875c304cce1bea2e28e.tar.gz
llvm-eba97c573f08332c9c9d1875c304cce1bea2e28e.tar.bz2
llvm-eba97c573f08332c9c9d1875c304cce1bea2e28e.tar.xz
[mips] Simplify code in function Filler::findDelayInstr.
1. Define and use function terminateSearch. 2. Use MachineBasicBlock::iterator instead of MachineBasicBlock::instr_iterator. 3. Delete the line which checks whether an instruction is a pseudo. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175219 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/Mips/MipsDelaySlotFiller.cpp')
-rw-r--r--lib/Target/Mips/MipsDelaySlotFiller.cpp67
1 files changed, 29 insertions, 38 deletions
diff --git a/lib/Target/Mips/MipsDelaySlotFiller.cpp b/lib/Target/Mips/MipsDelaySlotFiller.cpp
index cf0d9db4cc..672d4eab21 100644
--- a/lib/Target/Mips/MipsDelaySlotFiller.cpp
+++ b/lib/Target/Mips/MipsDelaySlotFiller.cpp
@@ -66,37 +66,38 @@ namespace {
}
private:
- typedef MachineBasicBlock::instr_iterator InstrIter;
- typedef MachineBasicBlock::reverse_instr_iterator ReverseInstrIter;
+ typedef MachineBasicBlock::iterator Iter;
+ typedef MachineBasicBlock::reverse_iterator ReverseIter;
bool runOnMachineBasicBlock(MachineBasicBlock &MBB);
bool isDelayFiller(MachineBasicBlock &MBB,
- InstrIter candidate);
+ Iter candidate);
- void insertCallUses(InstrIter MI,
+ void insertCallUses(Iter MI,
SmallSet<unsigned, 32> &RegDefs,
SmallSet<unsigned, 32> &RegUses);
- void insertDefsUses(InstrIter MI,
+ void insertDefsUses(Iter MI,
SmallSet<unsigned, 32> &RegDefs,
SmallSet<unsigned, 32> &RegUses);
bool IsRegInSet(SmallSet<unsigned, 32> &RegSet,
unsigned Reg);
- bool delayHasHazard(InstrIter candidate,
+ bool delayHasHazard(Iter candidate,
bool &sawLoad, bool &sawStore,
SmallSet<unsigned, 32> &RegDefs,
SmallSet<unsigned, 32> &RegUses);
bool
- findDelayInstr(MachineBasicBlock &MBB, InstrIter slot,
- InstrIter &Filler);
+ findDelayInstr(MachineBasicBlock &MBB, Iter slot,
+ Iter &Filler);
+
+ bool terminateSearch(const MachineInstr &Candidate) const;
TargetMachine &TM;
const TargetInstrInfo *TII;
- InstrIter LastFiller;
static char ID;
};
@@ -108,16 +109,14 @@ namespace {
bool Filler::
runOnMachineBasicBlock(MachineBasicBlock &MBB) {
bool Changed = false;
- LastFiller = MBB.instr_end();
- for (InstrIter I = MBB.instr_begin(); I != MBB.instr_end(); ++I) {
+ for (Iter I = MBB.begin(); I != MBB.end(); ++I) {
if (!I->hasDelaySlot())
continue;
++FilledSlots;
Changed = true;
- InstrIter InstrWithSlot = I;
- InstrIter D;
+ Iter D;
// Delay slot filling is disabled at -O0.
if (!DisableDelaySlotFiller && (TM.getOptLevel() != CodeGenOpt::None) &&
@@ -127,13 +126,8 @@ runOnMachineBasicBlock(MachineBasicBlock &MBB) {
} else
BuildMI(MBB, llvm::next(I), I->getDebugLoc(), TII->get(Mips::NOP));
- // Record the filler instruction that filled the delay slot.
- // The instruction after it will be visited in the next iteration.
- LastFiller = ++I;
-
- // Bundle the delay slot filler to InstrWithSlot so that the machine
- // verifier doesn't expect this instruction to be a terminator.
- MIBundleBuilder(MBB, InstrWithSlot, llvm::next(LastFiller));
+ // Bundle the delay slot filler to the instruction with the delay slot.
+ MIBundleBuilder(MBB, I, llvm::next(llvm::next(I)));
}
return Changed;
@@ -146,8 +140,8 @@ FunctionPass *llvm::createMipsDelaySlotFillerPass(MipsTargetMachine &tm) {
}
bool Filler::findDelayInstr(MachineBasicBlock &MBB,
- InstrIter slot,
- InstrIter &Filler) {
+ Iter slot,
+ Iter &Filler) {
SmallSet<unsigned, 32> RegDefs;
SmallSet<unsigned, 32> RegUses;
@@ -156,26 +150,17 @@ bool Filler::findDelayInstr(MachineBasicBlock &MBB,
bool sawLoad = false;
bool sawStore = false;
- for (ReverseInstrIter I(slot); I != MBB.instr_rend(); ++I) {
+ for (ReverseIter I(slot); I != MBB.rend(); ++I) {
// skip debug value
if (I->isDebugValue())
continue;
- // Convert to forward iterator.
- InstrIter FI(llvm::next(I).base());
-
- if (I->hasUnmodeledSideEffects()
- || I->isInlineAsm()
- || I->isLabel()
- || FI == LastFiller
- || I->isPseudo()
- //
- // Should not allow:
- // ERET, DERET or WAIT, PAUSE. Need to add these to instruction
- // list. TBD.
- )
+ if (terminateSearch(*I))
break;
+ // Convert to forward iterator.
+ Iter FI(llvm::next(I).base());
+
if (delayHasHazard(FI, sawLoad, sawStore, RegDefs, RegUses)) {
insertDefsUses(FI, RegDefs, RegUses);
continue;
@@ -188,7 +173,7 @@ bool Filler::findDelayInstr(MachineBasicBlock &MBB,
return false;
}
-bool Filler::delayHasHazard(InstrIter candidate,
+bool Filler::delayHasHazard(Iter candidate,
bool &sawLoad, bool &sawStore,
SmallSet<unsigned, 32> &RegDefs,
SmallSet<unsigned, 32> &RegUses) {
@@ -253,7 +238,7 @@ static void insertDefUse(const MachineOperand &MO,
}
// Insert Defs and Uses of MI into the sets RegDefs and RegUses.
-void Filler::insertDefsUses(InstrIter MI,
+void Filler::insertDefsUses(Iter MI,
SmallSet<unsigned, 32> &RegDefs,
SmallSet<unsigned, 32> &RegUses) {
unsigned I, E = MI->getDesc().getNumOperands();
@@ -288,3 +273,9 @@ bool Filler::IsRegInSet(SmallSet<unsigned, 32> &RegSet, unsigned Reg) {
return true;
return false;
}
+
+bool Filler::terminateSearch(const MachineInstr &Candidate) const {
+ return (Candidate.isTerminator() || Candidate.isCall() ||
+ Candidate.isLabel() || Candidate.isInlineAsm() ||
+ Candidate.hasUnmodeledSideEffects());
+}