aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJakob Stoklund Olesen <stoklund@2pi.dk>2011-04-02 06:03:31 +0000
committerJakob Stoklund Olesen <stoklund@2pi.dk>2011-04-02 06:03:31 +0000
commita122eaaee22750c4f92c33672e149eb2f0c538cb (patch)
tree9a3f4e26c0096f22309e006cb3d657001f11f3b9 /include
parent4071a711126a2a75585a32b96bb5d15ea267a915 (diff)
downloadexternal_llvm-a122eaaee22750c4f92c33672e149eb2f0c538cb.zip
external_llvm-a122eaaee22750c4f92c33672e149eb2f0c538cb.tar.gz
external_llvm-a122eaaee22750c4f92c33672e149eb2f0c538cb.tar.bz2
Use basic block numbers as indexes when mapping slot index ranges.
This is more compact and faster than using DenseMap. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128763 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/CodeGen/SlotIndexes.h49
1 files changed, 19 insertions, 30 deletions
diff --git a/include/llvm/CodeGen/SlotIndexes.h b/include/llvm/CodeGen/SlotIndexes.h
index 0e2adb5..2d9ae5f 100644
--- a/include/llvm/CodeGen/SlotIndexes.h
+++ b/include/llvm/CodeGen/SlotIndexes.h
@@ -337,15 +337,12 @@ namespace llvm {
typedef DenseMap<const MachineInstr*, SlotIndex> Mi2IndexMap;
Mi2IndexMap mi2iMap;
- /// MBB2IdxMap - The indexes of the first and last instructions in the
- /// specified basic block.
- typedef DenseMap<const MachineBasicBlock*,
- std::pair<SlotIndex, SlotIndex> > MBB2IdxMap;
- MBB2IdxMap mbb2IdxMap;
+ /// MBBRanges - Map MBB number to (start, stop) indexes.
+ SmallVector<std::pair<SlotIndex, SlotIndex>, 8> MBBRanges;
/// Idx2MBBMap - Sorted list of pairs of index of first instruction
/// and MBB id.
- std::vector<IdxMBBPair> idx2MBBMap;
+ SmallVector<IdxMBBPair, 8> idx2MBBMap;
// IndexListEntry allocator.
BumpPtrAllocator ileAllocator;
@@ -509,12 +506,16 @@ namespace llvm {
return nextNonNull;
}
+ /// Return the (start,end) range of the given basic block number.
+ const std::pair<SlotIndex, SlotIndex> &
+ getMBBRange(unsigned Num) const {
+ return MBBRanges[Num];
+ }
+
/// Return the (start,end) range of the given basic block.
const std::pair<SlotIndex, SlotIndex> &
- getMBBRange(const MachineBasicBlock *mbb) const {
- MBB2IdxMap::const_iterator itr = mbb2IdxMap.find(mbb);
- assert(itr != mbb2IdxMap.end() && "MBB not found in maps.");
- return itr->second;
+ getMBBRange(const MachineBasicBlock *MBB) const {
+ return getMBBRange(MBB->getNumber());
}
/// Returns the first index in the given basic block.
@@ -529,10 +530,10 @@ namespace llvm {
/// Returns the basic block which the given index falls in.
MachineBasicBlock* getMBBFromIndex(SlotIndex index) const {
- std::vector<IdxMBBPair>::const_iterator I =
+ SmallVectorImpl<IdxMBBPair>::const_iterator I =
std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), index);
// Take the pair containing the index
- std::vector<IdxMBBPair>::const_iterator J =
+ SmallVectorImpl<IdxMBBPair>::const_iterator J =
((I != idx2MBBMap.end() && I->first > index) ||
(I == idx2MBBMap.end() && idx2MBBMap.size()>0)) ? (I-1): I;
@@ -544,7 +545,7 @@ namespace llvm {
bool findLiveInMBBs(SlotIndex start, SlotIndex end,
SmallVectorImpl<MachineBasicBlock*> &mbbs) const {
- std::vector<IdxMBBPair>::const_iterator itr =
+ SmallVectorImpl<IdxMBBPair>::const_iterator itr =
std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), start);
bool resVal = false;
@@ -564,7 +565,7 @@ namespace llvm {
assert(start < end && "Backwards ranges not allowed.");
- std::vector<IdxMBBPair>::const_iterator itr =
+ SmallVectorImpl<IdxMBBPair>::const_iterator itr =
std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), start);
if (itr == idx2MBBMap.end()) {
@@ -596,11 +597,6 @@ namespace llvm {
assert(mbb != 0 && "Instr must be added to function.");
- MBB2IdxMap::iterator mbbRangeItr = mbb2IdxMap.find(mbb);
-
- assert(mbbRangeItr != mbb2IdxMap.end() &&
- "Instruction's parent MBB has not been added to SlotIndexes.");
-
MachineBasicBlock::iterator miItr(mi);
IndexListEntry *newEntry;
// Get previous index, considering that not all instructions are indexed.
@@ -608,7 +604,7 @@ namespace llvm {
for (;;) {
// If mi is at the mbb beginning, get the prev index from the mbb.
if (miItr == mbb->begin()) {
- prevEntry = &mbbRangeItr->second.first.entry();
+ prevEntry = &getMBBStartIdx(mbb).entry();
break;
}
// Otherwise rewind until we find a mapped instruction.
@@ -689,21 +685,14 @@ namespace llvm {
SlotIndex startIdx(startEntry, SlotIndex::LOAD);
SlotIndex endIdx(nextEntry, SlotIndex::LOAD);
- mbb2IdxMap.insert(
- std::make_pair(mbb, std::make_pair(startIdx, endIdx)));
+ assert(unsigned(mbb->getNumber()) == MBBRanges.size() &&
+ "Blocks must be added in order");
+ MBBRanges.push_back(std::make_pair(startIdx, endIdx));
idx2MBBMap.push_back(IdxMBBPair(startIdx, mbb));
- if (MachineFunction::iterator(mbb) != mbb->getParent()->begin()) {
- // Have to update the end index of the previous block.
- MachineBasicBlock *priorMBB =
- llvm::prior(MachineFunction::iterator(mbb));
- mbb2IdxMap[priorMBB].second = startIdx;
- }
-
renumberIndexes();
std::sort(idx2MBBMap.begin(), idx2MBBMap.end(), Idx2MBBCompare());
-
}
};