InsertPointAnalysis: Move current live interval from being a class member

to query interfaces argument; NFC

Differential Revision: http://reviews.llvm.org/D20532

llvm-svn: 270481
This commit is contained in:
Wei Mi 2016-05-23 19:39:19 +00:00
parent e45207608c
commit f3c8f532d2
3 changed files with 22 additions and 24 deletions

View File

@ -1079,7 +1079,8 @@ bool HoistSpillHelper::rmFromMergeableSpills(MachineInstr *Spill,
bool HoistSpillHelper::isSpillCandBB(unsigned OrigReg, VNInfo &OrigVNI, bool HoistSpillHelper::isSpillCandBB(unsigned OrigReg, VNInfo &OrigVNI,
MachineBasicBlock &BB, unsigned &LiveReg) { MachineBasicBlock &BB, unsigned &LiveReg) {
SlotIndex Idx; SlotIndex Idx;
MachineBasicBlock::iterator MI = IPA.getLastInsertPointIter(BB); LiveInterval &OrigLI = LIS.getInterval(OrigReg);
MachineBasicBlock::iterator MI = IPA.getLastInsertPointIter(OrigLI, BB);
if (MI != BB.end()) if (MI != BB.end())
Idx = LIS.getInstructionIndex(*MI); Idx = LIS.getInstructionIndex(*MI);
else else
@ -1381,7 +1382,6 @@ void HoistSpillHelper::hoistAllSpills() {
int Slot = Ent.first.first; int Slot = Ent.first.first;
unsigned OrigReg = SlotToOrigReg[Slot]; unsigned OrigReg = SlotToOrigReg[Slot];
LiveInterval &OrigLI = LIS.getInterval(OrigReg); LiveInterval &OrigLI = LIS.getInterval(OrigReg);
IPA.setInterval(&OrigLI);
VNInfo *OrigVNI = Ent.first.second; VNInfo *OrigVNI = Ent.first.second;
SmallPtrSet<MachineInstr *, 16> &EqValSpills = Ent.second; SmallPtrSet<MachineInstr *, 16> &EqValSpills = Ent.second;
if (Ent.second.empty()) if (Ent.second.empty())
@ -1422,7 +1422,7 @@ void HoistSpillHelper::hoistAllSpills() {
for (auto const Insert : SpillsToIns) { for (auto const Insert : SpillsToIns) {
MachineBasicBlock *BB = Insert.first; MachineBasicBlock *BB = Insert.first;
unsigned LiveReg = Insert.second; unsigned LiveReg = Insert.second;
MachineBasicBlock::iterator MI = IPA.getLastInsertPointIter(*BB); MachineBasicBlock::iterator MI = IPA.getLastInsertPointIter(OrigLI, *BB);
TII.storeRegToStackSlot(*BB, MI, LiveReg, false, Slot, TII.storeRegToStackSlot(*BB, MI, LiveReg, false, Slot,
MRI.getRegClass(LiveReg), &TRI); MRI.getRegClass(LiveReg), &TRI);
LIS.InsertMachineInstrRangeInMaps(std::prev(MI), MI); LIS.InsertMachineInstrRangeInMaps(std::prev(MI), MI);

View File

@ -43,10 +43,11 @@ STATISTIC(NumRepairs, "Number of invalid live ranges repaired");
InsertPointAnalysis::InsertPointAnalysis(const LiveIntervals &lis, InsertPointAnalysis::InsertPointAnalysis(const LiveIntervals &lis,
unsigned BBNum) unsigned BBNum)
: LIS(lis), CurLI(nullptr), LastInsertPoint(BBNum) {} : LIS(lis), LastInsertPoint(BBNum) {}
SlotIndex SlotIndex
InsertPointAnalysis::computeLastInsertPoint(const MachineBasicBlock &MBB) { InsertPointAnalysis::computeLastInsertPoint(const LiveInterval &CurLI,
const MachineBasicBlock &MBB) {
unsigned Num = MBB.getNumber(); unsigned Num = MBB.getNumber();
std::pair<SlotIndex, SlotIndex> &LIP = LastInsertPoint[Num]; std::pair<SlotIndex, SlotIndex> &LIP = LastInsertPoint[Num];
SlotIndex MBBEnd = LIS.getMBBEndIdx(&MBB); SlotIndex MBBEnd = LIS.getMBBEndIdx(&MBB);
@ -85,14 +86,13 @@ InsertPointAnalysis::computeLastInsertPoint(const MachineBasicBlock &MBB) {
if (!LIP.second) if (!LIP.second)
return LIP.first; return LIP.first;
assert(CurLI && "CurLI not being set");
if (none_of(EHPadSucessors, [&](const MachineBasicBlock *EHPad) { if (none_of(EHPadSucessors, [&](const MachineBasicBlock *EHPad) {
return LIS.isLiveInToMBB(*CurLI, EHPad); return LIS.isLiveInToMBB(CurLI, EHPad);
})) }))
return LIP.first; return LIP.first;
// Find the value leaving MBB. // Find the value leaving MBB.
const VNInfo *VNI = CurLI->getVNInfoBefore(MBBEnd); const VNInfo *VNI = CurLI.getVNInfoBefore(MBBEnd);
if (!VNI) if (!VNI)
return LIP.first; return LIP.first;
@ -109,8 +109,9 @@ InsertPointAnalysis::computeLastInsertPoint(const MachineBasicBlock &MBB) {
} }
MachineBasicBlock::iterator MachineBasicBlock::iterator
InsertPointAnalysis::getLastInsertPointIter(MachineBasicBlock &MBB) { InsertPointAnalysis::getLastInsertPointIter(const LiveInterval &CurLI,
SlotIndex LIP = getLastInsertPoint(MBB); MachineBasicBlock &MBB) {
SlotIndex LIP = getLastInsertPoint(CurLI, MBB);
if (LIP == LIS.getMBBEndIdx(&MBB)) if (LIP == LIS.getMBBEndIdx(&MBB))
return MBB.end(); return MBB.end();
return LIS.getInstructionFromIndex(LIP); return LIS.getInstructionFromIndex(LIP);
@ -328,7 +329,6 @@ bool SplitAnalysis::isOriginalEndpoint(SlotIndex Idx) const {
void SplitAnalysis::analyze(const LiveInterval *li) { void SplitAnalysis::analyze(const LiveInterval *li) {
clear(); clear();
CurLI = li; CurLI = li;
IPA.setInterval(li);
analyzeUses(); analyzeUses();
} }

View File

@ -44,34 +44,32 @@ class LLVM_LIBRARY_VISIBILITY InsertPointAnalysis {
private: private:
const LiveIntervals &LIS; const LiveIntervals &LIS;
/// Current LiveInterval for which to insert split or spill.
const LiveInterval *CurLI;
/// Last legal insert point in each basic block in the current function. /// Last legal insert point in each basic block in the current function.
/// The first entry is the first terminator, the second entry is the /// The first entry is the first terminator, the second entry is the
/// last valid point to insert a split or spill for a variable that is /// last valid point to insert a split or spill for a variable that is
/// live into a landing pad successor. /// live into a landing pad successor.
SmallVector<std::pair<SlotIndex, SlotIndex>, 8> LastInsertPoint; SmallVector<std::pair<SlotIndex, SlotIndex>, 8> LastInsertPoint;
SlotIndex computeLastInsertPoint(const MachineBasicBlock &MBB); SlotIndex computeLastInsertPoint(const LiveInterval &CurLI,
const MachineBasicBlock &MBB);
public: public:
InsertPointAnalysis(const LiveIntervals &lis, unsigned BBNum); InsertPointAnalysis(const LiveIntervals &lis, unsigned BBNum);
void setInterval(const LiveInterval *LI) { CurLI = LI; } /// Return the base index of the last valid insert point for \pCurLI in \pMBB.
SlotIndex getLastInsertPoint(const LiveInterval &CurLI,
/// Return the base index of the last valid insert point in \pMBB. const MachineBasicBlock &MBB) {
SlotIndex getLastInsertPoint(const MachineBasicBlock &MBB) {
unsigned Num = MBB.getNumber(); unsigned Num = MBB.getNumber();
// Inline the common simple case. // Inline the common simple case.
if (LastInsertPoint[Num].first.isValid() && if (LastInsertPoint[Num].first.isValid() &&
!LastInsertPoint[Num].second.isValid()) !LastInsertPoint[Num].second.isValid())
return LastInsertPoint[Num].first; return LastInsertPoint[Num].first;
return computeLastInsertPoint(MBB); return computeLastInsertPoint(CurLI, MBB);
} }
/// Returns the last insert point as an iterator. /// Returns the last insert point as an iterator for \pCurLI in \pMBB.
MachineBasicBlock::iterator getLastInsertPointIter(MachineBasicBlock &); MachineBasicBlock::iterator getLastInsertPointIter(const LiveInterval &CurLI,
MachineBasicBlock &MBB);
}; };
/// SplitAnalysis - Analyze a LiveInterval, looking for live range splitting /// SplitAnalysis - Analyze a LiveInterval, looking for live range splitting
@ -215,11 +213,11 @@ public:
bool shouldSplitSingleBlock(const BlockInfo &BI, bool SingleInstrs) const; bool shouldSplitSingleBlock(const BlockInfo &BI, bool SingleInstrs) const;
SlotIndex getLastSplitPoint(unsigned Num) { SlotIndex getLastSplitPoint(unsigned Num) {
return IPA.getLastInsertPoint(*MF.getBlockNumbered(Num)); return IPA.getLastInsertPoint(*CurLI, *MF.getBlockNumbered(Num));
} }
MachineBasicBlock::iterator getLastSplitPointIter(MachineBasicBlock *BB) { MachineBasicBlock::iterator getLastSplitPointIter(MachineBasicBlock *BB) {
return IPA.getLastInsertPointIter(*BB); return IPA.getLastInsertPointIter(*CurLI, *BB);
} }
}; };