[llvm-commits] [llvm] r86342 - in /llvm/trunk: include/llvm/CodeGen/SlotIndexes.h lib/CodeGen/SlotIndexes.cpp
Chris Lattner
clattner at apple.com
Fri Nov 6 22:32:13 PST 2009
On Nov 6, 2009, at 9:50 PM, Lang Hames wrote:
> Author: lhames
> Date: Fri Nov 6 23:50:28 2009
> New Revision: 86342
>
> URL: http://llvm.org/viewvc/llvm-project?rev=86342&view=rev
> Log:
> Update some globals to use ManagedStatic.
Thanks Lang, can you move the relevant methods out of line? I'd
prefer SlotIndexes.h to not #include ManagedStatic.h. Ideally
only .cpp files would include that header.
-Chris
>
> Modified:
> llvm/trunk/include/llvm/CodeGen/SlotIndexes.h
> llvm/trunk/lib/CodeGen/SlotIndexes.cpp
>
> Modified: llvm/trunk/include/llvm/CodeGen/SlotIndexes.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SlotIndexes.h?rev=86342&r1=86341&r2=86342&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/include/llvm/CodeGen/SlotIndexes.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/SlotIndexes.h Fri Nov 6
> 23:50:28 2009
> @@ -29,9 +29,13 @@
> #include "llvm/CodeGen/MachineInstr.h"
> #include "llvm/Support/Allocator.h"
> #include "llvm/Support/ErrorHandling.h"
> +#include "llvm/Support/ManagedStatic.h"
>
> namespace llvm {
>
> + class EmptyIndexListEntry;
> + class TombstoneIndexListEntry;
> +
> /// This class represents an entry in the slot index list held in
> the
> /// SlotIndexes pass. It should not be used directly. See the
> /// SlotIndex & SlotIndexes classes for the public interface to this
> @@ -39,16 +43,22 @@
> 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;
>
> + // The following statics are thread safe. They're read only,
> and you
> + // can't step from them to any other list entries.
> + static ManagedStatic<EmptyIndexListEntry> emptyKeyEntry;
> + static ManagedStatic<TombstoneIndexListEntry> tombstoneKeyEntry;
> +
> IndexListEntry *next, *prev;
> MachineInstr *mi;
> unsigned index;
>
> + protected:
> +
> + typedef enum { EMPTY_KEY, TOMBSTONE_KEY } ReservedEntryType;
> +
> // This constructor is only to be used by getEmptyKeyEntry
> // & getTombstoneKeyEntry. It sets index to the given
> // value and mi to zero.
> @@ -58,6 +68,8 @@
> case TOMBSTONE_KEY: index = TOMBSTONE_KEY_INDEX; break;
> default: assert(false && "Invalid value for constructor.");
> }
> + next = this;
> + prev = this;
> }
>
> public:
> @@ -70,38 +82,65 @@
> }
>
> MachineInstr* getInstr() const { return mi; }
> - void setInstr(MachineInstr *mi) { this->mi = mi; }
> + void setInstr(MachineInstr *mi) {
> + assert(index != EMPTY_KEY_INDEX && index !=
> TOMBSTONE_KEY_INDEX &&
> + "Attempt to modify reserved index.");
> + this->mi = mi;
> + }
>
> unsigned getIndex() const { return index; }
> - void setIndex(unsigned index) { this->index = index; }
> + void setIndex(unsigned index) {
> + assert(index != EMPTY_KEY_INDEX && index !=
> TOMBSTONE_KEY_INDEX &&
> + "Attempt to set index to invalid value.");
> + assert(this->index != EMPTY_KEY_INDEX &&
> + this->index != TOMBSTONE_KEY_INDEX &&
> + "Attempt to reset reserved index value.");
> + this->index = index;
> + }
>
> IndexListEntry* getNext() { return next; }
> const IndexListEntry* getNext() const { return next; }
> - void setNext(IndexListEntry *next) { this->next = next; }
> + void setNext(IndexListEntry *next) {
> + assert(index != EMPTY_KEY_INDEX && index !=
> TOMBSTONE_KEY_INDEX &&
> + "Attempt to modify reserved index.");
> + this->next = next;
> + }
>
> IndexListEntry* getPrev() { return prev; }
> const IndexListEntry* getPrev() const { return prev; }
> - void setPrev(IndexListEntry *prev) { this->prev = prev; }
> + void setPrev(IndexListEntry *prev) {
> + assert(index != EMPTY_KEY_INDEX && index !=
> TOMBSTONE_KEY_INDEX &&
> + "Attempt to modify reserved index.");
> + 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();
> - }
> + inline static IndexListEntry* getEmptyKeyEntry();
>
> // 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();
> - }
> + inline static IndexListEntry* getTombstoneKeyEntry();
> + };
> +
> + class EmptyIndexListEntry : public IndexListEntry {
> + public:
> + EmptyIndexListEntry() : IndexListEntry(EMPTY_KEY) {}
> };
>
> + class TombstoneIndexListEntry : public IndexListEntry {
> + public:
> + TombstoneIndexListEntry() : IndexListEntry(TOMBSTONE_KEY) {}
> + };
> +
> + inline IndexListEntry* IndexListEntry::getEmptyKeyEntry() {
> + return &*emptyKeyEntry;
> + }
> +
> + inline IndexListEntry* IndexListEntry::getTombstoneKeyEntry() {
> + return &*tombstoneKeyEntry;
> + }
> +
> // Specialize PointerLikeTypeTraits for IndexListEntry.
> template <>
> class PointerLikeTypeTraits<IndexListEntry*> {
>
> Modified: llvm/trunk/lib/CodeGen/SlotIndexes.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SlotIndexes.cpp?rev=86342&r1=86341&r2=86342&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/lib/CodeGen/SlotIndexes.cpp (original)
> +++ llvm/trunk/lib/CodeGen/SlotIndexes.cpp Fri Nov 6 23:50:28 2009
> @@ -16,8 +16,10 @@
>
> using namespace llvm;
>
> -std::auto_ptr<IndexListEntry> IndexListEntry::emptyKeyEntry,
> - IndexListEntry::tombstoneKeyEntry;
> +
> +// Yep - these are thread safe. See the header for details.
> +ManagedStatic<EmptyIndexListEntry> IndexListEntry::emptyKeyEntry;
> +ManagedStatic<TombstoneIndexListEntry>
> IndexListEntry::tombstoneKeyEntry;
>
> char SlotIndexes::ID = 0;
> static RegisterPass<SlotIndexes> X("slotindexes", "Slot index
> numbering");
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list