9#ifndef MLIR_IR_ATTRIBUTES_H
10#define MLIR_IR_ATTRIBUTES_H
13#include "llvm/Support/PointerLikeTypeTraits.h"
28 template <
typename ConcreteType,
typename BaseType,
typename StorageType,
29 template <
typename T>
class... Traits>
46 explicit operator bool()
const {
return impl; }
59 return impl->getAbstractAttribute().getDialect();
83 template <
typename InterfaceT>
87 mlir::isa<InterfaceT>(*
this);
91 template <
template <
typename T>
class Trait>
98 return impl->getAbstractAttribute();
125 auto walk(WalkFns &&...walkFns) {
127 (walker.
addWalk(std::forward<WalkFns>(walkFns)), ...);
128 return walker.
walk<Order>(*this);
135 template <
typename... ReplacementFns>
136 auto replace(ReplacementFns &&...replacementFns) {
138 (replacer.
addReplacement(std::forward<ReplacementFns>(replacementFns)),
140 return replacer.
replace(*
this);
182 void setName(StringAttr newName);
186 assert(value &&
"expected valid attribute value");
196 return name ==
rhs.name && value ==
rhs.value;
205 friend DenseMapInfo<NamedAttribute>;
215 using AttrPairT = std::pair<Attribute, Attribute>;
222 template <
typename T>
224 walker.
walk(param.getName());
225 walker.
walk(param.getValue());
227 template <
typename T>
231 return T(cast<
decltype(param.getName())>(paramRepls[0]), paramRepls[1]);
241template <
typename ConcreteType,
template <
typename>
class TraitType>
251template <
typename ConcreteType,
typename Traits>
254 AttributeTrait::TraitBase> {
269 llvm::getTypeName<ConcreteType>());
287template <
typename ConcreteType>
293template <
typename ConcreteType>
322 T, std::enable_if_t<std::is_base_of<mlir::Attribute, T>::value &&
323 !mlir::detail::IsInterface<T>::value>>
327 return T::getFromOpaquePointer(pointer);
331 return T::getFromOpaquePointer(pointer);
337struct PointerLikeTypeTraits<
mlir::Attribute> {
368template <
typename To,
typename From>
370 std::enable_if_t<std::is_same_v<mlir::Attribute,
371 std::remove_const_t<From>> ||
372 std::is_base_of_v<mlir::Attribute, From>>>
385 if constexpr (std::is_base_of_v<To, From>) {
388 return To::classof(ty);
This class contains all of the static information common to all instances of a registered Attribute.
bool hasTrait() const
Returns true if the attribute has a particular trait.
T::Concept * getInterface() const
Returns an instance of the concept object for the given interface if it was registered to this attrib...
void walkImmediateSubElements(Attribute attr, function_ref< void(Attribute)> walkAttrsFn, function_ref< void(Type)> walkTypesFn) const
Walk the immediate sub-elements of this attribute.
Attribute replaceImmediateSubElements(Attribute attr, ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
Replace the immediate sub-elements of this attribute.
This class provides management for the lifetime of the state used when printing the IR.
This is an attribute/type replacer that is naively cached.
Attribute replace(Attribute attr)
ArrayRef< T > take_front(unsigned n)
Take the first N replacements as an ArrayRef, dropping them from this replacement list.
void addWalk(WalkFn< Attribute > &&fn)
Register a walk function for a given attribute or type.
WalkResult walk(T element)
Walk the given attribute/type, and recursively walk any sub elements.
This class represents the base of an attribute interface.
detail::Interface< ConcreteType, Attribute, Traits, Attribute, AttributeTrait::TraitBase > InterfaceBase
AttributeInterface< ConcreteType, Traits > Base
static InterfaceBase::Concept * getInterfaceFor(Attribute attr)
Returns the impl interface instance for the given type.
Base storage class appearing in an attribute.
Attributes are known-constant values of operations.
detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::AttributeUniquer, Traits... > AttrBase
Utility class for implementing attributes.
Dialect & getDialect() const
Get the dialect this attribute is registered to.
friend::llvm::hash_code hash_value(Attribute arg)
AbstractAttribute AbstractTy
auto walk(WalkFns &&...walkFns)
Walk this attribute and all attibutes/types nested within using the provided walk functions.
const void * getAsOpaquePointer() const
Get an opaque pointer to the attribute.
Attribute(const ImplType *impl)
constexpr Attribute()=default
ImplType * getImpl() const
Return the internal Attribute implementation.
void printStripped(raw_ostream &os) const
Print the attribute without dialect wrapping.
bool operator==(Attribute other) const
void print(raw_ostream &os, bool elideType=false) const
Print the attribute.
auto replace(ReplacementFns &&...replacementFns)
Recursively replace all of the nested sub-attributes and sub-types using the provided map functions.
void walkImmediateSubElements(function_ref< void(Attribute)> walkAttrsFn, function_ref< void(Type)> walkTypesFn) const
Walk all of the immediately nested sub-attributes and sub-types.
bool operator!=(Attribute other) const
Attribute & operator=(const Attribute &other)=default
MLIRContext * getContext() const
Return the context this attribute belongs to.
auto replaceImmediateSubElements(ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
Replace the immediately nested sub-attributes and sub-types with those provided.
AttributeStorage ImplType
const AbstractTy & getAbstractAttribute() const
Return the abstract descriptor for this attribute.
bool hasTrait()
Returns true if the type was registered with a particular trait.
Attribute(const Attribute &other)=default
bool hasPromiseOrImplementsInterface()
Returns true if InterfaceT has been promised by the dialect or implemented.
TypeID getTypeID()
Return a unique identifier for the concrete attribute type.
static Attribute getFromOpaquePointer(const void *ptr)
Construct an attribute from the opaque pointer representation.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
MLIRContext is the top-level object for a collection of MLIR operations.
NamedAttribute represents a combination of a name and an Attribute value.
StringAttr getName() const
Return the name of the attribute.
void setName(StringAttr newName)
Set the name of this attribute.
bool operator==(const NamedAttribute &rhs) const
bool operator<(const NamedAttribute &rhs) const
Compare this attribute to the provided attribute, ordering by name.
NamedAttribute(StringAttr name, Attribute value)
Dialect * getNameDialect() const
Return the dialect of the name of this attribute, if the name is prefixed by a dialect namespace.
void setValue(Attribute newValue)
Set the value of this attribute.
Attribute getValue() const
Return the value of the attribute.
bool operator!=(const NamedAttribute &rhs) const
This class provides an efficient unique identifier for a specific C++ type.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
void addReplacement(ReplaceFn< Attribute > fn)
AttrTypeReplacerBase.
This class represents an abstract interface.
Interface< ConcreteType, Attribute, Traits, Attribute, AttributeTrait::TraitBase > InterfaceBase
typename Traits::Concept Concept
Utility class for implementing users of storage classes uniqued by a StorageUniquer.
Helper class for implementing traits for storage classes.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
This trait is used to determine if an attribute is a dynamic attribute or not; it should only be impl...
detail::StorageUserTrait::IsMutable< ConcreteType > IsMutable
This trait is used to determine if an attribute is mutable or not.
detail::StorageUserTraitBase< ConcreteType, TraitType > TraitBase
This class represents the base of an attribute trait.
bool hasPromisedInterface(Dialect &dialect, TypeID interfaceRequestorID, TypeID interfaceID)
Checks if a promise has been made for the interface/requestor pair.
void handleUseOfUndefinedPromisedInterface(Dialect &dialect, TypeID interfaceRequestorID, TypeID interfaceID, StringRef interfaceName)
Checks if the given interface, which is attempting to be used, is a promised interface of this dialec...
Include the generated interface declarations.
llvm::DenseMapInfo< T, Enable > DenseMapInfo
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
WalkOrder
Traversal order for region, block and operation walk utilities.
AttrTypeSubElementReplacements< Attribute > AttrSubElementReplacements
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
llvm::function_ref< Fn > function_ref
AttrTypeSubElementReplacements< Type > TypeSubElementReplacements
static To doCast(mlir::Attribute attr)
static bool isPossible(mlir::Attribute ty)
Arguments are taken as mlir::Attribute here and not as From, because when casting from an intermediat...
static T getTombstoneKey()
static bool isEqual(mlir::Attribute LHS, mlir::Attribute RHS)
static unsigned getHashValue(mlir::Attribute val)
static mlir::Attribute getEmptyKey()
static mlir::Attribute getTombstoneKey()
static unsigned getHashValue(mlir::NamedAttribute val)
static mlir::NamedAttribute getEmptyKey()
static mlir::NamedAttribute getTombstoneKey()
static bool isEqual(mlir::NamedAttribute lhs, mlir::NamedAttribute rhs)
static void * getAsVoidPointer(mlir::Attribute attr)
static mlir::Attribute getFromVoidPointer(void *ptr)
static constexpr int NumLowBitsAvailable
static void walk(T param, AttrTypeImmediateSubElementWalker &walker)
static T replace(T param, AttrSubElementReplacements &attrRepls, TypeSubElementReplacements &typeRepls)
This class provides support for interacting with the SubElementInterfaces for different types of para...
This trait is used to determine if an attribute is a location or not.
This trait is used to determine if a storage user, like Type, is mutable or not.