16#ifndef LLVM_ADT_FOLDINGSET_H
17#define LLVM_ADT_FOLDINGSET_H
134 unsigned Hash =
static_cast<unsigned>(
hash_value(*
this));
142 reinterpret_cast<const uint8_t *
>(
data()),
sizeof(
unsigned) *
size()));
167 template <
typename T>
void AddIntegerImpl(
T I) {
168 static_assert(std::is_integral_v<T> &&
sizeof(
T) <=
sizeof(
unsigned) * 2,
169 "T must be an integer type no wider than 64 bits");
171 if constexpr (
sizeof(
unsigned) <
sizeof(
T))
172 Bits.push_back(
static_cast<unsigned long long>(
I) >> 32);
186 static_assert(
sizeof(
uintptr_t) <=
sizeof(
unsigned long long),
187 "unexpected pointer size");
200 template <
typename T>
inline void Add(
const T &x) {
206 inline void clear() { Bits.clear(); }
254template <
typename T,
typename Enable>
268 X.Profile(ID, Context);
279template <
typename T,
typename Ctx>
284class FoldingSetInsertToken {
295 explicit operator bool()
const {
299 friend bool operator==(FoldingSetInsertToken
A, FoldingSetInsertToken
B) {
300 return A.Hash ==
B.Hash;
302 friend bool operator!=(FoldingSetInsertToken
A, FoldingSetInsertToken
B) {
331 while (Bucket != End && *Bucket ==
nullptr);
338 while (this->Bucket != this->End && *this->Bucket ==
nullptr)
344 return *
static_cast<T *
>(*Bucket);
361 return Bucket ==
RHS.Bucket;
364 return !(*
this ==
RHS);
408 void grow(
unsigned MinNumBuckets);
421 template <
typename MatchFn>
426 for (
unsigned I = Hash & Mask;
Buckets[
I];
I = (
I + 1) & Mask) {
428 if (
N->getFoldingSetHash() == Hash && IsMatch(
N)) {
452template <
class T,
class Trait = FoldingSetTrait<T>>
455 if constexpr (std::is_empty_v<typename Trait::ContextStorage>)
456 Trait::Profile(*
static_cast<T *
>(
N), ID);
458 Trait::Profile(*
static_cast<T *
>(
N), ID, this->
getContext());
462 if constexpr (std::is_empty_v<typename Trait::ContextStorage>)
463 return Trait::Equals(*
static_cast<T *
>(
N), ID);
465 return Trait::Equals(*
static_cast<T *
>(
N), ID, this->
getContext());
472 template <
typename C,
typename = std::enable_if_t<std::is_constructible_v<
473 typename Trait::ContextStorage,
C>>>
476 Trait::ContextStorage(
std::forward<
C>(Context)) {}
521 return static_cast<T *
>(
522 probe(ID.computeHash(), Token,
532 nodeProfile(
N, ProfileID);
534 "node profile must match the insert token");
544 assert(Inserted ==
N &&
"Node already inserted!");
557template <
class T,
class Trait = FoldingSetTrait<T>>
568template <
class T,
class Ctx>
603 return Set.lookup(ID, Token);
609 T *Result = Set.getOrInsert(
N);
619 Set.insert(
N, Token);
631 unsigned size()
const {
return Set.size(); }
634 [[nodiscard]]
bool empty()
const {
return Set.empty(); }
644 template <
typename... Ts>
646 : data(
std::forward<Ts>(Args)...) {}
653 operator T &() {
return data; }
654 operator const T &()
const {
return data; }
666 return Key ==
N.getKey();
695template <
typename T,
typename Info = UniquingSetInfo<T>>
721 return Info::isEqual(
Key, *
static_cast<T *
>(
N));
728 assert(Token &&
"Invalid token!");
730 "N does not key as the lookup that produced Token did");
739 if (
T *
E =
lookup(Info::getKey(*
N), Token))
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< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ATTRIBUTE_NOINLINE
LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so, mark a method "not for inl...
This file defines DenseMapInfo traits for DenseMap.
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.
const unsigned * data() const
bool isComparableWith(const HandleBase &) const
bool isHandleInSync() const
FastFoldingSetNode(const FoldingSetNodeID &ID)
void Profile(FoldingSetNodeID &ID) const
Non-templated base class for FoldingSet and ContextualFoldingSet, holding the memory management and p...
static FoldingSetInsertToken makeInsertToken(uint32_t Hash)
Wrap Hash, which must not be NotAHash, as the token insert takes.
LLVM_ABI bool erase(FoldingSetNode *N)
Remove a node from the folding set, returning true if one was removed or false if the node was not in...
unsigned size() const
Returns the number of nodes in the folding set.
FoldingSetNode ** Buckets
Array of node pointers; a null entry marks an empty slot.
LLVM_ABI FoldingSetBase & operator=(FoldingSetBase &&RHS)
LLVM_ABI ~FoldingSetBase()
FoldingSetNode * probe(uint32_t Hash, FoldingSetInsertToken &Token, MatchFn IsMatch)
Walk the probe chain for Hash, offering each node whose cached hash matches to IsMatch.
unsigned NumBuckets
Length of the Buckets array. Always a power of 2.
unsigned NumNodes
Number of nodes in the folding set.
bool empty() const
Returns true if there are no nodes in the folding set.
LLVM_ABI void insert(FoldingSetNode *N, FoldingSetInsertToken Token)
Insert the specified node into the folding set, knowing that it is not already in the folding set.
LLVM_ABI void reserve(unsigned N)
Grow the number of buckets so that we can hold at least N nodes before rebucketing.
LLVM_ABI void clear()
Remove all nodes from the folding set.
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
LLVM_ATTRIBUTE_NOINLINE T * getOrInsert(T *N)
~FoldingSetImpl()=default
FoldingSetImpl & operator=(FoldingSetImpl &&RHS)=default
FoldingSetIterator< const T > const_iterator
void insert(T *N, FoldingSetInsertToken Token)
const_iterator end() const
FoldingSetIterator< T > iterator
FoldingSetImpl(unsigned Log2InitSize=6)
T * lookup(const FoldingSetNodeID &ID, FoldingSetInsertToken &Token)
Look up the node specified by ID.
Insertion token: a failed lookup fills it in, the matching insert consumes it.
FoldingSetInsertToken()=default
friend bool operator!=(FoldingSetInsertToken A, FoldingSetInsertToken B)
friend class FoldingSetBase
friend bool operator==(FoldingSetInsertToken A, FoldingSetInsertToken B)
Forward iterator for FoldingSet and ContextualFoldingSet.
bool operator==(const FoldingSetIterator &RHS) const
FoldingSetIterator(FoldingSetNode **Bucket, FoldingSetNode **End, const DebugEpochBase *Epoch)
FoldingSetIterator operator++(int)
bool operator!=(const FoldingSetIterator &RHS) const
FoldingSetIterator & operator++()
This class describes a reference to an interned FoldingSetNodeID, which can be a useful to store node...
unsigned computeStableHash() const
unsigned computeHash() const
static constexpr unsigned NotAHash
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.
void clear()
Clear the accumulated profile, allowing this FoldingSetNodeID object to be used to compute a new prof...
FoldingSetNodeIDRef getRef() const
The accumulated profile, valid until this object is next modified.
void AddInteger(unsigned I)
FoldingSetNodeID()=default
void AddInteger(unsigned long long I)
void AddInteger(long long I)
LLVM_ABI void AddNodeID(const FoldingSetNodeID &ID)
unsigned computeHash() const
LLVM_ABI void AddString(StringRef String)
const T & getValue() const
FoldingSetNodeWrapper(Ts &&...Args)
void Profile(FoldingSetNodeID &ID)
This class is used to maintain node state in a folding set.
uint32_t getFoldingSetHash() const
void setFoldingSetHash(uint32_t Hash)
const_iterator end() const
void insert(T *N)
Insert the specified node into the folding set, knowing that it is not already in the folding set.
unsigned size() const
Returns the number of nodes in the folding set.
pointee_iterator< typename VectorT::const_iterator > const_iterator
T * lookup(const FoldingSetNodeID &ID, FoldingSetInsertToken &Token)
Look up the node specified by ID.
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 insert(T *N, FoldingSetInsertToken Token)
Insert the specified node into the folding set, knowing that it is not already in the folding set.
T * getOrInsert(T *N)
If there is an existing node exactly equal to the specified node, return it.
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.
FoldingSetIterator< T > iterator
bool erase(T *N)
Remove N, returning whether it was present.
const_iterator begin() const
UniquingSet(unsigned Log2InitSize=6)
T * lookup(const KeyTy &Key, FoldingSetInsertToken &Token)
Look up Key.
void insert(T *N, FoldingSetInsertToken Token)
Insert N, which must key identically to the lookup that produced Token.
FoldingSetIterator< const T > const_iterator
const_iterator end() const
typename Info::KeyTy KeyTy
LLVM_ATTRIBUTE_NOINLINE T * getOrInsert(T *N)
Look N up by its own key, inserting it if absent, and return the node in the set.
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
hash_code hash_value(const FixedPointSemantics &Val)
uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
Inline ArrayRef overloads of the xxhash entry points declared out-of-line in llvm/Support/xxhash....
bool operator!=(uint64_t V1, const APInt &V2)
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ 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.
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 void Profile(T &X, FoldingSetNodeID &ID, Ctx Context)
static bool Equals(T &X, const FoldingSetNodeID &ID, Ctx Context)
This class provides default implementations for FoldingSetTrait implementations.
static bool Equals(T &X, const FoldingSetNodeID &ID)
static void Profile(const T &X, FoldingSetNodeID &ID)
static void Profile(T &X, FoldingSetNodeID &ID)
An information struct used to provide DenseMap with the various necessary components for a given valu...
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...
The default UniquingSet Info: T supplies its own key.
static bool isEqual(const KeyTy &Key, const T &N)
static unsigned getHashValue(const KeyTy &Key)
remove_cvref_t< decltype(std::declval< const T & >().getKey())> KeyTy
static KeyTy getKey(const T &N)
An iterator type that allows iterating over the pointees via some other iterator.