MLIR  19.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:

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...
 
 operator TypedAttr () const
 Allow implicit conversion to TypedAttr. 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...
 
constexpr Attribute ()=default
 
 Attribute (const ImplType *impl)
 
 Attribute (const Attribute &other)=default
 
- Public Member Functions inherited from mlir::Attribute
constexpr Attribute ()=default
 
 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
 
void printStripped (raw_ostream &os) const
 Print the attribute without dialect wrapping. More...
 
void printStripped (raw_ostream &os, AsmState &state) const
 
const void * getAsOpaquePointer () const
 Get an opaque pointer to the attribute. More...
 
template<typename InterfaceT >
bool hasPromiseOrImplementsInterface ()
 Returns true if InterfaceT has been promised by the dialect or implemented. 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...
 
void walkImmediateSubElements (function_ref< void(Attribute)> walkAttrsFn, function_ref< void(Type)> walkTypesFn) const
 Walk all of the immediately nested sub-attributes and sub-types. More...
 
auto replaceImmediateSubElements (ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
 Replace the immediately nested sub-attributes and sub-types with those provided. More...
 
template<WalkOrder Order = WalkOrder::PostOrder, typename... WalkFns>
auto walk (WalkFns &&...walkFns)
 Walk this attribute and all attibutes/types nested within using the provided walk functions. More...
 
template<typename... ReplacementFns>
auto replace (ReplacementFns &&...replacementFns)
 Recursively replace all of the nested sub-attributes and sub-types using the provided map functions. 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 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 82 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 571 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 547 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 494 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 533 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 581 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 560 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 460 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 507 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 442 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 232 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 235 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 228 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 479 of file BuiltinAttributes.h.

Member Function Documentation

◆ Attribute() [1/3]

constexpr mlir::Attribute::Attribute
constexprdefault

◆ Attribute() [2/3]

mlir::Attribute::Attribute
default

◆ Attribute() [3/3]

mlir::Attribute::Attribute
inline

Definition at line 38 of file Attributes.h.

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

References mlir::detail::getDenseElementBitWidth(), getRawData(), and getType().

◆ classof()

bool DenseElementsAttr::classof ( Attribute  attr)
static

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

Definition at line 890 of file BuiltinAttributes.cpp.

◆ empty()

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

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

Definition at line 611 of file BuiltinAttributes.h.

References size().

◆ get() [1/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 121 of file BuiltinAttributes.h.

References getRawIntOrFloat().

◆ get() [2/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 145 of file BuiltinAttributes.h.

References getRawComplex().

◆ get() [3/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 189 of file BuiltinAttributes.h.

References get().

◆ get() [4/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 133 of file BuiltinAttributes.h.

References get().

◆ get() [5/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 1033 of file BuiltinAttributes.cpp.

References getDenseElementStorageWidth(), and hasSameElementsOrSplat().

◆ get() [6/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 1012 of file BuiltinAttributes.cpp.

References getDenseElementStorageWidth(), and hasSameElementsOrSplat().

◆ get() [7/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 894 of file BuiltinAttributes.cpp.

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

Referenced by binaryFolder(), mlir::constFoldBinaryOpConditional(), createConst(), createConstantAllBitsSet(), createFloatConst(), createFPConstant(), createIntConst(), mlir::LLVM::createPrintStrCall(), mlir::createScalarOrSplatConstant(), mlir::DenseFPElementsAttr::get(), mlir::DenseIntElementsAttr::get(), get(), getBoolAttribute(), getDenseAttribute(), mlir::sparse_tensor::getOneAttr(), mlir::Builder::getOneAttr(), getScalarOrVectorConstInt(), mlir::Builder::getZeroAttr(), mlirDenseElementsAttrBoolGet(), mlirDenseElementsAttrBoolSplatGet(), mlirDenseElementsAttrDoubleSplatGet(), mlirDenseElementsAttrFloatSplatGet(), mlirDenseElementsAttrGet(), mlirDenseElementsAttrInt32SplatGet(), mlirDenseElementsAttrInt64SplatGet(), mlirDenseElementsAttrInt8SplatGet(), mlirDenseElementsAttrSplatGet(), mlirDenseElementsAttrStringGet(), mlirDenseElementsAttrUInt32SplatGet(), mlirDenseElementsAttrUInt64SplatGet(), mlirDenseElementsAttrUInt8SplatGet(), mlir::detail::DenseArrayAttrImpl< T >::parse(), mlir::detail::Parser::parseSparseElementsAttr(), and mlir::detail::DenseArrayAttrImpl< T >::parseWithoutBraces().

◆ get() [8/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 978 of file BuiltinAttributes.cpp.

References mlir::detail::divideCeil(), hasSameElementsOrSplat(), isSplat(), and setBit().

◆ get() [9/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 1041 of file BuiltinAttributes.cpp.

References getDenseElementStorageWidth(), and hasSameElementsOrSplat().

◆ get() [10/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 1019 of file BuiltinAttributes.cpp.

References getDenseElementStorageWidth(), and hasSameElementsOrSplat().

◆ get() [11/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 1003 of file BuiltinAttributes.cpp.

References mlir::get().

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

Referenced by mlirDenseElementsAttrRawBufferGet().

◆ getNumElements()

int64_t DenseElementsAttr::getNumElements ( ) const

Returns the number of elements held by this attribute.

Definition at line 1291 of file BuiltinAttributes.cpp.

References getType().

Referenced by convertDenseElementsAttr(), raw_int_end(), size(), tryGetComplexFloatValues(), tryGetComplexIntValues(), and tryGetValues().

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

Referenced by get().

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

References mlir::Attribute::impl.

Referenced by bitcast(), convertDenseElementsAttr(), mlir::detail::DenseArrayAttrImpl< T >::operator ArrayRef< T >(), reshape(), resizeSplat(), and tryGetValues().

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

Referenced by get().

◆ getRawStringData()

ArrayRef< StringRef > DenseElementsAttr::getRawStringData ( ) const

Return the raw StringRef data held by this attribute.

Definition at line 1222 of file BuiltinAttributes.cpp.

References mlir::Attribute::impl.

Referenced by tryGetValues().

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

References isSplat().

Referenced by binaryFolder(), convertDenseElementsAttr(), isSplatOne(), isSplatZero(), and reshapeConstantSource().

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

◆ getType()

ShapedType DenseElementsAttr::getType ( ) const

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

References mlir::succeeded().

◆ isSplat()

bool DenseElementsAttr::isSplat ( ) const

Returns true if this attribute corresponds to a splat, i.e.

if all element values are the same.

Definition at line 1174 of file BuiltinAttributes.cpp.

References mlir::Attribute::impl.

Referenced by binaryFolder(), convertDenseElementsAttr(), get(), getSplatValue(), isSplatOne(), isSplatZero(), reshapeConstantSource(), resizeSplat(), and tryGetValues().

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

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

Referenced by tryGetValues().

◆ isValidComplex()

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

Definition at line 1165 of file BuiltinAttributes.cpp.

References getElementType(), and isValidIntOrFloat().

Referenced by tryGetValues().

◆ isValidIntOrFloat()

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

Definition at line 1161 of file BuiltinAttributes.cpp.

References getElementType(), and isValidIntOrFloat().

Referenced by tryGetValues().

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

References getDenseElementStorageWidth().

Referenced by mlirDenseElementsAttrRawBufferGet().

◆ mapValues() [1/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 1277 of file BuiltinAttributes.cpp.

References mapValues().

◆ mapValues() [2/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 1271 of file BuiltinAttributes.cpp.

References mapValues().

Referenced by mapValues().

◆ operator ElementsAttr()

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

Allow implicit conversion to ElementsAttr.

Definition at line 87 of file BuiltinAttributes.h.

◆ operator TypedAttr()

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

Allow implicit conversion to TypedAttr.

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

Referenced by tryGetFloatValues(), and tryGetValues().

◆ raw_int_end()

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

Definition at line 652 of file BuiltinAttributes.h.

References getNumElements().

Referenced by tryGetFloatValues(), and tryGetValues().

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

References getRawData(), and getType().

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

References getRawData(), getType(), and isSplat().

Referenced by reshapeConstantSource().

◆ size()

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

Returns the number of elements held by this attribute.

Definition at line 608 of file BuiltinAttributes.h.

References getNumElements().

Referenced by empty().

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

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

◆ tryGetComplexFloatValues()

auto DenseElementsAttr::tryGetComplexFloatValues ( ) const
protected

Definition at line 1203 of file BuiltinAttributes.cpp.

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

Referenced by tryGetValues().

◆ tryGetComplexIntValues()

auto DenseElementsAttr::tryGetComplexIntValues ( ) const
protected

◆ tryGetFloatValues()

auto DenseElementsAttr::tryGetFloatValues ( ) const
protected

Definition at line 1192 of file BuiltinAttributes.cpp.

References mlir::failure(), getElementType(), getType(), raw_int_begin(), and raw_int_end().

Referenced by tryGetValues().

◆ tryGetValues() [1/10]

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

◆ 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

◆ tryGetValues() [3/10]

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

Definition at line 483 of file BuiltinAttributes.h.

References getNumElements(), getRawStringData(), getType(), and isSplat().

◆ tryGetValues() [4/10]

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

Definition at line 498 of file BuiltinAttributes.h.

References getNumElements(), and getType().

◆ tryGetValues() [5/10]

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

Definition at line 523 of file BuiltinAttributes.h.

References getType().

◆ tryGetValues() [6/10]

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

Definition at line 536 of file BuiltinAttributes.h.

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

◆ tryGetValues() [7/10]

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

◆ tryGetValues() [8/10]

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

Definition at line 564 of file BuiltinAttributes.h.

References tryGetComplexIntValues().

◆ tryGetValues() [9/10]

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

Definition at line 574 of file BuiltinAttributes.h.

References tryGetFloatValues().

◆ tryGetValues() [10/10]

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

Definition at line 585 of file BuiltinAttributes.h.

References tryGetComplexFloatValues().

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


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