diff options
Diffstat (limited to 'lib/CodeGen/VirtRegMap.cpp')
-rw-r--r-- | lib/CodeGen/VirtRegMap.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/CodeGen/VirtRegMap.cpp b/lib/CodeGen/VirtRegMap.cpp index a4d0733e88..8e6ff027e9 100644 --- a/lib/CodeGen/VirtRegMap.cpp +++ b/lib/CodeGen/VirtRegMap.cpp @@ -35,6 +35,7 @@ namespace { Statistic<> NumStores("spiller", "Number of stores added"); Statistic<> NumLoads ("spiller", "Number of loads added"); Statistic<> NumReused("spiller", "Number of values reused"); + Statistic<> NumDSE ("spiller", "Number of dead stores elided"); enum SpillerName { simple, local }; @@ -283,6 +284,14 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) { // and ".second" is the virtual register that is spilled. std::vector<std::pair<unsigned, unsigned> > DefAndUseVReg; + // MaybeDeadStores - When we need to write a value back into a stack slot, + // keep track of the inserted store. If the stack slot value is never read + // (because the value was used from some available register, for example), and + // subsequently stored to, the original store is dead. This map keeps track + // of inserted stores that are not used. If we see a subsequent store to the + // same stack slot, the original store is deleted. + std::map<int, MachineInstr*> MaybeDeadStores; + for (MachineBasicBlock::iterator MII = MBB.begin(), E = MBB.end(); MII != E; ) { MachineInstr &MI = *MII; @@ -361,6 +370,9 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) { ClobberPhysReg(Op.AssignedPhysReg, SpillSlotsAvailable, PhysRegsAvailable); + // Any stores to this stack slot are not dead anymore. + MaybeDeadStores.erase(Op.StackSlot); + MI.SetMachineOperandReg(Op.Operand, Op.AssignedPhysReg); PhysRegsAvailable[Op.AssignedPhysReg] = Op.StackSlot; SpillSlotsAvailable[Op.StackSlot] = Op.AssignedPhysReg; @@ -383,6 +395,9 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) { // This invalidates PhysReg. ClobberPhysReg(PhysReg, SpillSlotsAvailable, PhysRegsAvailable); + // Any stores to this stack slot are not dead anymore. + MaybeDeadStores.erase(StackSlot); + MI.SetMachineOperandReg(i, PhysReg); PhysRegsAvailable[PhysReg] = StackSlot; SpillSlotsAvailable[StackSlot] = PhysReg; @@ -423,6 +438,9 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) { int SS = VRM.getStackSlot(I->second); DEBUG(std::cerr << " - StackSlot: " << SS << "\n"); + // Any stores to this stack slot are not dead anymore. + MaybeDeadStores.erase(SS); + std::map<int, unsigned>::iterator I = SpillSlotsAvailable.find(SS); if (I != SpillSlotsAvailable.end()) { PhysRegsAvailable.erase(I->second); @@ -476,6 +494,14 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) { DEBUG(std::cerr << "Store:\t" << *next(MII)); MI.SetMachineOperandReg(i, PhysReg); + // If there is a dead store to this stack slot, nuke it now. + MachineInstr *&LastStore = MaybeDeadStores[StackSlot]; + if (LastStore) { + ++NumDSE; + MBB.erase(LastStore); + } + LastStore = next(MII); + // If the stack slot value was previously available in some other // register, change it now. Otherwise, make the register available, // in PhysReg. |