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 static_assert(
sizeof(uintptr_t) <=
sizeof(
unsigned long long),
58 "unexpected pointer size");
71 if (
sizeof(
long) ==
sizeof(
int))
73 else if (
sizeof(
long) ==
sizeof(
long long)) {
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) {
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");
237 : Buckets(Arg.Buckets), NumBuckets(Arg.NumBuckets), NumNodes(Arg.NumNodes) {
238 Arg.Buckets =
nullptr;
248 RHS.Buckets =
nullptr;
269 void FoldingSetImpl::GrowBucketCount(
unsigned NewBucketCount) {
270 assert((NewBucketCount >
NumBuckets) &&
"Can't shrink a folding set with GrowBucketCount");
282 for (
unsigned i = 0;
i != OldNumBuckets; ++
i) {
283 void *Probe = OldBuckets[
i];
284 if (!Probe)
continue;
285 while (Node *NodeInBucket =
GetNextPtr(Probe)) {
287 Probe = NodeInBucket->getNextInBucket();
288 NodeInBucket->SetNextInBucket(
nullptr);
303 void FoldingSetImpl::GrowHashTable() {
324 void *Probe = *Bucket;
330 if (
NodeEquals(NodeInBucket, ID, IDHash, TempID))
334 Probe = NodeInBucket->getNextInBucket();
357 void **Bucket =
static_cast<void**
>(InsertPos);
359 void *Next = *Bucket;
365 Next =
reinterpret_cast<void*
>(
reinterpret_cast<intptr_t>(Bucket)|1);
378 if (!Ptr)
return false;
384 void *NodeNextPtr =
Ptr;
390 Ptr = NodeInBucket->getNextInBucket();
395 NodeInBucket->SetNextInBucket(NodeNextPtr);
405 *Bucket = NodeNextPtr;
430 while (*Bucket != reinterpret_cast<void*>(-1) &&
450 }
while (*Bucket != reinterpret_cast<void*>(-1) &&
461 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.
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...
FoldingSetImpl & operator=(FoldingSetImpl &&RHS)
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...
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
bool operator==(const FoldingSetNodeID &RHS) const
operator== - Used to compare two nodes to each other.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
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)
constexpr bool isPowerOf2_32(uint32_t Value)
isPowerOf2_32 - This function returns true if the argument is a power of two > 0. ...
Allocate memory in an ever growing pool, as if by bump-pointer.
void * getNextInBucket() const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
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.
Greedy Register Allocator
Node * FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos)
FindNodeOrInsertPos - Look up the node specified by ID.
FoldingSetImpl - Implements the folding set functionality.
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.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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 ...
unsigned capacity()
capacity - Returns the number of nodes permitted in the folding set before a rebucket operation is pe...
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
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
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void AddString(StringRef String)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
FoldingSetBucketIteratorImpl(void **Bucket)
uint64_t PowerOf2Floor(uint64_t A)
Returns the power of two which is less than or equal to the given value.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
void reserve(unsigned EltCount)
reserve - Increase the number of buckets such that adding the EltCount-th node won't cause a rebucket...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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