LLVM 19.0.0git
Classes | Public Types | Public Member Functions | List of all members
llvm::SetVector< T, Vector, Set, N > Class Template Reference

A vector that has set insertion semantics. More...

#include "llvm/ADT/SetVector.h"

Inherited by llvm::SmallSetVector< MachineInstr *, 2 >, llvm::SmallSetVector< unsigned, 32 >, llvm::SmallSetVector< DepTy, 2 >, llvm::SmallSetVector< llvm::Function *, 8 >, llvm::SmallSetVector< llvm::WeakVH, 16 >, llvm::SmallSetVector< llvm::BasicBlock *, 8 >, llvm::SmallSetVector< llvm::WeakVH, 8 >, llvm::SmallSetVector< llvm::AbstractAttribute *, 16 >, llvm::SmallSetVector< const llvm::DISubprogram *, 4 >, llvm::SmallSetVector< const llvm::DISubprogram *, 16 >, llvm::SmallSetVector< llvm::Instruction *, 8 >, llvm::SmallSetVector< llvm::Instruction *, 16 >, llvm::SmallSetVector< llvm::Function *, 4 >, llvm::SmallSetVector< llvm::MCSection *, 4 >, llvm::SmallSetVector< MemberTy, 8 >, llvm::SmallSetVector< const llvm::LiveInterval *, 8 >, llvm::SmallSetVector< Register, 8 >, llvm::SmallSetVector< llvm::ElementCount, 2 >, and llvm::SmallSetVector< unsigned, 2 >.

Public Types

using value_type = typename Vector::value_type
 
using key_type = typename Set::key_type
 
using reference = value_type &
 
using const_reference = const value_type &
 
using set_type = Set
 
using vector_type = Vector
 
using iterator = typename vector_type::const_iterator
 
using const_iterator = typename vector_type::const_iterator
 
using reverse_iterator = typename vector_type::const_reverse_iterator
 
using const_reverse_iterator = typename vector_type::const_reverse_iterator
 
using size_type = typename vector_type::size_type
 

Public Member Functions

 SetVector ()=default
 Construct an empty SetVector.
 
template<typename It >
 SetVector (It Start, It End)
 Initialize a SetVector with a range of elements.
 
ArrayRef< value_typegetArrayRef () const
 
Vector takeVector ()
 Clear the SetVector and return the underlying vector.
 
bool empty () const
 Determine if the SetVector is empty or not.
 
size_type size () const
 Determine the number of elements in the SetVector.
 
iterator begin ()
 Get an iterator to the beginning of the SetVector.
 
const_iterator begin () const
 Get a const_iterator to the beginning of the SetVector.
 
iterator end ()
 Get an iterator to the end of the SetVector.
 
const_iterator end () const
 Get a const_iterator to the end of the SetVector.
 
reverse_iterator rbegin ()
 Get an reverse_iterator to the end of the SetVector.
 
const_reverse_iterator rbegin () const
 Get a const_reverse_iterator to the end of the SetVector.
 
reverse_iterator rend ()
 Get a reverse_iterator to the beginning of the SetVector.
 
const_reverse_iterator rend () const
 Get a const_reverse_iterator to the beginning of the SetVector.
 
const value_typefront () const
 Return the first element of the SetVector.
 
const value_typeback () const
 Return the last element of the SetVector.
 
const_reference operator[] (size_type n) const
 Index into the SetVector.
 
bool insert (const value_type &X)
 Insert a new element into the SetVector.
 
template<typename It >
void insert (It Start, It End)
 Insert a range of elements into the SetVector.
 
bool remove (const value_type &X)
 Remove an item from the set vector.
 
iterator erase (const_iterator I)
 Erase a single element from the set vector.
 
template<typename UnaryPredicate >
bool remove_if (UnaryPredicate P)
 Remove items from the set vector based on a predicate function.
 
bool contains (const key_type &key) const
 Check if the SetVector contains the given key.
 
