2007-02-15 06:56:11 +01:00
|
|
|
//===- llvm/ADT/BitVector.h - Bit vectors -----------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-02-15 06:56:11 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the BitVector class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ADT_BITVECTOR_H
|
|
|
|
#define LLVM_ADT_BITVECTOR_H
|
|
|
|
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
2007-04-04 23:14:49 +02:00
|
|
|
#include <algorithm>
|
2007-04-05 00:13:39 +02:00
|
|
|
#include <cassert>
|
2009-04-01 20:45:54 +02:00
|
|
|
#include <climits>
|
2008-02-20 12:08:44 +01:00
|
|
|
#include <cstring>
|
2007-02-15 06:56:11 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class BitVector {
|
|
|
|
typedef unsigned long BitWord;
|
|
|
|
|
2009-04-01 20:45:54 +02:00
|
|
|
enum { BITWORD_SIZE = (unsigned)sizeof(BitWord) * CHAR_BIT };
|
2007-02-15 06:56:11 +01:00
|
|
|
|
2009-01-09 20:25:42 +01:00
|
|
|
BitWord *Bits; // Actual bits.
|
2007-02-15 06:56:11 +01:00
|
|
|
unsigned Size; // Size of bitvector in bits.
|
|
|
|
unsigned Capacity; // Size of allocated memory in BitWord.
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Encapsulation of a single bit.
|
|
|
|
class reference {
|
|
|
|
friend class BitVector;
|
|
|
|
|
|
|
|
BitWord *WordRef;
|
|
|
|
unsigned BitPos;
|
|
|
|
|
|
|
|
reference(); // Undefined
|
|
|
|
|
|
|
|
public:
|
|
|
|
reference(BitVector &b, unsigned Idx) {
|
2007-04-26 17:07:47 +02:00
|
|
|
WordRef = &b.Bits[Idx / BITWORD_SIZE];
|
|
|
|
BitPos = Idx % BITWORD_SIZE;
|
2007-02-15 06:56:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
~reference() {}
|
|
|
|
|
2010-04-30 22:50:28 +02:00
|
|
|
reference &operator=(reference t) {
|
|
|
|
*this = bool(t);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2007-02-15 06:56:11 +01:00
|
|
|
reference& operator=(bool t) {
|
|
|
|
if (t)
|
2007-02-15 20:03:23 +01:00
|
|
|
*WordRef |= 1L << BitPos;
|
2007-02-15 06:56:11 +01:00
|
|
|
else
|
2007-02-15 20:03:23 +01:00
|
|
|
*WordRef &= ~(1L << BitPos);
|
2007-02-15 06:56:11 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator bool() const {
|
2007-10-17 16:56:40 +02:00
|
|
|
return ((*WordRef) & (1L << BitPos)) ? true : false;
|
2007-02-15 06:56:11 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// BitVector default ctor - Creates an empty bitvector.
|
|
|
|
BitVector() : Size(0), Capacity(0) {
|
2008-05-29 21:52:31 +02:00
|
|
|
Bits = 0;
|
2007-02-15 06:56:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// BitVector ctor - Creates a bitvector of specified number of bits. All
|
|
|
|
/// bits are initialized to the specified value.
|
2007-02-15 20:05:25 +01:00
|
|
|
explicit BitVector(unsigned s, bool t = false) : Size(s) {
|
2007-02-15 06:56:11 +01:00
|
|
|
Capacity = NumBitWords(s);
|
|
|
|
Bits = new BitWord[Capacity];
|
|
|
|
init_words(Bits, Capacity, t);
|
2007-02-15 20:05:25 +01:00
|
|
|
if (t)
|
|
|
|
clear_unused_bits();
|
2007-02-15 06:56:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// BitVector copy ctor.
|
|
|
|
BitVector(const BitVector &RHS) : Size(RHS.size()) {
|
2007-02-15 20:05:25 +01:00
|
|
|
if (Size == 0) {
|
2008-05-29 21:52:31 +02:00
|
|
|
Bits = 0;
|
2007-02-15 21:14:06 +01:00
|
|
|
Capacity = 0;
|
2007-02-15 20:05:25 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-02-15 06:56:11 +01:00
|
|
|
Capacity = NumBitWords(RHS.size());
|
|
|
|
Bits = new BitWord[Capacity];
|
|
|
|
std::copy(RHS.Bits, &RHS.Bits[Capacity], Bits);
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-03-20 03:10:56 +01:00
|
|
|
~BitVector() {
|
|
|
|
delete[] Bits;
|
|
|
|
}
|
2007-02-15 06:56:11 +01:00
|
|
|
|
2010-01-05 16:04:49 +01:00
|
|
|
/// empty - Tests whether there are no bits in this bitvector.
|
|
|
|
bool empty() const { return Size == 0; }
|
|
|
|
|
2007-02-15 06:56:11 +01:00
|
|
|
/// size - Returns the number of bits in this bitvector.
|
|
|
|
unsigned size() const { return Size; }
|
|
|
|
|
|
|
|
/// count - Returns the number of bits which are set.
|
|
|
|
unsigned count() const {
|
|
|
|
unsigned NumBits = 0;
|
|
|
|
for (unsigned i = 0; i < NumBitWords(size()); ++i)
|
2007-02-15 20:09:36 +01:00
|
|
|
if (sizeof(BitWord) == 4)
|
2008-05-05 20:30:58 +02:00
|
|
|
NumBits += CountPopulation_32((uint32_t)Bits[i]);
|
2007-02-15 20:09:36 +01:00
|
|
|
else if (sizeof(BitWord) == 8)
|
|
|
|
NumBits += CountPopulation_64(Bits[i]);
|
|
|
|
else
|
2007-02-15 20:29:05 +01:00
|
|
|
assert(0 && "Unsupported!");
|
2007-02-15 06:56:11 +01:00
|
|
|
return NumBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// any - Returns true if any bit is set.
|
|
|
|
bool any() const {
|
|
|
|
for (unsigned i = 0; i < NumBitWords(size()); ++i)
|
|
|
|
if (Bits[i] != 0)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// none - Returns true if none of the bits are set.
|
|
|
|
bool none() const {
|
|
|
|
return !any();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// find_first - Returns the index of the first set bit, -1 if none
|
|
|
|
/// of the bits are set.
|
|
|
|
int find_first() const {
|
|
|
|
for (unsigned i = 0; i < NumBitWords(size()); ++i)
|
2007-03-02 03:31:37 +01:00
|
|
|
if (Bits[i] != 0) {
|
2007-04-16 20:10:23 +02:00
|
|
|
if (sizeof(BitWord) == 4)
|
2008-05-05 20:30:58 +02:00
|
|
|
return i * BITWORD_SIZE + CountTrailingZeros_32((uint32_t)Bits[i]);
|
2007-04-16 20:10:23 +02:00
|
|
|
else if (sizeof(BitWord) == 8)
|
2007-04-26 17:07:47 +02:00
|
|
|
return i * BITWORD_SIZE + CountTrailingZeros_64(Bits[i]);
|
2007-04-16 20:10:23 +02:00
|
|
|
else
|
|
|
|
assert(0 && "Unsupported!");
|
2007-03-02 03:31:37 +01:00
|
|
|
}
|
2007-02-15 06:56:11 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// find_next - Returns the index of the next set bit following the
|
|
|
|
/// "Prev" bit. Returns -1 if the next set bit is not found.
|
|
|
|
int find_next(unsigned Prev) const {
|
|
|
|
++Prev;
|
|
|
|
if (Prev >= Size)
|
|
|
|
return -1;
|
|
|
|
|
2007-04-26 17:07:47 +02:00
|
|
|
unsigned WordPos = Prev / BITWORD_SIZE;
|
|
|
|
unsigned BitPos = Prev % BITWORD_SIZE;
|
2007-02-15 06:56:11 +01:00
|
|
|
BitWord Copy = Bits[WordPos];
|
|
|
|
// Mask off previous bits.
|
2007-03-02 03:31:37 +01:00
|
|
|
Copy &= ~0L << BitPos;
|
2007-02-15 06:56:11 +01:00
|
|
|
|
2007-03-02 03:31:37 +01:00
|
|
|
if (Copy != 0) {
|
|
|
|
if (sizeof(BitWord) == 4)
|
2008-05-05 20:30:58 +02:00
|
|
|
return WordPos * BITWORD_SIZE + CountTrailingZeros_32((uint32_t)Copy);
|
2007-03-02 03:31:37 +01:00
|
|
|
else if (sizeof(BitWord) == 8)
|
2007-04-26 17:07:47 +02:00
|
|
|
return WordPos * BITWORD_SIZE + CountTrailingZeros_64(Copy);
|
2007-03-02 03:31:37 +01:00
|
|
|
else
|
2007-04-16 20:10:23 +02:00
|
|
|
assert(0 && "Unsupported!");
|
2007-03-02 03:31:37 +01:00
|
|
|
}
|
2007-02-15 06:56:11 +01:00
|
|
|
|
|
|
|
// Check subsequent words.
|
|
|
|
for (unsigned i = WordPos+1; i < NumBitWords(size()); ++i)
|
2007-03-02 03:31:37 +01:00
|
|
|
if (Bits[i] != 0) {
|
2007-04-16 20:10:23 +02:00
|
|
|
if (sizeof(BitWord) == 4)
|
2008-05-05 20:30:58 +02:00
|
|
|
return i * BITWORD_SIZE + CountTrailingZeros_32((uint32_t)Bits[i]);
|
2007-04-16 20:10:23 +02:00
|
|
|
else if (sizeof(BitWord) == 8)
|
2007-04-26 17:07:47 +02:00
|
|
|
return i * BITWORD_SIZE + CountTrailingZeros_64(Bits[i]);
|
2007-04-16 20:10:23 +02:00
|
|
|
else
|
|
|
|
assert(0 && "Unsupported!");
|
2007-03-02 03:31:37 +01:00
|
|
|
}
|
2007-02-15 06:56:11 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// clear - Clear all bits.
|
|
|
|
void clear() {
|
2007-02-15 20:10:34 +01:00
|
|
|
Size = 0;
|
2007-02-15 06:56:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// resize - Grow or shrink the bitvector.
|
2007-02-15 20:12:39 +01:00
|
|
|
void resize(unsigned N, bool t = false) {
|
2007-04-26 17:07:47 +02:00
|
|
|
if (N > Capacity * BITWORD_SIZE) {
|
2007-02-15 06:56:11 +01:00
|
|
|
unsigned OldCapacity = Capacity;
|
|
|
|
grow(N);
|
|
|
|
init_words(&Bits[OldCapacity], (Capacity-OldCapacity), t);
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
|
|
|
// Set any old unused bits that are now included in the BitVector. This
|
|
|
|
// may set bits that are not included in the new vector, but we will clear
|
2007-08-06 22:52:17 +02:00
|
|
|
// them back out below.
|
|
|
|
if (N > Size)
|
|
|
|
set_unused_bits(t);
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-08-06 22:52:17 +02:00
|
|
|
// Update the size, and clear out any bits that are now unused
|
|
|
|
unsigned OldSize = Size;
|
2007-02-15 06:56:11 +01:00
|
|
|
Size = N;
|
2007-08-06 22:52:17 +02:00
|
|
|
if (t || N < OldSize)
|
|
|
|
clear_unused_bits();
|
2007-02-15 06:56:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void reserve(unsigned N) {
|
2007-04-26 17:07:47 +02:00
|
|
|
if (N > Capacity * BITWORD_SIZE)
|
2007-02-15 06:56:11 +01:00
|
|
|
grow(N);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set, reset, flip
|
|
|
|
BitVector &set() {
|
2007-02-15 20:18:12 +01:00
|
|
|
init_words(Bits, Capacity, true);
|
|
|
|
clear_unused_bits();
|
2007-02-15 06:56:11 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
BitVector &set(unsigned Idx) {
|
2007-04-26 17:07:47 +02:00
|
|
|
Bits[Idx / BITWORD_SIZE] |= 1L << (Idx % BITWORD_SIZE);
|
2007-02-15 06:56:11 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
BitVector &reset() {
|
2007-02-15 20:18:12 +01:00
|
|
|
init_words(Bits, Capacity, false);
|
2007-02-15 06:56:11 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
BitVector &reset(unsigned Idx) {
|
2007-04-26 17:07:47 +02:00
|
|
|
Bits[Idx / BITWORD_SIZE] &= ~(1L << (Idx % BITWORD_SIZE));
|
2007-02-15 06:56:11 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
BitVector &flip() {
|
|
|
|
for (unsigned i = 0; i < NumBitWords(size()); ++i)
|
|
|
|
Bits[i] = ~Bits[i];
|
|
|
|
clear_unused_bits();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
BitVector &flip(unsigned Idx) {
|
2007-04-26 17:07:47 +02:00
|
|
|
Bits[Idx / BITWORD_SIZE] ^= 1L << (Idx % BITWORD_SIZE);
|
2007-02-15 06:56:11 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No argument flip.
|
|
|
|
BitVector operator~() const {
|
|
|
|
return BitVector(*this).flip();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Indexing.
|
|
|
|
reference operator[](unsigned Idx) {
|
2007-12-10 23:28:35 +01:00
|
|
|
assert (Idx < Size && "Out-of-bounds Bit access.");
|
2007-02-15 06:56:11 +01:00
|
|
|
return reference(*this, Idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator[](unsigned Idx) const {
|
2009-01-09 20:25:42 +01:00
|
|
|
assert (Idx < Size && "Out-of-bounds Bit access.");
|
2007-04-26 17:07:47 +02:00
|
|
|
BitWord Mask = 1L << (Idx % BITWORD_SIZE);
|
|
|
|
return (Bits[Idx / BITWORD_SIZE] & Mask) != 0;
|
2007-02-15 06:56:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test(unsigned Idx) const {
|
|
|
|
return (*this)[Idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Comparison operators.
|
|
|
|
bool operator==(const BitVector &RHS) const {
|
2007-10-12 05:48:59 +02:00
|
|
|
unsigned ThisWords = NumBitWords(size());
|
|
|
|
unsigned RHSWords = NumBitWords(RHS.size());
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i != std::min(ThisWords, RHSWords); ++i)
|
2007-02-15 06:56:11 +01:00
|
|
|
if (Bits[i] != RHS.Bits[i])
|
|
|
|
return false;
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-10-12 05:48:59 +02:00
|
|
|
// Verify that any extra words are all zeros.
|
|
|
|
if (i != ThisWords) {
|
|
|
|
for (; i != ThisWords; ++i)
|
|
|
|
if (Bits[i])
|
|
|
|
return false;
|
|
|
|
} else if (i != RHSWords) {
|
|
|
|
for (; i != RHSWords; ++i)
|
|
|
|
if (RHS.Bits[i])
|
|
|
|
return false;
|
|
|
|
}
|
2007-02-15 06:56:11 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const BitVector &RHS) const {
|
|
|
|
return !(*this == RHS);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intersection, union, disjoint union.
|
2009-01-26 12:07:20 +01:00
|
|
|
BitVector &operator&=(const BitVector &RHS) {
|
2007-10-11 08:12:33 +02:00
|
|
|
unsigned ThisWords = NumBitWords(size());
|
|
|
|
unsigned RHSWords = NumBitWords(RHS.size());
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i != std::min(ThisWords, RHSWords); ++i)
|
2007-02-15 06:56:11 +01:00
|
|
|
Bits[i] &= RHS.Bits[i];
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-10-11 08:12:33 +02:00
|
|
|
// Any bits that are just in this bitvector become zero, because they aren't
|
|
|
|
// in the RHS bit vector. Any words only in RHS are ignored because they
|
|
|
|
// are already zero in the LHS.
|
|
|
|
for (; i != ThisWords; ++i)
|
|
|
|
Bits[i] = 0;
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-02-15 06:56:11 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2009-01-26 12:07:20 +01:00
|
|
|
BitVector &operator|=(const BitVector &RHS) {
|
2010-02-10 06:54:04 +01:00
|
|
|
if (size() < RHS.size())
|
|
|
|
resize(RHS.size());
|
|
|
|
for (size_t i = 0, e = NumBitWords(RHS.size()); i != e; ++i)
|
2007-02-15 06:56:11 +01:00
|
|
|
Bits[i] |= RHS.Bits[i];
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2009-01-26 12:07:20 +01:00
|
|
|
BitVector &operator^=(const BitVector &RHS) {
|
2010-02-10 06:54:04 +01:00
|
|
|
if (size() < RHS.size())
|
|
|
|
resize(RHS.size());
|
|
|
|
for (size_t i = 0, e = NumBitWords(RHS.size()); i != e; ++i)
|
2007-02-15 06:56:11 +01:00
|
|
|
Bits[i] ^= RHS.Bits[i];
|
|
|
|
return *this;
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-02-15 06:56:11 +01:00
|
|
|
// Assignment operator.
|
|
|
|
const BitVector &operator=(const BitVector &RHS) {
|
|
|
|
if (this == &RHS) return *this;
|
|
|
|
|
2007-02-15 09:15:58 +01:00
|
|
|
Size = RHS.size();
|
|
|
|
unsigned RHSWords = NumBitWords(Size);
|
2007-04-26 17:07:47 +02:00
|
|
|
if (Size <= Capacity * BITWORD_SIZE) {
|
2010-03-16 20:07:05 +01:00
|
|
|
if (Size)
|
|
|
|
std::copy(RHS.Bits, &RHS.Bits[RHSWords], Bits);
|
2007-02-15 06:56:11 +01:00
|
|
|
clear_unused_bits();
|
|
|
|
return *this;
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-02-15 06:56:11 +01:00
|
|
|
// Grow the bitvector to have enough elements.
|
2007-08-06 22:52:17 +02:00
|
|
|
Capacity = RHSWords;
|
2007-02-15 06:56:11 +01:00
|
|
|
BitWord *NewBits = new BitWord[Capacity];
|
|
|
|
std::copy(RHS.Bits, &RHS.Bits[RHSWords], NewBits);
|
|
|
|
|
|
|
|
// Destroy the old bits.
|
|
|
|
delete[] Bits;
|
|
|
|
Bits = NewBits;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-01-05 16:04:49 +01:00
|
|
|
void swap(BitVector &RHS) {
|
|
|
|
std::swap(Bits, RHS.Bits);
|
|
|
|
std::swap(Size, RHS.Size);
|
|
|
|
std::swap(Capacity, RHS.Capacity);
|
|
|
|
}
|
|
|
|
|
2007-02-15 06:56:11 +01:00
|
|
|
private:
|
|
|
|
unsigned NumBitWords(unsigned S) const {
|
2007-04-26 17:07:47 +02:00
|
|
|
return (S + BITWORD_SIZE-1) / BITWORD_SIZE;
|
2007-02-15 06:56:11 +01:00
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-08-06 22:52:17 +02:00
|
|
|
// Set the unused bits in the high words.
|
|
|
|
void set_unused_bits(bool t = true) {
|
|
|
|
// Set high words first.
|
|
|
|
unsigned UsedWords = NumBitWords(Size);
|
|
|
|
if (Capacity > UsedWords)
|
|
|
|
init_words(&Bits[UsedWords], (Capacity-UsedWords), t);
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-08-06 22:52:17 +02:00
|
|
|
// Then set any stray high bits of the last used word.
|
2007-04-26 17:07:47 +02:00
|
|
|
unsigned ExtraBits = Size % BITWORD_SIZE;
|
2007-02-15 22:38:15 +01:00
|
|
|
if (ExtraBits) {
|
2007-08-06 22:52:17 +02:00
|
|
|
Bits[UsedWords-1] &= ~(~0L << ExtraBits);
|
|
|
|
Bits[UsedWords-1] |= (0 - (BitWord)t) << ExtraBits;
|
2007-02-15 19:59:15 +01:00
|
|
|
}
|
2007-02-15 06:56:11 +01:00
|
|
|
}
|
|
|
|
|
2007-08-06 22:52:17 +02:00
|
|
|
// Clear the unused bits in the high words.
|
|
|
|
void clear_unused_bits() {
|
|
|
|
set_unused_bits(false);
|
|
|
|
}
|
|
|
|
|
2007-02-15 06:56:11 +01:00
|
|
|
void grow(unsigned NewSize) {
|
|
|
|
unsigned OldCapacity = Capacity;
|
|
|
|
Capacity = NumBitWords(NewSize);
|
|
|
|
BitWord *NewBits = new BitWord[Capacity];
|
|
|
|
|
|
|
|
// Copy the old bits over.
|
|
|
|
if (OldCapacity != 0)
|
|
|
|
std::copy(Bits, &Bits[OldCapacity], NewBits);
|
|
|
|
|
|
|
|
// Destroy the old bits.
|
2007-02-15 20:18:12 +01:00
|
|
|
delete[] Bits;
|
2007-02-15 06:56:11 +01:00
|
|
|
Bits = NewBits;
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-12-10 23:28:35 +01:00
|
|
|
clear_unused_bits();
|
2007-02-15 06:56:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void init_words(BitWord *B, unsigned NumWords, bool t) {
|
2007-02-15 20:18:12 +01:00
|
|
|
memset(B, 0 - (int)t, NumWords*sizeof(BitWord));
|
2009-01-09 20:25:42 +01:00
|
|
|
}
|
2007-02-15 06:56:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
inline BitVector operator&(const BitVector &LHS, const BitVector &RHS) {
|
|
|
|
BitVector Result(LHS);
|
|
|
|
Result &= RHS;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline BitVector operator|(const BitVector &LHS, const BitVector &RHS) {
|
|
|
|
BitVector Result(LHS);
|
|
|
|
Result |= RHS;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline BitVector operator^(const BitVector &LHS, const BitVector &RHS) {
|
|
|
|
BitVector Result(LHS);
|
|
|
|
Result ^= RHS;
|
|
|
|
return Result;
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-02-15 06:56:11 +01:00
|
|
|
} // End llvm namespace
|
2010-01-05 16:04:49 +01:00
|
|
|
|
|
|
|
namespace std {
|
|
|
|
/// Implement std::swap in terms of BitVector swap.
|
|
|
|
inline void
|
|
|
|
swap(llvm::BitVector &LHS, llvm::BitVector &RHS) {
|
|
|
|
LHS.swap(RHS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-15 06:56:11 +01:00
|
|
|
#endif
|