MLIR  20.0.0git
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
mlir::Attribute Class Reference

Attributes are known-constant values of operations. More...

#include "mlir/IR/Attributes.h"

+ Inheritance diagram for mlir::Attribute:

Public Types

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

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 Attribute getFromOpaquePointer (const void *ptr)
 Construct an attribute from the opaque pointer representation. More...
 

Protected Attributes

ImplTypeimpl {nullptr}
 

Friends

::llvm::hash_code hash_value (Attribute arg)
 

Detailed Description

Attributes are known-constant values of operations.

Instances of the Attribute class are references to immortal key-value pairs with immutable, uniqued keys owned by MLIRContext. As such, an Attribute is a thin wrapper around an underlying storage pointer. Attributes are usually passed by value.

Definition at line 25 of file Attributes.h.

Member Typedef Documentation

◆ AbstractTy

Definition at line 35 of file Attributes.h.

◆ AttrBase

template<typename ConcreteType , typename BaseType , typename StorageType , template< typename T > class... Traits>
using mlir::Attribute::AttrBase = detail::StorageUserBase<ConcreteType, BaseType, StorageType, detail::AttributeUniquer, Traits...>

Utility class for implementing attributes.

Definition at line 30 of file Attributes.h.

◆ ImplType

Definition at line 33 of file Attributes.h.

◆ ValueType

Definition at line 34 of file Attributes.h.

Constructor & Destructor Documentation

◆ Attribute() [1/3]

constexpr mlir::Attribute::Attribute ( )
constexprdefault

Referenced by getFromOpaquePointer().

◆ Attribute() [2/3]

mlir::Attribute::Attribute ( const ImplType impl)
inline

Definition at line 38 of file Attributes.h.

◆ Attribute() [3/3]

mlir::Attribute::Attribute ( const Attribute other)
default

Member Function Documentation

◆ cast()

template<typename U >
U mlir::Attribute::cast

Definition at line 194 of file Attributes.h.

◆ dump()

void Attribute::dump ( ) const

Definition at line 3788 of file AsmPrinter.cpp.

◆ dyn_cast()

template<typename U >
U mlir::Attribute::dyn_cast

Definition at line 184 of file Attributes.h.

◆ dyn_cast_or_null()

template<typename U >
U mlir::Attribute::dyn_cast_or_null

Definition at line 189 of file Attributes.h.

◆ getAbstractAttribute()

const AbstractTy& mlir::Attribute::getAbstractAttribute ( ) const
inline

◆ getAsOpaquePointer()

const void* mlir::Attribute::getAsOpaquePointer ( ) const
inline

Get an opaque pointer to the attribute.

Definition at line 91 of file Attributes.h.

References impl.

Referenced by llvm::PointerLikeTypeTraits< mlir::Attribute >::getAsVoidPointer().

◆ getContext()

MLIRContext * Attribute::getContext ( ) const

◆ getDialect()

Dialect Attribute::getDialect ( ) const
inline

Get the dialect this attribute is registered to.

Definition at line 76 of file Attributes.h.

Referenced by mlir::AttributeInterface< ConcreteType, Traits >::getInterfaceFor(), hasPromiseOrImplementsInterface(), and mlir::detail::isSupportedMemorySpace().

◆ getFromOpaquePointer()

static Attribute mlir::Attribute::getFromOpaquePointer ( const void *  ptr)
inlinestatic

◆ getImpl()

ImplType* mlir::Attribute::getImpl ( ) const
inline

◆ getTypeID()

TypeID mlir::Attribute::getTypeID ( )
inline

Return a unique identifier for the concrete attribute type.

This is used to support dynamic type casting.

Definition at line 70 of file Attributes.h.

Referenced by getBases(), mlir::AttributeInterface< ConcreteType, Traits >::getInterfaceFor(), hasPromiseOrImplementsInterface(), mlir::DynamicAttr::isa(), and mlir::irdl::BaseAttrConstraint::verify().

◆ hasPromiseOrImplementsInterface()

template<typename InterfaceT >
bool mlir::Attribute::hasPromiseOrImplementsInterface ( )
inline

Returns true if InterfaceT has been promised by the dialect or implemented.

Definition at line 102 of file Attributes.h.

References getDialect(), getTypeID(), and mlir::dialect_extension_detail::hasPromisedInterface().

◆ hasTrait()

template<template< typename T > class Trait>
bool mlir::Attribute::hasTrait ( )
inline

Returns true if the type was registered with a particular trait.

Definition at line 110 of file Attributes.h.

