14 #ifndef MLIR_SUPPORT_STLEXTRAS_H 15 #define MLIR_SUPPORT_STLEXTRAS_H 18 #include "llvm/ADT/STLExtras.h" 23 template <
typename RangeT>
24 using ValueOfRange =
typename std::remove_reference<decltype(
25 *std::begin(std::declval<RangeT &>()))>::type;
38 template <
typename ForwardIterator,
typename UnaryFunctor,
39 typename NullaryFunctor,
40 typename =
typename std::enable_if<
41 !std::is_constructible<StringRef, UnaryFunctor>::value &&
42 !std::is_constructible<StringRef, NullaryFunctor>::value>::type>
43 inline void interleave(ForwardIterator begin, ForwardIterator end,
44 UnaryFunctor each_fn, NullaryFunctor between_fn) {
49 for (; begin != end; ++begin) {
55 template <
typename Container,
typename UnaryFunctor,
typename NullaryFunctor,
56 typename =
typename std::enable_if<
57 !std::is_constructible<StringRef, UnaryFunctor>::value &&
58 !std::is_constructible<StringRef, NullaryFunctor>::value>::type>
59 inline void interleave(
const Container &c, UnaryFunctor each_fn,
60 NullaryFunctor between_fn) {
61 interleave(c.begin(), c.end(), each_fn, between_fn);
65 template <
typename Container,
typename UnaryFunctor,
typename raw_ostream,
67 inline void interleave(
const Container &c, raw_ostream &os,
68 UnaryFunctor each_fn,
const StringRef &separator) {
69 interleave(c.begin(), c.end(), each_fn, [&] { os << separator; });
71 template <
typename Container,
typename raw_ostream,
73 inline void interleave(
const Container &c, raw_ostream &os,
74 const StringRef &separator) {
76 c, os, [&](
const T &a) { os << a; }, separator);
79 template <
typename Container,
typename UnaryFunctor,
typename raw_ostream,
82 UnaryFunctor each_fn) {
85 template <
typename Container,
typename raw_ostream,
114 template <
typename...>
using void_t = void;
115 template <
class,
template <
class...>
class Op,
class... Args>
struct detector {
118 template <
template <
class...>
class Op,
class... Args>
124 template <
template <
class...>
class Op,
class... Args>
129 template <
typename Callable,
typename... Args>
131 decltype(std::declval<Callable &>()(std::declval<Args>()...));
134 template <
typename Callable,
typename... Args>
143 template <
typename DerivedT,
typename BaseT,
typename T,
144 typename PointerT = T *,
typename ReferenceT = T &>
146 :
public llvm::iterator_facade_base<DerivedT,
147 std::random_access_iterator_tag, T,
148 std::ptrdiff_t, PointerT, ReferenceT> {
151 assert(base == rhs.
base &&
"incompatible iterators");
152 return index - rhs.
index;
155 return base == rhs.
base && index == rhs.
index;
158 assert(base == rhs.
base &&
"incompatible iterators");
159 return index < rhs.
index;
163 this->index += offset;
164 return static_cast<DerivedT &
>(*this);
167 this->index -= offset;
168 return static_cast<DerivedT &
>(*this);
179 : base(base), index(index) {}
194 template <
typename DerivedT,
typename BaseT,
typename T,
195 typename PointerT = T *,
typename ReferenceT = T &>
203 PointerT, ReferenceT> {
207 return DerivedT::dereference_iterator(this->getBase(), this->getIndex());
211 iterator(BaseT owner, ptrdiff_t curIndex)
221 : base(DerivedT::offset_base(begin.getBase(), begin.getIndex())),
222 count(end.getIndex() - begin.getIndex()) {}
226 : base(base), count(count) {}
228 iterator
begin()
const {
return iterator(base, 0); }
229 iterator
end()
const {
return iterator(base, count); }
231 assert(index < size() &&
"invalid index for value range");
232 return DerivedT::dereference_iterator(base, index);
236 size_t size()
const {
return count; }
239 bool empty()
const {
return size() == 0; }
242 DerivedT
slice(
size_t n,
size_t m)
const {
243 assert(n + m <= size() &&
"invalid size specifiers");
244 return DerivedT(DerivedT::offset_base(base, n), m);
249 assert(size() >= n &&
"Dropping more elements than exist");
250 return slice(n, size() - n);
254 assert(size() >= n &&
"Dropping more elements than exist");
255 return DerivedT(base, size() - n);
260 return n < size() ? drop_back(size() - n)
261 :
static_cast<const DerivedT &
>(*this);
268 return {begin(), end()};
291 template <
typename DerivedT,
typename BaseT,
typename T,
292 typename PointerT = T *,
typename ReferenceT = T &>
295 DerivedT, std::pair<BaseT, ptrdiff_t>, T, PointerT, ReferenceT> {
298 : detail::indexed_accessor_range_base<
299 DerivedT, std::pair<BaseT, ptrdiff_t>, T, PointerT, ReferenceT>(
300 std::make_pair(base, startIndex), count) {}
302 DerivedT, std::pair<BaseT, ptrdiff_t>, T, PointerT,
303 ReferenceT>::indexed_accessor_range_base;
306 const BaseT &
getBase()
const {
return this->base.first; }
312 static std::pair<BaseT, ptrdiff_t>
313 offset_base(
const std::pair<BaseT, ptrdiff_t> &base, ptrdiff_t index) {
316 return std::make_pair(base.first, base.second + index);
322 return DerivedT::dereference(base.first, base.second + index);
328 return llvm::map_range(
329 std::forward<ContainerTy>(c),
330 [](decltype((*std::begin(c))) elt) -> decltype((elt.second)) {
337 auto it = std::begin(c), e = std::end(c);
338 return it != e && std::next(it) == e;
349 template <typename T, bool isClass = std::is_class<T>::value>
353 template <
typename ClassType,
typename ReturnType,
typename... Args>
356 enum { num_args =
sizeof...(Args) };
363 using arg_t =
typename std::tuple_element<i, std::tuple<Args...>>::type;
366 template <
typename ReturnType,
typename... Args>
369 enum { num_args =
sizeof...(Args) };
376 using arg_t =
typename std::tuple_element<i, std::tuple<Args...>>::type;
385 static inline unsigned llvm_combineHashValue(
unsigned a,
unsigned b) {
386 uint64_t key = (uint64_t)a << 32 | (uint64_t)b;
395 return (
unsigned)key;
410 template <
unsigned I>
412 using EltType =
typename std::tuple_element<I, Tuple>::type;
413 std::integral_constant<bool, I + 1 ==
sizeof...(Ts)> atEnd;
414 return llvm_combineHashValue(
416 getHashValueImpl<I + 1>(values, atEnd));
419 template <
unsigned I>
425 std::integral_constant<bool, 0 ==
sizeof...(Ts)> atEnd;
426 return getHashValueImpl<0>(values, atEnd);
429 template <
unsigned I>
431 using EltType =
typename std::tuple_element<I, Tuple>::type;
432 std::integral_constant<bool, I + 1 ==
sizeof...(Ts)> atEnd;
434 isEqualImpl<I + 1>(lhs, rhs, atEnd);
437 template <
unsigned I>
443 std::integral_constant<bool, 0 ==
sizeof...(Ts)> atEnd;
444 return isEqualImpl<0>(lhs, rhs, atEnd);
450 #endif // MLIR_SUPPORT_STLEXTRAS_H Definition: InferTypeOpInterface.cpp:20
static Tuple getEmptyKey()
Definition: STLExtras.h:402
typename std::tuple_element< i, std::tuple< Args... > >::type arg_t
The type of an argument to this function.
Definition: STLExtras.h:376
bool has_single_element(ContainerTy &&c)
Returns true of the given range only contains a single element.
Definition: STLExtras.h:336
Definition: STLExtras.h:293
ReturnType result_t
The result type of this function.
Definition: STLExtras.h:372
Definition: STLExtras.h:95
Definition: PassRegistry.cpp:413
DerivedT & operator+=(ptrdiff_t offset)
Definition: STLExtras.h:162
ptrdiff_t count
The size from the owning range.
Definition: STLExtras.h:280
indexed_accessor_iterator(BaseT base, ptrdiff_t index)
Definition: STLExtras.h:178
const BaseT & getBase() const
Returns the current base of the range.
Definition: STLExtras.h:306
Definition: STLExtras.h:350
static bool isEqual(const Tuple &lhs, const Tuple &rhs)
Definition: STLExtras.h:442
Definition: STLExtras.h:196
bool empty() const
Return if the range is empty.
Definition: STLExtras.h:239
typename std::tuple_element< i, std::tuple< Args... > >::type arg_t
The type of an argument to this function.
Definition: STLExtras.h:363
Definition: STLExtras.h:115
std::false_type value_t
Definition: STLExtras.h:116
BaseT base
Definition: STLExtras.h:180
BaseT base
The base that owns the provided range of values.
Definition: STLExtras.h:278
DerivedT take_front(size_t n=1) const
Take the first n elements.
Definition: STLExtras.h:259
ptrdiff_t getIndex() const
Returns the current index of the iterator.
Definition: STLExtras.h:172
static bool isEqualImpl(const Tuple &lhs, const Tuple &rhs, std::false_type)
Definition: STLExtras.h:430
DerivedT drop_front(size_t n=1) const
Drop the first n elements.
Definition: STLExtras.h:248
std::true_type value_t
Definition: STLExtras.h:120
static bool isEqualImpl(const Tuple &lhs, const Tuple &rhs, std::true_type)
Definition: STLExtras.h:438
indexed_accessor_range(BaseT base, ptrdiff_t startIndex, ptrdiff_t count)
Definition: STLExtras.h:297
bool operator<(const indexed_accessor_iterator &rhs) const
Definition: STLExtras.h:157
indexed_accessor_range_base(BaseT base, ptrdiff_t count)
Definition: STLExtras.h:225
typename detail::detector< void, Op, Args... >::value_t is_detected
Definition: STLExtras.h:125
Definition: StandardTypes.h:62
An iterator element of this range.
Definition: STLExtras.h:202
ReturnType result_t
The result type of this function.
Definition: STLExtras.h:359
void interleaveComma(const Container &c, raw_ostream &os, UnaryFunctor each_fn)
Definition: STLExtras.h:81
static unsigned getHashValueImpl(const Tuple &values, std::true_type)
Definition: STLExtras.h:420
iterator begin() const
Definition: STLExtras.h:228
static std::pair< BaseT, ptrdiff_t > offset_base(const std::pair< BaseT, ptrdiff_t > &base, ptrdiff_t index)
See detail::indexed_accessor_range_base for details.
Definition: STLExtras.h:313
ptrdiff_t getStartIndex() const
Returns the current start index of the range.
Definition: STLExtras.h:309
DerivedT & operator-=(ptrdiff_t offset)
Definition: STLExtras.h:166
indexed_accessor_range_base(iterator begin, iterator end)
Definition: STLExtras.h:220
Definition: STLExtras.h:145
mlir::edsc::intrinsics::ValueBuilder< SliceOp > slice
Definition: Intrinsics.h:24
ptrdiff_t index
Definition: STLExtras.h:181
auto make_second_range(ContainerTy &&c)
Given a container of pairs, return a range over the second elements.
Definition: STLExtras.h:327
void interleave(ForwardIterator begin, ForwardIterator end, UnaryFunctor each_fn, NullaryFunctor between_fn)
Definition: STLExtras.h:43
NestedPattern Op(FilterFunctionType filter)
Definition: NestedMatcher.cpp:111
ptrdiff_t operator-(const indexed_accessor_iterator &rhs) const
Definition: STLExtras.h:150
iterator end() const
Definition: STLExtras.h:229
decltype(std::declval< Callable & >()(std::declval< Args >()...)) is_invocable
Definition: STLExtras.h:131
void void_t
Definition: STLExtras.h:114
static ReferenceT dereference_iterator(const std::pair< BaseT, ptrdiff_t > &base, ptrdiff_t index)
See detail::indexed_accessor_range_base for details.
Definition: STLExtras.h:320
typename std::remove_reference< decltype(*std::begin(std::declval< RangeT & >()))>::type ValueOfRange
Definition: STLExtras.h:25
static ClassID * getID()
Definition: STLExtras.h:96
std::tuple< Ts... > Tuple
Definition: STLExtras.h:400
bool operator==(const indexed_accessor_iterator &rhs) const
Definition: STLExtras.h:154
static unsigned getHashValueImpl(const Tuple &values, std::false_type)
Definition: STLExtras.h:411
Definition: OpDefinition.h:949
size_t size() const
Return the size of this range.
Definition: STLExtras.h:236
ReferenceT operator*() const
Definition: STLExtras.h:206
indexed_accessor_range_base(const iterator_range< iterator > &range)
Definition: STLExtras.h:223
static unsigned getHashValue(const std::tuple< Ts... > &values)
Definition: STLExtras.h:424
is_detected< detail::is_invocable, Callable, Args... > is_invocable
Definition: STLExtras.h:135
mlir::edsc::intrinsics::ValueBuilder< RangeOp > range
Definition: Intrinsics.h:23
const BaseT & getBase() const
Returns the current base of the iterator.
Definition: STLExtras.h:175
DerivedT slice(size_t n, size_t m) const
Drop the first N elements, and keep M elements.
Definition: STLExtras.h:242
ReferenceT operator[](unsigned index) const
Definition: STLExtras.h:230
static Tuple getTombstoneKey()
Definition: STLExtras.h:406
DerivedT drop_back(size_t n=1) const
Drop the last n elements.
Definition: STLExtras.h:253