MLIR  15.0.0git
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
mlir::DenseElementsAttr Class Reference

An attribute that represents a reference to a dense vector or tensor object. More...

#include "mlir/IR/BuiltinAttributes.h"

+ Inheritance diagram for mlir::DenseElementsAttr:
+ Collaboration diagram for mlir::DenseElementsAttr:

Classes

class  AttributeElementIterator
 A utility iterator that allows walking over the internal Attribute values of a DenseElementsAttr. More...
 
class  BoolElementIterator
 A utility iterator that allows walking over the internal bool values. More...
 
class  ComplexFloatElementIterator
 Iterator for walking over complex APFloat values. More...
 
class  ComplexIntElementIterator
 A utility iterator that allows walking over the internal raw complex APInt values. More...
 
struct  DerivedAttributeElementIterator
 
class  ElementIterator
 Iterator for walking raw element values of the specified type 'T', which may be any c++ data type matching the stored representation: int32_t, float, etc. More...
 
class  FloatElementIterator
 Iterator for walking over APFloat values. More...
 
class  IntElementIterator
 A utility iterator that allows walking over the internal raw APInt values. More...
 
struct  is_valid_cpp_fp_type
 Type trait used to check if the given type T is a potentially valid C++ floating point type that can be used to access the underlying element types of a DenseElementsAttr. More...
 

Public Types

template<typename IteratorT >
using iterator_range_impl = detail::ElementsAttrRange< IteratorT >
 The iterator range over the given iterator type T. More...
 
template<typename T , typename AttrT = DenseElementsAttr>
using iterator = decltype(std::declval< AttrT >().template value_begin< T >())
 The iterator for the given element type T. More...
 
template<typename T , typename AttrT = DenseElementsAttr>
using iterator_range = decltype(std::declval< AttrT >().template getValues< T >())
 The iterator range over the given element T. More...
 
template<typename T >
using IntFloatValueTemplateCheckT = typename std::enable_if<(!std::is_same< T, bool >::value &&std::numeric_limits< T >::is_integer)||is_valid_cpp_fp_type< T >::value >::type
 Return the held element values as a range of integer or floating-point values. More...
 
template<typename T , typename ElementT >
using ComplexValueTemplateCheckT = typename std::enable_if< detail::is_complex_t< T >::value &&(std::numeric_limits< ElementT >::is_integer||is_valid_cpp_fp_type< ElementT >::value)>::type
 Return the held element values as a range of std::complex. More...
 
template<typename T >
using StringRefValueTemplateCheckT = typename std::enable_if< std::is_same< T, StringRef >::value >::type
 Return the held element values as a range of StringRef. More...
 
template<typename T >
using AttributeValueTemplateCheckT = typename std::enable_if< std::is_same< T, Attribute >::value >::type
 Return the held element values as a range of Attributes. More...
 
template<typename T >
using DerivedAttrValueTemplateCheckT = typename std::enable_if< std::is_base_of< Attribute, T >::value &&!std::is_same< Attribute, T >::value >::type
 Return the held element values a range of T, where T is a derived attribute type. More...
 
template<typename T >
using BoolValueTemplateCheckT = typename std::enable_if< std::is_same< T, bool >::value >::type
 Return the held element values as a range of bool. More...
 
template<typename T >
using APIntValueTemplateCheckT = typename std::enable_if< std::is_same< T, APInt >::value >::type
 Return the held element values as a range of APInts. More...
 
template<typename T >
using ComplexAPIntValueTemplateCheckT = typename std::enable_if< std::is_same< T, std::complex< APInt > >::value >::type
 Return the held element values as a range of complex APInts. More...
 
template<typename T >
using APFloatValueTemplateCheckT = typename std::enable_if< std::is_same< T, APFloat >::value >::type
 Return the held element values as a range of APFloat. More...
 
template<typename T >
using ComplexAPFloatValueTemplateCheckT = typename std::enable_if< std::is_same< T, std::complex< APFloat > >::value >::type
 Return the held element values as a range of complex APFloat. More...
 
- Public Types inherited from mlir::Attribute
template<typename ConcreteType , typename BaseType , typename StorageType , template< typename T > class... Traits>
using AttrBase = detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::AttributeUniquer, Traits... >
 Utility class for implementing attributes. More...
 
using ImplType = AttributeStorage
 
using ValueType = void
 
using AbstractTy = AbstractAttribute
 

Public Member Functions

 operator ElementsAttr () const
 Allow implicit conversion to ElementsAttr. More...
 
bool isSplat () const
 Returns true if this attribute corresponds to a splat, i.e. More...
 
template<typename T >
std::enable_if<!std::is_base_of< Attribute, T >::value||std::is_same< Attribute, T >::value, T >::type getSplatValue () const
 Return the splat value for this attribute. More...
 
template<typename T >
std::enable_if< std::is_base_of< Attribute, T >::value &&!std::is_same< Attribute, T >::value, T >::type getSplatValue () const
 Return the splat value for derived attribute element types. More...
 
template<typename T , typename = IntFloatValueTemplateCheckT<T>>
iterator_range_impl< ElementIterator< T > > getValues () const
 
template<typename T , typename = IntFloatValueTemplateCheckT<T>>
ElementIterator< T > value_begin () const
 
template<typename T , typename = IntFloatValueTemplateCheckT<T>>
ElementIterator< T > value_end () const
 
template<typename T , typename ElementT = typename T::value_type, typename = ComplexValueTemplateCheckT<T, ElementT>>
iterator_range_impl< ElementIterator< T > > getValues () const
 
template<typename T , typename ElementT = typename T::value_type, typename = ComplexValueTemplateCheckT<T, ElementT>>
ElementIterator< T > value_begin () const
 
template<typename T , typename ElementT = typename T::value_type, typename = ComplexValueTemplateCheckT<T, ElementT>>
ElementIterator< T > value_end () const
 
template<typename T , typename = StringRefValueTemplateCheckT<T>>
iterator_range_impl< ElementIterator< StringRef > > getValues () const
 
