LLVM 24.0.0git
llvm::FoldingSetBase Class Reference

Non-templated base class for FoldingSet and ContextualFoldingSet, holding the memory management and probing that does not depend on the node type. More...

#include "llvm/ADT/FoldingSet.h"

Inheritance diagram for llvm::FoldingSetBase:
[legend]

Classes

struct  FoldingSetInfo
 Functions provided by the derived class to compute folding properties. More...
class  Node
 This class is used to maintain node state in a folding set. More...

Public Member Functions

LLVM_ABI void clear ()
 Remove all nodes from the folding set.
unsigned size () const
 Returns the number of nodes in the folding set.
bool empty () const
 Returns true if there are no nodes 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.
Public Member Functions inherited from llvm::DebugEpochBase
void incrementEpoch ()

Protected Member Functions

LLVM_ABI FoldingSetBase (unsigned Log2InitSize)
LLVM_ABI FoldingSetBase (FoldingSetBase &&Arg)
LLVM_ABI FoldingSetBaseoperator= (FoldingSetBase &&RHS)
LLVM_ABI ~FoldingSetBase ()
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 the folding set.
LLVM_ABI NodeGetOrInsertNode (Node *N, const FoldingSetInfo &Info)
 If there is an existing node exactly equal to the node N, return it.
LLVM_ABI NodeFindNodeOrInsertPos (const FoldingSetNodeID &ID, void *&InsertPos, const FoldingSetInfo &Info)
 Look up the node specified by ID.
LLVM_ABI void InsertNode (Node *N, void *InsertPos)
 Insert the specified node into the folding set, knowing that it is not already in the folding set.

Protected Attributes

void ** Buckets = nullptr
 Array of node pointers; a null entry marks an empty slot.
unsigned NumBuckets = 0
 Length of the Buckets array. Always a power of 2.
unsigned NumNodes = 0
 Number of nodes in the folding set.

Detailed Description

Non-templated base class for FoldingSet and ContextualFoldingSet, holding the memory management and probing that does not depend on the node type.

Definition at line 294 of file FoldingSet.h.

Constructor & Destructor Documentation

◆ FoldingSetBase() [1/2]

FoldingSetBase::FoldingSetBase ( unsigned Log2InitSize)
explicitprotected

Definition at line 145 of file FoldingSet.cpp.

References assert(), Buckets, NumBuckets, and llvm::safe_calloc().

Referenced by FoldingSetBase(), and operator=().

◆ FoldingSetBase() [2/2]

FoldingSetBase::FoldingSetBase ( FoldingSetBase && Arg)
protected

Definition at line 152 of file FoldingSet.cpp.

References Buckets, FoldingSetBase(), NumBuckets, and NumNodes.

◆ ~FoldingSetBase()

FoldingSetBase::~FoldingSetBase ( )
protected

Definition at line 172 of file FoldingSet.cpp.

References Buckets.

Member Function Documentation

◆ clear()

void FoldingSetBase::clear ( )

Remove all nodes from the folding set.

Definition at line 174 of file FoldingSet.cpp.

References Buckets, llvm::DebugEpochBase::incrementEpoch(), NumBuckets, and NumNodes.

◆ empty()

bool llvm::FoldingSetBase::empty ( ) const
inlinenodiscard

Returns true if there are no nodes in the folding set.

Definition at line 334 of file FoldingSet.h.

References NumNodes.

◆ FindNodeOrInsertPos()

FoldingSetBase::Node * FoldingSetBase::FindNodeOrInsertPos ( const FoldingSetNodeID & ID,
void *& InsertPos,
const FoldingSetInfo & Info )
protected

Look up the node specified by ID.

If it exists, return it. If not, return the insertion token that will make insertion faster.

Definition at line 222 of file FoldingSet.cpp.

References Buckets, encodeHash(), I, N, and NumBuckets.

Referenced by llvm::FoldingSetImpl< T, Trait >< ListTy >::FindNodeOrInsertPos(), and GetOrInsertNode().

◆ GetOrInsertNode()

FoldingSetBase::Node * FoldingSetBase::GetOrInsertNode ( Node * N,
const FoldingSetInfo & Info )
protected

If there is an existing node exactly equal to the node N, return it.

Otherwise, insert N and return it instead.

Definition at line 280 of file FoldingSet.cpp.

References FindNodeOrInsertPos(), InsertNode(), and N.

Referenced by llvm::FoldingSetImpl< T, Trait >< ListTy >::GetOrInsertNode().

◆ InsertNode()

void FoldingSetBase::InsertNode ( Node * N,
void * InsertPos )
protected

Insert the specified node into the folding set, knowing that it is not already in the folding set.

InsertPos must be obtained from FindNodeOrInsertPos for an ID that N profiles identically to.

Definition at line 238 of file FoldingSet.cpp.

References assert(), decodeHash(), llvm::DebugEpochBase::incrementEpoch(), LLVM_UNLIKELY, N, NumBuckets, and NumNodes.

Referenced by GetOrInsertNode(), and llvm::FoldingSetImpl< T, Trait >< ListTy >::InsertNode().

◆ operator=()

FoldingSetBase & FoldingSetBase::operator= ( FoldingSetBase && RHS)
protected

◆ RemoveNode()

bool FoldingSetBase::RemoveNode ( Node * N)
protected

Remove a node from the folding set, returning true if one was removed or false if the node was not in the folding set.

Definition at line 249 of file FoldingSet.cpp.

References Buckets, I, llvm::DebugEpochBase::incrementEpoch(), LLVM_UNLIKELY, N, llvm::FoldingSetNodeIDRef::NotAHash, NumBuckets, and NumNodes.

Referenced by llvm::FoldingSetImpl< T, Trait >< ListTy >::RemoveNode().

◆ reserve()

void FoldingSetBase::reserve ( unsigned N)

Grow the number of buckets so that we can hold at least N nodes before rebucketing.

May allocate more space than requested.

Definition at line 207 of file FoldingSet.cpp.

References N, and NumBuckets.

◆ size()

unsigned llvm::FoldingSetBase::size ( ) const
inline

Returns the number of nodes in the folding set.

Definition at line 331 of file FoldingSet.h.

References NumNodes.

Member Data Documentation

◆ Buckets

◆ NumBuckets

◆ NumNodes

unsigned llvm::FoldingSetBase::NumNodes = 0
protected

Number of nodes in the folding set.

Definition at line 303 of file FoldingSet.h.

Referenced by clear(), empty(), FoldingSetBase(), InsertNode(), operator=(), RemoveNode(), and size().


The documentation for this class was generated from the following files: