LLVM 24.0.0git
llvm::BitVector Class Reference

#include "llvm/ADT/BitVector.h"

Classes

class  reference

Public Types

using size_type = unsigned
using const_set_bits_iterator = const_set_bits_iterator_impl<BitVector>
using set_iterator = const_set_bits_iterator

Public Member Functions

const_set_bits_iterator set_bits_begin () const
const_set_bits_iterator set_bits_end () const
iterator_range< const_set_bits_iterator > set_bits () const
 BitVector ()=default
 BitVector default ctor - Creates an empty bitvector.
 BitVector (unsigned s, bool t=false)
 BitVector ctor - Creates a bitvector of specified number of bits.
bool empty () const
 Returns whether there are no bits in this bitvector.
size_type size () const
 Returns the number of bits in this bitvector.
size_type count () const
 Returns the number of bits which are set.
bool any () const
 Returns true if any bit is set.
bool all () const
 Returns true if all bits are set.
bool none () const
 Returns true if none of the bits are set.
int find_first_in (unsigned Begin, unsigned End, bool Set=true) const
 Returns the index of the first set/unset bit, depending on Set, in the range [Begin, End).
int find_last_in (unsigned Begin, unsigned End) const
 Returns the index of the last set bit in the range [Begin, End).
int find_first_unset_in (unsigned Begin, unsigned End) const
 Returns the index of the first unset bit in the range [Begin, End).
int find_last_unset_in (unsigned Begin, unsigned End) const
 Returns the index of the last unset bit in the range [Begin, End).
int find_first () const
 Returns the index of the first set bit, -1 if none of the bits are set.
int find_last () const
 Returns the index of the last set bit, -1 if none of the bits are set.
int find_next (unsigned Prev) const
 Returns the index of the next set bit following the "Prev" bit.
int find_prev (unsigned PriorTo) const
 Returns the index of the first set bit that precedes the bit at PriorTo.
int find_first_unset () const
 Returns the index of the first unset bit, -1 if all of the bits are set.
int find_next_unset (unsigned Prev) const
 Returns the index of the next unset bit following the Prev bit.
int find_last_unset () const
 Returns the index of the last unset bit, -1 if all of the bits are set.
int find_prev_unset (unsigned PriorTo) const
 Returns the index of the first unset bit that precedes the bit at PriorTo.
void clear ()
 Removes all bits from the bitvector.
void resize (unsigned N, bool t=false)
 Grow or shrink the bitvector.
void reserve (unsigned N)
 Reserve space for atleast N bits in the bitvector.
BitVector & set ()
 Set all bits in the bitvector.
BitVector & set (unsigned Idx)
BitVector & set (unsigned I, unsigned E)
 Efficiently set a range of bits in [I, E)
BitVector & reset ()
 Reset all bits in the bitvector.
BitVector & reset (unsigned Idx)
 Reset bit Idx in the bitvector.
BitVector & reset (unsigned I, unsigned E)
 Efficiently reset a range of bits in [I, E)
BitVector & flip ()
 Flip all bits in the bitvector.
BitVector & flip (unsigned Idx)
 Flip bit Idx in the bitvector.
reference operator[] (unsigned Idx)
bool operator[] (unsigned Idx) const
bool back () const
 Return the last element in the bitvector.
bool test (unsigned Idx) const
 Returns true if bit Idx is set.
bool test_all (unsigned Begin, unsigned End) const
 Returns true if all bits in the range [Begin, End) are set.
bool test_any (unsigned Begin, unsigned End) const
 Returns true if any of the bits in the range [Begin, End) are set.
void push_back (bool Val)
void pop_back ()
 Pop one bit from the end of the vector.
bool anyCommon (const BitVector &RHS) const
 Test if any common bits are set.
bool operator== (const BitVector &RHS) const
bool operator!= (const BitVector &RHS) const
BitVector & operator&= (const BitVector &RHS)
 Intersection of this bitvector with RHS.
BitVector & reset (const BitVector &RHS)
 Reset bits that are set in RHS. Same as *this &= ~RHS.
bool test (const BitVector &RHS) const
 Check if (This - RHS) is non-zero.
bool subsetOf (const BitVector &RHS) const
 Check if This is a subset of RHS.
BitVector & operator|= (const BitVector &RHS)
 Union of this bitvector with RHS.
BitVector & operator^= (const BitVector &RHS)
 Disjoint union of this bitvector with RHS.
BitVector & operator>>= (unsigned N)
BitVector & operator<<= (unsigned N)
void swap (BitVector &RHS)
ArrayRef< BitWord > getData () const
void setBitsInMask (const uint32_t *Mask, unsigned MaskWords=~0u)
 Add '1' bits from Mask to this vector.
void clearBitsInMask (const uint32_t *Mask, unsigned MaskWords=~0u)
 Clear any bits in this vector that are set in Mask.
void setBitsNotInMask (const uint32_t *Mask, unsigned MaskWords=~0u)
 Add a bit to this vector for every '0' bit in Mask.
void clearBitsNotInMask (const uint32_t *Mask, unsigned MaskWords=~0u)
 Clear a bit in this vector for every '0' bit in Mask.
size_type getMemorySize () const
 Return the size (in bytes) of the bit vector.
size_type getBitCapacity () const

Static Public Member Functions

template<class F, class... ArgTys>
static BitVector & apply (F &&f, BitVector &Out, BitVector const &Arg, ArgTys const &...Args)

Detailed Description

Definition at line 102 of file BitVector.h.

Member Typedef Documentation

◆ const_set_bits_iterator

◆ set_iterator

◆ size_type

Definition at line 116 of file BitVector.h.

Constructor & Destructor Documentation

◆ BitVector() [1/2]

◆ BitVector() [2/2]

llvm::BitVector::BitVector ( unsigned s,
bool t = false )
inlineexplicit

BitVector ctor - Creates a bitvector of specified number of bits.

All bits are initialized to the specified value.

Definition at line 169 of file BitVector.h.

Member Function Documentation

◆ all()

bool llvm::BitVector::all ( ) const
inline

Returns true if all bits are set.

Definition at line 195 of file BitVector.h.

Referenced by isInterestingPHIIncomingValue(), and matchIndexAsShuffle().

◆ any()

bool llvm::BitVector::any ( ) const
inline

◆ anyCommon()

bool llvm::BitVector::anyCommon ( const BitVector & RHS) const
inline

Test if any common bits are set.

Definition at line 529 of file BitVector.h.

References BitVector(), and RHS.

Referenced by llvm::HexagonLiveVariables::isDefLiveIn().

◆ apply()

template<class F, class... ArgTys>
BitVector & llvm::BitVector::apply ( F && f,
BitVector & Out,
BitVector const & Arg,
ArgTys const &... Args )
inlinestatic

◆ back()

bool llvm::BitVector::back ( ) const
inline

Return the last element in the bitvector.

Definition at line 477 of file BitVector.h.

References assert(), empty(), and size().

◆ clear()

◆ clearBitsInMask()

void llvm::BitVector::clearBitsInMask ( const uint32_t * Mask,
unsigned MaskWords = ~0u )
inline

Clear any bits in this vector that are set in Mask.

Don't resize. This computes "*this &= ~Mask".

Definition at line 749 of file BitVector.h.

Referenced by llvm::SIFrameLowering::determineCalleeSaves(), and llvm::SIFrameLowering::determineCalleeSavesSGPR().

◆ clearBitsNotInMask()

void llvm::BitVector::clearBitsNotInMask ( const uint32_t * Mask,
unsigned MaskWords = ~0u )
inline

Clear a bit in this vector for every '0' bit in Mask.

Don't resize. This computes "*this &= Mask".

Definition at line 761 of file BitVector.h.

Referenced by llvm::LiveIntervals::checkRegMaskInterference(), and llvm::SIFrameLowering::determineCalleeSaves().

◆ count()

◆ empty()

bool llvm::BitVector::empty ( ) const
inline

◆ find_first()

◆ find_first_in()

int llvm::BitVector::find_first_in ( unsigned Begin,
unsigned End,
bool Set = true ) const
inline

Returns the index of the first set/unset bit, depending on Set, in the range [Begin, End).

Returns -1 if all bits in the range are unset/set.

Definition at line 214 of file BitVector.h.

