Added an API to the SlotIndexes pass to allow new instructions to be inserted into the numbering.

PreAllocSplitting is now using this API to insert code.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@88725 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Lang Hames 2009-11-14 00:02:51 +00:00
parent 1f6a3c820a
commit b3661585c0
5 changed files with 98 additions and 178 deletions

View File

@ -189,20 +189,8 @@ namespace llvm {
return indexes_->getMBBFromIndex(index); return indexes_->getMBBFromIndex(index);
} }
bool hasGapBeforeInstr(SlotIndex index) { SlotIndex InsertMachineInstrInMaps(MachineInstr *MI) {
return indexes_->hasGapBeforeInstr(index); return indexes_->insertMachineInstrInMaps(MI);
}
bool hasGapAfterInstr(SlotIndex index) {
return indexes_->hasGapAfterInstr(index);
}
SlotIndex findGapBeforeInstr(SlotIndex index, bool furthest = false) {
return indexes_->findGapBeforeInstr(index, furthest);
}
void InsertMachineInstrInMaps(MachineInstr *MI, SlotIndex Index) {
indexes_->insertMachineInstrInMaps(MI, Index);
} }
void RemoveMachineInstrFromMaps(MachineInstr *MI) { void RemoveMachineInstrFromMaps(MachineInstr *MI) {
@ -219,7 +207,7 @@ namespace llvm {
} }
void renumber() { void renumber() {
indexes_->renumber(); indexes_->renumberIndexes();
} }
BumpPtrAllocator& getVNInfoAllocator() { return VNInfoAllocator; } BumpPtrAllocator& getVNInfoAllocator() { return VNInfoAllocator; }

View File

@ -487,7 +487,7 @@ namespace llvm {
void dump() const; void dump() const;
/// Renumber the index list, providing space for new instructions. /// Renumber the index list, providing space for new instructions.
void renumber(); void renumberIndexes();
/// Returns the zero index for this analysis. /// Returns the zero index for this analysis.
SlotIndex getZeroIndex() { SlotIndex getZeroIndex() {
@ -647,99 +647,89 @@ namespace llvm {
return 0; return 0;
} }
/// Returns true if there is a gap in the numbering before the given index. /// Insert the given machine instruction into the mapping. Returns the
bool hasGapBeforeInstr(SlotIndex index) { /// assigned index.
index = index.getBaseIndex(); SlotIndex insertMachineInstrInMaps(MachineInstr *mi,
SlotIndex prevIndex = index.getPrevIndex(); bool *deferredRenumber = 0) {
assert(mi2iMap.find(mi) == mi2iMap.end() && "Instr already indexed.");
if (prevIndex == getZeroIndex())
return false;
if (getInstructionFromIndex(prevIndex) == 0) MachineBasicBlock *mbb = mi->getParent();
return true;
if (prevIndex.distance(index) >= 2 * SlotIndex::NUM) assert(mbb != 0 && "Instr must be added to function.");
return true;
return false; MBB2IdxMap::iterator mbbRangeItr = mbb2IdxMap.find(mbb);
}
/// Returns true if there is a gap in the numbering after the given index. assert(mbbRangeItr != mbb2IdxMap.end() &&
bool hasGapAfterInstr(SlotIndex index) const { "Instruction's parent MBB has not been added to SlotIndexes.");
// Not implemented yet.
assert(false &&
"SlotIndexes::hasGapAfterInstr(SlotIndex) not implemented yet.");
return false;
}
/// findGapBeforeInstr - Find an empty instruction slot before the MachineBasicBlock::iterator miItr(mi);
/// specified index. If "Furthest" is true, find one that's furthest bool needRenumber = false;
/// away from the index (but before any index that's occupied). IndexListEntry *newEntry;
// FIXME: This whole method should go away in future. It should
// always be possible to insert code between existing indices.
SlotIndex findGapBeforeInstr(SlotIndex index, bool furthest = false) {
if (index == getZeroIndex())
return getInvalidIndex();
index = index.getBaseIndex(); IndexListEntry *prevEntry;
SlotIndex prevIndex = index.getPrevIndex(); if (miItr == mbb->begin()) {
// If mi is at the mbb beginning, get the prev index from the mbb.
if (prevIndex == getZeroIndex()) prevEntry = &mbbRangeItr->second.first.entry();
return getInvalidIndex(); } else {
// Otherwise get it from the previous instr.
// Try to reuse existing index objects with null-instrs. MachineBasicBlock::iterator pItr(prior(miItr));
if (getInstructionFromIndex(prevIndex) == 0) { prevEntry = &getInstructionIndex(pItr).entry();
if (furthest) {
while (getInstructionFromIndex(prevIndex) == 0 &&
prevIndex != getZeroIndex()) {
prevIndex = prevIndex.getPrevIndex();
}
prevIndex = prevIndex.getNextIndex();
}
assert(getInstructionFromIndex(prevIndex) == 0 && "Index list is broken.");
return prevIndex;
} }
int dist = prevIndex.distance(index); // Get next entry from previous entry.
IndexListEntry *nextEntry = prevEntry->getNext();
// Double check that the spacing between this instruction and // Get a number for the new instr, or 0 if there's no room currently.
// the last is sane. // In the latter case we'll force a renumber later.
assert(dist >= SlotIndex::NUM && unsigned dist = nextEntry->getIndex() - prevEntry->getIndex();
"Distance between indexes too small."); unsigned newNumber = dist > SlotIndex::NUM ?
prevEntry->getIndex() + ((dist >> 1) & ~3U) : 0;
// If there's no gap return an invalid index. if (newNumber == 0) {
if (dist < 2*SlotIndex::NUM) { needRenumber = true;
return getInvalidIndex();
} }
// Otherwise insert new index entries into the list using the // Insert a new list entry for mi.
// gap in the numbering. newEntry = createEntry(mi, newNumber);
IndexListEntry *newEntry = insert(nextEntry, newEntry);
createEntry(0, prevIndex.entry().getIndex() + SlotIndex::NUM);
SlotIndex newIndex(newEntry, SlotIndex::LOAD);
mi2iMap.insert(std::make_pair(mi, newIndex));
insert(&index.entry(), newEntry); if (miItr == mbb->end()) {
// If this is the last instr in the MBB then we need to fix up the bb
// range:
mbbRangeItr->second.second = SlotIndex(newIndex, SlotIndex::STORE);
}
// And return a pointer to the entry at the start of the gap. // Renumber if we need to.
return index.getPrevIndex(); if (needRenumber) {
if (deferredRenumber == 0)
renumberIndexes();
else
*deferredRenumber = true;
}
return newIndex;
} }
/// Insert the given machine instruction into the mapping at the given /// Add all instructions in the vector to the index list. This method will
/// index. /// defer renumbering until all instrs have been added, and should be
void insertMachineInstrInMaps(MachineInstr *mi, SlotIndex index) { /// preferred when adding multiple instrs.
index = index.getBaseIndex(); void insertMachineInstrsInMaps(SmallVectorImpl<MachineInstr*> &mis) {
IndexListEntry *miEntry = &index.entry(); bool renumber = false;
assert(miEntry->getInstr() == 0 && "Index already in use.");
miEntry->setInstr(mi);
assert(mi2iMap.find(mi) == mi2iMap.end() && for (SmallVectorImpl<MachineInstr*>::iterator
"MachineInstr already has an index."); miItr = mis.begin(), miEnd = mis.end();
miItr != miEnd; ++miItr) {
insertMachineInstrInMaps(*miItr, &renumber);
}
mi2iMap.insert(std::make_pair(mi, index)); if (renumber)
renumberIndexes();
} }
/// Remove the given machine instruction from the mapping. /// Remove the given machine instruction from the mapping.
void removeMachineInstrFromMaps(MachineInstr *mi) { void removeMachineInstrFromMaps(MachineInstr *mi) {
// remove index -> MachineInstr and // remove index -> MachineInstr and

View File

@ -133,17 +133,14 @@ namespace {
private: private:
MachineBasicBlock::iterator
findNextEmptySlot(MachineBasicBlock*, MachineInstr*,
SlotIndex&);
MachineBasicBlock::iterator MachineBasicBlock::iterator
findSpillPoint(MachineBasicBlock*, MachineInstr*, MachineInstr*, findSpillPoint(MachineBasicBlock*, MachineInstr*, MachineInstr*,
SmallPtrSet<MachineInstr*, 4>&, SlotIndex&); SmallPtrSet<MachineInstr*, 4>&);
MachineBasicBlock::iterator MachineBasicBlock::iterator
findRestorePoint(MachineBasicBlock*, MachineInstr*, SlotIndex, findRestorePoint(MachineBasicBlock*, MachineInstr*, SlotIndex,
SmallPtrSet<MachineInstr*, 4>&, SlotIndex&); SmallPtrSet<MachineInstr*, 4>&);
int CreateSpillStackSlot(unsigned, const TargetRegisterClass *); int CreateSpillStackSlot(unsigned, const TargetRegisterClass *);
@ -163,7 +160,6 @@ namespace {
bool Rematerialize(unsigned vreg, VNInfo* ValNo, bool Rematerialize(unsigned vreg, VNInfo* ValNo,
MachineInstr* DefMI, MachineInstr* DefMI,
MachineBasicBlock::iterator RestorePt, MachineBasicBlock::iterator RestorePt,
SlotIndex RestoreIdx,
SmallPtrSet<MachineInstr*, 4>& RefsInMBB); SmallPtrSet<MachineInstr*, 4>& RefsInMBB);
MachineInstr* FoldSpill(unsigned vreg, const TargetRegisterClass* RC, MachineInstr* FoldSpill(unsigned vreg, const TargetRegisterClass* RC,
MachineInstr* DefMI, MachineInstr* DefMI,
@ -210,24 +206,6 @@ X("pre-alloc-splitting", "Pre-Register Allocation Live Interval Splitting");
const PassInfo *const llvm::PreAllocSplittingID = &X; const PassInfo *const llvm::PreAllocSplittingID = &X;
/// findNextEmptySlot - Find a gap after the given machine instruction in the
/// instruction index map. If there isn't one, return end().
MachineBasicBlock::iterator
PreAllocSplitting::findNextEmptySlot(MachineBasicBlock *MBB, MachineInstr *MI,
SlotIndex &SpotIndex) {
MachineBasicBlock::iterator MII = MI;
if (++MII != MBB->end()) {
SlotIndex Index =
LIs->findGapBeforeInstr(LIs->getInstructionIndex(MII));
if (Index != SlotIndex()) {
SpotIndex = Index;
return MII;
}
}
return MBB->end();
}
/// findSpillPoint - Find a gap as far away from the given MI that's suitable /// findSpillPoint - Find a gap as far away from the given MI that's suitable
/// for spilling the current live interval. The index must be before any /// for spilling the current live interval. The index must be before any
/// defs and uses of the live interval register in the mbb. Return begin() if /// defs and uses of the live interval register in the mbb. Return begin() if
@ -235,8 +213,7 @@ PreAllocSplitting::findNextEmptySlot(MachineBasicBlock *MBB, MachineInstr *MI,
MachineBasicBlock::iterator MachineBasicBlock::iterator
PreAllocSplitting::findSpillPoint(MachineBasicBlock *MBB, MachineInstr *MI, PreAllocSplitting::findSpillPoint(MachineBasicBlock *MBB, MachineInstr *MI,
MachineInstr *DefMI, MachineInstr *DefMI,
SmallPtrSet<MachineInstr*, 4> &RefsInMBB, SmallPtrSet<MachineInstr*, 4> &RefsInMBB) {
SlotIndex &SpillIndex) {
MachineBasicBlock::iterator Pt = MBB->begin(); MachineBasicBlock::iterator Pt = MBB->begin();
MachineBasicBlock::iterator MII = MI; MachineBasicBlock::iterator MII = MI;
@ -249,8 +226,6 @@ PreAllocSplitting::findSpillPoint(MachineBasicBlock *MBB, MachineInstr *MI,
if (MII == EndPt || RefsInMBB.count(MII)) return Pt; if (MII == EndPt || RefsInMBB.count(MII)) return Pt;
while (MII != EndPt && !RefsInMBB.count(MII)) { while (MII != EndPt && !RefsInMBB.count(MII)) {
SlotIndex Index = LIs->getInstructionIndex(MII);
// We can't insert the spill between the barrier (a call), and its // We can't insert the spill between the barrier (a call), and its
// corresponding call frame setup. // corresponding call frame setup.
if (MII->getOpcode() == TRI->getCallFrameDestroyOpcode()) { if (MII->getOpcode() == TRI->getCallFrameDestroyOpcode()) {
@ -261,9 +236,8 @@ PreAllocSplitting::findSpillPoint(MachineBasicBlock *MBB, MachineInstr *MI,
} }
} }
continue; continue;
} else if (LIs->hasGapBeforeInstr(Index)) { } else {
Pt = MII; Pt = MII;
SpillIndex = LIs->findGapBeforeInstr(Index, true);
} }
if (RefsInMBB.count(MII)) if (RefsInMBB.count(MII))
@ -283,8 +257,7 @@ PreAllocSplitting::findSpillPoint(MachineBasicBlock *MBB, MachineInstr *MI,
MachineBasicBlock::iterator MachineBasicBlock::iterator
PreAllocSplitting::findRestorePoint(MachineBasicBlock *MBB, MachineInstr *MI, PreAllocSplitting::findRestorePoint(MachineBasicBlock *MBB, MachineInstr *MI,
SlotIndex LastIdx, SlotIndex LastIdx,
SmallPtrSet<MachineInstr*, 4> &RefsInMBB, SmallPtrSet<MachineInstr*, 4> &RefsInMBB) {
SlotIndex &RestoreIndex) {
// FIXME: Allow spill to be inserted to the beginning of the mbb. Update mbb // FIXME: Allow spill to be inserted to the beginning of the mbb. Update mbb
// begin index accordingly. // begin index accordingly.
MachineBasicBlock::iterator Pt = MBB->end(); MachineBasicBlock::iterator Pt = MBB->end();
@ -308,7 +281,6 @@ PreAllocSplitting::findRestorePoint(MachineBasicBlock *MBB, MachineInstr *MI,
SlotIndex Index = LIs->getInstructionIndex(MII); SlotIndex Index = LIs->getInstructionIndex(MII);
if (Index > LastIdx) if (Index > LastIdx)
break; break;
SlotIndex Gap = LIs->findGapBeforeInstr(Index);
// We can't insert a restore between the barrier (a call) and its // We can't insert a restore between the barrier (a call) and its
// corresponding call frame teardown. // corresponding call frame teardown.
@ -317,9 +289,8 @@ PreAllocSplitting::findRestorePoint(MachineBasicBlock *MBB, MachineInstr *MI,
if (MII == EndPt || RefsInMBB.count(MII)) return Pt; if (MII == EndPt || RefsInMBB.count(MII)) return Pt;
++MII; ++MII;
} while (MII->getOpcode() != TRI->getCallFrameDestroyOpcode()); } while (MII->getOpcode() != TRI->getCallFrameDestroyOpcode());
} else if (Gap != SlotIndex()) { } else {
Pt = MII; Pt = MII;
RestoreIndex = Gap;
} }
if (RefsInMBB.count(MII)) if (RefsInMBB.count(MII))
@ -742,7 +713,7 @@ void PreAllocSplitting::ReconstructLiveInterval(LiveInterval* LI) {
DefIdx = DefIdx.getDefIndex(); DefIdx = DefIdx.getDefIndex();
assert(DI->getOpcode() != TargetInstrInfo::PHI && assert(DI->getOpcode() != TargetInstrInfo::PHI &&
"Following NewVN isPHIDef flag incorrect. Fix me!"); "PHI instr in code during pre-alloc splitting.");
VNInfo* NewVN = LI->getNextValue(DefIdx, 0, true, Alloc); VNInfo* NewVN = LI->getNextValue(DefIdx, 0, true, Alloc);
// If the def is a move, set the copy field. // If the def is a move, set the copy field.
@ -898,25 +869,22 @@ void PreAllocSplitting::RenumberValno(VNInfo* VN) {
bool PreAllocSplitting::Rematerialize(unsigned VReg, VNInfo* ValNo, bool PreAllocSplitting::Rematerialize(unsigned VReg, VNInfo* ValNo,
MachineInstr* DefMI, MachineInstr* DefMI,
MachineBasicBlock::iterator RestorePt, MachineBasicBlock::iterator RestorePt,
SlotIndex RestoreIdx,
SmallPtrSet<MachineInstr*, 4>& RefsInMBB) { SmallPtrSet<MachineInstr*, 4>& RefsInMBB) {
MachineBasicBlock& MBB = *RestorePt->getParent(); MachineBasicBlock& MBB = *RestorePt->getParent();
MachineBasicBlock::iterator KillPt = BarrierMBB->end(); MachineBasicBlock::iterator KillPt = BarrierMBB->end();
SlotIndex KillIdx;
if (!ValNo->isDefAccurate() || DefMI->getParent() == BarrierMBB) if (!ValNo->isDefAccurate() || DefMI->getParent() == BarrierMBB)
KillPt = findSpillPoint(BarrierMBB, Barrier, NULL, RefsInMBB, KillIdx); KillPt = findSpillPoint(BarrierMBB, Barrier, NULL, RefsInMBB);
else else
KillPt = findNextEmptySlot(DefMI->getParent(), DefMI, KillIdx); KillPt = next(MachineBasicBlock::iterator(DefMI));
if (KillPt == DefMI->getParent()->end()) if (KillPt == DefMI->getParent()->end())
return false; return false;
TII->reMaterialize(MBB, RestorePt, VReg, 0, DefMI); TII->reMaterialize(MBB, RestorePt, VReg, 0, DefMI);
LIs->InsertMachineInstrInMaps(prior(RestorePt), RestoreIdx); SlotIndex RematIdx = LIs->InsertMachineInstrInMaps(prior(RestorePt));
ReconstructLiveInterval(CurrLI); ReconstructLiveInterval(CurrLI);
SlotIndex RematIdx = LIs->getInstructionIndex(prior(RestorePt));
RematIdx = RematIdx.getDefIndex(); RematIdx = RematIdx.getDefIndex();
RenumberValno(CurrLI->findDefinedVNInfoForRegInt(RematIdx)); RenumberValno(CurrLI->findDefinedVNInfoForRegInt(RematIdx));
@ -1088,17 +1056,15 @@ bool PreAllocSplitting::SplitRegLiveInterval(LiveInterval *LI) {
} }
// Find a point to restore the value after the barrier. // Find a point to restore the value after the barrier.
SlotIndex RestoreIndex;
MachineBasicBlock::iterator RestorePt = MachineBasicBlock::iterator RestorePt =
findRestorePoint(BarrierMBB, Barrier, LR->end, RefsInMBB, RestoreIndex); findRestorePoint(BarrierMBB, Barrier, LR->end, RefsInMBB);
if (RestorePt == BarrierMBB->end()) { if (RestorePt == BarrierMBB->end()) {
DEBUG(errs() << "FAILED (could not find a suitable restore point).\n"); DEBUG(errs() << "FAILED (could not find a suitable restore point).\n");
return false; return false;
} }
if (DefMI && LIs->isReMaterializable(*LI, ValNo, DefMI)) if (DefMI && LIs->isReMaterializable(*LI, ValNo, DefMI))
if (Rematerialize(LI->reg, ValNo, DefMI, RestorePt, if (Rematerialize(LI->reg, ValNo, DefMI, RestorePt, RefsInMBB)) {
RestoreIndex, RefsInMBB)) {
DEBUG(errs() << "success (remat).\n"); DEBUG(errs() << "success (remat).\n");
return true; return true;
} }
@ -1116,7 +1082,7 @@ bool PreAllocSplitting::SplitRegLiveInterval(LiveInterval *LI) {
SpillIndex = LIs->getInstructionIndex(SpillMI); SpillIndex = LIs->getInstructionIndex(SpillMI);
} else { } else {
MachineBasicBlock::iterator SpillPt = MachineBasicBlock::iterator SpillPt =
findSpillPoint(BarrierMBB, Barrier, NULL, RefsInMBB, SpillIndex); findSpillPoint(BarrierMBB, Barrier, NULL, RefsInMBB);
if (SpillPt == BarrierMBB->begin()) { if (SpillPt == BarrierMBB->begin()) {
DEBUG(errs() << "FAILED (could not find a suitable spill point).\n"); DEBUG(errs() << "FAILED (could not find a suitable spill point).\n");
return false; // No gap to insert spill. return false; // No gap to insert spill.
@ -1126,10 +1092,10 @@ bool PreAllocSplitting::SplitRegLiveInterval(LiveInterval *LI) {
SS = CreateSpillStackSlot(CurrLI->reg, RC); SS = CreateSpillStackSlot(CurrLI->reg, RC);
TII->storeRegToStackSlot(*BarrierMBB, SpillPt, CurrLI->reg, true, SS, RC); TII->storeRegToStackSlot(*BarrierMBB, SpillPt, CurrLI->reg, true, SS, RC);
SpillMI = prior(SpillPt); SpillMI = prior(SpillPt);
LIs->InsertMachineInstrInMaps(SpillMI, SpillIndex); SpillIndex = LIs->InsertMachineInstrInMaps(SpillMI);
} }
} else if (!IsAvailableInStack(DefMBB, CurrLI->reg, ValNo->def, } else if (!IsAvailableInStack(DefMBB, CurrLI->reg, ValNo->def,
RestoreIndex, SpillIndex, SS)) { LIs->getZeroIndex(), SpillIndex, SS)) {
// If it's already split, just restore the value. There is no need to spill // If it's already split, just restore the value. There is no need to spill
// the def again. // the def again.
if (!DefMI) { if (!DefMI) {
@ -1146,13 +1112,13 @@ bool PreAllocSplitting::SplitRegLiveInterval(LiveInterval *LI) {
if (DefMBB == BarrierMBB) { if (DefMBB == BarrierMBB) {
// Add spill after the def and the last use before the barrier. // Add spill after the def and the last use before the barrier.
SpillPt = findSpillPoint(BarrierMBB, Barrier, DefMI, SpillPt = findSpillPoint(BarrierMBB, Barrier, DefMI,
RefsInMBB, SpillIndex); RefsInMBB);
if (SpillPt == DefMBB->begin()) { if (SpillPt == DefMBB->begin()) {
DEBUG(errs() << "FAILED (could not find a suitable spill point).\n"); DEBUG(errs() << "FAILED (could not find a suitable spill point).\n");
return false; // No gap to insert spill. return false; // No gap to insert spill.
} }
} else { } else {
SpillPt = findNextEmptySlot(DefMBB, DefMI, SpillIndex); SpillPt = next(MachineBasicBlock::iterator(DefMI));
if (SpillPt == DefMBB->end()) { if (SpillPt == DefMBB->end()) {
DEBUG(errs() << "FAILED (could not find a suitable spill point).\n"); DEBUG(errs() << "FAILED (could not find a suitable spill point).\n");
return false; // No gap to insert spill. return false; // No gap to insert spill.
@ -1162,7 +1128,7 @@ bool PreAllocSplitting::SplitRegLiveInterval(LiveInterval *LI) {
SS = CreateSpillStackSlot(CurrLI->reg, RC); SS = CreateSpillStackSlot(CurrLI->reg, RC);
TII->storeRegToStackSlot(*DefMBB, SpillPt, CurrLI->reg, false, SS, RC); TII->storeRegToStackSlot(*DefMBB, SpillPt, CurrLI->reg, false, SS, RC);
SpillMI = prior(SpillPt); SpillMI = prior(SpillPt);
LIs->InsertMachineInstrInMaps(SpillMI, SpillIndex); SpillIndex = LIs->InsertMachineInstrInMaps(SpillMI);
} }
} }
@ -1172,6 +1138,7 @@ bool PreAllocSplitting::SplitRegLiveInterval(LiveInterval *LI) {
// Add restore. // Add restore.
bool FoldedRestore = false; bool FoldedRestore = false;
SlotIndex RestoreIndex;
if (MachineInstr* LMI = FoldRestore(CurrLI->reg, RC, Barrier, if (MachineInstr* LMI = FoldRestore(CurrLI->reg, RC, Barrier,
BarrierMBB, SS, RefsInMBB)) { BarrierMBB, SS, RefsInMBB)) {
RestorePt = LMI; RestorePt = LMI;
@ -1180,7 +1147,7 @@ bool PreAllocSplitting::SplitRegLiveInterval(LiveInterval *LI) {
} else { } else {
TII->loadRegFromStackSlot(*BarrierMBB, RestorePt, CurrLI->reg, SS, RC); TII->loadRegFromStackSlot(*BarrierMBB, RestorePt, CurrLI->reg, SS, RC);
MachineInstr *LoadMI = prior(RestorePt); MachineInstr *LoadMI = prior(RestorePt);
LIs->InsertMachineInstrInMaps(LoadMI, RestoreIndex); RestoreIndex = LIs->InsertMachineInstrInMaps(LoadMI);
} }
// Update spill stack slot live interval. // Update spill stack slot live interval.

View File

@ -156,7 +156,7 @@ bool SlotIndexes::runOnMachineFunction(MachineFunction &fn) {
return false; return false;
} }
void SlotIndexes::renumber() { void SlotIndexes::renumberIndexes() {
// Renumber updates the index of every element of the index list. // Renumber updates the index of every element of the index list.
// If all instrs in the function have been allocated an index (which has been // If all instrs in the function have been allocated an index (which has been
@ -184,7 +184,6 @@ void SlotIndexes::renumber() {
Slots = 1; Slots = 1;
index += (Slots + 1) * SlotIndex::NUM; index += (Slots + 1) * SlotIndex::NUM;
} }
} }
} }

View File

@ -52,16 +52,16 @@ protected:
/// Ensures there is space before the given machine instruction, returns the /// Ensures there is space before the given machine instruction, returns the
/// instruction's new number. /// instruction's new number.
SlotIndex makeSpaceBefore(MachineInstr *mi) { SlotIndex makeSpaceBefore(MachineInstr *mi) {
if (!lis->hasGapBeforeInstr(lis->getInstructionIndex(mi))) { //if (!lis->hasGapBeforeInstr(lis->getInstructionIndex(mi))) {
// FIXME: Should be updated to use rewrite-in-place methods when they're // FIXME: Should be updated to use rewrite-in-place methods when they're
// introduced. Currently broken. // introduced. Currently broken.
//lis->scaleNumbering(2); //lis->scaleNumbering(2);
//ls->scaleNumbering(2); //ls->scaleNumbering(2);
} //}
SlotIndex miIdx = lis->getInstructionIndex(mi); SlotIndex miIdx = lis->getInstructionIndex(mi);
assert(lis->hasGapBeforeInstr(miIdx)); //assert(lis->hasGapBeforeInstr(miIdx));
return miIdx; return miIdx;
} }
@ -69,16 +69,16 @@ protected:
/// Ensure there is space after the given machine instruction, returns the /// Ensure there is space after the given machine instruction, returns the
/// instruction's new number. /// instruction's new number.
SlotIndex makeSpaceAfter(MachineInstr *mi) { SlotIndex makeSpaceAfter(MachineInstr *mi) {
if (!lis->hasGapAfterInstr(lis->getInstructionIndex(mi))) { //if (!lis->hasGapAfterInstr(lis->getInstructionIndex(mi))) {
// FIXME: Should be updated to use rewrite-in-place methods when they're // FIXME: Should be updated to use rewrite-in-place methods when they're
// introduced. Currently broken. // introduced. Currently broken.
// lis->scaleNumbering(2); // lis->scaleNumbering(2);
// ls->scaleNumbering(2); // ls->scaleNumbering(2);
} //}
SlotIndex miIdx = lis->getInstructionIndex(mi); SlotIndex miIdx = lis->getInstructionIndex(mi);
assert(lis->hasGapAfterInstr(miIdx)); //assert(lis->hasGapAfterInstr(miIdx));
return miIdx; return miIdx;
} }
@ -99,14 +99,8 @@ protected:
true, ss, trc); true, ss, trc);
MachineBasicBlock::iterator storeInstItr(next(mi)); MachineBasicBlock::iterator storeInstItr(next(mi));
MachineInstr *storeInst = &*storeInstItr; MachineInstr *storeInst = &*storeInstItr;
SlotIndex storeInstIdx = miIdx.getNextIndex();
assert(lis->getInstructionFromIndex(storeInstIdx) == 0 &&
"Store inst index already in use.");
lis->InsertMachineInstrInMaps(storeInst, storeInstIdx); return lis->InsertMachineInstrInMaps(storeInst);
return storeInstIdx;
} }
/// Insert a store of the given vreg to the given stack slot immediately /// Insert a store of the given vreg to the given stack slot immediately
@ -120,14 +114,8 @@ protected:
tii->storeRegToStackSlot(*mi->getParent(), mi, vreg, true, ss, trc); tii->storeRegToStackSlot(*mi->getParent(), mi, vreg, true, ss, trc);
MachineBasicBlock::iterator storeInstItr(prior(mi)); MachineBasicBlock::iterator storeInstItr(prior(mi));
MachineInstr *storeInst = &*storeInstItr; MachineInstr *storeInst = &*storeInstItr;
SlotIndex storeInstIdx = miIdx.getPrevIndex();
assert(lis->getInstructionFromIndex(storeInstIdx) == 0 && return lis->InsertMachineInstrInMaps(storeInst);
"Store inst index already in use.");
lis->InsertMachineInstrInMaps(storeInst, storeInstIdx);
return storeInstIdx;
} }
void insertStoreAfterInstOnInterval(LiveInterval *li, void insertStoreAfterInstOnInterval(LiveInterval *li,
@ -164,14 +152,8 @@ protected:
tii->loadRegFromStackSlot(*mi->getParent(), nextInstItr, vreg, ss, trc); tii->loadRegFromStackSlot(*mi->getParent(), nextInstItr, vreg, ss, trc);
MachineBasicBlock::iterator loadInstItr(next(mi)); MachineBasicBlock::iterator loadInstItr(next(mi));
MachineInstr *loadInst = &*loadInstItr; MachineInstr *loadInst = &*loadInstItr;
SlotIndex loadInstIdx = miIdx.getNextIndex();
assert(lis->getInstructionFromIndex(loadInstIdx) == 0 &&
"Store inst index already in use.");
lis->InsertMachineInstrInMaps(loadInst, loadInstIdx); return lis->InsertMachineInstrInMaps(loadInst);
return loadInstIdx;
} }
/// Insert a load of the given vreg from the given stack slot immediately /// Insert a load of the given vreg from the given stack slot immediately
@ -186,14 +168,8 @@ protected:
tii->loadRegFromStackSlot(*mi->getParent(), mi, vreg, ss, trc); tii->loadRegFromStackSlot(*mi->getParent(), mi, vreg, ss, trc);
MachineBasicBlock::iterator loadInstItr(prior(mi)); MachineBasicBlock::iterator loadInstItr(prior(mi));
MachineInstr *loadInst = &*loadInstItr; MachineInstr *loadInst = &*loadInstItr;
SlotIndex loadInstIdx = miIdx.getPrevIndex();
assert(lis->getInstructionFromIndex(loadInstIdx) == 0 && return lis->InsertMachineInstrInMaps(loadInst);
"Load inst index already in use.");
lis->InsertMachineInstrInMaps(loadInst, loadInstIdx);
return loadInstIdx;
} }
void insertLoadBeforeInstOnInterval(LiveInterval *li, void insertLoadBeforeInstOnInterval(LiveInterval *li,