35 if (Size != RHS.Size)
return false;
36 return memcmp(Data, RHS.Data, Size*
sizeof(*Data)) == 0;
43 return Size < RHS.Size;
44 return memcmp(Data, RHS.Data, Size*
sizeof(*Data)) < 0;
57 Bits.
append(reinterpret_cast<unsigned *>(&Ptr),
58 reinterpret_cast<unsigned *>(&Ptr+1));
70 if (
sizeof(
long) ==
sizeof(
int))
72 else if (
sizeof(
long) ==
sizeof(
long long)) {
83 if ((uint64_t)(
unsigned)I != I)
88 unsigned Size = String.
size();
92 unsigned Units = Size / 4;
94 const unsigned *Base = (
const unsigned*) String.
data();
98 Bits.
append(Base, Base + Units);
99 Pos = (Units + 1) * 4;
105 "Unexpected host endianness");
107 for (Pos += 4; Pos <= Size; Pos += 4) {
108 unsigned V = ((
unsigned char)String[Pos - 4] << 24) |
109 ((
unsigned char)String[Pos - 3] << 16) |
110 ((
unsigned char)String[Pos - 2] << 8) |
111 (
unsigned char)String[Pos - 1];
115 for (Pos += 4; Pos <= Size; Pos += 4) {
116 unsigned V = ((
unsigned char)String[Pos - 1] << 24) |
117 ((
unsigned char)String[Pos - 2] << 16) |
118 ((
unsigned char)String[Pos - 3] << 8) |
119 (
unsigned char)String[Pos - 4];
129 switch (Pos - Size) {
130 case 1: V = (V << 8) | (
unsigned char)String[Size - 3];
131 case 2: V = (V << 8) | (
unsigned char)String[Size - 2];
132 case 3: V = (V << 8) | (
unsigned char)String[Size - 1];
break;
177 unsigned *New = Allocator.
Allocate<
unsigned>(Bits.
size());
178 std::uninitialized_copy(Bits.
begin(), Bits.
end(), New);
193 if (reinterpret_cast<intptr_t>(NextInBucketPtr) & 1)
203 assert((Ptr & 1) &&
"Not a bucket pointer");
204 return reinterpret_cast<void**
>(Ptr & ~
intptr_t(1));
211 unsigned BucketNum = Hash & (NumBuckets-1);
212 return Buckets + BucketNum;
217 void **Buckets =
static_cast<void**
>(calloc(NumBuckets+1,
sizeof(
void*)));
219 Buckets[NumBuckets] =
reinterpret_cast<void*
>(-1);
226 void FoldingSetImpl::anchor() {}
229 assert(5 < Log2InitSize && Log2InitSize < 32 &&
230 "Initial hash table size out of range");
251 void FoldingSetImpl::GrowHashTable() {
262 for (
unsigned i = 0; i != OldNumBuckets; ++i) {
263 void *Probe = OldBuckets[i];
264 if (!Probe)
continue;
265 while (Node *NodeInBucket =
GetNextPtr(Probe)) {
267 Probe = NodeInBucket->getNextInBucket();
268 NodeInBucket->SetNextInBucket(
nullptr);
289 void *Probe = *Bucket;
295 if (
NodeEquals(NodeInBucket, ID, IDHash, TempID))
299 Probe = NodeInBucket->getNextInBucket();
322 void **Bucket =
static_cast<void**
>(InsertPos);
324 void *Next = *Bucket;
330 Next =
reinterpret_cast<void*
>(
reinterpret_cast<intptr_t>(Bucket)|1);
343 if (!Ptr)
return false;
349 void *NodeNextPtr = Ptr;
355 Ptr = NodeInBucket->getNextInBucket();
360 NodeInBucket->SetNextInBucket(NodeNextPtr);
370 *Bucket = NodeNextPtr;
395 while (*Bucket != reinterpret_cast<void*>(-1) &&
415 }
while (*Bucket != reinterpret_cast<void*>(-1) &&
426 Ptr = (!*Bucket || !
GetNextPtr(*Bucket)) ? (
void*) Bucket : *Bucket;
Node * GetOrInsertNode(Node *N)
GetOrInsertNode - If there is an existing simple Node exactly equal to the specified node...
void AddPointer(const void *Ptr)
Add* - Add various data types to Bit data.
void push_back(const T &Elt)
static void ** AllocateBuckets(unsigned NumBuckets)
AllocateBuckets - Allocated initialized bucket memory.
size_t size() const
size - Get the string size.
void ** Buckets
Buckets - Array of bucket chains.
void InsertNode(Node *N, void *InsertPos)
InsertNode - Insert the specified node into the folding set, knowing that it is not already in the fo...
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
static void ** GetBucketPtr(void *NextInBucketPtr)
testing.
unsigned ComputeHash() const
ComputeHash - Compute a strong hash value for this FoldingSetNodeIDRef, used to lookup the node in th...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
virtual void GetNodeProfile(Node *N, FoldingSetNodeID &ID) const =0
GetNodeProfile - Instantiations of the FoldingSet template implement this function to gather data bit...
void AddInteger(signed I)
static const bool IsLittleEndianHost
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
bool operator==(const FoldingSetNodeID &RHS) const
operator== - Used to compare two nodes to each other.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
virtual unsigned ComputeNodeHash(Node *N, FoldingSetNodeID &TempID) const =0
ComputeNodeHash - Instantiations of the FoldingSet template implement this function to compute a hash...
void AddNodeID(const FoldingSetNodeID &ID)
Allocate memory in an ever growing pool, as if by bump-pointer.
void * getNextInBucket() const
bool operator<(FoldingSetNodeIDRef) const
Used to compare the "ordering" of two nodes as defined by the profiled bits and their ordering define...
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
static FoldingSetImpl::Node * GetNextPtr(void *NextInBucketPtr)
Helper functions for FoldingSetImpl.
Node * FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos)
FindNodeOrInsertPos - Look up the node specified by ID.
static void ** GetBucketFor(unsigned Hash, void **Buckets, unsigned NumBuckets)
GetBucketFor - Hash the specified node ID and return the hash bucket for the specified ID...
unsigned NumNodes
NumNodes - Number of nodes in the folding set.
FoldingSetImpl(unsigned Log2InitSize=6)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
bool RemoveNode(Node *N)
RemoveNode - Remove a node from the folding set, returning true if one was removed or false if the no...
bool operator<(const FoldingSetNodeID &RHS) const
Used to compare the "ordering" of two nodes as defined by the profiled bits and their ordering define...
void SetNextInBucket(void *N)
void clear()
clear - Clear the accumulated profile, allowing this FoldingSetNodeID object to be used to compute a ...
Node - This class is used to maintain the singly linked bucket list in a folding set.
unsigned NumBuckets
NumBuckets - Length of the Buckets array.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
FoldingSetNodeIDRef - This class describes a reference to an interned FoldingSetNodeID, which can be a useful to store node id data rather than using plain FoldingSetNodeIDs, since the 32-element SmallVector is often much larger than necessary, and the possibility of heap allocation means it requires a non-trivial destructor call.
pointer data()
Return a pointer to the vector's buffer, even if empty().
FoldingSetIteratorImpl(void **Bucket)
unsigned ComputeHash() const
ComputeHash - Compute a strong hash value for this FoldingSetNodeID, used to lookup the node in the F...
static const bool IsBigEndianHost
void AddString(StringRef String)
FoldingSetBucketIteratorImpl(void **Bucket)
FoldingSetNodeIDRef Intern(BumpPtrAllocator &Allocator) const
Intern - Copy this node's data to a memory region allocated from the given allocator and return a Fol...
std::string Hash(const Unit &U)
virtual bool NodeEquals(Node *N, const FoldingSetNodeID &ID, unsigned IDHash, FoldingSetNodeID &TempID) const =0
NodeEquals - Instantiations of the FoldingSet template implement this function to compare the given n...
StringRef - Represent a constant reference to a string, i.e.
void clear()
clear - Remove all nodes from the folding set.
bool operator==(FoldingSetNodeIDRef) const