19 #ifndef LLVM_CODEGEN_SLOTINDEXES_H
20 #define LLVM_CODEGEN_SLOTINDEXES_H
56 #ifdef EXPENSIVE_CHECKS
62 assert(((tmp & 0x1) == 0x0) &&
"Pointer already poisoned?");
67 bool isPoisoned()
const {
return (reinterpret_cast<intptr_t>(mi) & 0x1) == 0x1; }
68 #endif // EXPENSIVE_CHECKS
106 : lie(entry, slot) {}
108 IndexListEntry* listEntry()
const {
110 #ifdef EXPENSIVE_CHECKS
111 assert(!lie.getPointer()->isPoisoned() &&
112 "Attempt to access deleted list-entry.");
113 #endif // EXPENSIVE_CHECKS
114 return lie.getPointer();
117 unsigned getIndex()
const {
118 return listEntry()->
getIndex() | getSlot();
122 Slot getSlot()
const {
123 return static_cast<Slot
>(lie.getInt());
138 assert(lie.getPointer() !=
nullptr &&
139 "Attempt to construct index with 0 pointer.");
145 return lie.getPointer();
159 return lie == other.lie;
163 return lie != other.lie;
169 return getIndex() < other.getIndex();
174 return getIndex() <= other.getIndex();
180 return getIndex() > other.getIndex();
186 return getIndex() >= other.getIndex();
191 return A.lie.getPointer() == B.lie.getPointer();
208 return other.getIndex() - getIndex();
219 bool isBlock()
const {
return getSlot() == Slot_Block; }
226 bool isRegister()
const {
return getSlot() == Slot_Register; }
229 bool isDead()
const {
return getSlot() == Slot_Dead; }
235 return SlotIndex(listEntry(), Slot_Block);
242 return SlotIndex(listEntry(), Slot_Dead);
248 return SlotIndex(listEntry(), EC ? Slot_EarlyClobber : Slot_Register);
253 return SlotIndex(listEntry(), Slot_Dead);
264 if (s == Slot_Dead) {
265 return SlotIndex(&*++listEntry()->getIterator(), Slot_Block);
273 return SlotIndex(&*++listEntry()->getIterator(), getSlot());
284 if (s == Slot_Block) {
285 return SlotIndex(&*--listEntry()->getIterator(), Slot_Dead);
293 return SlotIndex(&*--listEntry()->getIterator(), getSlot());
316 return LHS.first < RHS.first;
331 #ifdef EXPENSIVE_CHECKS
333 #endif // EXPENSIVE_CHECKS
390 assert(indexList.front().getIndex() == 0 &&
"First index is not 0?");
402 return mi2iMap.
count(&instr);
410 assert(itr != mi2iMap.
end() &&
"Instruction not found in maps.");
437 assert(MBB &&
"MI must be inserted inna basic block");
444 if (MapItr != mi2iMap.
end())
445 return MapItr->second;
454 assert(MBB &&
"MI must be inserted inna basic block");
461 if (MapItr != mi2iMap.
end())
462 return MapItr->second;
467 const std::pair<SlotIndex, SlotIndex> &
469 return MBBRanges[Num];
473 const std::pair<SlotIndex, SlotIndex> &
504 return std::lower_bound(I, idx2MBBMap.
end(), To);
513 return idx2MBBMap.
begin();
517 return idx2MBBMap.
end();
523 return MI->getParent();
533 "index does not correspond to an MBB");
541 assert(start < end &&
"Backwards ranges not allowed.");
544 itr = std::prev(itr);
549 if (itr->first < end)
552 itr = std::prev(itr);
554 if (itr->first <= start)
567 "Instructions inside bundles should use bundle start's slot.");
568 assert(mi2iMap.
find(&MI) == mi2iMap.
end() &&
"Instr already indexed.");
573 assert(MI.
getParent() !=
nullptr &&
"Instr must be added to function.");
580 prevItr = std::prev(nextItr);
584 nextItr = std::next(prevItr);
589 unsigned dist = ((nextItr->getIndex() - prevItr->getIndex())/2) & ~3u;
590 unsigned newNumber = prevItr->getIndex() + dist;
594 indexList.
insert(nextItr, createEntry(&MI, newNumber));
600 SlotIndex newIndex(&*newItr, SlotIndex::Slot_Block);
601 mi2iMap.
insert(std::make_pair(&MI, newIndex));
610 if (mi2iItr != mi2iMap.
end()) {
612 assert(miEntry->getInstr() == &MI &&
"Instruction indexes broken.");
614 miEntry->setInstr(
nullptr);
615 mi2iMap.
erase(mi2iItr);
624 if (mi2iItr == mi2iMap.
end())
626 SlotIndex replaceBaseIndex = mi2iItr->second;
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;
645 startEntry = &indexList.back();
646 endEntry = createEntry(
nullptr, 0);
649 startEntry = createEntry(
nullptr, 0);
654 SlotIndex startIdx(startEntry, SlotIndex::Slot_Block);
655 SlotIndex endIdx(endEntry, SlotIndex::Slot_Block);
659 "Can't insert a new block at the beginning of a function.");
661 MBBRanges[prevMBB->getNumber()].second = startIdx;
664 "Blocks must be added in order");
665 MBBRanges.push_back(std::make_pair(startIdx, endIdx));
689 #ifdef EXPENSIVE_CHECKS
691 graveyardList.push_back(entry);
694 indexList.
erase(entry);
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).
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MBBIndexIterator advanceMBBIndex(MBBIndexIterator I, SlotIndex To) const
Move iterator to the next IdxMBBPair where the SlotIndex is greater or equal to To.
const_iterator end(StringRef path)
Get end iterator over path.
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
SlotIndex getInstructionIndex(const MachineInstr &MI) const
Returns the base index for the given instruction.
iterator erase(iterator where)
SlotIndex getBoundaryIndex() const
Returns the boundary index for associated with this index.
int getInstrDistance(SlotIndex other) const
Return the scaled distance from this index to the given one, where all slots on the same instruction ...
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.
int distance(SlotIndex other) const
Return the distance from this index to the given one.
MachineInstr * getInstr() const
SlotIndex getIndexAfter(const MachineInstr &MI) const
getIndexAfter - Returns the index of the first indexed instruction after MI, or the end index of its ...
MBBIndexIterator MBBIndexBegin() const
Returns an iterator for the begin of the idx2MBBMap.
void removeMachineInstrFromMaps(MachineInstr &MI)
Remove the given machine instruction from the mapping.
bool operator==(SlotIndex other) const
Compare two SlotIndex objects for equality.
bool isRegister() const
isRegister - Returns true if this is a normal register use/def slot.
MBBIndexIterator findMBBIndex(SlotIndex Idx) const
Get an iterator pointing to the IdxMBBPair with the biggest SlotIndex that is greater or equal to Idx...
bool isEarlyClobber() const
isEarlyClobber - Returns true if this is an early-clobber slot.
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
void dump() const
Dump this index to stderr.
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 operator>(SlotIndex other) const
Compare two SlotIndex objects.
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.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
SlotIndex getIndexBefore(const MachineInstr &MI) const
getIndexBefore - Returns the index of the last indexed instruction before MI, or the start index of i...
LLVM_NODISCARD bool empty() const
SlotIndex getNextNonNullIndex(SlotIndex Index)
Returns the next non-null index, if one exists.
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
void eraseIndex(SlotIndex index)
Free the resources that were required to maintain a SlotIndex.
MachineBasicBlock::instr_iterator getBundleStart(MachineBasicBlock::instr_iterator I)
Returns an iterator to the first instruction in the bundle containing I.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
bool operator!=(SlotIndex other) const
Compare two SlotIndex objects for inequality.
SlotIndex getPrevIndex() const
Returns the previous index.
void setIndex(unsigned index)
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
const MachineBasicBlock * getParent() const
bool isDebugValue() const
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
Use delete by default for iplist and ilist.
unsigned getIndex() const
bool erase(const KeyT &Val)
bool operator<=(SlotIndex other) const
Compare two SlotIndex objects.
void initializeSlotIndexesPass(PassRegistry &)
bool isValid() const
Returns true if this is a valid index.
The default distance between instructions as returned by distance().
SlotIndex(const SlotIndex &li, Slot s)
bool operator<(SlotIndex other) const
Compare two SlotIndex objects.
void insertMBBInMaps(MachineBasicBlock *mbb)
Add the given MachineBasicBlock into the maps.
PointerIntPair - This class implements a pair of a pointer and small integer.
Allocate memory in an ever growing pool, as if by bump-pointer.
MBBIndexIterator MBBIndexEnd() const
Return an iterator for the end of the idx2MBBMap.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
bool operator()(const IdxMBBPair &LHS, const IdxMBBPair &RHS) const
Represent the analysis usage information of a pass.
SlotIndex getZeroIndex()
Returns the zero index for this analysis.
static const unsigned End
self_iterator getIterator()
void setInstr(MachineInstr *mi)
An intrusive list with ownership and callbacks specified/controlled by ilist_traits, only with API safe for polymorphic types.
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction for the given index, or null if the given index has no instruction associated...
isPodLike - This is a type trait that is used to determine whether a given type can be copied around ...
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.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Returns the last index in the given basic block.
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...
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
IndexListEntry(MachineInstr *mi, unsigned index)
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.
SlotIndex getNextIndex() const
Returns the next index.
void print(raw_ostream &os) const
Print this index to the given raw_ostream.
Representation of each machine instruction.
pointer remove(iterator &IT)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
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.
bool runOnMachineFunction(MachineFunction &fn) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
SlotIndex()
Construct an invalid index.
iterator find(const KeyT &Val)
SmallVectorImpl< IdxMBBPair >::const_iterator MBBIndexIterator
Iterator over the idx2MBBMap (sorted pairs of slot index of basic block begin and basic block) ...
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator<(int64_t V1, const APSInt &V2)
const std::pair< SlotIndex, SlotIndex > & getMBBRange(const MachineBasicBlock *MBB) const
Return the (start,end) range of the given basic block.
void clearAndLeakNodesUnsafely()
Remove all nodes from the list like clear(), but do not call removeNodeFromList() or deleteNode()...
This class implements an extremely fast bulk output stream that can only output to a stream...
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Returns the first index in the given basic block.
SlotIndex getNextSlot() const
Returns the next slot in the index list.
iterator insertAfter(iterator where, pointer New)
SlotIndex - An opaque wrapper around machine indexes.
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...
const std::pair< SlotIndex, SlotIndex > & getMBBRange(unsigned Num) const
Return the (start,end) range of the given basic block number.