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