12#include "llvm/Config/llvm-config.h"
19#define DEBUG_TYPE "slotindexes"
32 OS <<
"Slot indexes in machine function: " << MF.
getName() <<
'\n';
48STATISTIC(NumLocalRenum,
"Number of local renumberings");
55void SlotIndexes::clear() {
79 assert(indexList.
empty() &&
"Index list non-empty at initial numbering?");
81 "Index -> MBB mapping non-empty at initial numbering?");
82 assert(MBBRanges.empty() &&
83 "MBB -> Index mapping non-empty at initial numbering?");
85 "MachineInstr -> Index mapping non-empty at initial numbering?");
91 indexList.
push_back(*createEntry(
nullptr, index));
96 SlotIndex blockStartIndex(&indexList.
back(), SlotIndex::Slot_Block);
99 if (
MI.isDebugOrPseudoInstr())
106 mi2iMap.
insert(std::make_pair(
115 SlotIndex(&indexList.back(), SlotIndex::Slot_Block);
127 assert((AllowBundled || !
MI.isBundledWithPred()) &&
128 "Use removeSingleMachineInstrFromMaps() instead");
130 if (mi2iItr == mi2iMap.end())
136 mi2iMap.erase(mi2iItr);
143 if (mi2iItr == mi2iMap.end())
149 mi2iMap.erase(mi2iItr);
153 if (
MI.isBundledWithSucc()) {
155 assert(!
MI.isBundledWithPred() &&
"Should be first bundle instruction");
160 mi2iMap.insert(std::make_pair(&NextMI, MIIndex));
170 "Can't remove the first block of a function.");
172 unsigned Num =
MBB.getAnalysisNumber();
173 SlotIndex StartIdx = MBBRanges[Num].first;
174 SlotIndex EndIdx = MBBRanges[Num].second;
177 auto PrevMBB = std::prev(
MBB.getIterator());
178 MBBRanges[PrevMBB->getAnalysisNumber()].second = EndIdx;
183 "MBB not found in index -> MBB map");
184 idx2MBBMap.erase(It);
188 StartIdx.listEntry()->
setInstr(
nullptr);
193void SlotIndexes::renumberIndexes(IndexList::iterator curItr) {
196 static_assert((Space & 3) == 0,
"InstrDist must be a multiple of 2*NUM");
199 unsigned index = startItr->getIndex();
200 unsigned BeginIndex = index;
202 curItr->setIndex(index += Space);
205 }
while (curItr != indexList.
end() && curItr->getIndex() <= index);
207 LLVM_DEBUG(
dbgs() <<
"\n*** Renumbered SlotIndexes " << startItr->getIndex()
208 <<
'-' << index <<
" ***\n");
213 if (index - BeginIndex >
224 bool includeStart = (Begin ==
MBB->begin());
232 if (End ==
MBB->end())
244 bool pastStart =
false;
245 bool OldIndexesRemoved =
false;
246 while (ListI != ListB ||
MBBI != Begin || (includeStart && !pastStart)) {
247 assert(ListI->getIndex() >= startIdx.getIndex() &&
248 (includeStart || !pastStart) &&
249 "Decremented past the beginning of region to repair.");
253 bool MBBIAtBegin =
MBBI == Begin && (!includeStart || pastStart);
254 bool MIIndexNotFound =
MI && !mi2iMap.contains(
MI);
255 bool SlotMIRemoved =
false;
257 if (SlotMI ==
MI && !MBBIAtBegin) {
263 }
else if (MIIndexNotFound || OldIndexesRemoved) {
273 OldIndexesRemoved =
true;
278 SlotMIRemoved =
true;
285 if ((MIIndexNotFound || SlotMIRemoved) && InstrToInsert->
getParent() &&
292 for (
auto [Index, Entry] :
enumerate(indexList))
298 OS << ILE.getIndex() <<
' ';
301 OS << *ILE.getInstr();
311#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
318 os << listEntry()->getIndex() <<
"Berd"[getSlot()];
323#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
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.
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
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
int getAnalysisNumber() const
For analyses, blocks have a more stable number.
Instructions::iterator instr_iterator
MachineInstrBundleIterator< MachineInstr > iterator
MachineFunctionPass(char &ID)
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 getMaxAnalysisBlockNumber() const
Representation of each machine instruction.
const MachineBasicBlock * getParent() const
bool isDebugOrPseudoInstr() const
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.
@ InstrDist
The default distance between instructions as returned by distance().
bool isValid() const
Returns true if this is a valid index.
LLVM_ABI void dump() const
Dump this index to stderr.
LLVM_ABI void print(raw_ostream &os) const
Print this index to the given raw_ostream.
LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &)
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
void getAnalysisUsage(AnalysisUsage &au) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
SlotIndex getLastIndex()
Returns the base index of the last slot in this analysis.
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
LLVM_ABI void removeMachineInstrFromMaps(MachineInstr &MI, bool AllowBundled=false)
Removes machine instruction (bundle) MI from the mapping.
LLVM_ABI void dump() const
Dump the indexes.
LLVM_ABI void repairIndexesInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End)
Repair indexes after adding and removing instructions.
MBBIndexIterator getMBBLowerBound(MBBIndexIterator Start, SlotIndex Idx) const
Get an iterator pointing to the first IdxMBBPair with SlotIndex greater than or equal to Idx.
LLVM_ABI void removeSingleMachineInstrFromMaps(MachineInstr &MI)
Removes a single machine instruction MI from the mapping.
MBBIndexIterator MBBIndexEnd() const
Return an iterator for the end of the idx2MBBMap.
SlotIndex getInstructionIndex(const MachineInstr &MI, bool IgnoreBundle=false) const
Returns the base index for the given instruction.
LLVM_ABI void packIndexes()
Renumber all indexes using the default instruction distance.
LLVM_ABI void removeMBBFromMaps(MachineBasicBlock &MBB)
Inverse of insertMBBInMaps: merge MBB's slot range into its layout predecessor and drop it from the m...
LLVM_ABI void print(raw_ostream &OS) const
SlotIndex getZeroIndex()
Returns the zero index for this analysis.
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Returns the index past the last valid index in the given basic block.
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Returns the first index in the given basic block.
void reserve(size_type N)
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.
bool empty() const
Check if the list is empty in constant time.
ilist_select_iterator_type< OptionsT, false, false > iterator
void push_back(reference Node)
Insert a node at the back; never copies.
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
std::pair< SlotIndex, MachineBasicBlock * > IdxMBBPair
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
A special type used by analysis passes to provide an address that identifies that particular analysis...