Coverage Report

Created: 2018-09-17 19:50

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/ADT/BitVector.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/ADT/BitVector.h - Bit vectors -----------------------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file implements the BitVector class.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_ADT_BITVECTOR_H
15
#define LLVM_ADT_BITVECTOR_H
16
17
#include "llvm/ADT/ArrayRef.h"
18
#include "llvm/ADT/iterator_range.h"
19
#include "llvm/Support/MathExtras.h"
20
#include <algorithm>
21
#include <cassert>
22
#include <climits>
23
#include <cstdint>
24
#include <cstdlib>
25
#include <cstring>
26
#include <utility>
27
28
namespace llvm {
29
30
/// ForwardIterator for the bits that are set.
31
/// Iterators get invalidated when resize / reserve is called.
32
template <typename BitVectorT> class const_set_bits_iterator_impl {
33
  const BitVectorT &Parent;
34
  int Current = 0;
35
36
194M
  void advance() {
37
194M
    assert(Current != -1 && "Trying to advance past end.");
38
194M
    Current = Parent.find_next(Current);
39
194M
  }
llvm::const_set_bits_iterator_impl<llvm::BitVector>::advance()
Line
Count
Source
36
189M
  void advance() {
37
189M
    assert(Current != -1 && "Trying to advance past end.");
38
189M
    Current = Parent.find_next(Current);
39
189M
  }
llvm::const_set_bits_iterator_impl<llvm::SmallBitVector>::advance()
Line
Count
Source
36
4.78M
  void advance() {
37
4.78M
    assert(Current != -1 && "Trying to advance past end.");
38
4.78M
    Current = Parent.find_next(Current);
39
4.78M
  }
40
41
public:
42
  const_set_bits_iterator_impl(const BitVectorT &Parent, int Current)
43
34.2M
      : Parent(Parent), Current(Current) {}
llvm::const_set_bits_iterator_impl<llvm::BitVector>::const_set_bits_iterator_impl(llvm::BitVector const&, int)
Line
Count
Source
43
28.2M
      : Parent(Parent), Current(Current) {}
llvm::const_set_bits_iterator_impl<llvm::SmallBitVector>::const_set_bits_iterator_impl(llvm::SmallBitVector const&, int)
Line
Count
Source
43
6.03M
      : Parent(Parent), Current(Current) {}
44
  explicit const_set_bits_iterator_impl(const BitVectorT &Parent)
45
17.1M
      : const_set_bits_iterator_impl(Parent, Parent.find_first()) {}
llvm::const_set_bits_iterator_impl<llvm::BitVector>::const_set_bits_iterator_impl(llvm::BitVector const&)
Line
Count
Source
45
14.1M
      : const_set_bits_iterator_impl(Parent, Parent.find_first()) {}
llvm::const_set_bits_iterator_impl<llvm::SmallBitVector>::const_set_bits_iterator_impl(llvm::SmallBitVector const&)
Line
Count
Source
45
3.01M
      : const_set_bits_iterator_impl(Parent, Parent.find_first()) {}
46
  const_set_bits_iterator_impl(const const_set_bits_iterator_impl &) = default;
47
48
  const_set_bits_iterator_impl operator++(int) {
49
    auto Prev = *this;
50
    advance();
51
    return Prev;
52
  }
53
54
194M
  const_set_bits_iterator_impl &operator++() {
55
194M
    advance();
56
194M
    return *this;
57
194M
  }
llvm::const_set_bits_iterator_impl<llvm::BitVector>::operator++()
Line
Count
Source
54
189M
  const_set_bits_iterator_impl &operator++() {
55
189M
    advance();
56
189M
    return *this;
57
189M
  }
llvm::const_set_bits_iterator_impl<llvm::SmallBitVector>::operator++()
Line
Count
Source
54
4.78M
  const_set_bits_iterator_impl &operator++() {
55
4.78M
    advance();
56
4.78M
    return *this;
57
4.78M
  }
58
59
194M
  unsigned operator*() const { return Current; }
llvm::const_set_bits_iterator_impl<llvm::BitVector>::operator*() const
Line
Count
Source
59
189M
  unsigned operator*() const { return Current; }
llvm::const_set_bits_iterator_impl<llvm::SmallBitVector>::operator*() const
Line
Count
Source
59
4.78M
  unsigned operator*() const { return Current; }
60
61
  bool operator==(const const_set_bits_iterator_impl &Other) const {
62
    assert(&Parent == &Other.Parent &&
63
           "Comparing iterators from different BitVectors");
64
    return Current == Other.Current;
65
  }
66
67
211M
  bool operator!=(const const_set_bits_iterator_impl &Other) const {
68
211M
    assert(&Parent == &Other.Parent &&
69
211M
           "Comparing iterators from different BitVectors");
70
211M
    return Current != Other.Current;
71
211M
  }
llvm::const_set_bits_iterator_impl<llvm::BitVector>::operator!=(llvm::const_set_bits_iterator_impl<llvm::BitVector> const&) const
Line
Count
Source
67
203M
  bool operator!=(const const_set_bits_iterator_impl &Other) const {
68
203M
    assert(&Parent == &Other.Parent &&
69
203M
           "Comparing iterators from different BitVectors");
70
203M
    return Current != Other.Current;
71
203M
  }
llvm::const_set_bits_iterator_impl<llvm::SmallBitVector>::operator!=(llvm::const_set_bits_iterator_impl<llvm::SmallBitVector> const&) const
Line
Count
Source
67
7.79M
  bool operator!=(const const_set_bits_iterator_impl &Other) const {
68
7.79M
    assert(&Parent == &Other.Parent &&
69
7.79M
           "Comparing iterators from different BitVectors");
70
7.79M
    return Current != Other.Current;
71
7.79M
  }
72
};
73
74
class BitVector {
75
  typedef unsigned long BitWord;
76
77
  enum { BITWORD_SIZE = (unsigned)sizeof(BitWord) * CHAR_BIT };
78
79
  static_assert(BITWORD_SIZE == 64 || BITWORD_SIZE == 32,
80
                "Unsupported word size");
81
82
  MutableArrayRef<BitWord> Bits; // Actual bits.
83
  unsigned Size;                 // Size of bitvector in bits.
84
85
public:
86
  typedef unsigned size_type;
87
  // Encapsulation of a single bit.
88
  class reference {
89
    friend class BitVector;
90
91
    BitWord *WordRef;
92
    unsigned BitPos;
93
94
  public:
95
541M
    reference(BitVector &b, unsigned Idx) {
96
541M
      WordRef = &b.Bits[Idx / BITWORD_SIZE];
97
541M
      BitPos = Idx % BITWORD_SIZE;
98
541M
    }
99
100
    reference() = delete;
101
    reference(const reference&) = default;
102
103
    reference &operator=(reference t) {
104
      *this = bool(t);
105
      return *this;
106
    }
107
108
211M
    reference& operator=(bool t) {
109
211M
      if (t)
110
33.3M
        *WordRef |= BitWord(1) << BitPos;
111
177M
      else
112
177M
        *WordRef &= ~(BitWord(1) << BitPos);
113
211M
      return *this;
114
211M
    }
115
116
329M
    operator bool() const {
117
329M
      return ((*WordRef) & (BitWord(1) << BitPos)) != 0;
118
329M
    }
119
  };
120
121
  typedef const_set_bits_iterator_impl<BitVector> const_set_bits_iterator;
122
  typedef const_set_bits_iterator set_iterator;
123
124
14.1M
  const_set_bits_iterator set_bits_begin() const {
125
14.1M
    return const_set_bits_iterator(*this);
126
14.1M
  }
127
14.1M
  const_set_bits_iterator set_bits_end() const {
128
14.1M
    return const_set_bits_iterator(*this, -1);
129
14.1M
  }
130
14.1M
  iterator_range<const_set_bits_iterator> set_bits() const {
131
14.1M
    return make_range(set_bits_begin(), set_bits_end());
132
14.1M
  }
133
134
  /// BitVector default ctor - Creates an empty bitvector.
135
38.1M
  BitVector() : Size(0) {}
136
137
  /// BitVector ctor - Creates a bitvector of specified number of bits. All
138
  /// bits are initialized to the specified value.
139
44.9M
  explicit BitVector(unsigned s, bool t = false) : Size(s) {
140
44.9M
    size_t Capacity = NumBitWords(s);
141
44.9M
    Bits = allocate(Capacity);
142
44.9M
    init_words(Bits, t);
143
44.9M
    if (t)
144
94.0k
      clear_unused_bits();
145
44.9M
  }
146
147
  /// BitVector copy ctor.
148
8.20M
  BitVector(const BitVector &RHS) : Size(RHS.size()) {
149
8.20M
    if (Size == 0) {
150
587k
      Bits = MutableArrayRef<BitWord>();
151
587k
      return;
152
587k
    }
153
7.61M
154
7.61M
    size_t Capacity = NumBitWords(RHS.size());
155
7.61M
    Bits = allocate(Capacity);
156
7.61M
    std::memcpy(Bits.data(), RHS.Bits.data(), Capacity * sizeof(BitWord));
157
7.61M
  }
158
159
6.23M
  BitVector(BitVector &&RHS) : Bits(RHS.Bits), Size(RHS.Size) {
160
6.23M
    RHS.Bits = MutableArrayRef<BitWord>();
161
6.23M
    RHS.Size = 0;
162
6.23M
  }
163
164
97.4M
  ~BitVector() { std::free(Bits.data()); }
165
166
  /// empty - Tests whether there are no bits in this bitvector.
167
100M
  bool empty() const { return Size == 0; }
168
169
  /// size - Returns the number of bits in this bitvector.
170
480M
  size_type size() const { return Size; }
171
172
  /// count - Returns the number of bits which are set.
173
1.99M
  size_type count() const {
174
1.99M
    unsigned NumBits = 0;
175
13.5M
    for (unsigned i = 0; i < NumBitWords(size()); 
++i11.5M
)
176
11.5M
      NumBits += countPopulation(Bits[i]);
177
1.99M
    return NumBits;
178
1.99M
  }
179
180
  /// any - Returns true if any bit is set.
181
4.25M
  bool any() const {
182
7.34M
    for (unsigned i = 0; i < NumBitWords(size()); 
++i3.09M
)
183
6.01M
      if (Bits[i] != 0)
184
2.92M
        return true;
185
4.25M
    
return false1.32M
;
186
4.25M
  }
187
188
  /// all - Returns true if all bits are set.
189
2.64k
  bool all() const {
190
2.65k
    for (unsigned i = 0; i < Size / BITWORD_SIZE; 
++i7
)
191
11
      if (Bits[i] != ~0UL)
192
4
        return false;
193
2.64k
194
2.64k
    // If bits remain check that they are ones. The unused bits are always zero.
195
2.64k
    
if (unsigned 2.64k
Remainder2.64k
= Size % BITWORD_SIZE)
196
2.63k
      return Bits[Size / BITWORD_SIZE] == (1UL << Remainder) - 1;
197
11
198
11
    return true;
199
11
  }
200
201
  /// none - Returns true if none of the bits are set.
202
620k
  bool none() const {
203
620k
    return !any();
204
620k
  }
205
206
  /// find_first_in - Returns the index of the first set bit in the range
207
  /// [Begin, End).  Returns -1 if all bits in the range are unset.
208
216M
  int find_first_in(unsigned Begin, unsigned End) const {
209
216M
    assert(Begin <= End && End <= Size);
210
216M
    if (Begin == End)
211
3.04M
      return -1;
212
213M
213
213M
    unsigned FirstWord = Begin / BITWORD_SIZE;
214
213M
    unsigned LastWord = (End - 1) / BITWORD_SIZE;
215
213M
216
213M
    // Check subsequent words.
217
272M
    for (unsigned i = FirstWord; i <= LastWord; 
++i59.4M
) {
218
259M
      BitWord Copy = Bits[i];
219
259M
220
259M
      if (i == FirstWord) {
221
213M
        unsigned FirstBit = Begin % BITWORD_SIZE;
222
213M
        Copy &= maskTrailingZeros<BitWord>(FirstBit);
223
213M
      }
224
259M
225
259M
      if (i == LastWord) {
226
88.3M
        unsigned LastBit = (End - 1) % BITWORD_SIZE;
227
88.3M
        Copy &= maskTrailingOnes<BitWord>(LastBit + 1);
228
88.3M
      }
229
259M
      if (Copy != 0)
230
199M
        return i * BITWORD_SIZE + countTrailingZeros(Copy);
231
259M
    }
232
213M
    
return -113.5M
;
233
213M
  }
234
235
  /// find_last_in - Returns the index of the last set bit in the range
236
  /// [Begin, End).  Returns -1 if all bits in the range are unset.
237
  int find_last_in(unsigned Begin, unsigned End) const {
238
    assert(Begin <= End && End <= Size);
239
    if (Begin == End)
240
      return -1;
241
242
    unsigned LastWord = (End - 1) / BITWORD_SIZE;
243
    unsigned FirstWord = Begin / BITWORD_SIZE;
244
245
    for (unsigned i = LastWord + 1; i >= FirstWord + 1; --i) {
246
      unsigned CurrentWord = i - 1;
247
248
      BitWord Copy = Bits[CurrentWord];
249
      if (CurrentWord == LastWord) {
250
        unsigned LastBit = (End - 1) % BITWORD_SIZE;
251
        Copy &= maskTrailingOnes<BitWord>(LastBit + 1);
252
      }
253
254
      if (CurrentWord == FirstWord) {
255
        unsigned FirstBit = Begin % BITWORD_SIZE;
256
        Copy &= maskTrailingZeros<BitWord>(FirstBit);
257
      }
258
259
      if (Copy != 0)
260
        return (CurrentWord + 1) * BITWORD_SIZE - countLeadingZeros(Copy) - 1;
261
    }
262
263
    return -1;
264
  }
265
266
  /// find_first_unset_in - Returns the index of the first unset bit in the
267
  /// range [Begin, End).  Returns -1 if all bits in the range are set.
268
  int find_first_unset_in(unsigned Begin, unsigned End) const {
269
    assert(Begin <= End && End <= Size);
270
    if (Begin == End)
271
      return -1;
272
273
    unsigned FirstWord = Begin / BITWORD_SIZE;
274
    unsigned LastWord = (End - 1) / BITWORD_SIZE;
275
276
    // Check subsequent words.
277
    for (unsigned i = FirstWord; i <= LastWord; ++i) {
278
      BitWord Copy = Bits[i];
279
280
      if (i == FirstWord) {
281
        unsigned FirstBit = Begin % BITWORD_SIZE;
282
        Copy |= maskTrailingOnes<BitWord>(FirstBit);
283
      }
284
285
      if (i == LastWord) {
286
        unsigned LastBit = (End - 1) % BITWORD_SIZE;
287
        Copy |= maskTrailingZeros<BitWord>(LastBit + 1);
288
      }
289
      if (Copy != ~0UL) {
290
        unsigned Result = i * BITWORD_SIZE + countTrailingOnes(Copy);
291
        return Result < size() ? Result : -1;
292
      }
293
    }
294
    return -1;
295
  }
296
297
  /// find_last_unset_in - Returns the index of the last unset bit in the
298
  /// range [Begin, End).  Returns -1 if all bits in the range are set.
299
  int find_last_unset_in(unsigned Begin, unsigned End) const {
300
    assert(Begin <= End && End <= Size);
301
    if (Begin == End)
302
      return -1;
303
304
    unsigned LastWord = (End - 1) / BITWORD_SIZE;
305
    unsigned FirstWord = Begin / BITWORD_SIZE;
306
307
    for (unsigned i = LastWord + 1; i >= FirstWord + 1; --i) {
308
      unsigned CurrentWord = i - 1;
309
310
      BitWord Copy = Bits[CurrentWord];
311
      if (CurrentWord == LastWord) {
312
        unsigned LastBit = (End - 1) % BITWORD_SIZE;
313
        Copy |= maskTrailingZeros<BitWord>(LastBit + 1);
314
      }
315
316
      if (CurrentWord == FirstWord) {
317
        unsigned FirstBit = Begin % BITWORD_SIZE;
318
        Copy |= maskTrailingOnes<BitWord>(FirstBit);
319
      }
320
321
      if (Copy != ~0UL) {
322
        unsigned Result =
323
            (CurrentWord + 1) * BITWORD_SIZE - countLeadingOnes(Copy) - 1;
324
        return Result < Size ? Result : -1;
325
      }
326
    }
327
    return -1;
328
  }
329
330
  /// find_first - Returns the index of the first set bit, -1 if none
331
  /// of the bits are set.
332
18.2M
  int find_first() const { return find_first_in(0, Size); }
333
334
  /// find_last - Returns the index of the last set bit, -1 if none of the bits
335
  /// are set.
336
  int find_last() const { return find_last_in(0, Size); }
337
338
  /// find_next - Returns the index of the next set bit following the
339
  /// "Prev" bit. Returns -1 if the next set bit is not found.
340
198M
  int find_next(unsigned Prev) const { return find_first_in(Prev + 1, Size); }
341
342
  /// find_prev - Returns the index of the first set bit that precedes the
343
  /// the bit at \p PriorTo.  Returns -1 if all previous bits are unset.
344
  int find_prev(unsigned PriorTo) const { return find_last_in(0, PriorTo); }
345
346
  /// find_first_unset - Returns the index of the first unset bit, -1 if all
347
  /// of the bits are set.
348
  int find_first_unset() const { return find_first_unset_in(0, Size); }
349
350
  /// find_next_unset - Returns the index of the next unset bit following the
351
  /// "Prev" bit.  Returns -1 if all remaining bits are set.
352
  int find_next_unset(unsigned Prev) const {
353
    return find_first_unset_in(Prev + 1, Size);
354
  }
355
356
  /// find_last_unset - Returns the index of the last unset bit, -1 if all of
357
  /// the bits are set.
358
  int find_last_unset() const { return find_last_unset_in(0, Size); }
359
360
  /// find_prev_unset - Returns the index of the first unset bit that precedes
361
  /// the bit at \p PriorTo.  Returns -1 if all previous bits are set.
362
  int find_prev_unset(unsigned PriorTo) {
363
    return find_last_unset_in(0, PriorTo);
364
  }
365
366
  /// clear - Removes all bits from the bitvector. Does not change capacity.
367
58.6M
  void clear() {
368
58.6M
    Size = 0;
369
58.6M
  }
370
371
  /// resize - Grow or shrink the bitvector.
372
94.3M
  void resize(unsigned N, bool t = false) {
373
94.3M
    if (N > getBitCapacity()) {
374
14.4M
      unsigned OldCapacity = Bits.size();
375
14.4M
      grow(N);
376
14.4M
      init_words(Bits.drop_front(OldCapacity), t);
377
14.4M
    }
378
94.3M
379
94.3M
    // Set any old unused bits that are now included in the BitVector. This
380
94.3M
    // may set bits that are not included in the new vector, but we will clear
381
94.3M
    // them back out below.
382
94.3M
    if (N > Size)
383
55.1M
      set_unused_bits(t);
384
94.3M
385
94.3M
    // Update the size, and clear out any bits that are now unused
386
94.3M
    unsigned OldSize = Size;
387
94.3M
    Size = N;
388
94.3M
    if (t || 
N < OldSize92.2M
)
389
27.4M
      clear_unused_bits();
390
94.3M
  }
391
392
  void reserve(unsigned N) {
393
    if (N > getBitCapacity())
394
      grow(N);
395
  }
396
397
  // Set, reset, flip
398
16
  BitVector &set() {
399
16
    init_words(Bits, true);
400
16
    clear_unused_bits();
401
16
    return *this;
402
16
  }
403
404
878M
  BitVector &set(unsigned Idx) {
405
878M
    assert(Bits.data() && "Bits never allocated");
406
878M
    Bits[Idx / BITWORD_SIZE] |= BitWord(1) << (Idx % BITWORD_SIZE);
407
878M
    return *this;
408
878M
  }
409
410
  /// set - Efficiently set a range of bits in [I, E)
411
2.27k
  BitVector &set(unsigned I, unsigned E) {
412
2.27k
    assert(I <= E && "Attempted to set backwards range!");
413
2.27k
    assert(E <= size() && "Attempted to set out-of-bounds range!");
414
2.27k
415
2.27k
    if (I == E) 
return *this0
;
416
2.27k
417
2.27k
    if (I / BITWORD_SIZE == E / BITWORD_SIZE) {
418
2.17k
      BitWord EMask = 1UL << (E % BITWORD_SIZE);
419
2.17k
      BitWord IMask = 1UL << (I % BITWORD_SIZE);
420
2.17k
      BitWord Mask = EMask - IMask;
421
2.17k
      Bits[I / BITWORD_SIZE] |= Mask;
422
2.17k
      return *this;
423
2.17k
    }
424
97
425
97
    BitWord PrefixMask = ~0UL << (I % BITWORD_SIZE);
426
97
    Bits[I / BITWORD_SIZE] |= PrefixMask;
427
97
    I = alignTo(I, BITWORD_SIZE);
428
97
429
158
    for (; I + BITWORD_SIZE <= E; 
I += BITWORD_SIZE61
)
430
61
      Bits[I / BITWORD_SIZE] = ~0UL;
431
97
432
97
    BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1;
433
97
    if (I < E)
434
25
      Bits[I / BITWORD_SIZE] |= PostfixMask;
435
97
436
97
    return *this;
437
97
  }
438
439
19.8M
  BitVector &reset() {
440
19.8M
    init_words(Bits, false);
441
19.8M
    return *this;
442
19.8M
  }
443
444
205M
  BitVector &reset(unsigned Idx) {
445
205M
    Bits[Idx / BITWORD_SIZE] &= ~(BitWord(1) << (Idx % BITWORD_SIZE));
446
205M
    return *this;
447
205M
  }
448
449
  /// reset - Efficiently reset a range of bits in [I, E)
450
651
  BitVector &reset(unsigned I, unsigned E) {
451
651
    assert(I <= E && "Attempted to reset backwards range!");
452
651
    assert(E <= size() && "Attempted to reset out-of-bounds range!");
453
651
454
651
    if (I == E) 
return *this0
;
455
651
456
651
    if (I / BITWORD_SIZE == E / BITWORD_SIZE) {
457
634
      BitWord EMask = 1UL << (E % BITWORD_SIZE);
458
634
      BitWord IMask = 1UL << (I % BITWORD_SIZE);
459
634
      BitWord Mask = EMask - IMask;
460
634
      Bits[I / BITWORD_SIZE] &= ~Mask;
461
634
      return *this;
462
634
    }
463
17
464
17
    BitWord PrefixMask = ~0UL << (I % BITWORD_SIZE);
465
17
    Bits[I / BITWORD_SIZE] &= ~PrefixMask;
466
17
    I = alignTo(I, BITWORD_SIZE);
467
17
468
25
    for (; I + BITWORD_SIZE <= E; 
I += BITWORD_SIZE8
)
469
8
      Bits[I / BITWORD_SIZE] = 0UL;
470
17
471
17
    BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1;
472
17
    if (I < E)
473
5
      Bits[I / BITWORD_SIZE] &= ~PostfixMask;
474
17
475
17
    return *this;
476
17
  }
477
478
10.1k
  BitVector &flip() {
479
53.0k
    for (unsigned i = 0; i < NumBitWords(size()); 
++i42.9k
)
480
42.9k
      Bits[i] = ~Bits[i];
481
10.1k
    clear_unused_bits();
482
10.1k
    return *this;
483
10.1k
  }
484
485
  BitVector &flip(unsigned Idx) {
486
    Bits[Idx / BITWORD_SIZE] ^= BitWord(1) << (Idx % BITWORD_SIZE);
487
    return *this;
488
  }
489
490
  // Indexing.
491
541M
  reference operator[](unsigned Idx) {
492
541M
    assert (Idx < Size && "Out-of-bounds Bit access.");
493
541M
    return reference(*this, Idx);
494
541M
  }
495
496
2.38G
  bool operator[](unsigned Idx) const {
497
2.38G
    assert (Idx < Size && "Out-of-bounds Bit access.");
498
2.38G
    BitWord Mask = BitWord(1) << (Idx % BITWORD_SIZE);
499
2.38G
    return (Bits[Idx / BITWORD_SIZE] & Mask) != 0;
500
2.38G
  }
501
502
1.49G
  bool test(unsigned Idx) const {
503
1.49G
    return (*this)[Idx];
504
1.49G
  }
505
506
  /// Test if any common bits are set.
507
3.83M
  bool anyCommon(const BitVector &RHS) const {
508
3.83M
    unsigned ThisWords = NumBitWords(size());
509
3.83M
    unsigned RHSWords  = NumBitWords(RHS.size());
510
7.35M
    for (unsigned i = 0, e = std::min(ThisWords, RHSWords); i != e; 
++i3.52M
)
511
3.84M
      if (Bits[i] & RHS.Bits[i])
512
319k
        return true;
513
3.83M
    
return false3.51M
;
514
3.83M
  }
515
516
  // Comparison operators.
517
2.36M
  bool operator==(const BitVector &RHS) const {
518
2.36M
    unsigned ThisWords = NumBitWords(size());
519
2.36M
    unsigned RHSWords  = NumBitWords(RHS.size());
520
2.36M
    unsigned i;
521
23.6M
    for (i = 0; i != std::min(ThisWords, RHSWords); 
++i21.2M
)
522
21.3M
      if (Bits[i] != RHS.Bits[i])
523
59.6k
        return false;
524
2.36M
525
2.36M
    // Verify that any extra words are all zeros.
526
2.36M
    
if (2.30M
i != ThisWords2.30M
) {
527
0
      for (; i != ThisWords; ++i)
528
0
        if (Bits[i])
529
0
          return false;
530
2.30M
    } else if (i != RHSWords) {
531
0
      for (; i != RHSWords; ++i)
532
0
        if (RHS.Bits[i])
533
0
          return false;
534
0
    }
535
2.30M
    return true;
536
2.30M
  }
537
538
2.32M
  bool operator!=(const BitVector &RHS) const {
539
2.32M
    return !(*this == RHS);
540
2.32M
  }
541
542
  /// Intersection, union, disjoint union.
543
43.8k
  BitVector &operator&=(const BitVector &RHS) {
544
43.8k
    unsigned ThisWords = NumBitWords(size());
545
43.8k
    unsigned RHSWords  = NumBitWords(RHS.size());
546
43.8k
    unsigned i;
547
166k
    for (i = 0; i != std::min(ThisWords, RHSWords); 
++i122k
)
548
122k
      Bits[i] &= RHS.Bits[i];
549
43.8k
550
43.8k
    // Any bits that are just in this bitvector become zero, because they aren't
551
43.8k
    // in the RHS bit vector.  Any words only in RHS are ignored because they
552
43.8k
    // are already zero in the LHS.
553
43.8k
    for (; i != ThisWords; 
++i0
)
554
0
      Bits[i] = 0;
555
43.8k
556
43.8k
    return *this;
557
43.8k
  }
558
559
  /// reset - Reset bits that are set in RHS. Same as *this &= ~RHS.
560
48.2M
  BitVector &reset(const BitVector &RHS) {
561
48.2M
    unsigned ThisWords = NumBitWords(size());
562
48.2M
    unsigned RHSWords  = NumBitWords(RHS.size());
563
48.2M
    unsigned i;
564
96.1M
    for (i = 0; i != std::min(ThisWords, RHSWords); 
++i47.9M
)
565
47.9M
      Bits[i] &= ~RHS.Bits[i];
566
48.2M
    return *this;
567
48.2M
  }
568
569
  /// test - Check if (This - RHS) is zero.
570
  /// This is the same as reset(RHS) and any().
571
3.87M
  bool test(const BitVector &RHS) const {
572
3.87M
    unsigned ThisWords = NumBitWords(size());
573
3.87M
    unsigned RHSWords  = NumBitWords(RHS.size());
574
3.87M
    unsigned i;
575
5.49M
    for (i = 0; i != std::min(ThisWords, RHSWords); 
++i1.61M
)
576
1.65M
      if ((Bits[i] & ~RHS.Bits[i]) != 0)
577
37.8k
        return true;
578
3.87M
579
4.41M
    
for (; 3.83M
i != ThisWords ;
++i583k
)
580
1.75M
      if (Bits[i] != 0)
581
1.17M
        return true;
582
3.83M
583
3.83M
    
return false2.66M
;
584
3.83M
  }
585
586
55.0M
  BitVector &operator|=(const BitVector &RHS) {
587
55.0M
    if (size() < RHS.size())
588
4.11M
      resize(RHS.size());
589
110M
    for (size_t i = 0, e = NumBitWords(RHS.size()); i != e; 
++i55.1M
)
590
55.1M
      Bits[i] |= RHS.Bits[i];
591
55.0M
    return *this;
592
55.0M
  }
593
594
  BitVector &operator^=(const BitVector &RHS) {
595
    if (size() < RHS.size())
596
      resize(RHS.size());
597
    for (size_t i = 0, e = NumBitWords(RHS.size()); i != e; ++i)
598
      Bits[i] ^= RHS.Bits[i];
599
    return *this;
600
  }
601
602
  BitVector &operator>>=(unsigned N) {
603
    assert(N <= Size);
604
    if (LLVM_UNLIKELY(empty() || N == 0))
605
      return *this;
606
607
    unsigned NumWords = NumBitWords(Size);
608
    assert(NumWords >= 1);
609
610
    wordShr(N / BITWORD_SIZE);
611
612
    unsigned BitDistance = N % BITWORD_SIZE;
613
    if (BitDistance == 0)
614
      return *this;
615
616
    // When the shift size is not a multiple of the word size, then we have
617
    // a tricky situation where each word in succession needs to extract some
618
    // of the bits from the next word and or them into this word while
619
    // shifting this word to make room for the new bits.  This has to be done
620
    // for every word in the array.
621
622
    // Since we're shifting each word right, some bits will fall off the end
623
    // of each word to the right, and empty space will be created on the left.
624
    // The final word in the array will lose bits permanently, so starting at
625
    // the beginning, work forwards shifting each word to the right, and
626
    // OR'ing in the bits from the end of the next word to the beginning of
627
    // the current word.
628
629
    // Example:
630
    //   Starting with {0xAABBCCDD, 0xEEFF0011, 0x22334455} and shifting right
631
    //   by 4 bits.
632
    // Step 1: Word[0] >>= 4           ; 0x0ABBCCDD
633
    // Step 2: Word[0] |= 0x10000000   ; 0x1ABBCCDD
634
    // Step 3: Word[1] >>= 4           ; 0x0EEFF001
635
    // Step 4: Word[1] |= 0x50000000   ; 0x5EEFF001
636
    // Step 5: Word[2] >>= 4           ; 0x02334455
637
    // Result: { 0x1ABBCCDD, 0x5EEFF001, 0x02334455 }
638
    const BitWord Mask = maskTrailingOnes<BitWord>(BitDistance);
639
    const unsigned LSH = BITWORD_SIZE - BitDistance;
640
641
    for (unsigned I = 0; I < NumWords - 1; ++I) {
642
      Bits[I] >>= BitDistance;
643
      Bits[I] |= (Bits[I + 1] & Mask) << LSH;
644
    }
645
646
    Bits[NumWords - 1] >>= BitDistance;
647
648
    return *this;
649
  }
650
651
  BitVector &operator<<=(unsigned N) {
652
    assert(N <= Size);
653
    if (LLVM_UNLIKELY(empty() || N == 0))
654
      return *this;
655
656
    unsigned NumWords = NumBitWords(Size);
657
    assert(NumWords >= 1);
658
659
    wordShl(N / BITWORD_SIZE);
660
661
    unsigned BitDistance = N % BITWORD_SIZE;
662
    if (BitDistance == 0)
663
      return *this;
664
665
    // When the shift size is not a multiple of the word size, then we have
666
    // a tricky situation where each word in succession needs to extract some
667
    // of the bits from the previous word and or them into this word while
668
    // shifting this word to make room for the new bits.  This has to be done
669
    // for every word in the array.  This is similar to the algorithm outlined
670
    // in operator>>=, but backwards.
671
672
    // Since we're shifting each word left, some bits will fall off the end
673
    // of each word to the left, and empty space will be created on the right.
674
    // The first word in the array will lose bits permanently, so starting at
675
    // the end, work backwards shifting each word to the left, and OR'ing
676
    // in the bits from the end of the next word to the beginning of the
677
    // current word.
678
679
    // Example:
680
    //   Starting with {0xAABBCCDD, 0xEEFF0011, 0x22334455} and shifting left
681
    //   by 4 bits.
682
    // Step 1: Word[2] <<= 4           ; 0x23344550
683
    // Step 2: Word[2] |= 0x0000000E   ; 0x2334455E
684
    // Step 3: Word[1] <<= 4           ; 0xEFF00110
685
    // Step 4: Word[1] |= 0x0000000A   ; 0xEFF0011A
686
    // Step 5: Word[0] <<= 4           ; 0xABBCCDD0
687
    // Result: { 0xABBCCDD0, 0xEFF0011A, 0x2334455E }
688
    const BitWord Mask = maskLeadingOnes<BitWord>(BitDistance);
689
    const unsigned RSH = BITWORD_SIZE - BitDistance;
690
691
    for (int I = NumWords - 1; I > 0; --I) {
692
      Bits[I] <<= BitDistance;
693
      Bits[I] |= (Bits[I - 1] & Mask) >> RSH;
694
    }
695
    Bits[0] <<= BitDistance;
696
    clear_unused_bits();
697
698
    return *this;
699
  }
700
701
  // Assignment operator.
702
7.28M
  const BitVector &operator=(const BitVector &RHS) {
703
7.28M
    if (this == &RHS) 
return *this407
;
704
7.28M
705
7.28M
    Size = RHS.size();
706
7.28M
    unsigned RHSWords = NumBitWords(Size);
707
7.28M
    if (Size <= getBitCapacity()) {
708
5.42M
      if (Size)
709
5.42M
        std::memcpy(Bits.data(), RHS.Bits.data(), RHSWords * sizeof(BitWord));
710
5.42M
      clear_unused_bits();
711
5.42M
      return *this;
712
5.42M
    }
713
1.85M
714
1.85M
    // Grow the bitvector to have enough elements.
715
1.85M
    unsigned NewCapacity = RHSWords;
716
1.85M
    assert(NewCapacity > 0 && "negative capacity?");
717
1.85M
    auto NewBits = allocate(NewCapacity);
718
1.85M
    std::memcpy(NewBits.data(), RHS.Bits.data(), NewCapacity * sizeof(BitWord));
719
1.85M
720
1.85M
    // Destroy the old bits.
721
1.85M
    std::free(Bits.data());
722
1.85M
    Bits = NewBits;
723
1.85M
724
1.85M
    return *this;
725
1.85M
  }
726
727
10.3M
  const BitVector &operator=(BitVector &&RHS) {
728
10.3M
    if (this == &RHS) 
return *this0
;
729
10.3M
730
10.3M
    std::free(Bits.data());
731
10.3M
    Bits = RHS.Bits;
732
10.3M
    Size = RHS.Size;
733
10.3M
734
10.3M
    RHS.Bits = MutableArrayRef<BitWord>();
735
10.3M
    RHS.Size = 0;
736
10.3M
737
10.3M
    return *this;
738
10.3M
  }
739
740
  void swap(BitVector &RHS) {
741
    std::swap(Bits, RHS.Bits);
742
    std::swap(Size, RHS.Size);
743
  }
744
745
  //===--------------------------------------------------------------------===//
746
  // Portable bit mask operations.
747
  //===--------------------------------------------------------------------===//
748
  //
749
  // These methods all operate on arrays of uint32_t, each holding 32 bits. The
750
  // fixed word size makes it easier to work with literal bit vector constants
751
  // in portable code.
752
  //
753
  // The LSB in each word is the lowest numbered bit.  The size of a portable
754
  // bit mask is always a whole multiple of 32 bits.  If no bit mask size is
755
  // given, the bit mask is assumed to cover the entire BitVector.
756
757
  /// setBitsInMask - Add '1' bits from Mask to this vector. Don't resize.
758
  /// This computes "*this |= Mask".
759
3.03M
  void setBitsInMask(const uint32_t *Mask, unsigned MaskWords = ~0u) {
760
3.03M
    applyMask<true, false>(Mask, MaskWords);
761
3.03M
  }
762
763
  /// clearBitsInMask - Clear any bits in this vector that are set in Mask.
764
  /// Don't resize. This computes "*this &= ~Mask".
765
  void clearBitsInMask(const uint32_t *Mask, unsigned MaskWords = ~0u) {
766
    applyMask<false, false>(Mask, MaskWords);
767
  }
768
769
  /// setBitsNotInMask - Add a bit to this vector for every '0' bit in Mask.
770
  /// Don't resize.  This computes "*this |= ~Mask".
771
2.00M
  void setBitsNotInMask(const uint32_t *Mask, unsigned MaskWords = ~0u) {
772
2.00M
    applyMask<true, true>(Mask, MaskWords);
773
2.00M
  }
774
775
  /// clearBitsNotInMask - Clear a bit in this vector for every '0' bit in Mask.
776
  /// Don't resize.  This computes "*this &= Mask".
777
23.3M
  void clearBitsNotInMask(const uint32_t *Mask, unsigned MaskWords = ~0u) {
778
23.3M
    applyMask<false, true>(Mask, MaskWords);
779
23.3M
  }
780
781
private:
782
  /// Perform a logical left shift of \p Count words by moving everything
783
  /// \p Count words to the right in memory.
784
  ///
785
  /// While confusing, words are stored from least significant at Bits[0] to
786
  /// most significant at Bits[NumWords-1].  A logical shift left, however,
787
  /// moves the current least significant bit to a higher logical index, and
788
  /// fills the previous least significant bits with 0.  Thus, we actually
789
  /// need to move the bytes of the memory to the right, not to the left.
790
  /// Example:
791
  ///   Words = [0xBBBBAAAA, 0xDDDDFFFF, 0x00000000, 0xDDDD0000]
792
  /// represents a BitVector where 0xBBBBAAAA contain the least significant
793
  /// bits.  So if we want to shift the BitVector left by 2 words, we need to
794
  /// turn this into 0x00000000 0x00000000 0xBBBBAAAA 0xDDDDFFFF by using a
795
  /// memmove which moves right, not left.
796
  void wordShl(uint32_t Count) {
797
    if (Count == 0)
798
      return;
799
800
    uint32_t NumWords = NumBitWords(Size);
801
802
    auto Src = Bits.take_front(NumWords).drop_back(Count);
803
    auto Dest = Bits.take_front(NumWords).drop_front(Count);
804
805
    // Since we always move Word-sized chunks of data with src and dest both
806
    // aligned to a word-boundary, we don't need to worry about endianness
807
    // here.
808
    std::memmove(Dest.begin(), Src.begin(), Dest.size() * sizeof(BitWord));
809
    std::memset(Bits.data(), 0, Count * sizeof(BitWord));
810
    clear_unused_bits();
811
  }
812
813
  /// Perform a logical right shift of \p Count words by moving those
814
  /// words to the left in memory.  See wordShl for more information.
815
  ///
816
  void wordShr(uint32_t Count) {
817
    if (Count == 0)
818
      return;
819
820
    uint32_t NumWords = NumBitWords(Size);
821
822
    auto Src = Bits.take_front(NumWords).drop_front(Count);
823
    auto Dest = Bits.take_front(NumWords).drop_back(Count);
824
    assert(Dest.size() == Src.size());
825
826
    std::memmove(Dest.begin(), Src.begin(), Dest.size() * sizeof(BitWord));
827
    std::memset(Dest.end(), 0, Count * sizeof(BitWord));
828
  }
829
830
54.3M
  MutableArrayRef<BitWord> allocate(size_t NumWords) {
831
54.3M
    BitWord *RawBits = static_cast<BitWord *>(
832
54.3M
        safe_malloc(NumWords * sizeof(BitWord)));
833
54.3M
    return MutableArrayRef<BitWord>(RawBits, NumWords);
834
54.3M
  }
835
836
  int next_unset_in_word(int WordIndex, BitWord Word) const {
837
    unsigned Result = WordIndex * BITWORD_SIZE + countTrailingOnes(Word);
838
    return Result < size() ? Result : -1;
839
  }
840
841
374M
  unsigned NumBitWords(unsigned S) const {
842
374M
    return (S + BITWORD_SIZE-1) / BITWORD_SIZE;
843
374M
  }
844
845
  // Set the unused bits in the high words.
846
107M
  void set_unused_bits(bool t = true) {
847
107M
    //  Set high words first.
848
107M
    unsigned UsedWords = NumBitWords(Size);
849
107M
    if (Bits.size() > UsedWords)
850
83.7M
      init_words(Bits.drop_front(UsedWords), t);
851
107M
852
107M
    //  Then set any stray high bits of the last used word.
853
107M
    unsigned ExtraBits = Size % BITWORD_SIZE;
854
107M
    if (ExtraBits) {
855
38.8M
      BitWord ExtraBitMask = ~0UL << ExtraBits;
856
38.8M
      if (t)
857
1.20k
        Bits[UsedWords-1] |= ExtraBitMask;
858
38.8M
      else
859
38.8M
        Bits[UsedWords-1] &= ~ExtraBitMask;
860
38.8M
    }
861
107M
  }
862
863
  // Clear the unused bits in the high words.
864
52.4M
  void clear_unused_bits() {
865
52.4M
    set_unused_bits(false);
866
52.4M
  }
867
868
14.4M
  void grow(unsigned NewSize) {
869
14.4M
    size_t NewCapacity = std::max<size_t>(NumBitWords(NewSize), Bits.size() * 2);
870
14.4M
    assert(NewCapacity > 0 && "realloc-ing zero space");
871
14.4M
    BitWord *NewBits = static_cast<BitWord *>(
872
14.4M
        safe_realloc(Bits.data(), NewCapacity * sizeof(BitWord)));
873
14.4M
    Bits = MutableArrayRef<BitWord>(NewBits, NewCapacity);
874
14.4M
    clear_unused_bits();
875
14.4M
  }
876
877
162M
  void init_words(MutableArrayRef<BitWord> B, bool t) {
878
162M
    if (B.size() > 0)
879
162M
      memset(B.data(), 0 - (int)t, B.size() * sizeof(BitWord));
880
162M
  }
881
882
  template<bool AddBits, bool InvertMask>
883
28.4M
  void applyMask(const uint32_t *Mask, unsigned MaskWords) {
884
28.4M
    static_assert(BITWORD_SIZE % 32 == 0, "Unsupported BitWord size.");
885
28.4M
    MaskWords = std::min(MaskWords, (size() + 31) / 32);
886
28.4M
    const unsigned Scale = BITWORD_SIZE / 32;
887
28.4M
    unsigned i;
888
269M
    for (i = 0; MaskWords >= Scale; 
++i, MaskWords -= Scale240M
) {
889
240M
      BitWord BW = Bits[i];
890
240M
      // This inner loop should unroll completely when BITWORD_SIZE > 32.
891
722M
      for (unsigned b = 0; b != BITWORD_SIZE; 
b += 32481M
) {
892
481M
        uint32_t M = *Mask++;
893
481M
        if (InvertMask) 
M = ~M471M
;
894
481M
        if (AddBits) 
BW |= BitWord(M) << b45.6M
;
895
436M
        else         BW &= ~(BitWord(M) << b);
896
481M
      }
897
240M
      Bits[i] = BW;
898
240M
    }
899
53.0M
    for (unsigned b = 0; MaskWords; 
b += 32, --MaskWords24.5M
) {
900
24.5M
      uint32_t M = *Mask++;
901
24.5M
      if (InvertMask) 
M = ~M24.4M
;
902
24.5M
      if (AddBits) 
Bits[i] |= BitWord(M) << b2.03M
;
903
22.5M
      else         Bits[i] &= ~(BitWord(M) << b);
904
24.5M
    }
905
28.4M
    if (AddBits)
906
5.04M
      clear_unused_bits();
907
28.4M
  }
void llvm::BitVector::applyMask<false, true>(unsigned int const*, unsigned int)
Line
Count
Source
883
23.3M
  void applyMask(const uint32_t *Mask, unsigned MaskWords) {
884
23.3M
    static_assert(BITWORD_SIZE % 32 == 0, "Unsupported BitWord size.");
885
23.3M
    MaskWords = std::min(MaskWords, (size() + 31) / 32);
886
23.3M
    const unsigned Scale = BITWORD_SIZE / 32;
887
23.3M
    unsigned i;
888
241M
    for (i = 0; MaskWords >= Scale; 
++i, MaskWords -= Scale218M
) {
889
218M
      BitWord BW = Bits[i];
890
218M
      // This inner loop should unroll completely when BITWORD_SIZE > 32.
891
654M
      for (unsigned b = 0; b != BITWORD_SIZE; 
b += 32436M
) {
892
436M
        uint32_t M = *Mask++;
893
436M
        if (InvertMask) 
M = ~M436M
;
894
436M
        if (AddBits) 
BW |= BitWord(M) << b0
;
895
436M
        else         BW &= ~(BitWord(M) << b);
896
436M
      }
897
218M
      Bits[i] = BW;
898
218M
    }
899
45.9M
    for (unsigned b = 0; MaskWords; 
b += 32, --MaskWords22.5M
) {
900
22.5M
      uint32_t M = *Mask++;
901
22.5M
      if (InvertMask) M = ~M;
902
22.5M
      if (AddBits) 
Bits[i] |= BitWord(M) << b0
;
903
22.5M
      else         Bits[i] &= ~(BitWord(M) << b);
904
22.5M
    }
905
23.3M
    if (AddBits)
906
0
      clear_unused_bits();
907
23.3M
  }
void llvm::BitVector::applyMask<true, false>(unsigned int const*, unsigned int)
Line
Count
Source
883
3.03M
  void applyMask(const uint32_t *Mask, unsigned MaskWords) {
884
3.03M
    static_assert(BITWORD_SIZE % 32 == 0, "Unsupported BitWord size.");
885
3.03M
    MaskWords = std::min(MaskWords, (size() + 31) / 32);
886
3.03M
    const unsigned Scale = BITWORD_SIZE / 32;
887
3.03M
    unsigned i;
888
8.24M
    for (i = 0; MaskWords >= Scale; 
++i, MaskWords -= Scale5.21M
) {
889
5.21M
      BitWord BW = Bits[i];
890
5.21M
      // This inner loop should unroll completely when BITWORD_SIZE > 32.
891
15.6M
      for (unsigned b = 0; b != BITWORD_SIZE; 
b += 3210.4M
) {
892
10.4M
        uint32_t M = *Mask++;
893
10.4M
        if (InvertMask) 
M = ~M0
;
894
10.4M
        if (AddBits) 
BW |= BitWord(M) << b10.4M
;
895
2
        else         BW &= ~(BitWord(M) << b);
896
10.4M
      }
897
5.21M
      Bits[i] = BW;
898
5.21M
    }
899
3.18M
    for (unsigned b = 0; MaskWords; 
b += 32, --MaskWords141k
) {
900
141k
      uint32_t M = *Mask++;
901
141k
      if (InvertMask) 
M = ~M0
;
902
141k
      if (AddBits) Bits[i] |=   BitWord(M) << b;
903
0
      else         Bits[i] &= ~(BitWord(M) << b);
904
141k
    }
905
3.03M
    if (AddBits)
906
3.03M
      clear_unused_bits();
907
3.03M
  }
Unexecuted instantiation: void llvm::BitVector::applyMask<false, false>(unsigned int const*, unsigned int)
void llvm::BitVector::applyMask<true, true>(unsigned int const*, unsigned int)
Line
Count
Source
883
2.00M
  void applyMask(const uint32_t *Mask, unsigned MaskWords) {
884
2.00M
    static_assert(BITWORD_SIZE % 32 == 0, "Unsupported BitWord size.");
885
2.00M
    MaskWords = std::min(MaskWords, (size() + 31) / 32);
886
2.00M
    const unsigned Scale = BITWORD_SIZE / 32;
887
2.00M
    unsigned i;
888
19.5M
    for (i = 0; MaskWords >= Scale; 
++i, MaskWords -= Scale17.5M
) {
889
17.5M
      BitWord BW = Bits[i];
890
17.5M
      // This inner loop should unroll completely when BITWORD_SIZE > 32.
891
52.7M
      for (unsigned b = 0; b != BITWORD_SIZE; 
b += 3235.1M
) {
892
35.1M
        uint32_t M = *Mask++;
893
35.1M
        if (InvertMask) M = ~M;
894
35.1M
        if (AddBits) BW |=   BitWord(M) << b;
895
0
        else         BW &= ~(BitWord(M) << b);
896
35.1M
      }
897
17.5M
      Bits[i] = BW;
898
17.5M
    }
899
3.89M
    for (unsigned b = 0; MaskWords; 
b += 32, --MaskWords1.88M
) {
900
1.88M
      uint32_t M = *Mask++;
901
1.88M
      if (InvertMask) M = ~M;
902
1.88M
      if (AddBits) Bits[i] |=   BitWord(M) << b;
903
0
      else         Bits[i] &= ~(BitWord(M) << b);
904
1.88M
    }
905
2.00M
    if (AddBits)
906
2.00M
      clear_unused_bits();
907
2.00M
  }
908
909
public:
910
  /// Return the size (in bytes) of the bit vector.
911
1
  size_t getMemorySize() const { return Bits.size() * sizeof(BitWord); }
912
101M
  size_t getBitCapacity() const { return Bits.size() * BITWORD_SIZE; }
913
};
914
915
1
inline size_t capacity_in_bytes(const BitVector &X) {
916
1
  return X.getMemorySize();
917
1
}
918
919
} // end namespace llvm
920
921
namespace std {
922
  /// Implement std::swap in terms of BitVector swap.
923
  inline void
924
  swap(llvm::BitVector &LHS, llvm::BitVector &RHS) {
925
    LHS.swap(RHS);
926
  }
927
} // end namespace std
928
929
#endif // LLVM_ADT_BITVECTOR_H