References getAbstractAttribute(), and mlir::AbstractAttribute::hasTrait().

Referenced by mlir::DynamicAttr::classof(), and mlir::LocationAttr::classof().

◆ isa()

template<typename... Tys>
bool mlir::Attribute::isa

Casting utility functions.

These are deprecated and will be removed, please prefer using the llvm namespace variants instead.

Definition at line 174 of file Attributes.h.

◆ isa_and_nonnull()

template<typename... Tys>
bool mlir::Attribute::isa_and_nonnull

Definition at line 179 of file Attributes.h.

◆ operator bool()

mlir::Attribute::operator bool ( ) const
inlineexplicit

Definition at line 46 of file Attributes.h.

References impl.

◆ operator!()

bool mlir::Attribute::operator! ( ) const
inline

Definition at line 48 of file Attributes.h.

◆ operator!=()

bool mlir::Attribute::operator!= ( Attribute  other) const
inline

Definition at line 45 of file Attributes.h.

◆ operator=()

Attribute& mlir::Attribute::operator= ( const Attribute other)
default

◆ operator==()

bool mlir::Attribute::operator== ( Attribute  other) const
inline

Definition at line 44 of file Attributes.h.

References impl.

◆ print() [1/2]

void Attribute::print ( raw_ostream &  os,
AsmState state,
bool  elideType = false 
) const

Definition at line 3781 of file AsmPrinter.cpp.

◆ print() [2/2]

void Attribute::print ( raw_ostream &  os,
bool  elideType = false 
) const

Print the attribute.

If elideType is set, the attribute is printed without a trailing colon type if it has one.

Definition at line 3772 of file AsmPrinter.cpp.

Referenced by mlir::operator<<(), mlir::detail::DenseArrayAttrImpl< T >::print(), and mlir::dataflow::ConstantValue::print().

◆ printStripped() [1/2]

void Attribute::printStripped ( raw_ostream &  os) const

Print the attribute without dialect wrapping.

Definition at line 3814 of file AsmPrinter.cpp.

◆ printStripped() [2/2]

void Attribute::printStripped ( raw_ostream &  os,
AsmState state 
) const

Definition at line 3793 of file AsmPrinter.cpp.

◆ replace()

template<typename... ReplacementFns>
auto mlir::Attribute::replace ( ReplacementFns &&...  replacementFns)
inline

Recursively replace all of the nested sub-attributes and sub-types using the provided map functions.

Returns nullptr in the case of failure. See AttrTypeReplacer for information on the support replacement function types.

Definition at line 154 of file Attributes.h.

References mlir::detail::AttrTypeReplacerBase< Concrete >::addReplacement(), and mlir::AttrTypeReplacer::replace().

◆ replaceImmediateSubElements()

auto mlir::Attribute::replaceImmediateSubElements ( ArrayRef< Attribute replAttrs,
ArrayRef< Type replTypes 
) const
inline

Replace the immediately nested sub-attributes and sub-types with those provided.

The order of the provided elements is derived from the order of the elements returned by the callbacks of walkImmediateSubElements. The element at index 0 would replace the very first attribute given by walkImmediateSubElements. On success, the new instance with the values replaced is returned. If replacement fails, nullptr is returned.

Definition at line 133 of file Attributes.h.

References getAbstractAttribute(), and mlir::AbstractAttribute::replaceImmediateSubElements().

◆ walk()

template<WalkOrder Order = WalkOrder::PostOrder, typename... WalkFns>
auto mlir::Attribute::walk ( WalkFns &&...  walkFns)
inline

Walk this attribute and all attibutes/types nested within using the provided walk functions.

See AttrTypeWalker for information on the supported walk function types.

Definition at line 143 of file Attributes.h.

References mlir::AttrTypeWalker::addWalk(), and mlir::AttrTypeWalker::walk().

◆ walkImmediateSubElements()

void mlir::Attribute::walkImmediateSubElements ( function_ref< void(Attribute)>  walkAttrsFn,
function_ref< void(Type)>  walkTypesFn 
) const
inline

Walk all of the immediately nested sub-attributes and sub-types.

This method does not recurse into sub elements.

Definition at line 121 of file Attributes.h.

References getAbstractAttribute(), and mlir::AbstractAttribute::walkImmediateSubElements().

Friends And Related Function Documentation

◆ hash_value

::llvm::hash_code hash_value ( Attribute  arg)
friend

Definition at line 198 of file Attributes.h.

Member Data Documentation

◆ impl

ImplType* mlir::Attribute::impl {nullptr}
protected

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