13 #include "llvm/Config/llvm-config.h" 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.isDebugInstr())
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));
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 LLVM_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 renumberIndexes()
Renumber the index list, providing space for new instructions.
This class represents lattice values for constants.
void removeSingleMachineInstrFromMaps(MachineInstr &MI)
Removes a single machine instruction MI from the mapping.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
bool isBundledWithPred() const
Return true if this instruction is part of a bundle, and it is not the first instruction in the bundl...
void push_back(const T &Elt)
void removeMachineInstrFromMaps(MachineInstr &MI)
Removes machine instruction (bundle) MI from the mapping.
STATISTIC(NumFunctions, "Total number of functions")
void reserve(size_type N)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it...
bool isBundledWithSucc() const
Return true if this instruction is part of a bundle, and it is not the last instruction in the bundle...
SlotIndex getInstructionIndex(const MachineInstr &MI) const
Returns the base index for the given instruction.
iterator find(const_arg_type_t< KeyT > Val)
void dump() const
Dump this index to stderr.
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
MachineInstr * getInstr() const
bool erase(const KeyT &Val)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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.
std::pair< SlotIndex, MachineBasicBlock * > IdxMBBPair
self_iterator getIterator()
void setInstr(MachineInstr *mi)
void dump() const
Dump the indexes.
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
bool isDebugInstr() const
void sort(IteratorTy Start, IteratorTy End)
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.
void push_back(pointer val)
void repairIndexesInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End)
Repair indexes after adding and removing instructions.
Representation of each machine instruction.
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...
LLVM_NODISCARD bool empty() const
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
INITIALIZE_PASS(SlotIndexes, DEBUG_TYPE, "Slot index numbering", false, false) STATISTIC(NumLocalRenum
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...
The default distance between instructions as returned by distance().
void print(raw_ostream &os) const
Print this index to the given raw_ostream.
SlotIndex - An opaque wrapper around machine indexes.
Number of local renumberings