template<typename T , typename = StringRefValueTemplateCheckT<T>>
ElementIterator< StringRef > value_begin () const
 
template<typename T , typename = StringRefValueTemplateCheckT<T>>
ElementIterator< StringRef > value_end () const
 
template<typename T , typename = AttributeValueTemplateCheckT<T>>
iterator_range_impl< AttributeElementIteratorgetValues () const
 
template<typename T , typename = AttributeValueTemplateCheckT<T>>
AttributeElementIterator value_begin () const
 
template<typename T , typename = AttributeValueTemplateCheckT<T>>
AttributeElementIterator value_end () const
 
template<typename T , typename = DerivedAttrValueTemplateCheckT<T>>
iterator_range_impl< DerivedAttributeElementIterator< T > > getValues () const
 
template<typename T , typename = DerivedAttrValueTemplateCheckT<T>>
DerivedAttributeElementIterator< T > value_begin () const
 
template<typename T , typename = DerivedAttrValueTemplateCheckT<T>>
DerivedAttributeElementIterator< T > value_end () const
 
template<typename T , typename = BoolValueTemplateCheckT<T>>
iterator_range_impl< BoolElementIteratorgetValues () const
 
template<typename T , typename = BoolValueTemplateCheckT<T>>
BoolElementIterator value_begin () const
 
template<typename T , typename = BoolValueTemplateCheckT<T>>
BoolElementIterator value_end () const
 
template<typename T , typename = APIntValueTemplateCheckT<T>>
iterator_range_impl< IntElementIteratorgetValues () const
 
template<typename T , typename = APIntValueTemplateCheckT<T>>
IntElementIterator value_begin () const
 
template<typename T , typename = APIntValueTemplateCheckT<T>>
IntElementIterator value_end () const
 
template<typename T , typename = ComplexAPIntValueTemplateCheckT<T>>
iterator_range_impl< ComplexIntElementIteratorgetValues () const
 
template<typename T , typename = ComplexAPIntValueTemplateCheckT<T>>
ComplexIntElementIterator value_begin () const
 
template<typename T , typename = ComplexAPIntValueTemplateCheckT<T>>
ComplexIntElementIterator value_end () const
 
template<typename T , typename = APFloatValueTemplateCheckT<T>>
iterator_range_impl< FloatElementIteratorgetValues () const
 
template<typename T , typename = APFloatValueTemplateCheckT<T>>
FloatElementIterator value_begin () const
 
template<typename T , typename = APFloatValueTemplateCheckT<T>>
FloatElementIterator value_end () const
 
template<typename T , typename = ComplexAPFloatValueTemplateCheckT<T>>
iterator_range_impl< ComplexFloatElementIteratorgetValues () const
 
template<typename T , typename = ComplexAPFloatValueTemplateCheckT<T>>
ComplexFloatElementIterator value_begin () const
 
template<typename T , typename = ComplexAPFloatValueTemplateCheckT<T>>
ComplexFloatElementIterator value_end () const
 
ArrayRef< char > getRawData () const
 Return the raw storage data held by this attribute. More...
 
ArrayRef< StringRef > getRawStringData () const
 Return the raw StringRef data held by this attribute. More...
 
ShapedType getType () const
 Return the type of this ElementsAttr, guaranteed to be a vector or tensor with static shape. More...
 
Type getElementType () const
 Return the element type of this DenseElementsAttr. More...
 
int64_t getNumElements () const
 Returns the number of elements held by this attribute. More...
 
int64_t size () const
 Returns the number of elements held by this attribute. More...
 
bool empty () const
 Returns if the number of elements held by this attribute is 0. More...
 
DenseElementsAttr reshape (ShapedType newType)
 Return a new DenseElementsAttr that has the same data as the current attribute, but has been reshaped to 'newType'. More...
 
DenseElementsAttr resizeSplat (ShapedType newType)
 Return a new DenseElementsAttr that has the same data as the current attribute, but with a different shape for a splat type. More...
 
DenseElementsAttr bitcast (Type newElType)
 Return a new DenseElementsAttr that has the same data as the current attribute, but has bitcast elements to 'newElType'. More...
 
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. More...
 
DenseElementsAttr mapValues (Type newElementType, function_ref< APInt(const APFloat &)> mapping) const
 Generates a new DenseElementsAttr by mapping each float value to a new underlying APInt. More...
 
- Public Member Functions inherited from mlir::Attribute
constexpr Attribute ()
 
 Attribute (const ImplType *impl)
 
 Attribute (const Attribute &other)=default
 
Attributeoperator= (const Attribute &other)=default
 
bool operator== (Attribute other) const
 
bool operator!= (Attribute other) const
 
 operator bool () const
 
bool operator! () const
 
template<typename U >
bool isa () const
 
template<typename First , typename Second , typename... Rest>
bool isa () const
 
template<typename First , typename... Rest>
bool isa_and_nonnull () const
 
template<typename U >
dyn_cast () const
 
template<typename U >
dyn_cast_or_null () const
 
template<typename U >
cast () const
 
TypeID getTypeID ()
 Return a unique identifier for the concrete attribute type. More...
 
Type getType () const
 Return the type of this attribute. More...
 
MLIRContextgetContext () const
 Return the context this attribute belongs to. More...
 
DialectgetDialect () const
 Get the dialect this attribute is registered to. More...
 
void print (raw_ostream &os) const
 Print the attribute. More...
 
void dump () const
 
const voidgetAsOpaquePointer () const
 Get an opaque pointer to the attribute. More...
 
template<template< typename T > class Trait>
bool hasTrait ()
 Returns true if the type was registered with a particular trait. More...
 
const AbstractTygetAbstractAttribute () const
 Return the abstract descriptor for this attribute. More...
 

Static Public Member Functions

static bool classof (Attribute attr)
 Method for support type inquiry through isa, cast and dyn_cast. More...
 
static DenseElementsAttr get (ShapedType type, ArrayRef< Attribute > values)
 Constructs a dense elements attribute from an array of element values. More...
 
