LLVM  4.0.0
SlotIndexes.h
Go to the documentation of this file.
1 //===- llvm/CodeGen/SlotIndexes.h - Slot indexes representation -*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements SlotIndex and related classes. The purpose of SlotIndex
11 // is to describe a position at which a register can become live, or cease to
12 // be live.
13 //
14 // SlotIndex is mostly a proxy for entries of the SlotIndexList, a class which
15 // is held is LiveIntervals and provides the real numbering. This allows
16 // LiveIntervals to perform largely transparent renumbering.
17 //===----------------------------------------------------------------------===//
18 
19 #ifndef LLVM_CODEGEN_SLOTINDEXES_H
20 #define LLVM_CODEGEN_SLOTINDEXES_H
21 
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/IntervalMap.h"
25 #include "llvm/ADT/SmallVector.h"
26 #include "llvm/ADT/ilist.h"
30 #include "llvm/Support/Allocator.h"
31 
32 namespace llvm {
33 
34  /// This class represents an entry in the slot index list held in the
35  /// SlotIndexes pass. It should not be used directly. See the
36  /// SlotIndex & SlotIndexes classes for the public interface to this
37  /// information.
38  class IndexListEntry : public ilist_node<IndexListEntry> {
39  MachineInstr *mi;
40  unsigned index;
41 
42  public:
43 
44  IndexListEntry(MachineInstr *mi, unsigned index) : mi(mi), index(index) {}
45 
46  MachineInstr* getInstr() const { return mi; }
47  void setInstr(MachineInstr *mi) {
48  this->mi = mi;
49  }
50 
51  unsigned getIndex() const { return index; }
52  void setIndex(unsigned index) {
53  this->index = index;
54  }
55 
56 #ifdef EXPENSIVE_CHECKS
57  // When EXPENSIVE_CHECKS is defined, "erased" index list entries will
58  // actually be moved to a "graveyard" list, and have their pointers
59  // poisoned, so that dangling SlotIndex access can be reliably detected.
60  void setPoison() {
61  intptr_t tmp = reinterpret_cast<intptr_t>(mi);
62  assert(((tmp & 0x1) == 0x0) && "Pointer already poisoned?");
63  tmp |= 0x1;
64  mi = reinterpret_cast<MachineInstr*>(tmp);
65  }
66 
67  bool isPoisoned() const { return (reinterpret_cast<intptr_t>(mi) & 0x1) == 0x1; }
68 #endif // EXPENSIVE_CHECKS
69  };
70 
71  template <>
73  : public ilist_noalloc_traits<IndexListEntry> {};
74 
75  /// SlotIndex - An opaque wrapper around machine indexes.
76  class SlotIndex {
77  friend class SlotIndexes;
78 
79  enum Slot {
80  /// Basic block boundary. Used for live ranges entering and leaving a
81  /// block without being live in the layout neighbor. Also used as the
82  /// def slot of PHI-defs.
83  Slot_Block,
84 
85  /// Early-clobber register use/def slot. A live range defined at
86  /// Slot_EarlyClobber interferes with normal live ranges killed at
87  /// Slot_Register. Also used as the kill slot for live ranges tied to an
88  /// early-clobber def.
89  Slot_EarlyClobber,
90 
91  /// Normal register use/def slot. Normal instructions kill and define
92  /// register live ranges at this slot.
93  Slot_Register,
94 
95  /// Dead def kill point. Kill slot for a live range that is defined by
96  /// the same instruction (Slot_Register or Slot_EarlyClobber), but isn't
97  /// used anywhere.
98  Slot_Dead,
99 
100  Slot_Count
101  };
102 
104 
105  SlotIndex(IndexListEntry *entry, unsigned slot)
106  : lie(entry, slot) {}
107 
108  IndexListEntry* listEntry() const {
109  assert(isValid() && "Attempt to compare reserved index.");
110 #ifdef EXPENSIVE_CHECKS
111  assert(!lie.getPointer()->isPoisoned() &&
112  "Attempt to access deleted list-entry.");
113 #endif // EXPENSIVE_CHECKS
114  return lie.getPointer();
115  }
116 
117  unsigned getIndex() const {
118  return listEntry()->getIndex() | getSlot();
119  }
120 
121  /// Returns the slot for this SlotIndex.
122  Slot getSlot() const {
123  return static_cast<Slot>(lie.getInt());
124  }
125 
126  public:
127  enum {
128  /// The default distance between instructions as returned by distance().
129  /// This may vary as instructions are inserted and removed.
130  InstrDist = 4 * Slot_Count
131  };
132 
133  /// Construct an invalid index.
134  SlotIndex() : lie(nullptr, 0) {}
135 
136  // Construct a new slot index from the given one, and set the slot.
137  SlotIndex(const SlotIndex &li, Slot s) : lie(li.listEntry(), unsigned(s)) {
138  assert(lie.getPointer() != nullptr &&
139  "Attempt to construct index with 0 pointer.");
140  }
141 
142  /// Returns true if this is a valid index. Invalid indices do
143  /// not point into an index table, and cannot be compared.
144  bool isValid() const {
145  return lie.getPointer();
146  }
147 
148  /// Return true for a valid index.
149  explicit operator bool() const { return isValid(); }
150 
151  /// Print this index to the given raw_ostream.
152  void print(raw_ostream &os) const;
153 
154  /// Dump this index to stderr.
155  void dump() const;
156 
157  /// Compare two SlotIndex objects for equality.
158  bool operator==(SlotIndex other) const {
159  return lie == other.lie;
160  }
161  /// Compare two SlotIndex objects for inequality.
162  bool operator!=(SlotIndex other) const {
163  return lie != other.lie;
164  }
165 
166  /// Compare two SlotIndex objects. Return true if the first index
167  /// is strictly lower than the second.
168  bool operator<(SlotIndex other) const {
169  return getIndex() < other.getIndex();
170  }
171  /// Compare two SlotIndex objects. Return true if the first index
172  /// is lower than, or equal to, the second.
173  bool operator<=(SlotIndex other) const {
174  return getIndex() <= other.getIndex();
175  }
176 
177  /// Compare two SlotIndex objects. Return true if the first index
178  /// is greater than the second.
179  bool operator>(SlotIndex other) const {
180  return getIndex() > other.getIndex();
181  }
182 
183  /// Compare two SlotIndex objects. Return true if the first index
184  /// is greater than, or equal to, the second.
185  bool operator>=(SlotIndex other) const {
186  return getIndex() >= other.getIndex();
187  }
188 
189  /// isSameInstr - Return true if A and B refer to the same instruction.
191  return A.lie.getPointer() == B.lie.getPointer();
192  }
193 
194  /// isEarlierInstr - Return true if A refers to an instruction earlier than
195  /// B. This is equivalent to A < B && !isSameInstr(A, B).
197  return A.listEntry()->getIndex() < B.listEntry()->getIndex();
198  }
199 
200  /// Return true if A refers to the same instruction as B or an earlier one.
201  /// This is equivalent to !isEarlierInstr(B, A).
203  return !isEarlierInstr(B, A);
204  }
205 
206  /// Return the distance from this index to the given one.
207  int distance(SlotIndex other) const {
208  return other.getIndex() - getIndex();
209  }
210 
211  /// Return the scaled distance from this index to the given one, where all
212  /// slots on the same instruction have zero distance.
213  int getInstrDistance(SlotIndex other) const {
214  return (other.listEntry()->getIndex() - listEntry()->getIndex())
215  / Slot_Count;
216  }
217 
218  /// isBlock - Returns true if this is a block boundary slot.
219  bool isBlock() const { return getSlot() == Slot_Block; }
220 
221  /// isEarlyClobber - Returns true if this is an early-clobber slot.
222  bool isEarlyClobber() const { return getSlot() == Slot_EarlyClobber; }
223 
224  /// isRegister - Returns true if this is a normal register use/def slot.
225  /// Note that early-clobber slots may also be used for uses and defs.
226  bool isRegister() const { return getSlot() == Slot_Register; }
227 
228  /// isDead - Returns true if this is a dead def kill slot.
229  bool isDead() const { return getSlot() == Slot_Dead; }
230 
231  /// Returns the base index for associated with this index. The base index
232  /// is the one associated with the Slot_Block slot for the instruction
233  /// pointed to by this index.
235  return SlotIndex(listEntry(), Slot_Block);
236  }
237 
238  /// Returns the boundary index for associated with this index. The boundary
239  /// index is the one associated with the Slot_Block slot for the instruction
240  /// pointed to by this index.
242  return SlotIndex(listEntry(), Slot_Dead);
243  }
244 
245  /// Returns the register use/def slot in the current instruction for a
246  /// normal or early-clobber def.
247  SlotIndex getRegSlot(bool EC = false) const {
248  return SlotIndex(listEntry(), EC ? Slot_EarlyClobber : Slot_Register);
249  }
250 
251  /// Returns the dead def kill slot for the current instruction.
253  return SlotIndex(listEntry(), Slot_Dead);
254  }
255 
256  /// Returns the next slot in the index list. This could be either the
257  /// next slot for the instruction pointed to by this index or, if this
258  /// index is a STORE, the first slot for the next instruction.
259  /// WARNING: This method is considerably more expensive than the methods
260  /// that return specific slots (getUseIndex(), etc). If you can - please
261  /// use one of those methods.
263  Slot s = getSlot();
264  if (s == Slot_Dead) {
265  return SlotIndex(&*++listEntry()->getIterator(), Slot_Block);
266  }
267  return SlotIndex(listEntry(), s + 1);
268  }
269 
270  /// Returns the next index. This is the index corresponding to the this
271  /// index's slot, but for the next instruction.
273  return SlotIndex(&*++listEntry()->getIterator(), getSlot());
274  }
275 
276  /// Returns the previous slot in the index list. This could be either the
277  /// previous slot for the instruction pointed to by this index or, if this
278  /// index is a Slot_Block, the last slot for the previous instruction.
279  /// WARNING: This method is considerably more expensive than the methods
280  /// that return specific slots (getUseIndex(), etc). If you can - please
281  /// use one of those methods.
283  Slot s = getSlot();
284  if (s == Slot_Block) {
285  return SlotIndex(&*--listEntry()->getIterator(), Slot_Dead);
286  }
287  return SlotIndex(listEntry(), s - 1);
288  }
289 
290  /// Returns the previous index. This is the index corresponding to this
291  /// index's slot, but for the previous instruction.
293  return SlotIndex(&*--listEntry()->getIterator(), getSlot());
294  }
295  };
296 
297  template <> struct isPodLike<SlotIndex> { static const bool value = true; };
298 
300  li.print(os);
301  return os;
302  }
303 
304  typedef std::pair<SlotIndex, MachineBasicBlock*> IdxMBBPair;
305 
306  inline bool operator<(SlotIndex V, const IdxMBBPair &IM) {
307  return V < IM.first;
308  }
309 
310  inline bool operator<(const IdxMBBPair &IM, SlotIndex V) {
311  return IM.first < V;
312  }
313 
314  struct Idx2MBBCompare {
315  bool operator()(const IdxMBBPair &LHS, const IdxMBBPair &RHS) const {
316  return LHS.first < RHS.first;
317  }
318  };
319 
320  /// SlotIndexes pass.
321  ///
322  /// This pass assigns indexes to each instruction.
324  private:
325  // IndexListEntry allocator.
326  BumpPtrAllocator ileAllocator;
327 
329  IndexList indexList;
330 
331 #ifdef EXPENSIVE_CHECKS
332  IndexList graveyardList;
333 #endif // EXPENSIVE_CHECKS
334 
335  MachineFunction *mf;
336 
338  Mi2IndexMap mi2iMap;
339 
340  /// MBBRanges - Map MBB number to (start, stop) indexes.
342 
343  /// Idx2MBBMap - Sorted list of pairs of index of first instruction
344  /// and MBB id.
345  SmallVector<IdxMBBPair, 8> idx2MBBMap;
346 
347  IndexListEntry* createEntry(MachineInstr *mi, unsigned index) {
348  IndexListEntry *entry =
349  static_cast<IndexListEntry *>(ileAllocator.Allocate(
350  sizeof(IndexListEntry), alignof(IndexListEntry)));
351 
352  new (entry) IndexListEntry(mi, index);
353 
354  return entry;
355  }
356 
357  /// Renumber locally after inserting curItr.
359 
360  public:
361  static char ID;
362 
365  }
366 
367  ~SlotIndexes() override {
368  // The indexList's nodes are all allocated in the BumpPtrAllocator.
369  indexList.clearAndLeakNodesUnsafely();
370  }
371 
372  void getAnalysisUsage(AnalysisUsage &au) const override;
373  void releaseMemory() override;
374 
375  bool runOnMachineFunction(MachineFunction &fn) override;
376 
377  /// Dump the indexes.
378  void dump() const;
379 
380  /// Renumber the index list, providing space for new instructions.
381  void renumberIndexes();
382 
383  /// Repair indexes after adding and removing instructions.
387 
388  /// Returns the zero index for this analysis.
390  assert(indexList.front().getIndex() == 0 && "First index is not 0?");
391  return SlotIndex(&indexList.front(), 0);
392  }
393 
394  /// Returns the base index of the last slot in this analysis.
396  return SlotIndex(&indexList.back(), 0);
397  }
398 
399  /// Returns true if the given machine instr is mapped to an index,
400  /// otherwise returns false.
401  bool hasIndex(const MachineInstr &instr) const {
402  return mi2iMap.count(&instr);
403  }
404 
405  /// Returns the base index for the given instruction.
407  // Instructions inside a bundle have the same number as the bundle itself.
408  const MachineInstr &BundleStart = *getBundleStart(MI.getIterator());
409  Mi2IndexMap::const_iterator itr = mi2iMap.find(&BundleStart);
410  assert(itr != mi2iMap.end() && "Instruction not found in maps.");
411  return itr->second;
412  }
413 
414  /// Returns the instruction for the given index, or null if the given
415  /// index has no instruction associated with it.
417  return index.isValid() ? index.listEntry()->getInstr() : nullptr;
418  }
419 
420  /// Returns the next non-null index, if one exists.
421  /// Otherwise returns getLastIndex().
423  IndexList::iterator I = Index.listEntry()->getIterator();
424  IndexList::iterator E = indexList.end();
425  while (++I != E)
426  if (I->getInstr())
427  return SlotIndex(&*I, Index.getSlot());
428  // We reached the end of the function.
429  return getLastIndex();
430  }
431 
432  /// getIndexBefore - Returns the index of the last indexed instruction
433  /// before MI, or the start index of its basic block.
434  /// MI is not required to have an index.
436  const MachineBasicBlock *MBB = MI.getParent();
437  assert(MBB && "MI must be inserted inna basic block");
439  for (;;) {
440  if (I == B)
441  return getMBBStartIdx(MBB);
442  --I;
443  Mi2IndexMap::const_iterator MapItr = mi2iMap.find(&*I);
444  if (MapItr != mi2iMap.end())
445  return MapItr->second;
446  }
447  }
448 
449  /// getIndexAfter - Returns the index of the first indexed instruction
450  /// after MI, or the end index of its basic block.
451  /// MI is not required to have an index.
453  const MachineBasicBlock *MBB = MI.getParent();
454  assert(MBB && "MI must be inserted inna basic block");
456  for (;;) {
457  ++I;
458  if (I == E)
459  return getMBBEndIdx(MBB);
460  Mi2IndexMap::const_iterator MapItr = mi2iMap.find(&*I);
461  if (MapItr != mi2iMap.end())
462  return MapItr->second;
463  }
464  }
465 
466  /// Return the (start,end) range of the given basic block number.
467  const std::pair<SlotIndex, SlotIndex> &
468  getMBBRange(unsigned Num) const {
469  return MBBRanges[Num];
470  }
471 
472  /// Return the (start,end) range of the given basic block.
473  const std::pair<SlotIndex, SlotIndex> &
475  return getMBBRange(MBB->getNumber());
476  }
477 
478  /// Returns the first index in the given basic block number.
479  SlotIndex getMBBStartIdx(unsigned Num) const {
480  return getMBBRange(Num).first;
481  }
482 
483  /// Returns the first index in the given basic block.
485  return getMBBRange(mbb).first;
486  }
487 
488  /// Returns the last index in the given basic block number.
489  SlotIndex getMBBEndIdx(unsigned Num) const {
490  return getMBBRange(Num).second;
491  }
492 
493  /// Returns the last index in the given basic block.
495  return getMBBRange(mbb).second;
496  }
497 
498  /// Iterator over the idx2MBBMap (sorted pairs of slot index of basic block
499  /// begin and basic block)
501  /// Move iterator to the next IdxMBBPair where the SlotIndex is greater or
502  /// equal to \p To.
504  return std::lower_bound(I, idx2MBBMap.end(), To);
505  }
506  /// Get an iterator pointing to the IdxMBBPair with the biggest SlotIndex
507  /// that is greater or equal to \p Idx.
509  return advanceMBBIndex(idx2MBBMap.begin(), Idx);
510  }
511  /// Returns an iterator for the begin of the idx2MBBMap.
513  return idx2MBBMap.begin();
514  }
515  /// Return an iterator for the end of the idx2MBBMap.
517  return idx2MBBMap.end();
518  }
519 
520  /// Returns the basic block which the given index falls in.
523  return MI->getParent();
524 
526  // Take the pair containing the index
527  MBBIndexIterator J =
528  ((I != MBBIndexEnd() && I->first > index) ||
529  (I == MBBIndexEnd() && !idx2MBBMap.empty())) ? std::prev(I) : I;
530 
531  assert(J != MBBIndexEnd() && J->first <= index &&
532  index < getMBBEndIdx(J->second) &&
533  "index does not correspond to an MBB");
534  return J->second;
535  }
536 
537  /// Returns the MBB covering the given range, or null if the range covers
538  /// more than one basic block.
540 
541  assert(start < end && "Backwards ranges not allowed.");
542  MBBIndexIterator itr = findMBBIndex(start);
543  if (itr == MBBIndexEnd()) {
544  itr = std::prev(itr);
545  return itr->second;
546  }
547 
548  // Check that we don't cross the boundary into this block.
549  if (itr->first < end)
550  return nullptr;
551 
552  itr = std::prev(itr);
553 
554  if (itr->first <= start)
555  return itr->second;
556 
557  return nullptr;
558  }
559 
560  /// Insert the given machine instruction into the mapping. Returns the
561  /// assigned index.
562  /// If Late is set and there are null indexes between mi's neighboring
563  /// instructions, create the new index after the null indexes instead of
564  /// before them.
566  assert(!MI.isInsideBundle() &&
567  "Instructions inside bundles should use bundle start's slot.");
568  assert(mi2iMap.find(&MI) == mi2iMap.end() && "Instr already indexed.");
569  // Numbering DBG_VALUE instructions could cause code generation to be
570  // affected by debug information.
571  assert(!MI.isDebugValue() && "Cannot number DBG_VALUE instructions.");
572 
573  assert(MI.getParent() != nullptr && "Instr must be added to function.");
574 
575  // Get the entries where MI should be inserted.
576  IndexList::iterator prevItr, nextItr;
577  if (Late) {
578  // Insert MI's index immediately before the following instruction.
579  nextItr = getIndexAfter(MI).listEntry()->getIterator();
580  prevItr = std::prev(nextItr);
581  } else {
582  // Insert MI's index immediately after the preceding instruction.
583  prevItr = getIndexBefore(MI).listEntry()->getIterator();
584  nextItr = std::next(prevItr);
585  }
586 
587  // Get a number for the new instr, or 0 if there's no room currently.
588  // In the latter case we'll force a renumber later.
589  unsigned dist = ((nextItr->getIndex() - prevItr->getIndex())/2) & ~3u;
590  unsigned newNumber = prevItr->getIndex() + dist;
591 
592  // Insert a new list entry for MI.
593  IndexList::iterator newItr =
594  indexList.insert(nextItr, createEntry(&MI, newNumber));
595 
596  // Renumber locally if we need to.
597  if (dist == 0)
598  renumberIndexes(newItr);
599 
600  SlotIndex newIndex(&*newItr, SlotIndex::Slot_Block);
601  mi2iMap.insert(std::make_pair(&MI, newIndex));
602  return newIndex;
603  }
604 
605  /// Remove the given machine instruction from the mapping.
607  // remove index -> MachineInstr and
608  // MachineInstr -> index mappings
609  Mi2IndexMap::iterator mi2iItr = mi2iMap.find(&MI);
610  if (mi2iItr != mi2iMap.end()) {
611  IndexListEntry *miEntry(mi2iItr->second.listEntry());
612  assert(miEntry->getInstr() == &MI && "Instruction indexes broken.");
613  // FIXME: Eventually we want to actually delete these indexes.
614  miEntry->setInstr(nullptr);
615  mi2iMap.erase(mi2iItr);
616  }
617  }
618 
619  /// ReplaceMachineInstrInMaps - Replacing a machine instr with a new one in
620  /// maps used by register allocator. \returns the index where the new
621  /// instruction was inserted.
623  Mi2IndexMap::iterator mi2iItr = mi2iMap.find(&MI);
624  if (mi2iItr == mi2iMap.end())
625  return SlotIndex();
626  SlotIndex replaceBaseIndex = mi2iItr->second;
627  IndexListEntry *miEntry(replaceBaseIndex.listEntry());
628  assert(miEntry->getInstr() == &MI &&
629  "Mismatched instruction in index tables.");
630  miEntry->setInstr(&NewMI);
631  mi2iMap.erase(mi2iItr);
632  mi2iMap.insert(std::make_pair(&NewMI, replaceBaseIndex));
633  return replaceBaseIndex;
634  }
635 
636  /// Add the given MachineBasicBlock into the maps.
638  MachineFunction::iterator nextMBB =
639  std::next(MachineFunction::iterator(mbb));
640 
641  IndexListEntry *startEntry = nullptr;
642  IndexListEntry *endEntry = nullptr;
643  IndexList::iterator newItr;
644  if (nextMBB == mbb->getParent()->end()) {
645  startEntry = &indexList.back();
646  endEntry = createEntry(nullptr, 0);
647  newItr = indexList.insertAfter(startEntry->getIterator(), endEntry);
648  } else {
649  startEntry = createEntry(nullptr, 0);
650  endEntry = getMBBStartIdx(&*nextMBB).listEntry();
651  newItr = indexList.insert(endEntry->getIterator(), startEntry);
652  }
653 
654  SlotIndex startIdx(startEntry, SlotIndex::Slot_Block);
655  SlotIndex endIdx(endEntry, SlotIndex::Slot_Block);
656 
657  MachineFunction::iterator prevMBB(mbb);
658  assert(prevMBB != mbb->getParent()->end() &&
659  "Can't insert a new block at the beginning of a function.");
660  --prevMBB;
661  MBBRanges[prevMBB->getNumber()].second = startIdx;
662 
663  assert(unsigned(mbb->getNumber()) == MBBRanges.size() &&
664  "Blocks must be added in order");
665  MBBRanges.push_back(std::make_pair(startIdx, endIdx));
666  idx2MBBMap.push_back(IdxMBBPair(startIdx, mbb));
667 
668  renumberIndexes(newItr);
669  std::sort(idx2MBBMap.begin(), idx2MBBMap.end(), Idx2MBBCompare());
670  }
671 
672  /// \brief Free the resources that were required to maintain a SlotIndex.
673  ///
674  /// Once an index is no longer needed (for instance because the instruction
675  /// at that index has been moved), the resources required to maintain the
676  /// index can be relinquished to reduce memory use and improve renumbering
677  /// performance. Any remaining SlotIndex objects that point to the same
678  /// index are left 'dangling' (much the same as a dangling pointer to a
679  /// freed object) and should not be accessed, except to destruct them.
680  ///
681  /// Like dangling pointers, access to dangling SlotIndexes can cause
682  /// painful-to-track-down bugs, especially if the memory for the index
683  /// previously pointed to has been re-used. To detect dangling SlotIndex
684  /// bugs, build with EXPENSIVE_CHECKS=1. This will cause "erased" indexes to
685  /// be retained in a graveyard instead of being freed. Operations on indexes
686  /// in the graveyard will trigger an assertion.
687  void eraseIndex(SlotIndex index) {
688  IndexListEntry *entry = index.listEntry();
689 #ifdef EXPENSIVE_CHECKS
690  indexList.remove(entry);
691  graveyardList.push_back(entry);
692  entry->setPoison();
693 #else
694  indexList.erase(entry);
695 #endif
696  }
697  };
698 
699  // Specialize IntervalMapInfo for half-open slot index intervals.
700  template <>
702  };
703 
704 } // end namespace llvm
705 
706 #endif // LLVM_CODEGEN_SLOTINDEXES_H
bool isInsideBundle() const
Return true if MI is in a bundle (but not the first MI in a bundle).
Definition: MachineInstr.h:217
void push_back(const T &Elt)
Definition: SmallVector.h:211
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
~SlotIndexes() override
Definition: SlotIndexes.h:367
MBBIndexIterator advanceMBBIndex(MBBIndexIterator I, SlotIndex To) const
Move iterator to the next IdxMBBPair where the SlotIndex is greater or equal to To.
Definition: SlotIndexes.h:503
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:241
void renumberIndexes()
Renumber the index list, providing space for new instructions.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
std::pair< SlotIndex, MachineBasicBlock * > IdxMBBPair
Definition: SlotIndexes.h:304
SlotIndex getInstructionIndex(const MachineInstr &MI) const
Returns the base index for the given instruction.
Definition: SlotIndexes.h:406
iterator erase(iterator where)
Definition: ilist.h:280
SlotIndex getBoundaryIndex() const
Returns the boundary index for associated with this index.
Definition: SlotIndexes.h:241
int getInstrDistance(SlotIndex other) const
Return the scaled distance from this index to the given one, where all slots on the same instruction ...
Definition: SlotIndexes.h:213
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
Definition: SlotIndexes.h:234
int distance(SlotIndex other) const
Return the distance from this index to the given one.
Definition: SlotIndexes.h:207
MachineInstr * getInstr() const
Definition: SlotIndexes.h:46
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:452
MBBIndexIterator MBBIndexBegin() const
Returns an iterator for the begin of the idx2MBBMap.
Definition: SlotIndexes.h:512
void removeMachineInstrFromMaps(MachineInstr &MI)
Remove the given machine instruction from the mapping.
Definition: SlotIndexes.h:606
bool operator==(SlotIndex other) const
Compare two SlotIndex objects for equality.
Definition: SlotIndexes.h:158
static const bool value
Definition: type_traits.h:48
bool isRegister() const
isRegister - Returns true if this is a normal register use/def slot.
Definition: SlotIndexes.h:226
MBBIndexIterator findMBBIndex(SlotIndex Idx) const
Get an iterator pointing to the IdxMBBPair with the biggest SlotIndex that is greater or equal to Idx...
Definition: SlotIndexes.h:508
bool isEarlyClobber() const
isEarlyClobber - Returns true if this is an early-clobber slot.
Definition: SlotIndexes.h:222
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
void dump() const
Dump this index to stderr.
Custom traits to do nothing on deletion.
Definition: ilist.h:57
static bool isEarlierInstr(SlotIndex A, SlotIndex B)
isEarlierInstr - Return true if A refers to an instruction earlier than B.
Definition: SlotIndexes.h:196
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:172
SlotIndex getLastIndex()
Returns the base index of the last slot in this analysis.
Definition: SlotIndexes.h:395
bool operator>=(SlotIndex other) const
Compare two SlotIndex objects.
Definition: SlotIndexes.h:185
bool operator>(SlotIndex other) const
Compare two SlotIndex objects.
Definition: SlotIndexes.h:179
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void dump() const
Dump the indexes.
bool hasIndex(const MachineInstr &instr) const
Returns true if the given machine instr is mapped to an index, otherwise returns false.
Definition: SlotIndexes.h:401
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:32
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
Definition: SlotIndexes.h:219
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
Definition: SlotIndexes.h:252
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:435
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:60
SlotIndex getNextNonNullIndex(SlotIndex Index)
Returns the next non-null index, if one exists.
Definition: SlotIndexes.h:422
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
Definition: SlotIndexes.h:229
void eraseIndex(SlotIndex index)
Free the resources that were required to maintain a SlotIndex.
Definition: SlotIndexes.h:687
SlotIndexes pass.
Definition: SlotIndexes.h:323
MachineBasicBlock::instr_iterator getBundleStart(MachineBasicBlock::instr_iterator I)
Returns an iterator to the first instruction in the bundle containing I.
MachineBasicBlock * MBB
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
bool operator!=(SlotIndex other) const
Compare two SlotIndex objects for inequality.
Definition: SlotIndexes.h:162
SlotIndex getPrevIndex() const
Returns the previous index.
Definition: SlotIndexes.h:292
void setIndex(unsigned index)
Definition: SlotIndexes.h:52
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
Definition: SlotIndexes.h:282
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:131
bool isDebugValue() const
Definition: MachineInstr.h:777
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
Definition: SlotIndexes.h:565
Use delete by default for iplist and ilist.
Definition: ilist.h:41
unsigned getIndex() const
Definition: SlotIndexes.h:51
bool erase(const KeyT &Val)
Definition: DenseMap.h:243
bool operator<=(SlotIndex other) const
Compare two SlotIndex objects.
Definition: SlotIndexes.h:173
void initializeSlotIndexesPass(PassRegistry &)
bool isValid() const
Returns true if this is a valid index.
Definition: SlotIndexes.h:144
The default distance between instructions as returned by distance().
Definition: SlotIndexes.h:130
SlotIndex(const SlotIndex &li, Slot s)
Definition: SlotIndexes.h:137
bool operator<(SlotIndex other) const
Compare two SlotIndex objects.
Definition: SlotIndexes.h:168
void insertMBBInMaps(MachineBasicBlock *mbb)
Add the given MachineBasicBlock into the maps.
Definition: SlotIndexes.h:637
PointerIntPair - This class implements a pair of a pointer and small integer.
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:138
MBBIndexIterator MBBIndexEnd() const
Return an iterator for the end of the idx2MBBMap.
Definition: SlotIndexes.h:516
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:115
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:212
bool operator()(const IdxMBBPair &LHS, const IdxMBBPair &RHS) const
Definition: SlotIndexes.h:315
Represent the analysis usage information of a pass.
SlotIndex getZeroIndex()
Returns the zero index for this analysis.
Definition: SlotIndexes.h:389
static const unsigned End
self_iterator getIterator()
Definition: ilist_node.h:81
void setInstr(MachineInstr *mi)
Definition: SlotIndexes.h:47
An intrusive list with ownership and callbacks specified/controlled by ilist_traits, only with API safe for polymorphic types.
Definition: ilist.h:403
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:416
isPodLike - This is a type trait that is used to determine whether a given type can be copied around ...
Definition: ArrayRef.h:507
Iterator for intrusive lists based on ilist_node.
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
Definition: SlotIndexes.h:190
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
Definition: SlotIndexes.h:521
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Returns the last index in the given basic block.
Definition: SlotIndexes.h:494
MachineBasicBlock * getMBBCoveringRange(SlotIndex start, SlotIndex end) const
Returns the MBB covering the given range, or null if the range covers more than one basic block...
Definition: SlotIndexes.h:539
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:122
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
Definition: SlotIndexes.h:489
IndexListEntry(MachineInstr *mi, unsigned index)
Definition: SlotIndexes.h:44
void repairIndexesInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End)
Repair indexes after adding and removing instructions.
void getAnalysisUsage(AnalysisUsage &au) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: SlotIndexes.cpp:28
SlotIndex getNextIndex() const
Returns the next index.
Definition: SlotIndexes.h:272
void print(raw_ostream &os) const
Print this index to the given raw_ostream.
Representation of each machine instruction.
Definition: MachineInstr.h:52
pointer remove(iterator &IT)
Definition: ilist.h:264
static char ID
Definition: SlotIndexes.h:361
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:119
iterator insert(iterator where, pointer New)
Definition: ilist.h:241
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:202
This class represents an entry in the slot index list held in the SlotIndexes pass.
Definition: SlotIndexes.h:38
bool runOnMachineFunction(MachineFunction &fn) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition: SlotIndexes.cpp:41
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Definition: SlotIndexes.cpp:33
#define I(x, y, z)
Definition: MD5.cpp:54
SlotIndex()
Construct an invalid index.
Definition: SlotIndexes.h:134
iterator end()
Definition: DenseMap.h:69
iterator find(const KeyT &Val)
Definition: DenseMap.h:127
SmallVectorImpl< IdxMBBPair >::const_iterator MBBIndexIterator
Iterator over the idx2MBBMap (sorted pairs of slot index of basic block begin and basic block) ...
Definition: SlotIndexes.h:500
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
Definition: SlotIndexes.h:479
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:1726
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:247
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator<(int64_t V1, const APSInt &V2)
Definition: APSInt.h:326
const std::pair< SlotIndex, SlotIndex > & getMBBRange(const MachineBasicBlock *MBB) const
Return the (start,end) range of the given basic block.
Definition: SlotIndexes.h:474
void clearAndLeakNodesUnsafely()
Remove all nodes from the list like clear(), but do not call removeNodeFromList() or deleteNode()...
Definition: ilist.h:293
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
IRTranslator LLVM IR MI
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Returns the first index in the given basic block.
Definition: SlotIndexes.h:484
SlotIndex getNextSlot() const
Returns the next slot in the index list.
Definition: SlotIndexes.h:262
iterator insertAfter(iterator where, pointer New)
Definition: ilist.h:250
SlotIndex - An opaque wrapper around machine indexes.
Definition: SlotIndexes.h:76
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
SlotIndex replaceMachineInstrInMaps(MachineInstr &MI, MachineInstr &NewMI)
ReplaceMachineInstrInMaps - Replacing a machine instr with a new one in maps used by register allocat...
Definition: SlotIndexes.h:622
const std::pair< SlotIndex, SlotIndex > & getMBBRange(unsigned Num) const
Return the (start,end) range of the given basic block number.
Definition: SlotIndexes.h:468