References assert(), llvm::countr_zero(), llvm::End, llvm::maskTrailingOnes(), and llvm::maskTrailingZeros().

Referenced by find_first(), find_first_unset_in(), and find_next().

◆ find_first_unset()

int llvm::BitVector::find_first_unset ( ) const
inline

Returns the index of the first unset bit, -1 if all of the bits are set.

Definition at line 332 of file BitVector.h.

References find_first_unset_in().

◆ find_first_unset_in()

int llvm::BitVector::find_first_unset_in ( unsigned Begin,
unsigned End ) const
inline

Returns the index of the first unset bit in the range [Begin, End).

Returns -1 if all bits in the range are set.

Definition at line 280 of file BitVector.h.

References llvm::End, and find_first_in().

Referenced by find_first_unset(), find_next_unset(), and removeRedundantDbgLocsUsingBackwardScan().

◆ find_last()

int llvm::BitVector::find_last ( ) const
inline

Returns the index of the last set bit, -1 if none of the bits are set.

Definition at line 321 of file BitVector.h.

References find_last_in().

◆ find_last_in()

int llvm::BitVector::find_last_in ( unsigned Begin,
unsigned End ) const
inline

Returns the index of the last set bit in the range [Begin, End).

Returns -1 if all bits in the range are unset.

Definition at line 249 of file BitVector.h.

References assert(), llvm::countl_zero(), llvm::End, llvm::maskTrailingOnes(), and llvm::maskTrailingZeros().

Referenced by find_last(), and find_prev().

◆ find_last_unset()

int llvm::BitVector::find_last_unset ( ) const
inline

Returns the index of the last unset bit, -1 if all of the bits are set.

Definition at line 341 of file BitVector.h.

References find_last_unset_in().

◆ find_last_unset_in()

int llvm::BitVector::find_last_unset_in ( unsigned Begin,
unsigned End ) const
inline

Returns the index of the last unset bit in the range [Begin, End).

Returns -1 if all bits in the range are set.

Definition at line 286 of file BitVector.h.

References assert(), llvm::countl_one(), llvm::End, llvm::maskTrailingOnes(), and llvm::maskTrailingZeros().

Referenced by find_last_unset(), and find_prev_unset().

◆ find_next()

int llvm::BitVector::find_next ( unsigned Prev) const
inline

Returns the index of the next set bit following the "Prev" bit.

Returns -1 if the next set bit is not found.

Definition at line 325 of file BitVector.h.

References find_first_in().

Referenced by llvm::HexagonFrameLowering::assignCalleeSavedSpillSlots(), llvm::X86FrameLowering::determineCalleeSaves(), dump_registers(), llvm::rdf::RegisterAggr::makeRegRef(), needsStackFrame(), llvm::rdf::RegisterAggr::ref_iterator::ref_iterator(), and scavengeStackSlot().

◆ find_next_unset()

int llvm::BitVector::find_next_unset ( unsigned Prev) const
inline

Returns the index of the next unset bit following the Prev bit.

Returns -1 if all remaining bits are set.

Definition at line 336 of file BitVector.h.

References find_first_unset_in().

◆ find_prev()

int llvm::BitVector::find_prev ( unsigned PriorTo) const
inline

Returns the index of the first set bit that precedes the bit at PriorTo.

Returns -1 if all previous bits are unset.

Definition at line 329 of file BitVector.h.

References find_last_in().

◆ find_prev_unset()

int llvm::BitVector::find_prev_unset ( unsigned PriorTo) const
inline

Returns the index of the first unset bit that precedes the bit at PriorTo.

Returns -1 if all previous bits are set.

Definition at line 345 of file BitVector.h.

References find_last_unset_in().

◆ flip() [1/2]

BitVector & llvm::BitVector::flip ( )
inline

Flip all bits in the bitvector.

Definition at line 451 of file BitVector.h.

References BitVector().

◆ flip() [2/2]

BitVector & llvm::BitVector::flip ( unsigned Idx)
inline

Flip bit Idx in the bitvector.

Definition at line 459 of file BitVector.h.

References BitVector().

◆ getBitCapacity()

size_type llvm::BitVector::getBitCapacity ( ) const
inline

Definition at line 861 of file BitVector.h.

Referenced by push_back().

◆ getData()

ArrayRef< BitWord > llvm::BitVector::getData ( ) const
inline

Definition at line 727 of file BitVector.h.

◆ getMemorySize()

size_type llvm::BitVector::getMemorySize ( ) const
inline

Return the size (in bytes) of the bit vector.

Definition at line 860 of file BitVector.h.

◆ none()

◆ operator!=()

bool llvm::BitVector::operator!= ( const BitVector & RHS) const
inline

Definition at line 546 of file BitVector.h.

References BitVector(), and RHS.

◆ operator&=()

BitVector & llvm::BitVector::operator&= ( const BitVector & RHS)
inline

Intersection of this bitvector with RHS.

Definition at line 549 of file BitVector.h.

References BitVector(), RHS, and size().

◆ operator<<=()

BitVector & llvm::BitVector::operator<<= ( unsigned N)
inline

Definition at line 672 of file BitVector.h.

References assert(), BitVector(), empty(), I, LLVM_UNLIKELY, llvm::maskLeadingOnes(), and N.

◆ operator==()

bool llvm::BitVector::operator== ( const BitVector & RHS) const
inline

Definition at line 539 of file BitVector.h.

References BitVector(), RHS, and size().

◆ operator>>=()

BitVector & llvm::BitVector::operator>>= ( unsigned N)
inline

Definition at line 623 of file BitVector.h.

References assert(), BitVector(), empty(), I, LLVM_UNLIKELY, llvm::maskTrailingOnes(), and N.

◆ operator[]() [1/2]

reference llvm::BitVector::operator[] ( unsigned Idx)
inline

Definition at line 465 of file BitVector.h.

References assert().

◆ operator[]() [2/2]

bool llvm::BitVector::operator[] ( unsigned Idx) const
inline

Definition at line 470 of file BitVector.h.

References assert().

◆ operator^=()

BitVector & llvm::BitVector::operator^= ( const BitVector & RHS)
inline

Disjoint union of this bitvector with RHS.

Definition at line 615 of file BitVector.h.

References BitVector(), E(), I, resize(), RHS, and size().

◆ operator|=()

BitVector & llvm::BitVector::operator|= ( const BitVector & RHS)
inline

Union of this bitvector with RHS.

Definition at line 606 of file BitVector.h.

References BitVector(), E(), I, resize(), RHS, and size().

◆ pop_back()

void llvm::BitVector::pop_back ( )
inline

Pop one bit from the end of the vector.

Definition at line 523 of file BitVector.h.

References assert(), empty(), resize(), and size().

◆ push_back()

void llvm::BitVector::push_back ( bool Val)
inline

◆ reserve()

void llvm::BitVector::reserve ( unsigned N)
inline

Reserve space for atleast N bits in the bitvector.

Definition at line 364 of file BitVector.h.

References N.

Referenced by llvm::SmallBitVector::reserve().

◆ reset() [1/4]

◆ reset() [2/4]

BitVector & llvm::BitVector::reset ( const BitVector & RHS)
inline

Reset bits that are set in RHS. Same as *this &= ~RHS.

Definition at line 566 of file BitVector.h.

References BitVector(), RHS, and size().

◆ reset() [3/4]

BitVector & llvm::BitVector::reset ( unsigned I,
unsigned E )
inline

Efficiently reset a range of bits in [I, E)

Definition at line 422 of file BitVector.h.

References alignTo(), assert(), BitVector(), E(), I, and size().

◆ reset() [4/4]

BitVector & llvm::BitVector::reset ( unsigned Idx)
inline

Reset bit Idx in the bitvector.

Definition at line 416 of file BitVector.h.

References BitVector().

◆ resize()

◆ set() [1/3]

BitVector & llvm::BitVector::set ( )
inline

Set all bits in the bitvector.

Definition at line 367 of file BitVector.h.

References BitVector().