template<typename T , typename = typename std::enable_if< std::numeric_limits<T>::is_integer || is_valid_cpp_fp_type<T>::value>::type>
static DenseElementsAttr get (const ShapedType &type, ArrayRef< T > values)
 Constructs a dense integer elements attribute from an array of integer or floating-point values. More...
 
template<typename T , typename = typename std::enable_if< std::numeric_limits<T>::is_integer || is_valid_cpp_fp_type<T>::value || detail::is_complex_t<T>::value>::type>
static DenseElementsAttr get (const ShapedType &type, T value)
 Constructs a dense integer elements attribute from a single element. More...
 
template<typename T , typename ElementT = typename T::value_type, typename = typename std::enable_if< detail::is_complex_t<T>::value && (std::numeric_limits<ElementT>::is_integer || is_valid_cpp_fp_type<ElementT>::value)>::type>
static DenseElementsAttr get (const ShapedType &type, ArrayRef< T > values)
 Constructs a dense complex elements attribute from an array of complex values. More...
 
static DenseElementsAttr get (ShapedType type, ArrayRef< bool > values)
 Overload of the above 'get' method that is specialized for boolean values. More...
 
static DenseElementsAttr get (ShapedType type, ArrayRef< StringRef > values)
 Overload of the above 'get' method that is specialized for StringRef values. More...
 
static DenseElementsAttr get (ShapedType type, ArrayRef< APInt > values)
 Constructs a dense integer elements attribute from an array of APInt values. More...
 
static DenseElementsAttr get (ShapedType type, ArrayRef< std::complex< APInt >> values)
 Constructs a dense complex elements attribute from an array of APInt values. More...
 
static DenseElementsAttr get (ShapedType type, ArrayRef< APFloat > values)
 Constructs a dense float elements attribute from an array of APFloat values. More...
 
static DenseElementsAttr get (ShapedType type, ArrayRef< std::complex< APFloat >> values)
 Constructs a dense complex elements attribute from an array of APFloat values. More...
 
template<typename T >
static DenseElementsAttr get (const ShapedType &type, const std::initializer_list< T > &list)
 Construct a dense elements attribute for an initializer_list of values. More...
 
static DenseElementsAttr getFromRawBuffer (ShapedType type, ArrayRef< char > rawBuffer)
 Construct a dense elements attribute from a raw buffer representing the data for this attribute. More...
 
static bool isValidRawBuffer (ShapedType type, ArrayRef< char > rawBuffer, bool &detectedSplat)
 Returns true if the given buffer is a valid raw buffer for the given type. More...
 
- Static Public Member Functions inherited from mlir::Attribute
static bool classof (Attribute)
 
static Attribute getFromOpaquePointer (const void *ptr)
 Construct an attribute from the opaque pointer representation. More...
 

Protected Member Functions

IntElementIterator raw_int_begin () const
 Iterators to various elements that require out-of-line definition. More...
 
IntElementIterator raw_int_end () const
 
iterator_range_impl< ComplexIntElementIteratorgetComplexIntValues () const
 
ComplexIntElementIterator complex_value_begin () const
 
ComplexIntElementIterator complex_value_end () const
 
iterator_range_impl< FloatElementIteratorgetFloatValues () const
 Return the held element values as a range of APFloat. More...
 
FloatElementIterator float_value_begin () const
 
FloatElementIterator float_value_end () const
 
iterator_range_impl< ComplexFloatElementIteratorgetComplexFloatValues () const
 
ComplexFloatElementIterator complex_float_value_begin () const
 
ComplexFloatElementIterator complex_float_value_end () const
 
bool isValidBool () const
 Check the information for a C++ data type, check if this type is valid for the current attribute. More...
 
bool isValidIntOrFloat (int64_t dataEltSize, bool isInt, bool isSigned) const
 
bool isValidComplex (int64_t dataEltSize, bool isInt, bool isSigned) const
 

Static Protected Member Functions

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. More...
 
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 type. More...
 

Additional Inherited Members

- Protected Attributes inherited from mlir::Attribute
ImplTypeimpl {nullptr}
 

Detailed Description

An attribute that represents a reference to a dense vector or tensor object.

Definition at line 71 of file BuiltinAttributes.h.

Member Typedef Documentation

◆ APFloatValueTemplateCheckT

template<typename T >
using mlir::DenseElementsAttr::APFloatValueTemplateCheckT = typename std::enable_if<std::is_same<T, APFloat>::value>::type

Return the held element values as a range of APFloat.

The element type of this attribute must be of float type.

Definition at line 588 of file BuiltinAttributes.h.

◆ APIntValueTemplateCheckT

template<typename T >
using mlir::DenseElementsAttr::APIntValueTemplateCheckT = typename std::enable_if<std::is_same<T, APInt>::value>::type

Return the held element values as a range of APInts.

The element type of this attribute must be of integer type.

Definition at line 549 of file BuiltinAttributes.h.

◆ AttributeValueTemplateCheckT

template<typename T >
using mlir::DenseElementsAttr::AttributeValueTemplateCheckT = typename std::enable_if<std::is_same<T, Attribute>::value>::type

Return the held element values as a range of Attributes.

Definition at line 476 of file BuiltinAttributes.h.

◆ BoolValueTemplateCheckT

template<typename T >
using mlir::DenseElementsAttr::BoolValueTemplateCheckT = typename std::enable_if<std::is_same<T, bool>::value>::type

Return the held element values as a range of bool.

The element type of this attribute must be of integer type of bitwidth 1.

Definition at line 527 of file BuiltinAttributes.h.

◆ ComplexAPFloatValueTemplateCheckT

template<typename T >
using mlir::DenseElementsAttr::ComplexAPFloatValueTemplateCheckT = typename std::enable_if< std::is_same<T, std::complex<APFloat> >::value>::type

Return the held element values as a range of complex APFloat.

The element type of this attribute must be a complex of float type.

Definition at line 606 of file BuiltinAttributes.h.

