LLVM 19.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(isValid() && "Attempt to construct index with 0 pointer.");
129 }
130
131 /// Returns true if this is a valid index. Invalid indices do
132 /// not point into an index table, and cannot be compared.
133 bool isValid() const {
134 return lie.getPointer();
135 }
136
137 /// Return true for a valid index.
138 explicit operator bool() const { return isValid(); }
139
140 /// Print this index to the given raw_ostream.
141 void print(raw_ostream &os) const;
142
143 /// Dump this index to stderr.
144 void dump() const;
145
146 /// Compare two SlotIndex objects for equality.
147 bool operator==(SlotIndex other) const {
148 return lie == other.lie;
149 }
150 /// Compare two SlotIndex objects for inequality.
151 bool operator!=(SlotIndex other) const {
152 return lie != other.lie;
153 }
154
155 /// Compare two SlotIndex objects. Return true if the first index
156 /// is strictly lower than the second.
157 bool operator<(SlotIndex other) const {
158 return getIndex() < other.getIndex();
159 }
160 /// Compare two SlotIndex objects. Return true if the first index
161 /// is lower than, or equal to, the second.
162 bool operator<=(SlotIndex other) const {
163 return getIndex() <= other.getIndex();
164 }
165
166 /// Compare two SlotIndex objects. Return true if the first index
167 /// is greater than the second.
168 bool operator>(SlotIndex other) const {
169 return getIndex() > other.getIndex();
170 }
171
172 /// Compare two SlotIndex objects. Return true if the first index
173 /// is greater than, or equal to, the second.
174 bool operator>=(SlotIndex other) const {
175 return getIndex() >= other.getIndex();
176 }
177
178 /// isSameInstr - Return true if A and B refer to the same instruction.
180 return A.listEntry() == B.listEntry();
181 }
182
183 /// isEarlierInstr - Return true if A refers to an instruction earlier than
184 /// B. This is equivalent to A < B && !isSameInstr(A, B).
186 return A.listEntry()->getIndex() < B.listEntry()->getIndex();
187 }
188
189 /// Return true if A refers to the same instruction as B or an earlier one.
190 /// This is equivalent to !isEarlierInstr(B, A).
192 return !isEarlierInstr(B, A);
193 }
194
195 /// Return the distance from this index to the given one.
196 int distance(SlotIndex other) const {
197 return other.getIndex() - getIndex();
198 }
199
200 /// Return the scaled distance from this index to the given one, where all
201 /// slots on the same instruction have zero distance, assuming that the slot
202 /// indices are packed as densely as possible. There are normally gaps
203 /// between instructions, so this assumption often doesn't hold. This
204 /// results in this function often returning a value greater than the actual
205 /// instruction distance.
207 return (other.listEntry()->getIndex() - listEntry()->getIndex())
208 / Slot_Count;
209 }
210
211 /// isBlock - Returns true if this is a block boundary slot.
212 bool isBlock() const { return getSlot() == Slot_Block; }
213
214 /// isEarlyClobber - Returns true if this is an early-clobber slot.
215 bool isEarlyClobber() const { return getSlot() == Slot_EarlyClobber; }
216
217 /// isRegister - Returns true if this is a normal register use/def slot.
218 /// Note that early-clobber slots may also be used for uses and defs.
219 bool isRegister() const { return getSlot() == Slot_Register; }
220
221 /// isDead - Returns true if this is a dead def kill slot.
222 bool isDead() const { return getSlot() == Slot_Dead; }
223
224 /// Returns the base index for associated with this index. The base index
225 /// is the one associated with the Slot_Block slot for the instruction
226 /// pointed to by this index.
228 return SlotIndex(listEntry(), Slot_Block);
229 }
230
231 /// Returns the boundary index for associated with this index. The boundary
232 /// index is the one associated with the Slot_Block slot for the instruction
233 /// pointed to by this index.
235 return SlotIndex(listEntry(), Slot_Dead);
236 }
237
238 /// Returns the register use/def slot in the current instruction for a
239 /// normal or early-clobber def.
240 SlotIndex getRegSlot(bool EC = false) const {
241 return SlotIndex(listEntry(), EC ? Slot_EarlyClobber : Slot_Register);
242 }
243
244 /// Returns the dead def kill slot for the current instruction.
246 return SlotIndex(listEntry(), Slot_Dead);
247 }
248
249 /// Returns the next slot in the index list. This could be either the
250 /// next slot for the instruction pointed to by this index or, if this
251 /// index is a STORE, the first slot for the next instruction.
252 /// WARNING: This method is considerably more expensive than the methods
253 /// that return specific slots (getUseIndex(), etc). If you can - please
254 /// use one of those methods.
256 Slot s = getSlot();
257 if (s == Slot_Dead) {
258 return SlotIndex(&*++listEntry()->getIterator(), Slot_Block);
259 }
260 return SlotIndex(listEntry(), s + 1);
261 }
262
263 /// Returns the next index. This is the index corresponding to the this
264 /// index's slot, but for the next instruction.
266 return SlotIndex(&*++listEntry()->getIterator(), getSlot());
267 }
268
269 /// Returns the previous slot in the index list. This could be either the
270 /// previous slot for the instruction pointed to by this index or, if this
271 /// index is a Slot_Block, the last slot for the previous instruction.
272 /// WARNING: This method is considerably more expensive than the methods
273 /// that return specific slots (getUseIndex(), etc). If you can - please
274 /// use one of those methods.
276 Slot s = getSlot();
277 if (s == Slot_Block) {
278 return SlotIndex(&*--listEntry()->getIterator(), Slot_Dead);
279 }
280 return SlotIndex(listEntry(), s - 1);
281 }
282
283 /// Returns the previous index. This is the index corresponding to this
284 /// index's slot, but for the previous instruction.
286 return SlotIndex(&*--listEntry()->getIterator(), getSlot());
287 }
288 };
289
291 li.print(os);
292 return os;
293 }
294
295 using IdxMBBPair = std::pair<SlotIndex, MachineBasicBlock *>;
296
297 /// SlotIndexes pass.
298 ///
299 /// This pass assigns indexes to each instruction.
301 private:
302 // IndexListEntry allocator.
303 BumpPtrAllocator ileAllocator;
304
306 IndexList indexList;
307
308 MachineFunction *mf = nullptr;
309
311 Mi2IndexMap mi2iMap;
312
313 /// MBBRanges - Map MBB number to (start, stop) indexes.
315
316 /// Idx2MBBMap - Sorted list of pairs of index of first instruction
317 /// and MBB id.
319
320 IndexListEntry* createEntry(MachineInstr *mi, unsigned index) {
321 IndexListEntry *entry =
322 static_cast<IndexListEntry *>(ileAllocator.Allocate(
323 sizeof(IndexListEntry), alignof(IndexListEntry)));
324
325 new (entry) IndexListEntry(mi, index);
326
327 return entry;
328 }
329
330 /// Renumber locally after inserting curItr.
331 void renumberIndexes(IndexList::iterator curItr);
332
333 public:
334 static char ID;
335
336 SlotIndexes();
337
338 ~SlotIndexes() override;
339
340 void getAnalysisUsage(AnalysisUsage &au) const override;
341 void releaseMemory() override;
342
343 bool runOnMachineFunction(MachineFunction &fn) override;
344
345 /// Dump the indexes.
346 void dump() const;
347
348 /// Repair indexes after adding and removing instructions.
352
353 /// Returns the zero index for this analysis.
355 assert(indexList.front().getIndex() == 0 && "First index is not 0?");
356 return SlotIndex(&indexList.front(), 0);
357 }
358
359 /// Returns the base index of the last slot in this analysis.
361 return SlotIndex(&indexList.back(), 0);
362 }
363
364 /// Returns true if the given machine instr is mapped to an index,
365 /// otherwise returns false.
366 bool hasIndex(const MachineInstr &instr) const {
367 return mi2iMap.count(&instr);
368 }
369
370 /// Returns the base index for the given instruction.
372 bool IgnoreBundle = false) const {
373 // Instructions inside a bundle have the same number as the bundle itself.
374 auto BundleStart = getBundleStart(MI.getIterator());
375 auto BundleEnd = getBundleEnd(MI.getIterator());
376 // Use the first non-debug instruction in the bundle to get SlotIndex.
377 const MachineInstr &BundleNonDebug =
378 IgnoreBundle ? MI
379 : *skipDebugInstructionsForward(BundleStart, BundleEnd);
380 assert(!BundleNonDebug.isDebugInstr() &&
381 "Could not use a debug instruction to query mi2iMap.");
382 Mi2IndexMap::const_iterator itr = mi2iMap.find(&BundleNonDebug);
383 assert(itr != mi2iMap.end() && "Instruction not found in maps.");
384 return itr->second;
385 }
386
387 /// Returns the instruction for the given index, or null if the given
388 /// index has no instruction associated with it.
390 return index.listEntry()->getInstr();
391 }
392
393 /// Returns the next non-null index, if one exists.
394 /// Otherwise returns getLastIndex().
396 IndexList::iterator I = Index.listEntry()->getIterator();
397 IndexList::iterator E = indexList.end();
398 while (++I != E)
399 if (I->getInstr())
400 return SlotIndex(&*I, Index.getSlot());
401 // We reached the end of the function.
402 return getLastIndex();
403 }
404
405 /// getIndexBefore - Returns the index of the last indexed instruction
406 /// before MI, or the start index of its basic block.
407 /// MI is not required to have an index.
409 const MachineBasicBlock *MBB = MI.getParent();
410 assert(MBB && "MI must be inserted in a basic block");
412 while (true) {
413 if (I == B)
414 return getMBBStartIdx(MBB);
415 --I;
416 Mi2IndexMap::const_iterator MapItr = mi2iMap.find(&*I);
417 if (MapItr != mi2iMap.end())
418 return MapItr->second;
419 }
420 }
421
422 /// getIndexAfter - Returns the index of the first indexed instruction
423 /// after MI, or the end index of its basic block.
424 /// MI is not required to have an index.
426 const MachineBasicBlock *MBB = MI.getParent();
427 assert(MBB && "MI must be inserted in a basic block");
429 while (true) {
430 ++I;
431 if (I == E)
432 return getMBBEndIdx(MBB);
433 Mi2IndexMap::const_iterator MapItr = mi2iMap.find(&*I);
434 if (MapItr != mi2iMap.end())
435 return MapItr->second;
436 }
437 }
438
439 /// Return the (start,end) range of the given basic block number.
440 const std::pair<SlotIndex, SlotIndex> &
441 getMBBRange(unsigned Num) const {
442 return MBBRanges[Num];
443 }
444
445 /// Return the (start,end) range of the given basic block.
446 const std::pair<SlotIndex, SlotIndex> &
448 return getMBBRange(MBB->getNumber());
449 }
450
451 /// Returns the first index in the given basic block number.
452 SlotIndex getMBBStartIdx(unsigned Num) const {
453 return getMBBRange(Num).first;
454 }
455
456 /// Returns the first index in the given basic block.
458 return getMBBRange(mbb).first;
459 }
460
461 /// Returns the last index in the given basic block number.
462 SlotIndex getMBBEndIdx(unsigned Num) const {
463 return getMBBRange(Num).second;
464 }
465
466 /// Returns the last index in the given basic block.
468 return getMBBRange(mbb).second;
469 }
470
471 /// Iterator over the idx2MBBMap (sorted pairs of slot index of basic block
472 /// begin and basic block)
474
475 /// Get an iterator pointing to the first IdxMBBPair with SlotIndex greater
476 /// than or equal to \p Idx. If \p Start is provided, only search the range
477 /// from \p Start to the end of the function.
479 SlotIndex Idx) const {
480 return std::lower_bound(
481 Start, MBBIndexEnd(), Idx,
482 [](const IdxMBBPair &IM, SlotIndex Idx) { return IM.first < Idx; });
483 }
486 }
487
488 /// Get an iterator pointing to the first IdxMBBPair with SlotIndex greater
489 /// than \p Idx.
491 return std::upper_bound(
493 [](SlotIndex Idx, const IdxMBBPair &IM) { return Idx < IM.first; });
494 }
495
496 /// Returns an iterator for the begin of the idx2MBBMap.
498 return idx2MBBMap.begin();
499 }
500
501 /// Return an iterator for the end of the idx2MBBMap.
503 return idx2MBBMap.end();
504 }
505
506 /// Returns the basic block which the given index falls in.
509 return MI->getParent();
510
511 MBBIndexIterator I = std::prev(getMBBUpperBound(index));
512 assert(I != MBBIndexEnd() && I->first <= index &&
513 index < getMBBEndIdx(I->second) &&
514 "index does not correspond to an MBB");
515 return I->second;
516 }
517
518 /// Insert the given machine instruction into the mapping. Returns the
519 /// assigned index.
520 /// If Late is set and there are null indexes between mi's neighboring
521 /// instructions, create the new index after the null indexes instead of
522 /// before them.
524 assert(!MI.isInsideBundle() &&
525 "Instructions inside bundles should use bundle start's slot.");
526 assert(!mi2iMap.contains(&MI) && "Instr already indexed.");
527 // Numbering debug instructions could cause code generation to be
528 // affected by debug information.
529 assert(!MI.isDebugInstr() && "Cannot number debug instructions.");
530
531 assert(MI.getParent() != nullptr && "Instr must be added to function.");
532
533 // Get the entries where MI should be inserted.
534 IndexList::iterator prevItr, nextItr;
535 if (Late) {
536 // Insert MI's index immediately before the following instruction.
537 nextItr = getIndexAfter(MI).listEntry()->getIterator();
538 prevItr = std::prev(nextItr);
539 } else {
540 // Insert MI's index immediately after the preceding instruction.
541 prevItr = getIndexBefore(MI).listEntry()->getIterator();
542 nextItr = std::next(prevItr);
543 }
544
545 // Get a number for the new instr, or 0 if there's no room currently.
546 // In the latter case we'll force a renumber later.
547 unsigned dist = ((nextItr->getIndex() - prevItr->getIndex())/2) & ~3u;
548 unsigned newNumber = prevItr->getIndex() + dist;
549
550 // Insert a new list entry for MI.
551 IndexList::iterator newItr =
552 indexList.insert(nextItr, createEntry(&MI, newNumber));
553
554 // Renumber locally if we need to.
555 if (dist == 0)
556 renumberIndexes(newItr);
557
558 SlotIndex newIndex(&*newItr, SlotIndex::Slot_Block);
559 mi2iMap.insert(std::make_pair(&MI, newIndex));
560 return newIndex;
561 }
562
563 /// Removes machine instruction (bundle) \p MI from the mapping.
564 /// This should be called before MachineInstr::eraseFromParent() is used to
565 /// remove a whole bundle or an unbundled instruction.
566 /// If \p AllowBundled is set then this can be used on a bundled
567 /// instruction; however, this exists to support handleMoveIntoBundle,
568 /// and in general removeSingleMachineInstrFromMaps should be used instead.
570 bool AllowBundled = false);
571
572 /// Removes a single machine instruction \p MI from the mapping.
573 /// This should be called before MachineInstr::eraseFromBundle() is used to
574 /// remove a single instruction (out of a bundle).
576
577 /// ReplaceMachineInstrInMaps - Replacing a machine instr with a new one in
578 /// maps used by register allocator. \returns the index where the new
579 /// instruction was inserted.
581 Mi2IndexMap::iterator mi2iItr = mi2iMap.find(&MI);
582 if (mi2iItr == mi2iMap.end())
583 return SlotIndex();
584 SlotIndex replaceBaseIndex = mi2iItr->second;
585 IndexListEntry *miEntry(replaceBaseIndex.listEntry());
586 assert(miEntry->getInstr() == &MI &&
587 "Mismatched instruction in index tables.");
588 miEntry->setInstr(&NewMI);
589 mi2iMap.erase(mi2iItr);
590 mi2iMap.insert(std::make_pair(&NewMI, replaceBaseIndex));
591 return replaceBaseIndex;
592 }
593
594 /// Add the given MachineBasicBlock into the maps.
595 /// If it contains any instructions then they must already be in the maps.
596 /// This is used after a block has been split by moving some suffix of its
597 /// instructions into a newly created block.
599 assert(mbb != &mbb->getParent()->front() &&
600 "Can't insert a new block at the beginning of a function.");
601 auto prevMBB = std::prev(MachineFunction::iterator(mbb));
602
603 // Create a new entry to be used for the start of mbb and the end of
604 // prevMBB.
605 IndexListEntry *startEntry = createEntry(nullptr, 0);
606 IndexListEntry *endEntry = getMBBEndIdx(&*prevMBB).listEntry();
607 IndexListEntry *insEntry =
608 mbb->empty() ? endEntry
609 : getInstructionIndex(mbb->front()).listEntry();
610 IndexList::iterator newItr =
611 indexList.insert(insEntry->getIterator(), startEntry);
612
613 SlotIndex startIdx(startEntry, SlotIndex::Slot_Block);
614 SlotIndex endIdx(endEntry, SlotIndex::Slot_Block);
615
616 MBBRanges[prevMBB->getNumber()].second = startIdx;
617
618 assert(unsigned(mbb->getNumber()) == MBBRanges.size() &&
619 "Blocks must be added in order");
620 MBBRanges.push_back(std::make_pair(startIdx, endIdx));
621 idx2MBBMap.push_back(IdxMBBPair(startIdx, mbb));
622
623 renumberIndexes(newItr);
624 llvm::sort(idx2MBBMap, less_first());
625 }
626
627 /// Renumber all indexes using the default instruction distance.
628 void packIndexes();
629 };
630
631 // Specialize IntervalMapInfo for half-open slot index intervals.
632 template <>
634 };
635
636} // end namespace llvm
637
638#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:480
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:69
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:179
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
Definition: SlotIndexes.h:212
SlotIndex getNextIndex() const
Returns the next index.
Definition: SlotIndexes.h:265
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
Definition: SlotIndexes.h:245
static bool isEarlierInstr(SlotIndex A, SlotIndex B)
isEarlierInstr - Return true if A refers to an instruction earlier than B.
Definition: SlotIndexes.h:185
SlotIndex()=default
Construct an invalid index.
bool isEarlyClobber() const
isEarlyClobber - Returns true if this is an early-clobber slot.
Definition: SlotIndexes.h:215
bool operator>=(SlotIndex other) const
Compare two SlotIndex objects.
Definition: SlotIndexes.h:174
int distance(SlotIndex other) const
Return the distance from this index to the given one.
Definition: SlotIndexes.h:196
bool operator>(SlotIndex other) const
Compare two SlotIndex objects.
Definition: SlotIndexes.h:168
@ 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:133
bool isRegister() const
isRegister - Returns true if this is a normal register use/def slot.
Definition: SlotIndexes.h:219
bool operator!=(SlotIndex other) const
Compare two SlotIndex objects for inequality.
Definition: SlotIndexes.h:151
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:191
SlotIndex getBoundaryIndex() const
Returns the boundary index for associated with this index.
Definition: SlotIndexes.h:234
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
Definition: SlotIndexes.h:227
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:285
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:255
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
Definition: SlotIndexes.h:275
bool operator<(SlotIndex other) const
Compare two SlotIndex objects.
Definition: SlotIndexes.h:157
bool operator<=(SlotIndex other) const
Compare two SlotIndex objects.
Definition: SlotIndexes.h:162
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:206
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:240
bool operator==(SlotIndex other) const
Compare two SlotIndex objects for equality.
Definition: SlotIndexes.h:147
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
Definition: SlotIndexes.h:222
SlotIndexes pass.
Definition: SlotIndexes.h:300
SlotIndex getLastIndex()
Returns the base index of the last slot in this analysis.
Definition: SlotIndexes.h:360
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
Definition: SlotIndexes.h:523
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:507
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:598
MBBIndexIterator getMBBLowerBound(MBBIndexIterator Start, SlotIndex Idx) const
Get an iterator pointing to the first IdxMBBPair with SlotIndex greater than or equal to Idx.
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:441
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
Definition: SlotIndexes.h:462
void removeSingleMachineInstrFromMaps(MachineInstr &MI)
Removes a single machine instruction MI from the mapping.
MBBIndexIterator getMBBLowerBound(SlotIndex Idx) const
Definition: SlotIndexes.h:484
MBBIndexIterator MBBIndexBegin() const
Returns an iterator for the begin of the idx2MBBMap.
Definition: SlotIndexes.h:497
SlotIndex getNextNonNullIndex(SlotIndex Index)
Returns the next non-null index, if one exists.
Definition: SlotIndexes.h:395
MBBIndexIterator MBBIndexEnd() const
Return an iterator for the end of the idx2MBBMap.
Definition: SlotIndexes.h:502
SmallVectorImpl< IdxMBBPair >::const_iterator MBBIndexIterator
Iterator over the idx2MBBMap (sorted pairs of slot index of basic block begin and basic block)
Definition: SlotIndexes.h:473
MBBIndexIterator getMBBUpperBound(SlotIndex Idx) const
Get an iterator pointing to the first IdxMBBPair with SlotIndex greater than Idx.
Definition: SlotIndexes.h:490
static char ID
Definition: SlotIndexes.h:334
SlotIndex getInstructionIndex(const MachineInstr &MI, bool IgnoreBundle=false) const
Returns the base index for the given instruction.
Definition: SlotIndexes.h:371
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:425
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
Definition: SlotIndexes.h:452
~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:366
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:408
SlotIndex replaceMachineInstrInMaps(MachineInstr &MI, MachineInstr &NewMI)
ReplaceMachineInstrInMaps - Replacing a machine instr with a new one in maps used by register allocat...
Definition: SlotIndexes.h:580
SlotIndex getZeroIndex()
Returns the zero index for this analysis.
Definition: SlotIndexes.h:354
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Returns the last index in the given basic block.
Definition: SlotIndexes.h:467
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Returns the first index in the given basic block.
Definition: SlotIndexes.h:457
const std::pair< SlotIndex, SlotIndex > & getMBBRange(const MachineBasicBlock *MBB) const
Return the (start,end) range of the given basic block.
Definition: SlotIndexes.h:447
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:389
size_t size() const
Definition: SmallVector.h:91
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:591
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
self_iterator getIterator()
Definition: ilist_node.h:109
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:295
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:1656
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:293
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:1459