diff options
author | Evan Cheng <evan.cheng@apple.com> | 2008-10-27 23:21:01 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2008-10-27 23:21:01 +0000 |
commit | f46642ada6a52ae61d01dac176fa59e6c9b598fe (patch) | |
tree | d755bde667d52d9a0b41b0fa24396ca2444ebfb3 /llvm/lib/CodeGen/SimpleRegisterCoalescing.cpp | |
parent | 54d399ac5d029889771fdac90693e640b3a03665 (diff) | |
download | bcm5719-llvm-f46642ada6a52ae61d01dac176fa59e6c9b598fe.tar.gz bcm5719-llvm-f46642ada6a52ae61d01dac176fa59e6c9b598fe.zip |
Remove val# defined by a remat'ed def that is now dead.
llvm-svn: 58294
Diffstat (limited to 'llvm/lib/CodeGen/SimpleRegisterCoalescing.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SimpleRegisterCoalescing.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/SimpleRegisterCoalescing.cpp b/llvm/lib/CodeGen/SimpleRegisterCoalescing.cpp index 6eeb21c1bf7..a60939c3010 100644 --- a/llvm/lib/CodeGen/SimpleRegisterCoalescing.cpp +++ b/llvm/lib/CodeGen/SimpleRegisterCoalescing.cpp @@ -707,6 +707,18 @@ bool SimpleRegisterCoalescing::ShortenDeadCopyLiveRange(LiveInterval &li, return false; } +/// RemoveDeadDef - If a def of a live interval is now determined dead, remove +/// the val# it defines. If the live interval becomes empty, remove it as well. +bool SimpleRegisterCoalescing::RemoveDeadDef(LiveInterval &li, + MachineInstr *DefMI) { + unsigned DefIdx = li_->getDefIndex(li_->getInstructionIndex(DefMI)); + LiveInterval::iterator MLR = li.FindLiveRangeContaining(DefIdx); + if (DefIdx != MLR->valno->def) + return false; + li.removeValNo(MLR->valno); + return removeIntervalIfEmpty(li, li_, tri_); +} + /// PropagateDeadness - Propagate the dead marker to the instruction which /// defines the val#. static void PropagateDeadness(LiveInterval &li, MachineInstr *CopyMI, @@ -2280,6 +2292,7 @@ bool SimpleRegisterCoalescing::runOnMachineFunction(MachineFunction &fn) { // Perform a final pass over the instructions and compute spill weights // and remove identity moves. + SmallVector<unsigned, 4> DeadDefs; for (MachineFunction::iterator mbbi = mf_->begin(), mbbe = mf_->end(); mbbi != mbbe; ++mbbi) { MachineBasicBlock* mbb = mbbi; @@ -2313,9 +2326,13 @@ bool SimpleRegisterCoalescing::runOnMachineFunction(MachineFunction &fn) { bool isDead = true; for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { const MachineOperand &MO = MI->getOperand(i); - if (!MO.isReg() || MO.isDead()) + if (!MO.isReg()) continue; unsigned Reg = MO.getReg(); + if (TargetRegisterInfo::isVirtualRegister(Reg)) + DeadDefs.push_back(Reg); + if (MO.isDead()) + continue; if (TargetRegisterInfo::isPhysicalRegister(Reg) || !mri_->use_empty(Reg)) { isDead = false; @@ -2323,10 +2340,16 @@ bool SimpleRegisterCoalescing::runOnMachineFunction(MachineFunction &fn) { } } if (isDead) { + while (!DeadDefs.empty()) { + unsigned DeadDef = DeadDefs.back(); + DeadDefs.pop_back(); + RemoveDeadDef(li_->getInterval(DeadDef), MI); + } li_->RemoveMachineInstrFromMaps(mii); mii = mbbi->erase(mii); continue; - } + } else + DeadDefs.clear(); } // If the move will be an identity move delete it |