mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-11 21:38:19 +00:00
[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
This commit is contained in:
@ -66,37 +66,38 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef MachineBasicBlock::instr_iterator InstrIter;
|
typedef MachineBasicBlock::iterator Iter;
|
||||||
typedef MachineBasicBlock::reverse_instr_iterator ReverseInstrIter;
|
typedef MachineBasicBlock::reverse_iterator ReverseIter;
|
||||||
|
|
||||||
bool runOnMachineBasicBlock(MachineBasicBlock &MBB);
|
bool runOnMachineBasicBlock(MachineBasicBlock &MBB);
|
||||||
|
|
||||||
bool isDelayFiller(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> &RegDefs,
|
||||||
SmallSet<unsigned, 32> &RegUses);
|
SmallSet<unsigned, 32> &RegUses);
|
||||||
|
|
||||||
void insertDefsUses(InstrIter MI,
|
void insertDefsUses(Iter MI,
|
||||||
SmallSet<unsigned, 32> &RegDefs,
|
SmallSet<unsigned, 32> &RegDefs,
|
||||||
SmallSet<unsigned, 32> &RegUses);
|
SmallSet<unsigned, 32> &RegUses);
|
||||||
|
|
||||||
bool IsRegInSet(SmallSet<unsigned, 32> &RegSet,
|
bool IsRegInSet(SmallSet<unsigned, 32> &RegSet,
|
||||||
unsigned Reg);
|
unsigned Reg);
|
||||||
|
|
||||||
bool delayHasHazard(InstrIter candidate,
|
bool delayHasHazard(Iter candidate,
|
||||||
bool &sawLoad, bool &sawStore,
|
bool &sawLoad, bool &sawStore,
|
||||||
SmallSet<unsigned, 32> &RegDefs,
|
SmallSet<unsigned, 32> &RegDefs,
|
||||||
SmallSet<unsigned, 32> &RegUses);
|
SmallSet<unsigned, 32> &RegUses);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
findDelayInstr(MachineBasicBlock &MBB, InstrIter slot,
|
findDelayInstr(MachineBasicBlock &MBB, Iter slot,
|
||||||
InstrIter &Filler);
|
Iter &Filler);
|
||||||
|
|
||||||
|
bool terminateSearch(const MachineInstr &Candidate) const;
|
||||||
|
|
||||||
TargetMachine &TM;
|
TargetMachine &TM;
|
||||||
const TargetInstrInfo *TII;
|
const TargetInstrInfo *TII;
|
||||||
InstrIter LastFiller;
|
|
||||||
|
|
||||||
static char ID;
|
static char ID;
|
||||||
};
|
};
|
||||||
@ -108,16 +109,14 @@ namespace {
|
|||||||
bool Filler::
|
bool Filler::
|
||||||
runOnMachineBasicBlock(MachineBasicBlock &MBB) {
|
runOnMachineBasicBlock(MachineBasicBlock &MBB) {
|
||||||
bool Changed = false;
|
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())
|
if (!I->hasDelaySlot())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
++FilledSlots;
|
++FilledSlots;
|
||||||
Changed = true;
|
Changed = true;
|
||||||
InstrIter InstrWithSlot = I;
|
Iter D;
|
||||||
InstrIter D;
|
|
||||||
|
|
||||||
// Delay slot filling is disabled at -O0.
|
// Delay slot filling is disabled at -O0.
|
||||||
if (!DisableDelaySlotFiller && (TM.getOptLevel() != CodeGenOpt::None) &&
|
if (!DisableDelaySlotFiller && (TM.getOptLevel() != CodeGenOpt::None) &&
|
||||||
@ -127,13 +126,8 @@ runOnMachineBasicBlock(MachineBasicBlock &MBB) {
|
|||||||
} else
|
} else
|
||||||
BuildMI(MBB, llvm::next(I), I->getDebugLoc(), TII->get(Mips::NOP));
|
BuildMI(MBB, llvm::next(I), I->getDebugLoc(), TII->get(Mips::NOP));
|
||||||
|
|
||||||
// Record the filler instruction that filled the delay slot.
|
// Bundle the delay slot filler to the instruction with the delay slot.
|
||||||
// The instruction after it will be visited in the next iteration.
|
MIBundleBuilder(MBB, I, llvm::next(llvm::next(I)));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Changed;
|
return Changed;
|
||||||
@ -146,8 +140,8 @@ FunctionPass *llvm::createMipsDelaySlotFillerPass(MipsTargetMachine &tm) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Filler::findDelayInstr(MachineBasicBlock &MBB,
|
bool Filler::findDelayInstr(MachineBasicBlock &MBB,
|
||||||
InstrIter slot,
|
Iter slot,
|
||||||
InstrIter &Filler) {
|
Iter &Filler) {
|
||||||
SmallSet<unsigned, 32> RegDefs;
|
SmallSet<unsigned, 32> RegDefs;
|
||||||
SmallSet<unsigned, 32> RegUses;
|
SmallSet<unsigned, 32> RegUses;
|
||||||
|
|
||||||
@ -156,26 +150,17 @@ bool Filler::findDelayInstr(MachineBasicBlock &MBB,
|
|||||||
bool sawLoad = false;
|
bool sawLoad = false;
|
||||||
bool sawStore = false;
|
bool sawStore = false;
|
||||||
|
|
||||||
for (ReverseInstrIter I(slot); I != MBB.instr_rend(); ++I) {
|
for (ReverseIter I(slot); I != MBB.rend(); ++I) {
|
||||||
// skip debug value
|
// skip debug value
|
||||||
if (I->isDebugValue())
|
if (I->isDebugValue())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Convert to forward iterator.
|
if (terminateSearch(*I))
|
||||||
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.
|
|
||||||
)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// Convert to forward iterator.
|
||||||
|
Iter FI(llvm::next(I).base());
|
||||||
|
|
||||||
if (delayHasHazard(FI, sawLoad, sawStore, RegDefs, RegUses)) {
|
if (delayHasHazard(FI, sawLoad, sawStore, RegDefs, RegUses)) {
|
||||||
insertDefsUses(FI, RegDefs, RegUses);
|
insertDefsUses(FI, RegDefs, RegUses);
|
||||||
continue;
|
continue;
|
||||||
@ -188,7 +173,7 @@ bool Filler::findDelayInstr(MachineBasicBlock &MBB,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Filler::delayHasHazard(InstrIter candidate,
|
bool Filler::delayHasHazard(Iter candidate,
|
||||||
bool &sawLoad, bool &sawStore,
|
bool &sawLoad, bool &sawStore,
|
||||||
SmallSet<unsigned, 32> &RegDefs,
|
SmallSet<unsigned, 32> &RegDefs,
|
||||||
SmallSet<unsigned, 32> &RegUses) {
|
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.
|
// 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> &RegDefs,
|
||||||
SmallSet<unsigned, 32> &RegUses) {
|
SmallSet<unsigned, 32> &RegUses) {
|
||||||
unsigned I, E = MI->getDesc().getNumOperands();
|
unsigned I, E = MI->getDesc().getNumOperands();
|
||||||
@ -288,3 +273,9 @@ bool Filler::IsRegInSet(SmallSet<unsigned, 32> &RegSet, unsigned Reg) {
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Filler::terminateSearch(const MachineInstr &Candidate) const {
|
||||||
|
return (Candidate.isTerminator() || Candidate.isCall() ||
|
||||||
|
Candidate.isLabel() || Candidate.isInlineAsm() ||
|
||||||
|
Candidate.hasUnmodeledSideEffects());
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user