16#ifndef LLVM_ADT_FOLDINGSET_H
17#define LLVM_ADT_FOLDINGSET_H
144template <
typename T,
typename Enable =
void>
156 X.Profile(ID, Context);
166template <
typename T,
typename Ctx>
176 const unsigned *Data =
nullptr;
193 reinterpret_cast<const uint8_t *
>(Data),
sizeof(
unsigned) * Size));
204 const unsigned *
getData()
const {
return Data; }
217 template <
typename T>
void AddIntegerImpl(
T I) {
218 static_assert(std::is_integral_v<T> &&
sizeof(
T) <=
sizeof(
unsigned) * 2,
219 "T must be an integer type no wider than 64 bits");
221 if constexpr (
sizeof(
unsigned) <
sizeof(
T))
222 Bits.push_back(
static_cast<unsigned long long>(
I) >> 32);
237 static_assert(
sizeof(
uintptr_t) <=
sizeof(
unsigned long long),
238 "unexpected pointer size");
251 template <
typename T>
inline void Add(
const T &x) {
257 inline void clear() { Bits.clear(); }
278 return !(*
this ==
RHS);
323 void *NextInFoldingSetBucket =
nullptr;
375 void GrowBucketCount(
unsigned NewBucketCount,
const FoldingSetInfo &Info);
425template <
typename T,
typename Ctx>
432template <
typename T,
typename Ctx>
442template <
class T,
class Trait = FoldingSetTrait<T>>
452 if constexpr (std::is_empty_v<typename Trait::ContextStorage>)
453 Trait::Profile(*
static_cast<T *
>(
N), ID);
456 *
static_cast<T *
>(
N), ID,
463 if constexpr (std::is_empty_v<typename Trait::ContextStorage>)
464 return Trait::Equals(*
static_cast<T *
>(
N), ID, IDHash, TempID);
466 return Trait::Equals(
467 *
static_cast<T *
>(
N), ID, IDHash, TempID,
473 if constexpr (std::is_empty_v<typename Trait::ContextStorage>)
474 return Trait::ComputeHash(*
static_cast<T *
>(
N), TempID);
476 return Trait::ComputeHash(
477 *
static_cast<T *
>(
N), TempID,
487 template <
typename C,
typename = std::enable_if_t<std::is_constructible_v<
488 typename Trait::ContextStorage,
C>>>
491 Trait::ContextStorage(
std::forward<
C>(Context)) {}
523 return static_cast<T *
>(
531 ID, InsertPos, getFoldingSetInfo()));
546 assert(Inserted ==
N &&
"Node already inserted!");
559template <
class T,
class Trait = FoldingSetTrait<T>>
570template <
class T,
class Ctx>
605 return Set.FindNodeOrInsertPos(ID, InsertPos);
611 T *Result = Set.GetOrInsertNode(
N);
621 Set.InsertNode(
N, InsertPos);
633 unsigned size()
const {
return Set.size(); }
636 [[nodiscard]]
bool empty()
const {
return Set.empty(); }
661 return !(*
this ==
RHS);
692 template <
typename... Ts>
694 : data(
std::forward<Ts>(Args)...) {}
701 operator T &() {
return data; }
702 operator const T &()
const {
return data; }
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DebugEpochBase and DebugEpochBase::HandleBase classes.
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
This file contains library features backported from future STL versions.
This file defines the SmallVector class.
static unsigned getSize(unsigned Kind)
bool isHandleInSync() const
FastFoldingSetNode(const FoldingSetNodeID &ID)
void Profile(FoldingSetNodeID &ID) const
This class is used to maintain the singly linked bucket list in a folding set.
void * getNextInBucket() const
void SetNextInBucket(void *N)
Implements the folding set functionality.
void ** Buckets
Array of bucket chains.
unsigned size() const
Returns the number of nodes in the folding set.
LLVM_ABI void reserve(unsigned EltCount, const FoldingSetInfo &Info)
Grow the number of buckets so that we can hold at least EltCount nodes before rebucketing.
unsigned capacity() const
Returns the number of nodes permitted in the folding set before a rebucket operation is performed.
LLVM_ABI bool RemoveNode(Node *N)
Remove a node from the folding set, returning true if one was removed or false if the node was not in...
LLVM_ABI FoldingSetBase & operator=(FoldingSetBase &&RHS)
LLVM_ABI ~FoldingSetBase()
unsigned NumBuckets
Length of the Buckets array. Always a power of 2.
unsigned NumNodes
Number of nodes in the folding set.
LLVM_ABI Node * GetOrInsertNode(Node *N, const FoldingSetInfo &Info)
If there is an existing node exactly equal to the node N, return it.
bool empty() const
Returns true if there are no nodes in the folding set.
LLVM_ABI void InsertNode(Node *N, void *InsertPos, const FoldingSetInfo &Info)
Insert the specified node into the folding set, knowing that it is not already in the folding set.
LLVM_ABI void clear()
Remove all nodes from the folding set.
LLVM_ABI Node * FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos, const FoldingSetInfo &Info)
Look up the node specified by ID.
LLVM_ABI FoldingSetBase(unsigned Log2InitSize)
An implementation detail that lets us share code between FoldingSet and ContextualFoldingSet.
FoldingSetImpl(FoldingSetImpl &&Arg)=default
FoldingSetImpl(C &&Context, unsigned Log2InitSize=6)
const_iterator begin() const
~FoldingSetImpl()=default
T * GetOrInsertNode(T *N)
FoldingSetImpl & operator=(FoldingSetImpl &&RHS)=default
void reserve(unsigned EltCount)
FoldingSetIterator< const T > const_iterator
const_iterator end() const
FoldingSetIterator< T > iterator
FoldingSetImpl(unsigned Log2InitSize=6)
T * FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos)
void InsertNode(T *N, void *InsertPos)
FoldingSetNode * getNode() const
bool operator==(const FoldingSetIteratorImpl &RHS) const
LLVM_ABI FoldingSetIteratorImpl(const DebugEpochBase *Epoch, void **Bucket)
bool operator!=(const FoldingSetIteratorImpl &RHS) const
FoldingSetIterator(const DebugEpochBase *Epoch, void **Bucket)
FoldingSetIterator operator++(int)
FoldingSetIterator & operator++()
This class describes a reference to an interned FoldingSetNodeID, which can be a useful to store node...
unsigned computeStableHash() const
LLVM_ABI bool operator==(FoldingSetNodeIDRef) const
FoldingSetNodeIDRef(const unsigned *D, size_t S)
LLVM_ABI bool operator<(FoldingSetNodeIDRef) const
Used to compare the "ordering" of two nodes as defined by the profiled bits and their ordering define...
bool operator!=(FoldingSetNodeIDRef RHS) const
unsigned ComputeHash() const
FoldingSetNodeIDRef()=default
const unsigned * getData() const
This class is used to gather all the unique data bits of a node.
LLVM_ABI FoldingSetNodeIDRef Intern(BumpPtrAllocator &Allocator) const
Copy this node's data to a memory region allocated from the given allocator and return a FoldingSetNo...
void AddInteger(signed I)
void AddInteger(unsigned long I)
FoldingSetNodeID(FoldingSetNodeIDRef Ref)
unsigned computeStableHash() const
void AddPointer(const void *Ptr)
Add* - Add various data types to Bit data.
bool operator!=(const FoldingSetNodeIDRef RHS) const
void clear()
Clear the accumulated profile, allowing this FoldingSetNodeID object to be used to compute a new prof...
void AddInteger(unsigned I)
FoldingSetNodeID()=default
LLVM_ABI bool operator==(const FoldingSetNodeID &RHS) const
operator== - Used to compare two nodes to each other.
bool operator!=(const FoldingSetNodeID &RHS) const
void AddInteger(unsigned long long I)
void AddInteger(long long I)
unsigned ComputeHash() const
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)
const T & getValue() const
FoldingSetNodeWrapper(Ts &&...Args)
void Profile(FoldingSetNodeID &ID)
T * GetOrInsertNode(T *N)
If there is an existing node exactly equal to the specified node, return it.
const_iterator end() const
void InsertNode(T *N)
Insert the specified node into the folding set, knowing that it is not already in the folding set.
T * FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos)
Look up the node specified by ID.
unsigned size() const
Returns the number of nodes in the folding set.
pointee_iterator< typename VectorT::const_iterator > const_iterator
pointee_iterator< typename VectorT::iterator > iterator
void clear()
Remove all nodes from the folding set.
bool empty() const
Returns true if there are no nodes in the folding set.
FoldingSetVector(unsigned Log2InitSize=6)
void InsertNode(T *N, void *InsertPos)
Insert the specified node into the folding set, knowing that it is not already in the folding set.
const_iterator begin() const
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
This is an optimization pass for GlobalISel generic memory operations.
uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
Inline ArrayRef overloads of the xxhash entry points declared out-of-line in llvm/Support/xxhash....
FoldingSetBase::Node FoldingSetNode
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
@ Ref
The access may reference the value stored in memory.
FoldingSetImpl< T, ContextualFoldingSetTrait< T, Ctx > > ContextualFoldingSet
This template class is a further refinement of FoldingSet which provides a context argument when call...
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
FoldingSetImpl< T, Trait > FoldingSet
This template class is used to instantiate a specialized implementation of the folding set to the nod...
Implement std::hash so that hash_code can be used in STL containers.
Like FoldingSetTrait, but for ContextualFoldingSets.
ContextStorage(Ctx Context)
Like DefaultFoldingSetTrait, but for ContextualFoldingSets.
static bool Equals(T &X, const FoldingSetNodeID &ID, unsigned IDHash, FoldingSetNodeID &TempID, Ctx Context)
static void Profile(T &X, FoldingSetNodeID &ID, Ctx Context)
static unsigned ComputeHash(T &X, FoldingSetNodeID &TempID, Ctx Context)
This class provides default implementations for FoldingSetTrait implementations.
static void Profile(const T &X, FoldingSetNodeID &ID)
static unsigned ComputeHash(T &X, FoldingSetNodeID &TempID)
static bool Equals(T &X, const FoldingSetNodeID &ID, unsigned IDHash, FoldingSetNodeID &TempID)
static void Profile(T &X, FoldingSetNodeID &ID)
Functions provided by the derived class to compute folding properties.
unsigned(* ComputeNodeHash)(const FoldingSetBase *Self, Node *N, FoldingSetNodeID &TempID)
Instantiations of the FoldingSet template implement this function to compute a hash value for the giv...
bool(* NodeEquals)(const FoldingSetBase *Self, Node *N, const FoldingSetNodeID &ID, unsigned IDHash, FoldingSetNodeID &TempID)
Instantiations of the FoldingSet template implement this function to compare the given node with the ...
void(* GetNodeProfile)(const FoldingSetBase *Self, Node *N, FoldingSetNodeID &ID)
Instantiations of the FoldingSet template implement this function to gather data bits for the given n...
static void Profile(const T &X, FoldingSetNodeID &ID)
static void Profile(T *X, FoldingSetNodeID &ID)
static void Profile(const std::pair< T1, T2 > &P, FoldingSetNodeID &ID)
This trait class is used to define behavior of how to "profile" (in the FoldingSet parlance) an objec...
An iterator type that allows iterating over the pointees via some other iterator.