◆ ComplexAPIntValueTemplateCheckT

template<typename T >
using mlir::DenseElementsAttr::ComplexAPIntValueTemplateCheckT = typename std::enable_if< std::is_same<T, std::complex<APInt> >::value>::type

Return the held element values as a range of complex APInts.

The element type of this attribute must be a complex of integer type.

Definition at line 570 of file BuiltinAttributes.h.

◆ ComplexValueTemplateCheckT

template<typename T , typename ElementT >
using mlir::DenseElementsAttr::ComplexValueTemplateCheckT = typename std::enable_if<detail::is_complex_t<T>::value && (std::numeric_limits<ElementT>::is_integer || is_valid_cpp_fp_type<ElementT>::value)>::type

Return the held element values as a range of std::complex.

Definition at line 424 of file BuiltinAttributes.h.

◆ DerivedAttrValueTemplateCheckT

template<typename T >
using mlir::DenseElementsAttr::DerivedAttrValueTemplateCheckT = typename std::enable_if<std::is_base_of<Attribute, T>::value && !std::is_same<Attribute, T>::value>::type

Return the held element values a range of T, where T is a derived attribute type.

Definition at line 496 of file BuiltinAttributes.h.

◆ IntFloatValueTemplateCheckT

template<typename T >
using mlir::DenseElementsAttr::IntFloatValueTemplateCheckT = typename std::enable_if<(!std::is_same<T, bool>::value && std::numeric_limits<T>::is_integer) || is_valid_cpp_fp_type<T>::value>::type

Return the held element values as a range of integer or floating-point values.

Definition at line 396 of file BuiltinAttributes.h.

◆ iterator

template<typename T , typename AttrT = DenseElementsAttr>
using mlir::DenseElementsAttr::iterator = decltype(std::declval<AttrT>().template value_begin<T>())

The iterator for the given element type T.

Definition at line 221 of file BuiltinAttributes.h.

◆ iterator_range

template<typename T , typename AttrT = DenseElementsAttr>
using mlir::DenseElementsAttr::iterator_range = decltype(std::declval<AttrT>().template getValues<T>())

The iterator range over the given element T.

Definition at line 225 of file BuiltinAttributes.h.

◆ iterator_range_impl

template<typename IteratorT >
using mlir::DenseElementsAttr::iterator_range_impl = detail::ElementsAttrRange<IteratorT>

The iterator range over the given iterator type T.

Definition at line 217 of file BuiltinAttributes.h.

◆ StringRefValueTemplateCheckT

template<typename T >
using mlir::DenseElementsAttr::StringRefValueTemplateCheckT = typename std::enable_if<std::is_same<T, StringRef>::value>::type

Return the held element values as a range of StringRef.

Definition at line 453 of file BuiltinAttributes.h.

Member Function Documentation

◆ bitcast()

DenseElementsAttr DenseElementsAttr::bitcast ( Type  newElType)

Return a new DenseElementsAttr that has the same data as the current attribute, but has bitcast elements to 'newElType'.

Return a new DenseElementsAttr that has the same data as the current attribute, but has bitcast elements such that it is now 'newType'.

The new type must have the same bitwidth as the current element type.

The new type must have the same shape and element types of the same bitwidth as the current type.

Definition at line 1009 of file BuiltinAttributes.cpp.

References mlir::detail::getDenseElementBitWidth().

◆ classof()

bool DenseElementsAttr::classof ( Attribute  attr)
static

Method for support type inquiry through isa, cast and dyn_cast.

Definition at line 672 of file BuiltinAttributes.cpp.

References mlir::Attribute::isa().

◆ complex_float_value_begin()

auto DenseElementsAttr::complex_float_value_begin ( ) const
protected

Definition at line 955 of file BuiltinAttributes.cpp.

References mlir::Type::cast(), getElementType(), and mlir::Type::isa().

◆ complex_float_value_end()

auto DenseElementsAttr::complex_float_value_end ( ) const
protected

◆ complex_value_begin()

auto DenseElementsAttr::complex_value_begin ( ) const
protected

Definition at line 916 of file BuiltinAttributes.cpp.

References getElementType(), and isComplexOfIntType().

◆ complex_value_end()

auto DenseElementsAttr::complex_value_end ( ) const
protected

Definition at line 922 of file BuiltinAttributes.cpp.

References getElementType(), getNumElements(), and isComplexOfIntType().

◆ empty()

bool mlir::DenseElementsAttr::empty ( ) const
inline

Returns if the number of elements held by this attribute is 0.

Definition at line 642 of file BuiltinAttributes.h.

◆ float_value_begin()

auto DenseElementsAttr::float_value_begin ( ) const
protected

Definition at line 937 of file BuiltinAttributes.cpp.

References mlir::Type::cast(), and getElementType().

◆ float_value_end()

auto DenseElementsAttr::float_value_end ( ) const
protected

Definition at line 941 of file BuiltinAttributes.cpp.

References mlir::Type::cast(), and getElementType().

◆ get() [1/11]

DenseElementsAttr DenseElementsAttr::get ( ShapedType  type,
ArrayRef< Attribute values 
)
static

Constructs a dense elements attribute from an array of element values.

Each element attribute value is expected to be an element of 'type'. 'type' must be a vector or tensor with static shape. If the element of type is non-integer/index/float it is assumed to be a string type.

Definition at line 676 of file BuiltinAttributes.cpp.

References mlir::Attribute::cast(), mlir::detail::getDenseElementBitWidth(), getDenseElementStorageWidth(), hasSameElementsOrSplat(), mlir::Attribute::isa(), and writeBits().

