summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2009-11-04 21:24:15 +0000
committerLang Hames <lhames@gmail.com>2009-11-04 21:24:15 +0000
commit0368e500eb7f5f03313e1a7af5b8fa48465c0560 (patch)
tree6233afaa0b66e09301657a0f269b3daac139c956
parent7127b13342f25a1fa06ed2c6f81891d3613df3fd (diff)
downloadllvm-0368e500eb7f5f03313e1a7af5b8fa48465c0560.tar.gz
llvm-0368e500eb7f5f03313e1a7af5b8fa48465c0560.tar.bz2
llvm-0368e500eb7f5f03313e1a7af5b8fa48465c0560.tar.xz
Handle empty/tombstone keys for LiveIndex more cleanly. Check for index sanity when constructing index list entries.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86049 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/CodeGen/SlotIndexes.h62
-rw-r--r--lib/CodeGen/SlotIndexes.cpp4
2 files changed, 46 insertions, 20 deletions
diff --git a/include/llvm/CodeGen/SlotIndexes.h b/include/llvm/CodeGen/SlotIndexes.h
index 3f175a7241..31623f4c0a 100644
--- a/include/llvm/CodeGen/SlotIndexes.h
+++ b/include/llvm/CodeGen/SlotIndexes.h
@@ -28,6 +28,7 @@
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/Support/Allocator.h"
+#include "llvm/Support/ErrorHandling.h"
namespace llvm {
@@ -38,14 +39,35 @@ namespace llvm {
class IndexListEntry {
private:
+ static std::auto_ptr<IndexListEntry> emptyKeyEntry,
+ tombstoneKeyEntry;
+ typedef enum { EMPTY_KEY, TOMBSTONE_KEY } ReservedEntryType;
+ static const unsigned EMPTY_KEY_INDEX = ~0U & ~3U,
+ TOMBSTONE_KEY_INDEX = ~0U & ~7U;
+
IndexListEntry *next, *prev;
MachineInstr *mi;
unsigned index;
+ // This constructor is only to be used by getEmptyKeyEntry
+ // & getTombstoneKeyEntry. It sets index to the given
+ // value and mi to zero.
+ IndexListEntry(ReservedEntryType r) : mi(0) {
+ switch(r) {
+ case EMPTY_KEY: index = EMPTY_KEY_INDEX; break;
+ case TOMBSTONE_KEY: index = TOMBSTONE_KEY_INDEX; break;
+ default: assert(false && "Invalid value for constructor.");
+ }
+ }
+
public:
- IndexListEntry(MachineInstr *mi, unsigned index)
- : mi(mi), index(index) {}
+ IndexListEntry(MachineInstr *mi, unsigned index) : mi(mi), index(index) {
+ if (index == EMPTY_KEY_INDEX || index == TOMBSTONE_KEY_INDEX) {
+ llvm_report_error("Attempt to create invalid index. "
+ "Available indexes may have been exhausted?.");
+ }
+ }
MachineInstr* getInstr() const { return mi; }
void setInstr(MachineInstr *mi) { this->mi = mi; }
@@ -60,6 +82,24 @@ namespace llvm {
IndexListEntry* getPrev() { return prev; }
const IndexListEntry* getPrev() const { return prev; }
void setPrev(IndexListEntry *prev) { this->prev = prev; }
+
+ // This function returns the index list entry that is to be used for empty
+ // SlotIndex keys.
+ static IndexListEntry* getEmptyKeyEntry() {
+ if (emptyKeyEntry.get() == 0) {
+ emptyKeyEntry.reset(new IndexListEntry(EMPTY_KEY));
+ }
+ return emptyKeyEntry.get();
+ }
+
+ // This function returns the index list entry that is to be used for
+ // tombstone SlotIndex keys.
+ static IndexListEntry* getTombstoneKeyEntry() {
+ if (tombstoneKeyEntry.get() == 0) {
+ tombstoneKeyEntry.reset(new IndexListEntry(TOMBSTONE_KEY));
+ }
+ return tombstoneKeyEntry.get();
+ }
};
// Specialize PointerLikeTypeTraits for IndexListEntry.
@@ -81,10 +121,6 @@ namespace llvm {
friend class DenseMapInfo<SlotIndex>;
private:
-
- // FIXME: Is there any way to statically allocate these things and have
- // them 8-byte aligned?
- static std::auto_ptr<IndexListEntry> emptyKeyPtr, tombstoneKeyPtr;
static const unsigned PHI_BIT = 1 << 2;
PointerIntPair<IndexListEntry*, 3, unsigned> lie;
@@ -116,21 +152,11 @@ namespace llvm {
enum Slot { LOAD, USE, DEF, STORE, NUM };
static inline SlotIndex getEmptyKey() {
- // FIXME: How do we guarantee these numbers don't get allocated to
- // legit indexes?
- if (emptyKeyPtr.get() == 0)
- emptyKeyPtr.reset(new IndexListEntry(0, ~0U & ~3U));
-
- return SlotIndex(emptyKeyPtr.get(), 0);
+ return SlotIndex(IndexListEntry::getEmptyKeyEntry(), 0);
}
static inline SlotIndex getTombstoneKey() {
- // FIXME: How do we guarantee these numbers don't get allocated to
- // legit indexes?
- if (tombstoneKeyPtr.get() == 0)
- tombstoneKeyPtr.reset(new IndexListEntry(0, ~0U & ~7U));
-
- return SlotIndex(tombstoneKeyPtr.get(), 0);
+ return SlotIndex(IndexListEntry::getTombstoneKeyEntry(), 0);
}
/// Construct an invalid index.
diff --git a/lib/CodeGen/SlotIndexes.cpp b/lib/CodeGen/SlotIndexes.cpp
index 6b04029fba..f3ad0d1cc0 100644
--- a/lib/CodeGen/SlotIndexes.cpp
+++ b/lib/CodeGen/SlotIndexes.cpp
@@ -16,8 +16,8 @@
using namespace llvm;
-std::auto_ptr<IndexListEntry> SlotIndex::emptyKeyPtr(0),
- SlotIndex::tombstoneKeyPtr(0);
+std::auto_ptr<IndexListEntry> IndexListEntry::emptyKeyEntry,
+ IndexListEntry::tombstoneKeyEntry;
char SlotIndexes::ID = 0;
static RegisterPass<SlotIndexes> X("slotindexes", "Slot index numbering");