MLIR 23.0.0git
BuiltinAttributes.h
Go to the documentation of this file.
1//===- BuiltinAttributes.h - MLIR Builtin Attribute Classes -----*- 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 MLIR_IR_BUILTINATTRIBUTES_H
10#define MLIR_IR_BUILTINATTRIBUTES_H
11
14#include "llvm/ADT/APFloat.h"
15#include "llvm/ADT/Sequence.h"
16#include <optional>
17
18namespace mlir {
19class AffineMap;
20class AsmResourceBlob;
21class BoolAttr;
22class BuiltinDialect;
24template <typename T>
27class FunctionType;
28class IntegerSet;
29class IntegerType;
30class Location;
31class Operation;
32class RankedTensorType;
33
34namespace detail {
38} // namespace detail
39
40//===----------------------------------------------------------------------===//
41// Elements Attributes
42//===----------------------------------------------------------------------===//
43
44namespace detail {
45/// Pair of raw pointer and a boolean flag of whether the pointer holds a splat,
46using DenseIterPtrAndSplat = std::pair<const char *, bool>;
47
48/// Impl iterator for indexed DenseElementsAttr iterators that records a data
49/// pointer and data index that is adjusted for the case of a splat attribute.
50template <typename ConcreteT, typename T, typename PointerT = T *,
51 typename ReferenceT = T &>
53 : public llvm::indexed_accessor_iterator<ConcreteT, DenseIterPtrAndSplat, T,
54 PointerT, ReferenceT> {
55protected:
56 DenseElementIndexedIteratorImpl(const char *data, bool isSplat,
57 size_t dataIndex)
58 : llvm::indexed_accessor_iterator<ConcreteT, DenseIterPtrAndSplat, T,
59 PointerT, ReferenceT>({data, isSplat},
60 dataIndex) {}
61
62 /// Return the current index for this iterator, adjusted for the case of a
63 /// splat.
64 ptrdiff_t getDataIndex() const {
65 bool isSplat = this->base.second;
66 return isSplat ? 0 : this->index;
67 }
68
69 /// Return the data base pointer.
70 const char *getData() const { return this->base.first; }
71};
72
73/// Type trait detector that checks if a given type T is a complex type.
74template <typename T>
75struct is_complex_t : public std::false_type {};
76template <typename T>
77struct is_complex_t<std::complex<T>> : public std::true_type {};
78template <typename T>
79struct is_complex_t<mlir::NonFloatComplex<T>> : public std::true_type {};
80} // namespace detail
81
82/// An attribute that represents a reference to a dense vector or tensor
83/// object.
85public:
87
88 /// Allow implicit conversion to ElementsAttr.
89 operator ElementsAttr() const { return cast_if_present<ElementsAttr>(*this); }
90 /// Allow implicit conversion to TypedAttr.
91 operator TypedAttr() const { return ElementsAttr(*this); }
92
93 /// Type trait used to check if the given type T is a potentially valid C++
94 /// floating point type that can be used to access the underlying element
95 /// types of a DenseElementsAttr.
96 template <typename T>
98 /// The type is a valid floating point type if it is a builtin floating
99 /// point type, or is a potentially user defined floating point type. The
100 /// latter allows for supporting users that have custom types defined for
101 /// bfloat16/half/etc.
102 static constexpr bool value = llvm::is_one_of<T, float, double>::value ||
103 (std::numeric_limits<T>::is_specialized &&
104 !std::numeric_limits<T>::is_integer);
105 };
106
107 /// Method for support type inquiry through isa, cast and dyn_cast.
108 static bool classof(Attribute attr);
109
110 /// Constructs a dense elements attribute from an array of element values.
111 /// Each element attribute value is expected to be an element of 'type'.
112 /// 'type' must be a vector or tensor with static shape. If the element of
113 /// `type` is non-integer/index/float it is assumed to be a string type.
114 static DenseElementsAttr get(ShapedType type, ArrayRef<Attribute> values);
115
116 /// Constructs a dense integer elements attribute from an array of integer
117 /// or floating-point values. Each value is expected to be the same bitwidth
118 /// of the element type of 'type'. 'type' must be a vector or tensor with
119 /// static shape.
120 template <typename T,
121 typename = std::enable_if_t<std::numeric_limits<T>::is_integer ||
123 static DenseElementsAttr get(const ShapedType &type, ArrayRef<T> values) {
124 const char *data = reinterpret_cast<const char *>(values.data());
125 return getRawIntOrFloat(
126 type, ArrayRef<char>(data, values.size() * sizeof(T)), sizeof(T),
127 std::numeric_limits<T>::is_integer, std::numeric_limits<T>::is_signed);
128 }
129
130 /// Constructs a dense integer elements attribute from a single element.
131 template <typename T,
132 typename = std::enable_if_t<std::numeric_limits<T>::is_integer ||
135 static DenseElementsAttr get(const ShapedType &type, T value) {
136 return get(type, llvm::ArrayRef(value));
137 }
138
139 /// Constructs a dense complex elements attribute from an array of complex
140 /// values. Each value is expected to be the same bitwidth of the element type
141 /// of 'type'. 'type' must be a vector or tensor with static shape.
142 template <
143 typename T, typename ElementT = typename T::value_type,
144 typename = std::enable_if_t<detail::is_complex_t<T>::value &&
145 (std::numeric_limits<ElementT>::is_integer ||
147 static DenseElementsAttr get(const ShapedType &type, ArrayRef<T> values) {
148 const char *data = reinterpret_cast<const char *>(values.data());
149 return getRawComplex(type, ArrayRef<char>(data, values.size() * sizeof(T)),
150 sizeof(T), std::numeric_limits<ElementT>::is_integer,
151 std::numeric_limits<ElementT>::is_signed);
152 }
153
154 /// Overload of the above 'get' method that is specialized for boolean values.
155 static DenseElementsAttr get(ShapedType type, ArrayRef<bool> values);
156
157 /// Overload of the above 'get' method that is specialized for StringRef
158 /// values.
159 static DenseElementsAttr get(ShapedType type, ArrayRef<StringRef> values);
160
161 /// Constructs a dense integer elements attribute from an array of APInt
162 /// values. Each APInt value is expected to have the same bitwidth as the
163 /// element type of 'type'. 'type' must be a vector or tensor with static
164 /// shape.
165 static DenseElementsAttr get(ShapedType type, ArrayRef<APInt> values);
166
167 /// Constructs a dense complex elements attribute from an array of APInt
168 /// values. Each APInt value is expected to have the same bitwidth as the
169 /// element type of 'type'. 'type' must be a vector or tensor with static
170 /// shape.
171 static DenseElementsAttr get(ShapedType type,
173
174 /// Constructs a dense float elements attribute from an array of APFloat
175 /// values. Each APFloat value is expected to have the same bitwidth as the
176 /// element type of 'type'. 'type' must be a vector or tensor with static
177 /// shape.
178 static DenseElementsAttr get(ShapedType type, ArrayRef<APFloat> values);
179
180 /// Constructs a dense complex elements attribute from an array of APFloat
181 /// values. Each APFloat value is expected to have the same bitwidth as the
182 /// element type of 'type'. 'type' must be a vector or tensor with static
183 /// shape.
184 static DenseElementsAttr get(ShapedType type,
186
187 /// Construct a dense elements attribute for an initializer_list of values.
188 /// Each value is expected to be the same bitwidth of the element type of
189 /// 'type'. 'type' must be a vector or tensor with static shape.
190 template <typename T>
191 static DenseElementsAttr get(const ShapedType &type,
192 const std::initializer_list<T> &list) {
193 return get(type, ArrayRef<T>(list));
194 }
195
196 /// Construct a dense elements attribute from a raw buffer representing the
197 /// data for this attribute. Users are encouraged to use one of the
198 /// constructors above, which provide more safeties. However, this
199 /// constructor is useful for tools which may want to interop and can
200 /// follow the precise definition.
201 ///
202 /// The format of the raw buffer is a densely packed array of values that
203 /// can be bitcast to the storage format of the element type specified.
204 /// Types that are not byte aligned will be rounded up to the next byte.
205 static DenseElementsAttr getFromRawBuffer(ShapedType type,
206 ArrayRef<char> rawBuffer);
207
208 /// Returns true if the given buffer is a valid raw buffer for the given type.
209 static bool isValidRawBuffer(ShapedType type, ArrayRef<char> rawBuffer);
210
211 //===--------------------------------------------------------------------===//
212 // Iterators
213 //===--------------------------------------------------------------------===//
214
215 /// The iterator range over the given iterator type T.
216 template <typename IteratorT>
218
219 /// The iterator for the given element type T.
220 template <typename T, typename AttrT = DenseElementsAttr>
221 using iterator = decltype(std::declval<AttrT>().template value_begin<T>());
222 /// The iterator range over the given element T.
223 template <typename T, typename AttrT = DenseElementsAttr>
225 decltype(std::declval<AttrT>().template getValues<T>());
226
227 /// A utility iterator that allows walking over the internal Attribute values
228 /// of a DenseElementsAttr.
229 class AttributeElementIterator
230 : public llvm::indexed_accessor_iterator<AttributeElementIterator,
231 const void *, Attribute,
233 public:
234 /// Accesses the Attribute value at this iterator position.
235 Attribute operator*() const;
236
237 private:
238 friend DenseElementsAttr;
239
240 /// Constructs a new iterator.
241 AttributeElementIterator(DenseElementsAttr attr, size_t index);
242 };
243
244 /// Iterator for walking raw element values of the specified type 'T', which
245 /// may be any c++ data type matching the stored representation: int32_t,
246 /// float, etc.
247 template <typename T>
248 class ElementIterator
249 : public detail::DenseElementIndexedIteratorImpl<ElementIterator<T>,
250 const T> {
251 public:
252 /// Accesses the raw value at this iterator position.
253 const T &operator*() const {
254 return reinterpret_cast<const T *>(this->getData())[this->getDataIndex()];
255 }
256
257 private:
258 friend DenseElementsAttr;
259
260 /// Constructs a new iterator.
261 ElementIterator(const char *data, bool isSplat, size_t dataIndex)
263 data, isSplat, dataIndex) {}
264 };
265
266 /// A utility iterator that allows walking over the internal bool values.
267 class BoolElementIterator
268 : public detail::DenseElementIndexedIteratorImpl<BoolElementIterator,
269 bool, bool, bool> {
270 public:
271 /// Accesses the bool value at this iterator position.
272 bool operator*() const;
273
274 private:
275 friend DenseElementsAttr;
276
277 /// Constructs a new iterator.
278 BoolElementIterator(DenseElementsAttr attr, size_t dataIndex);
279 };
280
281 /// A utility iterator that allows walking over the internal raw APInt values.
282 class IntElementIterator
283 : public detail::DenseElementIndexedIteratorImpl<IntElementIterator,
284 APInt, APInt, APInt> {
285 public:
286 /// Accesses the raw APInt value at this iterator position.
287 APInt operator*() const;
288
289 private:
290 friend DenseElementsAttr;
291
292 /// Constructs a new iterator.
293 IntElementIterator(DenseElementsAttr attr, size_t dataIndex);
294
295 /// The bitwidth of the element type.
296 size_t bitWidth;
297 };
298
299 /// A utility iterator that allows walking over the internal raw complex APInt
300 /// values.
301 class ComplexIntElementIterator
303 ComplexIntElementIterator, mlir::Complex<APInt>,
304 mlir::Complex<APInt>, mlir::Complex<APInt>> {
305 public:
306 /// Accesses the raw mlir::Complex<APInt> value at this iterator position.
308
309 private:
310 friend DenseElementsAttr;
311
312 /// Constructs a new iterator.
313 ComplexIntElementIterator(DenseElementsAttr attr, size_t dataIndex);
314
315 /// The bitwidth of the element type.
316 size_t bitWidth;
317 };
318
319 /// Iterator for walking over APFloat values.
320 class FloatElementIterator final
321 : public llvm::mapped_iterator_base<FloatElementIterator,
322 IntElementIterator, APFloat> {
323 public:
324 /// Map the element to the iterator result type.
325 APFloat mapElement(const APInt &value) const {
326 return APFloat(*smt, value);
327 }
328
329 private:
330 friend DenseElementsAttr;
331
332 /// Initializes the float element iterator to the specified iterator.
333 FloatElementIterator(const llvm::fltSemantics &smt, IntElementIterator it)
334 : BaseT(it), smt(&smt) {}
335
336 /// The float semantics to use when constructing the APFloat.
337 const llvm::fltSemantics *smt;
338 };
339
340 /// Iterator for walking over complex APFloat values.
341 class ComplexFloatElementIterator final
342 : public llvm::mapped_iterator_base<ComplexFloatElementIterator,
343 ComplexIntElementIterator,
344 mlir::Complex<APFloat>> {
345 public:
346 /// Map the element to the iterator result type.
348 return {APFloat(*smt, value.real()), APFloat(*smt, value.imag())};
349 }
350
351 private:
352 friend DenseElementsAttr;
353
354 /// Initializes the float element iterator to the specified iterator.
355 ComplexFloatElementIterator(const llvm::fltSemantics &smt,
357 : BaseT(it), smt(&smt) {}
358
359 /// The float semantics to use when constructing the APFloat.
360 const llvm::fltSemantics *smt;
361 };
362
363 //===--------------------------------------------------------------------===//
364 // Value Querying
365 //===--------------------------------------------------------------------===//
366
367 /// Returns true if this attribute corresponds to a splat, i.e. if all element
368 /// values are the same.
369 bool isSplat() const;
370
371 /// Return the splat value for this attribute. This asserts that the attribute
372 /// corresponds to a splat.
373 template <typename T>
374 std::enable_if_t<!std::is_base_of<Attribute, T>::value ||
375 std::is_same<Attribute, T>::value,
376 T>
378 assert(isSplat() && "expected the attribute to be a splat");
379 return *value_begin<T>();
380 }
381 /// Return the splat value for derived attribute element types.
382 template <typename T>
383 std::enable_if_t<std::is_base_of<Attribute, T>::value &&
384 !std::is_same<Attribute, T>::value,
385 T>
387 return llvm::cast<T>(getSplatValue<Attribute>());
388 }
389
390 /// Try to get an iterator of the given type to the start of the held element
391 /// values. Return failure if the type cannot be iterated.
392 template <typename T>
393 auto try_value_begin() const {
394 auto range = tryGetValues<T>();
395 using iterator = decltype(range->begin());
396 return failed(range) ? FailureOr<iterator>(failure()) : range->begin();
397 }
398
399 /// Try to get an iterator of the given type to the end of the held element
400 /// values. Return failure if the type cannot be iterated.
401 template <typename T>
402 auto try_value_end() const {
403 auto range = tryGetValues<T>();
404 using iterator = decltype(range->begin());
405 return failed(range) ? FailureOr<iterator>(failure()) : range->end();
406 }
407
408 /// Return the held element values as a range of the given type.
409 template <typename T>
410 auto getValues() const {
411 auto range = tryGetValues<T>();
412 assert(succeeded(range) && "element type cannot be iterated");
413 return std::move(*range);
414 }
415
416 /// Get an iterator of the given type to the start of the held element values.
417 template <typename T>
418 auto value_begin() const {
419 return getValues<T>().begin();
420 }
421
422 /// Get an iterator of the given type to the end of the held element values.
423 template <typename T>
424 auto value_end() const {
425 return getValues<T>().end();
426 }
427
428 /// Try to get the held element values as a range of integer or floating-point
429 /// values.
430 template <typename T>
432 std::enable_if_t<(!std::is_same<T, bool>::value &&
433 std::numeric_limits<T>::is_integer) ||
435 template <typename T, typename = IntFloatValueTemplateCheckT<T>>
436 FailureOr<iterator_range_impl<ElementIterator<T>>> tryGetValues() const {
437 if (!isValidIntOrFloat(sizeof(T), std::numeric_limits<T>::is_integer,
438 std::numeric_limits<T>::is_signed))
439 return failure();
440 const char *rawData = getRawData().data();
441 bool splat = isSplat();
443 getType(), ElementIterator<T>(rawData, splat, 0),
444 ElementIterator<T>(rawData, splat, getNumElements()));
445 }
446
447 /// Try to get the held element values as a range of mlir::Complex.
448 template <typename T, typename ElementT>
450 std::enable_if_t<detail::is_complex_t<T>::value &&
451 (std::numeric_limits<ElementT>::is_integer ||
453 template <typename T, typename ElementT = typename T::value_type,
455 FailureOr<iterator_range_impl<ElementIterator<T>>> tryGetValues() const {
456 if (!isValidComplex(sizeof(T), std::numeric_limits<ElementT>::is_integer,
457 std::numeric_limits<ElementT>::is_signed))
458 return failure();
459 const char *rawData = getRawData().data();
460 bool splat = isSplat();
462 getType(), ElementIterator<T>(rawData, splat, 0),
463 ElementIterator<T>(rawData, splat, getNumElements()));
464 }
465
466 /// Try to get the held element values as a range of StringRef.
467 template <typename T>
469 std::enable_if_t<std::is_same<T, StringRef>::value>;
470 template <typename T, typename = StringRefValueTemplateCheckT<T>>
471 FailureOr<iterator_range_impl<ElementIterator<StringRef>>>
472 tryGetValues() const {
473 auto stringRefs = getRawStringData();
474 const char *ptr = reinterpret_cast<const char *>(stringRefs.data());
475 bool splat = isSplat();
479 }
480
481 /// Try to get the held element values as a range of Attributes.
482 template <typename T>
484 std::enable_if_t<std::is_same<T, Attribute>::value>;
485 template <typename T, typename = AttributeValueTemplateCheckT<T>>
486 FailureOr<iterator_range_impl<AttributeElementIterator>>
492
493 /// Try to get the held element values a range of T, where T is a derived
494 /// attribute type.
495 template <typename T>
497 std::enable_if_t<std::is_base_of<Attribute, T>::value &&
498 !std::is_same<Attribute, T>::value>;
499 template <typename T>
501 : public llvm::mapped_iterator_base<DerivedAttributeElementIterator<T>,
502 AttributeElementIterator, T> {
503 using llvm::mapped_iterator_base<DerivedAttributeElementIterator<T>,
505 T>::mapped_iterator_base;
506
507 /// Map the element to the iterator result type.
508 T mapElement(Attribute attr) const { return llvm::cast<T>(attr); }
509 };
510 template <typename T, typename = DerivedAttrValueTemplateCheckT<T>>
511 FailureOr<iterator_range_impl<DerivedAttributeElementIterator<T>>>
512 tryGetValues() const {
513 using DerivedIterT = DerivedAttributeElementIterator<T>;
515 getType(), DerivedIterT(value_begin<Attribute>()),
516 DerivedIterT(value_end<Attribute>()));
517 }
518
519 /// Try to get the held element values as a range of bool. The element type of
520 /// this attribute must be of integer type of bitwidth 1.
521 template <typename T>
523 std::enable_if_t<std::is_same<T, bool>::value>;
524 template <typename T, typename = BoolValueTemplateCheckT<T>>
525 FailureOr<iterator_range_impl<BoolElementIterator>> tryGetValues() const {
526 if (!isValidBool())
527 return failure();
529 getType(), BoolElementIterator(*this, 0),
531 }
532
533 /// Try to get the held element values as a range of APInts. The element type
534 /// of this attribute must be of integer type.
535 template <typename T>
537 std::enable_if_t<std::is_same<T, APInt>::value>;
538 template <typename T, typename = APIntValueTemplateCheckT<T>>
539 FailureOr<iterator_range_impl<IntElementIterator>> tryGetValues() const {
540 if (!getElementType().isIntOrIndex())
541 return failure();
543 raw_int_end());
544 }
545
546 /// Try to get the held element values as a range of complex APInts. The
547 /// element type of this attribute must be a complex of integer type.
548 template <typename T>
550 std::enable_if_t<std::is_same<T, mlir::Complex<APInt>>::value>;
551 template <typename T, typename = ComplexAPIntValueTemplateCheckT<T>>
552 FailureOr<iterator_range_impl<ComplexIntElementIterator>>
553 tryGetValues() const {
554 return tryGetComplexIntValues();
555 }
556
557 /// Try to get the held element values as a range of APFloat. The element type
558 /// of this attribute must be of float type.
559 template <typename T>
561 std::enable_if_t<std::is_same<T, APFloat>::value>;
562 template <typename T, typename = APFloatValueTemplateCheckT<T>>
563 FailureOr<iterator_range_impl<FloatElementIterator>> tryGetValues() const {
564 return tryGetFloatValues();
565 }
566
567 /// Try to get the held element values as a range of complex APFloat. The
568 /// element type of this attribute must be a complex of float type.
569 template <typename T>
571 std::enable_if_t<std::is_same<T, mlir::Complex<APFloat>>::value>;
572 template <typename T, typename = ComplexAPFloatValueTemplateCheckT<T>>
573 FailureOr<iterator_range_impl<ComplexFloatElementIterator>>
574 tryGetValues() const {
576 }
577
578 /// Return the raw storage data held by this attribute. Users should generally
579 /// not use this directly, as the internal storage format is not always in the
580 /// form the user might expect.
582
583 /// Return the raw StringRef data held by this attribute.
585
586 /// Return the type of this ElementsAttr, guaranteed to be a vector or tensor
587 /// with static shape.
588 ShapedType getType() const;
589
590 /// Return the element type of this DenseElementsAttr.
591 Type getElementType() const;
592
593 /// Returns the number of elements held by this attribute.
594 int64_t getNumElements() const;
595
596 /// Returns the number of elements held by this attribute.
597 int64_t size() const { return getNumElements(); }
598
599 /// Returns if the number of elements held by this attribute is 0.
600 bool empty() const { return size() == 0; }
601
602 //===--------------------------------------------------------------------===//
603 // Mutation Utilities
604 //===--------------------------------------------------------------------===//
605
606 /// Return a new DenseElementsAttr that has the same data as the current
607 /// attribute, but has been reshaped to 'newType'. The new type must have the
608 /// same total number of elements as well as element type.
609 DenseElementsAttr reshape(ShapedType newType);
610
611 /// Return a new DenseElementsAttr that has the same data as the current
612 /// attribute, but with a different shape for a splat type. The new type must
613 /// have the same element type.
614 DenseElementsAttr resizeSplat(ShapedType newType);
615
616 /// Return a new DenseElementsAttr that has the same data as the current
617 /// attribute, but has bitcast elements to 'newElType'. The new type must have
618 /// the same bitwidth as the current element type.
619 DenseElementsAttr bitcast(Type newElType);
620
621 /// Generates a new DenseElementsAttr by mapping each int value to a new
622 /// underlying APInt. The new values can represent either an integer or float.
623 /// This underlying type must be an DenseIntElementsAttr.
624 DenseElementsAttr mapValues(Type newElementType,
625 function_ref<APInt(const APInt &)> mapping) const;
626
627 /// Generates a new DenseElementsAttr by mapping each float value to a new
628 /// underlying APInt. the new values can represent either an integer or float.
629 /// This underlying type must be an DenseFPElementsAttr.
631 mapValues(Type newElementType,
632 function_ref<APInt(const APFloat &)> mapping) const;
633
634protected:
635 /// Iterators to various elements that require out-of-line definition. These
636 /// are hidden from the user to encourage consistent use of the
637 /// getValues/value_begin/value_end API.
639 return IntElementIterator(*this, 0);
640 }
644 FailureOr<iterator_range_impl<ComplexIntElementIterator>>
646 FailureOr<iterator_range_impl<FloatElementIterator>>
647 tryGetFloatValues() const;
648 FailureOr<iterator_range_impl<ComplexFloatElementIterator>>
650
651 /// Overload of the raw 'get' method that asserts that the given type is of
652 /// complex type. This method is used to verify type invariants that the
653 /// templatized 'get' method cannot.
654 static DenseElementsAttr getRawComplex(ShapedType type, ArrayRef<char> data,
655 int64_t dataEltSize, bool isInt,
656 bool isSigned);
657
658 /// Overload of the raw 'get' method that asserts that the given type is of
659 /// integer or floating-point type. This method is used to verify type
660 /// invariants that the templatized 'get' method cannot.
661 static DenseElementsAttr getRawIntOrFloat(ShapedType type,
662 ArrayRef<char> data,
663 int64_t dataEltSize, bool isInt,
664 bool isSigned);
665
666 /// Check the information for a C++ data type, check if this type is valid for
667 /// the current attribute. This method is used to verify specific type
668 /// invariants that the templatized 'getValues' method cannot.
669 bool isValidBool() const { return getElementType().isInteger(1); }
670 bool isValidIntOrFloat(int64_t dataEltSize, bool isInt, bool isSigned) const;
671 bool isValidComplex(int64_t dataEltSize, bool isInt, bool isSigned) const;
672};
673
674/// An attribute that represents a reference to a splat vector or tensor
675/// constant, meaning all of the elements have the same value.
677public:
678 using DenseElementsAttr::DenseElementsAttr;
679
680 /// Method for support type inquiry through isa, cast and dyn_cast.
681 static bool classof(Attribute attr) {
682 auto denseAttr = llvm::dyn_cast<DenseElementsAttr>(attr);
683 return denseAttr && denseAttr.isSplat();
684 }
685};
686
687//===----------------------------------------------------------------------===//
688// DenseResourceElementsAttr
689//===----------------------------------------------------------------------===//
690
692
693} // namespace mlir
694
695//===----------------------------------------------------------------------===//
696// Tablegen Attribute Declarations
697//===----------------------------------------------------------------------===//
698
699#define GET_ATTRDEF_CLASSES
700#include "mlir/IR/BuiltinAttributes.h.inc"
701
702//===----------------------------------------------------------------------===//
703// C++ Attribute Declarations
704//===----------------------------------------------------------------------===//
705
706namespace mlir {
707/// DenseIntOrFPElementsAttr was renamed to DenseTypedElementsAttr. This alias
708/// is provided for backwards compatibility. It will be removed in the future.
709using DenseIntOrFPElementsAttr [[deprecated(
710 "DenseIntOrFPElementsAttr has been renamed to DenseTypedElementsAttr")]] =
712
713//===----------------------------------------------------------------------===//
714// DenseArrayAttr
715//===----------------------------------------------------------------------===//
716
717namespace detail {
718/// Base class for DenseArrayAttr that is instantiated and specialized for each
719/// supported element type below.
720template <typename T>
721class DenseArrayAttrImpl : public DenseArrayAttr {
722public:
723 using DenseArrayAttr::DenseArrayAttr;
724
725 /// Implicit conversion to ArrayRef<T>.
726 operator ArrayRef<T>() const;
727 ArrayRef<T> asArrayRef() const { return ArrayRef<T>{*this}; }
728
729 /// Random access to elements.
730 T operator[](std::size_t index) const { return asArrayRef()[index]; }
731
732 /// Builder from ArrayRef<T>.
734
735 /// Print the short form `[42, 100, -1]` without any type prefix.
736 void print(AsmPrinter &printer) const;
737 void print(raw_ostream &os) const;
738 /// Print the short form `42, 100, -1` without any braces or type prefix.
740
741 /// Parse the short form `[42, 100, -1]` without any type prefix.
742 static Attribute parse(AsmParser &parser, Type type);
743
744 /// Parse the short form `42, 100, -1` without any type prefix or braces.
746
747 /// Support for isa<>/cast<>.
748 static bool classof(Attribute attr);
749};
750
751extern template class DenseArrayAttrImpl<bool>;
752extern template class DenseArrayAttrImpl<int8_t>;
753extern template class DenseArrayAttrImpl<int16_t>;
754extern template class DenseArrayAttrImpl<int32_t>;
755extern template class DenseArrayAttrImpl<int64_t>;
756extern template class DenseArrayAttrImpl<float>;
757extern template class DenseArrayAttrImpl<double>;
758} // namespace detail
759
760// Public name for all the supported DenseArrayAttr
768
769//===----------------------------------------------------------------------===//
770// DenseResourceElementsAttr
771//===----------------------------------------------------------------------===//
772
773namespace detail {
774/// Base class for DenseResourceElementsAttr that is instantiated and
775/// specialized for each supported element type below.
776template <typename T>
777class DenseResourceElementsAttrBase : public DenseResourceElementsAttr {
778public:
779 using DenseResourceElementsAttr::DenseResourceElementsAttr;
780
781 /// A builder that inserts a new resource using the provided blob. The handle
782 /// of the inserted blob is used when building the attribute. The provided
783 /// `blobName` is used as a hint for the key of the new handle for the `blob`
784 /// resource, but may be changed if necessary to ensure uniqueness during
785 /// insertion.
787 get(ShapedType type, StringRef blobName, AsmResourceBlob blob);
788
789 /// Return the data of this attribute as an ArrayRef<T> if it is present,
790 /// returns std::nullopt otherwise.
791 std::optional<ArrayRef<T>> tryGetAsArrayRef() const;
792
793 /// Support for isa<>/cast<>.
794 static bool classof(Attribute attr);
795};
796
797extern template class DenseResourceElementsAttrBase<bool>;
798extern template class DenseResourceElementsAttrBase<int8_t>;
799extern template class DenseResourceElementsAttrBase<int16_t>;
800extern template class DenseResourceElementsAttrBase<int32_t>;
801extern template class DenseResourceElementsAttrBase<int64_t>;
802extern template class DenseResourceElementsAttrBase<uint8_t>;
803extern template class DenseResourceElementsAttrBase<uint16_t>;
804extern template class DenseResourceElementsAttrBase<uint32_t>;
805extern template class DenseResourceElementsAttrBase<uint64_t>;
806extern template class DenseResourceElementsAttrBase<float>;
807extern template class DenseResourceElementsAttrBase<double>;
808} // namespace detail
809
810// Public names for all the supported DenseResourceElementsAttr.
811
834
835//===----------------------------------------------------------------------===//
836// BoolAttr
837//===----------------------------------------------------------------------===//
838
839/// Special case of IntegerAttr to represent boolean integers, i.e., signless i1
840/// integers.
841class BoolAttr : public Attribute {
842public:
845
846 static BoolAttr get(MLIRContext *context, bool value);
847
848 /// Enable conversion to IntegerAttr and its interfaces. This uses conversion
849 /// vs. inheritance to avoid bringing in all of IntegerAttrs methods.
850 operator IntegerAttr() const { return IntegerAttr(impl); }
851 operator TypedAttr() const { return IntegerAttr(impl); }
852
853 /// Return the boolean value of this attribute.
854 bool getValue() const;
855
856 /// Methods for support type inquiry through isa, cast, and dyn_cast.
857 static bool classof(Attribute attr);
858};
859
860//===----------------------------------------------------------------------===//
861// FlatSymbolRefAttr
862//===----------------------------------------------------------------------===//
863
864/// A symbol reference with a reference path containing a single element. This
865/// is used to refer to an operation within the current symbol table.
866class FlatSymbolRefAttr : public SymbolRefAttr {
867public:
868 using SymbolRefAttr::SymbolRefAttr;
869 using ValueType = StringRef;
870
871 /// Construct a symbol reference for the given value name.
872 static FlatSymbolRefAttr get(StringAttr value) {
873 return SymbolRefAttr::get(value);
874 }
875 static FlatSymbolRefAttr get(MLIRContext *ctx, StringRef value) {
876 return SymbolRefAttr::get(ctx, value);
877 }
878
879 /// Convenience getter for building a SymbolRefAttr based on an operation
880 /// that implements the SymbolTrait.
882 return SymbolRefAttr::get(symbol);
883 }
884
885 /// Returns the name of the held symbol reference as a StringAttr.
886 StringAttr getAttr() const { return getRootReference(); }
887
888 /// Returns the name of the held symbol reference.
889 StringRef getValue() const { return getAttr().getValue(); }
890
891 /// Methods for support type inquiry through isa, cast, and dyn_cast.
892 static bool classof(Attribute attr) {
893 SymbolRefAttr refAttr = llvm::dyn_cast<SymbolRefAttr>(attr);
894 return refAttr && refAttr.getNestedReferences().empty();
895 }
896
897private:
898 using SymbolRefAttr::get;
899 using SymbolRefAttr::getNestedReferences;
900};
901
902//===----------------------------------------------------------------------===//
903// DenseFPElementsAttr
904//===----------------------------------------------------------------------===//
905
906/// An attribute that represents a reference to a dense float vector or tensor
907/// object. Each element is stored as a double.
909public:
911
912 using DenseTypedElementsAttr::DenseTypedElementsAttr;
913
914 /// Get an instance of a DenseFPElementsAttr with the given arguments. This
915 /// simply wraps the DenseElementsAttr::get calls.
916 template <typename Arg>
917 static DenseFPElementsAttr get(const ShapedType &type, Arg &&arg) {
918 return llvm::cast<DenseFPElementsAttr>(
920 }
921 template <typename T>
922 static DenseFPElementsAttr get(const ShapedType &type,
923 const std::initializer_list<T> &list) {
924 return llvm::cast<DenseFPElementsAttr>(DenseElementsAttr::get(type, list));
925 }
926
927 /// Generates a new DenseElementsAttr by mapping each value attribute, and
928 /// constructing the DenseElementsAttr given the new element type.
930 mapValues(Type newElementType,
931 function_ref<APInt(const APFloat &)> mapping) const;
932
933 /// Iterator access to the float element values.
934 iterator begin() const { return tryGetFloatValues()->begin(); }
935 iterator end() const { return tryGetFloatValues()->end(); }
936
937 /// Method for supporting type inquiry through isa, cast and dyn_cast.
938 static bool classof(Attribute attr);
939};
940
941//===----------------------------------------------------------------------===//
942// DenseIntElementsAttr
943//===----------------------------------------------------------------------===//
944
945/// An attribute that represents a reference to a dense integer vector or tensor
946/// object.
948public:
949 /// DenseIntElementsAttr iterates on APInt, so we can use the raw element
950 /// iterator directly.
952
953 using DenseTypedElementsAttr::DenseTypedElementsAttr;
954
955 /// Get an instance of a DenseIntElementsAttr with the given arguments. This
956 /// simply wraps the DenseElementsAttr::get calls.
957 template <typename Arg>
958 static DenseIntElementsAttr get(const ShapedType &type, Arg &&arg) {
959 return llvm::cast<DenseIntElementsAttr>(
961 }
962 template <typename T>
963 static DenseIntElementsAttr get(const ShapedType &type,
964 const std::initializer_list<T> &list) {
965 return llvm::cast<DenseIntElementsAttr>(DenseElementsAttr::get(type, list));
966 }
967
968 /// Generates a new DenseElementsAttr by mapping each value attribute, and
969 /// constructing the DenseElementsAttr given the new element type.
970 DenseElementsAttr mapValues(Type newElementType,
971 function_ref<APInt(const APInt &)> mapping) const;
972
973 /// Iterator access to the integer element values.
974 iterator begin() const { return raw_int_begin(); }
975 iterator end() const { return raw_int_end(); }
976
977 /// Method for supporting type inquiry through isa, cast and dyn_cast.
978 static bool classof(Attribute attr);
979};
980
981//===----------------------------------------------------------------------===//
982// SparseElementsAttr
983//===----------------------------------------------------------------------===//
984
985template <typename T>
986auto SparseElementsAttr::try_value_begin_impl(OverloadToken<T>) const
987 -> FailureOr<iterator<T>> {
988 auto zeroValue = getZeroValue<T>();
989 auto valueIt = getValues().try_value_begin<T>();
990 if (failed(valueIt))
991 return failure();
992 const SmallVector<ptrdiff_t> flatSparseIndices(getFlattenedSparseIndices());
993 std::function<T(ptrdiff_t)> mapFn =
994 [flatSparseIndices{flatSparseIndices}, valueIt{std::move(*valueIt)},
995 zeroValue{std::move(zeroValue)}](ptrdiff_t index) {
996 // Try to map the current index to one of the sparse indices.
997 for (unsigned i = 0, e = flatSparseIndices.size(); i != e; ++i)
998 if (flatSparseIndices[i] == index)
999 return *std::next(valueIt, i);
1000 // Otherwise, return the zero value.
1001 return zeroValue;
1002 };
1003 return iterator<T>(llvm::seq<ptrdiff_t>(0, getNumElements()).begin(), mapFn);
1004}
1005
1006//===----------------------------------------------------------------------===//
1007// DistinctAttr
1008//===----------------------------------------------------------------------===//
1009
1010namespace detail {
1011struct DistinctAttrStorage;
1013} // namespace detail
1014
1015/// An attribute that associates a referenced attribute with a unique
1016/// identifier. Every call to the create function allocates a new distinct
1017/// attribute instance. The address of the attribute instance serves as a
1018/// temporary identifier. Similar to the names of SSA values, the final
1019/// identifiers are generated during pretty printing. This delayed numbering
1020/// ensures the printed identifiers are deterministic even if multiple distinct
1021/// attribute instances are created in-parallel.
1022///
1023/// Examples:
1024///
1025/// #distinct = distinct[0]<42.0 : f32>
1026/// #distinct1 = distinct[1]<42.0 : f32>
1027/// #distinct2 = distinct[2]<array<i32: 10, 42>>
1028///
1029/// NOTE: The distinct attribute cannot be defined using ODS since it uses a
1030/// custom distinct attribute uniquer that cannot be set from ODS.
1032 : public detail::StorageUserBase<DistinctAttr, Attribute,
1033 detail::DistinctAttrStorage,
1034 detail::DistinctAttributeUniquer> {
1035public:
1036 using Base::Base;
1037
1038 /// Returns the referenced attribute.
1040
1041 /// Creates a distinct attribute that associates a referenced attribute with a
1042 /// unique identifier.
1043 static DistinctAttr create(Attribute referencedAttr);
1044
1045 static constexpr StringLiteral name = "builtin.distinct";
1046};
1047
1048//===----------------------------------------------------------------------===//
1049// StringAttr
1050//===----------------------------------------------------------------------===//
1051
1052/// Define comparisons for StringAttr against nullptr and itself to avoid the
1053/// StringRef overloads from being chosen when not desirable.
1054inline bool operator==(StringAttr lhs, std::nullptr_t) { return !lhs; }
1055inline bool operator!=(StringAttr lhs, std::nullptr_t) {
1056 return static_cast<bool>(lhs);
1057}
1058inline bool operator==(StringAttr lhs, StringAttr rhs) {
1059 return (Attribute)lhs == (Attribute)rhs;
1060}
1061inline bool operator!=(StringAttr lhs, StringAttr rhs) { return !(lhs == rhs); }
1062
1063/// Allow direct comparison with StringRef.
1064inline bool operator==(StringAttr lhs, StringRef rhs) {
1065 return lhs.getValue() == rhs;
1066}
1067inline bool operator!=(StringAttr lhs, StringRef rhs) { return !(lhs == rhs); }
1068inline bool operator==(StringRef lhs, StringAttr rhs) {
1069 return rhs.getValue() == lhs;
1070}
1071inline bool operator!=(StringRef lhs, StringAttr rhs) { return !(lhs == rhs); }
1072
1073} // namespace mlir
1074
1075//===----------------------------------------------------------------------===//
1076// Attribute Utilities
1077//===----------------------------------------------------------------------===//
1078
1079namespace mlir {
1080
1081/// Given a list of strides (in which ShapedType::kDynamic
1082/// represents a dynamic value), return the single result AffineMap which
1083/// represents the linearized strided layout map. Dimensions correspond to the
1084/// offset followed by the strides in order. Symbols are inserted for each
1085/// dynamic dimension in order. A stride is always positive.
1086///
1087/// Examples:
1088/// =========
1089///
1090/// 1. For offset: 0 strides: ?, ?, 1 return
1091/// (i, j, k)[M, N]->(M * i + N * j + k)
1092///
1093/// 2. For offset: 3 strides: 32, ?, 16 return
1094/// (i, j, k)[M]->(3 + 32 * i + M * j + 16 * k)
1095///
1096/// 3. For offset: ? strides: ?, ?, ? return
1097/// (i, j, k)[off, M, N, P]->(off + M * i + N * j + P * k)
1099 MLIRContext *context);
1100
1101} // namespace mlir
1102
1103namespace llvm {
1104
1105template <>
1106struct DenseMapInfo<mlir::StringAttr> : public DenseMapInfo<mlir::Attribute> {
1107 static mlir::StringAttr getEmptyKey() {
1108 const void *pointer = llvm::DenseMapInfo<const void *>::getEmptyKey();
1109 return mlir::StringAttr::getFromOpaquePointer(pointer);
1110 }
1111 static mlir::StringAttr getTombstoneKey() {
1113 return mlir::StringAttr::getFromOpaquePointer(pointer);
1114 }
1115};
1116template <>
1117struct PointerLikeTypeTraits<mlir::StringAttr>
1118 : public PointerLikeTypeTraits<mlir::Attribute> {
1119 static inline mlir::StringAttr getFromVoidPointer(void *p) {
1120 return mlir::StringAttr::getFromOpaquePointer(p);
1121 }
1122};
1123
1124template <>
1125struct PointerLikeTypeTraits<mlir::IntegerAttr>
1126 : public PointerLikeTypeTraits<mlir::Attribute> {
1127 static inline mlir::IntegerAttr getFromVoidPointer(void *p) {
1128 return mlir::IntegerAttr::getFromOpaquePointer(p);
1129 }
1130};
1131
1132template <>
1133struct PointerLikeTypeTraits<mlir::SymbolRefAttr>
1134 : public PointerLikeTypeTraits<mlir::Attribute> {
1135 static inline mlir::SymbolRefAttr getFromVoidPointer(void *ptr) {
1136 return mlir::SymbolRefAttr::getFromOpaquePointer(ptr);
1137 }
1138};
1139
1140} // namespace llvm
1141
1142#endif // MLIR_IR_BUILTINATTRIBUTES_H
lhs
static int64_t getNumElements(Type t)
Compute the total number of elements in the given type, also taking into account nested types.
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Definition AffineMap.h:46
This base class exposes generic asm parser hooks, usable across the various derived parsers.
This base class exposes generic asm printer hooks, usable across the various derived printers.
This class represents a processed binary blob of data.
Definition AsmState.h:91
Attributes are known-constant values of operations.
Definition Attributes.h:25
constexpr Attribute()=default
Special case of IntegerAttr to represent boolean integers, i.e., signless i1 integers.
constexpr Attribute()=default
A utility iterator that allows walking over the internal Attribute values of a DenseElementsAttr.
A utility iterator that allows walking over the internal bool values.
bool operator*() const
Accesses the bool value at this iterator position.
Iterator for walking over complex APFloat values.
mlir::Complex< APFloat > mapElement(const mlir::Complex< APInt > &value) const
Map the element to the iterator result type.
A utility iterator that allows walking over the internal raw complex APInt values.
mlir::Complex< APInt > operator*() const
Accesses the raw mlir::Complex<APInt> value at this iterator position.
Iterator for walking raw element values of the specified type 'T', which may be any c++ data type mat...
const T & operator*() const
Accesses the raw value at this iterator position.
Iterator for walking over APFloat values.
APFloat mapElement(const APInt &value) const
Map the element to the iterator result type.
A utility iterator that allows walking over the internal raw APInt values.
APInt operator*() const
Accesses the raw APInt value at this iterator position.
An attribute that represents a reference to a dense vector or tensor object.
ArrayRef< StringRef > getRawStringData() const
Return the raw StringRef data held by this attribute.
std::enable_if_t< std::is_same< T, mlir::Complex< APInt > >::value > ComplexAPIntValueTemplateCheckT
Try to get the held element values as a range of complex APInts.
IntElementIterator raw_int_begin() const
Iterators to various elements that require out-of-line definition.
static DenseElementsAttr getRawIntOrFloat(ShapedType type, ArrayRef< char > data, int64_t dataEltSize, bool isInt, bool isSigned)
Overload of the raw 'get' method that asserts that the given type is of integer or floating-point typ...
FailureOr< iterator_range_impl< AttributeElementIterator > > tryGetValues() const
auto value_begin() const
Get an iterator of the given type to the start of the held element values.
static DenseElementsAttr getRawComplex(ShapedType type, ArrayRef< char > data, int64_t dataEltSize, bool isInt, bool isSigned)
Overload of the raw 'get' method that asserts that the given type is of complex type.
std::enable_if_t< std::is_same< T, mlir::Complex< APFloat > >::value > ComplexAPFloatValueTemplateCheckT
Try to get the held element values as a range of complex APFloat.
auto try_value_begin() const
Try to get an iterator of the given type to the start of the held element values.
static bool classof(Attribute attr)
Method for support type inquiry through isa, cast and dyn_cast.
bool isValidComplex(int64_t dataEltSize, bool isInt, bool isSigned) const
FailureOr< iterator_range_impl< ElementIterator< T > > > tryGetValues() const
auto getValues() const
Return the held element values as a range of the given type.
DenseElementsAttr resizeSplat(ShapedType newType)
Return a new DenseElementsAttr that has the same data as the current attribute, but with a different ...
decltype(std::declval< AttrT >().template getValues< T >()) iterator_range
The iterator range over the given element T.
detail::ElementsAttrRange< IteratorT > iterator_range_impl
The iterator range over the given iterator type T.
int64_t getNumElements() const
Returns the number of elements held by this attribute.
std::enable_if_t<!std::is_base_of< Attribute, T >::value||std::is_same< Attribute, T >::value, T > getSplatValue() const
Return the splat value for this attribute.
static DenseElementsAttr getFromRawBuffer(ShapedType type, ArrayRef< char > rawBuffer)
Construct a dense elements attribute from a raw buffer representing the data for this attribute.
static bool isValidRawBuffer(ShapedType type, ArrayRef< char > rawBuffer)
Returns true if the given buffer is a valid raw buffer for the given type.
int64_t size() const
Returns the number of elements held by this attribute.
std::enable_if_t< std::is_same< T, Attribute >::value > AttributeValueTemplateCheckT
Try to get the held element values as a range of Attributes.
bool isValidBool() const
Check the information for a C++ data type, check if this type is valid for the current attribute.
bool isSplat() const
Returns true if this attribute corresponds to a splat, i.e.
auto try_value_end() const
Try to get an iterator of the given type to the end of the held element values.
ArrayRef< char > getRawData() const
Return the raw storage data held by this attribute.
constexpr Attribute()=default
FailureOr< iterator_range_impl< ElementIterator< T > > > tryGetValues() const
static DenseElementsAttr get(const ShapedType &type, ArrayRef< T > values)
Constructs a dense integer elements attribute from an array of integer or floating-point values.
DenseElementsAttr mapValues(Type newElementType, function_ref< APInt(const APInt &)> mapping) const
Generates a new DenseElementsAttr by mapping each int value to a new underlying APInt.
static DenseElementsAttr get(const ShapedType &type, const std::initializer_list< T > &list)
Construct a dense elements attribute for an initializer_list of values.
decltype(std::declval< AttrT >().template value_begin< T >()) iterator
The iterator for the given element type T.
std::enable_if_t< std::is_base_of< Attribute, T >::value && !std::is_same< Attribute, T >::value > DerivedAttrValueTemplateCheckT
Try to get the held element values a range of T, where T is a derived attribute type.
Type getElementType() const
Return the element type of this DenseElementsAttr.
FailureOr< iterator_range_impl< ComplexFloatElementIterator > > tryGetComplexFloatValues() const
std::enable_if_t< std::is_same< T, StringRef >::value > StringRefValueTemplateCheckT
Try to get the held element values as a range of StringRef.
IntElementIterator raw_int_end() const
std::enable_if_t<(!std::is_same< T, bool >::value && std::numeric_limits< T >::is_integer)|| is_valid_cpp_fp_type< T >::value > IntFloatValueTemplateCheckT
Try to get the held element values as a range of integer or floating-point values.
static DenseElementsAttr get(ShapedType type, ArrayRef< Attribute > values)
Constructs a dense elements attribute from an array of element values.
std::enable_if_t< std::is_same< T, APFloat >::value > APFloatValueTemplateCheckT
Try to get the held element values as a range of APFloat.
ShapedType getType() const
Return the type of this ElementsAttr, guaranteed to be a vector or tensor with static shape.
FailureOr< iterator_range_impl< FloatElementIterator > > tryGetFloatValues() const
std::enable_if_t< detail::is_complex_t< T >::value &&(std::numeric_limits< ElementT >::is_integer|| is_valid_cpp_fp_type< ElementT >::value)> ComplexValueTemplateCheckT
Try to get the held element values as a range of mlir::Complex.
std::enable_if_t< std::is_same< T, bool >::value > BoolValueTemplateCheckT
Try to get the held element values as a range of bool.
bool empty() const
Returns if the number of elements held by this attribute is 0.
DenseElementsAttr bitcast(Type newElType)
Return a new DenseElementsAttr that has the same data as the current attribute, but has bitcast eleme...
static DenseElementsAttr get(const ShapedType &type, T value)
Constructs a dense integer elements attribute from a single element.
std::enable_if_t< std::is_base_of< Attribute, T >::value &&!std::is_same< Attribute, T >::value, T > getSplatValue() const
Return the splat value for derived attribute element types.
bool isValidIntOrFloat(int64_t dataEltSize, bool isInt, bool isSigned) const
FailureOr< iterator_range_impl< ElementIterator< StringRef > > > tryGetValues() const
FailureOr< iterator_range_impl< IntElementIterator > > tryGetValues() const
DenseElementsAttr reshape(ShapedType newType)
Return a new DenseElementsAttr that has the same data as the current attribute, but has been reshaped...
FailureOr< iterator_range_impl< ComplexIntElementIterator > > tryGetComplexIntValues() const
auto value_end() const
Get an iterator of the given type to the end of the held element values.
static DenseElementsAttr get(const ShapedType &type, ArrayRef< T > values)
Constructs a dense complex elements attribute from an array of complex values.
std::enable_if_t< std::is_same< T, APInt >::value > APIntValueTemplateCheckT
Try to get the held element values as a range of APInts.
FailureOr< iterator_range_impl< BoolElementIterator > > tryGetValues() const
FailureOr< iterator_range_impl< DerivedAttributeElementIterator< T > > > tryGetValues() const
FailureOr< iterator_range_impl< ComplexFloatElementIterator > > tryGetValues() const
FailureOr< iterator_range_impl< ComplexIntElementIterator > > tryGetValues() const
FailureOr< iterator_range_impl< FloatElementIterator > > tryGetValues() const
An attribute that represents a reference to a dense float vector or tensor object.
static DenseFPElementsAttr get(const ShapedType &type, const std::initializer_list< T > &list)
DenseElementsAttr::FloatElementIterator iterator
static DenseFPElementsAttr get(const ShapedType &type, Arg &&arg)
Get an instance of a DenseFPElementsAttr with the given arguments.
iterator begin() const
Iterator access to the float element values.
An attribute that represents a reference to a dense integer vector or tensor object.
static DenseIntElementsAttr get(const ShapedType &type, const std::initializer_list< T > &list)
DenseElementsAttr::IntElementIterator iterator
DenseIntElementsAttr iterates on APInt, so we can use the raw element iterator directly.
iterator begin() const
Iterator access to the integer element values.
static DenseIntElementsAttr get(const ShapedType &type, Arg &&arg)
Get an instance of a DenseIntElementsAttr with the given arguments.
An attribute that associates a referenced attribute with a unique identifier.
static constexpr StringLiteral name
static DistinctAttr create(Attribute referencedAttr)
Creates a distinct attribute that associates a referenced attribute with a unique identifier.
Attribute getReferencedAttr() const
Returns the referenced attribute.
A symbol reference with a reference path containing a single element.
static FlatSymbolRefAttr get(StringAttr value)
Construct a symbol reference for the given value name.
static FlatSymbolRefAttr get(MLIRContext *ctx, StringRef value)
static bool classof(Attribute attr)
Methods for support type inquiry through isa, cast, and dyn_cast.
static FlatSymbolRefAttr get(Operation *symbol)
Convenience getter for building a SymbolRefAttr based on an operation that implements the SymbolTrait...
StringRef getValue() const
Returns the name of the held symbol reference.
StringAttr getAttr() const
Returns the name of the held symbol reference as a StringAttr.
An integer set representing a conjunction of one or more affine equalities and inequalities.
Definition IntegerSet.h:44
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:63
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
An attribute that represents a reference to a splat vector or tensor constant, meaning all of the ele...
static bool classof(Attribute attr)
Method for support type inquiry through isa, cast and dyn_cast.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
bool isInteger() const
Return true if this is an integer type (with the specified width).
Definition Types.cpp:58
Base class for DenseArrayAttr that is instantiated and specialized for each supported element type be...
static DenseArrayAttrImpl get(MLIRContext *context, ArrayRef< T > content)
Builder from ArrayRef<T>.
static bool classof(Attribute attr)
Support for isa<>/cast<>.
void print(raw_ostream &os) const
void print(AsmPrinter &printer) const
Print the short form [42, 100, -1] without any type prefix.
static Attribute parse(AsmParser &parser, Type type)
Parse the short form [42, 100, -1] without any type prefix.
static Attribute parseWithoutBraces(AsmParser &parser, Type type)
Parse the short form 42, 100, -1 without any type prefix or braces.
void printWithoutBraces(raw_ostream &os) const
Print the short form 42, 100, -1 without any braces or type prefix.
T operator[](std::size_t index) const
Random access to elements.
Impl iterator for indexed DenseElementsAttr iterators that records a data pointer and data index that...
ptrdiff_t getDataIndex() const
Return the current index for this iterator, adjusted for the case of a splat.
const char * getData() const
Return the data base pointer.
DenseElementIndexedIteratorImpl(const char *data, bool isSplat, size_t dataIndex)
Base class for DenseResourceElementsAttr that is instantiated and specialized for each supported elem...
static bool classof(Attribute attr)
Support for isa<>/cast<>.
static DenseResourceElementsAttrBase< T > get(ShapedType type, StringRef blobName, AsmResourceBlob blob)
A builder that inserts a new resource using the provided blob.
std::optional< ArrayRef< T > > tryGetAsArrayRef() const
Return the data of this attribute as an ArrayRef<T> if it is present, returns std::nullopt otherwise.
A specialized attribute uniquer for distinct attributes that always allocates since the distinct attr...
This class provides iterator utilities for an ElementsAttr range.
Utility class for implementing users of storage classes uniqued by a StorageUniquer.
StorageUserBase< ConcreteT, BaseT, StorageT, UniquerT, Traits... > Base
Utility declarations for the concrete attribute class.
This file contains the declaration of the mlir::NonFloatComplex type and mlir::Complex type alias.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:229
AttrTypeReplacer.
std::pair< const char *, bool > DenseIterPtrAndSplat
Pair of raw pointer and a boolean flag of whether the pointer holds a splat,.
Include the generated interface declarations.
detail::DenseArrayAttrImpl< int64_t > DenseI64ArrayAttr
detail::DenseResourceElementsAttrBase< uint64_t > DenseUI64ResourceElementsAttr
detail::DenseResourceElementsAttrBase< int32_t > DenseI32ResourceElementsAttr
detail::DenseResourceElementsAttrBase< uint32_t > DenseUI32ResourceElementsAttr
detail::DenseArrayAttrImpl< int8_t > DenseI8ArrayAttr
DialectResourceBlobHandle< BuiltinDialect > DenseResourceElementsHandle
detail::DenseResourceElementsAttrBase< float > DenseF32ResourceElementsAttr
bool operator==(StringAttr lhs, std::nullptr_t)
Define comparisons for StringAttr against nullptr and itself to avoid the StringRef overloads from be...
detail::DenseResourceElementsAttrBase< bool > DenseBoolResourceElementsAttr
bool operator!=(RegionBranchPoint lhs, RegionBranchPoint rhs)
detail::DenseResourceElementsAttrBase< int16_t > DenseI16ResourceElementsAttr
std::conditional_t< std::is_floating_point_v< T >, std::complex< T >, NonFloatComplex< T > > Complex
Definition Complex.h:265
detail::DenseResourceElementsAttrBase< int64_t > DenseI64ResourceElementsAttr
detail::DenseArrayAttrImpl< int32_t > DenseI32ArrayAttr
detail::DenseResourceElementsAttrBase< uint16_t > DenseUI16ResourceElementsAttr
AffineExpr operator*(int64_t val, AffineExpr expr)
Definition AffineExpr.h:252
AffineMap makeStridedLinearLayoutMap(ArrayRef< int64_t > strides, int64_t offset, MLIRContext *context)
Given a list of strides (in which ShapedType::kDynamic represents a dynamic value),...
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
detail::DenseArrayAttrImpl< double > DenseF64ArrayAttr
detail::DenseArrayAttrImpl< bool > DenseBoolArrayAttr
detail::DenseResourceElementsAttrBase< int8_t > DenseI8ResourceElementsAttr
detail::DenseArrayAttrImpl< float > DenseF32ArrayAttr
detail::DenseResourceElementsAttrBase< uint8_t > DenseUI8ResourceElementsAttr
detail::DenseArrayAttrImpl< int16_t > DenseI16ArrayAttr
llvm::function_ref< Fn > function_ref
Definition LLVM.h:147
detail::DenseResourceElementsAttrBase< double > DenseF64ResourceElementsAttr
static mlir::IntegerAttr getFromVoidPointer(void *p)
static mlir::StringAttr getFromVoidPointer(void *p)
static mlir::SymbolRefAttr getFromVoidPointer(void *ptr)
T mapElement(Attribute attr) const
Map the element to the iterator result type.
Type trait used to check if the given type T is a potentially valid C++ floating point type that can ...
static constexpr bool value
The type is a valid floating point type if it is a builtin floating point type, or is a potentially u...
This class defines a dialect specific handle to a resource blob.
An attribute representing a reference to a dense vector or tensor object containing strings.
An attribute representing a reference to a dense vector or tensor object.
An attribute to store a distinct reference to another attribute.
Type trait detector that checks if a given type T is a complex type.