MLIR  16.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 = std::enable_if_t<(!std::is_same< T, bool >::value &&std::numeric_limits< T >::is_integer)||is_valid_cpp_fp_type< T >::value >
 Try to get the held element values as a range of integer or floating-point values. More...
 
template<typename T , typename ElementT >
using ComplexValueTemplateCheckT = std::enable_if_t< detail::is_complex_t< T >::value &&(std::numeric_limits< ElementT >::is_integer||is_valid_cpp_fp_type< ElementT >::value)>
 Try to get the held element values as a range of std::complex. More...
 
template<typename T >
using StringRefValueTemplateCheckT = std::enable_if_t< std::is_same< T, StringRef >::value >
 Try to get the held element values as a range of StringRef. More...
 
template<typename T >
using AttributeValueTemplateCheckT = std::enable_if_t< std::is_same< T, Attribute >::value >
 Try to get the held element values as a range of Attributes. More...
 
template<typename T >
using DerivedAttrValueTemplateCheckT = std::enable_if_t< std::is_base_of< Attribute, T >::value &&!std::is_same< Attribute, T >::value >
 Try to get the held element values a range of T, where T is a derived attribute type. More...
 
template<typename T >
using BoolValueTemplateCheckT = std::enable_if_t< std::is_same< T, bool >::value >
 Try to get the held element values as a range of bool. More...
 
template<typename T >
using APIntValueTemplateCheckT = std::enable_if_t< std::is_same< T, APInt >::value >
 Try to get the held element values as a range of APInts. More...
 
template<typename T >
using ComplexAPIntValueTemplateCheckT = std::enable_if_t< std::is_same< T, std::complex< APInt > >::value >
 Try to get the held element values as a range of complex APInts. More...
 
template<typename T >
using APFloatValueTemplateCheckT = std::enable_if_t< std::is_same< T, APFloat >::value >
 Try to get the held element values as a range of APFloat. More...
 
template<typename T >
using ComplexAPFloatValueTemplateCheckT = std::enable_if_t< std::is_same< T, std::complex< APFloat > >::value >
 Try to get 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_t<!std::is_base_of< Attribute, T >::value||std::is_same< Attribute, T >::value, T > getSplatValue () const
 Return the splat value for this attribute. More...
 
template<typename T >
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. More...
 
template<typename T >
auto try_value_begin () const
 Try to get an iterator of the given type to the start of the held element values. More...
 
template<typename T >
auto try_value_end () const
 Try to get an iterator of the given type to the end of the held element values. More...
 
template<typename T >
auto getValues () const
 Return the held element values as a range of the given type. More...
 
template<typename T >
auto value_begin () const
 Get an iterator of the given type to the start of the held element values. More...
 
template<typename T >
auto value_end () const
 Get an iterator of the given type to the end of the held element values. More...
 
template<typename T , typename = IntFloatValueTemplateCheckT<T>>
FailureOr< iterator_range_impl< ElementIterator< T > > > tryGetValues () const
 
template<typename T , typename ElementT = typename T::value_type, typename = ComplexValueTemplateCheckT<T, ElementT>>
FailureOr< iterator_range_impl< ElementIterator< T > > > tryGetValues () const
 
template<typename T , typename = StringRefValueTemplateCheckT<T>>
FailureOr< iterator_range_impl< ElementIterator< StringRef > > > tryGetValues () const
 
template<typename T , typename = AttributeValueTemplateCheckT<T>>
FailureOr< iterator_range_impl< AttributeElementIterator > > tryGetValues () const
 
template<typename T , typename = DerivedAttrValueTemplateCheckT<T>>
FailureOr< iterator_range_impl< DerivedAttributeElementIterator< T > > > tryGetValues () const
 
template<typename T , typename = BoolValueTemplateCheckT<T>>
FailureOr< iterator_range_impl< BoolElementIterator > > tryGetValues () const
 
template<typename T , typename = APIntValueTemplateCheckT<T>>
FailureOr< iterator_range_impl< IntElementIterator > > tryGetValues () const
 
template<typename T , typename = ComplexAPIntValueTemplateCheckT<T>>
FailureOr< iterator_range_impl< ComplexIntElementIterator > > tryGetValues () const
 
template<typename T , typename = APFloatValueTemplateCheckT<T>>
FailureOr< iterator_range_impl< FloatElementIterator > > tryGetValues () const
 