Referenced by mlir::spirv::Deserializer::collect(), mlir::constFoldUnaryOp(), convertConstantOpMmaSync(), convertStructType(), createConstantAllBitsSet(), createFPConstant(), createInitialVector(), foldExtractStridedOpFromInsertChain(), foldTransferInBoundsAttribute(), genIndexValue(), mlir::DenseFPElementsAttr::get(), mlir::DenseIntElementsAttr::get(), getBoolAttribute(), getCanonicalSliceResultType(), getDenseAttribute(), mlir::sparse_tensor::getOneAttr(), mlir::Builder::getZeroAttr(), isBoolScalarOrVector(), mlir::vector::isBroadcastableTo(), joinShapes(), ConstantTransposeOptimization::matchAndRewrite(), MaterializePadValue::matchAndRewrite(), mlirDenseElementsAttrBoolGet(), mlirDenseElementsAttrBoolSplatGet(), mlirDenseElementsAttrDoubleSplatGet(), mlirDenseElementsAttrFloatSplatGet(), mlirDenseElementsAttrGet(), mlirDenseElementsAttrInt32SplatGet(), mlirDenseElementsAttrInt64SplatGet(), mlirDenseElementsAttrInt8SplatGet(), mlirDenseElementsAttrSplatGet(), mlirDenseElementsAttrStringGet(), mlirDenseElementsAttrUInt32SplatGet(), mlirDenseElementsAttrUInt64SplatGet(), mlirDenseElementsAttrUInt8SplatGet(), parseElementAttrHexValues(), parseInferType(), mlir::detail::Parser::parseSparseElementsAttr(), replaceTransferOpWithMubuf(), vectorizeConstant(), and verifyConstantType().

◆ get() [2/11]

template<typename T , typename = typename std::enable_if< std::numeric_limits<T>::is_integer || is_valid_cpp_fp_type<T>::value>::type>
static DenseElementsAttr mlir::DenseElementsAttr::get ( const ShapedType &  type,
ArrayRef< T >  values 
)
inlinestatic

Constructs a dense integer elements attribute from an array of integer or floating-point values.

Each value is expected to be the same bitwidth of the element type of 'type'. 'type' must be a vector or tensor with static shape.

Definition at line 110 of file BuiltinAttributes.h.

◆ get() [3/11]

template<typename T , typename = typename std::enable_if< std::numeric_limits<T>::is_integer || is_valid_cpp_fp_type<T>::value || detail::is_complex_t<T>::value>::type>
static DenseElementsAttr mlir::DenseElementsAttr::get ( const ShapedType &  type,
value 
)
inlinestatic

Constructs a dense integer elements attribute from a single element.

Definition at line 122 of file BuiltinAttributes.h.

References value.

◆ get() [4/11]

template<typename T , typename ElementT = typename T::value_type, typename = typename std::enable_if< detail::is_complex_t<T>::value && (std::numeric_limits<ElementT>::is_integer || is_valid_cpp_fp_type<ElementT>::value)>::type>
static DenseElementsAttr mlir::DenseElementsAttr::get ( const ShapedType &  type,
ArrayRef< T >  values 
)
inlinestatic

Constructs a dense complex elements attribute from an array of complex values.

Each value is expected to be the same bitwidth of the element type of 'type'. 'type' must be a vector or tensor with static shape.

Definition at line 134 of file BuiltinAttributes.h.

◆ get() [5/11]

DenseElementsAttr DenseElementsAttr::get ( ShapedType  type,
ArrayRef< bool >  values 
)
static

Overload of the above 'get' method that is specialized for boolean values.

Definition at line 724 of file BuiltinAttributes.cpp.

References hasSameElementsOrSplat(), and setBit().

◆ get() [6/11]

DenseElementsAttr DenseElementsAttr::get ( ShapedType  type,
ArrayRef< StringRef >  values 
)
static

Overload of the above 'get' method that is specialized for StringRef values.

Definition at line 749 of file BuiltinAttributes.cpp.

◆ get() [7/11]

DenseElementsAttr DenseElementsAttr::get ( ShapedType  type,
ArrayRef< APInt >  values 
)
static

Constructs a dense integer elements attribute from an array of APInt values.

Each APInt value is expected to have the same bitwidth as the element type of 'type'. 'type' must be a vector or tensor with static shape.

Each APInt value is expected to have the same bitwidth as the element type of 'type'.

Definition at line 758 of file BuiltinAttributes.cpp.

References getDenseElementStorageWidth(), and hasSameElementsOrSplat().

◆ get() [8/11]

DenseElementsAttr DenseElementsAttr::get ( ShapedType  type,
ArrayRef< std::complex< APInt >>  values 
)
static

Constructs a dense complex elements attribute from an array of APInt values.

Each APInt value is expected to have the same bitwidth as the element type of 'type'. 'type' must be a vector or tensor with static shape.

Definition at line 765 of file BuiltinAttributes.cpp.

References mlir::Type::cast(), getDenseElementStorageWidth(), getElementType(), and hasSameElementsOrSplat().

◆ get() [9/11]

DenseElementsAttr DenseElementsAttr::get ( ShapedType  type,
ArrayRef< APFloat >  values 
)
static

Constructs a dense float elements attribute from an array of APFloat values.

Each APFloat value is expected to have the same bitwidth as the element type of 'type'. 'type' must be a vector or tensor with static shape.

Definition at line 779 of file BuiltinAttributes.cpp.

References getDenseElementStorageWidth(), and hasSameElementsOrSplat().

◆ get() [10/11]

DenseElementsAttr DenseElementsAttr::get ( ShapedType  type,
ArrayRef< std::complex< APFloat >>  values 
)
static

Constructs a dense complex elements attribute from an array of APFloat values.

Each APFloat value is expected to have the same bitwidth as the element type of 'type'. 'type' must be a vector or tensor with static shape.

Definition at line 787 of file BuiltinAttributes.cpp.

References mlir::Type::cast(), getDenseElementStorageWidth(), getElementType(), and hasSameElementsOrSplat().

◆ get() [11/11]

template<typename T >
static DenseElementsAttr mlir::DenseElementsAttr::get ( const ShapedType &  type,
const std::initializer_list< T > &  list 
)
inlinestatic

Construct a dense elements attribute for an initializer_list of values.

Each value is expected to be the same bitwidth of the element type of 'type'. 'type' must be a vector or tensor with static shape.

