//
// The LLVM Compiler Infrastructure
//
-// This file was developed by Evan Cheng and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
#include "llvm/Support/MathExtras.h"
#include <algorithm>
-#include <cstdlib>
#include <cassert>
+#include <cstring>
namespace llvm {
class BitVector {
typedef unsigned long BitWord;
- enum { BITWORD_SIZE = sizeof(BitWord) * 8 };
+ enum { BITWORD_SIZE = (unsigned)sizeof(BitWord) * 8 };
BitWord *Bits; // Actual bits.
unsigned Size; // Size of bitvector in bits.
}
operator bool() const {
- return (*WordRef) & (1L << BitPos);
+ return ((*WordRef) & (1L << BitPos)) ? true : false;
}
};
/// BitVector default ctor - Creates an empty bitvector.
BitVector() : Size(0), Capacity(0) {
- Bits = NULL;
+ Bits = 0;
}
/// BitVector ctor - Creates a bitvector of specified number of bits. All
/// BitVector copy ctor.
BitVector(const BitVector &RHS) : Size(RHS.size()) {
if (Size == 0) {
- Bits = NULL;
+ Bits = 0;
Capacity = 0;
return;
}
unsigned NumBits = 0;
for (unsigned i = 0; i < NumBitWords(size()); ++i)
if (sizeof(BitWord) == 4)
- NumBits += CountPopulation_32(Bits[i]);
+ NumBits += CountPopulation_32((uint32_t)Bits[i]);
else if (sizeof(BitWord) == 8)
NumBits += CountPopulation_64(Bits[i]);
else
for (unsigned i = 0; i < NumBitWords(size()); ++i)
if (Bits[i] != 0) {
if (sizeof(BitWord) == 4)
- return i * BITWORD_SIZE + CountTrailingZeros_32(Bits[i]);
+ return i * BITWORD_SIZE + CountTrailingZeros_32((uint32_t)Bits[i]);
else if (sizeof(BitWord) == 8)
return i * BITWORD_SIZE + CountTrailingZeros_64(Bits[i]);
else
if (Copy != 0) {
if (sizeof(BitWord) == 4)
- return WordPos * BITWORD_SIZE + CountTrailingZeros_32(Copy);
+ return WordPos * BITWORD_SIZE + CountTrailingZeros_32((uint32_t)Copy);
else if (sizeof(BitWord) == 8)
return WordPos * BITWORD_SIZE + CountTrailingZeros_64(Copy);
else
for (unsigned i = WordPos+1; i < NumBitWords(size()); ++i)
if (Bits[i] != 0) {
if (sizeof(BitWord) == 4)
- return i * BITWORD_SIZE + CountTrailingZeros_32(Bits[i]);
+ return i * BITWORD_SIZE + CountTrailingZeros_32((uint32_t)Bits[i]);
else if (sizeof(BitWord) == 8)
return i * BITWORD_SIZE + CountTrailingZeros_64(Bits[i]);
else
// Indexing.
reference operator[](unsigned Idx) {
+ assert (Idx < Size && "Out-of-bounds Bit access.");
return reference(*this, Idx);
}
bool operator[](unsigned Idx) const {
+ assert (Idx < Size && "Out-of-bounds Bit access.");
BitWord Mask = 1L << (Idx % BITWORD_SIZE);
return (Bits[Idx / BITWORD_SIZE] & Mask) != 0;
}
// Destroy the old bits.
delete[] Bits;
Bits = NewBits;
+
+ clear_unused_bits();
}
void init_words(BitWord *B, unsigned NumWords, bool t) {