LLVM 18.0.0git
SlotIndexes.h
Go to the documentation of this file.
1//===- llvm/CodeGen/SlotIndexes.h - Slot indexes representation -*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
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
11// be live.
12//
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//===----------------------------------------------------------------------===//
17
18#ifndef LLVM_CODEGEN_SLOTINDEXES_H
19#define LLVM_CODEGEN_SLOTINDEXES_H
20
21#include "llvm/ADT/DenseMap.h"
25#include "llvm/ADT/ilist.h"
32#include <algorithm>
33#include <cassert>
34#include <iterator>
35#include <utility>
36
37namespace llvm {
38
39class raw_ostream;
40
41 /// This class represents an entry in the slot index list held in the
42 /// SlotIndexes pass. It should not be used directly. See the
43 /// SlotIndex & SlotIndexes classes for the public interface to this
44 /// information.
45 class IndexListEntry : public ilist_node<IndexListEntry> {
46 MachineInstr *mi;
47 unsigned index;
48
49 public:
50 IndexListEntry(MachineInstr *mi, unsigned index) : mi(mi), index(index) {}
51
52 MachineInstr* getInstr() const { return mi; }
54 this->mi = mi;
55 }
56
57 unsigned getIndex() const { return index; }
58 void setIndex(unsigned index) {
59 this->index = index;
60 }
61 };
62
63 template <>
65 : public ilist_noalloc_traits<IndexListEntry> {};
66
67 /// SlotIndex - An opaque wrapper around machine indexes.
68 class SlotIndex {
69 friend class SlotIndexes;
70
71 enum Slot {
72 /// Basic block boundary. Used for live ranges entering and leaving a
73 /// block without being live in the layout neighbor. Also used as the
74 /// def slot of PHI-defs.
75 Slot_Block,
76
77 /// Early-clobber register use/def slot. A live range defined at
78 /// Slot_EarlyClobber interferes with normal live ranges killed at
79 /// Slot_Register. Also used as the kill slot for live ranges tied to an
80 /// early-clobber def.
81 Slot_EarlyClobber,
82
83 /// Normal register use/def slot. Normal instructions kill and define
84 /// register live ranges at this slot.
85 Slot_Register,
86
87 /// Dead def kill point. Kill slot for a live range that is defined by
88 /// the same instruction (Slot_Register or Slot_EarlyClobber), but isn't
89 /// used anywhere.
90 Slot_Dead,
91
92 Slot_Count
93 };
94
96
97 IndexListEntry* listEntry() const {
98 assert(isValid() && "Attempt to compare reserved index.");
99 return lie.getPointer();
100 }
101
102 unsigned getIndex() const {
103 return listEntry()->getIndex() | getSlot();
104 }
105
106 /// Returns the slot for this SlotIndex.
107 Slot getSlot() const {
108 return static_cast<Slot>(lie.getInt());
109 }
110
111 public:
112 enum {
113 /// The default distance between instructions as returned by distance().
114 /// This may vary as instructions are inserted and removed.
115 InstrDist = 4 * Slot_Count
116 };
117
118 /// Construct an invalid index.
119 SlotIndex() = default;
120
121 // Creates a SlotIndex from an IndexListEntry and a slot. Generally should
122 // not be used. This method is only public to facilitate writing certain
123 // unit tests.
124 SlotIndex(IndexListEntry *entry, unsigned slot) : lie(entry, slot) {}
125
126 // Construct a new slot index from the given one, and set the slot.
127 SlotIndex(const SlotIndex &li, Slot s) : lie(li.listEntry(), unsigned(s)) {
128 assert(lie.getPointer() != nullptr &&
129 "Attempt to construct index with 0 pointer.");
130 }
131
132 /// Returns true if this is a valid index. Invalid indices do
133 /// not point into an index table, and cannot be compared.
134 bool isValid() const {
135 return lie.getPointer();
136 }
137
138 /// Return true for a valid index.
139 explicit operator bool() const { return isValid(); }
140
141 /// Print this index to the given raw_ostream.
142 void print(raw_ostream &os) const;
143
144 /// Dump this index to stderr.
145 void dump() const;
146
147 /// Compare two SlotIndex objects for equality.
148 bool operator==(SlotIndex other) const {
149 return lie == other.lie;
150 }
151 /// Compare two SlotIndex objects for inequality.
152 bool operator!=(SlotIndex other) const {
153 return lie != other.lie;
154 }
155
156 /// Compare two SlotIndex objects. Return true if the first index
157 /// is strictly lower than the second.
158 bool operator<(SlotIndex other) const {
159 return getIndex() < other.getIndex();
160 }
161 /// Compare two SlotIndex objects. Return true if the first index
162 /// is lower than, or equal to, the second.
163 bool operator<=(SlotIndex other) const {
164 return getIndex() <= other.getIndex();
165 }
166
167 /// Compare two SlotIndex objects. Return true if the first index
168 /// is greater than the second.
169 bool operator>(SlotIndex other) const {
170 return getIndex() > other.getIndex();
171 }
172
173 /// Compare two SlotIndex objects. Return true if the first index
174 /// is greater than, or equal to, the second.
175 bool operator>=(SlotIndex other) const {
176 return getIndex() >= other.getIndex();
177 }
178
179 /// isSameInstr - Return true if A and B refer to the same instruction.
181 return A.lie.getPointer() == B.lie.getPointer();
182 }
183
184 /// isEarlierInstr - Return true if A refers to an instruction earlier than
185 /// B. This is equivalent to A < B && !isSameInstr(A, B).
187 return A.listEntry()->getIndex() < B.listEntry()->getIndex();
188 }
189
190 /// Return true if A refers to the same instruction as B or an earlier one.
191 /// This is equivalent to !isEarlierInstr(B, A).
193 return !isEarlierInstr(B, A);
194 }
195
196 /// Return the distance from this index to the given one.
197 int distance(SlotIndex other) const {
198 return other.getIndex() - getIndex();
199 }
200
201 /// Return the scaled distance from this index to the given one, where all
202 /// slots on the same instruction have zero distance, assuming that the slot
203 /// indices are packed as densely as possible. There are normally gaps
204 /// between instructions, so this assumption often doesn't hold. This
205 /// results in this function often returning a value greater than the actual
206 /// instruction distance.
208 return (other.listEntry()->getIndex() - listEntry()->getIndex())
209 / Slot_Count;
210 }
211
212 /// isBlock - Returns true if this is a block boundary slot.
213 bool isBlock() const { return getSlot() == Slot_Block; }
214
215 /// isEarlyClobber - Returns true if this is an early-clobber slot.
216 bool isEarlyClobber() const { return getSlot() == Slot_EarlyClobber; }
217
218 /// isRegister - Returns true if this is a normal register use/def slot.
219 /// Note that early-clobber slots may also be used for uses and defs.
220 bool isRegister() const { return getSlot() == Slot_Register; }
221
222 /// isDead - Returns true if this is a dead def kill slot.
223 bool isDead() const { return getSlot() == Slot_Dead; }
224
225 /// Returns the base index for associated with this index. The base index
226 /// is the one associated with the Slot_Block slot for the instruction
227 /// pointed to by this index.
229 return SlotIndex(listEntry(), Slot_Block);
230 }
231
232 /// Returns the boundary index for associated with this index. The boundary
233 /// index is the one associated with the Slot_Block slot for the instruction
234 /// pointed to by this index.
236 return SlotIndex(listEntry(), Slot_Dead);
237 }
238
239 /// Returns the register use/def slot in the current instruction for a
240 /// normal or early-clobber def.
241 SlotIndex getRegSlot(bool EC = false) const {
242 return SlotIndex(listEntry(), EC ? Slot_EarlyClobber : Slot_Register);
243 }
244
245 /// Returns the dead def kill slot for the current instruction.
247 return SlotIndex(listEntry(), Slot_Dead);
248 }
249
250 /// Returns the next slot in the index list. This could be either the
251 /// next slot for the instruction pointed to by this index or, if this
252 /// index is a STORE, the first slot for the next instruction.
253 /// WARNING: This method is considerably more expensive than the methods
254 /// that return specific slots (getUseIndex(), etc). If you can - please
255 /// use one of those methods.
257 Slot s = getSlot();
258 if (s == Slot_Dead) {
259 return SlotIndex(&*++listEntry()->getIterator(), Slot_Block);
260 }
261 return SlotIndex(listEntry(), s + 1);
262 }
263
264 /// Returns the next index. This is the index corresponding to the this
265 /// index's slot, but for the next instruction.
267 return SlotIndex(&*++listEntry()->getIterator(), getSlot());
268 }
269
270 /// Returns the previous slot in the index list. This could be either the
271 /// previous slot for the instruction pointed to by this index or, if this
272 /// index is a Slot_Block, the last slot for the previous instruction.
273 /// WARNING: This method is considerably more expensive than the methods
274 /// that return specific slots (getUseIndex(), etc). If you can - please
275 /// use one of those methods.
277 Slot s = getSlot();
278 if (s == Slot_Block) {
279 return SlotIndex(&*--listEntry()->getIterator(), Slot_Dead);
280 }
281 return SlotIndex(listEntry(), s - 1);
282 }
283
284 /// Returns the previous index. This is the index corresponding to this
285 /// index's slot, but for the previous instruction.
287 return SlotIndex(&*--listEntry()->getIterator(), getSlot());
288 }
289 };
290
292 li.print(os);
293 return os;
294 }
295
296 using IdxMBBPair = std::pair<SlotIndex, MachineBasicBlock *>;
297
298 /// SlotIndexes pass.
299 ///
300 /// This pass assigns indexes to each instruction.
302 private:
303 // IndexListEntry allocator.
304 BumpPtrAllocator ileAllocator;
305
307 IndexList indexList;
308
309 MachineFunction *mf = nullptr;
310
312 Mi2IndexMap mi2iMap;
313
314 /// MBBRanges - Map MBB number to (start, stop) indexes.
316
317 /// Idx2MBBMap - Sorted list of pairs of index of first instruction
318 /// and MBB id.
320
321 IndexListEntry* createEntry(MachineInstr *mi, unsigned index) {
322 IndexListEntry *entry =
323 static_cast<IndexListEntry *>(ileAllocator.Allocate(
324 sizeof(IndexListEntry), alignof(IndexListEntry)));
325
326 new (entry) IndexListEntry(mi, index);
327
328 return entry;
329 }
330
331 /// Renumber locally after inserting curItr.
332 void renumberIndexes(IndexList::iterator curItr);
333
334 public:
335 static char ID;
336
337 SlotIndexes();
338
339 ~SlotIndexes() override;
340
341 void getAnalysisUsage(AnalysisUsage &au) const override;
342 void releaseMemory() override;
343
344 bool runOnMachineFunction(MachineFunction &fn) override;
345
346 /// Dump the indexes.
347 void dump() const;
348
349 /// Repair indexes after adding and removing instructions.
353
354 /// Returns the zero index for this analysis.
356 assert(indexList.front().getIndex() == 0 && "First index is not 0?");
357 return SlotIndex(&indexList.front(), 0);
358 }
359
360 /// Returns the base index of the last slot in this analysis.
362 return SlotIndex(&indexList.back(), 0);
363 }
364
365 /// Returns true if the given machine instr is mapped to an index,
366 /// otherwise returns false.
367 bool hasIndex(const MachineInstr &instr) const {
368 return mi2iMap.count(&instr);
369 }
370
371 /// Returns the base index for the given instruction.
373 bool IgnoreBundle = false) const {
374 // Instructions inside a bundle have the same number as the bundle itself.
375 auto BundleStart = getBundleStart(MI.getIterator());
376 auto BundleEnd = getBundleEnd(MI.getIterator());
377 // Use the first non-debug instruction in the bundle to get SlotIndex.
378 const MachineInstr &BundleNonDebug =
379 IgnoreBundle ? MI
380 : *skipDebugInstructionsForward(BundleStart, BundleEnd);
381 assert(!BundleNonDebug.isDebugInstr() &&
382 "Could not use a debug instruction to query mi2iMap.");
383 Mi2IndexMap::const_iterator itr = mi2iMap.find(&BundleNonDebug);
384 assert(itr != mi2iMap.end() && "Instruction not found in maps.");
385 return itr->second;
386 }
387
388 /// Returns the instruction for the given index, or null if the given
389 /// index has no instruction associated with it.
391 return index.isValid() ? index.listEntry()->getInstr() : nullptr;
392 }
393
394 /// Returns the next non-null index, if one exists.
395 /// Otherwise returns getLastIndex().
397 IndexList::iterator I = Index.listEntry()->getIterator();
398 IndexList::iterator E = indexList.end();
399 while (++I != E)
400 if (I->getInstr())
401 return SlotIndex(&*I, Index.getSlot());
402 // We reached the end of the function.
403 return getLastIndex();
404 }
405
406 /// getIndexBefore - Returns the index of the last indexed instruction
407 /// before MI, or the start index of its basic block.
408 /// MI is not required to have an index.
410 const MachineBasicBlock *MBB = MI.getParent();
411 assert(MBB && "MI must be inserted in a basic block");
413 while (true) {
414 if (I == B)
415 return getMBBStartIdx(MBB);
416 --I;
417 Mi2IndexMap::const_iterator MapItr = mi2iMap.find(&*I);
418 if (MapItr != mi2iMap.end())
419 return MapItr->second;
420 }
421 }
422
423 /// getIndexAfter - Returns the index of the first indexed instruction
424 /// after MI, or the end index of its basic block.
425 /// MI is not required to have an index.
427 const MachineBasicBlock *MBB = MI.getParent();
428 assert(MBB && "MI must be inserted in a basic block");
430 while (true) {
431 ++I;
432 if (I == E)
433 return getMBBEndIdx(MBB);
434 Mi2IndexMap::const_iterator MapItr = mi2iMap.find(&*I);
435 if (MapItr != mi2iMap.end())
436 return MapItr->second;
437 }
438 }
439
440 /// Return the (start,end) range of the given basic block number.
441 const std::pair<SlotIndex, SlotIndex> &
442 getMBBRange(unsigned Num) const {
443 return MBBRanges[Num];
444 }
445
446 /// Return the (start,end) range of the given basic block.
447 const std::pair<SlotIndex, SlotIndex> &
449 return getMBBRange(MBB->getNumber());
450 }
451
452 /// Returns the first index in the given basic block number.
453 SlotIndex getMBBStartIdx(unsigned Num) const {
454 return getMBBRange(Num).first;
455 }
456
457 /// Returns the first index in the given basic block.
459 return getMBBRange(mbb).first;
460 }
461
462 /// Returns the last index in the given basic block number.
463 SlotIndex getMBBEndIdx(unsigned Num) const {
464 return getMBBRange(Num).second;
465 }
466
467 /// Returns the last index in the given basic block.
469 return getMBBRange(mbb).second;
470 }
471
472 /// Iterator over the idx2MBBMap (sorted pairs of slot index of basic block
473 /// begin and basic block)
475
476 /// Move iterator to the next IdxMBBPair where the SlotIndex is greater or
477 /// equal to \p To.
479 return std::partition_point(
480 I, idx2MBBMap.end(),
481 [=](const IdxMBBPair &IM) { return IM.first < To; });
482 }
483
484 /// Get an iterator pointing to the IdxMBBPair with the biggest SlotIndex
485 /// that is greater or equal to \p Idx.
487 return advanceMBBIndex(idx2MBBMap.begin(), Idx);
488 }
489
490 /// Returns an iterator for the begin of the idx2MBBMap.
492 return idx2MBBMap.begin();
493 }
494
495 /// Return an iterator for the end of the idx2MBBMap.
497 return idx2MBBMap.end();
498 }
499
500 /// Returns the basic block which the given index falls in.
503 return MI->getParent();
504
506 // Take the pair containing the index
508 ((I != MBBIndexEnd() && I->first > index) ||
509 (I == MBBIndexEnd() && !idx2MBBMap.empty())) ? std::prev(I) : I;
510
511 assert(J != MBBIndexEnd() && J->first <= index &&
512 index < getMBBEndIdx(J->second) &&
513 "index does not correspond to an MBB");
514 return J->second;
515 }
516
517 /// Insert the given machine instruction into the mapping. Returns the
518 /// assigned index.
519 /// If Late is set and there are null indexes between mi's neighboring
520 /// instructions, create the new index after the null indexes instead of
521 /// before them.
523 assert(!MI.isInsideBundle() &&
524 "Instructions inside bundles should use bundle start's slot.");
525 assert(!mi2iMap.contains(&MI) && "Instr already indexed.");
526 // Numbering debug instructions could cause code generation to be
527 // affected by debug information.
528 assert(!MI.isDebugInstr() && "Cannot number debug instructions.");
529
530 assert(MI.getParent() != nullptr && "Instr must be added to function.");
531
532 // Get the entries where MI should be inserted.
533 IndexList::iterator prevItr, nextItr;
534 if (Late) {
535 // Insert MI's index immediately before the following instruction.
536 nextItr = getIndexAfter(MI).listEntry()->getIterator();
537 prevItr = std::prev(nextItr);
538 } else {
539 // Insert MI's index immediately after the preceding instruction.
540 prevItr = getIndexBefore(MI).listEntry()->getIterator();
541 nextItr = std::next(prevItr);
542 }
543
544 // Get a number for the new instr, or 0 if there's no room currently.
545 // In the latter case we'll force a renumber later.
546 unsigned dist = ((nextItr->getIndex() - prevItr->getIndex())/2) & ~3u;
547 unsigned newNumber = prevItr->getIndex() + dist;
548
549 // Insert a new list entry for MI.
550 IndexList::iterator newItr =
551 indexList.insert(nextItr, createEntry(&MI, newNumber));
552
553 // Renumber locally if we need to.
554 if (dist == 0)
555 renumberIndexes(newItr);
556
557 SlotIndex newIndex(&*newItr, SlotIndex::Slot_Block);
558 mi2iMap.insert(std::make_pair(&MI, newIndex));
559 return newIndex;
560 }
561
562 /// Removes machine instruction (bundle) \p MI from the mapping.
563 /// This should be called before MachineInstr::eraseFromParent() is used to
564 /// remove a whole bundle or an unbundled instruction.
565 /// If \p AllowBundled is set then this can be used on a bundled
566 /// instruction; however, this exists to support handleMoveIntoBundle,
567 /// and in general removeSingleMachineInstrFromMaps should be used instead.
569 bool AllowBundled = false);
570
571 /// Removes a single machine instruction \p MI from the mapping.
572 /// This should be called before MachineInstr::eraseFromBundle() is used to
573 /// remove a single instruction (out of a bundle).
575
576 /// ReplaceMachineInstrInMaps - Replacing a machine instr with a new one in
577 /// maps used by register allocator. \returns the index where the new
578 /// instruction was inserted.
580 Mi2IndexMap::iterator mi2iItr = mi2iMap.find(&MI);
581 if (mi2iItr == mi2iMap.end())
582 return SlotIndex();
583 SlotIndex replaceBaseIndex = mi2iItr->second;
584 IndexListEntry *miEntry(replaceBaseIndex.listEntry());
585 assert(miEntry->getInstr() == &MI &&
586 "Mismatched instruction in index tables.");
587 miEntry->setInstr(&NewMI);
588 mi2iMap.erase(mi2iItr);
589 mi2iMap.insert(std::make_pair(&NewMI, replaceBaseIndex));
590 return replaceBaseIndex;
591 }
592
593 /// Add the given MachineBasicBlock into the maps.
594 /// If it contains any instructions then they must already be in the maps.
595 /// This is used after a block has been split by moving some suffix of its
596 /// instructions into a newly created block.
598 assert(mbb != &mbb->getParent()->front() &&
599 "Can't insert a new block at the beginning of a function.");
600 auto prevMBB = std::prev(MachineFunction::iterator(mbb));
601
602 // Create a new entry to be used for the start of mbb and the end of
603 // prevMBB.
604 IndexListEntry *startEntry = createEntry(nullptr, 0);
605 IndexListEntry *endEntry = getMBBEndIdx(&*prevMBB).listEntry();
606 IndexListEntry *insEntry =
607 mbb->empty() ? endEntry
608 : getInstructionIndex(mbb->front()).listEntry();
609 IndexList::iterator newItr =
610 indexList.insert(insEntry->getIterator(), startEntry);
611
612 SlotIndex startIdx(startEntry, SlotIndex::Slot_Block);
613 SlotIndex endIdx(endEntry, SlotIndex::Slot_Block);
614
615 MBBRanges[prevMBB->getNumber()].second = startIdx;
616
617 assert(unsigned(mbb->getNumber()) == MBBRanges.size() &&
618 "Blocks must be added in order");
619 MBBRanges.push_back(std::make_pair(startIdx, endIdx));
620 idx2MBBMap.push_back(IdxMBBPair(startIdx, mbb));
621
622 renumberIndexes(newItr);
623 llvm::sort(idx2MBBMap, less_first());
624 }
625
626 /// Renumber all indexes using the default instruction distance.
627 void packIndexes();
628 };
629
630 // Specialize IntervalMapInfo for half-open slot index intervals.
631 template <>
633 };
634
635} // end namespace llvm
636
637#endif // LLVM_CODEGEN_SLOTINDEXES_H
MachineBasicBlock & MBB
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
bool End
Definition: ELF_riscv.cpp:469
IRTranslator LLVM IR MI
This file implements a coalescing interval map for small objects.
#define I(x, y, z)
Definition: MD5.cpp:58
This file defines the PointerIntPair class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
Represent the analysis usage information of a pass.
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:148
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
bool erase(const KeyT &Val)
Definition: DenseMap.h:329
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:151
iterator end()
Definition: DenseMap.h:84
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
Definition: DenseMap.h:145
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:220
This class represents an entry in the slot index list held in the SlotIndexes pass.
Definition: SlotIndexes.h:45
IndexListEntry(MachineInstr *mi, unsigned index)
Definition: SlotIndexes.h:50
void setInstr(MachineInstr *mi)
Definition: SlotIndexes.h:53
MachineInstr * getInstr() const
Definition: SlotIndexes.h:52
void setIndex(unsigned index)
Definition: SlotIndexes.h:58
unsigned getIndex() const
Definition: SlotIndexes.h:57
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const MachineBasicBlock & front() const
Representation of each machine instruction.
Definition: MachineInstr.h:68
bool isDebugInstr() const
PointerIntPair - This class implements a pair of a pointer and small integer.
IntType getInt() const
PointerTy getPointer() const
SlotIndex - An opaque wrapper around machine indexes.
Definition: SlotIndexes.h:68
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
Definition: SlotIndexes.h:180
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
Definition: SlotIndexes.h:213
SlotIndex getNextIndex() const
Returns the next index.
Definition: SlotIndexes.h:266
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
Definition: SlotIndexes.h:246
static bool isEarlierInstr(SlotIndex A, SlotIndex B)
isEarlierInstr - Return true if A refers to an instruction earlier than B.
Definition: SlotIndexes.h:186
SlotIndex()=default
Construct an invalid index.
bool isEarlyClobber() const
isEarlyClobber - Returns true if this is an early-clobber slot.
Definition: SlotIndexes.h:216
bool operator>=(SlotIndex other) const
Compare two SlotIndex objects.
Definition: SlotIndexes.h:175
int distance(SlotIndex other) const
Return the distance from this index to the given one.
Definition: SlotIndexes.h:197
bool operator>(SlotIndex other) const
Compare two SlotIndex objects.
Definition: SlotIndexes.h:169
@ InstrDist
The default distance between instructions as returned by distance().
Definition: SlotIndexes.h:115
bool isValid() const
Returns true if this is a valid index.
Definition: SlotIndexes.h:134
bool isRegister() const
isRegister - Returns true if this is a normal register use/def slot.
Definition: SlotIndexes.h:220
bool operator!=(SlotIndex other) const
Compare two SlotIndex objects for inequality.
Definition: SlotIndexes.h:152
static bool isEarlierEqualInstr(SlotIndex A, SlotIndex B)
Return true if A refers to the same instruction as B or an earlier one.
Definition: SlotIndexes.h:192
SlotIndex getBoundaryIndex() const
Returns the boundary index for associated with this index.
Definition: SlotIndexes.h:235
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
Definition: SlotIndexes.h:228
SlotIndex(IndexListEntry *entry, unsigned slot)
Definition: SlotIndexes.h:124
void dump() const
Dump this index to stderr.
SlotIndex(const SlotIndex &li, Slot s)
Definition: SlotIndexes.h:127
SlotIndex getPrevIndex() const
Returns the previous index.
Definition: SlotIndexes.h:286
void print(raw_ostream &os) const
Print this index to the given raw_ostream.
SlotIndex getNextSlot() const
Returns the next slot in the index list.
Definition: SlotIndexes.h:256
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
Definition: SlotIndexes.h:276
bool operator<(SlotIndex other) const
Compare two SlotIndex objects.
Definition: SlotIndexes.h:158
bool operator<=(SlotIndex other) const
Compare two SlotIndex objects.
Definition: SlotIndexes.h:163
int getApproxInstrDistance(SlotIndex other) const
Return the scaled distance from this index to the given one, where all slots on the same instruction ...
Definition: SlotIndexes.h:207
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
Definition: SlotIndexes.h:241
bool operator==(SlotIndex other) const
Compare two SlotIndex objects for equality.
Definition: SlotIndexes.h:148
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
Definition: SlotIndexes.h:223
SlotIndexes pass.
Definition: SlotIndexes.h:301
SlotIndex getLastIndex()
Returns the base index of the last slot in this analysis.
Definition: SlotIndexes.h:361
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
Definition: SlotIndexes.h:522
MBBIndexIterator findMBBIndex(SlotIndex Idx) const
Get an iterator pointing to the IdxMBBPair with the biggest SlotIndex that is greater or equal to Idx...
Definition: SlotIndexes.h:486
void removeMachineInstrFromMaps(MachineInstr &MI, bool AllowBundled=false)
Removes machine instruction (bundle) MI from the mapping.
void getAnalysisUsage(AnalysisUsage &au) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: SlotIndexes.cpp:37
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
Definition: SlotIndexes.h:501
void dump() const
Dump the indexes.
void repairIndexesInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End)
Repair indexes after adding and removing instructions.
bool runOnMachineFunction(MachineFunction &fn) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition: SlotIndexes.cpp:50
void insertMBBInMaps(MachineBasicBlock *mbb)
Add the given MachineBasicBlock into the maps.
Definition: SlotIndexes.h:597
MBBIndexIterator advanceMBBIndex(MBBIndexIterator I, SlotIndex To) const
Move iterator to the next IdxMBBPair where the SlotIndex is greater or equal to To.
Definition: SlotIndexes.h:478
const std::pair< SlotIndex, SlotIndex > & getMBBRange(unsigned Num) const
Return the (start,end) range of the given basic block number.
Definition: SlotIndexes.h:442
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
Definition: SlotIndexes.h:463
void removeSingleMachineInstrFromMaps(MachineInstr &MI)
Removes a single machine instruction MI from the mapping.
MBBIndexIterator MBBIndexBegin() const
Returns an iterator for the begin of the idx2MBBMap.
Definition: SlotIndexes.h:491
SlotIndex getNextNonNullIndex(SlotIndex Index)
Returns the next non-null index, if one exists.
Definition: SlotIndexes.h:396
MBBIndexIterator MBBIndexEnd() const
Return an iterator for the end of the idx2MBBMap.
Definition: SlotIndexes.h:496
SmallVectorImpl< IdxMBBPair >::const_iterator MBBIndexIterator
Iterator over the idx2MBBMap (sorted pairs of slot index of basic block begin and basic block)
Definition: SlotIndexes.h:474
static char ID
Definition: SlotIndexes.h:335
SlotIndex getInstructionIndex(const MachineInstr &MI, bool IgnoreBundle=false) const
Returns the base index for the given instruction.
Definition: SlotIndexes.h:372
SlotIndex getIndexAfter(const MachineInstr &MI) const
getIndexAfter - Returns the index of the first indexed instruction after MI, or the end index of its ...
Definition: SlotIndexes.h:426
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
Definition: SlotIndexes.h:453
~SlotIndexes() override
Definition: SlotIndexes.cpp:27
void packIndexes()
Renumber all indexes using the default instruction distance.
bool hasIndex(const MachineInstr &instr) const
Returns true if the given machine instr is mapped to an index, otherwise returns false.
Definition: SlotIndexes.h:367
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Definition: SlotIndexes.cpp:42
SlotIndex getIndexBefore(const MachineInstr &MI) const
getIndexBefore - Returns the index of the last indexed instruction before MI, or the start index of i...
Definition: SlotIndexes.h:409
SlotIndex replaceMachineInstrInMaps(MachineInstr &MI, MachineInstr &NewMI)
ReplaceMachineInstrInMaps - Replacing a machine instr with a new one in maps used by register allocat...
Definition: SlotIndexes.h:579
SlotIndex getZeroIndex()
Returns the zero index for this analysis.
Definition: SlotIndexes.h:355
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Returns the last index in the given basic block.
Definition: SlotIndexes.h:468
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Returns the first index in the given basic block.
Definition: SlotIndexes.h:458
const std::pair< SlotIndex, SlotIndex > & getMBBRange(const MachineBasicBlock *MBB) const
Return the (start,end) range of the given basic block.
Definition: SlotIndexes.h:448
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction for the given index, or null if the given index has no instruction associated...
Definition: SlotIndexes.h:390
bool empty() const
Definition: SmallVector.h:94
size_t size() const
Definition: SmallVector.h:91
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:582
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
self_iterator getIterator()
Definition: ilist_node.h:82
iterator insert(iterator where, pointer New)
Definition: ilist.h:165
An intrusive list with ownership and callbacks specified/controlled by ilist_traits,...
Definition: ilist.h:328
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This file defines classes to implement an intrusive doubly linked list class (i.e.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MachineBasicBlock::instr_iterator getBundleStart(MachineBasicBlock::instr_iterator I)
Returns an iterator to the first instruction in the bundle containing I.
std::pair< SlotIndex, MachineBasicBlock * > IdxMBBPair
Definition: SlotIndexes.h:296
IterT skipDebugInstructionsForward(IterT It, IterT End, bool SkipPseudoOp=true)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator.
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1652
MachineBasicBlock::instr_iterator getBundleEnd(MachineBasicBlock::instr_iterator I)
Returns an iterator pointing beyond the bundle containing I.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:292
Use delete by default for iplist and ilist.
Definition: ilist.h:41
Custom traits to do nothing on deletion.
Definition: ilist.h:57
Function object to check whether the first component of a container supported by std::get (like std::...
Definition: STLExtras.h:1455