Coverage Report

Created: 2018-11-13 17:19

/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
188M
  void advance() {
37
188M
    assert(Current != -1 && "Trying to advance past end.");
38
188M
    Current = Parent.find_next(Current);
39
188M
  }
llvm::const_set_bits_iterator_impl<llvm::BitVector>::advance()
Line
Count
Source
36
183M
  void advance() {
37
183M
    assert(Current != -1 && "Trying to advance past end.");
38
183M
    Current = Parent.find_next(Current);
39
183M
  }
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
33.8M
      : 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
27.7M
      : 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
16.9M
      : 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
13.8M
      : 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
188M
  const_set_bits_iterator_impl &operator++() {
55
188M
    advance();
56
188M
    return *this;
57
188M
  }
llvm::const_set_bits_iterator_impl<llvm::BitVector>::operator++()
Line
Count
Source
54
183M
  const_set_bits_iterator_impl &operator++() {
55
183M
    advance();
56
183M
    return *this;
57
183M
  }
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
188M
  unsigned operator*() const { return Current; }
llvm::const_set_bits_iterator_impl<llvm::BitVector>::operator*() const
Line
Count
Source
59
183M
  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
205M
  bool operator!=(const const_set_bits_iterator_impl &Other) const {
68
205M
    assert(&Parent == &Other.Parent &&
69
205M
           "Comparing iterators from different BitVectors");
70
205M
    return Current != Other.Current;
71
205M
  }
llvm::const_set_bits_iterator_impl<llvm::BitVector>::operator!=(llvm::const_set_bits_iterator_impl<llvm::BitVector> const&) const
Line
Count
Source
67
197M
  bool operator!=(const const_set_bits_iterator_impl &Other) const {
68
197M
    assert(&Parent == &Other.Parent &&
69
197M
           "Comparing iterators from different BitVectors");
70
197M
    return Current != Other.Current;
71
197M
  }
llvm::const_set_bits_iterator_impl<llvm::SmallBitVector>::operator!=(llvm::const_set_bits_iterator_impl<llvm::SmallBitVector> const&) const
Line
Count
Source
67
7.80M
  bool operator!=(const const_set_bits_iterator_impl &Other) const {
68
7.80M
    assert(&Parent == &Other.Parent &&
69
7.80M
           "Comparing iterators from different BitVectors");
70
7.80M
    return Current != Other.Current;
71
7.80M
  }
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
728M
    reference(BitVector &b, unsigned Idx) {
96
728M
      WordRef = &b.Bits[Idx / BITWORD_SIZE];
97
728M
      BitPos = Idx % BITWORD_SIZE;
98
728M
    }
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
12.9M
    reference& operator=(bool t) {
109
12.9M
      if (t)
110
3.85M
        *WordRef |= BitWord(1) << BitPos;
111
9.04M
      else
112
9.04M
        *WordRef &= ~(BitWord(1) << BitPos);
113
12.9M
      return *this;
114
12.9M
    }
115
116
715M
    operator bool() const {
117
715M
      return ((*WordRef) & (BitWord(1) << BitPos)) != 0;
118
715M
    }
119
  };
120
121
  typedef const_set_bits_iterator_impl<BitVector> const_set_bits_iterator;
122
  typedef const_set_bits_iterator set_iterator;
123
124
13.8M
  const_set_bits_iterator set_bits_begin() const {
125
13.8M
    return const_set_bits_iterator(*this);
126
13.8M
  }
127
13.8M
  const_set_bits_iterator set_bits_end() const {
128
13.8M
    return const_set_bits_iterator(*this, -1);
129
13.8M
  }
130
13.8M
  iterator_range<const_set_bits_iterator> set_bits() const {
131
13.8M
    return make_range(set_bits_begin(), set_bits_end());
132
13.8M
  }
133
134
  /// BitVector default ctor - Creates an empty bitvector.
135
38.8M
  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
45.8M
  explicit BitVector(unsigned s, bool t = false) : Size(s) {
140
45.8M
    size_t Capacity = NumBitWords(s);
141
45.8M
    Bits = allocate(Capacity);
142
45.8M
    init_words(Bits, t);
143
45.8M
    if (t)
144
95.2k
      clear_unused_bits();
145
45.8M
  }
146
147
  /// BitVector copy ctor.
148
8.54M
  BitVector(const BitVector &RHS) : Size(RHS.size()) {
149
8.54M
    if (Size == 0) {
150
587k
      Bits = MutableArrayRef<BitWord>();
151
587k
      return;
152
587k
    }
153
7.95M
154
7.95M
    size_t Capacity = NumBitWords(RHS.size());
155
7.95M
    Bits = allocate(Capacity);
156
7.95M
    std::memcpy(Bits.data(), RHS.Bits.data(), Capacity * sizeof(BitWord));
157
7.95M
  }
