forked from OSchip/llvm-project
SlotIndexes: Introduce an iterator into the idx2MBBMap.
llvm-svn: 245956
This commit is contained in:
parent
a7fc3856f1
commit
0cc11b1fa7
|
@ -502,18 +502,40 @@ namespace llvm {
|
||||||
return getMBBRange(mbb).second;
|
return getMBBRange(mbb).second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Iterator over the idx2MBBMap (sorted pairs of slot index of basic block
|
||||||
|
/// begin and basic block)
|
||||||
|
typedef SmallVectorImpl<IdxMBBPair>::const_iterator MBBIndexIterator;
|
||||||
|
/// Move iterator to the next IdxMBBPair where the SlotIndex is greater or
|
||||||
|
/// equal to \p To.
|
||||||
|
MBBIndexIterator advanceMBBIndex(MBBIndexIterator I, SlotIndex To) const {
|
||||||
|
return std::lower_bound(I, idx2MBBMap.end(), To);
|
||||||
|
}
|
||||||
|
/// Get an iterator pointing to the IdxMBBPair with the biggest SlotIndex
|
||||||
|
/// that is greater or equal to \p Idx.
|
||||||
|
MBBIndexIterator findMBBIndex(SlotIndex Idx) const {
|
||||||
|
return advanceMBBIndex(idx2MBBMap.begin(), Idx);
|
||||||
|
}
|
||||||
|
/// Returns an iterator for the begin of the idx2MBBMap.
|
||||||
|
MBBIndexIterator MBBIndexBegin() const {
|
||||||
|
return idx2MBBMap.begin();
|
||||||
|
}
|
||||||
|
/// Return an iterator for the end of the idx2MBBMap.
|
||||||
|
MBBIndexIterator MBBIndexEnd() const {
|
||||||
|
return idx2MBBMap.end();
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the basic block which the given index falls in.
|
/// Returns the basic block which the given index falls in.
|
||||||
MachineBasicBlock* getMBBFromIndex(SlotIndex index) const {
|
MachineBasicBlock* getMBBFromIndex(SlotIndex index) const {
|
||||||
if (MachineInstr *MI = getInstructionFromIndex(index))
|
if (MachineInstr *MI = getInstructionFromIndex(index))
|
||||||
return MI->getParent();
|
return MI->getParent();
|
||||||
SmallVectorImpl<IdxMBBPair>::const_iterator I =
|
|
||||||
std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), index);
|
|
||||||
// Take the pair containing the index
|
|
||||||
SmallVectorImpl<IdxMBBPair>::const_iterator J =
|
|
||||||
((I != idx2MBBMap.end() && I->first > index) ||
|
|
||||||
(I == idx2MBBMap.end() && idx2MBBMap.size()>0)) ? (I-1): I;
|
|
||||||
|
|
||||||
assert(J != idx2MBBMap.end() && J->first <= index &&
|
MBBIndexIterator I = findMBBIndex(index);
|
||||||
|
// Take the pair containing the index
|
||||||
|
MBBIndexIterator J =
|
||||||
|
((I != MBBIndexEnd() && I->first > index) ||
|
||||||
|
(I == MBBIndexEnd() && !idx2MBBMap.empty())) ? std::prev(I) : I;
|
||||||
|
|
||||||
|
assert(J != MBBIndexEnd() && J->first <= index &&
|
||||||
index < getMBBEndIdx(J->second) &&
|
index < getMBBEndIdx(J->second) &&
|
||||||
"index does not correspond to an MBB");
|
"index does not correspond to an MBB");
|
||||||
return J->second;
|
return J->second;
|
||||||
|
@ -521,16 +543,11 @@ namespace llvm {
|
||||||
|
|
||||||
bool findLiveInMBBs(SlotIndex start, SlotIndex end,
|
bool findLiveInMBBs(SlotIndex start, SlotIndex end,
|
||||||
SmallVectorImpl<MachineBasicBlock*> &mbbs) const {
|
SmallVectorImpl<MachineBasicBlock*> &mbbs) const {
|
||||||
SmallVectorImpl<IdxMBBPair>::const_iterator itr =
|
|
||||||
std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), start);
|
|
||||||
bool resVal = false;
|
bool resVal = false;
|
||||||
|
for (MBBIndexIterator itr = findMBBIndex(start);
|
||||||
while (itr != idx2MBBMap.end()) {
|
itr != MBBIndexEnd() && itr->first < end; ++itr) {
|
||||||
if (itr->first >= end)
|
|
||||||
break;
|
|
||||||
mbbs.push_back(itr->second);
|
mbbs.push_back(itr->second);
|
||||||
resVal = true;
|
resVal = true;
|
||||||
++itr;
|
|
||||||
}
|
}
|
||||||
return resVal;
|
return resVal;
|
||||||
}
|
}
|
||||||
|
@ -540,11 +557,8 @@ namespace llvm {
|
||||||
MachineBasicBlock* getMBBCoveringRange(SlotIndex start, SlotIndex end) const {
|
MachineBasicBlock* getMBBCoveringRange(SlotIndex start, SlotIndex end) const {
|
||||||
|
|
||||||
assert(start < end && "Backwards ranges not allowed.");
|
assert(start < end && "Backwards ranges not allowed.");
|
||||||
|
MBBIndexIterator itr = findMBBIndex(start);
|
||||||
SmallVectorImpl<IdxMBBPair>::const_iterator itr =
|
if (itr == MBBIndexEnd()) {
|
||||||
std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), start);
|
|
||||||
|
|
||||||
if (itr == idx2MBBMap.end()) {
|
|
||||||
itr = std::prev(itr);
|
itr = std::prev(itr);
|
||||||
return itr->second;
|
return itr->second;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue