LLVM: lib/CodeGen/SlotIndexes.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
12#include "llvm/Config/llvm-config.h"
16
17using namespace llvm;
18
19#define DEBUG_TYPE "slotindexes"
20
22
28
32 OS << "Slot indexes in machine function: " << MF.getName() << '\n';
35}
37
41
43
44 indexList.clear();
45}
46
48 false, false)
49
50STATISTIC(NumLocalRenum, "Number of local renumberings");
51
53 au.setPreservesAll();
55}
56
57void SlotIndexes::clear() {
59 MBBRanges.clear();
60 idx2MBBMap.clear();
61 indexList.clear();
62 ileAllocator.Reset();
63}
64
66
67
68
69
70
71
72
73
74
75
76
77
78 mf = &fn;
79
80
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?");
88
89 unsigned index = 0;
92
93 indexList.push_back(*createEntry(nullptr, index));
94
95
97
98 SlotIndex blockStartIndex(&indexList.back(), SlotIndex::Slot_Block);
99
101 if (MI.isDebugOrPseudoInstr())
102 continue;
103
104
106
107
108 mi2iMap.insert(std::make_pair(
109 &MI, SlotIndex(&indexList.back(), SlotIndex::Slot_Block)));
110 }
111
112
114
115 MBBRanges[MBB.getNumber()].first = blockStartIndex;
116 MBBRanges[MBB.getNumber()].second = SlotIndex(&indexList.back(),
117 SlotIndex::Slot_Block);
118 idx2MBBMap.push_back(IdxMBBPair(blockStartIndex, &MBB));
119 }
120
121
122 llvm::sort(idx2MBBMap, less_first());
123
125}
126
128 bool AllowBundled) {
129 assert((AllowBundled || .isBundledWithPred()) &&
130 "Use removeSingleMachineInstrFromMaps() instead");
132 if (mi2iItr == mi2iMap.end())
133 return;
134
135 SlotIndex MIIndex = mi2iItr->second;
137 assert(MIEntry.getInstr() == &MI && "Instruction indexes broken.");
138 mi2iMap.erase(mi2iItr);
139
141}
142
145 if (mi2iItr == mi2iMap.end())
146 return;
147
148 SlotIndex MIIndex = mi2iItr->second;
150 assert(MIEntry.getInstr() == &MI && "Instruction indexes broken.");
151 mi2iMap.erase(mi2iItr);
152
153
154
155 if (MI.isBundledWithSucc()) {
156
157 assert(.isBundledWithPred() && "Should be first bundle instruction");
158
162 mi2iMap.insert(std::make_pair(&NextMI, MIIndex));
163 return;
164 } else {
165
167 }
168}
169
170
171
172void SlotIndexes::renumberIndexes(IndexList::iterator curItr) {
173
175 static_assert((Space & 3) == 0, "InstrDist must be a multiple of 2*NUM");
176
178 unsigned index = startItr->getIndex();
179 do {
180 curItr->setIndex(index += Space);
181 ++curItr;
182
183 } while (curItr != indexList.end() && curItr->getIndex() <= index);
184
185 LLVM_DEBUG(dbgs() << "\n*** Renumbered SlotIndexes " << startItr->getIndex()
186 << '-' << index << " ***\n");
187 ++NumLocalRenum;
188}
189
190
194 bool includeStart = (Begin == MBB->begin());
196 if (includeStart)
198 else
200
202 if (End == MBB->end())
204 else
206
207
208
209
210
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.");
220
223 bool MBBIAtBegin = MBBI == Begin && (!includeStart || pastStart);
224 bool MIIndexNotFound = MI && !mi2iMap.contains(MI);
225 bool SlotMIRemoved = false;
226
227 if (SlotMI == MI && !MBBIAtBegin) {
228 --ListI;
229 if (MBBI != Begin)
231 else
232 pastStart = true;
233 } else if (MIIndexNotFound || OldIndexesRemoved) {
234 if (MBBI != Begin)
236 else
237 pastStart = true;
238 } else {
239
240
241
242 if (ListI == ListB)
243 OldIndexesRemoved = true;
244 else
245 --ListI;
246 if (SlotMI) {
248 SlotMIRemoved = true;
249 }
250 }
251
252 MachineInstr *InstrToInsert = SlotMIRemoved ? SlotMI : MI;
253
254
255 if ((MIIndexNotFound || SlotMIRemoved) && InstrToInsert->getParent() &&
258 }
259}
260
262 for (auto [Index, Entry] : enumerate(indexList))
264}
265
268 OS << ILE.getIndex() << ' ';
269
270 if (ILE.getInstr())
271 OS << *ILE.getInstr();
272 else
273 OS << '\n';
274 }
275
276 for (unsigned i = 0, e = MBBRanges.size(); i != e; ++i)
277 OS << "%bb." << i << "\t[" << MBBRanges[i].first << ';'
278 << MBBRanges[i].second << ")\n";
279}
280
281#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
283#endif
284
285
288 os << listEntry()->getIndex() << "Berd"[getSlot()];
289 else
290 os << "invalid";
291}
292
293#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
294
299#endif
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 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.
Definition SlotIndexes.cpp:295
LLVM_ABI void print(raw_ostream &os) const
Print this index to the given raw_ostream.
Definition SlotIndexes.cpp:286
LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &)
Definition SlotIndexes.cpp:24
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Definition SlotIndexes.cpp:30
SlotIndexesWrapperPass()
Definition SlotIndexes.cpp:38
void getAnalysisUsage(AnalysisUsage &au) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition SlotIndexes.cpp:52
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.
Definition SlotIndexes.cpp:127
LLVM_ABI void dump() const
Dump the indexes.
Definition SlotIndexes.cpp:282
LLVM_ABI void repairIndexesInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End)
Repair indexes after adding and removing instructions.
Definition SlotIndexes.cpp:191
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the index past the last valid index in the given basic block.
LLVM_ABI void removeSingleMachineInstrFromMaps(MachineInstr &MI)
Removes a single machine instruction MI from the mapping.
Definition SlotIndexes.cpp:143
SlotIndex getInstructionIndex(const MachineInstr &MI, bool IgnoreBundle=false) const
Returns the base index for the given instruction.
LLVM_ABI ~SlotIndexes()
Definition SlotIndexes.cpp:42
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.
Definition SlotIndexes.cpp:261
LLVM_ABI void print(raw_ostream &OS) const
Definition SlotIndexes.cpp:266
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
LLVM_ABI void initializeSlotIndexesWrapperPassPass(PassRegistry &)
FunctionAddr VTableAddr Next
A special type used by analysis passes to provide an address that identifies that particular analysis...