18 #ifndef LLVM_CODEGEN_SLOTINDEXES_H 19 #define LLVM_CODEGEN_SLOTINDEXES_H 63 #ifdef EXPENSIVE_CHECKS 69 assert(((tmp & 0x1) == 0x0) &&
"Pointer already poisoned?");
74 bool isPoisoned()
const {
return (reinterpret_cast<intptr_t>(mi) & 0x1) == 0x1; }
75 #endif // EXPENSIVE_CHECKS 113 : lie(entry, slot) {}
115 IndexListEntry* listEntry()
const {
116 assert(isValid() &&
"Attempt to compare reserved index.");
117 #ifdef EXPENSIVE_CHECKS 119 "Attempt to access deleted list-entry.");
120 #endif // EXPENSIVE_CHECKS 125 return listEntry()->getIndex() | getSlot();
129 Slot getSlot()
const {
130 return static_cast<Slot
>(lie.
getInt());
137 InstrDist = 4 * Slot_Count
146 "Attempt to construct index with 0 pointer.");
156 explicit operator bool()
const {
return isValid(); }
166 return lie == other.lie;
170 return lie != other.lie;
176 return getIndex() < other.getIndex();
181 return getIndex() <= other.getIndex();
187 return getIndex() > other.getIndex();
193 return getIndex() >= other.getIndex();
198 return A.lie.getPointer() == B.lie.getPointer();
210 return !isEarlierInstr(B, A);
215 return other.getIndex() -
getIndex();
221 return (other.listEntry()->
getIndex() - listEntry()->getIndex())
226 bool isBlock()
const {
return getSlot() == Slot_Block; }
233 bool isRegister()
const {
return getSlot() == Slot_Register; }
236 bool isDead()
const {
return getSlot() == Slot_Dead; }
242 return SlotIndex(listEntry(), Slot_Block);
249 return SlotIndex(listEntry(), Slot_Dead);
255 return SlotIndex(listEntry(), EC ? Slot_EarlyClobber : Slot_Register);
260 return SlotIndex(listEntry(), Slot_Dead);
271 if (s == Slot_Dead) {
291 if (s == Slot_Block) {
309 using IdxMBBPair = std::pair<SlotIndex, MachineBasicBlock *>;
334 IndexListEntry* createEntry(
MachineInstr *mi,
unsigned index) {
335 IndexListEntry *
entry =
336 static_cast<IndexListEntry *
>(ileAllocator.
Allocate(
337 sizeof(IndexListEntry),
alignof(IndexListEntry)));
345 void renumberIndexes(IndexList::iterator curItr);
355 void releaseMemory()
override;
369 assert(indexList.front().getIndex() == 0 &&
"First index is not 0?");
381 return mi2iMap.
count(&instr);
392 assert(!BundleNonDebug.isDebugInstr() &&
393 "Could not use a debug instruction to query mi2iMap.");
395 assert(itr != mi2iMap.
end() &&
"Instruction not found in maps.");
408 IndexList::iterator
I = Index.listEntry()->
getIterator();
409 IndexList::iterator
E = indexList.end();
414 return getLastIndex();
422 assert(MBB &&
"MI must be inserted in a basic block");
426 return getMBBStartIdx(MBB);
429 if (MapItr != mi2iMap.
end())
430 return MapItr->second;
439 assert(MBB &&
"MI must be inserted in a basic block");
444 return getMBBEndIdx(MBB);
446 if (MapItr != mi2iMap.
end())
447 return MapItr->second;
452 const std::pair<SlotIndex, SlotIndex> &
454 return MBBRanges[Num];
458 const std::pair<SlotIndex, SlotIndex> &
465 return getMBBRange(Num).first;
470 return getMBBRange(mbb).first;
475 return getMBBRange(Num).second;
480 return getMBBRange(mbb).second;
492 [=](
const IdxMBBPair &IM) {
return IM.first < To; });
498 return advanceMBBIndex(idx2MBBMap.
begin(), Idx);
503 return idx2MBBMap.
begin();
508 return idx2MBBMap.
end();
514 return MI->getParent();
519 ((I != MBBIndexEnd() && I->first > index) ||
520 (I == MBBIndexEnd() && !idx2MBBMap.
empty())) ? std::prev(I) :
I;
522 assert(J != MBBIndexEnd() && J->first <= index &&
523 index < getMBBEndIdx(J->second) &&
524 "index does not correspond to an MBB");
535 "Instructions inside bundles should use bundle start's slot.");
536 assert(mi2iMap.
find(&MI) == mi2iMap.
end() &&
"Instr already indexed.");
541 assert(MI.
getParent() !=
nullptr &&
"Instr must be added to function.");
544 IndexList::iterator prevItr, nextItr;
547 nextItr = getIndexAfter(MI).listEntry()->getIterator();
548 prevItr = std::prev(nextItr);
551 prevItr = getIndexBefore(MI).listEntry()->getIterator();
552 nextItr = std::next(prevItr);
557 unsigned dist = ((nextItr->getIndex() - prevItr->getIndex())/2) & ~3u;
558 unsigned newNumber = prevItr->getIndex() + dist;
561 IndexList::iterator newItr =
562 indexList.
insert(nextItr, createEntry(&MI, newNumber));
566 renumberIndexes(newItr);
568 SlotIndex newIndex(&*newItr, SlotIndex::Slot_Block);
569 mi2iMap.
insert(std::make_pair(&MI, newIndex));
581 void removeSingleMachineInstrFromMaps(
MachineInstr &MI);
588 if (mi2iItr == mi2iMap.
end())
590 SlotIndex replaceBaseIndex = mi2iItr->second;
591 IndexListEntry *miEntry(replaceBaseIndex.listEntry());
592 assert(miEntry->getInstr() == &MI &&
593 "Mismatched instruction in index tables.");
594 miEntry->setInstr(&NewMI);
595 mi2iMap.
erase(mi2iItr);
596 mi2iMap.
insert(std::make_pair(&NewMI, replaceBaseIndex));
597 return replaceBaseIndex;
605 IndexListEntry *startEntry =
nullptr;
606 IndexListEntry *endEntry =
nullptr;
607 IndexList::iterator newItr;
609 startEntry = &indexList.back();
610 endEntry = createEntry(
nullptr, 0);
613 startEntry = createEntry(
nullptr, 0);
614 endEntry = getMBBStartIdx(&*nextMBB).listEntry();
618 SlotIndex startIdx(startEntry, SlotIndex::Slot_Block);
619 SlotIndex endIdx(endEntry, SlotIndex::Slot_Block);
623 "Can't insert a new block at the beginning of a function.");
625 MBBRanges[prevMBB->getNumber()].second = startIdx;
628 "Blocks must be added in order");
629 MBBRanges.
push_back(std::make_pair(startIdx, endIdx));
632 renumberIndexes(newItr);
644 #endif // LLVM_CODEGEN_SLOTINDEXES_H
bool isRegister() const
isRegister - Returns true if this is a normal register use/def slot.
MBBIndexIterator advanceMBBIndex(MBBIndexIterator I, SlotIndex To) const
Move iterator to the next IdxMBBPair where the SlotIndex is greater or equal to To.
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
This class represents lattice values for constants.
PointerTy getPointer() const
SlotIndex getPrevIndex() const
Returns the previous index.
void push_back(const T &Elt)
MBBIndexIterator MBBIndexEnd() const
Return an iterator for the end of the idx2MBBMap.
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
bool operator<(SlotIndex other) const
Compare two SlotIndex objects.
bool isValid() const
Returns true if this is a valid index.
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
Custom traits to do nothing on deletion.
static bool isEarlierInstr(SlotIndex A, SlotIndex B)
isEarlierInstr - Return true if A refers to an instruction earlier than B.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
SlotIndex getLastIndex()
Returns the base index of the last slot in this analysis.
bool operator<=(SlotIndex other) const
Compare two SlotIndex objects.
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.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
SlotIndex getInstructionIndex(const MachineInstr &MI) const
Returns the base index for the given instruction.
SmallVectorImpl< IdxMBBPair >::const_iterator MBBIndexIterator
Iterator over the idx2MBBMap (sorted pairs of slot index of basic block begin and basic block) ...
SlotIndex getNextNonNullIndex(SlotIndex Index)
Returns the next non-null index, if one exists.
auto partition_point(R &&Range, Predicate P) -> decltype(adl_begin(Range))
Binary search for the first iterator in a range where a predicate is false.
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def...
MachineBasicBlock::instr_iterator getBundleStart(MachineBasicBlock::instr_iterator I)
Returns an iterator to the first instruction in the bundle containing I.
SlotIndex getIndexAfter(const MachineInstr &MI) const
getIndexAfter - Returns the index of the first indexed instruction after MI, or the end index of its ...
SlotIndex getNextSlot() const
Returns the next slot in the index list.
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Returns the first index in the given basic block.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
bool isInsideBundle() const
Return true if MI is in a bundle (but not the first MI in a bundle).
void setIndex(unsigned index)
BasicBlockListType::iterator iterator
bool operator==(SlotIndex other) const
Compare two SlotIndex objects for equality.
iterator find(const_arg_type_t< KeyT > Val)
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
MachineInstr * getInstr() const
Use delete by default for iplist and ilist.
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction for the given index, or null if the given index has no instruction associated...
bool erase(const KeyT &Val)
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Returns the last index in the given basic block.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
SlotIndex(const SlotIndex &li, Slot s)
void insertMBBInMaps(MachineBasicBlock *mbb)
Add the given MachineBasicBlock into the maps.
PointerIntPair - This class implements a pair of a pointer and small integer.
bool operator!=(SlotIndex other) const
Compare two SlotIndex objects for inequality.
Allocate memory in an ever growing pool, as if by bump-pointer.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
unsigned getIndex() const
SlotIndex getIndexBefore(const MachineInstr &MI) const
getIndexBefore - Returns the index of the last indexed instruction before MI, or the start index of i...
bool hasIndex(const MachineInstr &instr) const
Returns true if the given machine instr is mapped to an index, otherwise returns false.
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
Represent the analysis usage information of a pass.
int getInstrDistance(SlotIndex other) const
Return the scaled distance from this index to the given one, where all slots on the same instruction ...
std::pair< SlotIndex, MachineBasicBlock * > IdxMBBPair
SlotIndex getZeroIndex()
Returns the zero index for this analysis.
MBBIndexIterator MBBIndexBegin() const
Returns an iterator for the begin of the idx2MBBMap.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
self_iterator getIterator()
void setInstr(MachineInstr *mi)
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
bool isDebugInstr() const
An intrusive list with ownership and callbacks specified/controlled by ilist_traits, only with API safe for polymorphic types.
void sort(IteratorTy Start, IteratorTy End)
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool operator>(SlotIndex other) const
Compare two SlotIndex objects.
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
IndexListEntry(MachineInstr *mi, unsigned index)
bool isEarlyClobber() const
isEarlyClobber - Returns true if this is an early-clobber slot.
IterT skipDebugInstructionsForward(IterT It, IterT End)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator...
const MachineBasicBlock * getParent() const
bool operator>=(SlotIndex other) const
Compare two SlotIndex objects.
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator insert(iterator where, pointer New)
static bool isEarlierEqualInstr(SlotIndex A, SlotIndex B)
Return true if A refers to the same instruction as B or an earlier one.
This class represents an entry in the slot index list held in the SlotIndexes pass.
const std::pair< SlotIndex, SlotIndex > & getMBBRange(const MachineBasicBlock *MBB) const
Return the (start,end) range of the given basic block.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
LLVM_NODISCARD bool empty() const
int distance(SlotIndex other) const
Return the distance from this index to the given one.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
MBBIndexIterator findMBBIndex(SlotIndex Idx) const
Get an iterator pointing to the IdxMBBPair with the biggest SlotIndex that is greater or equal to Idx...
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
const std::pair< SlotIndex, SlotIndex > & getMBBRange(unsigned Num) const
Return the (start,end) range of the given basic block number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class implements an extremely fast bulk output stream that can only output to a stream...
print Instructions which execute on loop entry
void print(raw_ostream &os) const
Print this index to the given raw_ostream.
MachineBasicBlock::instr_iterator getBundleEnd(MachineBasicBlock::instr_iterator I)
Returns an iterator pointing beyond the bundle containing I.
iterator insertAfter(iterator where, pointer New)
SlotIndex - An opaque wrapper around machine indexes.
Function object to check whether the first component of a std::pair compares less than the first comp...
SlotIndex getBoundaryIndex() const
Returns the boundary index for associated with this index.
SlotIndex replaceMachineInstrInMaps(MachineInstr &MI, MachineInstr &NewMI)
ReplaceMachineInstrInMaps - Replacing a machine instr with a new one in maps used by register allocat...