1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

Code clean up. The peephole pass should be the one updating the instruction

iterator, not TII->OptimizeCompareInstr.

llvm-svn: 119186
This commit is contained in:
Evan Cheng 2010-11-15 21:20:45 +00:00
parent db1a4541c2
commit 4afa3a6b1f
4 changed files with 19 additions and 27 deletions

View File

@ -602,12 +602,10 @@ public:
/// OptimizeCompareInstr - See if the comparison instruction can be converted /// OptimizeCompareInstr - See if the comparison instruction can be converted
/// into something more efficient. E.g., on ARM most instructions can set the /// into something more efficient. E.g., on ARM most instructions can set the
/// flags register, obviating the need for a separate CMP. Update the iterator /// flags register, obviating the need for a separate CMP.
/// *only* if a transformation took place.
virtual bool OptimizeCompareInstr(MachineInstr *CmpInstr, virtual bool OptimizeCompareInstr(MachineInstr *CmpInstr,
unsigned SrcReg, int Mask, int Value, unsigned SrcReg, int Mask, int Value,
const MachineRegisterInfo *MRI, const MachineRegisterInfo *MRI) const {
MachineBasicBlock::iterator &) const {
return false; return false;
} }

View File

@ -82,8 +82,7 @@ namespace {
} }
private: private:
bool OptimizeCmpInstr(MachineInstr *MI, MachineBasicBlock *MBB, bool OptimizeCmpInstr(MachineInstr *MI, MachineBasicBlock *MBB);
MachineBasicBlock::iterator &MII);
bool OptimizeExtInstr(MachineInstr *MI, MachineBasicBlock *MBB, bool OptimizeExtInstr(MachineInstr *MI, MachineBasicBlock *MBB,
SmallPtrSet<MachineInstr*, 8> &LocalMIs); SmallPtrSet<MachineInstr*, 8> &LocalMIs);
}; };
@ -112,8 +111,6 @@ FunctionPass *llvm::createPeepholeOptimizerPass() {
bool PeepholeOptimizer:: bool PeepholeOptimizer::
OptimizeExtInstr(MachineInstr *MI, MachineBasicBlock *MBB, OptimizeExtInstr(MachineInstr *MI, MachineBasicBlock *MBB,
SmallPtrSet<MachineInstr*, 8> &LocalMIs) { SmallPtrSet<MachineInstr*, 8> &LocalMIs) {
LocalMIs.insert(MI);
unsigned SrcReg, DstReg, SubIdx; unsigned SrcReg, DstReg, SubIdx;
if (!TII->isCoalescableExtInstr(*MI, SrcReg, DstReg, SubIdx)) if (!TII->isCoalescableExtInstr(*MI, SrcReg, DstReg, SubIdx))
return false; return false;
@ -242,8 +239,7 @@ OptimizeExtInstr(MachineInstr *MI, MachineBasicBlock *MBB,
/// set) the same flag as the compare, then we can remove the comparison and use /// set) the same flag as the compare, then we can remove the comparison and use
/// the flag from the previous instruction. /// the flag from the previous instruction.
bool PeepholeOptimizer::OptimizeCmpInstr(MachineInstr *MI, bool PeepholeOptimizer::OptimizeCmpInstr(MachineInstr *MI,
MachineBasicBlock *MBB, MachineBasicBlock *MBB){
MachineBasicBlock::iterator &NextIter){
// If this instruction is a comparison against zero and isn't comparing a // If this instruction is a comparison against zero and isn't comparing a
// physical register, we can try to optimize it. // physical register, we can try to optimize it.
unsigned SrcReg; unsigned SrcReg;
@ -253,7 +249,7 @@ bool PeepholeOptimizer::OptimizeCmpInstr(MachineInstr *MI,
return false; return false;
// Attempt to optimize the comparison instruction. // Attempt to optimize the comparison instruction.
if (TII->OptimizeCompareInstr(MI, SrcReg, CmpMask, CmpValue, MRI, NextIter)) { if (TII->OptimizeCompareInstr(MI, SrcReg, CmpMask, CmpValue, MRI)) {
++NumEliminated; ++NumEliminated;
return true; return true;
} }
@ -262,6 +258,9 @@ bool PeepholeOptimizer::OptimizeCmpInstr(MachineInstr *MI,
} }
bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) { bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
if (DisablePeephole)
return false;
TM = &MF.getTarget(); TM = &MF.getTarget();
TII = TM->getInstrInfo(); TII = TM->getInstrInfo();
MRI = &MF.getRegInfo(); MRI = &MF.getRegInfo();
@ -276,17 +275,16 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
for (MachineBasicBlock::iterator for (MachineBasicBlock::iterator
MII = I->begin(), MIE = I->end(); MII != MIE; ) { MII = I->begin(), MIE = I->end(); MII != MIE; ) {
MachineInstr *MI = &*MII; MachineInstr *MI = &*MII++;
LocalMIs.insert(MI);
if (MI->getDesc().isCompare() && if (MI->getDesc().hasUnmodeledSideEffects())
!MI->getDesc().hasUnmodeledSideEffects()) { continue;
if (!DisablePeephole && OptimizeCmpInstr(MI, MBB, MII))
Changed = true; if (MI->getDesc().isCompare()) {
else Changed |= OptimizeCmpInstr(MI, MBB);
++MII;
} else { } else {
Changed |= OptimizeExtInstr(MI, MBB, LocalMIs); Changed |= OptimizeExtInstr(MI, MBB, LocalMIs);
++MII;
} }
} }
} }

View File

@ -1484,12 +1484,10 @@ static bool isSuitableForMask(MachineInstr *&MI, unsigned SrcReg,
} }
/// OptimizeCompareInstr - Convert the instruction supplying the argument to the /// OptimizeCompareInstr - Convert the instruction supplying the argument to the
/// comparison into one that sets the zero bit in the flags register. Update the /// comparison into one that sets the zero bit in the flags register.
/// iterator *only* if a transformation took place.
bool ARMBaseInstrInfo:: bool ARMBaseInstrInfo::
OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, int CmpMask, OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, int CmpMask,
int CmpValue, const MachineRegisterInfo *MRI, int CmpValue, const MachineRegisterInfo *MRI) const {
MachineBasicBlock::iterator &MII) const {
if (CmpValue != 0) if (CmpValue != 0)
return false; return false;
@ -1561,7 +1559,6 @@ OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, int CmpMask,
MI->RemoveOperand(5); MI->RemoveOperand(5);
MachineInstrBuilder(MI) MachineInstrBuilder(MI)
.addReg(ARM::CPSR, RegState::Define | RegState::Implicit); .addReg(ARM::CPSR, RegState::Define | RegState::Implicit);
MII = llvm::next(MachineBasicBlock::iterator(CmpInstr));
CmpInstr->eraseFromParent(); CmpInstr->eraseFromParent();
return true; return true;
} }

View File

@ -344,8 +344,7 @@ public:
/// that we can remove a "comparison with zero". /// that we can remove a "comparison with zero".
virtual bool OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, virtual bool OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
int CmpMask, int CmpValue, int CmpMask, int CmpValue,
const MachineRegisterInfo *MRI, const MachineRegisterInfo *MRI) const;
MachineBasicBlock::iterator &MII) const;
virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData, virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData,
const MachineInstr *MI) const; const MachineInstr *MI) const;