18#ifndef LLVM_CODEGEN_SLOTINDEXES_H
19#define LLVM_CODEGEN_SLOTINDEXES_H
101 IndexListEntry* listEntry()
const {
107 IndexListEntry *linkedEntry()
const {
108 assert(!listEntry()->isErased() &&
109 "SlotIndex outlived the instruction it pointed at; the analysis "
110 "holding it must retire it when the instruction is erased");
114 unsigned getIndex()
const {
115 return listEntry()->getIndex() | getSlot();
119 Slot getSlot()
const {
120 return static_cast<Slot
>(lie.getInt());
135 assert(
isValid() &&
"Attempt to construct index with 0 pointer.");
141 return lie.getPointer();
155 return lie == other.lie;
159 return lie != other.lie;
165 return getIndex() < other.getIndex();
170 return getIndex() <= other.getIndex();
176 return getIndex() > other.getIndex();
182 return getIndex() >= other.getIndex();
187 return A.listEntry() ==
B.listEntry();
193 return A.listEntry()->getIndex() <
B.listEntry()->getIndex();
204 return other.getIndex() - getIndex();
214 return (other.listEntry()->
getIndex() - listEntry()->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(&*++linkedEntry()->getIterator(), Slot_Block);
273 return SlotIndex(&*++linkedEntry()->getIterator(), getSlot());
284 if (s == Slot_Block) {
285 return SlotIndex(&*--linkedEntry()->getIterator(), Slot_Dead);
293 return SlotIndex(&*--linkedEntry()->getIterator(), getSlot());
302 using IdxMBBPair = std::pair<SlotIndex, MachineBasicBlock *>;
330 SlotIndexes() =
default;
373 assert(indexList.front().getIndex() == 0 &&
"First index is not 0?");
385 return mi2iMap.count(&
instr);
390 bool IgnoreBundle =
false)
const {
399 "Could not use a debug instruction to query mi2iMap.");
401 assert(itr != mi2iMap.end() &&
"Instruction not found in maps.");
408 return index.linkedEntry()->
getInstr();
442 assert(
MBB &&
"MI must be inserted in a basic block");
448 if (
I->isDebugInstr())
451 if (MapItr != mi2iMap.end())
452 return MapItr->second;
461 assert(
MBB &&
"MI must be inserted in a basic block");
467 if (
I->isDebugInstr())
470 if (MapItr != mi2iMap.end())
471 return MapItr->second;
476 const std::pair<SlotIndex, SlotIndex> &
478 return MBBRanges[
MBB->getAnalysisNumber()];
511 return std::lower_bound(
522 return std::upper_bound(
529 return idx2MBBMap.begin();
534 return idx2MBBMap.end();
540 return MI->getParent();
545 "index does not correspond to an MBB");
556 "Instructions inside bundles should use bundle start's slot.");
557 assert(!mi2iMap.contains(&
MI) &&
"Instr already indexed.");
560 assert(!
MI.isDebugInstr() &&
"Cannot number debug instructions.");
562 assert(
MI.getParent() !=
nullptr &&
"Instr must be added to function.");
569 prevItr = std::prev(nextItr);
573 nextItr = std::next(prevItr);
578 unsigned dist = ((nextItr->getIndex() - prevItr->getIndex())/2) & ~3u;
579 unsigned newNumber = prevItr->getIndex() + dist;
583 indexList.insert(nextItr, *createEntry(&
MI, newNumber));
587 renumberIndexes(newItr);
589 SlotIndex newIndex(&*newItr, SlotIndex::Slot_Block);
590 mi2iMap.insert(std::make_pair(&
MI, newIndex));
601 bool AllowBundled =
false);
613 if (mi2iItr == mi2iMap.end())
615 SlotIndex replaceBaseIndex = mi2iItr->second;
618 "Mismatched instruction in index tables.");
620 mi2iMap.erase(mi2iItr);
621 mi2iMap.insert(std::make_pair(&NewMI, replaceBaseIndex));
622 return replaceBaseIndex;
631 "Can't insert a new block at the beginning of a function.");
641 FirstIndexed == mbb->
end()
645 indexList.insert(insEntry->
getIterator(), *startEntry);
647 SlotIndex startIdx(startEntry, SlotIndex::Slot_Block);
648 SlotIndex endIdx(endEntry, SlotIndex::Slot_Block);
650 MBBRanges[prevMBB->getAnalysisNumber()].second = startIdx;
653 "Blocks must be added in order");
654 MBBRanges.push_back(std::make_pair(startIdx, endIdx));
656 renumberIndexes(newItr);
659 return IM.first < startIdx;
661 idx2MBBMap.insert(InsertPt,
IdxMBBPair(startIdx, mbb));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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")
This file defines the DenseMap class.
This file implements a coalescing interval map for small objects.
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
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
This class represents an entry in the slot index list held in the SlotIndexes pass.
IndexListEntry(MachineInstr *mi, unsigned index)
void setInstr(MachineInstr *mi)
MachineInstr * getInstr() const
void setIndex(unsigned index)
unsigned getIndex() const
MachineInstrBundleIterator< const MachineInstr > const_iterator
int getAnalysisNumber() const
For analyses, blocks have a more stable number.
LLVM_ABI iterator getFirstNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the first non-debug instruction in the basic block, or end().
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineInstrBundleIterator< MachineInstr > iterator
MachineFunctionPass(char &ID)
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.
SlotIndex - An opaque wrapper around machine indexes.
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.
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...
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.
LLVM_ABI unsigned compactIndexes()
Erase index list entries left behind by deleted instructions, then renumber.
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 ...
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()
This class implements an extremely fast bulk output stream that can only output to a stream.
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.
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.
@ End
Run the machine verifier once, at the end of the pipeline.
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...
A CRTP mix-in for passes that should not be skipped.