12#include "llvm/Config/llvm-config.h"
19#define DEBUG_TYPE "slotindexes"
32 OS <<
"Slot indexes in machine function: " << MF.
getName() <<
'\n';
50STATISTIC(NumLocalRenum,
"Number of local renumberings");
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(
116 MBBRanges[
MBB.
getNumber()].second = SlotIndex(&indexList.back(),
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());
202 if (End ==
MBB->end())
214 bool pastStart =
false;
215 bool OldIndexesRemoved =
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);
224 bool MIIndexNotFound =
MI && !mi2iMap.contains(
MI);
225 bool SlotMIRemoved =
false;
227 if (SlotMI ==
MI && !MBBIAtBegin) {
233 }
else if (MIIndexNotFound || OldIndexesRemoved) {
243 OldIndexesRemoved =
true;
248 SlotMIRemoved =
true;
255 if ((MIIndexNotFound || SlotMIRemoved) && InstrToInsert->
getParent() &&
262 for (
auto [Index, Entry] :
enumerate(indexList))
268 OS << ILE.getIndex() <<
' ';
271 OS << *ILE.getInstr();
276 for (
unsigned i = 0, e = MBBRanges.size(); i != e; ++i)
277 OS <<
"%bb." << i <<
"\t[" << MBBRanges[i].first <<
';'
278 << MBBRanges[i].second <<
")\n";
281#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
288 os << listEntry()->getIndex() <<
"Berd"[getSlot()];
293#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.
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it,...
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 getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
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 getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
Representation of each machine instruction.
const MachineBasicBlock * getParent() const
bool isDebugOrPseudoInstr() const
static LLVM_ABI 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.
@ 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 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.
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
LLVM_ABI 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.
LLVM_ABI void packIndexes()
Renumber all indexes using the default instruction distance.
LLVM_ABI void print(raw_ostream &OS) const
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.
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.
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
LLVM_ABI void initializeSlotIndexesWrapperPassPass(PassRegistry &)
FunctionAddr VTableAddr Next
A special type used by analysis passes to provide an address that identifies that particular analysis...