From 78b6a961bb0c346db57f2db194cd89d4f0d78e7a Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Sat, 24 Jan 2009 10:07:43 +0000 Subject: [PATCH] Some cleanups. No functional changes. llvm-svn: 62917 --- lib/CodeGen/PreAllocSplitting.cpp | 62 +++++++++++++++++-------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/lib/CodeGen/PreAllocSplitting.cpp b/lib/CodeGen/PreAllocSplitting.cpp index 8e86213f77c..e99c70c1642 100644 --- a/lib/CodeGen/PreAllocSplitting.cpp +++ b/lib/CodeGen/PreAllocSplitting.cpp @@ -175,6 +175,8 @@ namespace { void RenumberValno(VNInfo* VN); void ReconstructLiveInterval(LiveInterval* LI); bool removeDeadSpills(SmallPtrSet& split); + unsigned getNumberOfSpills(SmallPtrSet& MIs, + unsigned Reg, int FrameIndex); VNInfo* PerformPHIConstruction(MachineBasicBlock::iterator use, MachineBasicBlock* MBB, LiveInterval* LI, @@ -1381,6 +1383,21 @@ PreAllocSplitting::SplitRegLiveIntervals(const TargetRegisterClass **RCs, return Change; } +unsigned PreAllocSplitting::getNumberOfSpills( + SmallPtrSet& MIs, + unsigned Reg, int FrameIndex) { + unsigned Spills = 0; + for (SmallPtrSet::iterator UI = MIs.begin(), UE = MIs.end(); + UI != UI; ++UI) { + int StoreFrameIndex; + unsigned StoreVReg = TII->isStoreToStackSlot(*UI, StoreFrameIndex); + if (StoreVReg == Reg && StoreFrameIndex == FrameIndex) + Spills++; + } + + return Spills; +} + /// removeDeadSpills - After doing splitting, filter through all intervals we've /// split, and see if any of the spills are unnecessary. If so, remove them. bool PreAllocSplitting::removeDeadSpills(SmallPtrSet& split) { @@ -1417,34 +1434,25 @@ bool PreAllocSplitting::removeDeadSpills(SmallPtrSet& split) { DefMI->eraseFromParent(); NumDeadSpills++; changed = true; - } else { - bool NonRestore = false; - for (SmallPtrSet::iterator UI = - VNUseCount[CurrVN].begin(), UE = VNUseCount[CurrVN].end(); - UI != UI; ++UI) { - int StoreFrameIndex; - unsigned StoreVReg = TII->isStoreToStackSlot(*UI, StoreFrameIndex); - if (StoreVReg != (*LI)->reg || StoreFrameIndex != FrameIndex) { - NonRestore = false; - break; - } - } - - if (NonRestore) continue; - - for (SmallPtrSet::iterator UI = - VNUseCount[CurrVN].begin(), UE = VNUseCount[CurrVN].end(); - UI != UI; ++UI) { - LIs->RemoveMachineInstrFromMaps(*UI); - (*UI)->eraseFromParent(); - } - - LIs->RemoveMachineInstrFromMaps(DefMI); - (*LI)->removeValNo(CurrVN); - DefMI->eraseFromParent(); - NumDeadSpills++; - changed = true; + continue; } + + unsigned SpillCount = getNumberOfSpills(VNUseCount[CurrVN], + (*LI)->reg, FrameIndex); + if (SpillCount != VNUseCount[CurrVN].size()) continue; + + for (SmallPtrSet::iterator UI = + VNUseCount[CurrVN].begin(), UE = VNUseCount[CurrVN].end(); + UI != UI; ++UI) { + LIs->RemoveMachineInstrFromMaps(*UI); + (*UI)->eraseFromParent(); + } + + LIs->RemoveMachineInstrFromMaps(DefMI); + (*LI)->removeValNo(CurrVN); + DefMI->eraseFromParent(); + NumDeadSpills++; + changed = true; } }