Definition at line 178 of file BuiltinAttributes.h.

◆ getComplexFloatValues()

auto DenseElementsAttr::getComplexFloatValues ( ) const
protected

◆ getComplexIntValues()

auto DenseElementsAttr::getComplexIntValues ( ) const
protected

Definition at line 909 of file BuiltinAttributes.cpp.

References getElementType(), getNumElements(), and isComplexOfIntType().

◆ getElementType()

Type DenseElementsAttr::getElementType ( ) const

◆ getFloatValues()

auto DenseElementsAttr::getFloatValues ( ) const
protected

Return the held element values as a range of APFloat.

The element type of this attribute must be of float type.

Definition at line 930 of file BuiltinAttributes.cpp.

References mlir::Type::cast(), getElementType(), and mlir::FloatType::getFloatSemantics().

◆ getFromRawBuffer()

DenseElementsAttr DenseElementsAttr::getFromRawBuffer ( ShapedType  type,
ArrayRef< char >  rawBuffer 
)
static

Construct a dense elements attribute from a raw buffer representing the data for this attribute.

Users are encouraged to use one of the constructors above, which provide more safeties. However, this constructor is useful for tools which may want to interop and can follow the precise definition.

The format of the raw buffer is a densely packed array of values that can be bitcast to the storage format of the element type specified. Types that are not byte aligned will be:

  • For bitwidth > 1: Rounded up to the next byte.
  • For bitwidth = 1: Packed into 8bit bytes with bits corresponding to the linear order of the shape type from MSB to LSB, padded to on the right.

Users should generally not use this methods as the expected buffer format may not be a form the user expects.

Definition at line 802 of file BuiltinAttributes.cpp.

Referenced by mlirDenseElementsAttrRawBufferGet(), parseElementAttrHexValues(), and verifyTensorReshapeOp().

◆ getNumElements()

int64_t DenseElementsAttr::getNumElements ( ) const

Returns the number of elements held by this attribute.

Definition at line 1041 of file BuiltinAttributes.cpp.

Referenced by convertDenseElementsAttr().

◆ getRawComplex()

DenseElementsAttr DenseElementsAttr::getRawComplex ( ShapedType  type,
ArrayRef< char >  data,
int64_t  dataEltSize,
bool  isInt,
bool  isSigned 
)
staticprotected

Overload of the raw 'get' method that asserts that the given type is of complex type.

Defaults down the subclass implementation.

This method is used to verify type invariants that the templatized 'get' method cannot.

Definition at line 871 of file BuiltinAttributes.cpp.

◆ getRawData()

ArrayRef< char > DenseElementsAttr::getRawData ( ) const

Return the raw storage data held by this attribute.

Users should generally not use this directly, as the internal storage format is not always in the form the user might expect.

Definition at line 970 of file BuiltinAttributes.cpp.

Referenced by convertDenseElementsAttr(), mlir::DenseElementsAttr::AttributeElementIterator::operator*(), mlir::DenseElementsAttr::BoolElementIterator::operator*(), mlir::DenseElementsAttr::IntElementIterator::operator*(), and verifyTensorReshapeOp().

◆ getRawIntOrFloat()

DenseElementsAttr DenseElementsAttr::getRawIntOrFloat ( ShapedType  type,
ArrayRef< char >  data,
int64_t  dataEltSize,
bool  isInt,
bool  isSigned 
)
staticprotected

Overload of the raw 'get' method that asserts that the given type is of integer or floating-point type.

This method is used to verify type invariants that the templatized 'get' method cannot.

Definition at line 878 of file BuiltinAttributes.cpp.

◆ getRawStringData()

ArrayRef< StringRef > DenseElementsAttr::getRawStringData ( ) const

Return the raw StringRef data held by this attribute.

Definition at line 974 of file BuiltinAttributes.cpp.

◆ getSplatValue() [1/2]

template<typename T >
std::enable_if<!std::is_base_of<Attribute, T>::value || std::is_same<Attribute, T>::value, T>::type mlir::DenseElementsAttr::getSplatValue ( ) const
inline

Return the splat value for this attribute.

This asserts that the attribute corresponds to a splat.

Definition at line 377 of file BuiltinAttributes.h.

References value.

Referenced by collapseGenericOpIterationDims(), convertDenseElementsAttr(), AddZeroOptimization::matchAndRewrite(), MulOneOptimization::matchAndRewrite(), and verifyMemoryOpIndexing().

◆ getSplatValue() [2/2]

template<typename T >
std::enable_if<std::is_base_of<Attribute, T>::value && !std::is_same<Attribute, T>::value, T>::type mlir::DenseElementsAttr::getSplatValue ( ) const
inline

Return the splat value for derived attribute element types.

Definition at line 386 of file BuiltinAttributes.h.

References value.

◆ getType()

ShapedType DenseElementsAttr::getType ( ) const

Return the type of this ElementsAttr, guaranteed to be a vector or tensor with static shape.

Definition at line 1033 of file BuiltinAttributes.cpp.

References mlir::Type::cast(), and mlir::Attribute::getType().

Referenced by mlir::DenseIntElementsAttr::classof(), collapseGenericOpIterationDims(), convertDenseElementsAttr(), AddZeroOptimization::matchAndRewrite(), and MulOneOptimization::matchAndRewrite().

◆ getValues() [1/10]

template<typename T , typename = IntFloatValueTemplateCheckT<T>>
iterator_range_impl<ElementIterator<T> > mlir::DenseElementsAttr::getValues ( ) const
inline

◆ getValues() [2/10]

template<typename T , typename ElementT = typename T::value_type, typename = ComplexValueTemplateCheckT<T, ElementT>>
iterator_range_impl<ElementIterator<T> > mlir::DenseElementsAttr::getValues ( ) const
inline

Definition at line 427 of file BuiltinAttributes.h.

References getNumElements(), and mlir::Attribute::getType().

◆ getValues() [3/10]

