MLIR 22.0.0git
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
 Utility class for implementing attributes.
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
TypeID getTypeID ()
 Return a unique identifier for the concrete attribute type.
MLIRContextgetContext () const
 Return the context this attribute belongs to.
DialectgetDialect () const
 Get the dialect this attribute is registered to.
void print (raw_ostream &os, bool elideType=false) const
 Print the attribute.
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.
void printStripped (raw_ostream &os, AsmState &state) const
const voidgetAsOpaquePointer () const
 Get an opaque pointer to the attribute.
friend::llvm::hash_code hash_value (Attribute arg)
template<typename InterfaceT>
bool hasPromiseOrImplementsInterface ()
 Returns true if InterfaceT has been promised by the dialect or implemented.
template<template< typename T > class Trait>
bool hasTrait ()
 Returns true if the type was registered with a particular trait.
const AbstractTygetAbstractAttribute () const
 Return the abstract descriptor for this attribute.
void walkImmediateSubElements (function_ref< void(Attribute)> walkAttrsFn, function_ref< void(Type)> walkTypesFn) const
 Walk all of the immediately nested sub-attributes and sub-types.
auto replaceImmediateSubElements (ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
 Replace the immediately nested sub-attributes and sub-types with those provided.
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.
template<typename... ReplacementFns>
auto replace (ReplacementFns &&...replacementFns)
 Recursively replace all of the nested sub-attributes and sub-types using the provided map functions.
ImplTypegetImpl () const
 Return the internal Attribute implementation.

Static Public Member Functions

static Attribute getFromOpaquePointer (const void *ptr)
 Construct an attribute from the opaque pointer representation.

Protected Attributes

ImplTypeimpl {nullptr}

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
Initial value:
detail::StorageUserBase<ConcreteType, BaseType, StorageType,
Utility class for implementing users of storage classes uniqued by a StorageUniquer.

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]

mlir::Attribute::Attribute ( )
constexprdefault

◆ 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

References Attribute().

Member Function Documentation

◆ dump()

void Attribute::dump ( ) const

Definition at line 3949 of file AsmPrinter.cpp.

References print().

◆ 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 73 of file Attributes.h.

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

◆ getContext()

◆ getDialect()

◆ getFromOpaquePointer()

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

◆ getImpl()

◆ 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 52 of file Attributes.h.

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

◆ hash_value()

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

References Attribute().

◆ hasPromiseOrImplementsInterface()

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

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

Definition at line 84 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 92 of file Attributes.h.

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

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

◆ operator bool()

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

Definition at line 46 of file Attributes.h.

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

References Attribute().

◆ operator=()

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

References Attribute().

◆ operator==()

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

Definition at line 44 of file Attributes.h.

References Attribute(), and impl.

◆ print() [1/2]

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

◆ 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 3933 of file AsmPrinter.cpp.

References getContext(), and print().

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

◆ printStripped() [1/2]

void Attribute::printStripped ( raw_ostream & os) const

Print the attribute without dialect wrapping.

Definition at line 3975 of file AsmPrinter.cpp.

References getContext(), and printStripped().

Referenced by printStripped().

◆ printStripped() [2/2]

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

◆ 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 136 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 115 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 125 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 103 of file Attributes.h.

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

Member Data Documentation

◆ impl

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

Definition at line 147 of file Attributes.h.

Referenced by mlir::hash_value(), and operator==().


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