size_type count (const key_type &key) const
 Count the number of elements of a given key in the SetVector.
 
void clear ()
 Completely clear the SetVector.
 
void pop_back ()
 Remove the last element of the SetVector.
 
value_type pop_back_val ()
 
bool operator== (const SetVector &that) const
 
bool operator!= (const SetVector &that) const
 
template<class STy >
bool set_union (const STy &S)
 Compute This := This u S, return whether 'This' changed.
 
template<class STy >
void set_subtract (const STy &S)
 Compute This := This - B TODO: We should be able to use set_subtract from SetOperations.h, but SetVector interface is inconsistent with DenseSet.
 
void swap (SetVector< T, Vector, Set, N > &RHS)
 

Detailed Description

template<typename T, typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
class llvm::SetVector< T, Vector, Set, N >

A vector that has set insertion semantics.

This adapter class provides a way to keep a set of things that also has the property of a deterministic iteration order. The order of iteration is the order of insertion.

The key and value types are derived from the Set and Vector types respectively. This allows the vector-type operations and set-type operations to have different types. In particular, this is useful when storing pointers as "Foo *" values but looking them up as "const Foo *" keys.

No constraint is placed on the key and value types, although it is assumed that value_type can be converted into key_type for insertion. Users must be aware of any loss of information in this conversion. For example, setting value_type to float and key_type to int can produce very surprising results, but it is not explicitly disallowed.

The parameter N specifies the "small" size of the container, which is the number of elements upto which a linear scan over the Vector will be used when searching for elements instead of checking Set, due to it being better for performance. A value of 0 means that this mode of operation is not used, and is the default value.

Definition at line 57 of file SetVector.h.

Member Typedef Documentation

◆ const_iterator

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
using llvm::SetVector< T, Vector, Set, N >::const_iterator = typename vector_type::const_iterator

Definition at line 70 of file SetVector.h.

◆ const_reference

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
using llvm::SetVector< T, Vector, Set, N >::const_reference = const value_type &

Definition at line 66 of file SetVector.h.

◆ const_reverse_iterator

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
using llvm::SetVector< T, Vector, Set, N >::const_reverse_iterator = typename vector_type::const_reverse_iterator

Definition at line 72 of file SetVector.h.

◆ iterator

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
using llvm::SetVector< T, Vector, Set, N >::iterator = typename vector_type::const_iterator

Definition at line 69 of file SetVector.h.

◆ key_type

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
using llvm::SetVector< T, Vector, Set, N >::key_type = typename Set::key_type

Definition at line 64 of file SetVector.h.

◆ reference

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
using llvm::SetVector< T, Vector, Set, N >::reference = value_type &

Definition at line 65 of file SetVector.h.

◆ reverse_iterator

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
using llvm::SetVector< T, Vector, Set, N >::reverse_iterator = typename vector_type::const_reverse_iterator

Definition at line 71 of file SetVector.h.

◆ set_type

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
using llvm::SetVector< T, Vector, Set, N >::set_type = Set

Definition at line 67 of file SetVector.h.

◆ size_type

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
using llvm::SetVector< T, Vector, Set, N >::size_type = typename vector_type::size_type

Definition at line 73 of file SetVector.h.

◆ value_type

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
using llvm::SetVector< T, Vector, Set, N >::value_type = typename Vector::value_type

Definition at line 63 of file SetVector.h.

◆ vector_type

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
using llvm::SetVector< T, Vector, Set, N >::vector_type = Vector

Definition at line 68 of file SetVector.h.

Constructor & Destructor Documentation

◆ SetVector() [1/2]

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
llvm::SetVector< T, Vector, Set, N >::SetVector ( )
default

Construct an empty SetVector.

◆ SetVector() [2/2]

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
template<typename It >
llvm::SetVector< T, Vector, Set, N >::SetVector ( It  Start,
It  End 
)
inline

Initialize a SetVector with a range of elements.

Definition at line 80 of file SetVector.h.

