#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Target/TargetInstrInfo.h"
using namespace llvm;
}
char SlotIndexes::ID = 0;
-static RegisterPass<SlotIndexes> X("slotindexes", "Slot index numbering");
+INITIALIZE_PASS(SlotIndexes, "slotindexes",
+ "Slot index numbering", false, false)
IndexListEntry* IndexListEntry::getEmptyKeyEntry() {
return &*IndexListEntryEmptyKey;
mi2iMap.clear();
mbb2IdxMap.clear();
idx2MBBMap.clear();
- terminatorGaps.clear();
clearList();
}
functionSize = 0;
unsigned index = 0;
- // Iterate over the the function.
+ push_back(createEntry(0, index));
+
+ // Iterate over the function.
for (MachineFunction::iterator mbbItr = mf->begin(), mbbEnd = mf->end();
mbbItr != mbbEnd; ++mbbItr) {
MachineBasicBlock *mbb = &*mbbItr;
// Insert an index for the MBB start.
- push_back(createEntry(0, index));
SlotIndex blockStartIndex(back(), SlotIndex::LOAD);
index += SlotIndex::NUM;
for (MachineBasicBlock::iterator miItr = mbb->begin(), miEnd = mbb->end();
miItr != miEnd; ++miItr) {
- MachineInstr *mi = &*miItr;
-
- if (miItr == mbb->getFirstTerminator()) {
- push_back(createEntry(0, index));
- terminatorGaps.insert(
- std::make_pair(mbb, SlotIndex(back(), SlotIndex::PHI_BIT)));
- index += SlotIndex::NUM;
- }
+ MachineInstr *mi = miItr;
+ if (mi->isDebugValue())
+ continue;
// Insert a store index for the instr.
push_back(createEntry(mi, index));
index += (Slots + 1) * SlotIndex::NUM;
}
- if (mbb->getFirstTerminator() == mbb->end()) {
- push_back(createEntry(0, index));
- terminatorGaps.insert(
- std::make_pair(mbb, SlotIndex(back(), SlotIndex::PHI_BIT)));
- index += SlotIndex::NUM;
- }
+ // We insert two blank instructions between basic blocks.
+ // One to represent live-out registers and one to represent live-ins.
+ push_back(createEntry(0, index));
+ index += SlotIndex::NUM;
+
+ push_back(createEntry(0, index));
- SlotIndex blockEndIndex(back(), SlotIndex::STORE);
+ SlotIndex blockEndIndex(back(), SlotIndex::LOAD);
mbb2IdxMap.insert(
std::make_pair(mbb, std::make_pair(blockStartIndex, blockEndIndex)));
idx2MBBMap.push_back(IdxMBBPair(blockStartIndex, mbb));
}
- // One blank instruction at the end.
- push_back(createEntry(0, index));
-
// Sort the Idx2MBBMap
std::sort(idx2MBBMap.begin(), idx2MBBMap.end(), Idx2MBBCompare());
return false;
}
-void SlotIndexes::renumber() {
+void SlotIndexes::renumberIndexes() {
// Renumber updates the index of every element of the index list.
// If all instrs in the function have been allocated an index (which has been
curEntry->setIndex(index);
if (curEntry->getInstr() == 0) {
- // MBB start entry or terminator gap. Just step index by 1.
+ // MBB start entry. Just step index by 1.
index += SlotIndex::NUM;
}
else {
Slots = 1;
index += (Slots + 1) * SlotIndex::NUM;
-
}
}
}
void SlotIndexes::dump() const {
for (const IndexListEntry *itr = front(); itr != getTail();
itr = itr->getNext()) {
- errs() << itr->getIndex() << " ";
+ dbgs() << itr->getIndex() << " ";
if (itr->getInstr() != 0) {
- errs() << *itr->getInstr();
+ dbgs() << *itr->getInstr();
} else {
- errs() << "\n";
+ dbgs() << "\n";
}
}
- for (MBB2IdxMap::iterator itr = mbb2IdxMap.begin();
+ for (MBB2IdxMap::const_iterator itr = mbb2IdxMap.begin();
itr != mbb2IdxMap.end(); ++itr) {
- errs() << "MBB " << itr->first->getNumber() << " (" << itr->first << ") - ["
+ dbgs() << "MBB " << itr->first->getNumber() << " (" << itr->first << ") - ["
<< itr->second.first << ", " << itr->second.second << "]\n";
}
}
// Print a SlotIndex to a raw_ostream.
void SlotIndex::print(raw_ostream &os) const {
- os << getIndex();
- if (isPHI())
- os << "*";
+ os << entry().getIndex() << "LudS"[getSlot()];
}
// Dump a SlotIndex to stderr.
void SlotIndex::dump() const {
- print(errs());
- errs() << "\n";
+ print(dbgs());
+ dbgs() << "\n";
}