Author: kremenek Date: Fri Jan 18 22:22:50 2008 New Revision: 46187 URL: http://llvm.org/viewvc/llvm-project?rev=46187&view=rev Log: Made 'FoldingSetNodeID' a proper class instead of a nested class in 'FoldingSetNodeImpl' (previously 'FoldingSetNodeID' was a typedef of 'FoldingSetNodeImpl::NodeID').
Why? Clients can now easily forward declare 'FoldingSetNodeID' without having to include FoldingSet.h. Modified: llvm/trunk/include/llvm/ADT/FoldingSet.h llvm/trunk/lib/Support/FoldingSet.cpp Modified: llvm/trunk/include/llvm/ADT/FoldingSet.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/FoldingSet.h?rev=46187&r1=46186&r2=46187&view=diff ============================================================================== --- llvm/trunk/include/llvm/ADT/FoldingSet.h (original) +++ llvm/trunk/include/llvm/ADT/FoldingSet.h Fri Jan 18 22:22:50 2008 @@ -96,8 +96,9 @@ /// bool WasRemoved = RemoveNode(N); /// /// The result indicates whether the node existed in the folding set. - - + +class FoldingSetNodeID; + //===----------------------------------------------------------------------===// /// FoldingSetImpl - Implements the folding set functionality. The main /// structure is an array of buckets. Each bucket is indexed by the hash of @@ -123,49 +124,6 @@ explicit FoldingSetImpl(unsigned Log2InitSize = 6); virtual ~FoldingSetImpl(); - // Forward declaration. - class Node; - - //===--------------------------------------------------------------------===// - /// NodeID - This class is used to gather all the unique data bits of a - /// node. When all the bits are gathered this class is used to produce a - /// hash value for the node. - /// - class NodeID { - /// Bits - Vector of all the data bits that make the node unique. - /// Use a SmallVector to avoid a heap allocation in the common case. - SmallVector<unsigned, 32> Bits; - - public: - NodeID() {} - - /// getRawData - Return the ith entry in the Bits data. - /// - unsigned getRawData(unsigned i) const { - return Bits[i]; - } - - /// Add* - Add various data types to Bit data. - /// - void AddPointer(const void *Ptr); - void AddInteger(signed I); - void AddInteger(unsigned I); - void AddInteger(int64_t I); - void AddInteger(uint64_t I); - void AddFloat(float F); - void AddDouble(double D); - void AddAPFloat(const APFloat& apf); - void AddString(const std::string &String); - - /// ComputeHash - Compute a strong hash value for this NodeID, used to - /// lookup the node in the FoldingSetImpl. - unsigned ComputeHash() const; - - /// operator== - Used to compare two nodes to each other. - /// - bool operator==(const NodeID &RHS) const; - }; - //===--------------------------------------------------------------------===// /// Node - This class is used to maintain the singly linked bucket list in /// a folding set. @@ -196,7 +154,7 @@ /// FindNodeOrInsertPos - Look up the node specified by ID. If it exists, /// return it. If not, return the insertion token that will make insertion /// faster. - Node *FindNodeOrInsertPos(const NodeID &ID, void *&InsertPos); + Node *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos); /// InsertNode - Insert the specified node into the folding set, knowing that /// it is not already in the folding set. InsertPos must be obtained from @@ -216,13 +174,51 @@ /// GetNodeProfile - Instantiations of the FoldingSet template implement /// this function to gather data bits for the given node. - virtual void GetNodeProfile(NodeID &ID, Node *N) const = 0; + virtual void GetNodeProfile(FoldingSetNodeID &ID, Node *N) const = 0; }; -// Convenience types to hide the implementation of the folding set. -typedef FoldingSetImpl::Node FoldingSetNode; -typedef FoldingSetImpl::NodeID FoldingSetNodeID; +//===--------------------------------------------------------------------===// +/// FoldingSetNodeID - This class is used to gather all the unique data bits of +/// a node. When all the bits are gathered this class is used to produce a +/// hash value for the node. +/// +class FoldingSetNodeID { + /// Bits - Vector of all the data bits that make the node unique. + /// Use a SmallVector to avoid a heap allocation in the common case. + SmallVector<unsigned, 32> Bits; + +public: + FoldingSetNodeID() {} + + /// getRawData - Return the ith entry in the Bits data. + /// + unsigned getRawData(unsigned i) const { + return Bits[i]; + } + + /// Add* - Add various data types to Bit data. + /// + void AddPointer(const void *Ptr); + void AddInteger(signed I); + void AddInteger(unsigned I); + void AddInteger(int64_t I); + void AddInteger(uint64_t I); + void AddFloat(float F); + void AddDouble(double D); + void AddAPFloat(const APFloat& apf); + void AddString(const std::string &String); + + /// ComputeHash - Compute a strong hash value for this FoldingSetNodeID, used + /// to lookup the node in the FoldingSetImpl. + unsigned ComputeHash() const; + + /// operator== - Used to compare two nodes to each other. + /// + bool operator==(const FoldingSetNodeID &RHS) const; +}; +// Convenience type to hide the implementation of the folding set. +typedef FoldingSetImpl::Node FoldingSetNode; template<class T> class FoldingSetIterator; //===----------------------------------------------------------------------===// @@ -247,7 +243,7 @@ private: /// GetNodeProfile - Each instantiatation of the FoldingSet needs to provide a /// way to convert nodes into a unique specifier. - virtual void GetNodeProfile(NodeID &ID, Node *N) const { + virtual void GetNodeProfile(FoldingSetNodeID &ID, Node *N) const { T *TN = static_cast<T *>(N); FoldingSetTrait<T>::Profile(*TN,ID); } Modified: llvm/trunk/lib/Support/FoldingSet.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FoldingSet.cpp?rev=46187&r1=46186&r2=46187&view=diff ============================================================================== --- llvm/trunk/lib/Support/FoldingSet.cpp (original) +++ llvm/trunk/lib/Support/FoldingSet.cpp Fri Jan 18 22:22:50 2008 @@ -21,11 +21,11 @@ using namespace llvm; //===----------------------------------------------------------------------===// -// FoldingSetImpl::NodeID Implementation +// FoldingSetNodeID Implementation /// Add* - Add various data types to Bit data. /// -void FoldingSetImpl::NodeID::AddPointer(const void *Ptr) { +void FoldingSetNodeID::AddPointer(const void *Ptr) { // Note: this adds pointers to the hash using sizes and endianness that // depend on the host. It doesn't matter however, because hashing on // pointer values in inherently unstable. Nothing should depend on the @@ -35,35 +35,35 @@ if (sizeof(intptr_t) > sizeof(unsigned)) Bits.push_back(unsigned(uint64_t(PtrI) >> 32)); } -void FoldingSetImpl::NodeID::AddInteger(signed I) { +void FoldingSetNodeID::AddInteger(signed I) { Bits.push_back(I); } -void FoldingSetImpl::NodeID::AddInteger(unsigned I) { +void FoldingSetNodeID::AddInteger(unsigned I) { Bits.push_back(I); } -void FoldingSetImpl::NodeID::AddInteger(int64_t I) { +void FoldingSetNodeID::AddInteger(int64_t I) { AddInteger((uint64_t)I); } -void FoldingSetImpl::NodeID::AddInteger(uint64_t I) { +void FoldingSetNodeID::AddInteger(uint64_t I) { Bits.push_back(unsigned(I)); // If the integer is small, encode it just as 32-bits. if ((uint64_t)(int)I != I) Bits.push_back(unsigned(I >> 32)); } -void FoldingSetImpl::NodeID::AddFloat(float F) { +void FoldingSetNodeID::AddFloat(float F) { Bits.push_back(FloatToBits(F)); } -void FoldingSetImpl::NodeID::AddDouble(double D) { +void FoldingSetNodeID::AddDouble(double D) { AddInteger(DoubleToBits(D)); } -void FoldingSetImpl::NodeID::AddAPFloat(const APFloat& apf) { +void FoldingSetNodeID::AddAPFloat(const APFloat& apf) { APInt api = apf.convertToAPInt(); const uint64_t *p = api.getRawData(); for (unsigned i=0; i<api.getNumWords(); i++) AddInteger(*p++); } -void FoldingSetImpl::NodeID::AddString(const std::string &String) { +void FoldingSetNodeID::AddString(const std::string &String) { unsigned Size = String.size(); Bits.push_back(Size); if (!Size) return; @@ -100,9 +100,9 @@ Bits.push_back(V); } -/// ComputeHash - Compute a strong hash value for this NodeID, used to +/// ComputeHash - Compute a strong hash value for this FoldingSetNodeID, used to /// lookup the node in the FoldingSetImpl. -unsigned FoldingSetImpl::NodeID::ComputeHash() const { +unsigned FoldingSetNodeID::ComputeHash() const { // This is adapted from SuperFastHash by Paul Hsieh. unsigned Hash = Bits.size(); for (const unsigned *BP = &Bits[0], *E = BP+Bits.size(); BP != E; ++BP) { @@ -125,7 +125,7 @@ /// operator== - Used to compare two nodes to each other. /// -bool FoldingSetImpl::NodeID::operator==(const FoldingSetImpl::NodeID &RHS)const{ +bool FoldingSetNodeID::operator==(const FoldingSetNodeID &RHS)const{ if (Bits.size() != RHS.Bits.size()) return false; return memcmp(&Bits[0], &RHS.Bits[0], Bits.size()*sizeof(Bits[0])) == 0; } @@ -158,7 +158,7 @@ /// GetBucketFor - Hash the specified node ID and return the hash bucket for /// the specified ID. -static void **GetBucketFor(const FoldingSetImpl::NodeID &ID, +static void **GetBucketFor(const FoldingSetNodeID &ID, void **Buckets, unsigned NumBuckets) { // NumBuckets is always a power of 2. unsigned BucketNum = ID.ComputeHash() & (NumBuckets-1); @@ -209,7 +209,7 @@ NodeInBucket->SetNextInBucket(0); // Insert the node into the new bucket, after recomputing the hash. - NodeID ID; + FoldingSetNodeID ID; GetNodeProfile(ID, NodeInBucket); InsertNode(NodeInBucket, GetBucketFor(ID, Buckets, NumBuckets)); } @@ -221,7 +221,7 @@ /// FindNodeOrInsertPos - Look up the node specified by ID. If it exists, /// return it. If not, return the insertion token that will make insertion /// faster. -FoldingSetImpl::Node *FoldingSetImpl::FindNodeOrInsertPos(const NodeID &ID, +FoldingSetImpl::Node *FoldingSetImpl::FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos) { void **Bucket = GetBucketFor(ID, Buckets, NumBuckets); void *Probe = *Bucket; @@ -229,7 +229,7 @@ InsertPos = 0; while (Node *NodeInBucket = GetNextPtr(Probe)) { - NodeID OtherID; + FoldingSetNodeID OtherID; GetNodeProfile(OtherID, NodeInBucket); if (OtherID == ID) return NodeInBucket; @@ -250,7 +250,7 @@ // Do we need to grow the hashtable? if (NumNodes+1 > NumBuckets*2) { GrowHashTable(); - NodeID ID; + FoldingSetNodeID ID; GetNodeProfile(ID, N); InsertPos = GetBucketFor(ID, Buckets, NumBuckets); } @@ -317,7 +317,7 @@ /// equal to the specified node, return it. Otherwise, insert 'N' and it /// instead. FoldingSetImpl::Node *FoldingSetImpl::GetOrInsertNode(FoldingSetImpl::Node *N) { - NodeID ID; + FoldingSetNodeID ID; GetNodeProfile(ID, N); void *IP; if (Node *E = FindNodeOrInsertPos(ID, IP)) _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits