[llvm] 894ad26 - Update {Small}BitVector size_type definition
Renato Golin via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 19 03:13:47 PDT 2021
Author: Renato Golin
Date: 2021-08-19T11:13:38+01:00
New Revision: 894ad26bd55f91cbcfd12f5f54426efb859dc14d
URL: https://github.com/llvm/llvm-project/commit/894ad26bd55f91cbcfd12f5f54426efb859dc14d
DIFF: https://github.com/llvm/llvm-project/commit/894ad26bd55f91cbcfd12f5f54426efb859dc14d.diff
LOG: Update {Small}BitVector size_type definition
SmallBitVector implements a level of indirection over BitVector by
storing a smaller bit-vector in a pointer-sized element, or in case the
number of elements exceeds the bucket size, it creates a new pointer to
a BitVector and uses that as its storage.
However, the functions returning the vector size were using `unsigned`,
which is ok for BitVector, but not for SmallBitVector, which is actually
`uintptr_t`.
This commit reuses the `size_type` definition to more than just `count`
and propagates them into range iteration, size calculation, etc.
This is a continuation of D108124.
I haven't changed all occurrences of `unsigned` or `uintptr_t` to
`size_type`, just those that were directly related.
Following directions from clang-tidy on case of variables.
Differential Revision: https://reviews.llvm.org/D108290
Added:
Modified:
llvm/include/llvm/ADT/BitVector.h
llvm/include/llvm/ADT/SmallBitVector.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/BitVector.h b/llvm/include/llvm/ADT/BitVector.h
index 31d388073633..cd1964cbdd98 100644
--- a/llvm/include/llvm/ADT/BitVector.h
+++ b/llvm/include/llvm/ADT/BitVector.h
@@ -85,7 +85,7 @@ class BitVector {
unsigned Size; // Size of bitvector in bits.
public:
- typedef unsigned size_type;
+ using size_type = unsigned;
// Encapsulation of a single bit.
class reference {
@@ -536,8 +536,8 @@ class BitVector {
[&Arg](auto const &BV) { return Arg.size() == BV; }) &&
"consistent sizes");
Out.resize(Arg.size());
- for (size_t i = 0, e = Arg.Bits.size(); i != e; ++i)
- Out.Bits[i] = f(Arg.Bits[i], Args.Bits[i]...);
+ for (size_type I = 0, E = Arg.Bits.size(); I != E; ++I)
+ Out.Bits[I] = f(Arg.Bits[I], Args.Bits[I]...);
Out.clear_unused_bits();
return Out;
}
@@ -545,16 +545,16 @@ class BitVector {
BitVector &operator|=(const BitVector &RHS) {
if (size() < RHS.size())
resize(RHS.size());
- for (size_t i = 0, e = RHS.Bits.size(); i != e; ++i)
- Bits[i] |= RHS.Bits[i];
+ for (size_type I = 0, E = RHS.Bits.size(); I != E; ++I)
+ Bits[I] |= RHS.Bits[I];
return *this;
}
BitVector &operator^=(const BitVector &RHS) {
if (size() < RHS.size())
resize(RHS.size());
- for (size_t i = 0, e = RHS.Bits.size(); i != e; ++i)
- Bits[i] ^= RHS.Bits[i];
+ for (size_type I = 0, E = RHS.Bits.size(); I != E; ++I)
+ Bits[I] ^= RHS.Bits[I];
return *this;
}
@@ -808,11 +808,11 @@ class BitVector {
public:
/// Return the size (in bytes) of the bit vector.
- size_t getMemorySize() const { return Bits.size() * sizeof(BitWord); }
- size_t getBitCapacity() const { return Bits.size() * BITWORD_SIZE; }
+ size_type getMemorySize() const { return Bits.size() * sizeof(BitWord); }
+ size_type getBitCapacity() const { return Bits.size() * BITWORD_SIZE; }
};
-inline size_t capacity_in_bytes(const BitVector &X) {
+inline BitVector::size_type capacity_in_bytes(const BitVector &X) {
return X.getMemorySize();
}
@@ -824,8 +824,8 @@ template <> struct DenseMapInfo<BitVector> {
return V;
}
static unsigned getHashValue(const BitVector &V) {
- return DenseMapInfo<std::pair<unsigned, ArrayRef<uintptr_t>>>::getHashValue(
- std::make_pair(V.size(), V.getData()));
+ return DenseMapInfo<std::pair<BitVector::size_type, ArrayRef<uintptr_t>>>::
+ getHashValue(std::make_pair(V.size(), V.getData()));
}
static bool isEqual(const BitVector &LHS, const BitVector &RHS) {
if (LHS.isInvalid() || RHS.isInvalid())
diff --git a/llvm/include/llvm/ADT/SmallBitVector.h b/llvm/include/llvm/ADT/SmallBitVector.h
index c70bc88fb1f2..51ee5dbbce05 100644
--- a/llvm/include/llvm/ADT/SmallBitVector.h
+++ b/llvm/include/llvm/ADT/SmallBitVector.h
@@ -60,7 +60,7 @@ class SmallBitVector {
"Unsupported word size");
public:
- using size_type = unsigned;
+ using size_type = uintptr_t;
// Encapsulation of a single bit.
class reference {
@@ -96,7 +96,7 @@ class SmallBitVector {
return reinterpret_cast<BitVector *>(X);
}
- void switchToSmall(uintptr_t NewSmallBits, size_t NewSize) {
+ void switchToSmall(uintptr_t NewSmallBits, size_type NewSize) {
X = 1;
setSmallSize(NewSize);
setSmallBits(NewSmallBits);
@@ -120,9 +120,11 @@ class SmallBitVector {
}
// Return the size.
- size_t getSmallSize() const { return getSmallRawBits() >> SmallNumDataBits; }
+ size_type getSmallSize() const {
+ return getSmallRawBits() >> SmallNumDataBits;
+ }
- void setSmallSize(size_t Size) {
+ void setSmallSize(size_type Size) {
setSmallRawBits(getSmallBits() | (Size << SmallNumDataBits));
}
@@ -189,7 +191,7 @@ class SmallBitVector {
}
/// Returns the number of bits in this bitvector.
- size_t size() const {
+ size_type size() const {
return isSmall() ? getSmallSize() : getPointer()->size();
}
@@ -336,8 +338,8 @@ class SmallBitVector {
} else {
BitVector *BV = new BitVector(N, t);
uintptr_t OldBits = getSmallBits();
- for (size_t i = 0, e = getSmallSize(); i != e; ++i)
- (*BV)[i] = (OldBits >> i) & 1;
+ for (size_type I = 0, E = getSmallSize(); I != E; ++I)
+ (*BV)[I] = (OldBits >> I) & 1;
switchToLarge(BV);
}
}
@@ -346,11 +348,11 @@ class SmallBitVector {
if (isSmall()) {
if (N > SmallNumDataBits) {
uintptr_t OldBits = getSmallRawBits();
- size_t SmallSize = getSmallSize();
+ size_type SmallSize = getSmallSize();
BitVector *BV = new BitVector(SmallSize);
- for (size_t i = 0; i < SmallSize; ++i)
- if ((OldBits >> i) & 1)
- BV->set(i);
+ for (size_type I = 0; I < SmallSize; ++I)
+ if ((OldBits >> I) & 1)
+ BV->set(I);
BV->reserve(N);
switchToLarge(BV);
}
@@ -491,8 +493,8 @@ class SmallBitVector {
else if (!isSmall() && !RHS.isSmall())
return *getPointer() == *RHS.getPointer();
else {
- for (size_t i = 0, e = size(); i != e; ++i) {
- if ((*this)[i] != RHS[i])
+ for (size_type I = 0, E = size(); I != E; ++I) {
+ if ((*this)[I] != RHS[I])
return false;
}
return true;
@@ -512,11 +514,11 @@ class SmallBitVector {
else if (!isSmall() && !RHS.isSmall())
getPointer()->operator&=(*RHS.getPointer());
else {
- size_t i, e;
- for (i = 0, e = std::min(size(), RHS.size()); i != e; ++i)
- (*this)[i] = test(i) && RHS.test(i);
- for (e = size(); i != e; ++i)
- reset(i);
+ size_type I, E;
+ for (I = 0, E = std::min(size(), RHS.size()); I != E; ++I)
+ (*this)[I] = test(I) && RHS.test(I);
+ for (E = size(); I != E; ++I)
+ reset(I);
}
return *this;
}
@@ -561,8 +563,8 @@ class SmallBitVector {
else if (!isSmall() && !RHS.isSmall())
getPointer()->operator|=(*RHS.getPointer());
else {
- for (size_t i = 0, e = RHS.size(); i != e; ++i)
- (*this)[i] = test(i) || RHS.test(i);
+ for (size_type I = 0, E = RHS.size(); I != E; ++I)
+ (*this)[I] = test(I) || RHS.test(I);
}
return *this;
}
@@ -574,8 +576,8 @@ class SmallBitVector {
else if (!isSmall() && !RHS.isSmall())
getPointer()->operator^=(*RHS.getPointer());
else {
- for (size_t i = 0, e = RHS.size(); i != e; ++i)
- (*this)[i] = test(i) != RHS.test(i);
+ for (size_type I = 0, E = RHS.size(); I != E; ++I)
+ (*this)[I] = test(I) != RHS.test(I);
}
return *this;
}
@@ -721,8 +723,9 @@ template <> struct DenseMapInfo<SmallBitVector> {
}
static unsigned getHashValue(const SmallBitVector &V) {
uintptr_t Store;
- return DenseMapInfo<std::pair<size_t, ArrayRef<uintptr_t>>>::getHashValue(
- std::make_pair(V.size(), V.getData(Store)));
+ return DenseMapInfo<
+ std::pair<SmallBitVector::size_type, ArrayRef<uintptr_t>>>::
+ getHashValue(std::make_pair(V.size(), V.getData(Store)));
}
static bool isEqual(const SmallBitVector &LHS, const SmallBitVector &RHS) {
if (LHS.isInvalid() || RHS.isInvalid())
More information about the llvm-commits
mailing list