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");
59 AddInteger(reinterpret_cast<uintptr_t>(Ptr));
68 AddInteger((
unsigned long)I);
71 if (
sizeof(
long) ==
sizeof(
int))
72 AddInteger(
unsigned(I));
73 else if (
sizeof(
long) ==
sizeof(
long long)) {
74 AddInteger((
unsigned long long)I);
80 AddInteger((
unsigned long long)I);
83 AddInteger(
unsigned(I));
84 AddInteger(
unsigned(I >> 32));
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));
209 static void **
GetBucketFor(
unsigned Hash,
void **Buckets,
unsigned NumBuckets) {
211 unsigned BucketNum = Hash & (NumBuckets-1);
212 return Buckets + BucketNum;
217 void **Buckets =
static_cast<void**
>(
safe_calloc(NumBuckets + 1,
220 Buckets[NumBuckets] =
reinterpret_cast<void*
>(-1);
227 void FoldingSetBase::anchor() {}
230 assert(5 < Log2InitSize && Log2InitSize < 32 &&
231 "Initial hash table size out of range");
232 NumBuckets = 1 << Log2InitSize;
238 : Buckets(
Arg.Buckets), NumBuckets(
Arg.NumBuckets), NumNodes(
Arg.NumNodes) {
239 Arg.Buckets =
nullptr;
249 RHS.Buckets =
nullptr;
270 void FoldingSetBase::GrowBucketCount(
unsigned NewBucketCount) {
271 assert((NewBucketCount >
NumBuckets) &&
"Can't shrink a folding set with GrowBucketCount");
284 for (
unsigned i = 0; i != OldNumBuckets; ++i) {
285 void *Probe = OldBuckets[i];
286 if (!Probe)
continue;
289 Probe = NodeInBucket->getNextInBucket();
290 NodeInBucket->SetNextInBucket(
nullptr);
305 void FoldingSetBase::GrowHashTable() {
326 void *Probe = *Bucket;
332 if (
NodeEquals(NodeInBucket, ID, IDHash, TempID))
336 Probe = NodeInBucket->getNextInBucket();
359 void **Bucket =
static_cast<void**
>(InsertPos);
361 void *Next = *Bucket;
367 Next =
reinterpret_cast<void*
>(
reinterpret_cast<intptr_t>(Bucket)|1);
380 if (!Ptr)
return false;
386 void *NodeNextPtr = Ptr;
392 Ptr = NodeInBucket->getNextInBucket();
397 NodeInBucket->SetNextInBucket(NodeNextPtr);
407 *Bucket = NodeNextPtr;
432 while (*Bucket != reinterpret_cast<void*>(-1) &&
441 void *Probe =
NodePtr->getNextInBucket();
452 }
while (*Bucket != reinterpret_cast<void*>(-1) &&
463 Ptr = (!*Bucket || !
GetNextPtr(*Bucket)) ? (
void*) Bucket : *Bucket;
void AddPointer(const void *Ptr)
Add* - Add various data types to Bit data.
static void ** AllocateBuckets(unsigned NumBuckets)
AllocateBuckets - Allocated initialized bucket memory.
void clear()
clear - Remove all nodes from the folding set.
void reserve(unsigned EltCount)
reserve - Increase the number of buckets such that adding the EltCount-th node won't cause a rebucket...
This class represents lattice values for constants.
FoldingSetNodeIDRef()=default
unsigned NumBuckets
NumBuckets - Length of the Buckets array. Always a power of 2.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
bool operator<(const FoldingSetNodeID &RHS) const
Used to compare the "ordering" of two nodes as defined by the profiled bits and their ordering define...
FoldingSetNodeIDRef Intern(BumpPtrAllocator &Allocator) const
Intern - Copy this node's data to a memory region allocated from the given allocator and return a Fol...
unsigned capacity()
capacity - Returns the number of nodes permitted in the folding set before a rebucket operation is pe...
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).
unsigned ComputeHash() const
ComputeHash - Compute a strong hash value for this FoldingSetNodeID, used to lookup the node in the F...
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
bool operator<(FoldingSetNodeIDRef) const
Used to compare the "ordering" of two nodes as defined by the profiled bits and their ordering define...
static void ** GetBucketPtr(void *NextInBucketPtr)
testing.
constexpr bool IsBigEndianHost
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...
void AddInteger(signed I)
static const bool IsLittleEndianHost
Node * GetOrInsertNode(Node *N)
GetOrInsertNode - If there is an existing simple Node exactly equal to the specified node...
void InsertNode(Node *N, void *InsertPos)
InsertNode - Insert the specified node into the folding set, knowing that it is not already in the fo...
unsigned ComputeHash() const
ComputeHash - Compute a strong hash value for this FoldingSetNodeIDRef, used to lookup the node in th...
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
void SetNextInBucket(void *N)
void AddNodeID(const FoldingSetNodeID &ID)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Allocate memory in an ever growing pool, as if by bump-pointer.
std::shared_ptr< Node > NodePtr
Short-hand for a Node pointer.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
void * getNextInBucket() const
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...
void ** Buckets
Buckets - Array of bucket chains.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned NumNodes
NumNodes - Number of nodes in the folding set.
FoldingSetBase(unsigned Log2InitSize=6)
void clear()
clear - Clear the accumulated profile, allowing this FoldingSetNodeID object to be used to compute a ...
virtual void GetNodeProfile(Node *N, FoldingSetNodeID &ID) const =0
GetNodeProfile - Instantiations of the FoldingSet template implement this function to gather data bit...
FoldingSetBase - Implements the folding set functionality.
static FoldingSetBase::Node * GetNextPtr(void *NextInBucketPtr)
Helper functions for FoldingSetBase.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
amdgpu Simplify well known AMD library false Value Value * Arg
bool operator==(FoldingSetNodeIDRef) const
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().
Merge contiguous icmps into a memcmp
Node - This class is used to maintain the singly linked bucket list in a folding set.
FoldingSetIteratorImpl(void **Bucket)
void AddString(StringRef String)
virtual unsigned ComputeNodeHash(Node *N, FoldingSetNodeID &TempID) const =0
ComputeNodeHash - Instantiations of the FoldingSet template implement this function to compute a hash...
bool RemoveNode(Node *N)
RemoveNode - Remove a node from the folding set, returning true if one was removed or false if the no...
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.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_calloc(size_t Count, size_t Sz)
StringRef - Represent a constant reference to a string, i.e.
FoldingSetBase & operator=(FoldingSetBase &&RHS)
bool operator==(const FoldingSetNodeID &RHS) const
operator== - Used to compare two nodes to each other.