LLVM 20.0.0git
ArrayRef.h
Go to the documentation of this file.
1//===- ArrayRef.h - Array Reference Wrapper ---------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_ADT_ARRAYREF_H
10#define LLVM_ADT_ARRAYREF_H
11
12#include "llvm/ADT/Hashing.h"
14#include "llvm/ADT/STLExtras.h"
16#include <algorithm>
17#include <array>
18#include <cassert>
19#include <cstddef>
20#include <initializer_list>
21#include <iterator>
22#include <memory>
23#include <type_traits>
24#include <vector>
25
26namespace llvm {
27 template<typename T> class [[nodiscard]] MutableArrayRef;
28
29 /// ArrayRef - Represent a constant reference to an array (0 or more elements
30 /// consecutively in memory), i.e. a start pointer and a length. It allows
31 /// various APIs to take consecutive elements easily and conveniently.
32 ///
33 /// This class does not own the underlying data, it is expected to be used in
34 /// situations where the data resides in some other buffer, whose lifetime
35 /// extends past that of the ArrayRef. For this reason, it is not in general
36 /// safe to store an ArrayRef.
37 ///
38 /// This is intended to be trivially copyable, so it should be passed by
39 /// value.
40 template<typename T>
41 class LLVM_GSL_POINTER [[nodiscard]] ArrayRef {
42 public:
43 using value_type = T;
45 using const_pointer = const value_type *;
47 using const_reference = const value_type &;
50 using reverse_iterator = std::reverse_iterator<iterator>;
51 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
52 using size_type = size_t;
54
55 private:
56 /// The start of the array, in an external buffer.
57 const T *Data = nullptr;
58
59 /// The number of elements.
60 size_type Length = 0;
61
62 public:
63 /// @name Constructors
64 /// @{
65
66 /// Construct an empty ArrayRef.
67 /*implicit*/ ArrayRef() = default;
68
69 /// Construct an empty ArrayRef from std::nullopt.
70 /*implicit*/ ArrayRef(std::nullopt_t) {}
71
72 /// Construct an ArrayRef from a single element.
73 /*implicit*/ ArrayRef(const T &OneElt LLVM_LIFETIME_BOUND)
74 : Data(&OneElt), Length(1) {}
75
76 /// Construct an ArrayRef from a pointer and length.
77 constexpr /*implicit*/ ArrayRef(const T *data LLVM_LIFETIME_BOUND,
78 size_t length)
79 : Data(data), Length(length) {}
80
81 /// Construct an ArrayRef from a range.
82 constexpr ArrayRef(const T *begin LLVM_LIFETIME_BOUND, const T *end)
83 : Data(begin), Length(end - begin) {
84 assert(begin <= end);
85 }
86
87 /// Construct an ArrayRef from a SmallVector. This is templated in order to
88 /// avoid instantiating SmallVectorTemplateCommon<T> whenever we
89 /// copy-construct an ArrayRef.
90 template<typename U>
92 : Data(Vec.data()), Length(Vec.size()) {
93 }
94
95 /// Construct an ArrayRef from a std::vector.
96 template<typename A>
97 /*implicit*/ ArrayRef(const std::vector<T, A> &Vec)
98 : Data(Vec.data()), Length(Vec.size()) {}
99
100 /// Construct an ArrayRef from a std::array
101 template <size_t N>
102 /*implicit*/ constexpr ArrayRef(const std::array<T, N> &Arr)
103 : Data(Arr.data()), Length(N) {}
104
105 /// Construct an ArrayRef from a C array.
106 template <size_t N>
107 /*implicit*/ constexpr ArrayRef(const T (&Arr LLVM_LIFETIME_BOUND)[N])
108 : Data(Arr), Length(N) {}
109
110 /// Construct an ArrayRef from a std::initializer_list.
111#if LLVM_GNUC_PREREQ(9, 0, 0)
112// Disable gcc's warning in this constructor as it generates an enormous amount
113// of messages. Anyone using ArrayRef should already be aware of the fact that
114// it does not do lifetime extension.
115#pragma GCC diagnostic push
116#pragma GCC diagnostic ignored "-Winit-list-lifetime"
117#endif
118 constexpr /*implicit*/ ArrayRef(
119 std::initializer_list<T> Vec LLVM_LIFETIME_BOUND)
120 : Data(Vec.begin() == Vec.end() ? (T *)nullptr : Vec.begin()),
121 Length(Vec.size()) {}
122#if LLVM_GNUC_PREREQ(9, 0, 0)
123#pragma GCC diagnostic pop
124#endif
125
126 /// Construct an ArrayRef<const T*> from ArrayRef<T*>. This uses SFINAE to
127 /// ensure that only ArrayRefs of pointers can be converted.
128 template <typename U>
130 std::enable_if_t<std::is_convertible<U *const *, T const *>::value>
131 * = nullptr)
132 : Data(A.data()), Length(A.size()) {}
133
134 /// Construct an ArrayRef<const T*> from a SmallVector<T*>. This is
135 /// templated in order to avoid instantiating SmallVectorTemplateCommon<T>
136 /// whenever we copy-construct an ArrayRef.
137 template <typename U, typename DummyT>
138 /*implicit*/ ArrayRef(
140 std::enable_if_t<std::is_convertible<U *const *, T const *>::value> * =
141 nullptr)
142 : Data(Vec.data()), Length(Vec.size()) {}
143
144 /// Construct an ArrayRef<const T*> from std::vector<T*>. This uses SFINAE
145 /// to ensure that only vectors of pointers can be converted.
146 template <typename U, typename A>
147 ArrayRef(const std::vector<U *, A> &Vec,
148 std::enable_if_t<std::is_convertible<U *const *, T const *>::value>
149 * = nullptr)
150 : Data(Vec.data()), Length(Vec.size()) {}
151
152 /// @}
153 /// @name Simple Operations
154 /// @{
155
156 iterator begin() const { return Data; }
157 iterator end() const { return Data + Length; }
158
159 reverse_iterator rbegin() const { return reverse_iterator(end()); }
160 reverse_iterator rend() const { return reverse_iterator(begin()); }
161
162 /// empty - Check if the array is empty.
163 bool empty() const { return Length == 0; }
164
165 const T *data() const { return Data; }
166
167 /// size - Get the array size.
168 size_t size() const { return Length; }
169
170 /// front - Get the first element.
171 const T &front() const {
172 assert(!empty());
173 return Data[0];
174 }
175
176 /// back - Get the last element.
177 const T &back() const {
178 assert(!empty());
179 return Data[Length-1];
180 }
181
182 // copy - Allocate copy in Allocator and return ArrayRef<T> to it.
183 template <typename Allocator> MutableArrayRef<T> copy(Allocator &A) {
184 T *Buff = A.template Allocate<T>(Length);
185 std::uninitialized_copy(begin(), end(), Buff);
186 return MutableArrayRef<T>(Buff, Length);
187 }
188
189 /// equals - Check for element-wise equality.
190 bool equals(ArrayRef RHS) const {
191 if (Length != RHS.Length)
192 return false;
193 return std::equal(begin(), end(), RHS.begin());
194 }
195
196 /// slice(n, m) - Chop off the first N elements of the array, and keep M
197 /// elements in the array.
198 ArrayRef<T> slice(size_t N, size_t M) const {
199 assert(N+M <= size() && "Invalid specifier");
200 return ArrayRef<T>(data()+N, M);
201 }
202
203 /// slice(n) - Chop off the first N elements of the array.
204 ArrayRef<T> slice(size_t N) const { return drop_front(N); }
205
206 /// Drop the first \p N elements of the array.
207 ArrayRef<T> drop_front(size_t N = 1) const {
208 assert(size() >= N && "Dropping more elements than exist");
209 return slice(N, size() - N);
210 }
211
212 /// Drop the last \p N elements of the array.
213 ArrayRef<T> drop_back(size_t N = 1) const {
214 assert(size() >= N && "Dropping more elements than exist");
215 return slice(0, size() - N);
216 }
217
218 /// Return a copy of *this with the first N elements satisfying the
219 /// given predicate removed.
220 template <class PredicateT> ArrayRef<T> drop_while(PredicateT Pred) const {
221 return ArrayRef<T>(find_if_not(*this, Pred), end());
222 }
223
224 /// Return a copy of *this with the first N elements not satisfying
225 /// the given predicate removed.
226 template <class PredicateT> ArrayRef<T> drop_until(PredicateT Pred) const {
227 return ArrayRef<T>(find_if(*this, Pred), end());
228 }
229
230 /// Return a copy of *this with only the first \p N elements.
231 ArrayRef<T> take_front(size_t N = 1) const {
232 if (N >= size())
233 return *this;
234 return drop_back(size() - N);
235 }
236
237 /// Return a copy of *this with only the last \p N elements.
238 ArrayRef<T> take_back(size_t N = 1) const {
239 if (N >= size())
240 return *this;
241 return drop_front(size() - N);
242 }
243
244 /// Return the first N elements of this Array that satisfy the given
245 /// predicate.
246 template <class PredicateT> ArrayRef<T> take_while(PredicateT Pred) const {
247 return ArrayRef<T>(begin(), find_if_not(*this, Pred));
248 }
249
250 /// Return the first N elements of this Array that don't satisfy the
251 /// given predicate.
252 template <class PredicateT> ArrayRef<T> take_until(PredicateT Pred) const {
253 return ArrayRef<T>(begin(), find_if(*this, Pred));
254 }
255
256 /// @}
257 /// @name Operator Overloads
258 /// @{
259 const T &operator[](size_t Index) const {
260 assert(Index < Length && "Invalid index!");
261 return Data[Index];
262 }
263
264 /// Disallow accidental assignment from a temporary.
265 ///
266 /// The declaration here is extra complicated so that "arrayRef = {}"
267 /// continues to select the move assignment operator.
268 template <typename U>
269 std::enable_if_t<std::is_same<U, T>::value, ArrayRef<T>> &
270 operator=(U &&Temporary) = delete;
271
272 /// Disallow accidental assignment from a temporary.
273 ///
274 /// The declaration here is extra complicated so that "arrayRef = {}"
275 /// continues to select the move assignment operator.
276 template <typename U>
277 std::enable_if_t<std::is_same<U, T>::value, ArrayRef<T>> &
278 operator=(std::initializer_list<U>) = delete;
279
280 /// @}
281 /// @name Expensive Operations
282 /// @{
283 std::vector<T> vec() const {
284 return std::vector<T>(Data, Data+Length);
285 }
286
287 /// @}
288 /// @name Conversion operators
289 /// @{
290 operator std::vector<T>() const {
291 return std::vector<T>(Data, Data+Length);
292 }
293
294 /// @}
295 };
296
297 /// MutableArrayRef - Represent a mutable reference to an array (0 or more
298 /// elements consecutively in memory), i.e. a start pointer and a length. It
299 /// allows various APIs to take and modify consecutive elements easily and
300 /// conveniently.
301 ///
302 /// This class does not own the underlying data, it is expected to be used in
303 /// situations where the data resides in some other buffer, whose lifetime
304 /// extends past that of the MutableArrayRef. For this reason, it is not in
305 /// general safe to store a MutableArrayRef.
306 ///
307 /// This is intended to be trivially copyable, so it should be passed by
308 /// value.
309 template<typename T>
310 class [[nodiscard]] MutableArrayRef : public ArrayRef<T> {
311 public:
312 using value_type = T;
314 using const_pointer = const value_type *;
319 using reverse_iterator = std::reverse_iterator<iterator>;
320 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
321 using size_type = size_t;
323
324 /// Construct an empty MutableArrayRef.
325 /*implicit*/ MutableArrayRef() = default;
326
327 /// Construct an empty MutableArrayRef from std::nullopt.
328 /*implicit*/ MutableArrayRef(std::nullopt_t) : ArrayRef<T>() {}
329
330 /// Construct a MutableArrayRef from a single element.
331 /*implicit*/ MutableArrayRef(T &OneElt) : ArrayRef<T>(OneElt) {}
332
333 /// Construct a MutableArrayRef from a pointer and length.
334 /*implicit*/ MutableArrayRef(T *data, size_t length)
335 : ArrayRef<T>(data, length) {}
336
337 /// Construct a MutableArrayRef from a range.
338 MutableArrayRef(T *begin, T *end) : ArrayRef<T>(begin, end) {}
339
340 /// Construct a MutableArrayRef from a SmallVector.
342 : ArrayRef<T>(Vec) {}
343
344 /// Construct a MutableArrayRef from a std::vector.
345 /*implicit*/ MutableArrayRef(std::vector<T> &Vec)
346 : ArrayRef<T>(Vec) {}
347
348 /// Construct a MutableArrayRef from a std::array
349 template <size_t N>
350 /*implicit*/ constexpr MutableArrayRef(std::array<T, N> &Arr)
351 : ArrayRef<T>(Arr) {}
352
353 /// Construct a MutableArrayRef from a C array.
354 template <size_t N>
355 /*implicit*/ constexpr MutableArrayRef(T (&Arr)[N]) : ArrayRef<T>(Arr) {}
356
357 T *data() const { return const_cast<T*>(ArrayRef<T>::data()); }
358
359 iterator begin() const { return data(); }
360 iterator end() const { return data() + this->size(); }
361
362 reverse_iterator rbegin() const { return reverse_iterator(end()); }
363 reverse_iterator rend() const { return reverse_iterator(begin()); }
364
365 /// front - Get the first element.
366 T &front() const {
367 assert(!this->empty());
368 return data()[0];
369 }
370
371 /// back - Get the last element.
372 T &back() const {
373 assert(!this->empty());
374 return data()[this->size()-1];
375 }
376
377 /// slice(n, m) - Chop off the first N elements of the array, and keep M
378 /// elements in the array.
379 MutableArrayRef<T> slice(size_t N, size_t M) const {
380 assert(N + M <= this->size() && "Invalid specifier");
381 return MutableArrayRef<T>(this->data() + N, M);
382 }
383
384 /// slice(n) - Chop off the first N elements of the array.
385 MutableArrayRef<T> slice(size_t N) const {
386 return slice(N, this->size() - N);
387 }
388
389 /// Drop the first \p N elements of the array.
390 MutableArrayRef<T> drop_front(size_t N = 1) const {
391 assert(this->size() >= N && "Dropping more elements than exist");
392 return slice(N, this->size() - N);
393 }
394
395 MutableArrayRef<T> drop_back(size_t N = 1) const {
396 assert(this->size() >= N && "Dropping more elements than exist");
397 return slice(0, this->size() - N);
398 }
399
400 /// Return a copy of *this with the first N elements satisfying the
401 /// given predicate removed.
402 template <class PredicateT>
404 return MutableArrayRef<T>(find_if_not(*this, Pred), end());
405 }
406
407 /// Return a copy of *this with the first N elements not satisfying
408 /// the given predicate removed.
409 template <class PredicateT>
411 return MutableArrayRef<T>(find_if(*this, Pred), end());
412 }
413
414 /// Return a copy of *this with only the first \p N elements.
415 MutableArrayRef<T> take_front(size_t N = 1) const {
416 if (N >= this->size())
417 return *this;
418 return drop_back(this->size() - N);
419 }
420
421 /// Return a copy of *this with only the last \p N elements.
422 MutableArrayRef<T> take_back(size_t N = 1) const {
423 if (N >= this->size())
424 return *this;
425 return drop_front(this->size() - N);
426 }
427
428 /// Return the first N elements of this Array that satisfy the given
429 /// predicate.
430 template <class PredicateT>
432 return MutableArrayRef<T>(begin(), find_if_not(*this, Pred));
433 }
434
435 /// Return the first N elements of this Array that don't satisfy the
436 /// given predicate.
437 template <class PredicateT>
439 return MutableArrayRef<T>(begin(), find_if(*this, Pred));
440 }
441
442 /// @}
443 /// @name Operator Overloads
444 /// @{
445 T &operator[](size_t Index) const {
446 assert(Index < this->size() && "Invalid index!");
447 return data()[Index];
448 }
449 };
450
451 /// This is a MutableArrayRef that owns its array.
452 template <typename T> class OwningArrayRef : public MutableArrayRef<T> {
453 public:
454 OwningArrayRef() = default;
456
458 : MutableArrayRef<T>(new T[Data.size()], Data.size()) {
459 std::copy(Data.begin(), Data.end(), this->begin());
460 }
461
462 OwningArrayRef(OwningArrayRef &&Other) { *this = std::move(Other); }
463
465 delete[] this->data();
467 Other.MutableArrayRef<T>::operator=(MutableArrayRef<T>());
468 return *this;
469 }
470
471 ~OwningArrayRef() { delete[] this->data(); }
472 };
473
474 /// @name ArrayRef Deduction guides
475 /// @{
476 /// Deduction guide to construct an ArrayRef from a single element.
477 template <typename T> ArrayRef(const T &OneElt) -> ArrayRef<T>;
478
479 /// Deduction guide to construct an ArrayRef from a pointer and length
480 template <typename T> ArrayRef(const T *data, size_t length) -> ArrayRef<T>;
481
482 /// Deduction guide to construct an ArrayRef from a range
483 template <typename T> ArrayRef(const T *data, const T *end) -> ArrayRef<T>;
484
485 /// Deduction guide to construct an ArrayRef from a SmallVector
486 template <typename T> ArrayRef(const SmallVectorImpl<T> &Vec) -> ArrayRef<T>;
487
488 /// Deduction guide to construct an ArrayRef from a SmallVector
489 template <typename T, unsigned N>
491
492 /// Deduction guide to construct an ArrayRef from a std::vector
493 template <typename T> ArrayRef(const std::vector<T> &Vec) -> ArrayRef<T>;
494
495 /// Deduction guide to construct an ArrayRef from a std::array
496 template <typename T, std::size_t N>
497 ArrayRef(const std::array<T, N> &Vec) -> ArrayRef<T>;
498
499 /// Deduction guide to construct an ArrayRef from an ArrayRef (const)
500 template <typename T> ArrayRef(const ArrayRef<T> &Vec) -> ArrayRef<T>;
501
502 /// Deduction guide to construct an ArrayRef from an ArrayRef
503 template <typename T> ArrayRef(ArrayRef<T> &Vec) -> ArrayRef<T>;
504
505 /// Deduction guide to construct an ArrayRef from a C array.
506 template <typename T, size_t N> ArrayRef(const T (&Arr)[N]) -> ArrayRef<T>;
507
508 /// @}
509
510 /// @name MutableArrayRef Deduction guides
511 /// @{
512 /// Deduction guide to construct a `MutableArrayRef` from a single element
513 template <class T> MutableArrayRef(T &OneElt) -> MutableArrayRef<T>;
514
515 /// Deduction guide to construct a `MutableArrayRef` from a pointer and
516 /// length.
517 template <class T>
518 MutableArrayRef(T *data, size_t length) -> MutableArrayRef<T>;
519
520 /// Deduction guide to construct a `MutableArrayRef` from a `SmallVector`.
521 template <class T>
523
524 template <class T, unsigned N>
526
527 /// Deduction guide to construct a `MutableArrayRef` from a `std::vector`.
528 template <class T> MutableArrayRef(std::vector<T> &Vec) -> MutableArrayRef<T>;
529
530 /// Deduction guide to construct a `MutableArrayRef` from a `std::array`.
531 template <class T, std::size_t N>
532 MutableArrayRef(std::array<T, N> &Vec) -> MutableArrayRef<T>;
533
534 /// Deduction guide to construct a `MutableArrayRef` from a C array.
535 template <typename T, size_t N>
537
538 /// @}
539 /// @name ArrayRef Comparison Operators
540 /// @{
541
542 template<typename T>
544 return LHS.equals(RHS);
545 }
546
547 template <typename T>
549 return ArrayRef<T>(LHS).equals(RHS);
550 }
551
552 template <typename T>
554 return !(LHS == RHS);
555 }
556
557 template <typename T>
559 return !(LHS == RHS);
560 }
561
562 /// @}
563
564 template <typename T> hash_code hash_value(ArrayRef<T> S) {
565 return hash_combine_range(S.begin(), S.end());
566 }
567
568 // Provide DenseMapInfo for ArrayRefs.
569 template <typename T> struct DenseMapInfo<ArrayRef<T>, void> {
570 static inline ArrayRef<T> getEmptyKey() {
571 return ArrayRef<T>(
572 reinterpret_cast<const T *>(~static_cast<uintptr_t>(0)), size_t(0));
573 }
574
575 static inline ArrayRef<T> getTombstoneKey() {
576 return ArrayRef<T>(
577 reinterpret_cast<const T *>(~static_cast<uintptr_t>(1)), size_t(0));
578 }
579
580 static unsigned getHashValue(ArrayRef<T> Val) {
581 assert(Val.data() != getEmptyKey().data() &&
582 "Cannot hash the empty key!");
583 assert(Val.data() != getTombstoneKey().data() &&
584 "Cannot hash the tombstone key!");
585 return (unsigned)(hash_value(Val));
586 }
587
589 if (RHS.data() == getEmptyKey().data())
590 return LHS.data() == getEmptyKey().data();
591 if (RHS.data() == getTombstoneKey().data())
592 return LHS.data() == getTombstoneKey().data();
593 return LHS == RHS;
594 }
595 };
596
597} // end namespace llvm
598
599#endif // LLVM_ADT_ARRAYREF_H
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_LIFETIME_BOUND
Definition: Compiler.h:419
#define LLVM_GSL_POINTER
LLVM_GSL_POINTER - Apply this to non-owning classes like StringRef to enable lifetime warnings.
Definition: Compiler.h:413
uint32_t Index
uint64_t Size
#define T
Basic Register Allocator
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallVector class.
Value * RHS
Value * LHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
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:52
std::vector< T > vec() const
Definition: ArrayRef.h:283
bool equals(ArrayRef RHS) const
equals - Check for element-wise equality.
Definition: ArrayRef.h:190
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:220
const T & back() const
back - Get the last element.
Definition: ArrayRef.h:177
ArrayRef(const std::vector< U *, A > &Vec, std::enable_if_t< std::is_convertible< U *const *, T const * >::value > *=nullptr)
Construct an ArrayRef<const T*> from std::vector<T*>.
Definition: ArrayRef.h:147
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition: ArrayRef.h:231
constexpr ArrayRef(std::initializer_list< T > Vec LLVM_LIFETIME_BOUND)
Construct an ArrayRef from a std::initializer_list.
Definition: ArrayRef.h:118
MutableArrayRef< T > copy(Allocator &A)
Definition: ArrayRef.h:183
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:207
ArrayRef< T > slice(size_t N) const
slice(n) - Chop off the first N elements of the array.
Definition: ArrayRef.h:204
reverse_iterator rend() const
Definition: ArrayRef.h:160
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:171
ArrayRef< T > take_while(PredicateT Pred) const
Return the first N elements of this Array that satisfy the given predicate.
Definition: ArrayRef.h:246
ArrayRef(const T &OneElt LLVM_LIFETIME_BOUND)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:73
constexpr ArrayRef(const T *begin LLVM_LIFETIME_BOUND, const T *end)
Construct an ArrayRef from a range.
Definition: ArrayRef.h:82
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: ArrayRef.h:51
iterator end() const
Definition: ArrayRef.h:157
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:252
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:226
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:168
ArrayRef()=default
Construct an empty ArrayRef.
ArrayRef(std::nullopt_t)
Construct an empty ArrayRef from std::nullopt.
Definition: ArrayRef.h:70
ArrayRef(const ArrayRef< U * > &A, std::enable_if_t< std::is_convertible< U *const *, T const * >::value > *=nullptr)
Construct an ArrayRef<const T*> from ArrayRef<T*>.
Definition: ArrayRef.h:129
std::reverse_iterator< iterator > reverse_iterator
Definition: ArrayRef.h:50
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
Definition: ArrayRef.h:213
iterator begin() const
Definition: ArrayRef.h:156
constexpr ArrayRef(const std::array< T, N > &Arr)
Construct an ArrayRef from a std::array.
Definition: ArrayRef.h:102
ArrayRef< T > take_back(size_t N=1) const
Return a copy of *this with only the last N elements.
Definition: ArrayRef.h:238
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:163
constexpr ArrayRef(const T(&Arr LLVM_LIFETIME_BOUND)[N])
Construct an ArrayRef from a C array.
Definition: ArrayRef.h:107
ArrayRef(const SmallVectorTemplateCommon< U *, DummyT > &Vec, std::enable_if_t< std::is_convertible< U *const *, T const * >::value > *=nullptr)
Construct an ArrayRef<const T*> from a SmallVector<T*>.
Definition: ArrayRef.h:138
constexpr ArrayRef(const T *data LLVM_LIFETIME_BOUND, size_t length)
Construct an ArrayRef from a pointer and length.
Definition: ArrayRef.h:77
const T & operator[](size_t Index) const
Definition: ArrayRef.h:259
ArrayRef(const std::vector< T, A > &Vec)
Construct an ArrayRef from a std::vector.
Definition: ArrayRef.h:97
const T * data() const
Definition: ArrayRef.h:165
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:159
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:198
ArrayRef(const SmallVectorTemplateCommon< T, U > &Vec)
Construct an ArrayRef from a SmallVector.
Definition: ArrayRef.h:91
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:310
T * data() const
Definition: ArrayRef.h:357
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:438
MutableArrayRef(T &OneElt)
Construct a MutableArrayRef from a single element.
Definition: ArrayRef.h:331
MutableArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:390
MutableArrayRef< T > take_back(size_t N=1) const
Return a copy of *this with only the last N elements.
Definition: ArrayRef.h:422
reverse_iterator rbegin() const
Definition: ArrayRef.h:362
MutableArrayRef(T *begin, T *end)
Construct a MutableArrayRef from a range.
Definition: ArrayRef.h:338
MutableArrayRef< T > slice(size_t N) const
slice(n) - Chop off the first N elements of the array.
Definition: ArrayRef.h:385
MutableArrayRef(T *data, size_t length)
Construct a MutableArrayRef from a pointer and length.
Definition: ArrayRef.h:334
MutableArrayRef()=default
Construct an empty MutableArrayRef.
constexpr MutableArrayRef(std::array< T, N > &Arr)
Construct a MutableArrayRef from a std::array.
Definition: ArrayRef.h:350
T & front() const
front - Get the first element.
Definition: ArrayRef.h:366
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: ArrayRef.h:320
iterator end() const
Definition: ArrayRef.h:360
iterator begin() const
Definition: ArrayRef.h:359
T & operator[](size_t Index) const
Definition: ArrayRef.h:445
T & back() const
back - Get the last element.
Definition: ArrayRef.h:372
MutableArrayRef(std::vector< T > &Vec)
Construct a MutableArrayRef from a std::vector.
Definition: ArrayRef.h:345
constexpr MutableArrayRef(T(&Arr)[N])
Construct a MutableArrayRef from a C array.
Definition: ArrayRef.h:355
MutableArrayRef(SmallVectorImpl< T > &Vec)
Construct a MutableArrayRef from a SmallVector.
Definition: ArrayRef.h:341
MutableArrayRef< T > drop_back(size_t N=1) const
Definition: ArrayRef.h:395
MutableArrayRef< T > take_while(PredicateT Pred) const
Return the first N elements of this Array that satisfy the given predicate.
Definition: ArrayRef.h:431
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:379
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:403
reverse_iterator rend() const
Definition: ArrayRef.h:363
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:410
MutableArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition: ArrayRef.h:415
MutableArrayRef(std::nullopt_t)
Construct an empty MutableArrayRef from std::nullopt.
Definition: ArrayRef.h:328
std::reverse_iterator< iterator > reverse_iterator
Definition: ArrayRef.h:319
This is a MutableArrayRef that owns its array.
Definition: ArrayRef.h:452
OwningArrayRef & operator=(OwningArrayRef &&Other)
Definition: ArrayRef.h:464
OwningArrayRef(OwningArrayRef &&Other)
Definition: ArrayRef.h:462
OwningArrayRef()=default
OwningArrayRef(ArrayRef< T > Data)
Definition: ArrayRef.h:457
OwningArrayRef(size_t Size)
Definition: ArrayRef.h:455
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
This is the part of SmallVectorTemplateBase which does not depend on whether the type T is a POD.
Definition: SmallVector.h:121
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
An opaque object representing a hash code.
Definition: Hashing.h:75
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Length
Definition: DWP.cpp:480
hash_code hash_value(const FixedPointSemantics &Val)
Definition: APFixedPoint.h:136
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.
Definition: STLExtras.h:1697
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:2082
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
auto find_if_not(R &&Range, UnaryPredicate P)
Definition: STLExtras.h:1771
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
@ Other
Any other memory.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1766
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Definition: Hashing.h:468
#define N
static bool isEqual(ArrayRef< T > LHS, ArrayRef< T > RHS)
Definition: ArrayRef.h:588
static ArrayRef< T > getTombstoneKey()
Definition: ArrayRef.h:575
static unsigned getHashValue(ArrayRef< T > Val)
Definition: ArrayRef.h:580
static ArrayRef< T > getEmptyKey()
Definition: ArrayRef.h:570
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:52