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>;
132 static const unsigned PHI_BIT = 1 << 2;
134 PointerIntPair<IndexListEntry*, 3, unsigned> lie;
136 SlotIndex(IndexListEntry *entry, unsigned phiAndSlot)
137 : lie(entry, phiAndSlot) {
138 assert(entry != 0 && "Attempt to construct index with 0 pointer.");
141 IndexListEntry& entry() const {
142 return *lie.getPointer();
145 int getIndex() const {
146 return entry().getIndex() | getSlot();
149 static inline unsigned getHashValue(const SlotIndex &v) {
150 IndexListEntry *ptrVal = &v.entry();
151 return (unsigned((intptr_t)ptrVal) >> 4) ^
152 (unsigned((intptr_t)ptrVal) >> 9);
157 // FIXME: Ugh. This is public because LiveIntervalAnalysis is still using it
158 // for some spill weight stuff. Fix that, then make this private.
159 enum Slot { LOAD, USE, DEF, STORE, NUM };
161 static inline SlotIndex getEmptyKey() {
162 return SlotIndex(IndexListEntry::getEmptyKeyEntry(), 0);
165 static inline SlotIndex getTombstoneKey() {
166 return SlotIndex(IndexListEntry::getTombstoneKeyEntry(), 0);
169 /// Construct an invalid index.
170 SlotIndex() : lie(IndexListEntry::getEmptyKeyEntry(), 0) {}
172 // Construct a new slot index from the given one, set the phi flag on the
173 // new index to the value of the phi parameter.
174 SlotIndex(const SlotIndex &li, bool phi)
175 : lie(&li.entry(), phi ? PHI_BIT | li.getSlot() : (unsigned)li.getSlot()){
176 assert(lie.getPointer() != 0 &&
177 "Attempt to construct index with 0 pointer.");
180 // Construct a new slot index from the given one, set the phi flag on the
181 // new index to the value of the phi parameter, and the slot to the new slot.
182 SlotIndex(const SlotIndex &li, bool phi, Slot s)
183 : lie(&li.entry(), phi ? PHI_BIT | s : (unsigned)s) {
184 assert(lie.getPointer() != 0 &&
185 "Attempt to construct index with 0 pointer.");
188 /// Returns true if this is a valid index. Invalid indicies do
189 /// not point into an index table, and cannot be compared.
190 bool isValid() const {
191 IndexListEntry *entry = lie.getPointer();
192 return ((entry!= 0) && (entry->isValid()));
195 /// Print this index to the given raw_ostream.
196 void print(raw_ostream &os) const;
198 /// Dump this index to stderr.
201 /// Compare two SlotIndex objects for equality.
202 bool operator==(SlotIndex other) const {
203 return getIndex() == other.getIndex();
205 /// Compare two SlotIndex objects for inequality.
206 bool operator!=(SlotIndex other) const {
207 return getIndex() != other.getIndex();
210 /// Compare two SlotIndex objects. Return true if the first index
211 /// is strictly lower than the second.
212 bool operator<(SlotIndex other) const {
213 return getIndex() < other.getIndex();
215 /// Compare two SlotIndex objects. Return true if the first index
216 /// is lower than, or equal to, the second.
217 bool operator<=(SlotIndex other) const {
218 return getIndex() <= other.getIndex();
221 /// Compare two SlotIndex objects. Return true if the first index
222 /// is greater than the second.
223 bool operator>(SlotIndex other) const {
224 return getIndex() > other.getIndex();
227 /// Compare two SlotIndex objects. Return true if the first index
228 /// is greater than, or equal to, the second.
229 bool operator>=(SlotIndex other) const {
230 return getIndex() >= other.getIndex();
233 /// Return the distance from this index to the given one.
234 int distance(SlotIndex other) const {
235 return other.getIndex() - getIndex();
238 /// Returns the slot for this SlotIndex.
239 Slot getSlot() const {
240 return static_cast<Slot>(lie.getInt() & ~PHI_BIT);
243 /// Returns the state of the PHI bit.
245 return lie.getInt() & PHI_BIT;
248 /// Returns the base index for associated with this index. The base index
249 /// is the one associated with the LOAD slot for the instruction pointed to
251 SlotIndex getBaseIndex() const {
252 return getLoadIndex();
255 /// Returns the boundary index for associated with this index. The boundary
256 /// index is the one associated with the LOAD slot for the instruction
257 /// pointed to by this index.
258 SlotIndex getBoundaryIndex() const {
259 return getStoreIndex();
262 /// Returns the index of the LOAD slot for the instruction pointed to by
264 SlotIndex getLoadIndex() const {
265 return SlotIndex(&entry(), SlotIndex::LOAD);
268 /// Returns the index of the USE slot for the instruction pointed to by
270 SlotIndex getUseIndex() const {
271 return SlotIndex(&entry(), SlotIndex::USE);
274 /// Returns the index of the DEF slot for the instruction pointed to by
276 SlotIndex getDefIndex() const {
277 return SlotIndex(&entry(), SlotIndex::DEF);
280 /// Returns the index of the STORE slot for the instruction pointed to by
282 SlotIndex getStoreIndex() const {
283 return SlotIndex(&entry(), SlotIndex::STORE);
286 /// Returns the next slot in the index list. This could be either the
287 /// next slot for the instruction pointed to by this index or, if this
288 /// index is a STORE, the first slot for the next instruction.
289 /// WARNING: This method is considerably more expensive than the methods
290 /// that return specific slots (getUseIndex(), etc). If you can - please
291 /// use one of those methods.
292 SlotIndex getNextSlot() const {
294 if (s == SlotIndex::STORE) {
295 return SlotIndex(entry().getNext(), SlotIndex::LOAD);
297 return SlotIndex(&entry(), s + 1);
300 /// Returns the next index. This is the index corresponding to the this
301 /// index's slot, but for the next instruction.
302 SlotIndex getNextIndex() const {
303 return SlotIndex(entry().getNext(), getSlot());
306 /// Returns the previous slot in the index list. This could be either the
307 /// previous slot for the instruction pointed to by this index or, if this
308 /// index is a LOAD, the last slot for the previous instruction.
309 /// WARNING: This method is considerably more expensive than the methods
310 /// that return specific slots (getUseIndex(), etc). If you can - please
311 /// use one of those methods.
312 SlotIndex getPrevSlot() const {
314 if (s == SlotIndex::LOAD) {
315 return SlotIndex(entry().getPrev(), SlotIndex::STORE);
317 return SlotIndex(&entry(), s - 1);
320 /// Returns the previous index. This is the index corresponding to this
321 /// index's slot, but for the previous instruction.
322 SlotIndex getPrevIndex() const {
323 return SlotIndex(entry().getPrev(), getSlot());
328 /// DenseMapInfo specialization for SlotIndex.
330 struct DenseMapInfo<SlotIndex> {
331 static inline SlotIndex getEmptyKey() {
332 return SlotIndex::getEmptyKey();
334 static inline SlotIndex getTombstoneKey() {
335 return SlotIndex::getTombstoneKey();
337 static inline unsigned getHashValue(const SlotIndex &v) {
338 return SlotIndex::getHashValue(v);
340 static inline bool isEqual(const SlotIndex &LHS, const SlotIndex &RHS) {
345 template <> struct isPodLike<SlotIndex> { static const bool value = true; };
348 inline raw_ostream& operator<<(raw_ostream &os, SlotIndex li) {
353 typedef std::pair<SlotIndex, MachineBasicBlock*> IdxMBBPair;
355 inline bool operator<(SlotIndex V, const IdxMBBPair &IM) {
359 inline bool operator<(const IdxMBBPair &IM, SlotIndex V) {
363 struct Idx2MBBCompare {
364 bool operator()(const IdxMBBPair &LHS, const IdxMBBPair &RHS) const {
365 return LHS.first < RHS.first;
369 /// SlotIndexes pass.
371 /// This pass assigns indexes to each instruction.
372 class SlotIndexes : public MachineFunctionPass {
376 IndexListEntry *indexListHead;
377 unsigned functionSize;
379 typedef DenseMap<const MachineInstr*, SlotIndex> Mi2IndexMap;
382 /// MBB2IdxMap - The indexes of the first and last instructions in the
383 /// specified basic block.
384 typedef DenseMap<const MachineBasicBlock*,
385 std::pair<SlotIndex, SlotIndex> > MBB2IdxMap;
386 MBB2IdxMap mbb2IdxMap;
388 /// Idx2MBBMap - Sorted list of pairs of index of first instruction
390 std::vector<IdxMBBPair> idx2MBBMap;
392 typedef DenseMap<const MachineBasicBlock*, SlotIndex> TerminatorGapsMap;
393 TerminatorGapsMap terminatorGaps;
395 // IndexListEntry allocator.
396 BumpPtrAllocator ileAllocator;
398 IndexListEntry* createEntry(MachineInstr *mi, unsigned index) {
399 IndexListEntry *entry =
400 static_cast<IndexListEntry*>(
401 ileAllocator.Allocate(sizeof(IndexListEntry),
402 alignof<IndexListEntry>()));
404 new (entry) IndexListEntry(mi, index);
410 assert(indexListHead == 0 && "Zero entry non-null at initialisation.");
411 indexListHead = createEntry(0, ~0U);
412 indexListHead->setNext(0);
413 indexListHead->setPrev(indexListHead);
418 ileAllocator.Reset();
421 IndexListEntry* getTail() {
422 assert(indexListHead != 0 && "Call to getTail on uninitialized list.");
423 return indexListHead->getPrev();
426 const IndexListEntry* getTail() const {
427 assert(indexListHead != 0 && "Call to getTail on uninitialized list.");
428 return indexListHead->getPrev();
431 // Returns true if the index list is empty.
432 bool empty() const { return (indexListHead == getTail()); }
434 IndexListEntry* front() {
435 assert(!empty() && "front() called on empty index list.");
436 return indexListHead;
439 const IndexListEntry* front() const {
440 assert(!empty() && "front() called on empty index list.");
441 return indexListHead;
444 IndexListEntry* back() {
445 assert(!empty() && "back() called on empty index list.");
446 return getTail()->getPrev();
449 const IndexListEntry* back() const {
450 assert(!empty() && "back() called on empty index list.");
451 return getTail()->getPrev();
454 /// Insert a new entry before itr.
455 void insert(IndexListEntry *itr, IndexListEntry *val) {
456 assert(itr != 0 && "itr should not be null.");
457 IndexListEntry *prev = itr->getPrev();
461 if (itr != indexListHead) {
470 /// Push a new entry on to the end of the list.
471 void push_back(IndexListEntry *val) {
472 insert(getTail(), val);
478 SlotIndexes() : MachineFunctionPass(&ID), indexListHead(0) {}
480 virtual void getAnalysisUsage(AnalysisUsage &au) const;
481 virtual void releaseMemory();
483 virtual bool runOnMachineFunction(MachineFunction &fn);
485 /// Dump the indexes.
488 /// Renumber the index list, providing space for new instructions.
489 void renumberIndexes();
491 /// Returns the zero index for this analysis.
492 SlotIndex getZeroIndex() {
493 assert(front()->getIndex() == 0 && "First index is not 0?");
494 return SlotIndex(front(), 0);
497 /// Returns the base index of the last slot in this analysis.
498 SlotIndex getLastIndex() {
499 return SlotIndex(back(), 0);
502 /// Returns the invalid index marker for this analysis.
503 SlotIndex getInvalidIndex() {
504 return getZeroIndex();
507 /// Returns the distance between the highest and lowest indexes allocated
509 unsigned getIndexesLength() const {
510 assert(front()->getIndex() == 0 &&
511 "Initial index isn't zero?");
513 return back()->getIndex();
516 /// Returns the number of instructions in the function.
517 unsigned getFunctionSize() const {
521 /// Returns true if the given machine instr is mapped to an index,
522 /// otherwise returns false.
523 bool hasIndex(const MachineInstr *instr) const {
524 return (mi2iMap.find(instr) != mi2iMap.end());
527 /// Returns the base index for the given instruction.
528 SlotIndex getInstructionIndex(const MachineInstr *instr) const {
529 Mi2IndexMap::const_iterator itr = mi2iMap.find(instr);
530 assert(itr != mi2iMap.end() && "Instruction not found in maps.");
534 /// Returns the instruction for the given index, or null if the given
535 /// index has no instruction associated with it.
536 MachineInstr* getInstructionFromIndex(SlotIndex index) const {
537 return index.entry().getInstr();
540 /// Returns the next non-null index.
541 SlotIndex getNextNonNullIndex(SlotIndex index) {
542 SlotIndex nextNonNull = index.getNextIndex();
544 while (&nextNonNull.entry() != getTail() &&
545 getInstructionFromIndex(nextNonNull) == 0) {
546 nextNonNull = nextNonNull.getNextIndex();
552 /// Returns the first index in the given basic block.
553 SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const {
554 MBB2IdxMap::const_iterator itr = mbb2IdxMap.find(mbb);
555 assert(itr != mbb2IdxMap.end() && "MBB not found in maps.");
556 return itr->second.first;
559 /// Returns the last index in the given basic block.
560 SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const {
561 MBB2IdxMap::const_iterator itr = mbb2IdxMap.find(mbb);
562 assert(itr != mbb2IdxMap.end() && "MBB not found in maps.");
563 return itr->second.second;
566 /// Returns the terminator gap for the given index.
567 SlotIndex getTerminatorGap(const MachineBasicBlock *mbb) {
568 TerminatorGapsMap::iterator itr = terminatorGaps.find(mbb);
569 assert(itr != terminatorGaps.end() &&
570 "All MBBs should have terminator gaps in their indexes.");
574 /// Returns the basic block which the given index falls in.
575 MachineBasicBlock* getMBBFromIndex(SlotIndex index) const {
576 std::vector<IdxMBBPair>::const_iterator I =
577 std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), index);
578 // Take the pair containing the index
579 std::vector<IdxMBBPair>::const_iterator J =
580 ((I != idx2MBBMap.end() && I->first > index) ||
581 (I == idx2MBBMap.end() && idx2MBBMap.size()>0)) ? (I-1): I;
583 assert(J != idx2MBBMap.end() && J->first <= index &&
584 index < getMBBEndIdx(J->second) &&
585 "index does not correspond to an MBB");
589 bool findLiveInMBBs(SlotIndex start, SlotIndex end,
590 SmallVectorImpl<MachineBasicBlock*> &mbbs) const {
591 std::vector<IdxMBBPair>::const_iterator itr =
592 std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), start);
595 while (itr != idx2MBBMap.end()) {
596 if (itr->first >= end)
598 mbbs.push_back(itr->second);
605 /// Return a list of MBBs that can be reach via any branches or
607 bool findReachableMBBs(SlotIndex start, SlotIndex end,
608 SmallVectorImpl<MachineBasicBlock*> &mbbs) const {
609 std::vector<IdxMBBPair>::const_iterator itr =
610 std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), start);
613 while (itr != idx2MBBMap.end()) {
614 if (itr->first > end)
616 MachineBasicBlock *mbb = itr->second;
617 if (getMBBEndIdx(mbb) > end)
619 for (MachineBasicBlock::succ_iterator si = mbb->succ_begin(),
620 se = mbb->succ_end(); si != se; ++si)
628 /// Returns the MBB covering the given range, or null if the range covers
629 /// more than one basic block.
630 MachineBasicBlock* getMBBCoveringRange(SlotIndex start, SlotIndex end) const {
632 assert(start < end && "Backwards ranges not allowed.");
634 std::vector<IdxMBBPair>::const_iterator itr =
635 std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), start);
637 if (itr == idx2MBBMap.end()) {
642 // Check that we don't cross the boundary into this block.
643 if (itr->first < end)
648 if (itr->first <= start)
654 /// Insert the given machine instruction into the mapping. Returns the
656 SlotIndex insertMachineInstrInMaps(MachineInstr *mi,
657 bool *deferredRenumber = 0) {
658 assert(mi2iMap.find(mi) == mi2iMap.end() && "Instr already indexed.");
660 MachineBasicBlock *mbb = mi->getParent();
662 assert(mbb != 0 && "Instr must be added to function.");
664 MBB2IdxMap::iterator mbbRangeItr = mbb2IdxMap.find(mbb);
666 assert(mbbRangeItr != mbb2IdxMap.end() &&
667 "Instruction's parent MBB has not been added to SlotIndexes.");
669 MachineBasicBlock::iterator miItr(mi);
670 bool needRenumber = false;
671 IndexListEntry *newEntry;
672 // Get previous index, considering that not all instructions are indexed.
673 IndexListEntry *prevEntry;
675 // If mi is at the mbb beginning, get the prev index from the mbb.
676 if (miItr == mbb->begin()) {
677 prevEntry = &mbbRangeItr->second.first.entry();
680 // Otherwise rewind until we find a mapped instruction.
681 Mi2IndexMap::const_iterator itr = mi2iMap.find(--miItr);
682 if (itr != mi2iMap.end()) {
683 prevEntry = &itr->second.entry();
688 // Get next entry from previous entry.
689 IndexListEntry *nextEntry = prevEntry->getNext();
691 // Get a number for the new instr, or 0 if there's no room currently.
692 // In the latter case we'll force a renumber later.
693 unsigned dist = nextEntry->getIndex() - prevEntry->getIndex();
694 unsigned newNumber = dist > SlotIndex::NUM ?
695 prevEntry->getIndex() + ((dist >> 1) & ~3U) : 0;
697 if (newNumber == 0) {
701 // Insert a new list entry for mi.
702 newEntry = createEntry(mi, newNumber);
703 insert(nextEntry, newEntry);
705 SlotIndex newIndex(newEntry, SlotIndex::LOAD);
706 mi2iMap.insert(std::make_pair(mi, newIndex));
708 if (miItr == mbb->end()) {
709 // If this is the last instr in the MBB then we need to fix up the bb
711 mbbRangeItr->second.second = SlotIndex(newEntry, SlotIndex::STORE);
714 // Renumber if we need to.
716 if (deferredRenumber == 0)
719 *deferredRenumber = true;
725 /// Add all instructions in the vector to the index list. This method will
726 /// defer renumbering until all instrs have been added, and should be
727 /// preferred when adding multiple instrs.
728 void insertMachineInstrsInMaps(SmallVectorImpl<MachineInstr*> &mis) {
729 bool renumber = false;
731 for (SmallVectorImpl<MachineInstr*>::iterator
732 miItr = mis.begin(), miEnd = mis.end();
733 miItr != miEnd; ++miItr) {
734 insertMachineInstrInMaps(*miItr, &renumber);
742 /// Remove the given machine instruction from the mapping.
743 void removeMachineInstrFromMaps(MachineInstr *mi) {
744 // remove index -> MachineInstr and
745 // MachineInstr -> index mappings
746 Mi2IndexMap::iterator mi2iItr = mi2iMap.find(mi);
747 if (mi2iItr != mi2iMap.end()) {
748 IndexListEntry *miEntry(&mi2iItr->second.entry());
749 assert(miEntry->getInstr() == mi && "Instruction indexes broken.");
750 // FIXME: Eventually we want to actually delete these indexes.
751 miEntry->setInstr(0);
752 mi2iMap.erase(mi2iItr);
756 /// ReplaceMachineInstrInMaps - Replacing a machine instr with a new one in
757 /// maps used by register allocator.
758 void replaceMachineInstrInMaps(MachineInstr *mi, MachineInstr *newMI) {
759 Mi2IndexMap::iterator mi2iItr = mi2iMap.find(mi);
760 if (mi2iItr == mi2iMap.end())
762 SlotIndex replaceBaseIndex = mi2iItr->second;
763 IndexListEntry *miEntry(&replaceBaseIndex.entry());
764 assert(miEntry->getInstr() == mi &&
765 "Mismatched instruction in index tables.");
766 miEntry->setInstr(newMI);
767 mi2iMap.erase(mi2iItr);
768 mi2iMap.insert(std::make_pair(newMI, replaceBaseIndex));
771 /// Add the given MachineBasicBlock into the maps.
772 void insertMBBInMaps(MachineBasicBlock *mbb) {
773 MachineFunction::iterator nextMBB =
774 llvm::next(MachineFunction::iterator(mbb));
775 IndexListEntry *startEntry = createEntry(0, 0);
776 IndexListEntry *terminatorEntry = createEntry(0, 0);
777 IndexListEntry *nextEntry = 0;
779 if (nextMBB == mbb->getParent()->end()) {
780 nextEntry = getTail();
782 nextEntry = &getMBBStartIdx(nextMBB).entry();
785 insert(nextEntry, startEntry);
786 insert(nextEntry, terminatorEntry);
788 SlotIndex startIdx(startEntry, SlotIndex::LOAD);
789 SlotIndex terminatorIdx(terminatorEntry, SlotIndex::PHI_BIT);
790 SlotIndex endIdx(nextEntry, SlotIndex::LOAD);
792 terminatorGaps.insert(
793 std::make_pair(mbb, terminatorIdx));
796 std::make_pair(mbb, std::make_pair(startIdx, endIdx)));
798 idx2MBBMap.push_back(IdxMBBPair(startIdx, mbb));
800 if (MachineFunction::iterator(mbb) != mbb->getParent()->begin()) {
801 // Have to update the end index of the previous block.
802 MachineBasicBlock *priorMBB =
803 llvm::prior(MachineFunction::iterator(mbb));
804 mbb2IdxMap[priorMBB].second = startIdx;
808 std::sort(idx2MBBMap.begin(), idx2MBBMap.end(), Idx2MBBCompare());
817 #endif // LLVM_CODEGEN_LIVEINDEX_H