NULL terminate name in pubtypes sections.
[oota-llvm.git] / lib / CodeGen / SlotIndexes.cpp
index d99d120509ddde3c2da688b06a857adae4f58180..a23efb2b8d9447b993467abcc1294a9df2c98c15 100644 (file)
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Target/TargetInstrInfo.h"
 
 using namespace llvm;
 
 
 // Yep - these are thread safe. See the header for details. 
-ManagedStatic<EmptyIndexListEntry> IndexListEntry::emptyKeyEntry;
-ManagedStatic<TombstoneIndexListEntry> IndexListEntry::tombstoneKeyEntry;
+namespace {
+
+
+  class EmptyIndexListEntry : public IndexListEntry {
+  public:
+    EmptyIndexListEntry() : IndexListEntry(EMPTY_KEY) {}
+  };
+
+  class TombstoneIndexListEntry : public IndexListEntry {
+  public:
+    TombstoneIndexListEntry() : IndexListEntry(TOMBSTONE_KEY) {}
+  };
+
+  // The following statics are thread safe. They're read only, and you
+  // can't step from them to any other list entries.
+  ManagedStatic<EmptyIndexListEntry> IndexListEntryEmptyKey;
+  ManagedStatic<TombstoneIndexListEntry> IndexListEntryTombstoneKey;
+}
 
 char SlotIndexes::ID = 0;
 static RegisterPass<SlotIndexes> X("slotindexes", "Slot index numbering");
 
+IndexListEntry* IndexListEntry::getEmptyKeyEntry() {
+  return &*IndexListEntryEmptyKey;
+}
+
+IndexListEntry* IndexListEntry::getTombstoneKeyEntry() {
+  return &*IndexListEntryTombstoneKey;
+}
+
+
 void SlotIndexes::getAnalysisUsage(AnalysisUsage &au) const {
   au.setPreservesAll();
   MachineFunctionPass::getAnalysisUsage(au);
@@ -66,13 +93,14 @@ bool SlotIndexes::runOnMachineFunction(MachineFunction &fn) {
   functionSize = 0;
   unsigned index = 0;
 
+  push_back(createEntry(0, index));
+
   // Iterate over the 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;
@@ -80,6 +108,8 @@ bool SlotIndexes::runOnMachineFunction(MachineFunction &fn) {
     for (MachineBasicBlock::iterator miItr = mbb->begin(), miEnd = mbb->end();
          miItr != miEnd; ++miItr) {
       MachineInstr *mi = &*miItr;
+      if (mi->getOpcode()==TargetInstrInfo::DEBUG_VALUE)
+        continue;
 
       if (miItr == mbb->getFirstTerminator()) {
         push_back(createEntry(0, index));
@@ -111,16 +141,16 @@ bool SlotIndexes::runOnMachineFunction(MachineFunction &fn) {
       index += SlotIndex::NUM;
     }
 
-    SlotIndex blockEndIndex(back(), SlotIndex::STORE);
+    // One blank instruction at the end.
+    push_back(createEntry(0, index));    
+
+    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());
 
@@ -130,7 +160,7 @@ bool SlotIndexes::runOnMachineFunction(MachineFunction &fn) {
   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
@@ -158,7 +188,6 @@ void SlotIndexes::renumber() {
         Slots = 1;
 
       index += (Slots + 1) * SlotIndex::NUM;
-
     }
   }
 }
@@ -166,18 +195,18 @@ void SlotIndexes::renumber() {
 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";
   }
 }
@@ -191,7 +220,7 @@ void SlotIndex::print(raw_ostream &os) const {
 
 // Dump a SlotIndex to stderr.
 void SlotIndex::dump() const {
-  print(errs());
-  errs() << "\n";
+  print(dbgs());
+  dbgs() << "\n";
 }