Skip to content

Commit df2a7a9

Browse files
[ADT] clang-format several files (NFC)
I'm planning to modify these files.
1 parent fefe670 commit df2a7a9

File tree

4 files changed

+74
-109
lines changed

4 files changed

+74
-109
lines changed

llvm/include/llvm/ADT/IndexedMap.h

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,67 +20,56 @@
2020
#ifndef LLVM_ADT_INDEXEDMAP_H
2121
#define LLVM_ADT_INDEXEDMAP_H
2222

23-
#include "llvm/ADT/SmallVector.h"
2423
#include "llvm/ADT/STLExtras.h"
24+
#include "llvm/ADT/SmallVector.h"
2525
#include "llvm/ADT/identity.h"
2626
#include <cassert>
2727

2828
namespace llvm {
2929

30-
template <typename T, typename ToIndexT = identity<unsigned>>
31-
class IndexedMap {
32-
using IndexT = typename ToIndexT::argument_type;
33-
// Prefer SmallVector with zero inline storage over std::vector. IndexedMaps
34-
// can grow very large and SmallVector grows more efficiently as long as T
35-
// is trivially copyable.
36-
using StorageT = SmallVector<T, 0>;
37-
38-
StorageT storage_;
39-
T nullVal_;
40-
ToIndexT toIndex_;
41-
42-
public:
43-
IndexedMap() : nullVal_(T()) {}
44-
45-
explicit IndexedMap(const T& val) : nullVal_(val) {}
46-
47-
typename StorageT::reference operator[](IndexT n) {
48-
assert(toIndex_(n) < storage_.size() && "index out of bounds!");
49-
return storage_[toIndex_(n)];
50-
}
51-
52-
typename StorageT::const_reference operator[](IndexT n) const {
53-
assert(toIndex_(n) < storage_.size() && "index out of bounds!");
54-
return storage_[toIndex_(n)];
55-
}
56-
57-
void reserve(typename StorageT::size_type s) {
58-
storage_.reserve(s);
59-
}
60-
61-
void resize(typename StorageT::size_type s) {
62-
storage_.resize(s, nullVal_);
63-
}
64-
65-
void clear() {
66-
storage_.clear();
67-
}
68-
69-
void grow(IndexT n) {
70-
unsigned NewSize = toIndex_(n) + 1;
71-
if (NewSize > storage_.size())
72-
resize(NewSize);
73-
}
74-
75-
bool inBounds(IndexT n) const {
76-
return toIndex_(n) < storage_.size();
77-
}
78-
79-
typename StorageT::size_type size() const {
80-
return storage_.size();
81-
}
82-
};
83-
84-
} // end namespace llvm
30+
template <typename T, typename ToIndexT = identity<unsigned>> class IndexedMap {
31+
using IndexT = typename ToIndexT::argument_type;
32+
// Prefer SmallVector with zero inline storage over std::vector. IndexedMaps
33+
// can grow very large and SmallVector grows more efficiently as long as T
34+
// is trivially copyable.
35+
using StorageT = SmallVector<T, 0>;
36+
37+
StorageT storage_;
38+
T nullVal_;
39+
ToIndexT toIndex_;
40+
41+
public:
42+
IndexedMap() : nullVal_(T()) {}
43+
44+
explicit IndexedMap(const T &val) : nullVal_(val) {}
45+
46+
typename StorageT::reference operator[](IndexT n) {
47+
assert(toIndex_(n) < storage_.size() && "index out of bounds!");
48+
return storage_[toIndex_(n)];
49+
}
50+
51+
typename StorageT::const_reference operator[](IndexT n) const {
52+
assert(toIndex_(n) < storage_.size() && "index out of bounds!");
53+
return storage_[toIndex_(n)];
54+
}
55+
56+
void reserve(typename StorageT::size_type s) { storage_.reserve(s); }
57+
58+
void resize(typename StorageT::size_type s) { storage_.resize(s, nullVal_); }
59+
60+
void clear() { storage_.clear(); }
61+
62+
void grow(IndexT n) {
63+
unsigned NewSize = toIndex_(n) + 1;
64+
if (NewSize > storage_.size())
65+
resize(NewSize);
66+
}
67+
68+
bool inBounds(IndexT n) const { return toIndex_(n) < storage_.size(); }
69+
70+
typename StorageT::size_type size() const { return storage_.size(); }
71+
};
72+
73+
} // namespace llvm
8574