Referenced by addRegUnits(), llvm::SIMachineFunctionInfo::allocateVGPRSpillToAGPR(), llvm::BlockFrequencyInfoImplBase::analyzeIrreducible(), applyBitsNotInRegMaskToRegUnitsMask(), assignCalleeSavedSpillSlots(), llvm::PPCFrameLowering::assignCalleeSavedSpillSlots(), llvm::TargetRegisterInfo::checkAllSuperRegsMarked(), checkNumAlignedDPRCS2Regs(), llvm::ConnectedVNInfoEqClasses::Classify(), collectCandidateMembers(), collectLoads(), llvm::AArch64FrameLowering::determineCalleeSaves(), llvm::ARCFrameLowering::determineCalleeSaves(), llvm::ARMFrameLowering::determineCalleeSaves(), llvm::AVRFrameLowering::determineCalleeSaves(), llvm::CSKYFrameLowering::determineCalleeSaves(), llvm::HexagonFrameLowering::determineCalleeSaves(), llvm::LoongArchFrameLowering::determineCalleeSaves(), llvm::M68kFrameLowering::determineCalleeSaves(), llvm::Mips16FrameLowering::determineCalleeSaves(), llvm::PPCFrameLowering::determineCalleeSaves(), llvm::RISCVFrameLowering::determineCalleeSaves(), llvm::SystemZELFFrameLowering::determineCalleeSaves(), llvm::SystemZXPLINKFrameLowering::determineCalleeSaves(), llvm::TargetFrameLowering::determineCalleeSaves(), llvm::X86FrameLowering::determineCalleeSaves(), llvm::XtensaFrameLowering::determineCalleeSaves(), llvm::SIFrameLowering::determineCalleeSavesSGPR(), llvm::TargetFrameLowering::determineUncondPrologCalleeSaves(), llvm::finalizeBundle(), llvm::SwitchCG::SwitchLowering::findBitTestClusters(), llvm::SelectionDAG::FoldConstantArithmetic(), getBitVecRegAntiHints(), llvm::ARMFrameLowering::getCalleeSaves(), llvm::TargetFrameLowering::getCalleeSaves(), llvm::BuildVectorSDNode::getConstantRawBits(), getInputSegmentList(), llvm::BasicTTIImplBase< BasicTTIImpl >::getInterleavedMemoryOpCost(), llvm::SystemZTTIImpl::getInterleavedMemoryOpCost(), llvm::IndexedMemProfReader::getMemProfCallerCalleePairs(), llvm::MachineFrameInfo::getPristineRegs(), llvm::ScheduleDAGTopologicalSort::GetSubGraph(), INITIALIZE_PASS(), llvm::HexagonLiveVariables::isDefLiveIn(), isInterestingPHIIncomingValue(), llvm::LiveRangeCalc::isJointlyDominated(), llvm::dwarf_linker::classic::DWARFLinker::link(), loadsMayOverlap(), matchIndexAsShuffle(), llvm::BranchFolder::OptimizeFunction(), llvm::optimizeGlobalCtorsList(), llvm::SIFrameLowering::processFunctionBeforeFrameFinalized(), push_back(), llvm::BuildVectorSDNode::recastRawBits(), regColoring(), removeRedundantDbgLocsUsingBackwardScan(), llvm::SmallBitVector::reserve(), llvm::rdf::Liveness::resetKills(), llvm::PPCFrameLowering::restoreCalleeSavedRegisters(), setAliasRegs(), llvm::SystemZRegisterInfo::shouldCoalesce(), llvm::PPCFrameLowering::spillCalleeSavedRegisters(), and llvm::PPCFrameLowering::updateCalleeSaves().

◆ set() [2/3]

BitVector & llvm::BitVector::set ( unsigned I,
unsigned E )
inline

Efficiently set a range of bits in [I, E)

Definition at line 381 of file BitVector.h.

References alignTo(), assert(), BitVector(), E(), I, and size().

◆ set() [3/3]

BitVector & llvm::BitVector::set ( unsigned Idx)
inline

Definition at line 374 of file BitVector.h.

References assert(), and BitVector().

◆ set_bits()

◆ set_bits_begin()

const_set_bits_iterator llvm::BitVector::set_bits_begin ( ) const
inline

Definition at line 154 of file BitVector.h.

Referenced by set_bits().

◆ set_bits_end()

const_set_bits_iterator llvm::BitVector::set_bits_end ( ) const
inline

Definition at line 157 of file BitVector.h.

Referenced by set_bits().

◆ setBitsInMask()

