1 //===- llvm/CodeGen/SlotIndexes.h - Slot indexes representation -*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements SlotIndex and related classes. The purpose of SlotIndex
10 // is to describe a position at which a register can become live, or cease to
13 // SlotIndex is mostly a proxy for entries of the SlotIndexList, a class which
14 // is held is LiveIntervals and provides the real numbering. This allows
15 // LiveIntervals to perform largely transparent renumbering.
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_CODEGEN_SLOTINDEXES_H
19 #define LLVM_CODEGEN_SLOTINDEXES_H
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/IntervalMap.h"
23 #include "llvm/ADT/PointerIntPair.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/ADT/ilist.h"
26 #include "llvm/CodeGen/MachineBasicBlock.h"
27 #include "llvm/CodeGen/MachineFunction.h"
28 #include "llvm/CodeGen/MachineFunctionPass.h"
29 #include "llvm/CodeGen/MachineInstr.h"
30 #include "llvm/CodeGen/MachineInstrBundle.h"
31 #include "llvm/Pass.h"
32 #include "llvm/Support/Allocator.h"
42 /// This class represents an entry in the slot index list held in the
43 /// SlotIndexes pass. It should not be used directly. See the
44 /// SlotIndex & SlotIndexes classes for the public interface to this
46 class IndexListEntry
: public ilist_node
<IndexListEntry
> {
51 IndexListEntry(MachineInstr
*mi
, unsigned index
) : mi(mi
), index(index
) {}
53 MachineInstr
* getInstr() const { return mi
; }
54 void setInstr(MachineInstr
*mi
) {
58 unsigned getIndex() const { return index
; }
59 void setIndex(unsigned index
) {
63 #ifdef EXPENSIVE_CHECKS
64 // When EXPENSIVE_CHECKS is defined, "erased" index list entries will
65 // actually be moved to a "graveyard" list, and have their pointers
66 // poisoned, so that dangling SlotIndex access can be reliably detected.
68 intptr_t tmp
= reinterpret_cast<intptr_t>(mi
);
69 assert(((tmp
& 0x1) == 0x0) && "Pointer already poisoned?");
71 mi
= reinterpret_cast<MachineInstr
*>(tmp
);
74 bool isPoisoned() const { return (reinterpret_cast<intptr_t>(mi
) & 0x1) == 0x1; }
75 #endif // EXPENSIVE_CHECKS
79 struct ilist_alloc_traits
<IndexListEntry
>
80 : public ilist_noalloc_traits
<IndexListEntry
> {};
82 /// SlotIndex - An opaque wrapper around machine indexes.
84 friend class SlotIndexes
;
87 /// Basic block boundary. Used for live ranges entering and leaving a
88 /// block without being live in the layout neighbor. Also used as the
89 /// def slot of PHI-defs.
92 /// Early-clobber register use/def slot. A live range defined at
93 /// Slot_EarlyClobber interferes with normal live ranges killed at
94 /// Slot_Register. Also used as the kill slot for live ranges tied to an
95 /// early-clobber def.
98 /// Normal register use/def slot. Normal instructions kill and define
99 /// register live ranges at this slot.
102 /// Dead def kill point. Kill slot for a live range that is defined by
103 /// the same instruction (Slot_Register or Slot_EarlyClobber), but isn't
110 PointerIntPair
<IndexListEntry
*, 2, unsigned> lie
;
112 SlotIndex(IndexListEntry
*entry
, unsigned slot
)
113 : lie(entry
, slot
) {}
115 IndexListEntry
* listEntry() const {
116 assert(isValid() && "Attempt to compare reserved index.");
117 #ifdef EXPENSIVE_CHECKS
118 assert(!lie
.getPointer()->isPoisoned() &&
119 "Attempt to access deleted list-entry.");
120 #endif // EXPENSIVE_CHECKS
121 return lie
.getPointer();
124 unsigned getIndex() const {
125 return listEntry()->getIndex() | getSlot();
128 /// Returns the slot for this SlotIndex.
129 Slot
getSlot() const {
130 return static_cast<Slot
>(lie
.getInt());
135 /// The default distance between instructions as returned by distance().
136 /// This may vary as instructions are inserted and removed.
137 InstrDist
= 4 * Slot_Count
140 /// Construct an invalid index.
141 SlotIndex() = default;
143 // Construct a new slot index from the given one, and set the slot.
144 SlotIndex(const SlotIndex
&li
, Slot s
) : lie(li
.listEntry(), unsigned(s
)) {
145 assert(lie
.getPointer() != nullptr &&
146 "Attempt to construct index with 0 pointer.");
149 /// Returns true if this is a valid index. Invalid indices do
150 /// not point into an index table, and cannot be compared.
151 bool isValid() const {
152 return lie
.getPointer();
155 /// Return true for a valid index.
156 explicit operator bool() const { return isValid(); }
158 /// Print this index to the given raw_ostream.
159 void print(raw_ostream
&os
) const;
161 /// Dump this index to stderr.
164 /// Compare two SlotIndex objects for equality.
165 bool operator==(SlotIndex other
) const {
166 return lie
== other
.lie
;
168 /// Compare two SlotIndex objects for inequality.
169 bool operator!=(SlotIndex other
) const {
170 return lie
!= other
.lie
;
173 /// Compare two SlotIndex objects. Return true if the first index
174 /// is strictly lower than the second.
175 bool operator<(SlotIndex other
) const {
176 return getIndex() < other
.getIndex();
178 /// Compare two SlotIndex objects. Return true if the first index
179 /// is lower than, or equal to, the second.
180 bool operator<=(SlotIndex other
) const {
181 return getIndex() <= other
.getIndex();
184 /// Compare two SlotIndex objects. Return true if the first index
185 /// is greater than the second.
186 bool operator>(SlotIndex other
) const {
187 return getIndex() > other
.getIndex();
190 /// Compare two SlotIndex objects. Return true if the first index
191 /// is greater than, or equal to, the second.
192 bool operator>=(SlotIndex other
) const {
193 return getIndex() >= other
.getIndex();
196 /// isSameInstr - Return true if A and B refer to the same instruction.
197 static bool isSameInstr(SlotIndex A
, SlotIndex B
) {
198 return A
.lie
.getPointer() == B
.lie
.getPointer();
201 /// isEarlierInstr - Return true if A refers to an instruction earlier than
202 /// B. This is equivalent to A < B && !isSameInstr(A, B).
203 static bool isEarlierInstr(SlotIndex A
, SlotIndex B
) {
204 return A
.listEntry()->getIndex() < B
.listEntry()->getIndex();
207 /// Return true if A refers to the same instruction as B or an earlier one.
208 /// This is equivalent to !isEarlierInstr(B, A).
209 static bool isEarlierEqualInstr(SlotIndex A
, SlotIndex B
) {
210 return !isEarlierInstr(B
, A
);
213 /// Return the distance from this index to the given one.
214 int distance(SlotIndex other
) const {
215 return other
.getIndex() - getIndex();
218 /// Return the scaled distance from this index to the given one, where all
219 /// slots on the same instruction have zero distance.
220 int getInstrDistance(SlotIndex other
) const {
221 return (other
.listEntry()->getIndex() - listEntry()->getIndex())
225 /// isBlock - Returns true if this is a block boundary slot.
226 bool isBlock() const { return getSlot() == Slot_Block
; }
228 /// isEarlyClobber - Returns true if this is an early-clobber slot.
229 bool isEarlyClobber() const { return getSlot() == Slot_EarlyClobber
; }
231 /// isRegister - Returns true if this is a normal register use/def slot.
232 /// Note that early-clobber slots may also be used for uses and defs.
233 bool isRegister() const { return getSlot() == Slot_Register
; }
235 /// isDead - Returns true if this is a dead def kill slot.
236 bool isDead() const { return getSlot() == Slot_Dead
; }
238 /// Returns the base index for associated with this index. The base index
239 /// is the one associated with the Slot_Block slot for the instruction
240 /// pointed to by this index.
241 SlotIndex
getBaseIndex() const {
242 return SlotIndex(listEntry(), Slot_Block
);
245 /// Returns the boundary index for associated with this index. The boundary
246 /// index is the one associated with the Slot_Block slot for the instruction
247 /// pointed to by this index.
248 SlotIndex
getBoundaryIndex() const {
249 return SlotIndex(listEntry(), Slot_Dead
);
252 /// Returns the register use/def slot in the current instruction for a
253 /// normal or early-clobber def.
254 SlotIndex
getRegSlot(bool EC
= false) const {
255 return SlotIndex(listEntry(), EC
? Slot_EarlyClobber
: Slot_Register
);
258 /// Returns the dead def kill slot for the current instruction.
259 SlotIndex
getDeadSlot() const {
260 return SlotIndex(listEntry(), Slot_Dead
);
263 /// Returns the next slot in the index list. This could be either the
264 /// next slot for the instruction pointed to by this index or, if this
265 /// index is a STORE, the first slot for the next instruction.
266 /// WARNING: This method is considerably more expensive than the methods
267 /// that return specific slots (getUseIndex(), etc). If you can - please
268 /// use one of those methods.
269 SlotIndex
getNextSlot() const {
271 if (s
== Slot_Dead
) {
272 return SlotIndex(&*++listEntry()->getIterator(), Slot_Block
);
274 return SlotIndex(listEntry(), s
+ 1);
277 /// Returns the next index. This is the index corresponding to the this
278 /// index's slot, but for the next instruction.
279 SlotIndex
getNextIndex() const {
280 return SlotIndex(&*++listEntry()->getIterator(), getSlot());
283 /// Returns the previous slot in the index list. This could be either the
284 /// previous slot for the instruction pointed to by this index or, if this
285 /// index is a Slot_Block, the last slot for the previous instruction.
286 /// WARNING: This method is considerably more expensive than the methods
287 /// that return specific slots (getUseIndex(), etc). If you can - please
288 /// use one of those methods.
289 SlotIndex
getPrevSlot() const {
291 if (s
== Slot_Block
) {
292 return SlotIndex(&*--listEntry()->getIterator(), Slot_Dead
);
294 return SlotIndex(listEntry(), s
- 1);
297 /// Returns the previous index. This is the index corresponding to this
298 /// index's slot, but for the previous instruction.
299 SlotIndex
getPrevIndex() const {
300 return SlotIndex(&*--listEntry()->getIterator(), getSlot());
304 inline raw_ostream
& operator<<(raw_ostream
&os
, SlotIndex li
) {
309 using IdxMBBPair
= std::pair
<SlotIndex
, MachineBasicBlock
*>;
311 inline bool operator<(SlotIndex V
, const IdxMBBPair
&IM
) {
315 inline bool operator<(const IdxMBBPair
&IM
, SlotIndex V
) {
319 struct Idx2MBBCompare
{
320 bool operator()(const IdxMBBPair
&LHS
, const IdxMBBPair
&RHS
) const {
321 return LHS
.first
< RHS
.first
;
325 /// SlotIndexes pass.
327 /// This pass assigns indexes to each instruction.
328 class SlotIndexes
: public MachineFunctionPass
{
330 // IndexListEntry allocator.
331 BumpPtrAllocator ileAllocator
;
333 using IndexList
= ilist
<IndexListEntry
>;
336 #ifdef EXPENSIVE_CHECKS
337 IndexList graveyardList
;
338 #endif // EXPENSIVE_CHECKS
342 using Mi2IndexMap
= DenseMap
<const MachineInstr
*, SlotIndex
>;
345 /// MBBRanges - Map MBB number to (start, stop) indexes.
346 SmallVector
<std::pair
<SlotIndex
, SlotIndex
>, 8> MBBRanges
;
348 /// Idx2MBBMap - Sorted list of pairs of index of first instruction
350 SmallVector
<IdxMBBPair
, 8> idx2MBBMap
;
352 IndexListEntry
* createEntry(MachineInstr
*mi
, unsigned index
) {
353 IndexListEntry
*entry
=
354 static_cast<IndexListEntry
*>(ileAllocator
.Allocate(
355 sizeof(IndexListEntry
), alignof(IndexListEntry
)));
357 new (entry
) IndexListEntry(mi
, index
);
362 /// Renumber locally after inserting curItr.
363 void renumberIndexes(IndexList::iterator curItr
);
368 SlotIndexes() : MachineFunctionPass(ID
) {
369 initializeSlotIndexesPass(*PassRegistry::getPassRegistry());
372 ~SlotIndexes() override
{
373 // The indexList's nodes are all allocated in the BumpPtrAllocator.
374 indexList
.clearAndLeakNodesUnsafely();
377 void getAnalysisUsage(AnalysisUsage
&au
) const override
;
378 void releaseMemory() override
;
380 bool runOnMachineFunction(MachineFunction
&fn
) override
;
382 /// Dump the indexes.
385 /// Renumber the index list, providing space for new instructions.
386 void renumberIndexes();
388 /// Repair indexes after adding and removing instructions.
389 void repairIndexesInRange(MachineBasicBlock
*MBB
,
390 MachineBasicBlock::iterator Begin
,
391 MachineBasicBlock::iterator End
);
393 /// Returns the zero index for this analysis.
394 SlotIndex
getZeroIndex() {
395 assert(indexList
.front().getIndex() == 0 && "First index is not 0?");
396 return SlotIndex(&indexList
.front(), 0);
399 /// Returns the base index of the last slot in this analysis.
400 SlotIndex
getLastIndex() {
401 return SlotIndex(&indexList
.back(), 0);
404 /// Returns true if the given machine instr is mapped to an index,
405 /// otherwise returns false.
406 bool hasIndex(const MachineInstr
&instr
) const {
407 return mi2iMap
.count(&instr
);
410 /// Returns the base index for the given instruction.
411 SlotIndex
getInstructionIndex(const MachineInstr
&MI
) const {
412 // Instructions inside a bundle have the same number as the bundle itself.
413 auto BundleStart
= getBundleStart(MI
.getIterator());
414 auto BundleEnd
= getBundleEnd(MI
.getIterator());
415 // Use the first non-debug instruction in the bundle to get SlotIndex.
416 const MachineInstr
&BundleNonDebug
=
417 *skipDebugInstructionsForward(BundleStart
, BundleEnd
);
418 assert(!BundleNonDebug
.isDebugInstr() &&
419 "Could not use a debug instruction to query mi2iMap.");
420 Mi2IndexMap::const_iterator itr
= mi2iMap
.find(&BundleNonDebug
);
421 assert(itr
!= mi2iMap
.end() && "Instruction not found in maps.");
425 /// Returns the instruction for the given index, or null if the given
426 /// index has no instruction associated with it.
427 MachineInstr
* getInstructionFromIndex(SlotIndex index
) const {
428 return index
.isValid() ? index
.listEntry()->getInstr() : nullptr;
431 /// Returns the next non-null index, if one exists.
432 /// Otherwise returns getLastIndex().
433 SlotIndex
getNextNonNullIndex(SlotIndex Index
) {
434 IndexList::iterator I
= Index
.listEntry()->getIterator();
435 IndexList::iterator E
= indexList
.end();
438 return SlotIndex(&*I
, Index
.getSlot());
439 // We reached the end of the function.
440 return getLastIndex();
443 /// getIndexBefore - Returns the index of the last indexed instruction
444 /// before MI, or the start index of its basic block.
445 /// MI is not required to have an index.
446 SlotIndex
getIndexBefore(const MachineInstr
&MI
) const {
447 const MachineBasicBlock
*MBB
= MI
.getParent();
448 assert(MBB
&& "MI must be inserted in a basic block");
449 MachineBasicBlock::const_iterator I
= MI
, B
= MBB
->begin();
452 return getMBBStartIdx(MBB
);
454 Mi2IndexMap::const_iterator MapItr
= mi2iMap
.find(&*I
);
455 if (MapItr
!= mi2iMap
.end())
456 return MapItr
->second
;
460 /// getIndexAfter - Returns the index of the first indexed instruction
461 /// after MI, or the end index of its basic block.
462 /// MI is not required to have an index.
463 SlotIndex
getIndexAfter(const MachineInstr
&MI
) const {
464 const MachineBasicBlock
*MBB
= MI
.getParent();
465 assert(MBB
&& "MI must be inserted in a basic block");
466 MachineBasicBlock::const_iterator I
= MI
, E
= MBB
->end();
470 return getMBBEndIdx(MBB
);
471 Mi2IndexMap::const_iterator MapItr
= mi2iMap
.find(&*I
);
472 if (MapItr
!= mi2iMap
.end())
473 return MapItr
->second
;
477 /// Return the (start,end) range of the given basic block number.
478 const std::pair
<SlotIndex
, SlotIndex
> &
479 getMBBRange(unsigned Num
) const {
480 return MBBRanges
[Num
];
483 /// Return the (start,end) range of the given basic block.
484 const std::pair
<SlotIndex
, SlotIndex
> &
485 getMBBRange(const MachineBasicBlock
*MBB
) const {
486 return getMBBRange(MBB
->getNumber());
489 /// Returns the first index in the given basic block number.
490 SlotIndex
getMBBStartIdx(unsigned Num
) const {
491 return getMBBRange(Num
).first
;
494 /// Returns the first index in the given basic block.
495 SlotIndex
getMBBStartIdx(const MachineBasicBlock
*mbb
) const {
496 return getMBBRange(mbb
).first
;
499 /// Returns the last index in the given basic block number.
500 SlotIndex
getMBBEndIdx(unsigned Num
) const {
501 return getMBBRange(Num
).second
;
504 /// Returns the last index in the given basic block.
505 SlotIndex
getMBBEndIdx(const MachineBasicBlock
*mbb
) const {
506 return getMBBRange(mbb
).second
;
509 /// Iterator over the idx2MBBMap (sorted pairs of slot index of basic block
510 /// begin and basic block)
511 using MBBIndexIterator
= SmallVectorImpl
<IdxMBBPair
>::const_iterator
;
513 /// Move iterator to the next IdxMBBPair where the SlotIndex is greater or
515 MBBIndexIterator
advanceMBBIndex(MBBIndexIterator I
, SlotIndex To
) const {
516 return std::lower_bound(I
, idx2MBBMap
.end(), To
);
519 /// Get an iterator pointing to the IdxMBBPair with the biggest SlotIndex
520 /// that is greater or equal to \p Idx.
521 MBBIndexIterator
findMBBIndex(SlotIndex Idx
) const {
522 return advanceMBBIndex(idx2MBBMap
.begin(), Idx
);
525 /// Returns an iterator for the begin of the idx2MBBMap.
526 MBBIndexIterator
MBBIndexBegin() const {
527 return idx2MBBMap
.begin();
530 /// Return an iterator for the end of the idx2MBBMap.
531 MBBIndexIterator
MBBIndexEnd() const {
532 return idx2MBBMap
.end();
535 /// Returns the basic block which the given index falls in.
536 MachineBasicBlock
* getMBBFromIndex(SlotIndex index
) const {
537 if (MachineInstr
*MI
= getInstructionFromIndex(index
))
538 return MI
->getParent();
540 MBBIndexIterator I
= findMBBIndex(index
);
541 // Take the pair containing the index
543 ((I
!= MBBIndexEnd() && I
->first
> index
) ||
544 (I
== MBBIndexEnd() && !idx2MBBMap
.empty())) ? std::prev(I
) : I
;
546 assert(J
!= MBBIndexEnd() && J
->first
<= index
&&
547 index
< getMBBEndIdx(J
->second
) &&
548 "index does not correspond to an MBB");
552 /// Returns the MBB covering the given range, or null if the range covers
553 /// more than one basic block.
554 MachineBasicBlock
* getMBBCoveringRange(SlotIndex start
, SlotIndex end
) const {
556 assert(start
< end
&& "Backwards ranges not allowed.");
557 MBBIndexIterator itr
= findMBBIndex(start
);
558 if (itr
== MBBIndexEnd()) {
559 itr
= std::prev(itr
);
563 // Check that we don't cross the boundary into this block.
564 if (itr
->first
< end
)
567 itr
= std::prev(itr
);
569 if (itr
->first
<= start
)
575 /// Insert the given machine instruction into the mapping. Returns the
577 /// If Late is set and there are null indexes between mi's neighboring
578 /// instructions, create the new index after the null indexes instead of
580 SlotIndex
insertMachineInstrInMaps(MachineInstr
&MI
, bool Late
= false) {
581 assert(!MI
.isInsideBundle() &&
582 "Instructions inside bundles should use bundle start's slot.");
583 assert(mi2iMap
.find(&MI
) == mi2iMap
.end() && "Instr already indexed.");
584 // Numbering debug instructions could cause code generation to be
585 // affected by debug information.
586 assert(!MI
.isDebugInstr() && "Cannot number debug instructions.");
588 assert(MI
.getParent() != nullptr && "Instr must be added to function.");
590 // Get the entries where MI should be inserted.
591 IndexList::iterator prevItr
, nextItr
;
593 // Insert MI's index immediately before the following instruction.
594 nextItr
= getIndexAfter(MI
).listEntry()->getIterator();
595 prevItr
= std::prev(nextItr
);
597 // Insert MI's index immediately after the preceding instruction.
598 prevItr
= getIndexBefore(MI
).listEntry()->getIterator();
599 nextItr
= std::next(prevItr
);
602 // Get a number for the new instr, or 0 if there's no room currently.
603 // In the latter case we'll force a renumber later.
604 unsigned dist
= ((nextItr
->getIndex() - prevItr
->getIndex())/2) & ~3u;
605 unsigned newNumber
= prevItr
->getIndex() + dist
;
607 // Insert a new list entry for MI.
608 IndexList::iterator newItr
=
609 indexList
.insert(nextItr
, createEntry(&MI
, newNumber
));
611 // Renumber locally if we need to.
613 renumberIndexes(newItr
);
615 SlotIndex
newIndex(&*newItr
, SlotIndex::Slot_Block
);
616 mi2iMap
.insert(std::make_pair(&MI
, newIndex
));
620 /// Removes machine instruction (bundle) \p MI from the mapping.
621 /// This should be called before MachineInstr::eraseFromParent() is used to
622 /// remove a whole bundle or an unbundled instruction.
623 void removeMachineInstrFromMaps(MachineInstr
&MI
);
625 /// Removes a single machine instruction \p MI from the mapping.
626 /// This should be called before MachineInstr::eraseFromBundle() is used to
627 /// remove a single instruction (out of a bundle).
628 void removeSingleMachineInstrFromMaps(MachineInstr
&MI
);
630 /// ReplaceMachineInstrInMaps - Replacing a machine instr with a new one in
631 /// maps used by register allocator. \returns the index where the new
632 /// instruction was inserted.
633 SlotIndex
replaceMachineInstrInMaps(MachineInstr
&MI
, MachineInstr
&NewMI
) {
634 Mi2IndexMap::iterator mi2iItr
= mi2iMap
.find(&MI
);
635 if (mi2iItr
== mi2iMap
.end())
637 SlotIndex replaceBaseIndex
= mi2iItr
->second
;
638 IndexListEntry
*miEntry(replaceBaseIndex
.listEntry());
639 assert(miEntry
->getInstr() == &MI
&&
640 "Mismatched instruction in index tables.");
641 miEntry
->setInstr(&NewMI
);
642 mi2iMap
.erase(mi2iItr
);
643 mi2iMap
.insert(std::make_pair(&NewMI
, replaceBaseIndex
));
644 return replaceBaseIndex
;
647 /// Add the given MachineBasicBlock into the maps.
648 void insertMBBInMaps(MachineBasicBlock
*mbb
) {
649 MachineFunction::iterator nextMBB
=
650 std::next(MachineFunction::iterator(mbb
));
652 IndexListEntry
*startEntry
= nullptr;
653 IndexListEntry
*endEntry
= nullptr;
654 IndexList::iterator newItr
;
655 if (nextMBB
== mbb
->getParent()->end()) {
656 startEntry
= &indexList
.back();
657 endEntry
= createEntry(nullptr, 0);
658 newItr
= indexList
.insertAfter(startEntry
->getIterator(), endEntry
);
660 startEntry
= createEntry(nullptr, 0);
661 endEntry
= getMBBStartIdx(&*nextMBB
).listEntry();
662 newItr
= indexList
.insert(endEntry
->getIterator(), startEntry
);
665 SlotIndex
startIdx(startEntry
, SlotIndex::Slot_Block
);
666 SlotIndex
endIdx(endEntry
, SlotIndex::Slot_Block
);
668 MachineFunction::iterator
prevMBB(mbb
);
669 assert(prevMBB
!= mbb
->getParent()->end() &&
670 "Can't insert a new block at the beginning of a function.");
672 MBBRanges
[prevMBB
->getNumber()].second
= startIdx
;
674 assert(unsigned(mbb
->getNumber()) == MBBRanges
.size() &&
675 "Blocks must be added in order");
676 MBBRanges
.push_back(std::make_pair(startIdx
, endIdx
));
677 idx2MBBMap
.push_back(IdxMBBPair(startIdx
, mbb
));
679 renumberIndexes(newItr
);
680 llvm::sort(idx2MBBMap
, Idx2MBBCompare());
683 /// Free the resources that were required to maintain a SlotIndex.
685 /// Once an index is no longer needed (for instance because the instruction
686 /// at that index has been moved), the resources required to maintain the
687 /// index can be relinquished to reduce memory use and improve renumbering
688 /// performance. Any remaining SlotIndex objects that point to the same
689 /// index are left 'dangling' (much the same as a dangling pointer to a
690 /// freed object) and should not be accessed, except to destruct them.
692 /// Like dangling pointers, access to dangling SlotIndexes can cause
693 /// painful-to-track-down bugs, especially if the memory for the index
694 /// previously pointed to has been re-used. To detect dangling SlotIndex
695 /// bugs, build with EXPENSIVE_CHECKS=1. This will cause "erased" indexes to
696 /// be retained in a graveyard instead of being freed. Operations on indexes
697 /// in the graveyard will trigger an assertion.
698 void eraseIndex(SlotIndex index
) {
699 IndexListEntry
*entry
= index
.listEntry();
700 #ifdef EXPENSIVE_CHECKS
701 indexList
.remove(entry
);
702 graveyardList
.push_back(entry
);
705 indexList
.erase(entry
);
710 // Specialize IntervalMapInfo for half-open slot index intervals.
712 struct IntervalMapInfo
<SlotIndex
> : IntervalMapHalfOpenInfo
<SlotIndex
> {
715 } // end namespace llvm
717 #endif // LLVM_CODEGEN_SLOTINDEXES_H