8675
#endif // LLVM_ADT_INDEXEDMAP_H

llvm/include/llvm/ADT/SparseMultiSet.h

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#ifndef LLVM_ADT_SPARSEMULTISET_H
2222
#define LLVM_ADT_SPARSEMULTISET_H
2323

24-
#include "llvm/ADT/identity.h"
2524
#include "llvm/ADT/SmallVector.h"
2625
#include "llvm/ADT/SparseSet.h"
26+
#include "llvm/ADT/identity.h"
2727
#include <cassert>
2828
#include <cstdint>
2929
#include <cstdlib>
@@ -80,9 +80,8 @@ namespace llvm {
8080
/// @tparam KeyFunctorT A functor that computes an unsigned index from KeyT.
8181
/// @tparam SparseT An unsigned integer type. See above.
8282
///
83-
template<typename ValueT,
84-
typename KeyFunctorT = identity<unsigned>,
85-
typename SparseT = uint8_t>
83+
template <typename ValueT, typename KeyFunctorT = identity<unsigned>,
84+
typename SparseT = uint8_t>
8685
class SparseMultiSet {
8786
static_assert(std::is_unsigned_v<SparseT>,
8887
"SparseT must be an unsigned integer type");
@@ -103,14 +102,10 @@ class SparseMultiSet {
103102
SMSNode(ValueT D, unsigned P, unsigned N) : Data(D), Prev(P), Next(N) {}
104103

105104
/// List tails have invalid Nexts.
106-
bool isTail() const {
107-
return Next == INVALID;
108-
}
105+
bool isTail() const { return Next == INVALID; }
109106

110107
/// Whether this node is a tombstone node, and thus is in our freelist.
111-
bool isTombstone() const {
112-
return Prev == INVALID;
113-
}
108+
bool isTombstone() const { return Prev == INVALID; }
114109

115110
/// Since the list is circular in Prev, all non-tombstone nodes have a valid
116111
/// Prev.
@@ -156,7 +151,7 @@ class SparseMultiSet {
156151

157152
/// Add in the given SMSNode. Uses a free entry in our freelist if
158153
/// available. Returns the index of the added node.
159-
unsigned addValue(const ValueT& V, unsigned Prev, unsigned Next) {
154+
unsigned addValue(const ValueT &V, unsigned Prev, unsigned Next) {
160155
if (NumFree == 0) {
161156
Dense.push_back(SMSNode(V, Prev, Next));
162157
return Dense.size() - 1;
@@ -204,13 +199,13 @@ class SparseMultiSet {
204199
// seem like a likely use case, so we can add that code when we need it.
205200
assert(empty() && "Can only resize universe on an empty map");
206201
// Hysteresis prevents needless reallocations.
207-
if (U >= Universe/4 && U <= Universe)
202+
if (U >= Universe / 4 && U <= Universe)
208203
return;
209204
free(Sparse);
210205
// The Sparse array doesn't actually need to be initialized, so malloc
211206
// would be enough here, but that will cause tools like valgrind to
212207
// complain about branching on uninitialized data.
213-
Sparse = static_cast<SparseT*>(safe_calloc(U, sizeof(SparseT)));
208+
Sparse = static_cast<SparseT *>(safe_calloc(U, sizeof(SparseT)));
214209
Universe = U;
215210
}
216211

@@ -232,7 +227,7 @@ class SparseMultiSet {
232227
unsigned SparseIdx;
233228

234229
iterator_base(SMSPtrTy P, unsigned I, unsigned SI)
235-
: SMS(P), Idx(I), SparseIdx(SI) {}
230+
: SMS(P), Idx(I), SparseIdx(SI) {}
236231

237232
/// Whether our iterator has fallen outside our dense vector.
238233
bool isEnd() const {
@@ -273,9 +268,7 @@ class SparseMultiSet {
273268
return false;
274269
}
275270

276-
bool operator!=(const iterator_base &RHS) const {
277-
return !operator==(RHS);
278-
}
271+
bool operator!=(const iterator_base &RHS) const { return !operator==(RHS); }
279272

280273
/// Increment and decrement operators
281274
iterator_base &operator--() { // predecrement - Back up
@@ -372,12 +365,10 @@ class SparseMultiSet {
372365
/// @param Key A valid key to find.
373366
/// @returns An iterator to the element identified by key, or end().
374367
///
375-
iterator find(const KeyT &Key) {
376-
return findIndex(KeyIndexOf(Key));
377-
}
368+
iterator find(const KeyT &Key) { return findIndex(KeyIndexOf(Key)); }
378369

379370
const_iterator find(const KeyT &Key) const {
380-
iterator I = const_cast<SparseMultiSet*>(this)->findIndex(KeyIndexOf(Key));
371+
iterator I = const_cast<SparseMultiSet *>(this)->findIndex(KeyIndexOf(Key));
381372
return const_iterator(I.SMS, I.Idx, KeyIndexOf(Key));
382373
}
383374

@@ -392,9 +383,7 @@ class SparseMultiSet {
392383
}
393384

394385
/// Returns true if this set contains an element identified by Key.
395-
bool contains(const KeyT &Key) const {
396-
return find(Key) != end();
397-
}
386+
bool contains(const KeyT &Key) const { return find(Key) != end(); }
398387

399388
/// Return the head and tail of the subset's list, otherwise returns end().
400389
iterator getHead(const KeyT &Key) { return find(Key); }
@@ -517,6 +506,6 @@ class SparseMultiSet {
517506
}
518507
};
519508

520-
} // end namespace llvm
509+
} // namespace llvm
521510

522511
#endif // LLVM_ADT_SPARSEMULTISET_H

llvm/include/llvm/ADT/SparseSet.h

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#ifndef LLVM_ADT_SPARSESET_H
2121
#define LLVM_ADT_SPARSESET_H
2222

23-
#include "llvm/ADT/identity.h"
2423
#include "llvm/ADT/SmallVector.h"
24+
#include "llvm/ADT/identity.h"
2525
#include "llvm/Support/AllocatorBase.h"
2626
#include <cassert>
2727
#include <cstdint>
@@ -53,8 +53,7 @@ namespace llvm {
5353
///
5454
/// For best results, ValueT should not require a destructor.
5555
///
56-
template<typename ValueT>
57-
struct SparseSetValTraits {
56+
template <typename ValueT> struct SparseSetValTraits {
5857
static unsigned getValIndex(const ValueT &Val) {
5958
return Val.getSparseSetIndex();
6059
}
@@ -64,7 +63,7 @@ struct SparseSetValTraits {
6463
/// generic implementation handles ValueT classes which either provide
6564
/// getSparseSetIndex() or specialize SparseSetValTraits<>.
6665
///
67-
template<typename KeyT, typename ValueT, typename KeyFunctorT>
66+
template <typename KeyT, typename ValueT, typename KeyFunctorT>
6867
struct SparseSetValFunctor {
6968
unsigned operator()(const ValueT &Val) const {
7069
return SparseSetValTraits<ValueT>::getValIndex(Val);
@@ -73,11 +72,9 @@ struct SparseSetValFunctor {
7372

7473
/// SparseSetValFunctor<KeyT, KeyT> - Helper class for the common case of
7574
/// identity key/value sets.
76-
template<typename KeyT, typename KeyFunctorT>
75+
template <typename KeyT, typename KeyFunctorT>
7776
struct SparseSetValFunctor<KeyT, KeyT, KeyFunctorT> {
78-
unsigned operator()(const KeyT &Key) const {
79-
return KeyFunctorT()(Key);
80-
}
77+
unsigned operator()(const KeyT &Key) const { return KeyFunctorT()(Key); }
8178
};
8279

8380
/// SparseSet - Fast set implementation for objects that can be identified by
@@ -118,9 +115,8 @@ struct SparseSetValFunctor<KeyT, KeyT, KeyFunctorT> {
118115
/// @tparam KeyFunctorT A functor that computes an unsigned index from KeyT.
119116
/// @tparam SparseT An unsigned integer type. See above.
120117
///
121-
template<typename ValueT,
122-
typename KeyFunctorT = identity<unsigned>,
123-
typename SparseT = uint8_t>
118+
template <typename ValueT, typename KeyFunctorT = identity<unsigned>,
119+
typename SparseT = uint8_t>
124120
class SparseSet {
125121
static_assert(std::is_unsigned_v<SparseT>,
126122
"SparseT must be an unsigned integer type");
@@ -162,7 +158,7 @@ class SparseSet {
162158
// seem like a likely use case, so we can add that code when we need it.
163159
assert(empty() && "Can only resize universe on an empty map");
164160
// Hysteresis prevents needless reallocations.
165-
if (U >= Universe/4 && U <= Universe)
161+
if (U >= Universe / 4 && U <= Universe)
166162
return;
167163
// The Sparse array doesn't actually need to be initialized, so malloc
168164
// would be enough here, but that will cause tools like valgrind to
@@ -226,12 +222,10 @@ class SparseSet {
226222
/// @param Key A valid key to find.
227223
/// @returns An iterator to the element identified by key, or end().
228224
///
229-
iterator find(const KeyT &Key) {
230-
return findIndex(KeyIndexOf(Key));
231-
}
225+
iterator find(const KeyT &Key) { return findIndex(KeyIndexOf(Key)); }
232226

233227
const_iterator find(const KeyT &Key) const {
234-
return const_cast<SparseSet*>(this)->findIndex(KeyIndexOf(Key));
228+
return const_cast<SparseSet *>(this)->findIndex(KeyIndexOf(Key));
235229
}
236230

237231
/// Check if the set contains the given \c Key.
@@ -267,9 +261,7 @@ class SparseSet {
267261
/// array subscript - If an element already exists with this key, return it.
268262
/// Otherwise, automatically construct a new value from Key, insert it,
269263
/// and return the newly inserted element.
270-
ValueT &operator[](const KeyT &Key) {
271-
return *insert(ValueT(Key)).first;
272-
}
264+
ValueT &operator[](const KeyT &Key) { return *insert(ValueT(Key)).first; }
273265

274266
ValueT pop_back_val() {
275267
// Sparse does not need to be cleared, see find().
@@ -318,6 +310,6 @@ class SparseSet {
318310
}
319311
};
320312

321-
} // end namespace llvm
313+
} // namespace llvm
322314

323315
#endif // LLVM_ADT_SPARSESET_H

llvm/include/llvm/ADT/identity.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,17 @@
1515
#ifndef LLVM_ADT_IDENTITY_H
1616
#define LLVM_ADT_IDENTITY_H
1717

18-
1918
namespace llvm {
2019

2120
// Similar to `std::identity` from C++20.
2221
template <class Ty> struct identity {
2322
using is_transparent = void;
2423
using argument_type = Ty;
2524

26-
Ty &operator()(Ty &self) const {
27-
return self;
28-
}
29-
const Ty &operator()(const Ty &self) const {
30-
return self;
31-
}
25+
Ty &operator()(Ty &self) const { return self; }
26+
const Ty &operator()(const Ty &self) const { return self; }
3227
};
3328

34-
} // end namespace llvm
29+
} // namespace llvm
3530

3631
#endif // LLVM_ADT_IDENTITY_H

0 commit comments

Comments
 (0)