template<typename T , typename = ComplexAPFloatValueTemplateCheckT<T>>
FailureOr< iterator_range_impl< ComplexFloatElementIterator > > tryGetValues () 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... Tys>
bool isa () const
 Casting utility functions. More...
 
template<typename... Tys>
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...
 
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, bool elideType=false) const
 Print the attribute. More...
 
void print (raw_ostream &os, AsmState &state, bool elideType=false) const
 
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...
 
ImplTypegetImpl () const
 Return the internal Attribute implementation. 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 = std::enable_if_t<std::numeric_limits<T>::is_integer || is_valid_cpp_fp_type<T>::value>>
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 = std::enable_if_t<std::numeric_limits<T>::is_integer || is_valid_cpp_fp_type<T>::value || detail::is_complex_t<T>::value>>
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 = std::enable_if_t<detail::is_complex_t<T>::value && (std::numeric_limits<ElementT>::is_integer || is_valid_cpp_fp_type<ElementT>::value)>>
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
 
FailureOr< iterator_range_impl< ComplexIntElementIterator > > tryGetComplexIntValues () const
 
FailureOr< iterator_range_impl< FloatElementIterator > > tryGetFloatValues () const
 
FailureOr< iterator_range_impl< ComplexFloatElementIterator > > tryGetComplexFloatValues () 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 76 of file BuiltinAttributes.h.

Member Typedef Documentation

◆ APFloatValueTemplateCheckT

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

Try to get the held element values as a range of APFloat.

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

Definition at line 566 of file BuiltinAttributes.h.

◆ APIntValueTemplateCheckT

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

Try to get the held element values as a range of APInts.

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

Definition at line 542 of file BuiltinAttributes.h.

◆ AttributeValueTemplateCheckT

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

Try to get the held element values as a range of Attributes.

Definition at line 489 of file BuiltinAttributes.h.

◆ BoolValueTemplateCheckT

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

Try to get 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 528 of file BuiltinAttributes.h.

◆ ComplexAPFloatValueTemplateCheckT

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

Try to get 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 576 of file BuiltinAttributes.h.

◆ ComplexAPIntValueTemplateCheckT

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

Try to get 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 555 of file BuiltinAttributes.h.

◆ ComplexValueTemplateCheckT

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

Try to get the held element values as a range of std::complex.

Definition at line 457 of file BuiltinAttributes.h.

◆ DerivedAttrValueTemplateCheckT

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

Try to get the held element values a range of T, where T is a derived attribute type.

Definition at line 503 of file BuiltinAttributes.h.

◆ IntFloatValueTemplateCheckT

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

Try to get the held element values as a range of integer or floating-point values.

Definition at line 439 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 226 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 230 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 222 of file BuiltinAttributes.h.

◆ StringRefValueTemplateCheckT

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

Try to get the held element values as a range of StringRef.

Definition at line 474 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 1301 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 988 of file BuiltinAttributes.cpp.

References mlir::Attribute::isa().

◆ empty()

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

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

Definition at line 605 of file BuiltinAttributes.h.

◆ 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 992 of file BuiltinAttributes.cpp.

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

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

◆ get() [2/11]

template<typename T , typename = std::enable_if_t<std::numeric_limits<T>::is_integer || is_valid_cpp_fp_type<T>::value>>
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 115 of file BuiltinAttributes.h.

◆ get() [3/11]

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

Constructs a dense integer elements attribute from a single element.

Definition at line 127 of file BuiltinAttributes.h.

References value.

◆ get() [4/11]

template<typename T , typename ElementT = typename T::value_type, typename = std::enable_if_t<detail::is_complex_t<T>::value && (std::numeric_limits<ElementT>::is_integer || is_valid_cpp_fp_type<ElementT>::value)>>
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 139 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 1042 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 1067 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 1076 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 1083 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 1097 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 1105 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 183 of file BuiltinAttributes.h.

◆ getElementType()

Type DenseElementsAttr::getElementType ( ) const

◆ 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 1120 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 1333 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 1189 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 1262 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 1196 of file BuiltinAttributes.cpp.

◆ getRawStringData()

ArrayRef< StringRef > DenseElementsAttr::getRawStringData ( ) const

Return the raw StringRef data held by this attribute.

Definition at line 1266 of file BuiltinAttributes.cpp.

◆ getSplatValue() [1/2]

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

Return the splat value for this attribute.

This asserts that the attribute corresponds to a splat.

Definition at line 382 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_t<std::is_base_of<Attribute, T>::value && !std::is_same<Attribute, T>::value, T> mlir::DenseElementsAttr::getSplatValue ( ) const
inline

