LLVM 24.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 SlotIndex(IndexListEntry *entry, unsigned slot) : lie(entry, slot) {}
96
97 IndexListEntry* listEntry() const {
98 assert(isValid() && "Attempt to compare reserved index.");
99 return lie.getPointer();
100 }
101
102 unsigned getIndex() const {
103 return listEntry()->getIndex() | getSlot();
104 }
105
106 /// Returns the slot for this SlotIndex.
107 Slot getSlot() const {
108 return static_cast<Slot>(lie.getInt());
109 }
110
111 public:
112 enum {
113 /// The default distance between instructions as returned by distance().
114 /// This may vary as instructions are inserted and removed.
115 InstrDist = 4 * Slot_Count
116 };
117
118 /// Construct an invalid index.
119 SlotIndex() = default;
120
121 // Construct a new slot index from the given one, and set the slot.
122 SlotIndex(const SlotIndex &li, Slot s) : lie(li.listEntry(), unsigned(s)) {
123 assert(isValid() && "Attempt to construct index with 0 pointer.");
124 }
125
126 /// Returns true if this is a valid index. Invalid indices do
127 /// not point into an index table, and cannot be compared.
128 bool isValid() const {
129 return lie.getPointer();
130 }
131
132 /// Return true for a valid index.
133 explicit operator bool() const { return isValid(); }
134
135 /// Print this index to the given raw_ostream.
136 LLVM_ABI void print(raw_ostream &os) const;
137
138 /// Dump this index to stderr.
139 LLVM_ABI void dump() const;
140
141 /// Compare two SlotIndex objects for equality.
142 bool operator==(SlotIndex other) const {
143 return lie == other.lie;
144 }
145 /// Compare two SlotIndex objects for inequality.
146 bool operator!=(SlotIndex other) const {
147 return lie != other.lie;
148 }
149
150 /// Compare two SlotIndex objects. Return true if the first index
151 /// is strictly lower than the second.
152 bool operator<(SlotIndex other) const {
153 return getIndex() < other.getIndex();
154 }
155 /// Compare two SlotIndex objects. Return true if the first index
156 /// is lower than, or equal to, the second.
157 bool operator<=(SlotIndex other) const {
158 return getIndex() <= other.getIndex();
159 }
160
161 /// Compare two SlotIndex objects. Return true if the first index
162 /// is greater than the second.
163 bool operator>(SlotIndex other) const {
164 return getIndex() > other.getIndex();
165 }
166
167 /// Compare two SlotIndex objects. Return true if the first index
168 /// is greater than, or equal to, the second.
169 bool operator>=(SlotIndex other) const {
170 return getIndex() >= other.getIndex();
171 }
172
173 /// isSameInstr - Return true if A and B refer to the same instruction.
174 static bool isSameInstr(SlotIndex A, SlotIndex B) {
175 return A.listEntry() == B.listEntry();
176 }
177
178 /// isEarlierInstr - Return true if A refers to an instruction earlier than
179 /// B. This is equivalent to A < B && !isSameInstr(A, B).
180 static bool isEarlierInstr(SlotIndex A, SlotIndex B) {
181 return A.listEntry()->getIndex() < B.listEntry()->getIndex();
182 }
183
184 /// Return true if A refers to the same instruction as B or an earlier one.
185 /// This is equivalent to !isEarlierInstr(B, A).
186 static bool isEarlierEqualInstr(SlotIndex A, SlotIndex B) {
187 return !isEarlierInstr(B, A);
188 }
189
190 /// Return the distance from this index to the given one.
191 int distance(SlotIndex other) const {
192 return other.getIndex() - getIndex();
193 }
194
195 /// Return the scaled distance from this index to the given one, where all
196 /// slots on the same instruction have zero distance, assuming that the slot
197 /// indices are packed as densely as possible. There are normally gaps
198 /// between instructions, so this assumption often doesn't hold. This
199 /// results in this function often returning a value greater than the actual
200 /// instruction distance.
201 int getApproxInstrDistance(SlotIndex other) const {
202 return (other.listEntry()->getIndex() - listEntry()->getIndex())
203 / Slot_Count;
204 }
205
206 /// isBlock - Returns true if this is a block boundary slot.
207 bool isBlock() const { return getSlot() == Slot_Block; }
208
209 /// isEarlyClobber - Returns true if this is an early-clobber slot.
210 bool isEarlyClobber() const { return getSlot() == Slot_EarlyClobber; }
211
212 /// isRegister - Returns true if this is a normal register use/def slot.
213 /// Note that early-clobber slots may also be used for uses and defs.
214 bool isRegister() const { return getSlot() == Slot_Register; }
215
216 /// isDead - Returns true if this is a dead def kill slot.
217 bool isDead() const { return getSlot() == Slot_Dead; }
218
219 /// Returns the base index for associated with this index. The base index
220 /// is the one associated with the Slot_Block slot for the instruction
221 /// pointed to by this index.
222 SlotIndex getBaseIndex() const {
223 return SlotIndex(listEntry(), Slot_Block);
224 }
225
226 /// Returns the boundary index for associated with this index. The boundary
227 /// index is the one associated with the Slot_Block slot for the instruction
228 /// pointed to by this index.
229 SlotIndex getBoundaryIndex() const {
230 return SlotIndex(listEntry(), Slot_Dead);
231 }
232
233 /// Returns the register use/def slot in the current instruction for a
234 /// normal or early-clobber def.
235 SlotIndex getRegSlot(bool EC = false) const {
236 return SlotIndex(listEntry(), EC ? Slot_EarlyClobber : Slot_Register);
237 }
238
239 /// Returns the dead def kill slot for the current instruction.
240 SlotIndex getDeadSlot() const {
241 return SlotIndex(listEntry(), Slot_Dead);
242 }
243
244 /// Returns the next slot in the index list. This could be either the
245 /// next slot for the instruction pointed to by this index or, if this
246 /// index is a STORE, the first slot for the next instruction.
247 /// WARNING: This method is considerably more expensive than the methods
248 /// that return specific slots (getUseIndex(), etc). If you can - please
249 /// use one of those methods.
250 SlotIndex getNextSlot() const {
251 Slot s = getSlot();
252 if (s == Slot_Dead) {
253 return SlotIndex(&*++listEntry()->getIterator(), Slot_Block);
254 }
255 return SlotIndex(listEntry(), s + 1);
256 }
257
258 /// Returns the next index. This is the index corresponding to the this
259 /// index's slot, but for the next instruction.
260 SlotIndex getNextIndex() const {
261 return SlotIndex(&*++listEntry()->getIterator(), getSlot());
262 }
263
264 /// Returns the previous slot in the index list. This could be either the
265 /// previous slot for the instruction pointed to by this index or, if this
266 /// index is a Slot_Block, the last slot for the previous instruction.
267 /// WARNING: This method is considerably more expensive than the methods
268 /// that return specific slots (getUseIndex(), etc). If you can - please
269 /// use one of those methods.
270 SlotIndex getPrevSlot() const {
271 Slot s = getSlot();
272 if (s == Slot_Block) {
273 return SlotIndex(&*--listEntry()->getIterator(), Slot_Dead);
274 }
275 return SlotIndex(listEntry(), s - 1);
276 }
277
278 /// Returns the previous index. This is the index corresponding to this
279 /// index's slot, but for the previous instruction.
280 SlotIndex getPrevIndex() const {
281 return SlotIndex(&*--listEntry()->getIterator(), getSlot());
282 }
283 };
284
286 li.print(os);
287 return os;
288 }
289
290 using IdxMBBPair = std::pair<SlotIndex, MachineBasicBlock *>;
291
292 /// SlotIndexes pass.
293 ///
294 /// This pass assigns indexes to each instruction.
295 class SlotIndexes {
297
298 private:
299 // IndexListEntry allocator.
300 BumpPtrAllocator ileAllocator;
301
302 using IndexList = simple_ilist<IndexListEntry>;
303 IndexList indexList;
304
305 MachineFunction *mf = nullptr;
306
308 Mi2IndexMap mi2iMap;
309
310 /// MBBRanges - Map analysis block number to (start, stop) indexes.
312
313 /// Idx2MBBMap - Sorted list of pairs of index of first instruction
314 /// and MBB id.
316
317 // For legacy pass manager.
318 SlotIndexes() = default;
319
320 LLVM_ABI void clear();
321
322 LLVM_ABI void analyze(MachineFunction &MF);
323
324 IndexListEntry* createEntry(MachineInstr *mi, unsigned index) {
325 IndexListEntry *entry =
326 static_cast<IndexListEntry *>(ileAllocator.Allocate(
327 sizeof(IndexListEntry), alignof(IndexListEntry)));
328
329 new (entry) IndexListEntry(mi, index);
330
331 return entry;
332 }
333
334 /// Renumber locally after inserting curItr.
335 LLVM_ABI void renumberIndexes(IndexList::iterator curItr);
336
337 public:
338 SlotIndexes(SlotIndexes &&) = default;
339
340 SlotIndexes(MachineFunction &MF) { analyze(MF); }
341
343
345 clear();
346 analyze(MF);
347 }
348
349 LLVM_ABI void print(raw_ostream &OS) const;
350
351 /// Dump the indexes.
352 LLVM_ABI void dump() const;
353
354 /// Repair indexes after adding and removing instructions.
358
359 /// Returns the zero index for this analysis.
361 assert(indexList.front().getIndex() == 0 && "First index is not 0?");
362 return SlotIndex(&indexList.front(), 0);
363 }
364
365 /// Returns the base index of the last slot in this analysis.
367 return SlotIndex(&indexList.back(), 0);
368 }
369
370 /// Returns true if the given machine instr is mapped to an index,
371 /// otherwise returns false.
372 bool hasIndex(const MachineInstr &instr) const {
373 return mi2iMap.count(&instr);
374 }
375
376 /// Returns the base index for the given instruction.
378 bool IgnoreBundle = false) const {
379 // Instructions inside a bundle have the same number as the bundle itself.
380 auto BundleStart = getBundleStart(MI.getIterator());
381 auto BundleEnd = getBundleEnd(MI.getIterator());
382 // Use the first non-debug instruction in the bundle to get SlotIndex.
383 const MachineInstr &BundleNonDebug =
384 IgnoreBundle ? MI
385 : *skipDebugInstructionsForward(BundleStart, BundleEnd);
386 assert(!BundleNonDebug.isDebugInstr() &&
387 "Could not use a debug instruction to query mi2iMap.");
388 Mi2IndexMap::const_iterator itr = mi2iMap.find(&BundleNonDebug);
389 assert(itr != mi2iMap.end() && "Instruction not found in maps.");
390 return itr->second;
391 }
392
393 /// Returns the instruction for the given index, or null if the given
394 /// index has no instruction associated with it.
396 return index.listEntry()->getInstr();
397 }
398
399 /// Returns true if \p Idx refers to an entry created to mark a basic block
400 /// boundary. Such entries never have an instruction attached.
402
403 /// Returns true if \p Idx refers to an instruction that has been erased.
404 bool isStaleIndex(SlotIndex Idx) const {
405 return !getInstructionFromIndex(Idx) && !isBlockBoundaryIndex(Idx);
406 }
407
408 /// Returns the register slot of the closest instruction preceding a stale
409 /// \p Idx, or the start index of its basic block if there is none. Returns
410 /// \p Idx unchanged if it is not stale.
412
413 /// Returns the next non-null index, if one exists.
414 /// Otherwise returns getLastIndex().
416 IndexList::iterator I = Index.listEntry()->getIterator();
417 IndexList::iterator E = indexList.end();
418 while (++I != E)
419 if (I->getInstr())
420 return SlotIndex(&*I, Index.getSlot());
421 // We reached the end of the function.
422 return getLastIndex();
423 }
424
425 /// getIndexBefore - Returns the index of the last indexed instruction
426 /// before MI, or the start index of its basic block.
427 /// MI is not required to have an index.
429 const MachineBasicBlock *MBB = MI.getParent();
430 assert(MBB && "MI must be inserted in a basic block");
432 while (true) {
433 if (I == B)
434 return getMBBStartIdx(MBB);
435 --I;
436 if (I->isDebugInstr())
437 continue;
438 Mi2IndexMap::const_iterator MapItr = mi2iMap.find(&*I);
439 if (MapItr != mi2iMap.end())
440 return MapItr->second;
441 }
442 }
443
444 /// getIndexAfter - Returns the index of the first indexed instruction
445 /// after MI, or the end index of its basic block.
446 /// MI is not required to have an index.
448 const MachineBasicBlock *MBB = MI.getParent();
449 assert(MBB && "MI must be inserted in a basic block");
451 while (true) {
452 ++I;
453 if (I == E)
454 return getMBBEndIdx(MBB);
455 if (I->isDebugInstr())
456 continue;
457 Mi2IndexMap::const_iterator MapItr = mi2iMap.find(&*I);
458 if (MapItr != mi2iMap.end())
459 return MapItr->second;
460 }
461 }
462
463 /// Return the (start,end) range of the given basic block.
464 const std::pair<SlotIndex, SlotIndex> &
466 return MBBRanges[MBB->getAnalysisNumber()];
467 }
468
469 /// Returns the first index in the given basic block.
471 return getMBBRange(mbb).first;
472 }
473
474 /// Returns the index past the last valid index in the given basic block.
476 return getMBBRange(mbb).second;
477 }
478
479 /// Returns the last valid index in the given basic block.
480 /// This index corresponds to the dead slot of the last non-debug
481 /// instruction and can be used to find live-out ranges of the block. Note
482 /// that getMBBEndIdx returns the start index of the next block, which is
483 /// also used as the start index for segments with phi-def values. If the
484 /// basic block doesn't contain any non-debug instructions, this returns
485 /// the same as getMBBStartIdx.getDeadSlot().
489
490 /// Iterator over the idx2MBBMap (sorted pairs of slot index of basic block
491 /// begin and basic block)
493
494 /// Get an iterator pointing to the first IdxMBBPair with SlotIndex greater
495 /// than or equal to \p Idx. If \p Start is provided, only search the range
496 /// from \p Start to the end of the function.
498 SlotIndex Idx) const {
499 return std::lower_bound(
500 Start, MBBIndexEnd(), Idx,
501 [](const IdxMBBPair &IM, SlotIndex Idx) { return IM.first < Idx; });
502 }
506
507 /// Get an iterator pointing to the first IdxMBBPair with SlotIndex greater
508 /// than \p Idx.
510 return std::upper_bound(
511 MBBIndexBegin(), MBBIndexEnd(), Idx,
512 [](SlotIndex Idx, const IdxMBBPair &IM) { return Idx < IM.first; });
513 }
514
515 /// Returns an iterator for the begin of the idx2MBBMap.
517 return idx2MBBMap.begin();
518 }
519
520 /// Return an iterator for the end of the idx2MBBMap.
522 return idx2MBBMap.end();
523 }
524
525 /// Returns the basic block which the given index falls in.
528 return MI->getParent();
529
530 MBBIndexIterator I = std::prev(getMBBUpperBound(index));
531 assert(I != MBBIndexEnd() && I->first <= index &&
532 index < getMBBEndIdx(I->second) &&
533 "index does not correspond to an MBB");
534 return I->second;
535 }
536
537 /// Insert the given machine instruction into the mapping. Returns the
538 /// assigned index.
539 /// If Late is set and there are null indexes between mi's neighboring
540 /// instructions, create the new index after the null indexes instead of
541 /// before them.
543 assert(!MI.isInsideBundle() &&
544 "Instructions inside bundles should use bundle start's slot.");
545 assert(!mi2iMap.contains(&MI) && "Instr already indexed.");
546 // Numbering debug instructions could cause code generation to be
547 // affected by debug information.
548 assert(!MI.isDebugInstr() && "Cannot number debug instructions.");
549
550 assert(MI.getParent() != nullptr && "Instr must be added to function.");
551
552 // Get the entries where MI should be inserted.
553 IndexList::iterator prevItr, nextItr;
554 if (Late) {
555 // Insert MI's index immediately before the following instruction.
556 nextItr = getIndexAfter(MI).listEntry()->getIterator();
557 prevItr = std::prev(nextItr);
558 } else {
559 // Insert MI's index immediately after the preceding instruction.
560 prevItr = getIndexBefore(MI).listEntry()->getIterator();
561 nextItr = std::next(prevItr);
562 }
563
564 // Get a number for the new instr, or 0 if there's no room currently.
565 // In the latter case we'll force a renumber later.
566 unsigned dist = ((nextItr->getIndex() - prevItr->getIndex())/2) & ~3u;
567 unsigned newNumber = prevItr->getIndex() + dist;
568
569 // Insert a new list entry for MI.
570 IndexList::iterator newItr =
571 indexList.insert(nextItr, *createEntry(&MI, newNumber));
572
573 // Renumber locally if we need to.
574 if (dist == 0)
575 renumberIndexes(newItr);
576
577 SlotIndex newIndex(&*newItr, SlotIndex::Slot_Block);
578 mi2iMap.insert(std::make_pair(&MI, newIndex));
579 return newIndex;
580 }
581
582 /// Removes machine instruction (bundle) \p MI from the mapping.
583 /// This should be called before MachineInstr::eraseFromParent() is used to
584 /// remove a whole bundle or an unbundled instruction.
585 /// If \p AllowBundled is set then this can be used on a bundled
586 /// instruction; however, this exists to support handleMoveIntoBundle,
587 /// and in general removeSingleMachineInstrFromMaps should be used instead.
589 bool AllowBundled = false);
590
591 /// Removes a single machine instruction \p MI from the mapping.
592 /// This should be called before MachineInstr::eraseFromBundle() is used to
593 /// remove a single instruction (out of a bundle).
595
596 /// ReplaceMachineInstrInMaps - Replacing a machine instr with a new one in
597 /// maps used by register allocator. \returns the index where the new
598 /// instruction was inserted.
600 Mi2IndexMap::iterator mi2iItr = mi2iMap.find(&MI);
601 if (mi2iItr == mi2iMap.end())
602 return SlotIndex();
603 SlotIndex replaceBaseIndex = mi2iItr->second;
604 IndexListEntry *miEntry(replaceBaseIndex.listEntry());
605 assert(miEntry->getInstr() == &MI &&
606 "Mismatched instruction in index tables.");
607 miEntry->setInstr(&NewMI);
608 mi2iMap.erase(mi2iItr);
609 mi2iMap.insert(std::make_pair(&NewMI, replaceBaseIndex));
610 return replaceBaseIndex;
611 }
612
613 /// Add the given MachineBasicBlock into the maps.
614 /// If it contains any instructions then they must already be in the maps.
615 /// This is used after a block has been split by moving some suffix of its
616 /// instructions into a newly created block.
618 assert(mbb != &mbb->getParent()->front() &&
619 "Can't insert a new block at the beginning of a function.");
620 auto prevMBB = std::prev(MachineFunction::iterator(mbb));
621
622 // Create a new entry to be used for the start of mbb and the end of
623 // prevMBB.
624 IndexListEntry *startEntry = createEntry(nullptr, 0);
625 IndexListEntry *endEntry = getMBBEndIdx(&*prevMBB).listEntry();
626 IndexListEntry *insEntry =
627 mbb->empty() ? endEntry
628 : getInstructionIndex(mbb->front()).listEntry();
629 IndexList::iterator newItr =
630 indexList.insert(insEntry->getIterator(), *startEntry);
631
632 SlotIndex startIdx(startEntry, SlotIndex::Slot_Block);
633 SlotIndex endIdx(endEntry, SlotIndex::Slot_Block);
634
635 MBBRanges[prevMBB->getAnalysisNumber()].second = startIdx;
636
637 assert(unsigned(mbb->getAnalysisNumber()) == MBBRanges.size() &&
638 "Blocks must be added in order");
639 MBBRanges.push_back(std::make_pair(startIdx, endIdx));
640
641 renumberIndexes(newItr);
642 auto InsertPt =
643 llvm::partition_point(idx2MBBMap, [=](const IdxMBBPair &IM) {
644 return IM.first < startIdx;
645 });
646 idx2MBBMap.insert(InsertPt, IdxMBBPair(startIdx, mbb));
647 }
648
649 /// Inverse of insertMBBInMaps: merge \p MBB's slot range into its layout
650 /// predecessor and drop it from the maps. Call before erasing \p MBB and
651 /// after its instructions have been removed from the maps.
653
654 /// Renumber all indexes using the default instruction distance.
655 LLVM_ABI void packIndexes();
656 };
657
658 // Specialize IntervalMapInfo for half-open slot index intervals.
659 template <>
661 };
662
663 class SlotIndexesAnalysis : public AnalysisInfoMixin<SlotIndexesAnalysis> {
665 LLVM_ABI static AnalysisKey Key;
666
667 public:
670 };
671
673 : public RequiredPassInfoMixin<SlotIndexesPrinterPass> {
674 raw_ostream &OS;
675
676 public:
677 explicit SlotIndexesPrinterPass(raw_ostream &OS) : OS(OS) {}
680 };
681
683 SlotIndexes SI;
684
685 public:
686 static char ID;
687
689
690 void getAnalysisUsage(AnalysisUsage &au) const override;
691 void releaseMemory() override { SI.clear(); }
692
694 SI.analyze(fn);
695 return false;
696 }
697
698 SlotIndexes &getSI() { return SI; }
699 };
700
701} // end namespace llvm
702
703#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< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:215
This file defines the DenseMap class.
IRTranslator LLVM IR MI
This file implements a coalescing interval map for small objects.
#define I(x, y, z)
Definition MD5.cpp:57
This file defines the PointerIntPair class.
This file defines the SmallVector class.
Represent the analysis usage information of a pass.
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
Definition DenseMap.h:680
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
Definition DenseMap.h:679
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
MachineInstrBundleIterator< const MachineInstr > const_iterator
int getAnalysisNumber() const
For analyses, blocks have a more stable number.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineInstrBundleIterator< MachineInstr > iterator
BasicBlockListType::iterator iterator
const MachineBasicBlock & front() const
Representation of each machine instruction.
bool isDebugInstr() const
PointerIntPair - This class implements a pair of a pointer and small integer.
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.
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
SlotIndex getNextIndex() const
Returns the next index.
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
static bool isEarlierInstr(SlotIndex A, SlotIndex B)
isEarlierInstr - Return true if A refers to an instruction earlier than B.
SlotIndex()=default
Construct an invalid index.
bool isEarlyClobber() const
isEarlyClobber - Returns true if this is an early-clobber slot.
bool operator>=(SlotIndex other) const
Compare two SlotIndex objects.
int distance(SlotIndex other) const
Return the distance from this index to the given one.
bool operator>(SlotIndex other) const
Compare two SlotIndex objects.
@ InstrDist
The default distance between instructions as returned by distance().
bool isValid() const
Returns true if this is a valid index.
bool isRegister() const
isRegister - Returns true if this is a normal register use/def slot.
bool operator!=(SlotIndex other) const
Compare two SlotIndex objects for inequality.
static bool isEarlierEqualInstr(SlotIndex A, SlotIndex B)
Return true if A refers to the same instruction as B or an earlier one.
SlotIndex getBoundaryIndex() const
Returns the boundary index for associated with this index.
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
LLVM_ABI void dump() const
Dump this index to stderr.
SlotIndex(const SlotIndex &li, Slot s)
SlotIndex getPrevIndex() const
Returns the previous index.
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.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
bool operator<(SlotIndex other) const
Compare two SlotIndex objects.
bool operator<=(SlotIndex other) const
Compare two SlotIndex objects.
int getApproxInstrDistance(SlotIndex other) const
Return the scaled distance from this index to the given one, where all slots on the same instruction ...
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
friend class SlotIndexes
Definition SlotIndexes.h:67
bool operator==(SlotIndex other) const
Compare two SlotIndex objects for equality.
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &)
SlotIndexesPrinterPass(raw_ostream &OS)
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
bool runOnMachineFunction(MachineFunction &fn) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
void getAnalysisUsage(AnalysisUsage &au) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
SlotIndexes pass.
LLVM_ABI bool isBlockBoundaryIndex(SlotIndex Idx) const
Returns true if Idx refers to an entry created to mark a basic block boundary.
SlotIndex getLastIndex()
Returns the base index of the last slot in this analysis.
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
SlotIndex getMBBLastIdx(const MachineBasicBlock *MBB) const
Returns the last valid index in the given basic block.
SlotIndexes(SlotIndexes &&)=default
LLVM_ABI void removeMachineInstrFromMaps(MachineInstr &MI, bool AllowBundled=false)
Removes machine instruction (bundle) MI from the mapping.
LLVM_ABI SlotIndex canonicalizeIndex(SlotIndex Idx) const
Returns the register slot of the closest instruction preceding a stale Idx, or the start index of its...
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
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.
MBBIndexIterator getMBBLowerBound(MBBIndexIterator Start, SlotIndex Idx) const
Get an iterator pointing to the first IdxMBBPair with SlotIndex greater than or equal to Idx.
void reanalyze(MachineFunction &MF)
LLVM_ABI void removeSingleMachineInstrFromMaps(MachineInstr &MI)
Removes a single machine instruction MI from the mapping.
MBBIndexIterator getMBBLowerBound(SlotIndex Idx) const
MBBIndexIterator MBBIndexBegin() const
Returns an iterator for the begin of the idx2MBBMap.
SlotIndex getNextNonNullIndex(SlotIndex Index)
Returns the next non-null index, if one exists.
MBBIndexIterator MBBIndexEnd() const
Return an iterator for the end of the idx2MBBMap.
SmallVectorImpl< IdxMBBPair >::const_iterator MBBIndexIterator
Iterator over the idx2MBBMap (sorted pairs of slot index of basic block begin and basic block)
MBBIndexIterator getMBBUpperBound(SlotIndex Idx) const
Get an iterator pointing to the first IdxMBBPair with SlotIndex greater than Idx.
SlotIndexes(MachineFunction &MF)
SlotIndex getInstructionIndex(const MachineInstr &MI, bool IgnoreBundle=false) const
Returns the base index for the given instruction.
SlotIndex getIndexAfter(const MachineInstr &MI) const
getIndexAfter - Returns the index of the first indexed instruction after MI, or the end index of its ...
LLVM_ABI ~SlotIndexes()
bool isStaleIndex(SlotIndex Idx) const
Returns true if Idx refers to an instruction that has been erased.
LLVM_ABI void packIndexes()
Renumber all indexes using the default instruction distance.
LLVM_ABI void removeMBBFromMaps(MachineBasicBlock &MBB)
Inverse of insertMBBInMaps: merge MBB's slot range into its layout predecessor and drop it from the m...
bool hasIndex(const MachineInstr &instr) const
Returns true if the given machine instr is mapped to an index, otherwise returns false.
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...
SlotIndex replaceMachineInstrInMaps(MachineInstr &MI, MachineInstr &NewMI)
ReplaceMachineInstrInMaps - Replacing a machine instr with a new one in maps used by register allocat...
SlotIndex getZeroIndex()
Returns the zero index for this analysis.
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Returns the index past the last valid index in the given basic block.
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Returns the first index in the given basic block.
const std::pair< SlotIndex, SlotIndex > & getMBBRange(const MachineBasicBlock *MBB) const
Return the (start,end) range of the given basic block.
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction for the given index, or null if the given index has no instruction associated...
friend class SlotIndexesWrapperPass
typename SuperClass::const_iterator const_iterator
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
self_iterator getIterator()
Definition ilist_node.h:123
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
A simple intrusive list implementation.
ilist_select_iterator_type< OptionsT, false, false > iterator
This is an optimization pass for GlobalISel generic memory operations.
MachineBasicBlock::instr_iterator getBundleStart(MachineBasicBlock::instr_iterator I)
Returns an iterator to the first instruction in the bundle containing I.
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
Definition STLExtras.h:2145
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
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.
MachineBasicBlock::instr_iterator getBundleEnd(MachineBasicBlock::instr_iterator I)
Returns an iterator pointing beyond the bundle containing I.
std::pair< SlotIndex, MachineBasicBlock * > IdxMBBPair
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:391
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
A CRTP mix-in for passes that should not be skipped.