References End, and llvm::SetVector< T, Vector, Set, N >::insert().

Member Function Documentation

◆ back()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
const value_type & llvm::SetVector< T, Vector, Set, N >::back ( ) const
inline

◆ begin() [1/2]

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
iterator llvm::SetVector< T, Vector, Set, N >::begin ( )
inline

◆ begin() [2/2]

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
const_iterator llvm::SetVector< T, Vector, Set, N >::begin ( ) const
inline

Get a const_iterator to the beginning of the SetVector.

Definition at line 108 of file SetVector.h.

◆ clear()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
void llvm::SetVector< T, Vector, Set, N >::clear ( )
inline

◆ contains()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
bool llvm::SetVector< T, Vector, Set, N >::contains ( const key_type key) const
inline

◆ count()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
size_type llvm::SetVector< T, Vector, Set, N >::count ( const key_type key) const
inline

◆ empty()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
bool llvm::SetVector< T, Vector, Set, N >::empty ( ) const
inline

◆ end() [1/2]

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
iterator llvm::SetVector< T, Vector, Set, N >::end ( )
inline

◆ end() [2/2]

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
const_iterator llvm::SetVector< T, Vector, Set, N >::end ( ) const
inline

Get a const_iterator to the end of the SetVector.

Definition at line 118 of file SetVector.h.

◆ erase()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
iterator llvm::SetVector< T, Vector, Set, N >::erase ( const_iterator  I)
inline

Erase a single element from the set vector.

Returns
an iterator pointing to the next element that followed the element erased. This is the end of the SetVector if the last element is erased.

Definition at line 212 of file SetVector.h.

References assert(), and I.

◆ front()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
const value_type & llvm::SetVector< T, Vector, Set, N >::front ( ) const
inline

Return the first element of the SetVector.

Definition at line 143 of file SetVector.h.

References assert(), and llvm::SetVector< T, Vector, Set, N >::empty().

Referenced by llvm::DGNode< NodeType, EdgeType >::front(), and makeReducible().

◆ getArrayRef()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
ArrayRef< value_type > llvm::SetVector< T, Vector, Set, N >::getArrayRef ( ) const
inline

◆ insert() [1/2]

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
bool llvm::SetVector< T, Vector, Set, N >::insert ( const value_type X)
inline

Insert a new element into the SetVector.

Returns
true if the element was inserted into the SetVector.

Definition at line 162 of file SetVector.h.

References llvm::is_contained(), N, and X.

