9#ifndef LLVM_ADT_ARRAYREF_H
10#define LLVM_ADT_ARRAYREF_H
20#include <initializer_list>
57 const T *Data =
nullptr;
74 : Data(&OneElt),
Length(1) {}
78 : Data(data),
Length(length) {}
82 : Data(begin),
Length(end - begin) {
102 : Data(Arr.data()),
Length(
N) {}
109#if LLVM_GNUC_PREREQ(9, 0, 0)
113#pragma GCC diagnostic push
114#pragma GCC diagnostic ignored "-Winit-list-lifetime"
116 constexpr ArrayRef(
const std::initializer_list<T> &Vec)
117 : Data(Vec.begin() == Vec.end() ? (
T *)nullptr : Vec.begin()),
119#if LLVM_GNUC_PREREQ(9, 0, 0)
120#pragma GCC diagnostic pop
125 template <
typename U>
127 std::enable_if_t<std::is_convertible<U *const *, T const *>::value>
134 template <
typename U,
typename DummyT>
137 std::enable_if_t<std::is_convertible<U *const *, T const *>::value> * =
143 template <
typename U,
typename A>
145 std::enable_if_t<std::is_convertible<U *const *, T const *>::value>
162 const T *
data()
const {
return Data; }
181 T *Buff =
A.template Allocate<T>(
Length);
182 std::uninitialized_copy(begin(), end(), Buff);
190 return std::equal(begin(), end(),
RHS.begin());
205 assert(
size() >=
N &&
"Dropping more elements than exist");
206 return slice(
N,
size() -
N);
211 assert(
size() >=
N &&
"Dropping more elements than exist");
212 return slice(0,
size() -
N);
231 return drop_back(
size() -
N);
238 return drop_front(
size() -
N);
265 template <
typename U>
266 std::enable_if_t<std::is_same<U, T>::value,
ArrayRef<T>> &
273 template <
typename U>
274 std::enable_if_t<std::is_same<U, T>::value,
ArrayRef<T>> &
280 std::vector<T>
vec()
const {
281 return std::vector<T>(Data, Data+
Length);
287 operator std::vector<T>()
const {
288 return std::vector<T>(Data, Data+
Length);
371 return data()[this->
size()-1];
377 assert(
N + M <= this->
size() &&
"Invalid specifier");
383 return slice(
N, this->
size() -
N);
388 assert(this->
size() >=
N &&
"Dropping more elements than exist");
389 return slice(
N, this->
size() -
N);
393 assert(this->
size() >=
N &&
"Dropping more elements than exist");
394 return slice(0, this->
size() -
N);
399 template <
class PredicateT>
406 template <
class PredicateT>
413 if (
N >= this->
size())
415 return drop_back(this->
size() -
N);
420 if (
N >= this->
size())
422 return drop_front(this->
size() -
N);
427 template <
class PredicateT>
434 template <
class PredicateT>
443 assert(Index < this->
size() &&
"Invalid index!");
444 return data()[
Index];
456 std::copy(Data.begin(), Data.end(), this->begin());
462 delete[] this->
data();
486 template <
typename T,
unsigned N>
493 template <
typename T, std::
size_t N>
521 template <
class T,
unsigned N>
528 template <
class T, std::
size_t N>
532 template <
typename T,
size_t N>
544 template <
typename T>
549 template <
typename T>
554 template <
typename T>
569 reinterpret_cast<const T *
>(~
static_cast<uintptr_t
>(0)),
size_t(0));
574 reinterpret_cast<const T *
>(~
static_cast<uintptr_t
>(1)),
size_t(0));
579 "Cannot hash the empty key!");
580 assert(Val.
data() != getTombstoneKey().data() &&
581 "Cannot hash the tombstone key!");
586 if (
RHS.data() == getEmptyKey().data())
587 return LHS.data() == getEmptyKey().data();
588 if (
RHS.data() == getTombstoneKey().data())
589 return LHS.data() == getTombstoneKey().data();
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_GSL_POINTER
LLVM_GSL_POINTER - Apply this to non-owning classes like StringRef to enable lifetime warnings.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
constexpr ArrayRef(const T(&Arr)[N])
Construct an ArrayRef from a C array.
std::enable_if_t< std::is_same< U, T >::value, ArrayRef< T > > & operator=(std::initializer_list< U >)=delete
Disallow accidental assignment from a temporary.
std::vector< T > vec() const
bool equals(ArrayRef RHS) const
equals - Check for element-wise equality.
ArrayRef< T > drop_while(PredicateT Pred) const
Return a copy of *this with the first N elements satisfying the given predicate removed.
const T & back() const
back - Get the last element.
constexpr ArrayRef(const T *data, size_t length)
Construct an ArrayRef from a pointer and length.
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*>.
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
ArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
MutableArrayRef< T > copy(Allocator &A)
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
ArrayRef< T > slice(size_t N) const
slice(n) - Chop off the first N elements of the array.
reverse_iterator rend() const
const T & front() const
front - Get the first element.
ArrayRef< T > take_while(PredicateT Pred) const
Return the first N elements of this Array that satisfy the given predicate.
std::reverse_iterator< const_iterator > const_reverse_iterator
ArrayRef< T > take_until(PredicateT Pred) const
Return the first N elements of this Array that don't satisfy the given predicate.
ArrayRef< T > drop_until(PredicateT Pred) const
Return a copy of *this with the first N elements not satisfying the given predicate removed.
size_t size() const
size - Get the array size.
ArrayRef()=default
Construct an empty ArrayRef.
ArrayRef(std::nullopt_t)
Construct an empty ArrayRef from std::nullopt.
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*>.
std::reverse_iterator< iterator > reverse_iterator
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
constexpr ArrayRef(const std::array< T, N > &Arr)
Construct an ArrayRef from a std::array.
ArrayRef< T > take_back(size_t N=1) const
Return a copy of *this with only the last N elements.
bool empty() const
empty - Check if the array is empty.
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*>.
const T & operator[](size_t Index) const
constexpr ArrayRef(const std::initializer_list< T > &Vec)
Construct an ArrayRef from a std::initializer_list.
ArrayRef(const std::vector< T, A > &Vec)
Construct an ArrayRef from a std::vector.
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
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.
constexpr ArrayRef(const T *begin, const T *end)
Construct an ArrayRef from a range.
ArrayRef(const SmallVectorTemplateCommon< T, U > &Vec)
Construct an ArrayRef from a SmallVector.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
MutableArrayRef< T > take_until(PredicateT Pred) const
Return the first N elements of this Array that don't satisfy the given predicate.
MutableArrayRef(T &OneElt)
Construct a MutableArrayRef from a single element.
MutableArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
MutableArrayRef< T > take_back(size_t N=1) const
Return a copy of *this with only the last N elements.
reverse_iterator rbegin() const
MutableArrayRef(T *begin, T *end)
Construct a MutableArrayRef from a range.
MutableArrayRef< T > slice(size_t N) const
slice(n) - Chop off the first N elements of the array.
MutableArrayRef(T *data, size_t length)
Construct a MutableArrayRef from a pointer and length.
MutableArrayRef()=default
Construct an empty MutableArrayRef.
constexpr MutableArrayRef(std::array< T, N > &Arr)
Construct a MutableArrayRef from a std::array.
T & front() const
front - Get the first element.
std::reverse_iterator< const_iterator > const_reverse_iterator
T & operator[](size_t Index) const
T & back() const
back - Get the last element.
MutableArrayRef(std::vector< T > &Vec)
Construct a MutableArrayRef from a std::vector.
constexpr MutableArrayRef(T(&Arr)[N])
Construct a MutableArrayRef from a C array.
MutableArrayRef(SmallVectorImpl< T > &Vec)
Construct a MutableArrayRef from a SmallVector.
MutableArrayRef< T > drop_back(size_t N=1) const
MutableArrayRef< T > take_while(PredicateT Pred) const
Return the first N elements of this Array that satisfy the given predicate.
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.
MutableArrayRef< T > drop_while(PredicateT Pred) const
Return a copy of *this with the first N elements satisfying the given predicate removed.
reverse_iterator rend() const
MutableArrayRef< T > drop_until(PredicateT Pred) const
Return a copy of *this with the first N elements not satisfying the given predicate removed.
MutableArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
MutableArrayRef(std::nullopt_t)
Construct an empty MutableArrayRef from std::nullopt.
std::reverse_iterator< iterator > reverse_iterator
This is a MutableArrayRef that owns its array.
OwningArrayRef & operator=(OwningArrayRef &&Other)
OwningArrayRef(OwningArrayRef &&Other)
OwningArrayRef(ArrayRef< T > Data)
OwningArrayRef(size_t Size)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is the part of SmallVectorTemplateBase which does not depend on whether the type T is a POD.
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.
This is an optimization pass for GlobalISel generic memory operations.
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==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
auto find_if_not(R &&Range, UnaryPredicate P)
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.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
static bool isEqual(ArrayRef< T > LHS, ArrayRef< T > RHS)
static ArrayRef< T > getTombstoneKey()
static unsigned getHashValue(ArrayRef< T > Val)
static ArrayRef< T > getEmptyKey()
An information struct used to provide DenseMap with the various necessary components for a given valu...