summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/PeepholeOptimizer.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2010-11-15 21:20:45 +0000
committerEvan Cheng <evan.cheng@apple.com>2010-11-15 21:20:45 +0000
commit2ce016c7f8dd6ef2bbc8a85b3a7291d9ddd1ad2c (patch)
tree1a459d821dcf8ee3c6ed45b3edfaac4731e646d8 /llvm/lib/CodeGen/PeepholeOptimizer.cpp
parent7d97a99f4c330a9e3e52715a2bf2377b30c65a52 (diff)
downloadbcm5719-llvm-2ce016c7f8dd6ef2bbc8a85b3a7291d9ddd1ad2c.tar.gz
bcm5719-llvm-2ce016c7f8dd6ef2bbc8a85b3a7291d9ddd1ad2c.zip
Code clean up. The peephole pass should be the one updating the instruction
iterator, not TII->OptimizeCompareInstr. llvm-svn: 119186
Diffstat (limited to 'llvm/lib/CodeGen/PeepholeOptimizer.cpp')
-rw-r--r--llvm/lib/CodeGen/PeepholeOptimizer.cpp32
1 files changed, 15 insertions, 17 deletions
diff --git a/llvm/lib/CodeGen/PeepholeOptimizer.cpp b/llvm/lib/CodeGen/PeepholeOptimizer.cpp
index 0f2ba41d7cf..75f453ad71d 100644
--- a/llvm/lib/CodeGen/PeepholeOptimizer.cpp
+++ b/llvm/lib/CodeGen/PeepholeOptimizer.cpp
@@ -82,8 +82,7 @@ namespace {
}
private:
- bool OptimizeCmpInstr(MachineInstr *MI, MachineBasicBlock *MBB,
- MachineBasicBlock::iterator &MII);
+ bool OptimizeCmpInstr(MachineInstr *MI, MachineBasicBlock *MBB);
bool OptimizeExtInstr(MachineInstr *MI, MachineBasicBlock *MBB,
SmallPtrSet<MachineInstr*, 8> &LocalMIs);
};
@@ -112,12 +111,10 @@ FunctionPass *llvm::createPeepholeOptimizerPass() {
bool PeepholeOptimizer::
OptimizeExtInstr(MachineInstr *MI, MachineBasicBlock *MBB,
SmallPtrSet<MachineInstr*, 8> &LocalMIs) {
- LocalMIs.insert(MI);
-
unsigned SrcReg, DstReg, SubIdx;
if (!TII->isCoalescableExtInstr(*MI, SrcReg, DstReg, SubIdx))
return false;
-
+
if (TargetRegisterInfo::isPhysicalRegister(DstReg) ||
TargetRegisterInfo::isPhysicalRegister(SrcReg))
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
/// the flag from the previous instruction.
bool PeepholeOptimizer::OptimizeCmpInstr(MachineInstr *MI,
- MachineBasicBlock *MBB,
- MachineBasicBlock::iterator &NextIter){
+ MachineBasicBlock *MBB){
// If this instruction is a comparison against zero and isn't comparing a
// physical register, we can try to optimize it.
unsigned SrcReg;
@@ -253,7 +249,7 @@ bool PeepholeOptimizer::OptimizeCmpInstr(MachineInstr *MI,
return false;
// Attempt to optimize the comparison instruction.
- if (TII->OptimizeCompareInstr(MI, SrcReg, CmpMask, CmpValue, MRI, NextIter)) {
+ if (TII->OptimizeCompareInstr(MI, SrcReg, CmpMask, CmpValue, MRI)) {
++NumEliminated;
return true;
}
@@ -262,6 +258,9 @@ bool PeepholeOptimizer::OptimizeCmpInstr(MachineInstr *MI,
}
bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
+ if (DisablePeephole)
+ return false;
+
TM = &MF.getTarget();
TII = TM->getInstrInfo();
MRI = &MF.getRegInfo();
@@ -276,17 +275,16 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
for (MachineBasicBlock::iterator
MII = I->begin(), MIE = I->end(); MII != MIE; ) {
- MachineInstr *MI = &*MII;
-
- if (MI->getDesc().isCompare() &&
- !MI->getDesc().hasUnmodeledSideEffects()) {
- if (!DisablePeephole && OptimizeCmpInstr(MI, MBB, MII))
- Changed = true;
- else
- ++MII;
+ MachineInstr *MI = &*MII++;
+ LocalMIs.insert(MI);
+
+ if (MI->getDesc().hasUnmodeledSideEffects())
+ continue;
+
+ if (MI->getDesc().isCompare()) {
+ Changed |= OptimizeCmpInstr(MI, MBB);
} else {
Changed |= OptimizeExtInstr(MI, MBB, LocalMIs);
- ++MII;
}
}
}
OpenPOWER on IntegriCloud