LLVM 17.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)
74 : Data(&OneElt), Length(1) {}
75
76 /// Construct an ArrayRef from a pointer and length.
77 constexpr /*implicit*/ ArrayRef(const T *data, size_t length)
78 : Data(data), Length(length) {}
79
80 /// Construct an ArrayRef from a range.
81 constexpr ArrayRef(const T *begin, const T *end)
82 : Data(begin), Length(end - begin) {}
83
84 /// Construct an ArrayRef from a SmallVector. This is templated in order to
85 /// avoid instantiating SmallVectorTemplateCommon<T> whenever we
86 /// copy-construct an ArrayRef.
87 template<typename U>
89 : Data(Vec.data()), Length(Vec.size()) {
90 }
91
92 /// Construct an ArrayRef from a std::vector.
93 template<typename A>
94 /*implicit*/ ArrayRef(const std::vector<T, A> &Vec)
95 : Data(Vec.data()), Length(Vec.size()) {}
96
97 /// Construct an ArrayRef from a std::array
98 template <size_t N>
99 /*implicit*/ constexpr ArrayRef(const std::array<T, N> &Arr)
100 : Data(Arr.data()), Length(N) {}
101
102 /// Construct an ArrayRef from a C array.
103 template <size_t N>
104 /*implicit*/ constexpr ArrayRef(const T (&Arr)[N]) : Data(Arr), Length(N) {}
105
106 /// Construct an ArrayRef from a std::initializer_list.
107#if LLVM_GNUC_PREREQ(9, 0, 0)
108// Disable gcc's warning in this constructor as it generates an enormous amount
109// of messages. Anyone using ArrayRef should already be aware of the fact that
110// it does not do lifetime extension.
111#pragma GCC diagnostic push
112#pragma GCC diagnostic ignored "-Winit-list-lifetime"
113#endif
114 constexpr /*implicit*/ ArrayRef(const std::initializer_list<T> &Vec)
115 : Data(Vec.begin() == Vec.end() ? (T *)nullptr : Vec.begin()),
116 Length(Vec.size()) {}
117#if LLVM_GNUC_PREREQ(9, 0, 0)
118#pragma GCC diagnostic pop
119#endif
120
121 /// Construct an ArrayRef<const T*> from ArrayRef<T*>. This uses SFINAE to
122 /// ensure that only ArrayRefs of pointers can be converted.
123 template <typename U>
125 std::enable_if_t<std::is_convertible<U *const *, T const *>::value>
126 * = nullptr)
127 : Data(A.data()), Length(A.size()) {}
128
129 /// Construct an ArrayRef<const T*> from a SmallVector<T*>. This is
130 /// templated in order to avoid instantiating SmallVectorTemplateCommon<T>
131 /// whenever we copy-construct an ArrayRef.
132 template <typename U, typename DummyT>
133 /*implicit*/ ArrayRef(
135 std::enable_if_t<std::is_convertible<U *const *, T const *>::value> * =
136 nullptr)
137 : Data(Vec.data()), Length(Vec.size()) {}
138
139 /// Construct an ArrayRef<const T*> from std::vector<T*>. This uses SFINAE
140 /// to ensure that only vectors of pointers can be converted.
141 template <typename U, typename A>
142 ArrayRef(const std::vector<U *, A> &Vec,
143 std::enable_if_t<std::is_convertible<U *const *, T const *>::value>
144 * = nullptr)
145 : Data(Vec.data()), Length(Vec.size()) {}
146
147 /// @}
148 /// @name Simple Operations
149 /// @{
150
151 iterator begin() const { return Data; }
152 iterator end() const { return Data + Length; }
153
154 reverse_iterator rbegin() const { return reverse_iterator(end()); }
155 reverse_iterator rend() const { return reverse_iterator(begin()); }
156
157 /// empty - Check if the array is empty.
158 bool empty() const { return Length == 0; }
159
160 const T *data() const { return Data; }
161
162 /// size - Get the array size.
163 size_t size() const { return Length; }
164
165 /// front - Get the first element.
166 const T &front() const {
167 assert(!empty());
168 return Data[0];
169 }
170
171 /// back - Get the last element.
172 const T &back() const {
173 assert(!empty());
174 return Data[Length-1];
175 }
176
177 // copy - Allocate copy in Allocator and return ArrayRef<T> to it.
178 template <typename Allocator> MutableArrayRef<T> copy(Allocator &A) {
179 T *Buff = A.template Allocate<T>(Length);
180 std::uninitialized_copy(begin(), end(), Buff);
181 return MutableArrayRef<T>(Buff, Length);
182 }
183
184 /// equals - Check for element-wise equality.
185 bool equals(ArrayRef RHS) const {
186 if (Length != RHS.Length)
187 return false;
188 return std::equal(begin(), end(), RHS.begin());
189 }
190
191 /// slice(n, m) - Chop off the first N elements of the array, and keep M
192 /// elements in the array.
193 ArrayRef<T> slice(size_t N, size_t M) const {
194 assert(N+M <= size() && "Invalid specifier");
195 return ArrayRef<T>(data()+N, M);
196 }
197
198 /// slice(n) - Chop off the first N elements of the array.
199 ArrayRef<T> slice(size_t N) const { return slice(N, size() - N); }
200
201 /// Drop the first \p N elements of the array.
202 ArrayRef<T> drop_front(size_t N = 1) const {
203 assert(size() >= N && "Dropping more elements than exist");
204 return slice(N, size() - N);
205 }
206
207 /// Drop the last \p N elements of the array.
208 ArrayRef<T> drop_back(size_t N = 1) const {
209 assert(size() >= N && "Dropping more elements than exist");
210 return slice(0, size() - N);
211 }
212
213 /// Return a copy of *this with the first N elements satisfying the
214 /// given predicate removed.
215 template <class PredicateT> ArrayRef<T> drop_while(PredicateT Pred) const {
216 return ArrayRef<T>(find_if_not(*this, Pred), end());
217 }
218
219 /// Return a copy of *this with the first N elements not satisfying
220 /// the given predicate removed.
221 template <class PredicateT> ArrayRef<T> drop_until(PredicateT Pred) const {
222 return ArrayRef<T>(find_if(*this, Pred), end());
223 }
224
225 /// Return a copy of *this with only the first \p N elements.
226 ArrayRef<T> take_front(size_t N = 1) const {
227 if (N >= size())
228 return *this;
229 return drop_back(size() - N);
230 }
231
232 /// Return a copy of *this with only the last \p N elements.
233 ArrayRef<T> take_back(size_t N = 1) const {
234 if (N >= size())
235 return *this;
236 return drop_front(size() - N);
237 }
238
239 /// Return the first N elements of this Array that satisfy the given
240 /// predicate.
241 template <class PredicateT> ArrayRef<T> take_while(PredicateT Pred) const {
242 return ArrayRef<T>(begin(), find_if_not(*this, Pred));
243 }
244
245 /// Return the first N elements of this Array that don't satisfy the
246 /// given predicate.
247 template <class PredicateT> ArrayRef<T> take_until(PredicateT Pred) const {
248 return ArrayRef<T>(begin(), find_if(*this, Pred));
249 }
250
251 /// @}
252 /// @name Operator Overloads
253 /// @{
254 const T &operator[](size_t Index) const {
255 assert(Index < Length && "Invalid index!");
256 return Data[Index];
257 }
258
259 /// Disallow accidental assignment from a temporary.
260 ///
261 /// The declaration here is extra complicated so that "arrayRef = {}"
262 /// continues to select the move assignment operator.
263 template <typename U>
264 std::enable_if_t<std::is_same<U, T>::value, ArrayRef<T>> &
265 operator=(U &&Temporary) = delete;
266
267 /// Disallow accidental assignment from a temporary.
268 ///
269 /// The declaration here is extra complicated so that "arrayRef = {}"
270 /// continues to select the move assignment operator.
271 template <typename U>
272 std::enable_if_t<std::is_same<U, T>::value, ArrayRef<T>> &
273 operator=(std::initializer_list<U>) = delete;
274
275 /// @}
276 /// @name Expensive Operations
277 /// @{
278 std::vector<T> vec() const {
279 return std::vector<T>(Data, Data+Length);
280 }
281
282 /// @}
283 /// @name Conversion operators
284 /// @{
285 operator std::vector<T>() const {
286 return std::vector<T>(Data, Data+Length);
287 }
288
289 /// @}
290 };
291
292 /// MutableArrayRef - Represent a mutable reference to an array (0 or more
293 /// elements consecutively in memory), i.e. a start pointer and a length. It
294 /// allows various APIs to take and modify consecutive elements easily and
295 /// conveniently.
296 ///
297 /// This class does not own the underlying data, it is expected to be used in
298 /// situations where the data resides in some other buffer, whose lifetime
299 /// extends past that of the MutableArrayRef. For this reason, it is not in
300 /// general safe to store a MutableArrayRef.
301 ///
302 /// This is intended to be trivially copyable, so it should be passed by
303 /// value.
304 template<typename T>
305 class [[nodiscard]] MutableArrayRef : public ArrayRef<T> {
306 public:
307 using value_type = T;
309 using const_pointer = const value_type *;
314 using reverse_iterator = std::reverse_iterator<iterator>;
315 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
316 using size_type = size_t;
318
319 /// Construct an empty MutableArrayRef.
320 /*implicit*/ MutableArrayRef() = default;
321
322 /// Construct an empty MutableArrayRef from std::nullopt.
323 /*implicit*/ MutableArrayRef(std::nullopt_t) : ArrayRef<T>() {}
324
325 /// Construct a MutableArrayRef from a single element.
326 /*implicit*/ MutableArrayRef(T &OneElt) : ArrayRef<T>(OneElt) {}
327
328 /// Construct a MutableArrayRef from a pointer and length.
329 /*implicit*/ MutableArrayRef(T *data, size_t length)
330 : ArrayRef<T>(data, length) {}
331
332 /// Construct a MutableArrayRef from a range.
333 MutableArrayRef(T *begin, T *end) : ArrayRef<T>(begin, end) {}
334
335 /// Construct a MutableArrayRef from a SmallVector.
337 : ArrayRef<T>(Vec) {}
338
339 /// Construct a MutableArrayRef from a std::vector.
340 /*implicit*/ MutableArrayRef(std::vector<T> &Vec)
341 : ArrayRef<T>(Vec) {}
342
343 /// Construct a MutableArrayRef from a std::array
344 template <size_t N>
345 /*implicit*/ constexpr MutableArrayRef(std::array<T, N> &Arr)
346 : ArrayRef<T>(Arr) {}
347
348 /// Construct a MutableArrayRef from a C array.
349 template <size_t N>
350 /*implicit*/ constexpr MutableArrayRef(T (&Arr)[N]) : ArrayRef<T>(Arr) {}
351
352 T *data() const { return const_cast<T*>(ArrayRef<T>::data()); }
353
354 iterator begin() const { return data(); }
355 iterator end() const { return data() + this->size(); }
356
357 reverse_iterator rbegin() const { return reverse_iterator(end()); }
358 reverse_iterator rend() const { return reverse_iterator(begin()); }
359
360 /// front - Get the first element.
361 T &front() const {
362 assert(!this->empty());
363 return data()[0];
364 }
365
366 /// back - Get the last element.
367 T &back() const {
368 assert(!this->empty());
369 return data()[this->size()-1];
370 }
371
372 /// slice(n, m) - Chop off the first N elements of the array, and keep M
373 /// elements in the array.
374 MutableArrayRef<T> slice(size_t N, size_t M) const {
375 assert(N + M <= this->size() && "Invalid specifier");
376 return MutableArrayRef<T>(this->data() + N, M);
377 }
378
379 /// slice(n) - Chop off the first N elements of the array.
380 MutableArrayRef<T> slice(size_t N) const {
381 return slice(N, this->size() - N);
382 }
383
384 /// Drop the first \p N elements of the array.
385 MutableArrayRef<T> drop_front(size_t N = 1) const {
386 assert(this->size() >= N && "Dropping more elements than exist");
387 return slice(N, this->size() - N);
388 }
389
390 MutableArrayRef<T> drop_back(size_t N = 1) const {
391 assert(this->size() >= N && "Dropping more elements than exist");
392 return slice(0, this->size() - N);
393 }
394
395 /// Return a copy of *this with the first N elements satisfying the
396 /// given predicate removed.
397 template <class PredicateT>
399 return MutableArrayRef<T>(find_if_not(*this, Pred), end());
400 }
401
402 /// Return a copy of *this with the first N elements not satisfying
403 /// the given predicate removed.
404 template <class PredicateT>
406 return MutableArrayRef<T>(find_if(*this, Pred), end());
407 }
408
409 /// Return a copy of *this with only the first \p N elements.
410 MutableArrayRef<T> take_front(size_t N = 1) const {
411 if (N >= this->size())
412 return *this;
413 return drop_back(this->size() - N);
414 }
415
416 /// Return a copy of *this with only the last \p N elements.
417 MutableArrayRef<T> take_back(size_t N = 1) const {
418 if (N >= this->size())
419 return *this;
420 return drop_front(this->size() - N);
421 }
422
423 /// Return the first N elements of this Array that satisfy the given
424 /// predicate.
425 template <class PredicateT>
427 return MutableArrayRef<T>(begin(), find_if_not(*this, Pred));
428 }
429
430 /// Return the first N elements of this Array that don't satisfy the
431 /// given predicate.
432 template <class PredicateT>
434 return MutableArrayRef<T>(begin(), find_if(*this, Pred));
435 }
436
437 /// @}
438 /// @name Operator Overloads
439 /// @{
440 T &operator[](size_t Index) const {
441 assert(Index < this->size() && "Invalid index!");
442 return data()[Index];
443 }
444 };
445
446 /// This is a MutableArrayRef that owns its array.
447 template <typename T> class OwningArrayRef : public MutableArrayRef<T> {
448 public:
449 OwningArrayRef() = default;
451
453 : MutableArrayRef<T>(new T[Data.size()], Data.size()) {
454 std::copy(Data.begin(), Data.end(), this->begin());
455 }
456
457 OwningArrayRef(OwningArrayRef &&Other) { *this = std::move(Other); }
458
460 delete[] this->data();
462 Other.MutableArrayRef<T>::operator=(MutableArrayRef<T>());
463 return *this;
464 }
465
466 ~OwningArrayRef() { delete[] this->data(); }
467 };
468
469 /// @name ArrayRef Deduction guides
470 /// @{
471 /// Deduction guide to construct an ArrayRef from a single element.
472 template <typename T> ArrayRef(const T &OneElt) -> ArrayRef<T>;
473
474 /// Deduction guide to construct an ArrayRef from a pointer and length
475 template <typename T> ArrayRef(const T *data, size_t length) -> ArrayRef<T>;
476
477 /// Deduction guide to construct an ArrayRef from a range
478 template <typename T> ArrayRef(const T *data, const T *end) -> ArrayRef<T>;
479
480 /// Deduction guide to construct an ArrayRef from a SmallVector
481 template <typename T> ArrayRef(const SmallVectorImpl<T> &Vec) -> ArrayRef<T>;
482
483 /// Deduction guide to construct an ArrayRef from a SmallVector
484 template <typename T, unsigned N>
486
487 /// Deduction guide to construct an ArrayRef from a std::vector
488 template <typename T> ArrayRef(const std::vector<T> &Vec) -> ArrayRef<T>;
489
490 /// Deduction guide to construct an ArrayRef from a std::array
491 template <typename T, std::size_t N>
492 ArrayRef(const std::array<T, N> &Vec) -> ArrayRef<T>;
493
494 /// Deduction guide to construct an ArrayRef from an ArrayRef (const)
495 template <typename T> ArrayRef(const ArrayRef<T> &Vec) -> ArrayRef<T>;
496
497 /// Deduction guide to construct an ArrayRef from an ArrayRef
498 template <typename T> ArrayRef(ArrayRef<T> &Vec) -> ArrayRef<T>;
499
500 /// Deduction guide to construct an ArrayRef from a C array.
501 template <typename T, size_t N> ArrayRef(const T (&Arr)[N]) -> ArrayRef<T>;
502
503 /// @}
504
505 /// @name ArrayRef Convenience constructors
506 /// @{
507 /// Construct an ArrayRef from a single element.
508 template <typename T>
509 LLVM_DEPRECATED("Use deduction guide instead", "ArrayRef")
511 return OneElt;
512 }
513
514 /// Construct an ArrayRef from a pointer and length.
515 template <typename T>
516 LLVM_DEPRECATED("Use deduction guide instead", "ArrayRef")
517 ArrayRef<T> makeArrayRef(const T *data, size_t length) {
518 return ArrayRef<T>(data, length);
519 }
520
521 /// Construct an ArrayRef from a range.
522 template <typename T>
523 LLVM_DEPRECATED("Use deduction guide instead", "ArrayRef")
525 return ArrayRef<T>(begin, end);
526 }
527
528 /// Construct an ArrayRef from a SmallVector.
529 template <typename T>
530 LLVM_DEPRECATED("Use deduction guide instead", "ArrayRef")
532 return Vec;
533 }
534
535 /// Construct an ArrayRef from a SmallVector.
536 template <typename T, unsigned N>
537 LLVM_DEPRECATED("Use deduction guide instead", "ArrayRef")
539 return Vec;
540 }
541
542 /// Construct an ArrayRef from a std::vector.
543 template <typename T>
544 LLVM_DEPRECATED("Use deduction guide instead", "ArrayRef")
545 ArrayRef<T> makeArrayRef(const std::vector<T> &Vec) {
546 return Vec;
547 }
548
549 /// Construct an ArrayRef from a std::array.
550 template <typename T, std::size_t N>
551 LLVM_DEPRECATED("Use deduction guide instead", "ArrayRef")
552 ArrayRef<T> makeArrayRef(const std::array<T, N> &Arr) {
553 return Arr;
554 }
555
556 /// Construct an ArrayRef from an ArrayRef (no-op) (const)
557 template <typename T>
558 LLVM_DEPRECATED("Use deduction guide instead", "ArrayRef")
560 return Vec;
561 }
562
563 /// Construct an ArrayRef from an ArrayRef (no-op)
564 template <typename T>
565 LLVM_DEPRECATED("Use deduction guide instead", "ArrayRef")
567 return Vec;
568 }
569
570 /// Construct an ArrayRef from a C array.
571 template <typename T, size_t N>
572 LLVM_DEPRECATED("Use deduction guide instead", "ArrayRef")
574 return ArrayRef<T>(Arr);
575 }
576
577 /// @name MutableArrayRef Deduction guides
578 /// @{
579 /// Deduction guide to construct a `MutableArrayRef` from a single element
580 template <class T> MutableArrayRef(T &OneElt) -> MutableArrayRef<T>;
581
582 /// Deduction guide to construct a `MutableArrayRef` from a pointer and
583 /// length.
584 template <class T>
585 MutableArrayRef(T *data, size_t length) -> MutableArrayRef<T>;
586
587 /// Deduction guide to construct a `MutableArrayRef` from a `SmallVector`.
588 template <class T>
590
591 template <class T, unsigned N>
593
594 /// Deduction guide to construct a `MutableArrayRef` from a `std::vector`.
595 template <class T> MutableArrayRef(std::vector<T> &Vec) -> MutableArrayRef<T>;
596
597 /// Deduction guide to construct a `MutableArrayRef` from a `std::array`.
598 template <class T, std::size_t N>
599 MutableArrayRef(std::array<T, N> &Vec) -> MutableArrayRef<T>;
600
601 /// Deduction guide to construct a `MutableArrayRef` from a C array.
602 template <typename T, size_t N>
604
605 /// @}
606
607 /// Construct a MutableArrayRef from a single element.
608 template <typename T>
609 LLVM_DEPRECATED("Use deduction guide instead", "MutableArrayRef")
611 return OneElt;
612 }
613
614 /// Construct a MutableArrayRef from a pointer and length.
615 template <typename T>
616 LLVM_DEPRECATED("Use deduction guide instead", "MutableArrayRef")
617 MutableArrayRef<T> makeMutableArrayRef(T *data, size_t length) {
618 return MutableArrayRef<T>(data, length);
619 }
620
621 /// Construct a MutableArrayRef from a SmallVector.
622 template <typename T>
623 LLVM_DEPRECATED("Use deduction guide instead", "MutableArrayRef")
625 return Vec;
626 }
627
628 /// Construct a MutableArrayRef from a SmallVector.
629 template <typename T, unsigned N>
630 LLVM_DEPRECATED("Use deduction guide instead", "MutableArrayRef")
632 return Vec;
633 }
634
635 /// Construct a MutableArrayRef from a std::vector.
636 template <typename T>
637 LLVM_DEPRECATED("Use deduction guide instead", "MutableArrayRef")
639 return Vec;
640 }
641
642 /// Construct a MutableArrayRef from a std::array.
643 template <typename T, std::size_t N>
644 LLVM_DEPRECATED("Use deduction guide instead", "MutableArrayRef")
646 return Arr;
647 }
648
649 /// Construct a MutableArrayRef from a MutableArrayRef (no-op) (const)
650 template <typename T>
651 LLVM_DEPRECATED("Use deduction guide instead", "MutableArrayRef")
653 return Vec;
654 }
655
656 /// Construct a MutableArrayRef from a C array.
657 template <typename T, size_t N>
658 LLVM_DEPRECATED("Use deduction guide instead", "MutableArrayRef")
660 return MutableArrayRef<T>(Arr);
661 }
662
663 /// @}
664 /// @name ArrayRef Comparison Operators
665 /// @{
666
667 template<typename T>
669 return LHS.equals(RHS);
670 }
671
672 template <typename T>
674 return ArrayRef<T>(LHS).equals(RHS);
675 }
676
677 template <typename T>
679 return !(LHS == RHS);
680 }
681
682 template <typename T>
684 return !(LHS == RHS);
685 }
686
687 /// @}
688
689 template <typename T> hash_code hash_value(ArrayRef<T> S) {
690 return hash_combine_range(S.begin(), S.end());
691 }
692
693 // Provide DenseMapInfo for ArrayRefs.
694 template <typename T> struct DenseMapInfo<ArrayRef<T>, void> {
695 static inline ArrayRef<T> getEmptyKey() {
696 return ArrayRef<T>(
697 reinterpret_cast<const T *>(~static_cast<uintptr_t>(0)), size_t(0));
698 }
699
700 static inline ArrayRef<T> getTombstoneKey() {
701 return ArrayRef<T>(
702 reinterpret_cast<const T *>(~static_cast<uintptr_t>(1)), size_t(0));
703 }
704
705 static unsigned getHashValue(ArrayRef<T> Val) {
706 assert(Val.data() != getEmptyKey().data() &&
707 "Cannot hash the empty key!");
708 assert(Val.data() != getTombstoneKey().data() &&
709 "Cannot hash the tombstone key!");
710 return (unsigned)(hash_value(Val));
711 }
712
714 if (RHS.data() == getEmptyKey().data())
715 return LHS.data() == getEmptyKey().data();
716 if (RHS.data() == getTombstoneKey().data())
717 return LHS.data() == getTombstoneKey().data();
718 return LHS == RHS;
719 }
720 };
721
722} // end namespace llvm
723
724#endif // LLVM_ADT_ARRAYREF_H
aarch64 promote const
Replace within non kernel function use of LDS with pointer
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DEPRECATED(MSG, FIX)
Definition: Compiler.h:145
#define LLVM_GSL_POINTER
LLVM_GSL_POINTER - Apply this to non-owning classes like StringRef to enable lifetime warnings.
Definition: Compiler.h:295
uint32_t Index
uint64_t Size
#define T
return ToRemove size() > 0
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
constexpr ArrayRef(const T(&Arr)[N])
Construct an ArrayRef from a C array.
Definition: ArrayRef.h:104
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:278
bool equals(ArrayRef RHS) const
equals - Check for element-wise equality.
Definition: ArrayRef.h:185
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:215
const T & back() const
back - Get the last element.
Definition: ArrayRef.h:172
constexpr ArrayRef(const T *data, size_t length)
Construct an ArrayRef from a pointer and length.
Definition: ArrayRef.h:77
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:142
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition: ArrayRef.h:226
ArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:73
MutableArrayRef< T > copy(Allocator &A)
Definition: ArrayRef.h:178
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:202
ArrayRef< T > slice(size_t N) const
slice(n) - Chop off the first N elements of the array.
Definition: ArrayRef.h:199
reverse_iterator rend() const
Definition: ArrayRef.h:155
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:166
ArrayRef< T > take_while(PredicateT Pred) const
Return the first N elements of this Array that satisfy the given predicate.
Definition: ArrayRef.h:241
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: ArrayRef.h:51
iterator end() const
Definition: ArrayRef.h:152
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:247
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:221
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:163
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:124
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:208
iterator begin() const
Definition: ArrayRef.h:151
constexpr ArrayRef(const std::array< T, N > &Arr)
Construct an ArrayRef from a std::array.
Definition: ArrayRef.h:99
ArrayRef< T > take_back(size_t N=1) const
Return a copy of *this with only the last N elements.
Definition: ArrayRef.h:233
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:158
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:133
const T & operator[](size_t Index) const
Definition: ArrayRef.h:254
constexpr ArrayRef(const std::initializer_list< T > &Vec)
Construct an ArrayRef from a std::initializer_list.
Definition: ArrayRef.h:114
ArrayRef(const std::vector< T, A > &Vec)
Construct an ArrayRef from a std::vector.
Definition: ArrayRef.h:94
const T * data() const
Definition: ArrayRef.h:160
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:154
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:193
constexpr ArrayRef(const T *begin, const T *end)
Construct an ArrayRef from a range.
Definition: ArrayRef.h:81
ArrayRef(const SmallVectorTemplateCommon< T, U > &Vec)
Construct an ArrayRef from a SmallVector.
Definition: ArrayRef.h:88
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:305
T * data() const
Definition: ArrayRef.h:352
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:433
MutableArrayRef(T &OneElt)
Construct a MutableArrayRef from a single element.
Definition: ArrayRef.h:326
MutableArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:385
MutableArrayRef< T > take_back(size_t N=1) const
Return a copy of *this with only the last N elements.
Definition: ArrayRef.h:417
reverse_iterator rbegin() const
Definition: ArrayRef.h:357
MutableArrayRef(T *begin, T *end)
Construct a MutableArrayRef from a range.
Definition: ArrayRef.h:333
MutableArrayRef< T > slice(size_t N) const
slice(n) - Chop off the first N elements of the array.
Definition: ArrayRef.h:380
MutableArrayRef(T *data, size_t length)
Construct a MutableArrayRef from a pointer and length.
Definition: ArrayRef.h:329
MutableArrayRef()=default
Construct an empty MutableArrayRef.
constexpr MutableArrayRef(std::array< T, N > &Arr)
Construct a MutableArrayRef from a std::array.
Definition: ArrayRef.h:345
T & front() const
front - Get the first element.
Definition: ArrayRef.h:361
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: ArrayRef.h:315
iterator end() const
Definition: ArrayRef.h:355
iterator begin() const
Definition: ArrayRef.h:354
T & operator[](size_t Index) const
Definition: ArrayRef.h:440
T & back() const
back - Get the last element.
Definition: ArrayRef.h:367
MutableArrayRef(std::vector< T > &Vec)
Construct a MutableArrayRef from a std::vector.
Definition: ArrayRef.h:340
constexpr MutableArrayRef(T(&Arr)[N])
Construct a MutableArrayRef from a C array.
Definition: ArrayRef.h:350
MutableArrayRef(SmallVectorImpl< T > &Vec)
Construct a MutableArrayRef from a SmallVector.
Definition: ArrayRef.h:336
MutableArrayRef< T > drop_back(size_t N=1) const
Definition: ArrayRef.h:390
MutableArrayRef< T > take_while(PredicateT Pred) const
Return the first N elements of this Array that satisfy the given predicate.
Definition: ArrayRef.h:426
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:374
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:398
reverse_iterator rend() const
Definition: ArrayRef.h:358
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:405
MutableArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition: ArrayRef.h:410
MutableArrayRef(std::nullopt_t)
Construct an empty MutableArrayRef from std::nullopt.
Definition: ArrayRef.h:323
std::reverse_iterator< iterator > reverse_iterator
Definition: ArrayRef.h:314
This is a MutableArrayRef that owns its array.
Definition: ArrayRef.h:447
OwningArrayRef & operator=(OwningArrayRef &&Other)
Definition: ArrayRef.h:459
OwningArrayRef(OwningArrayRef &&Other)
Definition: ArrayRef.h:457
OwningArrayRef()=default
OwningArrayRef(ArrayRef< T > Data)
Definition: ArrayRef.h:452
OwningArrayRef(size_t Size)
Definition: ArrayRef.h:450
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
This is the part of SmallVectorTemplateBase which does not depend on whether the type T is a POD.
Definition: SmallVector.h:124
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
An opaque object representing a hash code.
Definition: Hashing.h:74
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Length
Definition: DWP.cpp:406
hash_code hash_value(const FixedPointSemantics &Val)
Definition: APFixedPoint.h:128
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:2040
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
auto find_if_not(R &&Range, UnaryPredicate P)
Definition: STLExtras.h:1767
ArrayRef< T > makeArrayRef(const T &OneElt)
Definition: ArrayRef.h:510
MutableArrayRef(T &OneElt) -> MutableArrayRef< 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.
Definition: STLExtras.h:1762
MutableArrayRef< T > makeMutableArrayRef(T &OneElt)
Construct a MutableArrayRef from a single element.
Definition: ArrayRef.h:610
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Definition: Hashing.h:486
Definition: BitVector.h:851
#define N
static bool isEqual(ArrayRef< T > LHS, ArrayRef< T > RHS)
Definition: ArrayRef.h:713
static ArrayRef< T > getTombstoneKey()
Definition: ArrayRef.h:700
static unsigned getHashValue(ArrayRef< T > Val)
Definition: ArrayRef.h:705
static ArrayRef< T > getEmptyKey()
Definition: ArrayRef.h:695
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:51