diff options
author | Bill Wendling <isanbard@gmail.com> | 2009-03-31 08:26:26 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2009-03-31 08:26:26 +0000 |
commit | 9193518e774925af5b64215b71d939337db5b1fb (patch) | |
tree | 56d4020e70d6a8011baf1a2efd0733143ed5753b /lib/CodeGen/Spiller.cpp | |
parent | d86e6be9835f2942145c5e8eda7002f4f0b5ffcb (diff) | |
download | external_llvm-9193518e774925af5b64215b71d939337db5b1fb.zip external_llvm-9193518e774925af5b64215b71d939337db5b1fb.tar.gz external_llvm-9193518e774925af5b64215b71d939337db5b1fb.tar.bz2 |
Revert r68073. It's causing a failure in the Apple-style builds.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68092 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/Spiller.cpp')
-rw-r--r-- | lib/CodeGen/Spiller.cpp | 93 |
1 files changed, 62 insertions, 31 deletions
diff --git a/lib/CodeGen/Spiller.cpp b/lib/CodeGen/Spiller.cpp index 7b2a32f..4bfae39 100644 --- a/lib/CodeGen/Spiller.cpp +++ b/lib/CodeGen/Spiller.cpp @@ -578,6 +578,20 @@ bool LocalSpiller::runOnMachineFunction(MachineFunction &MF, VirtRegMap &VRM) { DOUT << "**** Post Machine Instrs ****\n"; DEBUG(MF.dump()); + // See if any of the spills we added are actually dead and can be deleted. + for (std::vector<MachineInstr*> >::iterator + I = AddedSpills.begin(), E = AddedSpills.end(); I != E; ++I) { + MachineInstr *MI = *I; + + if (VRM.OnlyUseOfStackSlot(MI)) { + MachineBasicBlock *MBB = MI->getParent(); + DOUT << "Removed dead store:\t" << *MI; + VRM.RemoveMachineInstrFromMaps(MI); + MBB->erase(MI); + ++NumDSE; + } + } + // Mark unused spill slots. MachineFrameInfo *MFI = MF.getFrameInfo(); int SS = VRM.getLowSpillSlot(); @@ -588,6 +602,7 @@ bool LocalSpiller::runOnMachineFunction(MachineFunction &MF, VirtRegMap &VRM) { ++NumDSS; } + AddedSpills.clear(); return true; } @@ -798,9 +813,50 @@ bool LocalSpiller::CommuteToFoldReload(MachineBasicBlock &MBB, return false; } +void LocalSpiller::RemoveDeadStore(MachineInstr *Store, + MachineBasicBlock &MBB, + MachineBasicBlock::iterator &MII, + SmallSet<MachineInstr*, 4> &ReMatDefs, + BitVector &RegKills, + std::vector<MachineOperand*> &KillOps, + VirtRegMap &VRM) { + // If there is a dead store to this stack slot, nuke it now. + DOUT << "Removed dead store:\t" << *Store; + ++NumDSE; + SmallVector<unsigned, 2> KillRegs; + InvalidateKills(*Store, RegKills, KillOps, &KillRegs); + + MachineBasicBlock::iterator PrevMII = Store; + bool CheckDef = PrevMII != MBB.begin(); + if (CheckDef) --PrevMII; + + VRM.RemoveMachineInstrFromMaps(Store); + MBB.erase(Store); + + if (CheckDef) { + // Look at defs of killed registers on the store. Mark the defs as dead + // since the store has been deleted and they aren't being reused. + for (unsigned j = 0, ee = KillRegs.size(); j != ee; ++j) { + bool HasOtherDef = false; + + if (InvalidateRegDef(PrevMII, *MII, KillRegs[j], HasOtherDef)) { + MachineInstr *DeadDef = PrevMII; + + if (ReMatDefs.count(DeadDef) && !HasOtherDef) { + // FIXME: This assumes a remat def does not have side effects. + VRM.RemoveMachineInstrFromMaps(DeadDef); + MBB.erase(DeadDef); + ++NumDRM; + } + } + } + } +} + /// SpillRegToStackSlot - Spill a register to a specified stack slot. Check if /// the last store to the same slot is now dead. If so, remove the last store. -void LocalSpiller::SpillRegToStackSlot(MachineBasicBlock &MBB, +void +LocalSpiller::SpillRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MII, int Idx, unsigned PhysReg, int StackSlot, const TargetRegisterClass *RC, @@ -816,36 +872,8 @@ void LocalSpiller::SpillRegToStackSlot(MachineBasicBlock &MBB, DOUT << "Store:\t" << *StoreMI; // If there is a dead store to this stack slot, nuke it now. - if (LastStore) { - DOUT << "Removed dead store:\t" << *LastStore; - ++NumDSE; - SmallVector<unsigned, 2> KillRegs; - InvalidateKills(*LastStore, RegKills, KillOps, &KillRegs); - MachineBasicBlock::iterator PrevMII = LastStore; - bool CheckDef = PrevMII != MBB.begin(); - if (CheckDef) - --PrevMII; - VRM.RemoveMachineInstrFromMaps(LastStore); - MBB.erase(LastStore); - if (CheckDef) { - // Look at defs of killed registers on the store. Mark the defs - // as dead since the store has been deleted and they aren't - // being reused. - for (unsigned j = 0, ee = KillRegs.size(); j != ee; ++j) { - bool HasOtherDef = false; - if (InvalidateRegDef(PrevMII, *MII, KillRegs[j], HasOtherDef)) { - MachineInstr *DeadDef = PrevMII; - if (ReMatDefs.count(DeadDef) && !HasOtherDef) { - // FIXME: This assumes a remat def does not have side - // effects. - VRM.RemoveMachineInstrFromMaps(DeadDef); - MBB.erase(DeadDef); - ++NumDRM; - } - } - } - } - } + if (LastStore) + RemoveDeadStore(LastStore, MBB, MII, ReMatDefs, RegKills, KillOps, VRM); LastStore = next(MII); @@ -1060,6 +1088,7 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM, if (VRM.isSpillPt(&MI)) { std::vector<std::pair<unsigned,bool> > &SpillRegs = VRM.getSpillPtSpills(&MI); + for (unsigned i = 0, e = SpillRegs.size(); i != e; ++i) { unsigned VirtReg = SpillRegs[i].first; bool isKill = SpillRegs[i].second; @@ -1073,7 +1102,9 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM, VRM.addSpillSlotUse(StackSlot, StoreMI); DOUT << "Store:\t" << *StoreMI; VRM.virtFolded(VirtReg, StoreMI, VirtRegMap::isMod); + AddedSpills.push_back(StoreMI); } + NextMII = next(MII); } |