Referenced by llvm::InstructionWorklist::add(), llvm::DGNode< NodeType, EdgeType >::addEdge(), llvm::MCContext::addGenDwarfSection(), llvm::InstrProfWriter::addTemporalProfileTraces(), llvm::VPlan::addVF(), analyzeExitPHIsForOutputUses(), llvm::InterleavedAccessInfo::analyzeInterleaving(), analyzeLoopUnrollCost(), llvm::CombinerHelper::applyExtendThroughPhis(), buildClonedLoops(), llvm::LoopVectorizationCostModel::calculateRegisterUsage(), canRewriteGEPAsOffset(), llvm::VPlanTransforms::clearReductionWrapFlags(), llvm::CloneAndPruneIntoFromInst(), computeBlocksDominatingExits(), computeFunctionSummary(), computeKillSet(), llvm::rdf::Liveness::computeLiveIns(), computeLiveInValues(), computeLiveOutSeed(), llvm::rdf::Liveness::computePhiInfo(), llvm::MDNode::concatenate(), llvm::MachO::convertToInterfaceFile(), llvm::convertUsersOfConstantsToInstructions(), llvm::DwarfCompileUnit::createAndAddScopeChildren(), llvm::TemporalProfTraceTy::createBPFunctionNodes(), llvm::Combiner::WorkListMaintainer::createdInstr(), createNaturalLoopInternal(), DCEInstruction(), deleteDeadBlocksFromLoop(), llvm::HexagonFrameLowering::determineCalleeSaves(), llvm::DGNode< NodeType, EdgeType >::DGNode(), llvm::LLVMContextImpl::dropTriviallyDeadConstantArrays(), eraseLifetimeMarkersOnInputs(), llvm::HexagonEvaluator::evaluate(), llvm::SetTheory::evaluate(), llvm::CodeExtractor::excludeArgFromAggregate(), llvm::CodeExtractor::findAllocas(), findBestInsertionSet(), llvm::CodeExtractor::findInputsOutputs(), llvm::FunctionPropertiesUpdater::finish(), llvm::formLCSSAForInstructions(), llvm::rdf::Liveness::getAllReachingDefs(), getLeastCommonType(), llvm::MDNode::getMostGenericAliasScope(), llvm::DWARFYAML::Data::getNonEmptySectionNames(), getPlanEntry(), llvm::AliasSet::getPointers(), getPotentialCopiesOfMemoryValue(), llvm::FunctionImporter::importFunctions(), llvm::SetVector< T, Vector, Set, N >::insert(), llvm::NodeSet::insert(), insertIfNamed(), insertTrivialPHIs(), isFunctionMallocLike(), llvm::LiveRangeCalc::isJointlyDominated(), llvm::AA::isPotentiallyAffectedByBarrier(), isReturnNonNull(), isVectorPromotionViable(), LinearizeExprTree(), lowerStatepointMetaArgs(), makeReducible(), mergeReplicateRegionsIntoSuccessors(), SlotIndexUpdateDelegate::MF_HandleInsertion(), NegateValue(), pred_L(), llvm::Attributor::registerAA(), remapExtractedInputs(), llvm::MemorySSAUpdater::removeMemoryAccess(), llvm::removeUnreachableBlocks(), llvm::slpvectorizer::BoUpSLP::reorderBottomToTop(), replaceAndRecursivelySimplifyImpl(), llvm::SIMachineFunctionInfo::reserveWWMRegister(), llvm::AttributorCGSCCPass::run(), llvm::AttributorLightCGSCCPass::run(), llvm::AttributorPass::run(), llvm::AttributorLightPass::run(), llvm::OpenMPOptPass::run(), runAttributorOnFunctions(), llvm::PlaceSafepointsPass::runImpl(), runIPSCCP(), llvm::SetVector< T, Vector, Set, N >::set_union(), llvm::VPlan::setUF(), llvm::SetVector< T, Vector, Set, N >::SetVector(), llvm::VPlan::setVF(), llvm::SIMachineFunctionInfo::shiftSpillPhysVGPRsToLowestRange(), simplifyAndDCEInstruction(), simplifyOneLoop(), llvm::InnerLoopVectorizer::sinkScalarOperands(), sinkScalarOperands(), sinkSpillUsesAfterCoroBegin(), sortBlocks(), llvm::SplitIndirectBrCriticalEdges(), succ_L(), tryInterleave(), unifyLoopExits(), llvm::UnrollLoop(), unswitchNontrivialInvariants(), updateCGAndAnalysisManagerForPass(), and llvm::slpvectorizer::BoUpSLP::vectorizeTree().

◆ insert() [2/2]

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
template<typename It >
void llvm::SetVector< T, Vector, Set, N >::insert ( It  Start,
It  End 
)
inline

Insert a range of elements into the SetVector.

Definition at line 182 of file SetVector.h.

References End, and llvm::SetVector< T, Vector, Set, N >::insert().

◆ operator!=()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
bool llvm::SetVector< T, Vector, Set, N >::operator!= ( const SetVector< T, Vector, Set, N > &  that) const
inline

Definition at line 295 of file SetVector.h.

◆ operator==()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
bool llvm::SetVector< T, Vector, Set, N >::operator== ( const SetVector< T, Vector, Set, N > &  that) const
inline

Definition at line 291 of file SetVector.h.

◆ operator[]()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
const_reference llvm::SetVector< T, Vector, Set, N >::operator[] ( size_type  n) const
inline

