29 if (Size != RHS.Size)
return false;
30 return memcmp(Data, RHS.Data, Size*
sizeof(*Data)) == 0;
37 return Size < RHS.Size;
38 return memcmp(Data, RHS.Data, Size*
sizeof(*Data)) < 0;
50 Bits.reserve(Bits.size() + NumInserts);
55 unsigned Units =
Size / 4;
57 const unsigned *
Base = (
const unsigned*)
String.data();
60 if (!((intptr_t)
Base & 3)) {
62 Pos = (Units + 1) * 4;
68 "Unexpected host endianness");
70 for (Pos += 4; Pos <=
Size; Pos += 4) {
71 unsigned V = ((
unsigned char)
String[Pos - 4] << 24) |
72 ((
unsigned char)
String[Pos - 3] << 16) |
74 (
unsigned char)
String[Pos - 1];
78 for (Pos += 4; Pos <=
Size; Pos += 4) {
79 unsigned V = ((
unsigned char)
String[Pos - 1] << 24) |
80 ((
unsigned char)
String[Pos - 2] << 16) |
82 (
unsigned char)
String[Pos - 4];
93 case 1: V = (V << 8) | (
unsigned char)
String[
Size - 3]; [[fallthrough]];
94 case 2: V = (V << 8) | (
unsigned char)
String[
Size - 2]; [[fallthrough]];
95 case 3: V = (V << 8) | (
unsigned char)
String[
Size - 1];
break;
104 Bits.append(
ID.Bits.begin(),
ID.Bits.end());
134 unsigned *New = Allocator.Allocate<
unsigned>(Bits.size());
150 if (
reinterpret_cast<intptr_t
>(NextInBucketPtr) & 1)
159 intptr_t Ptr =
reinterpret_cast<intptr_t
>(NextInBucketPtr);
160 assert((Ptr & 1) &&
"Not a bucket pointer");
161 return reinterpret_cast<void**
>(Ptr & ~intptr_t(1));
166static void **
GetBucketFor(
unsigned Hash,
void **Buckets,
unsigned NumBuckets) {
168 unsigned BucketNum = Hash & (NumBuckets-1);
169 return Buckets + BucketNum;
174 void **Buckets =
static_cast<void**
>(
safe_calloc(NumBuckets + 1,
177 Buckets[NumBuckets] =
reinterpret_cast<void*
>(-1);
185 assert(5 < Log2InitSize && Log2InitSize < 32 &&
186 "Initial hash table size out of range");
194 Arg.Buckets =
nullptr;
204 RHS.Buckets =
nullptr;
225void FoldingSetBase::GrowBucketCount(
unsigned NewBucketCount,
226 const FoldingSetInfo &Info) {
228 "Can't shrink a folding set with GrowBucketCount");
241 for (
unsigned i = 0; i != OldNumBuckets; ++i) {
242 void *Probe = OldBuckets[i];
243 if (!Probe)
continue;
246 Probe = NodeInBucket->getNextInBucket();
247 NodeInBucket->SetNextInBucket(
nullptr);
251 GetBucketFor(Info.ComputeNodeHash(
this, NodeInBucket, TempID),
263void FoldingSetBase::GrowHashTable(
const FoldingSetInfo &Info) {
281 unsigned IDHash =
ID.ComputeHash();
283 void *Probe = *Bucket;
289 if (Info.NodeEquals(
this, NodeInBucket,
ID, IDHash, TempID))
293 Probe = NodeInBucket->getNextInBucket();
318 void **Bucket =
static_cast<void**
>(InsertPos);
320 void *
Next = *Bucket;
326 Next =
reinterpret_cast<void*
>(
reinterpret_cast<intptr_t
>(Bucket)|1);
329 N->SetNextInBucket(
Next);
338 void *Ptr =
N->getNextInBucket();
339 if (!Ptr)
return false;
342 N->SetNextInBucket(
nullptr);
345 void *NodeNextPtr = Ptr;
351 Ptr = NodeInBucket->getNextInBucket();
356 NodeInBucket->SetNextInBucket(NodeNextPtr);
366 *Bucket = NodeNextPtr;
380 Info.GetNodeProfile(
this,
N,
ID);
393 while (*Bucket !=
reinterpret_cast<void*
>(-1) &&
402 void *Probe =
NodePtr->getNextInBucket();
413 }
while (*Bucket !=
reinterpret_cast<void*
>(-1) &&
424 Ptr = (!*Bucket || !
GetNextPtr(*Bucket)) ? (
void*) Bucket : *Bucket;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the BumpPtrAllocator interface.
static void ** GetBucketPtr(void *NextInBucketPtr)
testing.
static void ** GetBucketFor(unsigned Hash, void **Buckets, unsigned NumBuckets)
GetBucketFor - Hash the specified node ID and return the hash bucket for the specified ID.
static void ** AllocateBuckets(unsigned NumBuckets)
AllocateBuckets - Allocated initialized bucket memory.
static FoldingSetBase::Node * GetNextPtr(void *NextInBucketPtr)
Helper functions for FoldingSetBase.
This file defines a hash set that can be used to remove duplication of nodes in a graph.
Node - This class is used to maintain the singly linked bucket list in a folding set.
LLVM_ABI FoldingSetBase(unsigned Log2InitSize=6)
void ** Buckets
Buckets - Array of bucket chains.
LLVM_ABI void reserve(unsigned EltCount, const FoldingSetInfo &Info)
reserve - Increase the number of buckets such that adding the EltCount-th node won't cause a rebucket...
LLVM_ABI bool RemoveNode(Node *N)
RemoveNode - Remove a node from the folding set, returning true if one was removed or false if the no...
LLVM_ABI FoldingSetBase & operator=(FoldingSetBase &&RHS)
LLVM_ABI ~FoldingSetBase()
unsigned NumBuckets
NumBuckets - Length of the Buckets array. Always a power of 2.
unsigned NumNodes
NumNodes - Number of nodes in the folding set.
unsigned capacity()
capacity - Returns the number of nodes permitted in the folding set before a rebucket operation is pe...
LLVM_ABI Node * GetOrInsertNode(Node *N, const FoldingSetInfo &Info)
GetOrInsertNode - If there is an existing simple Node exactly equal to the specified node,...
LLVM_ABI void InsertNode(Node *N, void *InsertPos, const FoldingSetInfo &Info)
InsertNode - Insert the specified node into the folding set, knowing that it is not already in the fo...
LLVM_ABI void clear()
clear - Remove all nodes from the folding set.
LLVM_ABI Node * FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos, const FoldingSetInfo &Info)
FindNodeOrInsertPos - Look up the node specified by ID.
LLVM_ABI FoldingSetBucketIteratorImpl(void **Bucket)
LLVM_ABI FoldingSetIteratorImpl(void **Bucket)
FoldingSetNodeIDRef - This class describes a reference to an interned FoldingSetNodeID,...
LLVM_ABI bool operator==(FoldingSetNodeIDRef) const
LLVM_ABI bool operator<(FoldingSetNodeIDRef) const
Used to compare the "ordering" of two nodes as defined by the profiled bits and their ordering define...
FoldingSetNodeIDRef()=default
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
LLVM_ABI FoldingSetNodeIDRef Intern(BumpPtrAllocator &Allocator) const
Intern - Copy this node's data to a memory region allocated from the given allocator and return a Fol...
void clear()
clear - Clear the accumulated profile, allowing this FoldingSetNodeID object to be used to compute a ...
FoldingSetNodeID()=default
LLVM_ABI bool operator==(const FoldingSetNodeID &RHS) const
operator== - Used to compare two nodes to each other.
LLVM_ABI bool operator<(const FoldingSetNodeID &RHS) const
Used to compare the "ordering" of two nodes as defined by the profiled bits and their ordering define...
LLVM_ABI void AddNodeID(const FoldingSetNodeID &ID)
LLVM_ABI void AddString(StringRef String)
Add* - Add various data types to Bit data.
StringRef - Represent a constant reference to a string, i.e.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
constexpr bool IsLittleEndianHost
constexpr bool IsBigEndianHost
This is an optimization pass for GlobalISel generic memory operations.
FoldingSetBase::Node FoldingSetNode
auto uninitialized_copy(R &&Src, IterTy Dst)
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_calloc(size_t Count, size_t Sz)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
FunctionAddr VTableAddr Next
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
T bit_floor(T Value)
Returns the largest integral power of two no greater than Value if Value is nonzero.
Functions provided by the derived class to compute folding properties.