12#include "llvm/Config/llvm-config.h"
19#define DEBUG_TYPE "slotindexes"
33 "Slot index numbering",
false,
false)
66 assert(indexList.empty() &&
"Index list non-empty at initial numbering?");
68 "Index -> MBB mapping non-empty at initial numbering?");
69 assert(MBBRanges.empty() &&
70 "MBB -> Index mapping non-empty at initial numbering?");
72 "MachineInstr -> Index mapping non-empty at initial numbering?");
78 indexList.
push_back(createEntry(
nullptr, index));
83 SlotIndex blockStartIndex(&indexList.back(), SlotIndex::Slot_Block);
86 if (
MI.isDebugOrPseudoInstr())
93 mi2iMap.
insert(std::make_pair(
94 &
MI,
SlotIndex(&indexList.back(), SlotIndex::Slot_Block)));
102 SlotIndex::Slot_Block);
117 assert((AllowBundled || !
MI.isBundledWithPred()) &&
118 "Use removeSingleMachineInstrFromMaps() instead");
120 if (mi2iItr == mi2iMap.
end())
126 mi2iMap.
erase(mi2iItr);
133 if (mi2iItr == mi2iMap.
end())
139 mi2iMap.
erase(mi2iItr);
143 if (
MI.isBundledWithSucc()) {
145 assert(!
MI.isBundledWithPred() &&
"Should be first bundle instruction");
150 mi2iMap.
insert(std::make_pair(&NextMI, MIIndex));
160void SlotIndexes::renumberIndexes(IndexList::iterator curItr) {
163 static_assert((Space & 3) == 0,
"InstrDist must be a multiple of 2*NUM");
166 unsigned index = startItr->getIndex();
168 curItr->setIndex(index += Space);
171 }
while (curItr != indexList.end() && curItr->getIndex() <= index);
173 LLVM_DEBUG(
dbgs() <<
"\n*** Renumbered SlotIndexes " << startItr->getIndex()
174 <<
'-' << index <<
" ***\n");
182 bool includeStart = (Begin ==
MBB->
begin());
202 bool pastStart =
false;
203 while (ListI != ListB ||
MBBI != Begin || (includeStart && !pastStart)) {
204 assert(ListI->getIndex() >= startIdx.getIndex() &&
205 (includeStart || !pastStart) &&
206 "Decremented past the beginning of region to repair.");
210 bool MBBIAtBegin =
MBBI == Begin && (!includeStart || pastStart);
212 if (SlotMI ==
MI && !MBBIAtBegin) {
235 if (!
MI.isDebugOrPseudoInstr() && !mi2iMap.
contains(&
MI))
245#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
248 dbgs() << ILE.getIndex() <<
" ";
250 if (ILE.getInstr()) {
251 dbgs() << *ILE.getInstr();
257 for (
unsigned i = 0, e = MBBRanges.size(); i != e; ++i)
258 dbgs() <<
"%bb." << i <<
"\t[" << MBBRanges[i].first <<
';'
259 << MBBRanges[i].second <<
")\n";
266 os << listEntry()->
getIndex() <<
"Berd"[getSlot()];
271#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
MachineBasicBlock MachineBasicBlock::iterator MBBI
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Represent the analysis usage information of a pass.
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it,...
iterator find(const_arg_type_t< KeyT > Val)
bool erase(const KeyT &Val)
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
This class represents an entry in the slot index list held in the SlotIndexes pass.
void setInstr(MachineInstr *mi)
MachineInstr * getInstr() const
unsigned getIndex() const
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
Representation of each machine instruction.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
SlotIndex - An opaque wrapper around machine indexes.
@ InstrDist
The default distance between instructions as returned by distance().
bool isValid() const
Returns true if this is a valid index.
void dump() const
Dump this index to stderr.
void print(raw_ostream &os) const
Print this index to the given raw_ostream.
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
void removeMachineInstrFromMaps(MachineInstr &MI, bool AllowBundled=false)
Removes machine instruction (bundle) MI from the mapping.
void dump() const
Dump the indexes.
void repairIndexesInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End)
Repair indexes after adding and removing instructions.
bool runOnMachineFunction(MachineFunction &fn) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
void removeSingleMachineInstrFromMaps(MachineInstr &MI)
Removes a single machine instruction MI from the mapping.
SlotIndex getInstructionIndex(const MachineInstr &MI, bool IgnoreBundle=false) const
Returns the base index for the given instruction.
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
void packIndexes()
Renumber all indexes using the default instruction distance.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
void reserve(size_type N)
void push_back(const T &Elt)
Iterator for intrusive lists based on ilist_node.
self_iterator getIterator()
void push_back(pointer val)
base_list_type::iterator iterator
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.
This is an optimization pass for GlobalISel generic memory operations.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
std::pair< SlotIndex, MachineBasicBlock * > IdxMBBPair
void sort(IteratorTy Start, IteratorTy End)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void initializeSlotIndexesPass(PassRegistry &)
Function object to check whether the first component of a container supported by std::get (like std::...