9#ifndef LLVM_ADT_ARRAYREF_H
10#define LLVM_ADT_ARRAYREF_H
20#include <initializer_list>
57 const T *Data =
nullptr;
75 : Data(&OneElt),
Length(1) {}
84 : Data(begin),
Length(end - begin) {
92 typename = std::enable_if_t<
95 decltype(std::declval<const C &>().data()) *,
97 std::is_integral<
decltype(std::declval<const C &>().size())>>,
100 : Data(V.data()),
Length(V.size()) {}
108#if LLVM_GNUC_PREREQ(9, 0, 0)
112#pragma GCC diagnostic push
113#pragma GCC diagnostic ignored "-Winit-list-lifetime"
117 : Data(Vec.begin() == Vec.end() ? (
T *)nullptr : Vec.begin()),
119#if LLVM_GNUC_PREREQ(9, 0, 0)
120#pragma GCC diagnostic pop
126 template <
typename U,
typename = std::enable_if_t<
127 std::is_convertible_v<U *const *, T *const *>>>
144 const T *
data()
const {
return Data; }
163 const T &Ret = front();
164 *
this = drop_front();
170 const T &Ret = back();
177 T *Buff =
A.template Allocate<T>(
Length);
186 return std::equal(begin(), end(),
RHS.begin());
201 assert(
size() >=
N &&
"Dropping more elements than exist");
202 return slice(
N,
size() -
N);
207 assert(
size() >=
N &&
"Dropping more elements than exist");
208 return slice(0,
size() -
N);
227 return drop_back(
size() -
N);
234 return drop_front(
size() -
N);
261 template <
typename U>
262 std::enable_if_t<std::is_same<U, T>::value,
ArrayRef<T>> &
269 template <
typename U>
270 std::enable_if_t<std::is_same<U, T>::value,
ArrayRef<T>> &
276 std::vector<T>
vec()
const {
277 return std::vector<T>(Data, Data+
Length);
283 operator std::vector<T>()
const {
284 return std::vector<T>(Data, Data+
Length);
332 template <
typename C,
333 typename = std::enable_if_t<
336 decltype(std::declval<C &>().data()) *,
T *
const *>,
337 std::is_integral<
decltype(std::declval<C &>().size())>>,
368 *
this = drop_front();
382 assert(
N + M <= this->
size() &&
"Invalid specifier");
388 return slice(
N, this->
size() -
N);
393 assert(this->
size() >=
N &&
"Dropping more elements than exist");
394 return slice(
N, this->
size() -
N);
398 assert(this->
size() >=
N &&
"Dropping more elements than exist");
399 return slice(0, this->
size() -
N);
404 template <
class PredicateT>
411 template <
class PredicateT>
418 if (
N >= this->
size())
420 return drop_back(this->
size() -
N);
425 if (
N >= this->
size())
427 return drop_front(this->
size() -
N);
432 template <
class PredicateT>
439 template <
class PredicateT>
448 assert(Index < this->
size() &&
"Invalid index!");
461 std::copy(
Data.begin(),
Data.end(), this->begin());
467 delete[] this->
data();
491 template <
typename T,
unsigned N>
498 template <
typename T, std::
size_t N>
526 template <
class T,
unsigned N>
533 template <
class T, std::
size_t N>
537 template <
typename T,
size_t N>
549 template <
typename T>
554 template <
typename T>
559 template <
typename T>
564 template <
typename T>
566 return std::lexicographical_compare(
LHS.begin(),
LHS.end(),
RHS.begin(),
570 template <
typename T>
575 template <
typename T>
580 template <
typename T>
595 reinterpret_cast<const T *
>(~
static_cast<uintptr_t
>(0)),
size_t(0));
600 reinterpret_cast<const T *
>(~
static_cast<uintptr_t
>(1)),
size_t(0));
605 "Cannot hash the empty key!");
607 "Cannot hash the tombstone key!");
612 if (
RHS.data() == getEmptyKey().
data())
613 return LHS.data() == getEmptyKey().data();
614 if (
RHS.data() == getTombstoneKey().
data())
615 return LHS.data() == getTombstoneKey().data();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#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),...
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.
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
constexpr ArrayRef(std::initializer_list< T > Vec LLVM_LIFETIME_BOUND)
Construct an ArrayRef from a std::initializer_list.
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.
ArrayRef(const T &OneElt LLVM_LIFETIME_BOUND)
Construct an ArrayRef from a single element.
constexpr ArrayRef(const T *begin LLVM_LIFETIME_BOUND, const T *end)
Construct an ArrayRef from a range.
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.
const T & consume_back()
consume_back() - Returns the last element and drops it from ArrayRef.
std::reverse_iterator< iterator > reverse_iterator
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the 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.
constexpr ArrayRef(const T(&Arr LLVM_LIFETIME_BOUND)[N])
Construct an ArrayRef from a C array.
ArrayRef(const iterator_range< U * > &Range)
Construct an ArrayRef<T> from iterator_range<U*>.
constexpr ArrayRef(const T *data LLVM_LIFETIME_BOUND, size_t length)
Construct an ArrayRef from a pointer and length.
const T & operator[](size_t Index) const
LLVM_DEPRECATED("Use {} or ArrayRef<T>() instead", "{}") ArrayRef(std
Construct an empty ArrayRef from std::nullopt.
constexpr ArrayRef(const C &V)
Construct an ArrayRef from a type that has a data() method that returns a pointer convertible to cons...
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.
const T & consume_front()
consume_front() - Returns the first element and drops it from ArrayRef.
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.
T & consume_front()
consume_front() - Returns the first element and drops it from ArrayRef.
T & consume_back()
consume_back() - Returns the last element and drops it from ArrayRef.
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.
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.
constexpr MutableArrayRef(const C &V)
Construct a MutableArrayRef from a type that has a data() method that returns a pointer convertible t...
constexpr MutableArrayRef(T(&Arr)[N])
Construct a MutableArrayRef from a C array.
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.
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 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.
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 >
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)
Implement std::hash so that hash_code can be used in STL containers.
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...