1 //===- llvm/CodeGen/SlotIndexes.h - Slot indexes representation -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements SlotIndex and related classes. The purpuse of SlotIndex
11 // is to describe a position at which a register can become live, or cease to
14 // SlotIndex is mostly a proxy for entries of the SlotIndexList, a class which
15 // is held is LiveIntervals and provides the real numbering. This allows
16 // LiveIntervals to perform largely transparent renumbering. The SlotIndex
17 // class does hold a PHI bit, which determines whether the index relates to a
18 // PHI use or def point, or an actual instruction. See the SlotIndex class
19 // description for futher information.
20 //===----------------------------------------------------------------------===//
22 #ifndef LLVM_CODEGEN_SLOTINDEXES_H
23 #define LLVM_CODEGEN_SLOTINDEXES_H
25 #include "llvm/CodeGen/MachineBasicBlock.h"
26 #include "llvm/CodeGen/MachineFunction.h"
27 #include "llvm/CodeGen/MachineFunctionPass.h"
28 #include "llvm/ADT/PointerIntPair.h"
29 #include "llvm/ADT/SmallVector.h"
30 #include "llvm/ADT/DenseMap.h"
31 #include "llvm/Support/Allocator.h"
35 /// This class represents an entry in the slot index list held in the
36 /// SlotIndexes pass. It should not be used directly. See the
37 /// SlotIndex & SlotIndexes classes for the public interface to this
39 class IndexListEntry {
40 static const unsigned EMPTY_KEY_INDEX = ~0U & ~3U,
41 TOMBSTONE_KEY_INDEX = ~0U & ~7U;
43 IndexListEntry *next, *prev;
49 typedef enum { EMPTY_KEY, TOMBSTONE_KEY } ReservedEntryType;
51 // This constructor is only to be used by getEmptyKeyEntry
52 // & getTombstoneKeyEntry. It sets index to the given
53 // value and mi to zero.
54 IndexListEntry(ReservedEntryType r) : mi(0) {
56 case EMPTY_KEY: index = EMPTY_KEY_INDEX; break;
57 case TOMBSTONE_KEY: index = TOMBSTONE_KEY_INDEX; break;
58 default: assert(false && "Invalid value for constructor.");
66 IndexListEntry(MachineInstr *mi, unsigned index) : mi(mi), index(index) {
67 assert(index != EMPTY_KEY_INDEX && index != TOMBSTONE_KEY_INDEX &&
68 "Attempt to create invalid index. "
69 "Available indexes may have been exhausted?.");
72 bool isValid() const {
73 return (index != EMPTY_KEY_INDEX && index != TOMBSTONE_KEY_INDEX);
76 MachineInstr* getInstr() const { return mi; }
77 void setInstr(MachineInstr *mi) {
78 assert(isValid() && "Attempt to modify reserved index.");
82 unsigned getIndex() const { return index; }
83 void setIndex(unsigned index) {
84 assert(index != EMPTY_KEY_INDEX && index != TOMBSTONE_KEY_INDEX &&
85 "Attempt to set index to invalid value.");
86 assert(isValid() && "Attempt to reset reserved index value.");
90 IndexListEntry* getNext() { return next; }
91 const IndexListEntry* getNext() const { return next; }
92 void setNext(IndexListEntry *next) {
93 assert(isValid() && "Attempt to modify reserved index.");
97 IndexListEntry* getPrev() { return prev; }
98 const IndexListEntry* getPrev() const { return prev; }
99 void setPrev(IndexListEntry *prev) {
100 assert(isValid() && "Attempt to modify reserved index.");
104 // This function returns the index list entry that is to be used for empty
106 static IndexListEntry* getEmptyKeyEntry();
108 // This function returns the index list entry that is to be used for
109 // tombstone SlotIndex keys.
110 static IndexListEntry* getTombstoneKeyEntry();
113 // Specialize PointerLikeTypeTraits for IndexListEntry.
115 class PointerLikeTypeTraits<IndexListEntry*> {
117 static inline void* getAsVoidPointer(IndexListEntry *p) {
120 static inline IndexListEntry* getFromVoidPointer(void *p) {
121 return static_cast<IndexListEntry*>(p);
123 enum { NumLowBitsAvailable = 3 };
126 /// SlotIndex - An opaque wrapper around machine indexes.
128 friend class SlotIndexes;
129 friend struct DenseMapInfo<SlotIndex>;
131 enum Slot { LOAD, USE, DEF, STORE, NUM };
133 static const unsigned PHI_BIT = 1 << 2;
135 PointerIntPair<IndexListEntry*, 3, unsigned> lie;
137 SlotIndex(IndexListEntry *entry, unsigned phiAndSlot)
138 : lie(entry, phiAndSlot) {
139 assert(entry != 0 && "Attempt to construct index with 0 pointer.");
142 IndexListEntry& entry() const {
143 return *lie.getPointer();
146 int getIndex() const {
147 return entry().getIndex() | getSlot();
150 /// Returns the slot for this SlotIndex.
151 Slot getSlot() const {
152 return static_cast<Slot>(lie.getInt() & ~PHI_BIT);
155 static inline unsigned getHashValue(const SlotIndex &v) {
156 IndexListEntry *ptrVal = &v.entry();
157 return (unsigned((intptr_t)ptrVal) >> 4) ^
158 (unsigned((intptr_t)ptrVal) >> 9);
162 static inline SlotIndex getEmptyKey() {
163 return SlotIndex(IndexListEntry::getEmptyKeyEntry(), 0);
166 static inline SlotIndex getTombstoneKey() {
167 return SlotIndex(IndexListEntry::getTombstoneKeyEntry(), 0);
170 /// Construct an invalid index.
171 SlotIndex() : lie(IndexListEntry::getEmptyKeyEntry(), 0) {}
173 // Construct a new slot index from the given one, set the phi flag on the
174 // new index to the value of the phi parameter.
175 SlotIndex(const SlotIndex &li, bool phi)
176 : lie(&li.entry(), phi ? PHI_BIT | li.getSlot() : (unsigned)li.getSlot()){
177 assert(lie.getPointer() != 0 &&
178 "Attempt to construct index with 0 pointer.");
181 // Construct a new slot index from the given one, set the phi flag on the
182 // new index to the value of the phi parameter, and the slot to the new slot.
183 SlotIndex(const SlotIndex &li, bool phi, Slot s)
184 : lie(&li.entry(), phi ? PHI_BIT | s : (unsigned)s) {
185 assert(lie.getPointer() != 0 &&
186 "Attempt to construct index with 0 pointer.");
189 /// Returns true if this is a valid index. Invalid indicies do
190 /// not point into an index table, and cannot be compared.
191 bool isValid() const {
192 IndexListEntry *entry = lie.getPointer();
193 return ((entry!= 0) && (entry->isValid()));
196 /// Print this index to the given raw_ostream.
197 void print(raw_ostream &os) const;
199 /// Dump this index to stderr.
202 /// Compare two SlotIndex objects for equality.
203 bool operator==(SlotIndex other) const {
204 return getIndex() == other.getIndex();
206 /// Compare two SlotIndex objects for inequality.
207 bool operator!=(SlotIndex other) const {
208 return getIndex() != other.getIndex();
211 /// Compare two SlotIndex objects. Return true if the first index
212 /// is strictly lower than the second.
213 bool operator<(SlotIndex other) const {
214 return getIndex() < other.getIndex();
216 /// Compare two SlotIndex objects. Return true if the first index
217 /// is lower than, or equal to, the second.
218 bool operator<=(SlotIndex other) const {
219 return getIndex() <= other.getIndex();
222 /// Compare two SlotIndex objects. Return true if the first index
223 /// is greater than the second.
224 bool operator>(SlotIndex other) const {
225 return getIndex() > other.getIndex();
228 /// Compare two SlotIndex objects. Return true if the first index
229 /// is greater than, or equal to, the second.
230 bool operator>=(SlotIndex other) const {
231 return getIndex() >= other.getIndex();
234 /// Return the distance from this index to the given one.
235 int distance(SlotIndex other) const {
236 return other.getIndex() - getIndex();
239 /// Returns the state of the PHI bit.
241 return lie.getInt() & PHI_BIT;
244 /// isLoad - Return true if this is a LOAD slot.
245 bool isLoad() const {
246 return getSlot() == LOAD;
249 /// isDef - Return true if this is a DEF slot.
251 return getSlot() == DEF;
254 /// isUse - Return true if this is a USE slot.
256 return getSlot() == USE;
259 /// isStore - Return true if this is a STORE slot.
260 bool isStore() const {
261 return getSlot() == STORE;
264 /// Returns the base index for associated with this index. The base index
265 /// is the one associated with the LOAD slot for the instruction pointed to
267 SlotIndex getBaseIndex() const {
268 return getLoadIndex();
271 /// Returns the boundary index for associated with this index. The boundary
272 /// index is the one associated with the LOAD slot for the instruction
273 /// pointed to by this index.
274 SlotIndex getBoundaryIndex() const {
275 return getStoreIndex();
278 /// Returns the index of the LOAD slot for the instruction pointed to by
280 SlotIndex getLoadIndex() const {
281 return SlotIndex(&entry(), SlotIndex::LOAD);
284 /// Returns the index of the USE slot for the instruction pointed to by
286 SlotIndex getUseIndex() const {
287 return SlotIndex(&entry(), SlotIndex::USE);
290 /// Returns the index of the DEF slot for the instruction pointed to by
292 SlotIndex getDefIndex() const {
293 return SlotIndex(&entry(), SlotIndex::DEF);
296 /// Returns the index of the STORE slot for the instruction pointed to by
298 SlotIndex getStoreIndex() const {
299 return SlotIndex(&entry(), SlotIndex::STORE);
302 /// Returns the next slot in the index list. This could be either the
303 /// next slot for the instruction pointed to by this index or, if this
304 /// index is a STORE, the first slot for the next instruction.
305 /// WARNING: This method is considerably more expensive than the methods
306 /// that return specific slots (getUseIndex(), etc). If you can - please
307 /// use one of those methods.
308 SlotIndex getNextSlot() const {
310 if (s == SlotIndex::STORE) {
311 return SlotIndex(entry().getNext(), SlotIndex::LOAD);
313 return SlotIndex(&entry(), s + 1);
316 /// Returns the next index. This is the index corresponding to the this
317 /// index's slot, but for the next instruction.
318 SlotIndex getNextIndex() const {
319 return SlotIndex(entry().getNext(), getSlot());
322 /// Returns the previous slot in the index list. This could be either the
323 /// previous slot for the instruction pointed to by this index or, if this
324 /// index is a LOAD, the last slot for the previous instruction.
325 /// WARNING: This method is considerably more expensive than the methods
326 /// that return specific slots (getUseIndex(), etc). If you can - please
327 /// use one of those methods.
328 SlotIndex getPrevSlot() const {
330 if (s == SlotIndex::LOAD) {
331 return SlotIndex(entry().getPrev(), SlotIndex::STORE);
333 return SlotIndex(&entry(), s - 1);
336 /// Returns the previous index. This is the index corresponding to this
337 /// index's slot, but for the previous instruction.
338 SlotIndex getPrevIndex() const {
339 return SlotIndex(entry().getPrev(), getSlot());
344 /// DenseMapInfo specialization for SlotIndex.
346 struct DenseMapInfo<SlotIndex> {
347 static inline SlotIndex getEmptyKey() {
348 return SlotIndex::getEmptyKey();
350 static inline SlotIndex getTombstoneKey() {
351 return SlotIndex::getTombstoneKey();
353 static inline unsigned getHashValue(const SlotIndex &v) {
354 return SlotIndex::getHashValue(v);
356 static inline bool isEqual(const SlotIndex &LHS, const SlotIndex &RHS) {
361 template <> struct isPodLike<SlotIndex> { static const bool value = true; };
364 inline raw_ostream& operator<<(raw_ostream &os, SlotIndex li) {
369 typedef std::pair<SlotIndex, MachineBasicBlock*> IdxMBBPair;
371 inline bool operator<(SlotIndex V, const IdxMBBPair &IM) {
375 inline bool operator<(const IdxMBBPair &IM, SlotIndex V) {
379 struct Idx2MBBCompare {
380 bool operator()(const IdxMBBPair &LHS, const IdxMBBPair &RHS) const {
381 return LHS.first < RHS.first;
385 /// SlotIndexes pass.
387 /// This pass assigns indexes to each instruction.
388 class SlotIndexes : public MachineFunctionPass {
392 IndexListEntry *indexListHead;
393 unsigned functionSize;
395 typedef DenseMap<const MachineInstr*, SlotIndex> Mi2IndexMap;
398 /// MBB2IdxMap - The indexes of the first and last instructions in the
399 /// specified basic block.
400 typedef DenseMap<const MachineBasicBlock*,
401 std::pair<SlotIndex, SlotIndex> > MBB2IdxMap;
402 MBB2IdxMap mbb2IdxMap;
404 /// Idx2MBBMap - Sorted list of pairs of index of first instruction
406 std::vector<IdxMBBPair> idx2MBBMap;
408 typedef DenseMap<const MachineBasicBlock*, SlotIndex> TerminatorGapsMap;
409 TerminatorGapsMap terminatorGaps;
411 // IndexListEntry allocator.
412 BumpPtrAllocator ileAllocator;
414 IndexListEntry* createEntry(MachineInstr *mi, unsigned index) {
415 IndexListEntry *entry =
416 static_cast<IndexListEntry*>(
417 ileAllocator.Allocate(sizeof(IndexListEntry),
418 alignof<IndexListEntry>()));
420 new (entry) IndexListEntry(mi, index);
426 assert(indexListHead == 0 && "Zero entry non-null at initialisation.");
427 indexListHead = createEntry(0, ~0U);
428 indexListHead->setNext(0);
429 indexListHead->setPrev(indexListHead);
434 ileAllocator.Reset();
437 IndexListEntry* getTail() {
438 assert(indexListHead != 0 && "Call to getTail on uninitialized list.");
439 return indexListHead->getPrev();
442 const IndexListEntry* getTail() const {
443 assert(indexListHead != 0 && "Call to getTail on uninitialized list.");
444 return indexListHead->getPrev();
447 // Returns true if the index list is empty.
448 bool empty() const { return (indexListHead == getTail()); }
450 IndexListEntry* front() {
451 assert(!empty() && "front() called on empty index list.");
452 return indexListHead;
455 const IndexListEntry* front() const {
456 assert(!empty() && "front() called on empty index list.");
457 return indexListHead;
460 IndexListEntry* back() {
461 assert(!empty() && "back() called on empty index list.");
462 return getTail()->getPrev();
465 const IndexListEntry* back() const {
466 assert(!empty() && "back() called on empty index list.");
467 return getTail()->getPrev();
470 /// Insert a new entry before itr.
471 void insert(IndexListEntry *itr, IndexListEntry *val) {
472 assert(itr != 0 && "itr should not be null.");
473 IndexListEntry *prev = itr->getPrev();
477 if (itr != indexListHead) {
486 /// Push a new entry on to the end of the list.
487 void push_back(IndexListEntry *val) {
488 insert(getTail(), val);
494 SlotIndexes() : MachineFunctionPass(ID), indexListHead(0) {}
496 virtual void getAnalysisUsage(AnalysisUsage &au) const;
497 virtual void releaseMemory();
499 virtual bool runOnMachineFunction(MachineFunction &fn);
501 /// Dump the indexes.
504 /// Renumber the index list, providing space for new instructions.
505 void renumberIndexes();
507 /// Returns the zero index for this analysis.
508 SlotIndex getZeroIndex() {
509 assert(front()->getIndex() == 0 && "First index is not 0?");
510 return SlotIndex(front(), 0);
513 /// Returns the base index of the last slot in this analysis.
514 SlotIndex getLastIndex() {
515 return SlotIndex(back(), 0);
518 /// Returns the invalid index marker for this analysis.
519 SlotIndex getInvalidIndex() {
520 return getZeroIndex();
523 /// Returns the distance between the highest and lowest indexes allocated
525 unsigned getIndexesLength() const {
526 assert(front()->getIndex() == 0 &&
527 "Initial index isn't zero?");
529 return back()->getIndex();
532 /// Returns the number of instructions in the function.
533 unsigned getFunctionSize() const {
537 /// Returns true if the given machine instr is mapped to an index,
538 /// otherwise returns false.
539 bool hasIndex(const MachineInstr *instr) const {
540 return (mi2iMap.find(instr) != mi2iMap.end());
543 /// Returns the base index for the given instruction.
544 SlotIndex getInstructionIndex(const MachineInstr *instr) const {
545 Mi2IndexMap::const_iterator itr = mi2iMap.find(instr);
546 assert(itr != mi2iMap.end() && "Instruction not found in maps.");
550 /// Returns the instruction for the given index, or null if the given
551 /// index has no instruction associated with it.
552 MachineInstr* getInstructionFromIndex(SlotIndex index) const {
553 return index.entry().getInstr();
556 /// Returns the next non-null index.
557 SlotIndex getNextNonNullIndex(SlotIndex index) {
558 SlotIndex nextNonNull = index.getNextIndex();
560 while (&nextNonNull.entry() != getTail() &&
561 getInstructionFromIndex(nextNonNull) == 0) {
562 nextNonNull = nextNonNull.getNextIndex();
568 /// Returns the first index in the given basic block.
569 SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const {
570 MBB2IdxMap::const_iterator itr = mbb2IdxMap.find(mbb);
571 assert(itr != mbb2IdxMap.end() && "MBB not found in maps.");
572 return itr->second.first;
575 /// Returns the last index in the given basic block.
576 SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const {
577 MBB2IdxMap::const_iterator itr = mbb2IdxMap.find(mbb);
578 assert(itr != mbb2IdxMap.end() && "MBB not found in maps.");
579 return itr->second.second;
582 /// Returns the terminator gap for the given index.
583 SlotIndex getTerminatorGap(const MachineBasicBlock *mbb) {
584 TerminatorGapsMap::iterator itr = terminatorGaps.find(mbb);
585 assert(itr != terminatorGaps.end() &&
586 "All MBBs should have terminator gaps in their indexes.");
590 /// Returns the basic block which the given index falls in.
591 MachineBasicBlock* getMBBFromIndex(SlotIndex index) const {
592 std::vector<IdxMBBPair>::const_iterator I =
593 std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), index);
594 // Take the pair containing the index
595 std::vector<IdxMBBPair>::const_iterator J =
596 ((I != idx2MBBMap.end() && I->first > index) ||
597 (I == idx2MBBMap.end() && idx2MBBMap.size()>0)) ? (I-1): I;
599 assert(J != idx2MBBMap.end() && J->first <= index &&
600 index < getMBBEndIdx(J->second) &&
601 "index does not correspond to an MBB");
605 bool findLiveInMBBs(SlotIndex start, SlotIndex end,
606 SmallVectorImpl<MachineBasicBlock*> &mbbs) const {
607 std::vector<IdxMBBPair>::const_iterator itr =
608 std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), start);
611 while (itr != idx2MBBMap.end()) {
612 if (itr->first >= end)
614 mbbs.push_back(itr->second);
621 /// Return a list of MBBs that can be reach via any branches or
623 bool findReachableMBBs(SlotIndex start, SlotIndex end,
624 SmallVectorImpl<MachineBasicBlock*> &mbbs) const {
625 std::vector<IdxMBBPair>::const_iterator itr =
626 std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), start);
629 while (itr != idx2MBBMap.end()) {
630 if (itr->first > end)
632 MachineBasicBlock *mbb = itr->second;
633 if (getMBBEndIdx(mbb) > end)
635 for (MachineBasicBlock::succ_iterator si = mbb->succ_begin(),
636 se = mbb->succ_end(); si != se; ++si)
644 /// Returns the MBB covering the given range, or null if the range covers
645 /// more than one basic block.
646 MachineBasicBlock* getMBBCoveringRange(SlotIndex start, SlotIndex end) const {
648 assert(start < end && "Backwards ranges not allowed.");
650 std::vector<IdxMBBPair>::const_iterator itr =
651 std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), start);
653 if (itr == idx2MBBMap.end()) {
658 // Check that we don't cross the boundary into this block.
659 if (itr->first < end)
664 if (itr->first <= start)
670 /// Insert the given machine instruction into the mapping. Returns the
672 SlotIndex insertMachineInstrInMaps(MachineInstr *mi,
673 bool *deferredRenumber = 0) {
674 assert(mi2iMap.find(mi) == mi2iMap.end() && "Instr already indexed.");
676 MachineBasicBlock *mbb = mi->getParent();
678 assert(mbb != 0 && "Instr must be added to function.");
680 MBB2IdxMap::iterator mbbRangeItr = mbb2IdxMap.find(mbb);
682 assert(mbbRangeItr != mbb2IdxMap.end() &&
683 "Instruction's parent MBB has not been added to SlotIndexes.");
685 MachineBasicBlock::iterator miItr(mi);
686 bool needRenumber = false;
687 IndexListEntry *newEntry;
688 // Get previous index, considering that not all instructions are indexed.
689 IndexListEntry *prevEntry;
691 // If mi is at the mbb beginning, get the prev index from the mbb.
692 if (miItr == mbb->begin()) {
693 prevEntry = &mbbRangeItr->second.first.entry();
696 // Otherwise rewind until we find a mapped instruction.
697 Mi2IndexMap::const_iterator itr = mi2iMap.find(--miItr);
698 if (itr != mi2iMap.end()) {
699 prevEntry = &itr->second.entry();
704 // Get next entry from previous entry.
705 IndexListEntry *nextEntry = prevEntry->getNext();
707 // Get a number for the new instr, or 0 if there's no room currently.
708 // In the latter case we'll force a renumber later.
709 unsigned dist = nextEntry->getIndex() - prevEntry->getIndex();
710 unsigned newNumber = dist > SlotIndex::NUM ?
711 prevEntry->getIndex() + ((dist >> 1) & ~3U) : 0;
713 if (newNumber == 0) {
717 // Insert a new list entry for mi.
718 newEntry = createEntry(mi, newNumber);
719 insert(nextEntry, newEntry);
721 SlotIndex newIndex(newEntry, SlotIndex::LOAD);
722 mi2iMap.insert(std::make_pair(mi, newIndex));
724 if (miItr == mbb->end()) {
725 // If this is the last instr in the MBB then we need to fix up the bb
727 mbbRangeItr->second.second = SlotIndex(newEntry, SlotIndex::STORE);
730 // Renumber if we need to.
732 if (deferredRenumber == 0)
735 *deferredRenumber = true;
741 /// Add all instructions in the vector to the index list. This method will
742 /// defer renumbering until all instrs have been added, and should be
743 /// preferred when adding multiple instrs.
744 void insertMachineInstrsInMaps(SmallVectorImpl<MachineInstr*> &mis) {
745 bool renumber = false;
747 for (SmallVectorImpl<MachineInstr*>::iterator
748 miItr = mis.begin(), miEnd = mis.end();
749 miItr != miEnd; ++miItr) {
750 insertMachineInstrInMaps(*miItr, &renumber);
758 /// Remove the given machine instruction from the mapping.
759 void removeMachineInstrFromMaps(MachineInstr *mi) {
760 // remove index -> MachineInstr and
761 // MachineInstr -> index mappings
762 Mi2IndexMap::iterator mi2iItr = mi2iMap.find(mi);
763 if (mi2iItr != mi2iMap.end()) {
764 IndexListEntry *miEntry(&mi2iItr->second.entry());
765 assert(miEntry->getInstr() == mi && "Instruction indexes broken.");
766 // FIXME: Eventually we want to actually delete these indexes.
767 miEntry->setInstr(0);
768 mi2iMap.erase(mi2iItr);
772 /// ReplaceMachineInstrInMaps - Replacing a machine instr with a new one in
773 /// maps used by register allocator.
774 void replaceMachineInstrInMaps(MachineInstr *mi, MachineInstr *newMI) {
775 Mi2IndexMap::iterator mi2iItr = mi2iMap.find(mi);
776 if (mi2iItr == mi2iMap.end())
778 SlotIndex replaceBaseIndex = mi2iItr->second;
779 IndexListEntry *miEntry(&replaceBaseIndex.entry());
780 assert(miEntry->getInstr() == mi &&
781 "Mismatched instruction in index tables.");
782 miEntry->setInstr(newMI);
783 mi2iMap.erase(mi2iItr);
784 mi2iMap.insert(std::make_pair(newMI, replaceBaseIndex));
787 /// Add the given MachineBasicBlock into the maps.
788 void insertMBBInMaps(MachineBasicBlock *mbb) {
789 MachineFunction::iterator nextMBB =
790 llvm::next(MachineFunction::iterator(mbb));
791 IndexListEntry *startEntry = createEntry(0, 0);
792 IndexListEntry *terminatorEntry = createEntry(0, 0);
793 IndexListEntry *nextEntry = 0;
795 if (nextMBB == mbb->getParent()->end()) {
796 nextEntry = getTail();
798 nextEntry = &getMBBStartIdx(nextMBB).entry();
801 insert(nextEntry, startEntry);
802 insert(nextEntry, terminatorEntry);
804 SlotIndex startIdx(startEntry, SlotIndex::LOAD);
805 SlotIndex terminatorIdx(terminatorEntry, SlotIndex::PHI_BIT);
806 SlotIndex endIdx(nextEntry, SlotIndex::LOAD);
808 terminatorGaps.insert(
809 std::make_pair(mbb, terminatorIdx));
812 std::make_pair(mbb, std::make_pair(startIdx, endIdx)));
814 idx2MBBMap.push_back(IdxMBBPair(startIdx, mbb));
816 if (MachineFunction::iterator(mbb) != mbb->getParent()->begin()) {
817 // Have to update the end index of the previous block.
818 MachineBasicBlock *priorMBB =
819 llvm::prior(MachineFunction::iterator(mbb));
820 mbb2IdxMap[priorMBB].second = startIdx;
824 std::sort(idx2MBBMap.begin(), idx2MBBMap.end(), Idx2MBBCompare());
833 #endif // LLVM_CODEGEN_LIVEINDEX_H