LLVM: include/llvm/ADT/ArrayRef.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9#ifndef LLVM_ADT_ARRAYREF_H
10#define LLVM_ADT_ARRAYREF_H
11
16#include
17#include
18#include
19#include
20#include <initializer_list>
21#include
22#include <type_traits>
23#include
24
25namespace llvm {
27
28
29
30
31
32
33
34
35
36
37
38
39 template
41 public:
53
54 private:
55
56 const T *Data = nullptr;
57
58
60
61 public:
62
63
64
65
67
68
70 : Data(&OneElt), Length(1) {}
71
72
74 size_t length)
75 : Data(data), Length(length) {}
76
77
82
83
84
85 template <
86 typename C,
87 typename = std::enable_if_t<
88 std::conjunction_v<
89 std::is_convertible<
90 decltype(std::declval<const C &>().data()) *,
91 const T *const *>,
92 std::is_integral<decltype(std::declval<const C &>().size())>>,
93 void>>
96
97
98 template <size_t N>
100 : Data(Arr), Length(N) {}
101
102
103#if LLVM_GNUC_PREREQ(9, 0, 0)
104
105
106
107#pragma GCC diagnostic push
108#pragma GCC diagnostic ignored "-Winit-list-lifetime"
109#endif
112 : Data(Vec.begin() == Vec.end() ? (T *)nullptr : Vec.begin()),
113 Length(Vec.size()) {}
114#if LLVM_GNUC_PREREQ(9, 0, 0)
115#pragma GCC diagnostic pop
116#endif
117
118
119
120
121 template <typename U, typename = std::enable_if_t<
122 std::is_convertible_v<U *const *, T *const *>>>
125
126
127
128
129
132
135
136
137 bool empty() const { return Length == 0; }
138
139 const T *data() const { return Data; }
140
141
142 size_t size() const { return Length; }
143
144
147 return Data[0];
148 }
149
150
153 return Data[Length-1];
154 }
155
156
160 return Ret;
161 }
162
163
167 return Ret;
168 }
169
170
172 T *Buff = A.template Allocate(Length);
175 }
176
177
179 if (Length != RHS.Length)
180 return false;
181 return std::equal(begin(), end(), RHS.begin());
182 }
183
184
185
187 assert(N+M <= size() && "Invalid specifier");
189 }
190
191
193
194
196 assert(size() >= N && "Dropping more elements than exist");
198 }
199
200
202 assert(size() >= N && "Dropping more elements than exist");
204 }
205
206
207
211
212
213
217
218
224
225
231
232
233
237
238
239
243
244
245
246
248 assert(Index < Length && "Invalid index!");
249 return Data[Index];
250 }
251
252
253
254
255
256 template
257 std::enable_if_t<std::is_same<U, T>::value, ArrayRef> &
259
260
261
262
263
264 template
265 std::enable_if_t<std::is_same<U, T>::value, ArrayRef> &
266 operator=(std::initializer_list) = delete;
267
268
269
270
272 return std::vector(Data, Data+Length);
273 }
274
275
276
277
278 operator std::vector() const {
279 return std::vector(Data, Data+Length);
280 }
281
282
283 };
284
285
286
287
288
289
290
291
292
293
294
295
296
297 template
299 public:
311
312
314
315
317
318
321
322
324
325
326
327 template <typename C,
328 typename = std::enable_if_t<
329 std::conjunction_v<
330 std::is_convertible<
331 decltype(std::declval<C &>().data()) *, T *const *>,
332 std::is_integral<decltype(std::declval<C &>().size())>>,
333 void>>
335
336
337 template <size_t N>
339
341
344
347
348
351 return data()[0];
352 }
353
354
357 return data()[this->size()-1];
358 }
359
360
366
367
373
374
375
377 assert(N + M <= this->size() && "Invalid specifier");
379 }
380
381
385
386
388 assert(this->size() >= N && "Dropping more elements than exist");
390 }
391
393 assert(this->size() >= N && "Dropping more elements than exist");
395 }
396
397
398
399 template
403
404
405
406 template
410
411
414 return *this;
416 }
417
418
421 return *this;
423 }
424
425
426
427 template
431
432
433
434 template
438
439
440
441
443 assert(Index < this->size() && "Invalid index!");
444 return data()[Index];
445 }
446 };
447
448
450 public:
453
456 std::copy(Data.begin(), Data.end(), this->begin());
457 }
458
460
462 delete[] this->data();
465 return *this;
466 }
467
469 };
470
471
472
473
475
476
478
479
481
482
484
485
486 template <typename T, unsigned N>
488
489
491
492
493 template <typename T, std::size_t N>
495
496
498
499
501
502
504
505
506
507
508
509
511
512
513
514 template
516
517
518 template
520
521 template <class T, unsigned N>
523
524
526
527
528 template <class T, std::size_t N>
530
531
532 template <typename T, size_t N>
534
535
536
537
538
539 template
542 }
543
544 template
549
550 template
553 }
554
555 template
559 }
560
561 template
563 return std::lexicographical_compare(LHS.begin(), LHS.end(), RHS.begin(),
564 RHS.end());
565 }
566
567 template
571
572 template
576
577 template
581
582
583
587
588
592 reinterpret_cast<const T *>(~static_cast<uintptr_t>(0)), size_t(0));
593 }
594
597 reinterpret_cast<const T *>(~static_cast<uintptr_t>(1)), size_t(0));
598 }
599
602 "Cannot hash the empty key!");
604 "Cannot hash the tombstone key!");
606 }
607
615 };
616
617}
618
619#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_LIFETIME_BOUND
#define LLVM_GSL_POINTER
LLVM_GSL_POINTER - Apply this to non-owning classes like StringRef to enable lifetime warnings.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
std::enable_if_t< std::is_same< U, T >::value, ArrayRef< T > > & operator=(std::initializer_list< U >)=delete
Disallow accidental assignment from a temporary.
size_t size_type
Definition ArrayRef.h:51
std::vector< T > vec() const
Definition ArrayRef.h:271
bool equals(ArrayRef RHS) const
equals - Check for element-wise equality.
Definition ArrayRef.h:178
ArrayRef< T > drop_while(PredicateT Pred) const
Return a copy of *this with the first N elements satisfying the given predicate removed.
Definition ArrayRef.h:208
const T & back() const
back - Get the last element.
Definition ArrayRef.h:151
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition ArrayRef.h:219
constexpr ArrayRef(std::initializer_list< T > Vec LLVM_LIFETIME_BOUND)
Construct an ArrayRef from a std::initializer_list.
Definition ArrayRef.h:110
MutableArrayRef< T > copy(Allocator &A)
Definition ArrayRef.h:171
const value_type * const_pointer
Definition ArrayRef.h:44
ArrayRef< llvm::cfg::Update< MachineBasicBlock * > > drop_front(size_t N=1) const
Definition ArrayRef.h:195
ArrayRef< T > slice(size_t N) const
slice(n) - Chop off the first N elements of the array.
Definition ArrayRef.h:192
ptrdiff_t difference_type
Definition ArrayRef.h:52
reverse_iterator rend() const
Definition ArrayRef.h:134
const_pointer const_iterator
Definition ArrayRef.h:48
const T & front() const
front - Get the first element.
Definition ArrayRef.h:145
ArrayRef< T > take_while(PredicateT Pred) const
Return the first N elements of this Array that satisfy the given predicate.
Definition ArrayRef.h:234
ArrayRef(const T &OneElt LLVM_LIFETIME_BOUND)
Construct an ArrayRef from a single element.
Definition ArrayRef.h:69
constexpr ArrayRef(const T *begin LLVM_LIFETIME_BOUND, const T *end)
Construct an ArrayRef from a range.
Definition ArrayRef.h:78
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition ArrayRef.h:50
iterator end() const
Definition ArrayRef.h:131
const value_type & const_reference
Definition ArrayRef.h:46
value_type * pointer
Definition ArrayRef.h:43
ArrayRef< T > take_until(PredicateT Pred) const
Return the first N elements of this Array that don't satisfy the given predicate.
Definition ArrayRef.h:240
ArrayRef< T > drop_until(PredicateT Pred) const
Return a copy of *this with the first N elements not satisfying the given predicate removed.
Definition ArrayRef.h:214
size_t size() const
Definition ArrayRef.h:142
ArrayRef()=default
Construct an empty ArrayRef.
value_type & reference
Definition ArrayRef.h:45
const_pointer iterator
Definition ArrayRef.h:47
const T & consume_back()
consume_back() - Returns the last element and drops it from ArrayRef.
Definition ArrayRef.h:164
std::reverse_iterator< iterator > reverse_iterator
Definition ArrayRef.h:49
ArrayRef< llvm::cfg::Update< MachineBasicBlock * > > drop_back(size_t N=1) const
Definition ArrayRef.h:201
iterator begin() const
Definition ArrayRef.h:130
T value_type
Definition ArrayRef.h:42
ArrayRef< T > take_back(size_t N=1) const
Return a copy of *this with only the last N elements.
Definition ArrayRef.h:226
bool empty() const
empty - Check if the array is empty.
Definition ArrayRef.h:137
constexpr ArrayRef(const T(&Arr LLVM_LIFETIME_BOUND)[N])
Construct an ArrayRef from a C array.
Definition ArrayRef.h:99
ArrayRef(const iterator_range< U * > &Range)
Construct an ArrayRef from iterator_range<U*>.
Definition ArrayRef.h:123
constexpr ArrayRef(const T *data LLVM_LIFETIME_BOUND, size_t length)
Construct an ArrayRef from a pointer and length.
Definition ArrayRef.h:73
const T & operator[](size_t Index) const
Definition ArrayRef.h:247
const llvm::cfg::Update< MachineBasicBlock * > * data() const
Definition ArrayRef.h:139
constexpr ArrayRef(const C &V)
Construct an ArrayRef from a type that has a data() method that returns a pointer convertible to cons...
Definition ArrayRef.h:94
std::enable_if_t< std::is_same< U, T >::value, ArrayRef< T > > & operator=(U &&Temporary)=delete
Disallow accidental assignment from a temporary.
reverse_iterator rbegin() const
Definition ArrayRef.h:133
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Definition ArrayRef.h:186
const T & consume_front()
consume_front() - Returns the first element and drops it from ArrayRef.
Definition ArrayRef.h:157
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition ArrayRef.h:298
char * data() const
Definition ArrayRef.h:340
MutableArrayRef< T > take_until(PredicateT Pred) const
Return the first N elements of this Array that don't satisfy the given predicate.
Definition ArrayRef.h:435
MutableArrayRef(T &OneElt)
Construct a MutableArrayRef from a single element.
Definition ArrayRef.h:316
MutableArrayRef< char > drop_front(size_t N=1) const
Definition ArrayRef.h:387
T & consume_front()
consume_front() - Returns the first element and drops it from ArrayRef.
Definition ArrayRef.h:361
const value_type * const_pointer
Definition ArrayRef.h:302
T & consume_back()
consume_back() - Returns the last element and drops it from ArrayRef.
Definition ArrayRef.h:368
MutableArrayRef< T > take_back(size_t N=1) const
Return a copy of *this with only the last N elements.
Definition ArrayRef.h:419
reverse_iterator rbegin() const
Definition ArrayRef.h:345
value_type & reference
Definition ArrayRef.h:303
MutableArrayRef(T *begin, T *end)
Construct a MutableArrayRef from a range.
Definition ArrayRef.h:323
MutableArrayRef< T > slice(size_t N) const
slice(n) - Chop off the first N elements of the array.
Definition ArrayRef.h:382
MutableArrayRef(T *data, size_t length)
Construct a MutableArrayRef from a pointer and length.
Definition ArrayRef.h:319
MutableArrayRef()=default
Construct an empty MutableArrayRef.
T value_type
Definition ArrayRef.h:300
const_pointer const_iterator
Definition ArrayRef.h:306
T & front() const
front - Get the first element.
Definition ArrayRef.h:349
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition ArrayRef.h:308
pointer iterator
Definition ArrayRef.h:305
size_t size_type
Definition ArrayRef.h:309
iterator end() const
Definition ArrayRef.h:343
iterator begin() const
Definition ArrayRef.h:342
value_type * pointer
Definition ArrayRef.h:301
T & operator[](size_t Index) const
Definition ArrayRef.h:442
T & back() const
back - Get the last element.
Definition ArrayRef.h:355
const value_type & const_reference
Definition ArrayRef.h:304
constexpr MutableArrayRef(const C &V)
Construct a MutableArrayRef from a type that has a data() method that returns a pointer convertible t...
Definition ArrayRef.h:334
constexpr MutableArrayRef(T(&Arr)[N])
Construct a MutableArrayRef from a C array.
Definition ArrayRef.h:338
MutableArrayRef< char > drop_back(size_t N=1) const
Definition ArrayRef.h:392
MutableArrayRef< T > take_while(PredicateT Pred) const
Return the first N elements of this Array that satisfy the given predicate.
Definition ArrayRef.h:428
MutableArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Definition ArrayRef.h:376
MutableArrayRef< T > drop_while(PredicateT Pred) const
Return a copy of *this with the first N elements satisfying the given predicate removed.
Definition ArrayRef.h:400
ptrdiff_t difference_type
Definition ArrayRef.h:310
reverse_iterator rend() const
Definition ArrayRef.h:346
MutableArrayRef< T > drop_until(PredicateT Pred) const
Return a copy of *this with the first N elements not satisfying the given predicate removed.
Definition ArrayRef.h:407
MutableArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition ArrayRef.h:412
std::reverse_iterator< iterator > reverse_iterator
Definition ArrayRef.h:307
OwningArrayRef & operator=(OwningArrayRef &&Other)
Definition ArrayRef.h:461
OwningArrayRef(OwningArrayRef &&Other)
Definition ArrayRef.h:459
~OwningArrayRef()
Definition ArrayRef.h:468
OwningArrayRef(ArrayRef< T > Data)
Definition ArrayRef.h:454
OwningArrayRef(size_t Size)
Definition ArrayRef.h:452
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An opaque object representing a hash code.
A range adaptor for a pair of iterators.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
hash_code hash_value(const FixedPointSemantics &Val)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
bool operator!=(uint64_t V1, const APInt &V2)
bool operator>=(int64_t V1, const APSInt &V2)
auto uninitialized_copy(R &&Src, IterTy Dst)
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
bool operator>(int64_t V1, const APSInt &V2)
auto find_if_not(R &&Range, UnaryPredicate P)
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
ArrayRef(const T &OneElt) -> ArrayRef< T >
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
bool operator<=(int64_t V1, const APSInt &V2)
static bool isEqual(ArrayRef< T > LHS, ArrayRef< T > RHS)
Definition ArrayRef.h:608
static ArrayRef< T > getTombstoneKey()
Definition ArrayRef.h:595
static unsigned getHashValue(ArrayRef< T > Val)
Definition ArrayRef.h:600
static ArrayRef< T > getEmptyKey()
Definition ArrayRef.h:590
An information struct used to provide DenseMap with the various necessary components for a given valu...