16 #ifndef LLVM_ADT_FOLDINGSET_H
17 #define LLVM_ADT_FOLDINGSET_H
103 class FoldingSetNodeID;
114 virtual void anchor();
142 void *NextInFoldingSetBucket;
145 Node() : NextInFoldingSetBucket(nullptr) {}
164 void reserve(
unsigned EltCount);
176 void GrowHashTable();
181 void GrowBucketCount(
unsigned NewBucketCount);
259 template<
typename T,
typename Ctx>
262 X.Profile(ID, Context);
283 const unsigned *Data =
nullptr;
302 const unsigned *
getData()
const {
return Data; }
320 : Bits(Ref.getData(), Ref.getData() + Ref.getSize()) {}
335 template <
typename T>
386 template<
typename T,
typename Ctx>
396 template<
typename T,
typename Ctx>
466 assert(Inserted == N &&
"Node already inserted!");
486 T *TN =
static_cast<T *
>(
N);
494 T *TN =
static_cast<T *
>(
N);
500 unsigned ComputeNodeHash(Node *N,
FoldingSetNodeID &TempID)
const override {
501 T *TN =
static_cast<T *
>(
N);
507 :
Super(Log2InitSize) {}
522 template <
class T,
class Ctx>
537 T *TN =
static_cast<T *
>(
N);
543 T *TN =
static_cast<T *
>(
N);
548 unsigned ComputeNodeHash(Node *N,
FoldingSetNodeID &TempID)
const override {
549 T *TN =
static_cast<T *
>(
N);
555 :
Super(Log2InitSize), Context(Context)
566 template <
class T,
class VectorT = SmallVector<T*, 8>>
573 : Set(Log2InitSize) {
585 void clear() { Set.clear(); Vector.clear(); }
591 return Set.FindNodeOrInsertPos(ID, InsertPos);
598 T *Result = Set.GetOrInsertNode(N);
599 if (Result == N) Vector.push_back(N);
607 Set.InsertNode(N, InsertPos);
619 unsigned size()
const {
return Set.size(); }
622 bool empty()
const {
return Set.empty(); }
645 template <
class T>
class FoldingSetIterator :
public FoldingSetIteratorImpl {
682 uintptr_t x =
reinterpret_cast<uintptr_t
>(Probe) & ~0x1;
683 Ptr =
reinterpret_cast<void*
>(x);
696 class FoldingSetBucketIterator :
public FoldingSetBucketIteratorImpl {
719 template <
typename T>
724 template <
typename... Ts>
726 : data(std::forward<Ts>(
Args)...) {}
733 operator T&() {
return data; }
734 operator const T&()
const {
return data; }
761 template <
typename T1,
typename T2>
763 static inline void Profile(
const std::pair<T1, T2> &
P,
772 #endif // LLVM_ADT_FOLDINGSET_H
FoldingSetVector - This template class combines a FoldingSet and a vector to provide the interface of...
void AddPointer(const void *Ptr)
Add* - Add various data types to Bit data.
FoldingSetNodeIDRef(const unsigned *D, size_t S)
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...
FoldingSetNodeIDRef()=default
unsigned NumBuckets
NumBuckets - Length of the Buckets array.
ContextualFoldingSet(Ctx Context, unsigned Log2InitSize=6)
FastFoldingSetNode - This is a subclass of FoldingSetNode which stores a FoldingSetNodeID value rathe...
T * FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos)
FindNodeOrInsertPos - Look up the node specified by ID.
FastFoldingSetNode(const FoldingSetNodeID &ID)
FoldingSetBucketIterator< T > bucket_iterator
unsigned size() const
size - Returns the 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...
static void Profile(const T &X, FoldingSetNodeID &ID)
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
FoldingSet(unsigned Log2InitSize=6)
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...
pointee_iterator< typename VectorT::const_iterator > const_iterator
unsigned ComputeHash() const
ComputeHash - Compute a strong hash value for this FoldingSetNodeIDRef, used to lookup the node in th...
static void Profile(T *X, FoldingSetNodeID &ID)
FoldingSetBase::Node FoldingSetNode
ContextualFoldingSetTrait - Like FoldingSetTrait, but for ContextualFoldingSets.
static unsigned ComputeHash(T &X, FoldingSetNodeID &TempID)
void AddInteger(signed I)
FoldingSetIteratorImpl - This is the common iterator support shared by all folding sets...
void InsertNode(T *N, void *InsertPos)
InsertNode - Insert the specified node into the folding set, knowing that it is not already in the fo...
Node * GetOrInsertNode(Node *N)
GetOrInsertNode - If there is an existing simple Node exactly equal to the specified node...
bool operator==(const FoldingSetNodeID &RHS) const
operator== - Used to compare two nodes to each other.
void InsertNode(Node *N, void *InsertPos)
InsertNode - Insert the specified node into the folding set, knowing that it is not already in the fo...
void InsertNode(T *N)
InsertNode - Insert the specified node into the folding set, knowing that it is not already in the fo...
const_iterator end() const
const_iterator begin() const
FoldingSetNodeID()=default
void Profile(FoldingSetNodeID &ID)
void clear()
clear - Remove all nodes from the folding set.
void * getNextInBucket() const
FoldingSetImpl(unsigned Log2InitSize)
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
void SetNextInBucket(void *N)
FoldingSetTrait - This trait class is used to define behavior of how to "profile" (in the FoldingSet ...
void AddNodeID(const FoldingSetNodeID &ID)
const T & getValue() const
Allocate memory in an ever growing pool, as if by bump-pointer.
void Profile(FoldingSetNodeID &ID) const
static unsigned ComputeHash(T &X, FoldingSetNodeID &TempID, Ctx Context)
FoldingSet & operator=(FoldingSet &&RHS)=default
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
bool operator<(FoldingSetNodeIDRef) const
Used to compare the "ordering" of two nodes as defined by the profiled bits and their ordering define...
FoldingSetImpl & operator=(FoldingSetImpl &&RHS)=default
FoldingSetIterator< T > iterator
T * FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos)
FindNodeOrInsertPos - Look up the node specified by ID.
FoldingSetBucketIterator operator++(int)
FoldingSetNodeWrapper(Ts &&...Args)
Node * FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos)
FindNodeOrInsertPos - Look up the node specified by ID.
FoldingSetImpl - An implementation detail that lets us share code between FoldingSet and ContextualFo...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
T * GetOrInsertNode(T *N)
GetOrInsertNode - If there is an existing simple Node exactly equal to the specified node...
bool empty() const
empty - Returns true if there are no nodes in the folding set.
FoldingSetIterator operator++(int)
unsigned size() const
size - Returns the number of nodes in the folding set.
FoldingSetBucketIterator & operator++()
void InsertNode(T *N, void *InsertPos)
InsertNode - Insert the specified node into the folding set, knowing that it is not already in the fo...
void ** Buckets
Buckets - Array of bucket chains.
FoldingSetVector(unsigned Log2InitSize=6)
FoldingSet - This template class is used to instantiate a specialized implementation of the folding s...
unsigned NumNodes
NumNodes - Number of nodes in the folding set.
static bool Equals(T &X, const FoldingSetNodeID &ID, unsigned IDHash, FoldingSetNodeID &TempID)
bool operator!=(const FoldingSetNodeID &RHS) const
bucket_iterator bucket_end(unsigned hash)
bool empty() const
empty - Returns true if there are no nodes in the folding set.
FoldingSetNodeWrapper - This template class is used to "wrap" arbitrary types in an enclosing object ...
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 InsertNode(T *N)
InsertNode - Insert the specified node into the folding set, knowing that it is not already in the fo...
FoldingSetNodeID(FoldingSetNodeIDRef Ref)
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...
FoldingSetBucketIterator(void **Bucket)
bool operator!=(const FoldingSetNodeIDRef RHS) const
FoldingSetBucketIterator(void **Bucket, bool)
const_iterator begin() const
An iterator type that allows iterating over the pointees via some other iterator. ...
ContextualFoldingSet - This template class is a further refinement of FoldingSet which provides a con...
FoldingSetIterator & operator++()
FoldingSetBase - Implements the folding set functionality.
static void Profile(T &X, FoldingSetNodeID &ID)
const unsigned * getData() const
T * GetOrInsertNode(T *N)
GetOrInsertNode - If there is an existing simple Node exactly equal to the specified node...
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.
Node - This class is used to maintain the singly linked bucket list in a folding set.
FoldingSetIterator< const T > const_iterator
FoldingSetIteratorImpl(void **Bucket)
unsigned ComputeHash() const
ComputeHash - Compute a strong hash value for this FoldingSetNodeID, used to lookup the node in the F...
const_iterator end() const
void AddString(StringRef String)
bucket_iterator bucket_begin(unsigned hash)
bool operator==(const FoldingSetIteratorImpl &RHS) const
virtual unsigned ComputeNodeHash(Node *N, FoldingSetNodeID &TempID) const =0
ComputeNodeHash - Instantiations of the FoldingSet template implement this function to compute a hash...
pointee_iterator< typename VectorT::iterator > iterator
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())
DefaultContextualFoldingSetTrait - Like DefaultFoldingSetTrait, but for ContextualFoldingSets.
FoldingSetBucketIteratorImpl(void **Bucket)
bool RemoveNode(T *N)
RemoveNode - Remove a node from the folding set, returning true if one was removed or false if the no...
DefaultFoldingSetTrait - This class provides default implementations for FoldingSetTrait implementati...
FoldingSetIterator(void **Bucket)
bool operator!=(FoldingSetNodeIDRef RHS) const
FoldingSetNodeIDRef Intern(BumpPtrAllocator &Allocator) const
Intern - Copy this node's data to a memory region allocated from the given allocator and return a Fol...
static void Profile(const std::pair< T1, T2 > &P, FoldingSetNodeID &ID)
StringRef - Represent a constant reference to a string, i.e.
~FoldingSetImpl()=default
bool operator==(const FoldingSetBucketIteratorImpl &RHS) const
FoldingSetBase & operator=(FoldingSetBase &&RHS)
FoldingSetBucketIteratorImpl(void **Bucket, bool)
bool operator!=(const FoldingSetIteratorImpl &RHS) const
FoldingSetBucketIteratorImpl - This is the common bucket iterator support shared by all folding sets...
bool operator!=(const FoldingSetBucketIteratorImpl &RHS) const
bool operator==(FoldingSetNodeIDRef) const
static void Profile(T &X, FoldingSetNodeID &ID, Ctx Context)
static bool Equals(T &X, const FoldingSetNodeID &ID, unsigned IDHash, FoldingSetNodeID &TempID, Ctx Context)