template<typename T , typename = StringRefValueTemplateCheckT<T>>
iterator_range_impl<ElementIterator<StringRef> > mlir::DenseElementsAttr::getValues ( ) const
inline

Definition at line 455 of file BuiltinAttributes.h.

References getNumElements(), and mlir::Attribute::getType().

◆ getValues() [4/10]

template<typename T , typename = AttributeValueTemplateCheckT<T>>
iterator_range_impl<AttributeElementIterator> mlir::DenseElementsAttr::getValues ( ) const
inline

Definition at line 478 of file BuiltinAttributes.h.

References mlir::Attribute::getType().

◆ getValues() [5/10]

template<typename T , typename = DerivedAttrValueTemplateCheckT<T>>
iterator_range_impl<DerivedAttributeElementIterator<T> > mlir::DenseElementsAttr::getValues ( ) const
inline

Definition at line 509 of file BuiltinAttributes.h.

References mlir::Attribute::getType().

◆ getValues() [6/10]

template<typename T , typename = BoolValueTemplateCheckT<T>>
iterator_range_impl<BoolElementIterator> mlir::DenseElementsAttr::getValues ( ) const
inline

Definition at line 529 of file BuiltinAttributes.h.

References getNumElements(), and mlir::Attribute::getType().

◆ getValues() [7/10]

template<typename T , typename = APIntValueTemplateCheckT<T>>
iterator_range_impl<IntElementIterator> mlir::DenseElementsAttr::getValues ( ) const
inline

Definition at line 551 of file BuiltinAttributes.h.

References getElementType(), and mlir::Attribute::getType().

◆ getValues() [8/10]

template<typename T , typename = ComplexAPIntValueTemplateCheckT<T>>
iterator_range_impl<ComplexIntElementIterator> mlir::DenseElementsAttr::getValues ( ) const
inline

Definition at line 572 of file BuiltinAttributes.h.

◆ getValues() [9/10]

template<typename T , typename = APFloatValueTemplateCheckT<T>>
iterator_range_impl<FloatElementIterator> mlir::DenseElementsAttr::getValues ( ) const
inline

Definition at line 590 of file BuiltinAttributes.h.

◆ getValues() [10/10]

template<typename T , typename = ComplexAPFloatValueTemplateCheckT<T>>
iterator_range_impl<ComplexFloatElementIterator> mlir::DenseElementsAttr::getValues ( ) const
inline

Definition at line 608 of file BuiltinAttributes.h.

◆ isSplat()

bool DenseElementsAttr::isSplat ( ) const

◆ isValidBool()

bool mlir::DenseElementsAttr::isValidBool ( ) const
inlineprotected

Check the information for a C++ data type, check if this type is valid for the current attribute.

This method is used to verify specific type invariants that the templatized 'getValues' method cannot.

Definition at line 715 of file BuiltinAttributes.h.

References getElementType(), and isValidIntOrFloat().

◆ isValidComplex()

bool DenseElementsAttr::isValidComplex ( int64_t  dataEltSize,
bool  isInt,
bool  isSigned 
) const
protected

Definition at line 891 of file BuiltinAttributes.cpp.

References getElementType(), and isValidIntOrFloat().

◆ isValidIntOrFloat()

bool DenseElementsAttr::isValidIntOrFloat ( int64_t  dataEltSize,
bool  isInt,
bool  isSigned 
) const
protected

Definition at line 887 of file BuiltinAttributes.cpp.

References getElementType(), and isValidIntOrFloat().

◆ isValidRawBuffer()

bool DenseElementsAttr::isValidRawBuffer ( ShapedType  type,
ArrayRef< char >  rawBuffer,
bool &  detectedSplat 
)
static

Returns true if the given buffer is a valid raw buffer for the given type.

detectedSplat is set if the buffer is valid and represents a splat buffer. The definition may be expanded over time, but currently, a splat buffer is detected if:

  • For >1bit: The buffer consists of a single element.
  • For 1bit: The buffer consists of a single byte with value 0 or 255.

User code should be prepared for additional, conformant patterns to be identified as splats in the future.

Definition at line 807 of file BuiltinAttributes.cpp.

References getDenseElementStorageWidth().

Referenced by mlirDenseElementsAttrRawBufferGet(), and parseElementAttrHexValues().

◆ mapValues() [1/2]

DenseElementsAttr 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.

The new values can represent either an integer or float. This underlying type must be an DenseIntElementsAttr.

Definition at line 1023 of file BuiltinAttributes.cpp.

◆ mapValues() [2/2]

DenseElementsAttr DenseElementsAttr::mapValues ( Type  newElementType,
function_ref< APInt(const APFloat &)>  mapping 
) const

Generates a new DenseElementsAttr by mapping each float value to a new underlying APInt.

the new values can represent either an integer or float. This underlying type must be an DenseFPElementsAttr.

Definition at line 1028 of file BuiltinAttributes.cpp.

◆ operator ElementsAttr()

mlir::DenseElementsAttr::operator ElementsAttr ( ) const
inline

Allow implicit conversion to ElementsAttr.

Definition at line 76 of file BuiltinAttributes.h.

◆ raw_int_begin()

IntElementIterator mlir::DenseElementsAttr::raw_int_begin ( ) const
inlineprotected

Iterators to various elements that require out-of-line definition.

These are hidden from the user to encourage consistent use of the getValues/value_begin/value_end API.

Definition at line 680 of file BuiltinAttributes.h.

◆ raw_int_end()

IntElementIterator mlir::DenseElementsAttr::raw_int_end ( ) const
inlineprotected

Definition at line 683 of file BuiltinAttributes.h.

References getNumElements().

◆ reshape()

DenseElementsAttr DenseElementsAttr::reshape ( ShapedType  newType)

Return a new DenseElementsAttr that has the same data as the current attribute, but has been reshaped to 'newType'.

The new type must have the same total number of elements as well as element type.

Definition at line 981 of file BuiltinAttributes.cpp.

Referenced by ReshapeConstOptimization::matchAndRewrite().

◆ resizeSplat()

