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