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