19 #define DEBUG_TYPE "slotindexes"
23 "Slot index numbering",
false,
false)
26 STATISTIC(NumGlobalRenum, "Number of global renumberings");
57 assert(indexList.empty() &&
"Index list non-empty at initial numbering?");
59 "Index -> MBB mapping non-empty at initial numbering?");
60 assert(MBBRanges.empty() &&
61 "MBB -> Index mapping non-empty at initial numbering?");
63 "MachineInstr -> Index mapping non-empty at initial numbering?");
69 indexList.
push_back(createEntry(
nullptr, index));
74 SlotIndex blockStartIndex(&indexList.back(), SlotIndex::Slot_Block);
77 if (
MI.isDebugValue())
84 mi2iMap.
insert(std::make_pair(
85 &
MI,
SlotIndex(&indexList.back(), SlotIndex::Slot_Block)));
91 MBBRanges[MBB.getNumber()].first = blockStartIndex;
92 MBBRanges[MBB.getNumber()].second =
SlotIndex(&indexList.back(),
93 SlotIndex::Slot_Block);
108 "Use removeSingleMachineInstrFromMaps() instread");
110 if (mi2iItr == mi2iMap.
end())
115 assert(MIEntry.
getInstr() == &MI &&
"Instruction indexes broken.");
116 mi2iMap.
erase(mi2iItr);
123 if (mi2iItr == mi2iMap.
end())
128 assert(MIEntry.
getInstr() == &MI &&
"Instruction indexes broken.");
129 mi2iMap.
erase(mi2iItr);
140 mi2iMap.
insert(std::make_pair(&NextMI, MIIndex));
150 DEBUG(
dbgs() <<
"\n*** Renumbering SlotIndexes ***\n");
167 static_assert((Space & 3) == 0,
"InstrDist must be a multiple of 2*NUM");
170 unsigned index = startItr->getIndex();
172 curItr->setIndex(index += Space);
175 }
while (curItr != indexList.end() && curItr->getIndex() <= index);
177 DEBUG(
dbgs() <<
"\n*** Renumbered SlotIndexes " << startItr->getIndex() <<
'-'
178 << index <<
" ***\n");
195 bool includeStart = (Begin == MBB->
begin());
203 if (End == MBB->
end())
215 bool pastStart =
false;
216 while (ListI != ListB || MBBI != Begin || (includeStart && !pastStart)) {
217 assert(ListI->getIndex() >= startIdx.getIndex() &&
218 (includeStart || !pastStart) &&
219 "Decremented past the beginning of region to repair.");
223 bool MBBIAtBegin = MBBI == Begin && (!includeStart || pastStart);
225 if (SlotMI == MI && !MBBIAtBegin) {
231 }
else if (MI && mi2iMap.
find(MI) == mi2iMap.
end()) {
253 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
256 itr != indexList.end(); ++itr) {
257 dbgs() << itr->getIndex() <<
" ";
259 if (itr->getInstr()) {
260 dbgs() << *itr->getInstr();
266 for (
unsigned i = 0, e = MBBRanges.size(); i != e; ++i)
267 dbgs() <<
"BB#" << i <<
"\t[" << MBBRanges[i].first <<
';'
268 << MBBRanges[i].second <<
")\n";
275 os << listEntry()->
getIndex() <<
"Berd"[getSlot()];
280 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void push_back(const T &Elt)
void renumberIndexes()
Renumber the index list, providing space for new instructions.
SlotIndex getInstructionIndex(const MachineInstr &MI) const
Returns the base index for the given instruction.
STATISTIC(NumFunctions,"Total number of functions")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
void removeSingleMachineInstrFromMaps(MachineInstr &MI)
Removes a single machine instruction MI from the mapping.
MachineInstr * getInstr() const
void removeMachineInstrFromMaps(MachineInstr &MI)
Removes machine instruction (bundle) MI from the mapping.
void reserve(size_type N)
void dump() const
Dump this index to stderr.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it...
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.
LLVM_NODISCARD bool empty() const
bool isBundledWithSucc() const
Return true if this instruction is part of a bundle, and it is not the last instruction in the bundle...
The default distance between instructions as returned by distance().
iterator find(const_arg_type_t< KeyT > Val)
bool isDebugValue() const
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
unsigned getIndex() const
bool erase(const KeyT &Val)
bool isValid() const
Returns true if this is a valid index.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
std::pair< SlotIndex, MachineBasicBlock * > IdxMBBPair
static const unsigned End
self_iterator getIterator()
bool isBundledWithPred() const
Return true if this instruction is part of a bundle, and it is not the first instruction in the bundl...
void setInstr(MachineInstr *mi)
INITIALIZE_PASS(SlotIndexes, DEBUG_TYPE,"Slot index numbering", false, false) STATISTIC(NumLocalRenum
Iterator for intrusive lists based on ilist_node.
base_list_type::iterator iterator
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
void push_back(pointer val)
void repairIndexesInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End)
Repair indexes after adding and removing instructions.
void print(raw_ostream &os) const
Print this index to the given raw_ostream.
Representation of each machine instruction.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
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 getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
Instructions::iterator instr_iterator
LLVM_NODISCARD bool empty() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class implements an extremely fast bulk output stream that can only output to a stream...
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
SlotIndex - An opaque wrapper around machine indexes.
Number of local renumberings