12#include "llvm/Config/llvm-config.h"
19#define DEBUG_TYPE "slotindexes"
32 OS <<
"Slot indexes in machine function: " << MF.
getName() <<
'\n';
57void SlotIndexes::clear() {
81 assert(indexList.
empty() &&
"Index list non-empty at initial numbering?");
83 "Index -> MBB mapping non-empty at initial numbering?");
84 assert(MBBRanges.empty() &&
85 "MBB -> Index mapping non-empty at initial numbering?");
87 "MachineInstr -> Index mapping non-empty at initial numbering?");
93 indexList.
push_back(*createEntry(
nullptr, index));
98 SlotIndex blockStartIndex(&indexList.
back(), SlotIndex::Slot_Block);
101 if (
MI.isDebugOrPseudoInstr())
108 mi2iMap.
insert(std::make_pair(
117 SlotIndex::Slot_Block);
129 assert((AllowBundled || !
MI.isBundledWithPred()) &&
130 "Use removeSingleMachineInstrFromMaps() instead");
132 if (mi2iItr == mi2iMap.
end())
138 mi2iMap.
erase(mi2iItr);
145 if (mi2iItr == mi2iMap.
end())
151 mi2iMap.
erase(mi2iItr);
155 if (
MI.isBundledWithSucc()) {
157 assert(!
MI.isBundledWithPred() &&
"Should be first bundle instruction");
162 mi2iMap.
insert(std::make_pair(&NextMI, MIIndex));
172void SlotIndexes::renumberIndexes(IndexList::iterator curItr) {
175 static_assert((Space & 3) == 0,
"InstrDist must be a multiple of 2*NUM");
178 unsigned index = startItr->getIndex();
180 curItr->setIndex(index += Space);
183 }
while (curItr != indexList.
end() && curItr->getIndex() <= index);
185 LLVM_DEBUG(
dbgs() <<
"\n*** Renumbered SlotIndexes " << startItr->getIndex()
186 <<
'-' << index <<
" ***\n");
194 bool includeStart = (Begin ==
MBB->
begin());
214 bool pastStart =
false;
215 while (ListI != ListB ||
MBBI != Begin || (includeStart && !pastStart)) {
216 assert(ListI->getIndex() >= startIdx.getIndex() &&
217 (includeStart || !pastStart) &&
218 "Decremented past the beginning of region to repair.");
222 bool MBBIAtBegin =
MBBI == Begin && (!includeStart || pastStart);
224 if (SlotMI ==
MI && !MBBIAtBegin) {
247 if (!
MI.isDebugOrPseudoInstr() && !mi2iMap.
contains(&
MI))
259 OS << ILE.getIndex() <<
' ';
262 OS << *ILE.getInstr();
267 for (
unsigned i = 0, e = MBBRanges.size(); i != e; ++i)
268 OS <<
"%bb." << i <<
"\t[" << MBBRanges[i].first <<
';'
269 << MBBRanges[i].second <<
")\n";
272#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
279 os << listEntry()->
getIndex() <<
"Berd"[getSlot()];
284#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)
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
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...
Instructions::iterator instr_iterator
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.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
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...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
SlotIndex - An opaque wrapper around machine indexes.
bool isValid() const
Returns true if this is a valid index.
@ InstrDist
The default distance between instructions as returned by distance().
void dump() const
Dump this index to stderr.
void print(raw_ostream &os) const
Print this index to the given raw_ostream.
Result run(MachineFunction &MF, MachineFunctionAnalysisManager &)
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
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.
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 print(raw_ostream &OS) const
void reserve(size_type N)
void push_back(const T &Elt)
self_iterator getIterator()
This class implements an extremely fast bulk output stream that can only output to a stream.
void clear()
Clear the list; never deletes.
typename ilist_select_iterator_type< OptionsT::has_iterator_bits, OptionsT, false, false >::type iterator
bool empty() const
Check if the list is empty in constant time.
void push_back(reference Node)
Insert a node at the back; never copies.
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 tuples (A, B,...
std::pair< SlotIndex, MachineBasicBlock * > IdxMBBPair
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)
void sort(IteratorTy Start, IteratorTy End)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void initializeSlotIndexesWrapperPassPass(PassRegistry &)
A special type used by analysis passes to provide an address that identifies that particular analysis...
Function object to check whether the first component of a container supported by std::get (like std::...