Index into the SetVector.

Definition at line 155 of file SetVector.h.

References assert().

◆ pop_back()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
void llvm::SetVector< T, Vector, Set, N >::pop_back ( )
inline

◆ pop_back_val()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
value_type llvm::SetVector< T, Vector, Set, N >::pop_back_val ( )
inline

◆ rbegin() [1/2]

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
reverse_iterator llvm::SetVector< T, Vector, Set, N >::rbegin ( )
inline

Get an reverse_iterator to the end of the SetVector.

Definition at line 123 of file SetVector.h.

◆ rbegin() [2/2]

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
const_reverse_iterator llvm::SetVector< T, Vector, Set, N >::rbegin ( ) const
inline

Get a const_reverse_iterator to the end of the SetVector.

Definition at line 128 of file SetVector.h.

◆ remove()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
bool llvm::SetVector< T, Vector, Set, N >::remove ( const value_type X)
inline

◆ remove_if()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
template<typename UnaryPredicate >
bool llvm::SetVector< T, Vector, Set, N >::remove_if ( UnaryPredicate  P)
inline

Remove items from the set vector based on a predicate function.

This is intended to be equivalent to the following code, if we could write it:

V.erase(remove_if(V, P), V.end());
#define P(N)
bool remove_if(UnaryPredicate P)
Remove items from the set vector based on a predicate function.
Definition: SetVector.h:237

However, SetVector doesn't expose non-const iterators, making any algorithm like remove_if impossible to use.

Returns
true if any element is removed.

Definition at line 237 of file SetVector.h.

References I, P, and llvm::remove_if().

Referenced by llvm::MDNode::intersect(), and llvm::NodeSet::remove_if().

◆ rend() [1/2]

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
reverse_iterator llvm::SetVector< T, Vector, Set, N >::rend ( )
inline

Get a reverse_iterator to the beginning of the SetVector.

Definition at line 133 of file SetVector.h.

◆ rend() [2/2]

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
const_reverse_iterator llvm::SetVector< T, Vector, Set, N >::rend ( ) const
inline

Get a const_reverse_iterator to the beginning of the SetVector.

Definition at line 138 of file SetVector.h.

◆ set_subtract()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
template<class STy >
void llvm::SetVector< T, Vector, Set, N >::set_subtract ( const STy &  S)
inline

Compute This := This - B TODO: We should be able to use set_subtract from SetOperations.h, but SetVector interface is inconsistent with DenseSet.

Definition at line 318 of file SetVector.h.

References llvm::SetVector< T, Vector, Set, N >::remove().

Referenced by computeLiveInValues().

◆ set_union()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
template<class STy >
bool llvm::SetVector< T, Vector, Set, N >::set_union ( const STy &  S)
inline

Compute This := This u S, return whether 'This' changed.

TODO: We should be able to use set_union from SetOperations.h, but SetVector interface is inconsistent with DenseSet.

Definition at line 303 of file SetVector.h.

References llvm::SetVector< T, Vector, Set, N >::insert().

Referenced by computeLiveInValues(), and llvm::BlockCoverageInference::getDependencies().

◆ size()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
size_type llvm::SetVector< T, Vector, Set, N >::size ( ) const
inline

◆ swap()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
void llvm::SetVector< T, Vector, Set, N >::swap ( SetVector< T, Vector, Set, N > &  RHS)
inline

Definition at line 324 of file SetVector.h.

References RHS.

◆ takeVector()

template<typename T , typename Vector = SmallVector<T, 0>, typename Set = DenseSet<T>, unsigned N = 0>
Vector llvm::SetVector< T, Vector, Set, N >::takeVector ( )
inline

Clear the SetVector and return the underlying vector.

Definition at line 87 of file SetVector.h.

Referenced by computeFunctionSummary(), computeVariableSummary(), llvm::AliasSet::getPointers(), lowerStatepointMetaArgs(), and llvm::removeUnreachableBlocks().


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