void llvm::BitVector::setBitsInMask ( const uint32_t * Mask,
unsigned MaskWords = ~0u )
inline

Add '1' bits from Mask to this vector.

Don't resize. This computes "*this |= Mask".

Definition at line 743 of file BitVector.h.

Referenced by llvm::SIMachineFunctionInfo::allocateVGPRSpillToAGPR(), and llvm::TargetLoweringBase::findRepresentativeClass().

◆ setBitsNotInMask()

void llvm::BitVector::setBitsNotInMask ( const uint32_t * Mask,
unsigned MaskWords = ~0u )
inline

Add a bit to this vector for every '0' bit in Mask.

Don't resize. This computes "*this |= ~Mask".

Definition at line 755 of file BitVector.h.

◆ size()

◆ subsetOf()

bool llvm::BitVector::subsetOf ( const BitVector & RHS) const
inline

Check if This is a subset of RHS.

Definition at line 592 of file BitVector.h.

References BitVector(), RHS, and test.

◆ swap()

void llvm::BitVector::swap ( BitVector & RHS)
inline

Definition at line 722 of file BitVector.h.

References BitVector(), RHS, and std::swap().

◆ test() [1/2]

bool llvm::BitVector::test ( const BitVector & RHS) const
inline

Check if (This - RHS) is non-zero.

This is the same as reset(RHS) and any().

Definition at line 576 of file BitVector.h.

References BitVector(), and RHS.

◆ test() [2/2]

bool llvm::BitVector::test ( unsigned Idx) const
inline

Returns true if bit Idx is set.

Definition at line 483 of file BitVector.h.

Referenced by addLiveInRegs(), llvm::BlockFrequencyInfoImplBase::analyzeIrreducible(), assignCalleeSavedSpillSlots(), llvm::AggressiveAntiDepBreaker::BreakAntiDependencies(), checkNumAlignedDPRCS2Regs(), llvm::ConnectedVNInfoEqClasses::Classify(), collectCandidateMembers(), collectLoads(), commitFpm(), llvm::Thumb1InstrInfo::copyPhysReg(), createIrreducibleLoop(), llvm::AArch64FrameLowering::determineCalleeSaves(), llvm::ARMFrameLowering::determineCalleeSaves(), llvm::CSKYFrameLowering::determineCalleeSaves(), llvm::PPCFrameLowering::determineCalleeSaves(), llvm::RISCVFrameLowering::determineCalleeSaves(), llvm::SystemZELFFrameLowering::determineCalleeSaves(), llvm::ARMFrameLowering::emitEpilogue(), EstimateFunctionSizeInBytes(), findFreePredicateReg(), findTemporariesForLR(), llvm::LoongArchTargetLowering::getRegisterByName(), llvm::MipsTargetLowering::getRegisterByName(), llvm::RISCVTargetLowering::getRegisterByName(), llvm::SIRegisterInfo::getReservedRegs(), llvm::ScheduleDAGTopologicalSort::GetSubGraph(), INITIALIZE_PASS(), llvm::TargetRegisterInfo::isAntiHintedReg(), llvm::ARMBaseRegisterInfo::isAsmClobberable(), llvm::PPCRegisterInfo::isAsmClobberable(), llvm::MachineRegisterInfo::isReserved(), isStrictSubset(), isVariantApplicableInContextHelper(), loadsMayOverlap(), llvm::BranchFolder::OptimizeFunction(), llvm::SIFrameLowering::processFunctionBeforeFrameFinalized(), removeGlobalCtors(), scavengeStackSlot(), llvm::CriticalAntiDepBreaker::StartBlock(), llvm::PPCFrameLowering::updateCalleeSaves(), and llvm::LivenessInfo::UpdateLiveness().

◆ test_all()

bool llvm::BitVector::test_all ( unsigned Begin,
unsigned End ) const
inline

Returns true if all bits in the range [Begin, End) are set.

Definition at line 488 of file BitVector.h.

References llvm::End, and test.

◆ test_any()

bool llvm::BitVector::test_any ( unsigned Begin,
unsigned End ) const
inline

Returns true if any of the bits in the range [Begin, End) are set.

Definition at line 497 of file BitVector.h.

References llvm::End, and test.


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