Coverage Report

Created: 2018-09-17 19:50

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/ADT/SparseMultiSet.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/ADT/SparseMultiSet.h - Sparse multiset --------------*- 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 defines the SparseMultiSet class, which adds multiset behavior to
11
// the SparseSet.
12
//
13
// A sparse multiset holds a small number of objects identified by integer keys
14
// from a moderately sized universe. The sparse multiset uses more memory than
15
// other containers in order to provide faster operations. Any key can map to
16
// multiple values. A SparseMultiSetNode class is provided, which serves as a
17
// convenient base class for the contents of a SparseMultiSet.
18
//
19
//===----------------------------------------------------------------------===//
20
21
#ifndef LLVM_ADT_SPARSEMULTISET_H
22
#define LLVM_ADT_SPARSEMULTISET_H
23
24
#include "llvm/ADT/STLExtras.h"
25
#include "llvm/ADT/SmallVector.h"
26
#include "llvm/ADT/SparseSet.h"
27
#include <cassert>
28
#include <cstdint>
29
#include <cstdlib>
30
#include <iterator>
31
#include <limits>
32
#include <utility>
33
34
namespace llvm {
35
36
/// Fast multiset implementation for objects that can be identified by small
37
/// unsigned keys.
38
///
39
/// SparseMultiSet allocates memory proportional to the size of the key
40
/// universe, so it is not recommended for building composite data structures.
41
/// It is useful for algorithms that require a single set with fast operations.
42
///
43
/// Compared to DenseSet and DenseMap, SparseMultiSet provides constant-time
44
/// fast clear() as fast as a vector.  The find(), insert(), and erase()
45
/// operations are all constant time, and typically faster than a hash table.
46
/// The iteration order doesn't depend on numerical key values, it only depends
47
/// on the order of insert() and erase() operations.  Iteration order is the
48
/// insertion order. Iteration is only provided over elements of equivalent
49
/// keys, but iterators are bidirectional.
50
///
51
/// Compared to BitVector, SparseMultiSet<unsigned> uses 8x-40x more memory, but
52
/// offers constant-time clear() and size() operations as well as fast iteration
53
/// independent on the size of the universe.
54
///
55
/// SparseMultiSet contains a dense vector holding all the objects and a sparse
56
/// array holding indexes into the dense vector.  Most of the memory is used by
57
/// the sparse array which is the size of the key universe. The SparseT template
58
/// parameter provides a space/speed tradeoff for sets holding many elements.
59
///
60
/// When SparseT is uint32_t, find() only touches up to 3 cache lines, but the
61
/// sparse array uses 4 x Universe bytes.
62
///
63
/// When SparseT is uint8_t (the default), find() touches up to 3+[N/256] cache
64
/// lines, but the sparse array is 4x smaller.  N is the number of elements in
65
/// the set.
66
///
67
/// For sets that may grow to thousands of elements, SparseT should be set to
68
/// uint16_t or uint32_t.
69
///
70
/// Multiset behavior is provided by providing doubly linked lists for values
71
/// that are inlined in the dense vector. SparseMultiSet is a good choice when
72
/// one desires a growable number of entries per key, as it will retain the
73
/// SparseSet algorithmic properties despite being growable. Thus, it is often a
74
/// better choice than a SparseSet of growable containers or a vector of
75
/// vectors. SparseMultiSet also keeps iterators valid after erasure (provided
76
/// the iterators don't point to the element erased), allowing for more
77
/// intuitive and fast removal.
78
///
79
/// @tparam ValueT      The type of objects in the set.
80
/// @tparam KeyFunctorT A functor that computes an unsigned index from KeyT.
81
/// @tparam SparseT     An unsigned integer type. See above.
82
///
83
template<typename ValueT,
84
         typename KeyFunctorT = identity<unsigned>,
85
         typename SparseT = uint8_t>
86
class SparseMultiSet {
87
  static_assert(std::numeric_limits<SparseT>::is_integer &&
88
                !std::numeric_limits<SparseT>::is_signed,
89
                "SparseT must be an unsigned integer type");
90
91
  /// The actual data that's stored, as a doubly-linked list implemented via
92
  /// indices into the DenseVector.  The doubly linked list is implemented
93
  /// circular in Prev indices, and INVALID-terminated in Next indices. This
94
  /// provides efficient access to list tails. These nodes can also be
95
  /// tombstones, in which case they are actually nodes in a single-linked
96
  /// freelist of recyclable slots.
97
  struct SMSNode {
98
    static const unsigned INVALID = ~0U;
99
100
    ValueT Data;
101
    unsigned Prev;
102
    unsigned Next;
103
104
29.5M
    SMSNode(ValueT D, unsigned P, unsigned N) : Data(D), Prev(P), Next(N) {}
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::SMSNode::SMSNode(llvm::VReg2SUnit, unsigned int, unsigned int)
Line
Count
Source
104
4.56M
    SMSNode(ValueT D, unsigned P, unsigned N) : Data(D), Prev(P), Next(N) {}
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::SMSNode::SMSNode(llvm::PhysRegSUOper, unsigned int, unsigned int)
Line
Count
Source
104
13.4M
    SMSNode(ValueT D, unsigned P, unsigned N) : Data(D), Prev(P), Next(N) {}
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::SMSNode::SMSNode(llvm::VReg2SUnitOperIdx, unsigned int, unsigned int)
Line
Count
Source
104
11.5M
    SMSNode(ValueT D, unsigned P, unsigned N) : Data(D), Prev(P), Next(N) {}
105
106
    /// List tails have invalid Nexts.
107
38.8M
    bool isTail() const {
108
38.8M
      return Next == INVALID;
109
38.8M
    }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::SMSNode::isTail() const
Line
Count
Source
107
6.45M
    bool isTail() const {
108
6.45M
      return Next == INVALID;
109
6.45M
    }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::SMSNode::isTail() const
Line
Count
Source
107
24.4M
    bool isTail() const {
108
24.4M
      return Next == INVALID;
109
24.4M
    }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::SMSNode::isTail() const
Line
Count
Source
107
7.96M
    bool isTail() const {
108
7.96M
      return Next == INVALID;
109
7.96M
    }
110
111
    /// Whether this node is a tombstone node, and thus is in our freelist.
112
    bool isTombstone() const {
113
      return Prev == INVALID;
114
    }
115
116
    /// Since the list is circular in Prev, all non-tombstone nodes have a valid
117
    /// Prev.
118
38.8M
    bool isValid() const { return Prev != INVALID; }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::SMSNode::isValid() const
Line
Count
Source
118
6.45M
    bool isValid() const { return Prev != INVALID; }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::SMSNode::isValid() const
Line
Count
Source
118
25.2M
    bool isValid() const { return Prev != INVALID; }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::SMSNode::isValid() const
Line
Count
Source
118
7.18M
    bool isValid() const { return Prev != INVALID; }
119
  };
120
121
  using KeyT = typename KeyFunctorT::argument_type;
122
  using DenseT = SmallVector<SMSNode, 8>;
123
  DenseT Dense;
124
  SparseT *Sparse = nullptr;
125
  unsigned Universe = 0;
126
  KeyFunctorT KeyIndexOf;
127
  SparseSetValFunctor<KeyT, ValueT, KeyFunctorT> ValIndexOf;
128
129
  /// We have a built-in recycler for reusing tombstone slots. This recycler
130
  /// puts a singly-linked free list into tombstone slots, allowing us quick
131
  /// erasure, iterator preservation, and dense size.
132
  unsigned FreelistIdx = SMSNode::INVALID;
133
  unsigned NumFree = 0;
134
135
144M
  unsigned sparseIndex(const ValueT &Val) const {
136
144M
    assert(ValIndexOf(Val) < Universe &&
137
144M
           "Invalid key in set. Did object mutate?");
138
144M
    return ValIndexOf(Val);
139
144M
  }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::sparseIndex(llvm::VReg2SUnit const&) const
Line
Count
Source
135
19.1M
  unsigned sparseIndex(const ValueT &Val) const {
136
19.1M
    assert(ValIndexOf(Val) < Universe &&
137
19.1M
           "Invalid key in set. Did object mutate?");
138
19.1M
    return ValIndexOf(Val);
139
19.1M
  }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::sparseIndex(llvm::PhysRegSUOper const&) const
Line
Count
Source
135
99.1M
  unsigned sparseIndex(const ValueT &Val) const {
136
99.1M
    assert(ValIndexOf(Val) < Universe &&
137
99.1M
           "Invalid key in set. Did object mutate?");
138
99.1M
    return ValIndexOf(Val);
139
99.1M
  }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::sparseIndex(llvm::VReg2SUnitOperIdx const&) const
Line
Count
Source
135
26.2M
  unsigned sparseIndex(const ValueT &Val) const {
136
26.2M
    assert(ValIndexOf(Val) < Universe &&
137
26.2M
           "Invalid key in set. Did object mutate?");
138
26.2M
    return ValIndexOf(Val);
139
26.2M
  }
140
115M
  unsigned sparseIndex(const SMSNode &N) const { return sparseIndex(N.Data); }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::sparseIndex(llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::SMSNode const&) const
Line
Count
Source
140
14.6M
  unsigned sparseIndex(const SMSNode &N) const { return sparseIndex(N.Data); }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::sparseIndex(llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::SMSNode const&) const
Line
Count
Source
140
85.7M
  unsigned sparseIndex(const SMSNode &N) const { return sparseIndex(N.Data); }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::sparseIndex(llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::SMSNode const&) const
Line
Count
Source
140
14.7M
  unsigned sparseIndex(const SMSNode &N) const { return sparseIndex(N.Data); }
141
142
  /// Whether the given entry is the head of the list. List heads's previous
143
  /// pointers are to the tail of the list, allowing for efficient access to the
144
  /// list tail. D must be a valid entry node.
145
38.8M
  bool isHead(const SMSNode &D) const {
146
38.8M
    assert(D.isValid() && "Invalid node for head");
147
38.8M
    return Dense[D.Prev].isTail();
148
38.8M
  }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::isHead(llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::SMSNode const&) const
Line
Count
Source
145
6.45M
  bool isHead(const SMSNode &D) const {
146
6.45M
    assert(D.isValid() && "Invalid node for head");
147
6.45M
    return Dense[D.Prev].isTail();
148
6.45M
  }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::isHead(llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::SMSNode const&) const
Line
Count
Source
145
24.4M
  bool isHead(const SMSNode &D) const {
146
24.4M
    assert(D.isValid() && "Invalid node for head");
147
24.4M
    return Dense[D.Prev].isTail();
148
24.4M
  }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::isHead(llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::SMSNode const&) const
Line
Count
Source
145
7.95M
  bool isHead(const SMSNode &D) const {
146
7.95M
    assert(D.isValid() && "Invalid node for head");
147
7.95M
    return Dense[D.Prev].isTail();
148
7.95M
  }
149
150
  /// Whether the given entry is a singleton entry, i.e. the only entry with
151
  /// that key.
152
10.9M
  bool isSingleton(const SMSNode &N) const {
153
10.9M
    assert(N.isValid() && "Invalid node for singleton");
154
10.9M
    // Is N its own predecessor?
155
10.9M
    return &Dense[N.Prev] == &N;
156
10.9M
  }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::isSingleton(llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::SMSNode const&) const
Line
Count
Source
152
5.17M
  bool isSingleton(const SMSNode &N) const {
153
5.17M
    assert(N.isValid() && "Invalid node for singleton");
154
5.17M
    // Is N its own predecessor?
155
5.17M
    return &Dense[N.Prev] == &N;
156
5.17M
  }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::isSingleton(llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::SMSNode const&) const
Line
Count
Source
152
5.73M
  bool isSingleton(const SMSNode &N) const {
153
5.73M
    assert(N.isValid() && "Invalid node for singleton");
154
5.73M
    // Is N its own predecessor?
155
5.73M
    return &Dense[N.Prev] == &N;
156
5.73M
  }
157
158
  /// Add in the given SMSNode. Uses a free entry in our freelist if
159
  /// available. Returns the index of the added node.
160
29.5M
  unsigned addValue(const ValueT& V, unsigned Prev, unsigned Next) {
161
29.5M
    if (NumFree == 0) {
162
24.2M
      Dense.push_back(SMSNode(V, Prev, Next));
163
24.2M
      return Dense.size() - 1;
164
24.2M
    }
165
5.30M
166
5.30M
    // Peel off a free slot
167
5.30M
    unsigned Idx = FreelistIdx;
168
5.30M
    unsigned NextFree = Dense[Idx].Next;
169
5.30M
    assert(Dense[Idx].isTombstone() && "Non-tombstone free?");
170
5.30M
171
5.30M
    Dense[Idx] = SMSNode(V, Prev, Next);
172
5.30M
    FreelistIdx = NextFree;
173
5.30M
    --NumFree;
174
5.30M
    return Idx;
175
5.30M
  }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::addValue(llvm::VReg2SUnit const&, unsigned int, unsigned int)
Line
Count
Source
160
4.56M
  unsigned addValue(const ValueT& V, unsigned Prev, unsigned Next) {
161
4.56M
    if (NumFree == 0) {
162
4.56M
      Dense.push_back(SMSNode(V, Prev, Next));
163
4.56M
      return Dense.size() - 1;
164
4.56M
    }
165
0
166
0
    // Peel off a free slot
167
0
    unsigned Idx = FreelistIdx;
168
0
    unsigned NextFree = Dense[Idx].Next;
169
0
    assert(Dense[Idx].isTombstone() && "Non-tombstone free?");
170
0
171
0
    Dense[Idx] = SMSNode(V, Prev, Next);
172
0
    FreelistIdx = NextFree;
173
0
    --NumFree;
174
0
    return Idx;
175
0
  }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::addValue(llvm::PhysRegSUOper const&, unsigned int, unsigned int)
Line
Count
Source
160
13.4M
  unsigned addValue(const ValueT& V, unsigned Prev, unsigned Next) {
161
13.4M
    if (NumFree == 0) {
162
11.8M
      Dense.push_back(SMSNode(V, Prev, Next));
163
11.8M
      return Dense.size() - 1;
164
11.8M
    }
165
1.58M
166
1.58M
    // Peel off a free slot
167
1.58M
    unsigned Idx = FreelistIdx;
168
1.58M
    unsigned NextFree = Dense[Idx].Next;
169
1.58M
    assert(Dense[Idx].isTombstone() && "Non-tombstone free?");
170
1.58M
171
1.58M
    Dense[Idx] = SMSNode(V, Prev, Next);
172
1.58M
    FreelistIdx = NextFree;
173
1.58M
    --NumFree;
174
1.58M
    return Idx;
175
1.58M
  }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::addValue(llvm::VReg2SUnitOperIdx const&, unsigned int, unsigned int)
Line
Count
Source
160
11.5M
  unsigned addValue(const ValueT& V, unsigned Prev, unsigned Next) {
161
11.5M
    if (NumFree == 0) {
162
7.84M
      Dense.push_back(SMSNode(V, Prev, Next));
163
7.84M
      return Dense.size() - 1;
164
7.84M
    }
165
3.71M
166
3.71M
    // Peel off a free slot
167
3.71M
    unsigned Idx = FreelistIdx;
168
3.71M
    unsigned NextFree = Dense[Idx].Next;
169
3.71M
    assert(Dense[Idx].isTombstone() && "Non-tombstone free?");
170
3.71M
171
3.71M
    Dense[Idx] = SMSNode(V, Prev, Next);
172
3.71M
    FreelistIdx = NextFree;
173
3.71M
    --NumFree;
174
3.71M
    return Idx;
175
3.71M
  }
176
177
  /// Make the current index a new tombstone. Pushes it onto the freelist.
178
10.9M
  void makeTombstone(unsigned Idx) {
179
10.9M
    Dense[Idx].Prev = SMSNode::INVALID;
180
10.9M
    Dense[Idx].Next = FreelistIdx;
181
10.9M
    FreelistIdx = Idx;
182
10.9M
    ++NumFree;
183
10.9M
  }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::makeTombstone(unsigned int)
Line
Count
Source
178
5.17M
  void makeTombstone(unsigned Idx) {
179
5.17M
    Dense[Idx].Prev = SMSNode::INVALID;
180
5.17M
    Dense[Idx].Next = FreelistIdx;
181
5.17M
    FreelistIdx = Idx;
182
5.17M
    ++NumFree;
183
5.17M
  }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::makeTombstone(unsigned int)
Line
Count
Source
178
5.73M
  void makeTombstone(unsigned Idx) {
179
5.73M
    Dense[Idx].Prev = SMSNode::INVALID;
180
5.73M
    Dense[Idx].Next = FreelistIdx;
181
5.73M
    FreelistIdx = Idx;
182
5.73M
    ++NumFree;
183
5.73M
  }
184
185
public:
186
  using value_type = ValueT;
187
  using reference = ValueT &;
188
  using const_reference = const ValueT &;
189
  using pointer = ValueT *;
190
  using const_pointer = const ValueT *;
191
  using size_type = unsigned;
192
193
2.39M
  SparseMultiSet() = default;
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::SparseMultiSet()
Line
Count
Source
193
916k
  SparseMultiSet() = default;
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::SparseMultiSet()
Line
Count
Source
193
986k
  SparseMultiSet() = default;
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::SparseMultiSet()
Line
Count
Source
193
493k
  SparseMultiSet() = default;
194
  SparseMultiSet(const SparseMultiSet &) = delete;
195
  SparseMultiSet &operator=(const SparseMultiSet &) = delete;
196
2.39M
  ~SparseMultiSet() { free(Sparse); }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::~SparseMultiSet()
Line
Count
Source
196
493k
  ~SparseMultiSet() { free(Sparse); }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::~SparseMultiSet()
Line
Count
Source
196
916k
  ~SparseMultiSet() { free(Sparse); }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::~SparseMultiSet()
Line
Count
Source
196
986k
  ~SparseMultiSet() { free(Sparse); }
197
198
  /// Set the universe size which determines the largest key the set can hold.
199
  /// The universe must be sized before any elements can be added.
200
  ///
201
  /// @param U Universe size. All object keys must be less than U.
202
  ///
203
12.1M
  void setUniverse(unsigned U) {
204
12.1M
    // It's not hard to resize the universe on a non-empty set, but it doesn't
205
12.1M
    // seem like a likely use case, so we can add that code when we need it.
206
12.1M
    assert(empty() && "Can only resize universe on an empty map");
207
12.1M
    // Hysteresis prevents needless reallocations.
208
12.1M
    if (U >= Universe/4 && 
U <= Universe12.1M
)
209
10.3M
      return;
210
1.80M
    free(Sparse);
211
1.80M
    // The Sparse array doesn't actually need to be initialized, so malloc
212
1.80M
    // would be enough here, but that will cause tools like valgrind to
213
1.80M
    // complain about branching on uninitialized data.
214
1.80M
    Sparse = static_cast<SparseT*>(safe_calloc(U, sizeof(SparseT)));
215
1.80M
    Universe = U;
216
1.80M
  }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::setUniverse(unsigned int)
Line
Count
Source
203
3.15M
  void setUniverse(unsigned U) {
204
3.15M
    // It's not hard to resize the universe on a non-empty set, but it doesn't
205
3.15M
    // seem like a likely use case, so we can add that code when we need it.
206
3.15M
    assert(empty() && "Can only resize universe on an empty map");
207
3.15M
    // Hysteresis prevents needless reallocations.
208
3.15M
    if (U >= Universe/4 && U <= Universe)
209
2.66M
      return;
210
493k
    free(Sparse);
211
493k
    // The Sparse array doesn't actually need to be initialized, so malloc
212
493k
    // would be enough here, but that will cause tools like valgrind to
213
493k
    // complain about branching on uninitialized data.
214
493k
    Sparse = static_cast<SparseT*>(safe_calloc(U, sizeof(SparseT)));
215
493k
    Universe = U;
216
493k
  }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::setUniverse(unsigned int)
Line
Count
Source
203
6.02M
  void setUniverse(unsigned U) {
204
6.02M
    // It's not hard to resize the universe on a non-empty set, but it doesn't
205
6.02M
    // seem like a likely use case, so we can add that code when we need it.
206
6.02M
    assert(empty() && "Can only resize universe on an empty map");
207
6.02M
    // Hysteresis prevents needless reallocations.
208
6.02M
    if (U >= Universe/4 && 
U <= Universe6.02M
)
209
5.10M
      return;
210
915k
    free(Sparse);
211
915k
    // The Sparse array doesn't actually need to be initialized, so malloc
212
915k
    // would be enough here, but that will cause tools like valgrind to
213
915k
    // complain about branching on uninitialized data.
214
915k
    Sparse = static_cast<SparseT*>(safe_calloc(U, sizeof(SparseT)));
215
915k
    Universe = U;
216
915k
  }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::setUniverse(unsigned int)
Line
Count
Source
203
3.01M
  void setUniverse(unsigned U) {
204
3.01M
    // It's not hard to resize the universe on a non-empty set, but it doesn't
205
3.01M
    // seem like a likely use case, so we can add that code when we need it.
206
3.01M
    assert(empty() && "Can only resize universe on an empty map");
207
3.01M
    // Hysteresis prevents needless reallocations.
208
3.01M
    if (U >= Universe/4 && U <= Universe)
209
2.61M
      return;
210
395k
    free(Sparse);
211
395k
    // The Sparse array doesn't actually need to be initialized, so malloc
212
395k
    // would be enough here, but that will cause tools like valgrind to
213
395k
    // complain about branching on uninitialized data.
214
395k
    Sparse = static_cast<SparseT*>(safe_calloc(U, sizeof(SparseT)));
215
395k
    Universe = U;
216
395k
  }
217
218
  /// Our iterators are iterators over the collection of objects that share a
219
  /// key.
220
  template<typename SMSPtrTy>
221
  class iterator_base : public std::iterator<std::bidirectional_iterator_tag,
222
                                             ValueT> {
223
    friend class SparseMultiSet;
224
225
    SMSPtrTy SMS;
226
    unsigned Idx;
227
    unsigned SparseIdx;
228
229
    iterator_base(SMSPtrTy P, unsigned I, unsigned SI)
230
472M
      : SMS(P), Idx(I), SparseIdx(SI) {}
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>*>::iterator_base(llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>*, unsigned int, unsigned int)
Line
Count
Source
230
74.8M
      : SMS(P), Idx(I), SparseIdx(SI) {}
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>*>::iterator_base(llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>*, unsigned int, unsigned int)
Line
Count
Source
230
180M
      : SMS(P), Idx(I), SparseIdx(SI) {}
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short> const*>::iterator_base(llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short> const*, unsigned int, unsigned int)
Line
Count
Source
230
162M
      : SMS(P), Idx(I), SparseIdx(SI) {}
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>*>::iterator_base(llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>*, unsigned int, unsigned int)
Line
Count
Source
230
54.1M
      : SMS(P), Idx(I), SparseIdx(SI) {}
231
232
    /// Whether our iterator has fallen outside our dense vector.
233
1.16k
    bool isEnd() const {
234
1.16k
      if (Idx == SMSNode::INVALID)
235
1.16k
        return true;
236
0
237
0
      assert(Idx < SMS->Dense.size() && "Out of range, non-INVALID Idx?");
238
0
      return false;
239
0
    }
240
241
    /// Whether our iterator is properly keyed, i.e. the SparseIdx is valid
242
    bool isKeyed() const { return SparseIdx < SMS->Universe; }
243
244
4.51M
    unsigned Prev() const { return SMS->Dense[Idx].Prev; }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>*>::Prev() const
Line
Count
Source
244
1.71M
    unsigned Prev() const { return SMS->Dense[Idx].Prev; }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>*>::Prev() const
Line
Count
Source
244
663k
    unsigned Prev() const { return SMS->Dense[Idx].Prev; }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>*>::Prev() const
Line
Count
Source
244
2.13M
    unsigned Prev() const { return SMS->Dense[Idx].Prev; }
245
35.9M
    unsigned Next() const { return SMS->Dense[Idx].Next; }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>*>::Next() const
Line
Count
Source
245
26.9M
    unsigned Next() const { return SMS->Dense[Idx].Next; }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>*>::Next() const
Line
Count
Source
245
8.81M
    unsigned Next() const { return SMS->Dense[Idx].Next; }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>*>::Next() const
Line
Count
Source
245
155k
    unsigned Next() const { return SMS->Dense[Idx].Next; }
246
247
3.60k
    void setPrev(unsigned P) { SMS->Dense[Idx].Prev = P; }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>*>::setPrev(unsigned int)
Line
Count
Source
247
181
    void setPrev(unsigned P) { SMS->Dense[Idx].Prev = P; }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>*>::setPrev(unsigned int)
Line
Count
Source
247
3.42k
    void setPrev(unsigned P) { SMS->Dense[Idx].Prev = P; }
248
    void setNext(unsigned N) { SMS->Dense[Idx].Next = N; }
249
250
  public:
251
    using super = std::iterator<std::bidirectional_iterator_tag, ValueT>;
252
    using value_type = typename super::value_type;
253
    using difference_type = typename super::difference_type;
254
    using pointer = typename super::pointer;
255
    using reference = typename super::reference;
256
257
58.9M
    reference operator*() const {
258
58.9M
      assert(isKeyed() && SMS->sparseIndex(SMS->Dense[Idx].Data) == SparseIdx &&
259
58.9M
             "Dereferencing iterator of invalid key or index");
260
58.9M
261
58.9M
      return SMS->Dense[Idx].Data;
262
58.9M
    }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>*>::operator*() const
Line
Count
Source
257
26.9M
    reference operator*() const {
258
26.9M
      assert(isKeyed() && SMS->sparseIndex(SMS->Dense[Idx].Data) == SparseIdx &&
259
26.9M
             "Dereferencing iterator of invalid key or index");
260
26.9M
261
26.9M
      return SMS->Dense[Idx].Data;
262
26.9M
    }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>*>::operator*() const
Line
Count
Source
257
14.3M
    reference operator*() const {
258
14.3M
      assert(isKeyed() && SMS->sparseIndex(SMS->Dense[Idx].Data) == SparseIdx &&
259
14.3M
             "Dereferencing iterator of invalid key or index");
260
14.3M
261
14.3M
      return SMS->Dense[Idx].Data;
262
14.3M
    }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>*>::operator*() const
Line
Count
Source
257
17.6M
    reference operator*() const {
258
17.6M
      assert(isKeyed() && SMS->sparseIndex(SMS->Dense[Idx].Data) == SparseIdx &&
259
17.6M
             "Dereferencing iterator of invalid key or index");
260
17.6M
261
17.6M
      return SMS->Dense[Idx].Data;
262
17.6M
    }
263
52.8M
    pointer operator->() const { return &operator*(); }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>*>::operator->() const
Line
Count
Source
263
20.8M
    pointer operator->() const { return &operator*(); }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>*>::operator->() const
Line
Count
Source
263
14.3M
    pointer operator->() const { return &operator*(); }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>*>::operator->() const
Line
Count
Source
263
17.6M
    pointer operator->() const { return &operator*(); }
264
265
    /// Comparison operators
266
206M
    bool operator==(const iterator_base &RHS) const {
267
206M
      // end compares equal
268
206M
      if (SMS == RHS.SMS && Idx == RHS.Idx) {
269
143M
        assert((isEnd() || SparseIdx == RHS.SparseIdx) &&
270
143M
               "Same dense entry, but different keys?");
271
143M
        return true;
272
143M
      }
273
63.0M
274
63.0M
      return false;
275
63.0M
    }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>*>::operator==(llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>*> const&) const
Line
Count
Source
266
53.2M
    bool operator==(const iterator_base &RHS) const {
267
53.2M
      // end compares equal
268
53.2M
      if (SMS == RHS.SMS && Idx == RHS.Idx) {
269
24.4M
        assert((isEnd() || SparseIdx == RHS.SparseIdx) &&
270
24.4M
               "Same dense entry, but different keys?");
271
24.4M
        return true;
272
24.4M
      }
273
28.7M
274
28.7M
      return false;
275
28.7M
    }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short> const*>::operator==(llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short> const*> const&) const
Line
Count
Source
266
81.3M
    bool operator==(const iterator_base &RHS) const {
267
81.3M
      // end compares equal
268
81.3M
      if (
SMS == RHS.SMS81.3M
&& Idx == RHS.Idx) {
269
69.6M
        assert((isEnd() || SparseIdx == RHS.SparseIdx) &&
270
69.6M
               "Same dense entry, but different keys?");
271
69.6M
        return true;
272
69.6M
      }
273
11.6M
274
11.6M
      return false;
275
11.6M
    }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>*>::operator==(llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>*> const&) const
Line
Count
Source
266
47.4M
    bool operator==(const iterator_base &RHS) const {
267
47.4M
      // end compares equal
268
47.4M
      if (SMS == RHS.SMS && 
Idx == RHS.Idx47.4M
) {
269
32.7M
        assert((isEnd() || SparseIdx == RHS.SparseIdx) &&
270
32.7M
               "Same dense entry, but different keys?");
271
32.7M
        return true;
272
32.7M
      }
273
14.6M
274
14.6M
      return false;
275
14.6M
    }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>*>::operator==(llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>*> const&) const
Line
Count
Source
266
24.3M
    bool operator==(const iterator_base &RHS) const {
267
24.3M
      // end compares equal
268
24.3M
      if (SMS == RHS.SMS && Idx == RHS.Idx) {
269
16.2M
        assert((isEnd() || SparseIdx == RHS.SparseIdx) &&
270
16.2M
               "Same dense entry, but different keys?");
271
16.2M
        return true;
272
16.2M
      }
273
8.02M
274
8.02M
      return false;
275
8.02M
    }
276
277
173M
    bool operator!=(const iterator_base &RHS) const {
278
173M
      return !operator==(RHS);
279
173M
    }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>*>::operator!=(llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>*> const&) const
Line
Count
Source
277
45.5M
    bool operator!=(const iterator_base &RHS) const {
278
45.5M
      return !operator==(RHS);
279
45.5M
    }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short> const*>::operator!=(llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short> const*> const&) const
Line
Count
Source
277
81.3M
    bool operator!=(const iterator_base &RHS) const {
278
81.3M
      return !operator==(RHS);
279
81.3M
    }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>*>::operator!=(llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>*> const&) const
Line
Count
Source
277
34.0M
    bool operator!=(const iterator_base &RHS) const {
278
34.0M
      return !operator==(RHS);
279
34.0M
    }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>*>::operator!=(llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>*> const&) const
Line
Count
Source
277
12.7M
    bool operator!=(const iterator_base &RHS) const {
278
12.7M
      return !operator==(RHS);
279
12.7M
    }
280
281
    /// Increment and decrement operators
282
1.16k
    iterator_base &operator--() { // predecrement - Back up
283
1.16k
      assert(isKeyed() && "Decrementing an invalid iterator");
284
1.16k
      assert((isEnd() || !SMS->isHead(SMS->Dense[Idx])) &&
285
1.16k
             "Decrementing head of list");
286
1.16k
287
1.16k
      // If we're at the end, then issue a new find()
288
1.16k
      if (isEnd())
289
1.16k
        Idx = SMS->findIndex(SparseIdx).Prev();
290
0
      else
291
0
        Idx = Prev();
292
1.16k
293
1.16k
      return *this;
294
1.16k
    }
295
35.9M
    iterator_base &operator++() { // preincrement - Advance
296
35.9M
      assert(!isEnd() && isKeyed() && "Incrementing an invalid/end iterator");
297
35.9M
      Idx = Next();
298
35.9M
      return *this;
299
35.9M
    }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>*>::operator++()
Line
Count
Source
295
26.9M
    iterator_base &operator++() { // preincrement - Advance
296
26.9M
      assert(!isEnd() && isKeyed() && "Incrementing an invalid/end iterator");
297
26.9M
      Idx = Next();
298
26.9M
      return *this;
299
26.9M
    }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>*>::operator++()
Line
Count
Source
295
8.81M
    iterator_base &operator++() { // preincrement - Advance
296
8.81M
      assert(!isEnd() && isKeyed() && "Incrementing an invalid/end iterator");
297
8.81M
      Idx = Next();
298
8.81M
      return *this;
299
8.81M
    }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>*>::operator++()
Line
Count
Source
295
155k
    iterator_base &operator++() { // preincrement - Advance
296
155k
      assert(!isEnd() && isKeyed() && "Incrementing an invalid/end iterator");
297
155k
      Idx = Next();
298
155k
      return *this;
299
155k
    }
300
    iterator_base operator--(int) { // postdecrement
301
      iterator_base I(*this);
302
      --*this;
303
      return I;
304
    }
305
    iterator_base operator++(int) { // postincrement
306
      iterator_base I(*this);
307
      ++*this;
308
      return I;
309
    }
310
  };
311
312
  using iterator = iterator_base<SparseMultiSet *>;
313
  using const_iterator = iterator_base<const SparseMultiSet *>;
314
315
  // Convenience types
316
  using RangePair = std::pair<iterator, iterator>;
317
318
  /// Returns an iterator past this container. Note that such an iterator cannot
319
  /// be decremented, but will compare equal to other end iterators.
320
231M
  iterator end() { return iterator(this, SMSNode::INVALID, SMSNode::INVALID); }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::end()
Line
Count
Source
320
63.8M
  iterator end() { return iterator(this, SMSNode::INVALID, SMSNode::INVALID); }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::end()
Line
Count
Source
320
137M
  iterator end() { return iterator(this, SMSNode::INVALID, SMSNode::INVALID); }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::end()
Line
Count
Source
320
29.9M
  iterator end() { return iterator(this, SMSNode::INVALID, SMSNode::INVALID); }
321
81.3M
  const_iterator end() const {
322
81.3M
    return const_iterator(this, SMSNode::INVALID, SMSNode::INVALID);
323
81.3M
  }
324
325
  /// Returns true if the set is empty.
326
  ///
327
  /// This is not the same as BitVector::empty().
328
  ///
329
  bool empty() const { return size() == 0; }
330
331
  /// Returns the number of elements in the set.
332
  ///
333
  /// This is not the same as BitVector::size() which returns the size of the
334
  /// universe.
335
  ///
336
  size_type size() const {
337
    assert(NumFree <= Dense.size() && "Out-of-bounds free entries");
338
    return Dense.size() - NumFree;
339
  }
340
341
  /// Clears the set.  This is a very fast constant time operation.
342
  ///
343
12.1M
  void clear() {
344
12.1M
    // Sparse does not need to be cleared, see find().
345
12.1M
    Dense.clear();
346
12.1M
    NumFree = 0;
347
12.1M
    FreelistIdx = SMSNode::INVALID;
348
12.1M
  }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::clear()
Line
Count
Source
343
3.15M
  void clear() {
344
3.15M
    // Sparse does not need to be cleared, see find().
345
3.15M
    Dense.clear();
346
3.15M
    NumFree = 0;
347
3.15M
    FreelistIdx = SMSNode::INVALID;
348
3.15M
  }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::clear()
Line
Count
Source
343
6.02M
  void clear() {
344
6.02M
    // Sparse does not need to be cleared, see find().
345
6.02M
    Dense.clear();
346
6.02M
    NumFree = 0;
347
6.02M
    FreelistIdx = SMSNode::INVALID;
348
6.02M
  }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::clear()
Line
Count
Source
343
3.01M
  void clear() {
344
3.01M
    // Sparse does not need to be cleared, see find().
345
3.01M
    Dense.clear();
346
3.01M
    NumFree = 0;
347
3.01M
    FreelistIdx = SMSNode::INVALID;
348
3.01M
  }
349
350
  /// Find an element by its index.
351
  ///
352
  /// @param   Idx A valid index to find.
353
  /// @returns An iterator to the element identified by key, or end().
354
  ///
355
156M
  iterator findIndex(unsigned Idx) {
356
156M
    assert(Idx < Universe && "Key out of range");
357
156M
    const unsigned Stride = std::numeric_limits<SparseT>::max() + 1u;
358
232M
    for (unsigned i = Sparse[Idx], e = Dense.size(); i < e; 
i += Stride76.2M
) {
359
113M
      const unsigned FoundIdx = sparseIndex(Dense[i]);
360
113M
      // Check that we're pointing at the correct entry and that it is the head
361
113M
      // of a valid list.
362
113M
      if (Idx == FoundIdx && 
Dense[i].isValid()38.8M
&&
isHead(Dense[i])37.5M
)
363
37.5M
        return iterator(this, i, Idx);
364
76.2M
      // Stride is 0 when SparseT >= unsigned.  We don't need to loop.
365
76.2M
      if (!Stride)
366
0
        break;
367
76.2M
    }
368
156M
    
return end()118M
;
369
156M
  }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::findIndex(unsigned int)
Line
Count
Source
355
23.1M
  iterator findIndex(unsigned Idx) {
356
23.1M
    assert(Idx < Universe && "Key out of range");
357
23.1M
    const unsigned Stride = std::numeric_limits<SparseT>::max() + 1u;
358
31.2M
    for (unsigned i = Sparse[Idx], e = Dense.size(); i < e; 
i += Stride8.15M
) {
359
14.6M
      const unsigned FoundIdx = sparseIndex(Dense[i]);
360
14.6M
      // Check that we're pointing at the correct entry and that it is the head
361
14.6M
      // of a valid list.
362
14.6M
      if (Idx == FoundIdx && 
Dense[i].isValid()6.45M
&&
isHead(Dense[i])6.45M
)
363
6.45M
        return iterator(this, i, Idx);
364
8.15M
      // Stride is 0 when SparseT >= unsigned.  We don't need to loop.
365
8.15M
      if (!Stride)
366
0
        break;
367
8.15M
    }
368
23.1M
    
return end()16.6M
;
369
23.1M
  }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::findIndex(unsigned int)
Line
Count
Source
355
114M
  iterator findIndex(unsigned Idx) {
356
114M
    assert(Idx < Universe && "Key out of range");
357
114M
    const unsigned Stride = std::numeric_limits<SparseT>::max() + 1u;
358
176M
    for (unsigned i = Sparse[Idx], e = Dense.size(); i < e; 
i += Stride61.3M
) {
359
85.5M
      const unsigned FoundIdx = sparseIndex(Dense[i]);
360
85.5M
      // Check that we're pointing at the correct entry and that it is the head
361
85.5M
      // of a valid list.
362
85.5M
      if (Idx == FoundIdx && 
Dense[i].isValid()25.2M
&&
isHead(Dense[i])24.2M
)
363
24.2M
        return iterator(this, i, Idx);
364
61.3M
      // Stride is 0 when SparseT >= unsigned.  We don't need to loop.
365
61.3M
      if (!Stride)
366
0
        break;
367
61.3M
    }
368
114M
    
return end()90.5M
;
369
114M
  }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::findIndex(unsigned int)
Line
Count
Source
355
18.4M
  iterator findIndex(unsigned Idx) {
356
18.4M
    assert(Idx < Universe && "Key out of range");
357
18.4M
    const unsigned Stride = std::numeric_limits<SparseT>::max() + 1u;
358
25.1M
    for (unsigned i = Sparse[Idx], e = Dense.size(); i < e; 
i += Stride6.75M
) {
359
13.6M
      const unsigned FoundIdx = sparseIndex(Dense[i]);
360
13.6M
      // Check that we're pointing at the correct entry and that it is the head
361
13.6M
      // of a valid list.
362
13.6M
      if (Idx == FoundIdx && 
Dense[i].isValid()7.18M
&&
isHead(Dense[i])6.85M
)
363
6.85M
        return iterator(this, i, Idx);
364
6.75M
      // Stride is 0 when SparseT >= unsigned.  We don't need to loop.
365
6.75M
      if (!Stride)
366
0
        break;
367
6.75M
    }
368
18.4M
    
return end()11.5M
;
369
18.4M
  }
370
371
  /// Find an element by its key.
372
  ///
373
  /// @param   Key A valid key to find.
374
  /// @returns An iterator to the element identified by key, or end().
375
  ///
376
45.4M
  iterator find(const KeyT &Key) {
377
45.4M
    return findIndex(KeyIndexOf(Key));
378
45.4M
  }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::find(unsigned int const&)
Line
Count
Source
376
18.5M
  iterator find(const KeyT &Key) {
377
18.5M
    return findIndex(KeyIndexOf(Key));
378
18.5M
  }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::find(unsigned int const&)
Line
Count
Source
376
20.0M
  iterator find(const KeyT &Key) {
377
20.0M
    return findIndex(KeyIndexOf(Key));
378
20.0M
  }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::find(unsigned int const&)
Line
Count
Source
376
6.86M
  iterator find(const KeyT &Key) {
377
6.86M
    return findIndex(KeyIndexOf(Key));
378
6.86M
  }
379
380
81.3M
  const_iterator find(const KeyT &Key) const {
381
81.3M
    iterator I = const_cast<SparseMultiSet*>(this)->findIndex(KeyIndexOf(Key));
382
81.3M
    return const_iterator(I.SMS, I.Idx, KeyIndexOf(Key));
383
81.3M
  }
384
385
  /// Returns the number of elements identified by Key. This will be linear in
386
  /// the number of elements of that key.
387
  size_type count(const KeyT &Key) const {
388
    unsigned Ret = 0;
389
    for (const_iterator It = find(Key); It != end(); ++It)
390
      ++Ret;
391
392
    return Ret;
393
  }
394
395
  /// Returns true if this set contains an element identified by Key.
396
81.3M
  bool contains(const KeyT &Key) const {
397
81.3M
    return find(Key) != end();
398
81.3M
  }
399
400
  /// Return the head and tail of the subset's list, otherwise returns end().
401
  iterator getHead(const KeyT &Key) { return find(Key); }
402
  iterator getTail(const KeyT &Key) {
403
    iterator I = find(Key);
404
    if (I != end())
405
      I = iterator(this, I.Prev(), KeyIndexOf(Key));
406
    return I;
407
  }
408
409
  /// The bounds of the range of items sharing Key K. First member is the head
410
  /// of the list, and the second member is a decrementable end iterator for
411
  /// that key.
412
1.44k
  RangePair equal_range(const KeyT &K) {
413
1.44k
    iterator B = find(K);
414
1.44k
    iterator E = iterator(this, SMSNode::INVALID, B.SparseIdx);
415
1.44k
    return make_pair(B, E);
416
1.44k
  }
417
418
  /// Insert a new element at the tail of the subset list. Returns an iterator
419
  /// to the newly added entry.
420
29.5M
  iterator insert(const ValueT &Val) {
421
29.5M
    unsigned Idx = sparseIndex(Val);
422
29.5M
    iterator I = findIndex(Idx);
423
29.5M
424
29.5M
    unsigned NodeIdx = addValue(Val, SMSNode::INVALID, SMSNode::INVALID);
425
29.5M
426
29.5M
    if (I == end()) {
427
25.0M
      // Make a singleton list
428
25.0M
      Sparse[Idx] = NodeIdx;
429
25.0M
      Dense[NodeIdx].Prev = NodeIdx;
430
25.0M
      return iterator(this, NodeIdx, Idx);
431
25.0M
    }
432
4.51M
433
4.51M
    // Stick it at the end.
434
4.51M
    unsigned HeadIdx = I.Idx;
435
4.51M
    unsigned TailIdx = I.Prev();
436
4.51M
    Dense[TailIdx].Next = NodeIdx;
437
4.51M
    Dense[HeadIdx].Prev = NodeIdx;
438
4.51M
    Dense[NodeIdx].Prev = TailIdx;
439
4.51M
440
4.51M
    return iterator(this, NodeIdx, Idx);
441
4.51M
  }
llvm::SparseMultiSet<llvm::VReg2SUnit, llvm::VirtReg2IndexFunctor, unsigned char>::insert(llvm::VReg2SUnit const&)
Line
Count
Source
420
4.56M
  iterator insert(const ValueT &Val) {
421
4.56M
    unsigned Idx = sparseIndex(Val);
422
4.56M
    iterator I = findIndex(Idx);
423
4.56M
424
4.56M
    unsigned NodeIdx = addValue(Val, SMSNode::INVALID, SMSNode::INVALID);
425
4.56M
426
4.56M
    if (I == end()) {
427
2.84M
      // Make a singleton list
428
2.84M
      Sparse[Idx] = NodeIdx;
429
2.84M
      Dense[NodeIdx].Prev = NodeIdx;
430
2.84M
      return iterator(this, NodeIdx, Idx);
431
2.84M
    }
432
1.71M
433
1.71M
    // Stick it at the end.
434
1.71M
    unsigned HeadIdx = I.Idx;
435
1.71M
    unsigned TailIdx = I.Prev();
436
1.71M
    Dense[TailIdx].Next = NodeIdx;
437
1.71M
    Dense[HeadIdx].Prev = NodeIdx;
438
1.71M
    Dense[NodeIdx].Prev = TailIdx;
439
1.71M
440
1.71M
    return iterator(this, NodeIdx, Idx);
441
1.71M
  }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::insert(llvm::PhysRegSUOper const&)
Line
Count
Source
420
13.4M
  iterator insert(const ValueT &Val) {
421
13.4M
    unsigned Idx = sparseIndex(Val);
422
13.4M
    iterator I = findIndex(Idx);
423
13.4M
424
13.4M
    unsigned NodeIdx = addValue(Val, SMSNode::INVALID, SMSNode::INVALID);
425
13.4M
426
13.4M
    if (I == end()) {
427
12.7M
      // Make a singleton list
428
12.7M
      Sparse[Idx] = NodeIdx;
429
12.7M
      Dense[NodeIdx].Prev = NodeIdx;
430
12.7M
      return iterator(this, NodeIdx, Idx);
431
12.7M
    }
432
662k
433
662k
    // Stick it at the end.
434
662k
    unsigned HeadIdx = I.Idx;
435
662k
    unsigned TailIdx = I.Prev();
436
662k
    Dense[TailIdx].Next = NodeIdx;
437
662k
    Dense[HeadIdx].Prev = NodeIdx;
438
662k
    Dense[NodeIdx].Prev = TailIdx;
439
662k
440
662k
    return iterator(this, NodeIdx, Idx);
441
662k
  }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::insert(llvm::VReg2SUnitOperIdx const&)
Line
Count
Source
420
11.5M
  iterator insert(const ValueT &Val) {
421
11.5M
    unsigned Idx = sparseIndex(Val);
422
11.5M
    iterator I = findIndex(Idx);
423
11.5M
424
11.5M
    unsigned NodeIdx = addValue(Val, SMSNode::INVALID, SMSNode::INVALID);
425
11.5M
426
11.5M
    if (I == end()) {
427
9.42M
      // Make a singleton list
428
9.42M
      Sparse[Idx] = NodeIdx;
429
9.42M
      Dense[NodeIdx].Prev = NodeIdx;
430
9.42M
      return iterator(this, NodeIdx, Idx);
431
9.42M
    }
432
2.13M
433
2.13M
    // Stick it at the end.
434
2.13M
    unsigned HeadIdx = I.Idx;
435
2.13M
    unsigned TailIdx = I.Prev();
436
2.13M
    Dense[TailIdx].Next = NodeIdx;
437
2.13M
    Dense[HeadIdx].Prev = NodeIdx;
438
2.13M
    Dense[NodeIdx].Prev = TailIdx;
439
2.13M
440
2.13M
    return iterator(this, NodeIdx, Idx);
441
2.13M
  }
442
443
  /// Erases an existing element identified by a valid iterator.
444
  ///
445
  /// This invalidates iterators pointing at the same entry, but erase() returns
446
  /// an iterator pointing to the next element in the subset's list. This makes
447
  /// it possible to erase selected elements while iterating over the subset:
448
  ///
449
  ///   tie(I, E) = Set.equal_range(Key);
450
  ///   while (I != E)
451
  ///     if (test(*I))
452
  ///       I = Set.erase(I);
453
  ///     else
454
  ///       ++I;
455
  ///
456
  /// Note that if the last element in the subset list is erased, this will
457
  /// return an end iterator which can be decremented to get the new tail (if it
458
  /// exists):
459
  ///
460
  ///  tie(B, I) = Set.equal_range(Key);
461
  ///  for (bool isBegin = B == I; !isBegin; /* empty */) {
462
  ///    isBegin = (--I) == B;
463
  ///    if (test(I))
464
  ///      break;
465
  ///    I = erase(I);
466
  ///  }
467
10.9M
  iterator erase(iterator I) {
468
10.9M
    assert(I.isKeyed() && !I.isEnd() && !Dense[I.Idx].isTombstone() &&
469
10.9M
           "erasing invalid/end/tombstone iterator");
470
10.9M
471
10.9M
    // First, unlink the node from its list. Then swap the node out with the
472
10.9M
    // dense vector's last entry
473
10.9M
    iterator NextI = unlink(Dense[I.Idx]);
474
10.9M
475
10.9M
    // Put in a tombstone.
476
10.9M
    makeTombstone(I.Idx);
477
10.9M
478
10.9M
    return NextI;
479
10.9M
  }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::erase(llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::iterator_base<llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>*>)
Line
Count
Source
467
5.17M
  iterator erase(iterator I) {
468
5.17M
    assert(I.isKeyed() && !I.isEnd() && !Dense[I.Idx].isTombstone() &&
469
5.17M
           "erasing invalid/end/tombstone iterator");
470
5.17M
471
5.17M
    // First, unlink the node from its list. Then swap the node out with the
472
5.17M
    // dense vector's last entry
473
5.17M
    iterator NextI = unlink(Dense[I.Idx]);
474
5.17M
475
5.17M
    // Put in a tombstone.
476
5.17M
    makeTombstone(I.Idx);
477
5.17M
478
5.17M
    return NextI;
479
5.17M
  }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::erase(llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::iterator_base<llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>*>)
Line
Count
Source
467
5.73M
  iterator erase(iterator I) {
468
5.73M
    assert(I.isKeyed() && !I.isEnd() && !Dense[I.Idx].isTombstone() &&
469
5.73M
           "erasing invalid/end/tombstone iterator");
470
5.73M
471
5.73M
    // First, unlink the node from its list. Then swap the node out with the
472
5.73M
    // dense vector's last entry
473
5.73M
    iterator NextI = unlink(Dense[I.Idx]);
474
5.73M
475
5.73M
    // Put in a tombstone.
476
5.73M
    makeTombstone(I.Idx);
477
5.73M
478
5.73M
    return NextI;
479
5.73M
  }
480
481
  /// Erase all elements with the given key. This invalidates all
482
  /// iterators of that key.
483
13.1M
  void eraseAll(const KeyT &K) {
484
18.2M
    for (iterator I = find(K); I != end(); /* empty */)
485
5.17M
      I = erase(I);
486
13.1M
  }
487
488
private:
489
  /// Unlink the node from its list. Returns the next node in the list.
490
10.9M
  iterator unlink(const SMSNode &N) {
491
10.9M
    if (isSingleton(N)) {
492
9.62M
      // Singleton is already unlinked
493
9.62M
      assert(N.Next == SMSNode::INVALID && "Singleton has next?");
494
9.62M
      return iterator(this, SMSNode::INVALID, ValIndexOf(N.Data));
495
9.62M
    }
496
1.28M
497
1.28M
    if (isHead(N)) {
498
1.28M
      // If we're the head, then update the sparse array and our next.
499
1.28M
      Sparse[sparseIndex(N)] = N.Next;
500
1.28M
      Dense[N.Next].Prev = N.Prev;
501
1.28M
      return iterator(this, N.Next, ValIndexOf(N.Data));
502
1.28M
    }
503
5.20k
504
5.20k
    if (N.isTail()) {
505
3.60k
      // If we're the tail, then update our head and our previous.
506
3.60k
      findIndex(sparseIndex(N)).setPrev(N.Prev);
507
3.60k
      Dense[N.Prev].Next = N.Next;
508
3.60k
509
3.60k
      // Give back an end iterator that can be decremented
510
3.60k
      iterator I(this, N.Prev, ValIndexOf(N.Data));
511
3.60k
      return ++I;
512
3.60k
    }
513
1.60k
514
1.60k
    // Otherwise, just drop us
515
1.60k
    Dense[N.Next].Prev = N.Prev;
516
1.60k
    Dense[N.Prev].Next = N.Next;
517
1.60k
    return iterator(this, N.Next, ValIndexOf(N.Data));
518
1.60k
  }
llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::unlink(llvm::SparseMultiSet<llvm::PhysRegSUOper, llvm::identity<unsigned int>, unsigned short>::SMSNode const&)
Line
Count
Source
490
5.17M
  iterator unlink(const SMSNode &N) {
491
5.17M
    if (isSingleton(N)) {
492
4.97M
      // Singleton is already unlinked
493
4.97M
      assert(N.Next == SMSNode::INVALID && "Singleton has next?");
494
4.97M
      return iterator(this, SMSNode::INVALID, ValIndexOf(N.Data));
495
4.97M
    }
496
192k
497
192k
    if (isHead(N)) {
498
192k
      // If we're the head, then update the sparse array and our next.
499
192k
      Sparse[sparseIndex(N)] = N.Next;
500
192k
      Dense[N.Next].Prev = N.Prev;
501
192k
      return iterator(this, N.Next, ValIndexOf(N.Data));
502
192k
    }
503
181
504
181
    if (N.isTail()) {
505
181
      // If we're the tail, then update our head and our previous.
506
181
      findIndex(sparseIndex(N)).setPrev(N.Prev);
507
181
      Dense[N.Prev].Next = N.Next;
508
181
509
181
      // Give back an end iterator that can be decremented
510
181
      iterator I(this, N.Prev, ValIndexOf(N.Data));
511
181
      return ++I;
512
181
    }
513
0
514
0
    // Otherwise, just drop us
515
0
    Dense[N.Next].Prev = N.Prev;
516
0
    Dense[N.Prev].Next = N.Next;
517
0
    return iterator(this, N.Next, ValIndexOf(N.Data));
518
0
  }
llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::unlink(llvm::SparseMultiSet<llvm::VReg2SUnitOperIdx, llvm::VirtReg2IndexFunctor, unsigned char>::SMSNode const&)
Line
Count
Source
490
5.73M
  iterator unlink(const SMSNode &N) {
491
5.73M
    if (isSingleton(N)) {
492
4.64M
      // Singleton is already unlinked
493
4.64M
      assert(N.Next == SMSNode::INVALID && "Singleton has next?");
494
4.64M
      return iterator(this, SMSNode::INVALID, ValIndexOf(N.Data));
495
4.64M
    }
496
1.09M
497
1.09M
    if (isHead(N)) {
498
1.09M
      // If we're the head, then update the sparse array and our next.
499
1.09M
      Sparse[sparseIndex(N)] = N.Next;
500
1.09M
      Dense[N.Next].Prev = N.Prev;
501
1.09M
      return iterator(this, N.Next, ValIndexOf(N.Data));
502
1.09M
    }
503
5.02k
504
5.02k
    if (N.isTail()) {
505
3.42k
      // If we're the tail, then update our head and our previous.
506
3.42k
      findIndex(sparseIndex(N)).setPrev(N.Prev);
507
3.42k
      Dense[N.Prev].Next = N.Next;
508
3.42k
509
3.42k
      // Give back an end iterator that can be decremented
510
3.42k
      iterator I(this, N.Prev, ValIndexOf(N.Data));
511
3.42k
      return ++I;
512
3.42k
    }
513
1.60k
514
1.60k
    // Otherwise, just drop us
515
1.60k
    Dense[N.Next].Prev = N.Prev;
516
1.60k
    Dense[N.Prev].Next = N.Next;
517
1.60k
    return iterator(this, N.Next, ValIndexOf(N.Data));
518
1.60k
  }
519
};
520
521
} // end namespace llvm
522
523
#endif // LLVM_ADT_SPARSEMULTISET_H