158
159
6.27M
  BitVector(BitVector &&RHS) : Bits(RHS.Bits), Size(RHS.Size) {
160
6.27M
    RHS.Bits = MutableArrayRef<BitWord>();
161
6.27M
    RHS.Size = 0;
162
6.27M
  }
163
164
99.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
496M
  size_type size() const { return Size; }
171
172
  /// count - Returns the number of bits which are set.
173
1.55M
  size_type count() const {
174
1.55M
    unsigned NumBits = 0;
175
12.1M
    for (unsigned i = 0; i < NumBitWords(size()); 
++i10.6M
)
176
10.6M
      NumBits += countPopulation(Bits[i]);
177
1.55M
    return NumBits;
178
1.55M
  }
179
180
  /// any - Returns true if any bit is set.
181
6.22M
  bool any() const {
182
11.3M
    for (unsigned i = 0; i < NumBitWords(size()); 
++i5.12M
)
183
7.91M
      if (Bits[i] != 0)
184
2.79M
        return true;
185
6.22M
    
return false3.43M
;
186
6.22M
  }
187
188
  /// all - Returns true if all bits are set.
189
2.50k
  bool all() const {
190
2.51k
    for (unsigned i = 0; i < Size / BITWORD_SIZE; 
++i7
)
191
11
      if (Bits[i] != ~0UL)
192
4
        return false;
193
2.50k
194
2.50k
    // If bits remain check that they are ones. The unused bits are always zero.
195
2.50k
    
if (unsigned 2.50k
Remainder2.50k
= Size % BITWORD_SIZE)
196
2.48k
      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
645k
  bool none() const {
203
645k
    return !any();
204
645k
  }
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
210M
  int find_first_in(unsigned Begin, unsigned End) const {
209
210M
    assert(Begin <= End && End <= Size);
210
210M
    if (Begin == End)
211
3.08M
      return -1;
212
207M
213
207M
    unsigned FirstWord = Begin / BITWORD_SIZE;
214
207M
    unsigned LastWord = (End - 1) / BITWORD_SIZE;
215
207M
216
207M
    // Check subsequent words.
217
268M
    for (unsigned i = FirstWord; i <= LastWord; 
++i60.8M
) {
218
254M
      BitWord Copy = Bits[i];
219
254M
220
254M
      if (i == FirstWord) {
221
207M
        unsigned FirstBit = Begin % BITWORD_SIZE;
222
207M
        Copy &= maskTrailingZeros<BitWord>(FirstBit);
223
207M
      }
224
254M
225
254M
      if (i == LastWord) {
226
86.8M
        unsigned LastBit = (End - 1) % BITWORD_SIZE;
227
86.8M
        Copy &= maskTrailingOnes<BitWord>(LastBit + 1);
228
86.8M
      }
229
254M
      if (Copy != 0)
230
193M
        return i * BITWORD_SIZE + countTrailingZeros(Copy);
231
254M
    }
232
207M
    
return -113.3M
;
233
207M
  }
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
192M
  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.9M
  void resize(unsigned N, bool t = false) {
373
94.9M
    if (N > getBitCapacity()) {
374
14.6M
      unsigned OldCapacity = Bits.size();
375
14.6M
      grow(N);
376
14.6M
      init_words(Bits.drop_front(OldCapacity), t);
377
14.6M
    }
378
94.9M
379
94.9M
    // Set any old unused bits that are now included in the BitVector. This
380
94.9M
    // may set bits that are not included in the new vector, but we will clear
381
94.9M
    // them back out below.
382
94.9M
    if (N > Size)
383
55.5M
      set_unused_bits(t);
384
94.9M
385
94.9M
    // Update the size, and clear out any bits that are now unused
386
94.9M
    unsigned OldSize = Size;
387
94.9M
    Size = N;
388
94.9M
    if (t || 
N < OldSize92.8M
)
389
27.4M
      clear_unused_bits();
390
94.9M
  }
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
912M
  BitVector &set(unsigned Idx) {
405
912M
    assert(Bits.data() && "Bits never allocated");
406
912M
    Bits[Idx / BITWORD_SIZE] |= BitWord(1) << (Idx % BITWORD_SIZE);
407
912M
    return *this;
408
912M
  }
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.9M
  BitVector &reset() {
440
19.9M
    init_words(Bits, false);
441
19.9M
    return *this;
442
19.9M
  }
443
444
199M
  BitVector &reset(unsigned Idx) {
445
199M
    Bits[Idx / BITWORD_SIZE] &= ~(BitWord(1) << (Idx % BITWORD_SIZE));
446
199M
    return *this;
447
199M
  }
448
449
  /// reset - Efficiently reset a range of bits in [I, E)
450
882
  BitVector &reset(unsigned I, unsigned E) {
451
882
    assert(I <= E && "Attempted to reset backwards range!");
452
882
    assert(E <= size() && "Attempted to reset out-of-bounds range!");
453
882
454
882
    if (I == E) 
return *this0
;
455
882
456
882
    if (I / BITWORD_SIZE == E / BITWORD_SIZE) {
457
849
      BitWord EMask = 1UL << (E % BITWORD_SIZE);
458
849
      BitWord IMask = 1UL << (I % BITWORD_SIZE);
459
849
      BitWord Mask = EMask - IMask;
460
849
      Bits[I / BITWORD_SIZE] &= ~Mask;
461
849
      return *this;
462
849
    }
463
33
464
33
    BitWord PrefixMask = ~0UL << (I % BITWORD_SIZE);
465
33
    Bits[I / BITWORD_SIZE] &= ~PrefixMask;
466
33
    I = alignTo(I, BITWORD_SIZE);
467
33
468
42
    for (; I + BITWORD_SIZE <= E; 
I += BITWORD_SIZE9
)
469
9
      Bits[I / BITWORD_SIZE] = 0UL;
470
33
471
33
    BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1;
472
33
    if (I < E)
473
6
      Bits[I / BITWORD_SIZE] &= ~PostfixMask;
474
33
475
33
    return *this;
476
33
  }
477
478
10.2k
  BitVector &flip() {
479
53.2k
    for (unsigned i = 0; i < NumBitWords(size()); 
++i43.0k
)
480
43.0k
      Bits[i] = ~Bits[i];
481
10.2k
    clear_unused_bits();
482
10.2k
    return *this;
483
10.2k
  }
484
485
  BitVector &flip(unsigned Idx) {
486
    Bits[Idx / BITWORD_SIZE] ^= BitWord(1) << (Idx % BITWORD_SIZE);
487
    return *this;
488
  }
489
490
  // Indexing.
491
728M
  reference operator[](unsigned Idx) {
492
728M
    assert (Idx < Size && "Out-of-bounds Bit access.");
493
728M
    return reference(*this, Idx);
494
728M
  }
495
496
2.37G
  bool operator[](unsigned Idx) const {
497
2.37G
    assert (Idx < Size && "Out-of-bounds Bit access.");
498
2.37G
    BitWord Mask = BitWord(1) << (Idx % BITWORD_SIZE);
499
2.37G
    return (Bits[Idx / BITWORD_SIZE] & Mask) != 0;
500
2.37G
  }
501
502
1.49G
  bool test(unsigned Idx) const {
503
1.49G
    return (*this)[Idx];
504
1.49G
  }
505
506
  // Push single bit to end of vector.
507
  void push_back(bool Val) {
508
    unsigned OldSize = Size;
509
    unsigned NewSize = Size + 1;
510
511
    // Resize, which will insert zeros.
512
    // If we already fit then the unused bits will be already zero.
513
    if (NewSize > getBitCapacity())
514
      resize(NewSize, false);
515
    else
516
      Size = NewSize;
517
518
    // If true, set single bit.
519
    if (Val)
520
      set(OldSize);
521
  }
522
523
  /// Test if any common bits are set.
524
3.99M
  bool anyCommon(const BitVector &RHS) const {
525
3.99M
    unsigned ThisWords = NumBitWords(size());
526
3.99M
    unsigned RHSWords  = NumBitWords(RHS.size());
527
7.66M
    for (unsigned i = 0, e = std::min(ThisWords, RHSWords); i != e; 
++i3.67M
)
528
4.00M
      if (Bits[i] & RHS.Bits[i])
529
330k
        return true;
530
3.99M
    
return false3.66M
;
531
3.99M
  }
532
533
  // Comparison operators.
534
2.42M
  bool operator==(const BitVector &RHS) const {
535
2.42M
    unsigned ThisWords = NumBitWords(size());
536
2.42M
    unsigned RHSWords  = NumBitWords(RHS.size());
537
2.42M
    unsigned i;
538
24.0M
    for (i = 0; i != std::min(ThisWords, RHSWords); 
++i21.6M
)
539
21.7M
      if (Bits[i] != RHS.Bits[i])
540
60.7k
        return false;
541
2.42M
542
2.42M
    // Verify that any extra words are all zeros.
543
2.42M
    
if (2.36M
i != ThisWords2.36M
) {
544
0
      for (; i != ThisWords; ++i)
545
0
        if (Bits[i])
546
0
          return false;
547
2.36M
    } else if (i != RHSWords) {
548
0
      for (; i != RHSWords; ++i)
549
0
        if (RHS.Bits[i])
550
0
          return false;
551
0
    }
552
2.36M
    return true;
553
2.36M
  }
554
555
2.38M
  bool operator!=(const BitVector &RHS) const {
556
2.38M
    return !(*this == RHS);
557
2.38M
  }
558
559
  /// Intersection, union, disjoint union.
560
43.8k
  BitVector &operator&=(const BitVector &RHS) {
561
43.8k
    unsigned ThisWords = NumBitWords(size());
562
43.8k
    unsigned RHSWords  = NumBitWords(RHS.size());
563
43.8k
    unsigned i;
564
165k
    for (i = 0; i != std::min(ThisWords, RHSWords); 
++i121k
)
565
121k
      Bits[i] &= RHS.Bits[i];
566
43.8k
567
43.8k
    // Any bits that are just in this bitvector become zero, because they aren't
568
43.8k
    // in the RHS bit vector.  Any words only in RHS are ignored because they
569
43.8k
    // are already zero in the LHS.
570
43.8k
    for (; i != ThisWords; 
++i0
)
571
0
      Bits[i] = 0;
572
43.8k
573
43.8k
    return *this;
574
43.8k
  }
575
576
  /// reset - Reset bits that are set in RHS. Same as *this &= ~RHS.
577
50.4M
  BitVector &reset(const BitVector &RHS) {
578
50.4M
    unsigned ThisWords = NumBitWords(size());
579
50.4M
    unsigned RHSWords  = NumBitWords(RHS.size());
580
50.4M
    unsigned i;
581
100M
    for (i = 0; i != std::min(ThisWords, RHSWords); 
++i50.1M
)
582
50.1M
      Bits[i] &= ~RHS.Bits[i];
583
50.4M
    return *this;
584
50.4M
  }
585
586
  /// test - Check if (This - RHS) is zero.
587
  /// This is the same as reset(RHS) and any().
588
3.85M
  bool test(const BitVector &RHS) const {
589
3.85M
    unsigned ThisWords = NumBitWords(size());
590
3.85M
    unsigned RHSWords  = NumBitWords(RHS.size());
591
3.85M
    unsigned i;
592
5.46M
    for (i = 0; i != std::min(ThisWords, RHSWords); 
++i1.60M
)
593
1.64M
      if ((Bits[i] & ~RHS.Bits[i]) != 0)
594
37.7k
        return true;
595
3.85M
596
4.40M
    
for (; 3.82M
i != ThisWords ;
++i584k
)
597
1.75M
      if (Bits[i] != 0)
598
1.17M
        return true;
599
3.82M
600
3.82M
    
return false2.64M
;
601
3.82M
  }
602
603
57.2M
  BitVector &operator|=(const BitVector &RHS) {
604
57.2M
    if (size() < RHS.size())
605
4.10M
      resize(RHS.size());
606
114M
    for (size_t i = 0, e = NumBitWords(RHS.size()); i != e; 
++i57.3M
)
607
57.3M
      Bits[i] |= RHS.Bits[i];
608
57.2M
    return *this;
609
57.2M
  }
610
611
  BitVector &operator^=(const BitVector &RHS) {
612
    if (size() < RHS.size())
613
      resize(RHS.size());
614
    for (size_t i = 0, e = NumBitWords(RHS.size()); i != e; ++i)
615
      Bits[i] ^= RHS.Bits[i];
616
    return *this;
617
  }
618
619
  BitVector &operator>>=(unsigned N) {
620
    assert(N <= Size);
621
    if (LLVM_UNLIKELY(empty() || N == 0))
622
      return *this;
623
624
    unsigned NumWords = NumBitWords(Size);
625
    assert(NumWords >= 1);
626
627
    wordShr(N / BITWORD_SIZE);
628
629
    unsigned BitDistance = N % BITWORD_SIZE;
630
    if (BitDistance == 0)
631
      return *this;
632
633
    // When the shift size is not a multiple of the word size, then we have
634
    // a tricky situation where each word in succession needs to extract some
635
    // of the bits from the next word and or them into this word while
636
    // shifting this word to make room for the new bits.  This has to be done
637
    // for every word in the array.
638
639
    // Since we're shifting each word right, some bits will fall off the end
640
    // of each word to the right, and empty space will be created on the left.
641
    // The final word in the array will lose bits permanently, so starting at
642
    // the beginning, work forwards shifting each word to the right, and
643
    // OR'ing in the bits from the end of the next word to the beginning of
644
    // the current word.
645
646
    // Example:
647
    //   Starting with {0xAABBCCDD, 0xEEFF0011, 0x22334455} and shifting right
648
    //   by 4 bits.
649
    // Step 1: Word[0] >>= 4           ; 0x0ABBCCDD
650
    // Step 2: Word[0] |= 0x10000000   ; 0x1ABBCCDD
651
    // Step 3: Word[1] >>= 4           ; 0x0EEFF001
652
    // Step 4: Word[1] |= 0x50000000   ; 0x5EEFF001
653
    // Step 5: Word[2] >>= 4           ; 0x02334455
654
    // Result: { 0x1ABBCCDD, 0x5EEFF001, 0x02334455 }
655
    const BitWord Mask = maskTrailingOnes<BitWord>(BitDistance);
656
    const unsigned LSH = BITWORD_SIZE - BitDistance;
657
658
    for (unsigned I = 0; I < NumWords - 1; ++I) {
659
      Bits[I] >>= BitDistance;
660
      Bits[I] |= (Bits[I + 1] & Mask) << LSH;
661
    }
662
663
    Bits[NumWords - 1] >>= BitDistance;
664
665
    return *this;
666
  }
667
668
  BitVector &operator<<=(unsigned N) {
669
    assert(N <= Size);
670
    if (LLVM_UNLIKELY(empty() || N == 0))
671
      return *this;
672
673
    unsigned NumWords = NumBitWords(Size);
674
    assert(NumWords >= 1);
675
676
    wordShl(N / BITWORD_SIZE);
677
678
    unsigned BitDistance = N % BITWORD_SIZE;
679
    if (BitDistance == 0)
680
      return *this;
681
682
    // When the shift size is not a multiple of the word size, then we have
683
    // a tricky situation where each word in succession needs to extract some
684
    // of the bits from the previous word and or them into this word while
685
    // shifting this word to make room for the new bits.  This has to be done
686
    // for every word in the array.  This is similar to the algorithm outlined
687
    // in operator>>=, but backwards.
688
689
    // Since we're shifting each word left, some bits will fall off the end
690
    // of each word to the left, and empty space will be created on the right.
691
    // The first word in the array will lose bits permanently, so starting at
692
    // the end, work backwards shifting each word to the left, and OR'ing
693
    // in the bits from the end of the next word to the beginning of the
694
    // current word.
695
696
    // Example:
697
    //   Starting with {0xAABBCCDD, 0xEEFF0011, 0x22334455} and shifting left
698
    //   by 4 bits.
699
    // Step 1: Word[2] <<= 4           ; 0x23344550
700
    // Step 2: Word[2] |= 0x0000000E   ; 0x2334455E
701
    // Step 3: Word[1] <<= 4           ; 0xEFF00110
702
    // Step 4: Word[1] |= 0x0000000A   ; 0xEFF0011A
703
    // Step 5: Word[0] <<= 4           ; 0xABBCCDD0
704
    // Result: { 0xABBCCDD0, 0xEFF0011A, 0x2334455E }
705
    const BitWord Mask = maskLeadingOnes<BitWord>(BitDistance);
706
    const unsigned RSH = BITWORD_SIZE - BitDistance;
707
708
    for (int I = NumWords - 1; I > 0; --I) {
709
      Bits[I] <<= BitDistance;
710
      Bits[I] |= (Bits[I - 1] & Mask) >> RSH;
711
    }
712
    Bits[0] <<= BitDistance;
713
    clear_unused_bits();
714
715
    return *this;
716
  }
717
718
  // Assignment operator.
719
7.51M
  const BitVector &operator=(const BitVector &RHS) {
720
7.51M
    if (this == &RHS) 
return *this0
;
721
7.51M
722
7.51M
    Size = RHS.size();
723
7.51M
    unsigned RHSWords = NumBitWords(Size);
724
7.51M
    if (Size <= getBitCapacity()) {
725
5.56M
      if (Size)
726
5.56M
        std::memcpy(Bits.data(), RHS.Bits.data(), RHSWords * sizeof(BitWord));
727
5.56M
      clear_unused_bits();
728
5.56M
      return *this;
729
5.56M
    }
730
1.94M
731
1.94M
    // Grow the bitvector to have enough elements.
732
1.94M
    unsigned NewCapacity = RHSWords;
733
1.94M
    assert(NewCapacity > 0 && "negative capacity?");
734
1.94M
    auto NewBits = allocate(NewCapacity);
735
1.94M
    std::memcpy(NewBits.data(), RHS.Bits.data(), NewCapacity * sizeof(BitWord));
736
1.94M
737
1.94M
    // Destroy the old bits.
738
1.94M
    std::free(Bits.data());
739
1.94M
    Bits = NewBits;
740
1.94M
741
1.94M
    return *this;
742
1.94M
  }
743
744
10.7M
  const BitVector &operator=(BitVector &&RHS) {
745
10.7M
    if (this == &RHS) 
return *this0
;
746
10.7M
747
10.7M
    std::free(Bits.data());
748
10.7M
    Bits = RHS.Bits;
749
10.7M
    Size = RHS.Size;
750
10.7M
751
10.7M
    RHS.Bits = MutableArrayRef<BitWord>();
752
10.7M
    RHS.Size = 0;
753
10.7M
754
10.7M
    return *this;
755
10.7M
  }
756
757
  void swap(BitVector &RHS) {
758
    std::swap(Bits, RHS.Bits);
759
    std::swap(Size, RHS.Size);
760
  }
761
762
  //===--------------------------------------------------------------------===//
763
  // Portable bit mask operations.
764
  //===--------------------------------------------------------------------===//
765
  //
766
  // These methods all operate on arrays of uint32_t, each holding 32 bits. The
767
  // fixed word size makes it easier to work with literal bit vector constants
768
  // in portable code.
769
  //
770
  // The LSB in each word is the lowest numbered bit.  The size of a portable
771
  // bit mask is always a whole multiple of 32 bits.  If no bit mask size is
772
  // given, the bit mask is assumed to cover the entire BitVector.
773
774
  /// setBitsInMask - Add '1' bits from Mask to this vector. Don't resize.
775
  /// This computes "*this |= Mask".
776
3.10M
  void setBitsInMask(const uint32_t *Mask, unsigned MaskWords = ~0u) {
777
3.10M
    applyMask<true, false>(Mask, MaskWords);
778
3.10M
  }
779
780
  /// clearBitsInMask - Clear any bits in this vector that are set in Mask.
781
  /// Don't resize. This computes "*this &= ~Mask".
782
  void clearBitsInMask(const uint32_t *Mask, unsigned MaskWords = ~0u) {
783
    applyMask<false, false>(Mask, MaskWords);
784
  }
785
786
  /// setBitsNotInMask - Add a bit to this vector for every '0' bit in Mask.
787
  /// Don't resize.  This computes "*this |= ~Mask".
788
2.00M
  void setBitsNotInMask(const uint32_t *Mask, unsigned MaskWords = ~0u) {
789
2.00M
    applyMask<true, true>(Mask, MaskWords);
790
2.00M
  }
791
792
  /// clearBitsNotInMask - Clear a bit in this vector for every '0' bit in Mask.
793
  /// Don't resize.  This computes "*this &= Mask".
794
23.3M
  void clearBitsNotInMask(const uint32_t *Mask, unsigned MaskWords = ~0u) {
795
23.3M
    applyMask<false, true>(Mask, MaskWords);
796
23.3M
  }
797
798
private:
799
  /// Perform a logical left shift of \p Count words by moving everything
800
  /// \p Count words to the right in memory.
801
  ///
802
  /// While confusing, words are stored from least significant at Bits[0] to
803
  /// most significant at Bits[NumWords-1].  A logical shift left, however,
804
  /// moves the current least significant bit to a higher logical index, and
805
  /// fills the previous least significant bits with 0.  Thus, we actually
806
  /// need to move the bytes of the memory to the right, not to the left.
807
  /// Example:
808
  ///   Words = [0xBBBBAAAA, 0xDDDDFFFF, 0x00000000, 0xDDDD0000]
809
  /// represents a BitVector where 0xBBBBAAAA contain the least significant
810
  /// bits.  So if we want to shift the BitVector left by 2 words, we need to
811
  /// turn this into 0x00000000 0x00000000 0xBBBBAAAA 0xDDDDFFFF by using a
812
  /// memmove which moves right, not left.
813
  void wordShl(uint32_t Count) {
814
    if (Count == 0)
815
      return;
816
817
    uint32_t NumWords = NumBitWords(Size);
818
819
    auto Src = Bits.take_front(NumWords).drop_back(Count);
820
    auto Dest = Bits.take_front(NumWords).drop_front(Count);
821
822
    // Since we always move Word-sized chunks of data with src and dest both
823
    // aligned to a word-boundary, we don't need to worry about endianness
824
    // here.
825
    std::memmove(Dest.begin(), Src.begin(), Dest.size() * sizeof(BitWord));
826
    std::memset(Bits.data(), 0, Count * sizeof(BitWord));
827
    clear_unused_bits();
828
  }
829
830
  /// Perform a logical right shift of \p Count words by moving those
831
  /// words to the left in memory.  See wordShl for more information.
832
  ///
833
  void wordShr(uint32_t Count) {
834
    if (Count == 0)
835
      return;
836
837
    uint32_t NumWords = NumBitWords(Size);
838
839
    auto Src = Bits.take_front(NumWords).drop_front(Count);
840
    auto Dest = Bits.take_front(NumWords).drop_back(Count);
841
    assert(Dest.size() == Src.size());
842
843
    std::memmove(Dest.begin(), Src.begin(), Dest.size() * sizeof(BitWord));
844
    std::memset(Dest.end(), 0, Count * sizeof(BitWord));
845
  }
846
847
55.7M
  MutableArrayRef<BitWord> allocate(size_t NumWords) {
848
55.7M
    BitWord *RawBits = static_cast<BitWord *>(
849
55.7M
        safe_malloc(NumWords * sizeof(BitWord)));
850
55.7M
    return MutableArrayRef<BitWord>(RawBits, NumWords);
851
55.7M
  }
852
853
  int next_unset_in_word(int WordIndex, BitWord Word) const {
854
    unsigned Result = WordIndex * BITWORD_SIZE + countTrailingOnes(Word);
855
    return Result < size() ? Result : -1;
856
  }
857
858
386M
  unsigned NumBitWords(unsigned S) const {
859
386M
    return (S + BITWORD_SIZE-1) / BITWORD_SIZE;
860
386M
  }
861
862
  // Set the unused bits in the high words.
863
108M
  void set_unused_bits(bool t = true) {
864
108M
    //  Set high words first.
865
108M
    unsigned UsedWords = NumBitWords(Size);
866
108M
    if (Bits.size() > UsedWords)
867
84.4M
      init_words(Bits.drop_front(UsedWords), t);
868
108M
869
108M
    //  Then set any stray high bits of the last used word.
870
108M
    unsigned ExtraBits = Size % BITWORD_SIZE;
871
108M
    if (ExtraBits) {
872
39.1M
      BitWord ExtraBitMask = ~0UL << ExtraBits;
873
39.1M
      if (t)
874
1.46k
        Bits[UsedWords-1] |= ExtraBitMask;
875
39.1M
      else
876
39.1M
        Bits[UsedWords-1] &= ~ExtraBitMask;
877
39.1M
    }
878
108M
  }
879
880
  // Clear the unused bits in the high words.
881
52.9M
  void clear_unused_bits() {
882
52.9M
    set_unused_bits(false);
883
52.9M
  }
884
885
14.6M
  void grow(unsigned NewSize) {
886
14.6M
    size_t NewCapacity = std::max<size_t>(NumBitWords(NewSize), Bits.size() * 2);
887
14.6M
    assert(NewCapacity > 0 && "realloc-ing zero space");
888
14.6M
    BitWord *NewBits = static_cast<BitWord *>(
889
14.6M
        safe_realloc(Bits.data(), NewCapacity * sizeof(BitWord)));
890
14.6M
    Bits = MutableArrayRef<BitWord>(NewBits, NewCapacity);
891
14.6M
    clear_unused_bits();
892
14.6M
  }
893
894
164M
  void init_words(MutableArrayRef<BitWord> B, bool t) {
895
164M
    if (B.size() > 0)
896
164M
      memset(B.data(), 0 - (int)t, B.size() * sizeof(BitWord));
897
164M
  }
898
899
  template<bool AddBits, bool InvertMask>
900
28.4M
  void applyMask(const uint32_t *Mask, unsigned MaskWords) {
901
28.4M
    static_assert(BITWORD_SIZE % 32 == 0, "Unsupported BitWord size.");
902
28.4M
    MaskWords = std::min(MaskWords, (size() + 31) / 32);
903
28.4M
    const unsigned Scale = BITWORD_SIZE / 32;
904
28.4M
    unsigned i;
905
268M
    for (i = 0; MaskWords >= Scale; 
++i, MaskWords -= Scale240M
) {
906
240M
      BitWord BW = Bits[i];
907
240M
      // This inner loop should unroll completely when BITWORD_SIZE > 32.
908
720M
      for (unsigned b = 0; b != BITWORD_SIZE; 
b += 32480M
) {
909
480M
        uint32_t M = *Mask++;
910
480M
        if (InvertMask) 
M = ~M469M
;
911
480M
        if (AddBits) 
BW |= BitWord(M) << b45.8M
;
912
434M
        else         BW &= ~(BitWord(M) << b);
913
480M
      }
914
240M
      Bits[i] = BW;
915
240M
    }
916
52.9M
    for (unsigned b = 0; MaskWords; 
b += 32, --MaskWords24.5M
) {
917
24.5M
      uint32_t M = *Mask++;
918
24.5M
      if (InvertMask) 
M = ~M24.3M
;
919
24.5M
      if (AddBits) 
Bits[i] |= BitWord(M) << b2.03M
;
920
22.4M
      else         Bits[i] &= ~(BitWord(M) << b);
921
24.5M
    }
922
28.4M
    if (AddBits)
923
5.10M
      clear_unused_bits();
924
28.4M
  }
void llvm::BitVector::applyMask<false, true>(unsigned int const*, unsigned int)
Line
Count
Source
900
23.3M
  void applyMask(const uint32_t *Mask, unsigned MaskWords) {
901
23.3M
    static_assert(BITWORD_SIZE % 32 == 0, "Unsupported BitWord size.");
902
23.3M
    MaskWords = std::min(MaskWords, (size() + 31) / 32);
903
23.3M
    const unsigned Scale = BITWORD_SIZE / 32;
904
23.3M
    unsigned i;
905
240M
    for (i = 0; MaskWords >= Scale; 
++i, MaskWords -= Scale217M
) {
906
217M
      BitWord BW = Bits[i];
907
217M
      // This inner loop should unroll completely when BITWORD_SIZE > 32.
908
652M
      for (unsigned b = 0; b != BITWORD_SIZE; 
b += 32434M
) {
909
434M
        uint32_t M = *Mask++;
910
434M
        if (
InvertMask434M
) M = ~M;
911
434M
        if (AddBits) 
BW |= BitWord(M) << b0
;
912
434M
        else         BW &= ~(BitWord(M) << b);
913
434M
      }
914
217M
      Bits[i] = BW;
915
217M
    }
916
45.8M
    for (unsigned b = 0; MaskWords; 
b += 32, --MaskWords22.4M
) {
917
22.4M
      uint32_t M = *Mask++;
918
22.4M
      if (InvertMask) 
M = ~M22.4M
;
919
22.4M
      if (AddBits) 
Bits[i] |= BitWord(M) << b0
;
920
22.4M
      else         Bits[i] &= ~(BitWord(M) << b);
921
22.4M
    }
922
23.3M
    if (AddBits)
923
0
      clear_unused_bits();
924
23.3M
  }
void llvm::BitVector::applyMask<true, false>(unsigned int const*, unsigned int)
Line
Count
Source
900
3.10M
  void applyMask(const uint32_t *Mask, unsigned MaskWords) {
901
3.10M
    static_assert(BITWORD_SIZE % 32 == 0, "Unsupported BitWord size.");
902
3.10M
    MaskWords = std::min(MaskWords, (size() + 31) / 32);
903
3.10M
    const unsigned Scale = BITWORD_SIZE / 32;
904
3.10M
    unsigned i;
905
8.41M
    for (i = 0; MaskWords >= Scale; 
++i, MaskWords -= Scale5.30M
) {
906
5.30M
      BitWord BW = Bits[i];
907
5.30M
      // This inner loop should unroll completely when BITWORD_SIZE > 32.
908
15.9M
      for (unsigned b = 0; b != BITWORD_SIZE; 
b += 3210.6M
) {
909
10.6M
        uint32_t M = *Mask++;
910
10.6M
        if (InvertMask) 
M = ~M0
;
911
10.6M
        if (
AddBits10.6M
) BW |= BitWord(M) << b;
912
18.4E
        else         BW &= ~(BitWord(M) << b);
913
10.6M
      }
914
5.30M
      Bits[i] = BW;
915
5.30M
    }
916
3.24M
    for (unsigned b = 0; MaskWords; 
b += 32, --MaskWords144k
) {
917
144k
      uint32_t M = *Mask++;
918
144k
      if (InvertMask) 
M = ~M0
;
919
144k
      if (AddBits) Bits[i] |=   BitWord(M) << b;
920
0
      else         Bits[i] &= ~(BitWord(M) << b);
921
144k
    }
922
3.10M
    if (AddBits)
923
3.10M
      clear_unused_bits();
924
3.10M
  }
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
900
2.00M
  void applyMask(const uint32_t *Mask, unsigned MaskWords) {
901
2.00M
    static_assert(BITWORD_SIZE % 32 == 0, "Unsupported BitWord size.");
902
2.00M
    MaskWords = std::min(MaskWords, (size() + 31) / 32);
903
2.00M
    const unsigned Scale = BITWORD_SIZE / 32;
904
2.00M
    unsigned i;
905
19.5M
    for (i = 0; MaskWords >= Scale; 
++i, MaskWords -= Scale17.5M
) {
906
17.5M
      BitWord BW = Bits[i];
907
17.5M
      // This inner loop should unroll completely when BITWORD_SIZE > 32.
908
52.7M
      for (unsigned b = 0; b != BITWORD_SIZE; 
b += 3235.1M
) {
909
35.1M
        uint32_t M = *Mask++;
910
35.1M
        if (InvertMask) M = ~M;
911
35.1M
        if (AddBits) BW |=   BitWord(M) << b;
912
0
        else         BW &= ~(BitWord(M) << b);
913
35.1M
      }
914
17.5M
      Bits[i] = BW;
915
17.5M
    }
916
3.89M
    for (unsigned b = 0; MaskWords; 
b += 32, --MaskWords1.88M
) {
917
1.88M
      uint32_t M = *Mask++;
918
1.88M
      if (InvertMask) M = ~M;
919
1.88M
      if (AddBits) Bits[i] |=   BitWord(M) << b;
920
0
      else         Bits[i] &= ~(BitWord(M) << b);
921
1.88M
    }
922
2.00M
    if (AddBits)
923
2.00M
      clear_unused_bits();
924
2.00M
  }
925
926
public:
927
  /// Return the size (in bytes) of the bit vector.
928
1
  size_t getMemorySize() const { return Bits.size() * sizeof(BitWord); }
929
367M
  size_t getBitCapacity() const { return Bits.size() * BITWORD_SIZE; }
930
};
931
932
1
inline size_t capacity_in_bytes(const BitVector &X) {
933
1
  return X.getMemorySize();
934
1
}
935
936
} // end namespace llvm
937
938
namespace std {
939
  /// Implement std::swap in terms of BitVector swap.
940
  inline void
941
  swap(llvm::BitVector &LHS, llvm::BitVector &RHS) {
942
    LHS.swap(RHS);
943
  }
944
} // end namespace std
945
946
#endif // LLVM_ADT_BITVECTOR_H