19 #ifndef LLVM_CODEGEN_SLOTINDEXES_H
20 #define LLVM_CODEGEN_SLOTINDEXES_H
56 #ifdef EXPENSIVE_CHECKS
62 assert(((tmp & 0x1) == 0x0) &&
"Pointer already poisoned?");
67 bool isPoisoned()
const {
return (reinterpret_cast<intptr_t>(mi) & 0x1) == 0x1; }
68 #endif // EXPENSIVE_CHECKS
122 : lie(entry, slot) {}
124 IndexListEntry* listEntry()
const {
125 assert(
isValid() &&
"Attempt to compare reserved index.");
126 #ifdef EXPENSIVE_CHECKS
127 assert(!lie.getPointer()->isPoisoned() &&
128 "Attempt to access deleted list-entry.");
129 #endif // EXPENSIVE_CHECKS
130 return lie.getPointer();
133 unsigned getIndex()
const {
134 return listEntry()->
getIndex() | getSlot();
138 Slot getSlot()
const {
139 return static_cast<Slot
>(lie.getInt());
154 assert(lie.getPointer() != 0 &&
155 "Attempt to construct index with 0 pointer.");
161 return lie.getPointer();
175 return lie == other.lie;
179 return lie != other.lie;
185 return getIndex() < other.getIndex();
190 return getIndex() <= other.getIndex();
196 return getIndex() > other.getIndex();
202 return getIndex() >= other.getIndex();
207 return A.lie.getPointer() == B.lie.getPointer();
218 return other.getIndex() - getIndex();
229 bool isBlock()
const {
return getSlot() == Slot_Block; }
236 bool isRegister()
const {
return getSlot() == Slot_Register; }
239 bool isDead()
const {
return getSlot() == Slot_Dead; }
245 return SlotIndex(listEntry(), Slot_Block);
252 return SlotIndex(listEntry(), Slot_Dead);
258 return SlotIndex(listEntry(), EC ? Slot_EarlyClobber : Slot_Register);
263 return SlotIndex(listEntry(), Slot_Dead);
274 if (s == Slot_Dead) {
275 return SlotIndex(listEntry()->getNextNode(), Slot_Block);
283 return SlotIndex(listEntry()->getNextNode(), getSlot());
294 if (s == Slot_Block) {
295 return SlotIndex(listEntry()->getPrevNode(), Slot_Dead);
303 return SlotIndex(listEntry()->getPrevNode(), getSlot());
327 return LHS.first < RHS.first;
340 #ifdef EXPENSIVE_CHECKS
342 #endif // EXPENSIVE_CHECKS
363 alignOf<IndexListEntry>()));
398 assert(indexList.
front().
getIndex() == 0 &&
"First index is not 0?");
410 return mi2iMap.
count(instr);
417 assert(itr != mi2iMap.
end() &&
"Instruction not found in maps.");
444 assert(MBB &&
"MI must be inserted inna basic block");
451 if (MapItr != mi2iMap.
end())
452 return MapItr->second;
461 assert(MBB &&
"MI must be inserted inna basic block");
468 if (MapItr != mi2iMap.
end())
469 return MapItr->second;
474 const std::pair<SlotIndex, SlotIndex> &
476 return MBBRanges[Num];
480 const std::pair<SlotIndex, SlotIndex> &
508 return MI->getParent();
510 std::lower_bound(idx2MBBMap.
begin(), idx2MBBMap.
end(), index);
513 ((I != idx2MBBMap.
end() && I->first > index) ||
514 (I == idx2MBBMap.
end() && idx2MBBMap.
size()>0)) ? (I-1): I;
516 assert(J != idx2MBBMap.
end() && J->first <= index &&
518 "index does not correspond to an MBB");
525 std::lower_bound(idx2MBBMap.
begin(), idx2MBBMap.
end(), start);
528 while (itr != idx2MBBMap.
end()) {
529 if (itr->first >= end)
542 assert(start < end &&
"Backwards ranges not allowed.");
545 std::lower_bound(idx2MBBMap.
begin(), idx2MBBMap.
end(), start);
547 if (itr == idx2MBBMap.
end()) {
553 if (itr->first < end)
558 if (itr->first <= start)
571 "Instructions inside bundles should use bundle start's slot.");
572 assert(mi2iMap.
find(mi) == mi2iMap.
end() &&
"Instr already indexed.");
575 assert(!mi->
isDebugValue() &&
"Cannot number DBG_VALUE instructions.");
577 assert(mi->
getParent() != 0 &&
"Instr must be added to function.");
584 prevItr =
prior(nextItr);
593 unsigned dist = ((nextItr->getIndex() - prevItr->getIndex())/2) & ~3u;
594 unsigned newNumber = prevItr->getIndex() + dist;
598 indexList.
insert(nextItr, createEntry(mi, newNumber));
604 SlotIndex newIndex(&*newItr, SlotIndex::Slot_Block);
605 mi2iMap.
insert(std::make_pair(mi, newIndex));
614 if (mi2iItr != mi2iMap.
end()) {
616 assert(miEntry->getInstr() == mi &&
"Instruction indexes broken.");
619 mi2iMap.
erase(mi2iItr);
627 if (mi2iItr == mi2iMap.
end())
629 SlotIndex replaceBaseIndex = mi2iItr->second;
631 assert(miEntry->getInstr() == mi &&
632 "Mismatched instruction in index tables.");
634 mi2iMap.
erase(mi2iItr);
635 mi2iMap.
insert(std::make_pair(newMI, replaceBaseIndex));
647 startEntry = &indexList.
back();
648 endEntry = createEntry(0, 0);
649 newItr = indexList.
insertAfter(startEntry, endEntry);
651 startEntry = createEntry(0, 0);
653 newItr = indexList.
insert(endEntry, startEntry);
656 SlotIndex startIdx(startEntry, SlotIndex::Slot_Block);
657 SlotIndex endIdx(endEntry, SlotIndex::Slot_Block);
661 "Can't insert a new block at the beginning of a function.");
663 MBBRanges[prevMBB->getNumber()].second = startIdx;
665 assert(
unsigned(mbb->
getNumber()) == MBBRanges.size() &&
666 "Blocks must be added in order");
667 MBBRanges.push_back(std::make_pair(startIdx, endIdx));
691 #ifdef EXPENSIVE_CHECKS
693 graveyardList.push_back(entry);
696 indexList.
erase(entry);
710 #endif // LLVM_CODEGEN_SLOTINDEXES_H
bool isInsideBundle() const
void push_back(const T &Elt)
const MachineFunction * getParent() const
const_iterator end(StringRef path)
Get end iterator over path.
void renumberIndexes()
Renumber the index list, providing space for new instructions.
static PassRegistry * getPassRegistry()
std::pair< SlotIndex, MachineBasicBlock * > IdxMBBPair
iplist< IndexListEntry >::iterator iterator
static NodeTy * createNode(const NodeTy &V)
SlotIndex getBoundaryIndex() const
int getInstrDistance(SlotIndex other) const
virtual bool runOnMachineFunction(MachineFunction &fn)
void destroySentinel(IndexListEntry *) const
SlotIndex getBaseIndex() const
int distance(SlotIndex other) const
Return the distance from this index to the given one.
MachineInstr * getInstr() const
bool operator==(SlotIndex other) const
Compare two SlotIndex objects for equality.
void deleteNode(IndexListEntry *N)
void operator<(const Optional< T > &X, const Optional< U > &Y)
Poison comparison between two Optional objects. Clients needs to explicitly compare the underlying va...
SlotIndex getIndexAfter(const MachineInstr *MI) const
bool isEarlyClobber() const
isEarlyClobber - Returns true if this is an early-clobber slot.
static bool isEarlierInstr(SlotIndex A, SlotIndex B)
SlotIndex getLastIndex()
Returns the base index of the last slot in this analysis.
bool operator>=(SlotIndex other) const
bool operator>(SlotIndex other) const
virtual void releaseMemory()
static void noteHead(IndexListEntry *, IndexListEntry *)
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
SlotIndex getNextNonNullIndex(SlotIndex Index)
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
void eraseIndex(SlotIndex index)
Free the resources that were required to maintain a SlotIndex.
bool operator!=(SlotIndex other) const
Compare two SlotIndex objects for inequality.
IndexListEntry * provideInitialHead() const
SlotIndex getPrevIndex() const
void setIndex(unsigned index)
SlotIndex getPrevSlot() const
const MachineBasicBlock * getParent() const
bool isDebugValue() const
unsigned getIndex() const
bool operator<=(SlotIndex other) const
void initializeSlotIndexesPass(PassRegistry &)
SlotIndex(const SlotIndex &li, Slot s)
bool operator<(SlotIndex other) const
void insertMBBInMaps(MachineBasicBlock *mbb)
Add the given MachineBasicBlock into the maps.
bool findLiveInMBBs(SlotIndex start, SlotIndex end, SmallVectorImpl< MachineBasicBlock * > &mbbs) const
iterator insertAfter(iterator where, NodeTy *New)
bool operator()(const IdxMBBPair &LHS, const IdxMBBPair &RHS) const
iterator insert(iterator where, const NodeTy &val)
ItTy next(ItTy it, Dist n)
void dump() const
Dump the indexes.
SlotIndex getZeroIndex()
Returns the zero index for this analysis.
void setInstr(MachineInstr *mi)
bool count(const KeyT &Val) const
count - Return true if the specified key is in the map.
SlotIndex getInstructionIndex(const MachineInstr *MI) const
Returns the base index for the given instruction.
iterator erase(iterator where)
MachineInstr * getInstructionFromIndex(SlotIndex index) const
SlotIndex getIndexBefore(const MachineInstr *MI) const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
bool hasIndex(const MachineInstr *instr) const
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Returns the last index in the given basic block.
bool erase(const KeyT &Val)
MachineBasicBlock * getMBBCoveringRange(SlotIndex start, SlotIndex end) const
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
void * Allocate(size_t Size, size_t Alignment)
IndexListEntry(MachineInstr *mi, unsigned index)
void repairIndexesInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End)
Repair indexes after adding and removing instructions.
MachineInstr * getBundleStart(MachineInstr *MI)
SlotIndex getNextIndex() const
void print(raw_ostream &os) const
Print this index to the given raw_ostream.
bundle_iterator< const MachineInstr, const_instr_iterator > const_iterator
void replaceMachineInstrInMaps(MachineInstr *mi, MachineInstr *newMI)
#define LLVM_EXPLICIT
Expands to explicit on compilers which support explicit conversion operators. Otherwise expands to no...
IndexListEntry * ensureHead(IndexListEntry *) const
void dump() const
Dump this index to stderr.
SlotIndex()
Construct an invalid index.
void removeMachineInstrFromMaps(MachineInstr *mi)
Remove the given machine instruction from the mapping.
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
virtual void getAnalysisUsage(AnalysisUsage &au) const
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
SlotIndex getRegSlot(bool EC=false) const
static NodeTy * createSentinel()
createSentinel - create the dynamic sentinel
IndexListEntry * createSentinel() const
const std::pair< SlotIndex, SlotIndex > & getMBBRange(const MachineBasicBlock *MBB) const
Return the (start,end) range of the given basic block.
BasicBlockListType::iterator iterator
ItTy prior(ItTy it, Dist n)
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Returns the first index in the given basic block.
SlotIndex getNextSlot() const
iterator find(const KeyT &Val)
SlotIndex - An opaque wrapper around machine indexes.
SlotIndex insertMachineInstrInMaps(MachineInstr *mi, bool Late=false)
NodeTy * remove(iterator &IT)
const std::pair< SlotIndex, SlotIndex > & getMBBRange(unsigned Num) const
Return the (start,end) range of the given basic block number.