Return the splat value for derived attribute element types.

Definition at line 391 of file BuiltinAttributes.h.

◆ getType()

ShapedType DenseElementsAttr::getType ( ) const

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

Definition at line 1325 of file BuiltinAttributes.cpp.

Referenced by mlir::detail::DenseResourceElementsAttrBase< T >::classof(), collapseGenericOpIterationDims(), convertDenseElementsAttr(), AddZeroOptimization::matchAndRewrite(), and MulOneOptimization::matchAndRewrite().

◆ getValues()

template<typename T >
auto mlir::DenseElementsAttr::getValues ( ) const
inline

Return the held element values as a range of the given type.

Definition at line 415 of file BuiltinAttributes.h.

References mlir::succeeded().

◆ 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 674 of file BuiltinAttributes.h.

References getElementType(), and isValidIntOrFloat().

◆ isValidComplex()

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

Definition at line 1209 of file BuiltinAttributes.cpp.

References getElementType(), and isValidIntOrFloat().

◆ isValidIntOrFloat()

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

Definition at line 1205 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 1125 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 1315 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 1320 of file BuiltinAttributes.cpp.

◆ operator ElementsAttr()

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

Allow implicit conversion to ElementsAttr.

Definition at line 81 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 643 of file BuiltinAttributes.h.

◆ raw_int_end()

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

Definition at line 646 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 1273 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 1285 of file BuiltinAttributes.cpp.

◆ size()

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

Returns the number of elements held by this attribute.

Definition at line 602 of file BuiltinAttributes.h.

References getNumElements().

◆ try_value_begin()

template<typename T >
auto mlir::DenseElementsAttr::try_value_begin ( ) const
inline

Try to get an iterator of the given type to the start of the held element values.

Return failure if the type cannot be iterated.

Definition at line 398 of file BuiltinAttributes.h.

References mlir::failed(), and mlir::failure().

◆ try_value_end()

template<typename T >
auto mlir::DenseElementsAttr::try_value_end ( ) const
inline

Try to get an iterator of the given type to the end of the held element values.

Return failure if the type cannot be iterated.

Definition at line 407 of file BuiltinAttributes.h.

References mlir::failed(), and mlir::failure().

◆ tryGetComplexFloatValues()

auto DenseElementsAttr::tryGetComplexFloatValues ( ) const
protected

◆ tryGetComplexIntValues()

auto DenseElementsAttr::tryGetComplexIntValues ( ) const
protected

◆ tryGetFloatValues()

auto DenseElementsAttr::tryGetFloatValues ( ) const
protected

Definition at line 1236 of file BuiltinAttributes.cpp.

References mlir::Type::dyn_cast(), mlir::failure(), and getElementType().

◆ tryGetValues() [1/10]

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

Definition at line 441 of file BuiltinAttributes.h.

References mlir::failure(), getNumElements(), isValidIntOrFloat(), and value.

◆ tryGetValues() [2/10]

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

Definition at line 460 of file BuiltinAttributes.h.

References mlir::failure(), and getNumElements().

◆ tryGetValues() [3/10]

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

Definition at line 477 of file BuiltinAttributes.h.

References getNumElements().

◆ tryGetValues() [4/10]

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

Definition at line 492 of file BuiltinAttributes.h.

References getNumElements(), and value.

◆ tryGetValues() [5/10]

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

Definition at line 517 of file BuiltinAttributes.h.

◆ tryGetValues() [6/10]

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

Definition at line 530 of file BuiltinAttributes.h.

References mlir::failure(), and getNumElements().

◆ tryGetValues() [7/10]

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

Definition at line 544 of file BuiltinAttributes.h.

References mlir::failure(), and getElementType().

◆ tryGetValues() [8/10]

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

Definition at line 558 of file BuiltinAttributes.h.

◆ tryGetValues() [9/10]

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

Definition at line 568 of file BuiltinAttributes.h.

◆ tryGetValues() [10/10]

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

Definition at line 579 of file BuiltinAttributes.h.

References getElementType(), and getNumElements().

◆ value_begin()

template<typename T >
auto mlir::DenseElementsAttr::value_begin ( ) const
inline

Get an iterator of the given type to the start of the held element values.

Definition at line 423 of file BuiltinAttributes.h.

◆ value_end()

template<typename T >
auto mlir::DenseElementsAttr::value_end ( ) const
inline

Get an iterator of the given type to the end of the held element values.

Definition at line 429 of file BuiltinAttributes.h.

References value.


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