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?");
58 assert(idx2MBBMap.
empty() &&
59 "Index -> MBB mapping non-empty at initial numbering?");
60 assert(MBBRanges.empty() &&
61 "MBB -> Index mapping non-empty at initial numbering?");
62 assert(mi2iMap.
empty() &&
63 "MachineInstr -> Index mapping non-empty at initial numbering?");
69 indexList.
push_back(createEntry(
nullptr, index));
73 mbbItr != mbbEnd; ++mbbItr) {
77 SlotIndex blockStartIndex(&indexList.
back(), SlotIndex::Slot_Block);
80 miItr != miEnd; ++miItr) {
90 SlotIndex::Slot_Block)));
96 MBBRanges[mbb->
getNumber()].first = blockStartIndex;
98 SlotIndex::Slot_Block);
113 DEBUG(
dbgs() <<
"\n*** Renumbering SlotIndexes ***\n");
130 static_assert((Space & 3) == 0,
"InstrDist must be a multiple of 2*NUM");
133 unsigned index = startItr->getIndex();
135 curItr->setIndex(index += Space);
138 }
while (curItr != indexList.
end() && curItr->getIndex() <= index);
140 DEBUG(
dbgs() <<
"\n*** Renumbered SlotIndexes " << startItr->getIndex() <<
'-'
141 << index <<
" ***\n");
158 bool includeStart = (Begin == MBB->
begin());
166 if (End == MBB->
end())
178 bool pastStart =
false;
179 while (ListI != ListB || MBBI != Begin || (includeStart && !pastStart)) {
180 assert(ListI->getIndex() >= startIdx.getIndex() &&
181 (includeStart || !pastStart) &&
182 "Decremented past the beginning of region to repair.");
186 bool MBBIAtBegin = MBBI == Begin && (!includeStart || pastStart);
188 if (SlotMI == MI && !MBBIAtBegin) {
194 }
else if (MI && mi2iMap.
find(MI) == mi2iMap.
end()) {
216 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
219 itr != indexList.
end(); ++itr) {
220 dbgs() << itr->getIndex() <<
" ";
222 if (itr->getInstr()) {
223 dbgs() << *itr->getInstr();
229 for (
unsigned i = 0, e = MBBRanges.size(); i != e; ++i)
230 dbgs() <<
"BB#" << i <<
"\t[" << MBBRanges[i].first <<
';'
231 << MBBRanges[i].second <<
")\n";
238 os << listEntry()->
getIndex() <<
"Berd"[getSlot()];
243 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void push_back(const T &Elt)
void renumberIndexes()
Renumber the index list, providing space for new instructions.
std::pair< SlotIndex, MachineBasicBlock * > IdxMBBPair
STATISTIC(NumFunctions,"Total number of functions")
iplist< IndexListEntry >::iterator iterator
int getNumber() const
getNumber - MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a M...
void reserve(size_type N)
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...
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
void print(raw_ostream &OS, SlotIndexes *=nullptr) const
print - Print out the MachineFunction in a format suitable for debugging to the specified stream...
The default distance between instructions as returned by distance().
bool isDebugValue() const
bundle_iterator< MachineInstr, instr_iterator > iterator
unsigned getIndex() const
bool isValid() const
Returns true if this is a valid index.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
void dump() const
Dump the indexes.
SlotIndex getInstructionIndex(const MachineInstr *MI) const
Returns the base index for the given instruction.
bool hasIndex(const MachineInstr *instr) const
Returns true if the given machine instr is mapped to an index, otherwise returns false.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
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 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.
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...
void dump() const
Dump this index to stderr.
iterator find(const KeyT &Val)
void removeMachineInstrFromMaps(MachineInstr *mi)
Remove the given machine instruction from the mapping.
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
BasicBlockListType::iterator iterator
This class implements an extremely fast bulk output stream that can only output to a stream...
INITIALIZE_PASS(SlotIndexes,"slotindexes","Slot index numbering", false, false) STATISTIC(NumLocalRenum
SlotIndex - An opaque wrapper around machine indexes.
SlotIndex insertMachineInstrInMaps(MachineInstr *mi, bool Late=false)
Insert the given machine instruction into the mapping.
Number of local renumberings
void push_back(const NodeTy &val)