DenseElementsAttr DenseElementsAttr::resizeSplat ( ShapedType  newType)

Return a new DenseElementsAttr that has the same data as the current attribute, but with a different shape for a splat type.

The new type must have the same element type.

Definition at line 993 of file BuiltinAttributes.cpp.

◆ size()

int64_t mlir::DenseElementsAttr::size ( ) const
inline

Returns the number of elements held by this attribute.

Definition at line 639 of file BuiltinAttributes.h.

References getNumElements().

◆ value_begin() [1/10]

template<typename T , typename = IntFloatValueTemplateCheckT<T>>
ElementIterator<T> mlir::DenseElementsAttr::value_begin ( ) const
inline

Definition at line 407 of file BuiltinAttributes.h.

References isValidIntOrFloat().

◆ value_begin() [2/10]

template<typename T , typename ElementT = typename T::value_type, typename = ComplexValueTemplateCheckT<T, ElementT>>
ElementIterator<T> mlir::DenseElementsAttr::value_begin ( ) const
inline

Definition at line 437 of file BuiltinAttributes.h.

◆ value_begin() [3/10]

template<typename T , typename = StringRefValueTemplateCheckT<T>>
ElementIterator<StringRef> mlir::DenseElementsAttr::value_begin ( ) const
inline

Definition at line 463 of file BuiltinAttributes.h.

◆ value_begin() [4/10]

template<typename T , typename = AttributeValueTemplateCheckT<T>>
AttributeElementIterator mlir::DenseElementsAttr::value_begin ( ) const
inline

Definition at line 483 of file BuiltinAttributes.h.

◆ value_begin() [5/10]

template<typename T , typename = DerivedAttrValueTemplateCheckT<T>>
DerivedAttributeElementIterator<T> mlir::DenseElementsAttr::value_begin ( ) const
inline

Definition at line 515 of file BuiltinAttributes.h.

◆ value_begin() [6/10]

template<typename T , typename = BoolValueTemplateCheckT<T>>
BoolElementIterator mlir::DenseElementsAttr::value_begin ( ) const
inline

Definition at line 535 of file BuiltinAttributes.h.

◆ value_begin() [7/10]

template<typename T , typename = APIntValueTemplateCheckT<T>>
IntElementIterator mlir::DenseElementsAttr::value_begin ( ) const
inline

Definition at line 556 of file BuiltinAttributes.h.

References getElementType().

◆ value_begin() [8/10]

template<typename T , typename = ComplexAPIntValueTemplateCheckT<T>>
ComplexIntElementIterator mlir::DenseElementsAttr::value_begin ( ) const
inline

Definition at line 576 of file BuiltinAttributes.h.

◆ value_begin() [9/10]

template<typename T , typename = APFloatValueTemplateCheckT<T>>
FloatElementIterator mlir::DenseElementsAttr::value_begin ( ) const
inline

Definition at line 594 of file BuiltinAttributes.h.

◆ value_begin() [10/10]

template<typename T , typename = ComplexAPFloatValueTemplateCheckT<T>>
ComplexFloatElementIterator mlir::DenseElementsAttr::value_begin ( ) const
inline

Definition at line 612 of file BuiltinAttributes.h.

◆ value_end() [1/10]

template<typename T , typename = IntFloatValueTemplateCheckT<T>>
ElementIterator<T> mlir::DenseElementsAttr::value_end ( ) const
inline

Definition at line 413 of file BuiltinAttributes.h.

References getNumElements(), isValidIntOrFloat(), and value.

◆ value_end() [2/10]

template<typename T , typename ElementT = typename T::value_type, typename = ComplexValueTemplateCheckT<T, ElementT>>
ElementIterator<T> mlir::DenseElementsAttr::value_end ( ) const
inline

Definition at line 444 of file BuiltinAttributes.h.

References getNumElements().

◆ value_end() [3/10]

template<typename T , typename = StringRefValueTemplateCheckT<T>>
ElementIterator<StringRef> mlir::DenseElementsAttr::value_end ( ) const
inline

Definition at line 468 of file BuiltinAttributes.h.

References getNumElements().

◆ value_end() [4/10]

template<typename T , typename = AttributeValueTemplateCheckT<T>>
AttributeElementIterator mlir::DenseElementsAttr::value_end ( ) const
inline

Definition at line 487 of file BuiltinAttributes.h.

References getNumElements(), and value.

◆ value_end() [5/10]

template<typename T , typename = DerivedAttrValueTemplateCheckT<T>>
DerivedAttributeElementIterator<T> mlir::DenseElementsAttr::value_end ( ) const
inline

Definition at line 519 of file BuiltinAttributes.h.

◆ value_end() [6/10]

template<typename T , typename = BoolValueTemplateCheckT<T>>
BoolElementIterator mlir::DenseElementsAttr::value_end ( ) const
inline

Definition at line 540 of file BuiltinAttributes.h.

References getNumElements().

◆ value_end() [7/10]

template<typename T , typename = APIntValueTemplateCheckT<T>>
IntElementIterator mlir::DenseElementsAttr::value_end ( ) const
inline

Definition at line 561 of file BuiltinAttributes.h.

References getElementType().

◆ value_end() [8/10]

template<typename T , typename = ComplexAPIntValueTemplateCheckT<T>>
ComplexIntElementIterator mlir::DenseElementsAttr::value_end ( ) const
inline

Definition at line 580 of file BuiltinAttributes.h.

◆ value_end() [9/10]

template<typename T , typename = APFloatValueTemplateCheckT<T>>
FloatElementIterator mlir::DenseElementsAttr::value_end ( ) const
inline

Definition at line 598 of file BuiltinAttributes.h.

◆ value_end() [10/10]

template<typename T , typename = ComplexAPFloatValueTemplateCheckT<T>>
ComplexFloatElementIterator mlir::DenseElementsAttr::value_end ( ) const
inline

Definition at line 616 of file BuiltinAttributes.h.

References getElementType(), and getNumElements().


The documentation for this class was generated from the following files: