forked from OSchip/llvm-project
Teach VirtRegRewriter to update slot indexes when erasing instructions.
It was leaving dangling pointers in the slot index maps. llvm-svn: 123334
This commit is contained in:
parent
71a3853332
commit
013c4649c0
|
@ -1056,6 +1056,7 @@ class LocalRewriter : public VirtRegRewriter {
|
||||||
const TargetRegisterInfo *TRI;
|
const TargetRegisterInfo *TRI;
|
||||||
const TargetInstrInfo *TII;
|
const TargetInstrInfo *TII;
|
||||||
VirtRegMap *VRM;
|
VirtRegMap *VRM;
|
||||||
|
LiveIntervals *LIs;
|
||||||
BitVector AllocatableRegs;
|
BitVector AllocatableRegs;
|
||||||
DenseMap<MachineInstr*, unsigned> DistanceMap;
|
DenseMap<MachineInstr*, unsigned> DistanceMap;
|
||||||
DenseMap<int, SmallVector<MachineInstr*,4> > Slot2DbgValues;
|
DenseMap<int, SmallVector<MachineInstr*,4> > Slot2DbgValues;
|
||||||
|
@ -1068,6 +1069,11 @@ public:
|
||||||
LiveIntervals* LIs);
|
LiveIntervals* LIs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void EraseInstr(MachineInstr *MI) {
|
||||||
|
VRM->RemoveMachineInstrFromMaps(MI);
|
||||||
|
LIs->RemoveMachineInstrFromMaps(MI);
|
||||||
|
MI->eraseFromParent();
|
||||||
|
}
|
||||||
|
|
||||||
bool OptimizeByUnfold2(unsigned VirtReg, int SS,
|
bool OptimizeByUnfold2(unsigned VirtReg, int SS,
|
||||||
MachineBasicBlock::iterator &MII,
|
MachineBasicBlock::iterator &MII,
|
||||||
|
@ -1123,11 +1129,12 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LocalRewriter::runOnMachineFunction(MachineFunction &MF, VirtRegMap &vrm,
|
bool LocalRewriter::runOnMachineFunction(MachineFunction &MF, VirtRegMap &vrm,
|
||||||
LiveIntervals* LIs) {
|
LiveIntervals* lis) {
|
||||||
MRI = &MF.getRegInfo();
|
MRI = &MF.getRegInfo();
|
||||||
TRI = MF.getTarget().getRegisterInfo();
|
TRI = MF.getTarget().getRegisterInfo();
|
||||||
TII = MF.getTarget().getInstrInfo();
|
TII = MF.getTarget().getInstrInfo();
|
||||||
VRM = &vrm;
|
VRM = &vrm;
|
||||||
|
LIs = lis;
|
||||||
AllocatableRegs = TRI->getAllocatableSet(MF);
|
AllocatableRegs = TRI->getAllocatableSet(MF);
|
||||||
DEBUG(dbgs() << "\n**** Local spiller rewriting function '"
|
DEBUG(dbgs() << "\n**** Local spiller rewriting function '"
|
||||||
<< MF.getFunction()->getName() << "':\n");
|
<< MF.getFunction()->getName() << "':\n");
|
||||||
|
@ -1196,10 +1203,8 @@ bool LocalRewriter::runOnMachineFunction(MachineFunction &MF, VirtRegMap &vrm,
|
||||||
MFI->RemoveStackObject(SS);
|
MFI->RemoveStackObject(SS);
|
||||||
for (unsigned j = 0, ee = DbgValues.size(); j != ee; ++j) {
|
for (unsigned j = 0, ee = DbgValues.size(); j != ee; ++j) {
|
||||||
MachineInstr *DVMI = DbgValues[j];
|
MachineInstr *DVMI = DbgValues[j];
|
||||||
MachineBasicBlock *DVMBB = DVMI->getParent();
|
|
||||||
DEBUG(dbgs() << "Removing debug info referencing FI#" << SS << '\n');
|
DEBUG(dbgs() << "Removing debug info referencing FI#" << SS << '\n');
|
||||||
VRM->RemoveMachineInstrFromMaps(DVMI);
|
EraseInstr(DVMI);
|
||||||
DVMBB->erase(DVMI);
|
|
||||||
}
|
}
|
||||||
++NumDSS;
|
++NumDSS;
|
||||||
}
|
}
|
||||||
|
@ -1279,8 +1284,7 @@ OptimizeByUnfold2(unsigned VirtReg, int SS,
|
||||||
VRM->transferRestorePts(&MI, NewMIs[0]);
|
VRM->transferRestorePts(&MI, NewMIs[0]);
|
||||||
MII = MBB->insert(MII, NewMIs[0]);
|
MII = MBB->insert(MII, NewMIs[0]);
|
||||||
InvalidateKills(MI, TRI, RegKills, KillOps);
|
InvalidateKills(MI, TRI, RegKills, KillOps);
|
||||||
VRM->RemoveMachineInstrFromMaps(&MI);
|
EraseInstr(&MI);
|
||||||
MBB->erase(&MI);
|
|
||||||
++NumModRefUnfold;
|
++NumModRefUnfold;
|
||||||
|
|
||||||
// Unfold next instructions that fold the same SS.
|
// Unfold next instructions that fold the same SS.
|
||||||
|
@ -1295,8 +1299,7 @@ OptimizeByUnfold2(unsigned VirtReg, int SS,
|
||||||
VRM->transferRestorePts(&NextMI, NewMIs[0]);
|
VRM->transferRestorePts(&NextMI, NewMIs[0]);
|
||||||
MBB->insert(NextMII, NewMIs[0]);
|
MBB->insert(NextMII, NewMIs[0]);
|
||||||
InvalidateKills(NextMI, TRI, RegKills, KillOps);
|
InvalidateKills(NextMI, TRI, RegKills, KillOps);
|
||||||
VRM->RemoveMachineInstrFromMaps(&NextMI);
|
EraseInstr(&NextMI);
|
||||||
MBB->erase(&NextMI);
|
|
||||||
++NumModRefUnfold;
|
++NumModRefUnfold;
|
||||||
// Skip over dbg_value instructions.
|
// Skip over dbg_value instructions.
|
||||||
while (NextMII != MBB->end() && NextMII->isDebugValue())
|
while (NextMII != MBB->end() && NextMII->isDebugValue())
|
||||||
|
@ -1423,8 +1426,7 @@ OptimizeByUnfold(MachineBasicBlock::iterator &MII,
|
||||||
VRM->virtFolded(VirtReg, FoldedMI, VirtRegMap::isRef);
|
VRM->virtFolded(VirtReg, FoldedMI, VirtRegMap::isRef);
|
||||||
MII = FoldedMI;
|
MII = FoldedMI;
|
||||||
InvalidateKills(MI, TRI, RegKills, KillOps);
|
InvalidateKills(MI, TRI, RegKills, KillOps);
|
||||||
VRM->RemoveMachineInstrFromMaps(&MI);
|
EraseInstr(&MI);
|
||||||
MBB->erase(&MI);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1530,14 +1532,11 @@ CommuteToFoldReload(MachineBasicBlock::iterator &MII,
|
||||||
|
|
||||||
// Delete all 3 old instructions.
|
// Delete all 3 old instructions.
|
||||||
InvalidateKills(*ReloadMI, TRI, RegKills, KillOps);
|
InvalidateKills(*ReloadMI, TRI, RegKills, KillOps);
|
||||||
VRM->RemoveMachineInstrFromMaps(ReloadMI);
|
EraseInstr(ReloadMI);
|
||||||
MBB->erase(ReloadMI);
|
|
||||||
InvalidateKills(*DefMI, TRI, RegKills, KillOps);
|
InvalidateKills(*DefMI, TRI, RegKills, KillOps);
|
||||||
VRM->RemoveMachineInstrFromMaps(DefMI);
|
EraseInstr(DefMI);
|
||||||
MBB->erase(DefMI);
|
|
||||||
InvalidateKills(MI, TRI, RegKills, KillOps);
|
InvalidateKills(MI, TRI, RegKills, KillOps);
|
||||||
VRM->RemoveMachineInstrFromMaps(&MI);
|
EraseInstr(&MI);
|
||||||
MBB->erase(&MI);
|
|
||||||
|
|
||||||
// If NewReg was previously holding value of some SS, it's now clobbered.
|
// If NewReg was previously holding value of some SS, it's now clobbered.
|
||||||
// This has to be done now because it's a physical register. When this
|
// This has to be done now because it's a physical register. When this
|
||||||
|
@ -1580,8 +1579,7 @@ SpillRegToStackSlot(MachineBasicBlock::iterator &MII,
|
||||||
bool CheckDef = PrevMII != MBB->begin();
|
bool CheckDef = PrevMII != MBB->begin();
|
||||||
if (CheckDef)
|
if (CheckDef)
|
||||||
--PrevMII;
|
--PrevMII;
|
||||||
VRM->RemoveMachineInstrFromMaps(LastStore);
|
EraseInstr(LastStore);
|
||||||
MBB->erase(LastStore);
|
|
||||||
if (CheckDef) {
|
if (CheckDef) {
|
||||||
// Look at defs of killed registers on the store. Mark the defs
|
// Look at defs of killed registers on the store. Mark the defs
|
||||||
// as dead since the store has been deleted and they aren't
|
// as dead since the store has been deleted and they aren't
|
||||||
|
@ -1592,8 +1590,7 @@ SpillRegToStackSlot(MachineBasicBlock::iterator &MII,
|
||||||
MachineInstr *DeadDef = PrevMII;
|
MachineInstr *DeadDef = PrevMII;
|
||||||
if (ReMatDefs.count(DeadDef) && !HasOtherDef) {
|
if (ReMatDefs.count(DeadDef) && !HasOtherDef) {
|
||||||
// FIXME: This assumes a remat def does not have side effects.
|
// FIXME: This assumes a remat def does not have side effects.
|
||||||
VRM->RemoveMachineInstrFromMaps(DeadDef);
|
EraseInstr(DeadDef);
|
||||||
MBB->erase(DeadDef);
|
|
||||||
++NumDRM;
|
++NumDRM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1689,8 +1686,7 @@ TransferDeadness(unsigned Reg, BitVector &RegKills,
|
||||||
LastUD->setIsDead();
|
LastUD->setIsDead();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
VRM->RemoveMachineInstrFromMaps(LastUDMI);
|
EraseInstr(LastUDMI);
|
||||||
MBB->erase(LastUDMI);
|
|
||||||
} else {
|
} else {
|
||||||
LastUD->setIsKill();
|
LastUD->setIsKill();
|
||||||
RegKills.set(Reg);
|
RegKills.set(Reg);
|
||||||
|
@ -2203,8 +2199,7 @@ void LocalRewriter::ProcessUses(MachineInstr &MI, AvailableSpills &Spills,
|
||||||
if (DeadStore) {
|
if (DeadStore) {
|
||||||
DEBUG(dbgs() << "Removed dead store:\t" << *DeadStore);
|
DEBUG(dbgs() << "Removed dead store:\t" << *DeadStore);
|
||||||
InvalidateKills(*DeadStore, TRI, RegKills, KillOps);
|
InvalidateKills(*DeadStore, TRI, RegKills, KillOps);
|
||||||
VRM->RemoveMachineInstrFromMaps(DeadStore);
|
EraseInstr(DeadStore);
|
||||||
MBB->erase(DeadStore);
|
|
||||||
MaybeDeadStores[PDSSlot] = NULL;
|
MaybeDeadStores[PDSSlot] = NULL;
|
||||||
++NumDSE;
|
++NumDSE;
|
||||||
}
|
}
|
||||||
|
@ -2332,8 +2327,7 @@ LocalRewriter::RewriteMBB(LiveIntervals *LIs,
|
||||||
}
|
}
|
||||||
|
|
||||||
InvalidateKills(MI, TRI, RegKills, KillOps);
|
InvalidateKills(MI, TRI, RegKills, KillOps);
|
||||||
VRM->RemoveMachineInstrFromMaps(&MI);
|
EraseInstr(&MI);
|
||||||
MBB->erase(&MI);
|
|
||||||
Erased = true;
|
Erased = true;
|
||||||
goto ProcessNextInst;
|
goto ProcessNextInst;
|
||||||
}
|
}
|
||||||
|
@ -2344,8 +2338,7 @@ LocalRewriter::RewriteMBB(LiveIntervals *LIs,
|
||||||
TII->unfoldMemoryOperand(MF, &MI, PhysReg, false, false, NewMIs)){
|
TII->unfoldMemoryOperand(MF, &MI, PhysReg, false, false, NewMIs)){
|
||||||
MBB->insert(MII, NewMIs[0]);
|
MBB->insert(MII, NewMIs[0]);
|
||||||
InvalidateKills(MI, TRI, RegKills, KillOps);
|
InvalidateKills(MI, TRI, RegKills, KillOps);
|
||||||
VRM->RemoveMachineInstrFromMaps(&MI);
|
EraseInstr(&MI);
|
||||||
MBB->erase(&MI);
|
|
||||||
Erased = true;
|
Erased = true;
|
||||||
--NextMII; // backtrack to the unfolded instruction.
|
--NextMII; // backtrack to the unfolded instruction.
|
||||||
BackTracked = true;
|
BackTracked = true;
|
||||||
|
@ -2381,8 +2374,7 @@ LocalRewriter::RewriteMBB(LiveIntervals *LIs,
|
||||||
MBB->insert(MII, NewStore);
|
MBB->insert(MII, NewStore);
|
||||||
VRM->addSpillSlotUse(SS, NewStore);
|
VRM->addSpillSlotUse(SS, NewStore);
|
||||||
InvalidateKills(MI, TRI, RegKills, KillOps);
|
InvalidateKills(MI, TRI, RegKills, KillOps);
|
||||||
VRM->RemoveMachineInstrFromMaps(&MI);
|
EraseInstr(&MI);
|
||||||
MBB->erase(&MI);
|
|
||||||
Erased = true;
|
Erased = true;
|
||||||
--NextMII;
|
--NextMII;
|
||||||
--NextMII; // backtrack to the unfolded instruction.
|
--NextMII; // backtrack to the unfolded instruction.
|
||||||
|
@ -2397,8 +2389,7 @@ LocalRewriter::RewriteMBB(LiveIntervals *LIs,
|
||||||
// If we get here, the store is dead, nuke it now.
|
// If we get here, the store is dead, nuke it now.
|
||||||
DEBUG(dbgs() << "Removed dead store:\t" << *DeadStore);
|
DEBUG(dbgs() << "Removed dead store:\t" << *DeadStore);
|
||||||
InvalidateKills(*DeadStore, TRI, RegKills, KillOps);
|
InvalidateKills(*DeadStore, TRI, RegKills, KillOps);
|
||||||
VRM->RemoveMachineInstrFromMaps(DeadStore);
|
EraseInstr(DeadStore);
|
||||||
MBB->erase(DeadStore);
|
|
||||||
if (!NewStore)
|
if (!NewStore)
|
||||||
++NumDSE;
|
++NumDSE;
|
||||||
}
|
}
|
||||||
|
@ -2475,8 +2466,7 @@ LocalRewriter::RewriteMBB(LiveIntervals *LIs,
|
||||||
// Last def is now dead.
|
// Last def is now dead.
|
||||||
TransferDeadness(MI.getOperand(1).getReg(), RegKills, KillOps);
|
TransferDeadness(MI.getOperand(1).getReg(), RegKills, KillOps);
|
||||||
}
|
}
|
||||||
VRM->RemoveMachineInstrFromMaps(&MI);
|
EraseInstr(&MI);
|
||||||
MBB->erase(&MI);
|
|
||||||
Erased = true;
|
Erased = true;
|
||||||
Spills.disallowClobberPhysReg(VirtReg);
|
Spills.disallowClobberPhysReg(VirtReg);
|
||||||
goto ProcessNextInst;
|
goto ProcessNextInst;
|
||||||
|
@ -2552,8 +2542,7 @@ LocalRewriter::RewriteMBB(LiveIntervals *LIs,
|
||||||
++NumDCE;
|
++NumDCE;
|
||||||
DEBUG(dbgs() << "Removing now-noop copy: " << MI);
|
DEBUG(dbgs() << "Removing now-noop copy: " << MI);
|
||||||
InvalidateKills(MI, TRI, RegKills, KillOps);
|
InvalidateKills(MI, TRI, RegKills, KillOps);
|
||||||
VRM->RemoveMachineInstrFromMaps(&MI);
|
EraseInstr(&MI);
|
||||||
MBB->erase(&MI);
|
|
||||||
Erased = true;
|
Erased = true;
|
||||||
UpdateKills(*LastStore, TRI, RegKills, KillOps);
|
UpdateKills(*LastStore, TRI, RegKills, KillOps);
|
||||||
goto ProcessNextInst;
|
goto ProcessNextInst;
|
||||||
|
@ -2564,8 +2553,7 @@ LocalRewriter::RewriteMBB(LiveIntervals *LIs,
|
||||||
// Delete dead instructions without side effects.
|
// Delete dead instructions without side effects.
|
||||||
if (!Erased && !BackTracked && isSafeToDelete(MI)) {
|
if (!Erased && !BackTracked && isSafeToDelete(MI)) {
|
||||||
InvalidateKills(MI, TRI, RegKills, KillOps);
|
InvalidateKills(MI, TRI, RegKills, KillOps);
|
||||||
VRM->RemoveMachineInstrFromMaps(&MI);
|
EraseInstr(&MI);
|
||||||
MBB->erase(&MI);
|
|
||||||
Erased = true;
|
Erased = true;
|
||||||
}
|
}
|
||||||
if (!Erased)
|
if (!Erased)
|
||||||
|
|
Loading…
Reference in New Issue