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; }
52 template <
typename... Tys>
54 template <
typename... Tys>
72 return impl->getAbstractAttribute().getDialect();
77 void print(raw_ostream &os,
bool elideType =
false)
const;
78 void print(raw_ostream &os,
AsmState &state,
bool elideType =
false)
const;
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);
155 template <
typename... Tys>
157 return llvm::isa<Tys...>(*this);
160 template <
typename... Tys>
162 return llvm::isa_and_present<Tys...>(*this);
165 template <
typename U>
167 return llvm::dyn_cast<U>(*
this);
170 template <
typename U>
172 return llvm::dyn_cast_if_present<U>(*
this);
175 template <
typename U>
177 return llvm::cast<U>(*
this);
206 void setName(StringAttr newName);
210 assert(value &&
"expected valid attribute value");
220 return name == rhs.name && value == rhs.value;
229 friend DenseMapInfo<NamedAttribute>;
239 using AttrPairT = std::pair<Attribute, Attribute>;
246 template <
typename T>
248 walker.
walk(param.getName());
249 walker.
walk(param.getValue());
251 template <
typename T>
255 return T(cast<decltype(param.getName())>(paramRepls[0]), paramRepls[1]);
263 namespace AttributeTrait {
265 template <
typename ConcreteType,
template <
typename>
class TraitType>
275 template <
typename ConcreteType,
typename Traits>
278 AttributeTrait::TraitBase> {
302 namespace AttributeTrait {
303 template <
typename ConcreteType>
329 template <
typename T>
331 T, std::enable_if_t<std::is_base_of<mlir::Attribute, T>::value &&
332 !mlir::detail::IsInterface<T>::value>>
336 return T::getFromOpaquePointer(pointer);
340 return T::getFromOpaquePointer(pointer);
346 struct PointerLikeTypeTraits<
mlir::Attribute> {
353 static constexpr
int NumLowBitsAvailable = llvm::PointerLikeTypeTraits<
377 template <
typename To,
typename From>
379 std::enable_if_t<std::is_same_v<mlir::Attribute,
380 std::remove_const_t<From>> ||
381 std::is_base_of_v<mlir::Attribute, From>>>
394 if constexpr (std::is_base_of_v<To, From>) {
398 return To::classof(ty);
This class contains all of the static information common to all instances of a registered Attribute.
T::Concept * getInterface() const
Returns an instance of the concept object for the given interface if it was registered to this attrib...
bool hasTrait() const
Returns true if the attribute has a particular trait.
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.
Attribute replace(Attribute attr)
Replace the given attribute/type, and recursively replace any sub elements.
void addReplacement(ReplaceFn< Attribute > fn)
Register a replacement function for mapping a given attribute or type.
This class is used by AttrTypeSubElementHandler instances to process sub element replacements.
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
Base storage class appearing in an attribute.
Attributes are known-constant values of operations.
U dyn_cast_or_null() const
Dialect & getDialect() const
Get the dialect this attribute is registered to.
auto walk(WalkFns &&...walkFns)
Walk this attribute and all attibutes/types nested within using the provided walk functions.
Attribute(const ImplType *impl)
constexpr Attribute()=default
const AbstractTy & getAbstractAttribute() const
Return the abstract descriptor for this attribute.
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
bool isa() const
Casting utility functions.
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.
Attribute & operator=(const Attribute &other)=default
friend ::llvm::hash_code hash_value(Attribute arg)
bool hasTrait()
Returns true if the type was registered with a particular trait.
const void * getAsOpaquePointer() const
Get an opaque pointer to the attribute.
Attribute(const Attribute &other)=default
bool isa_and_nonnull() const
ImplType * getImpl() const
Return the internal Attribute implementation.
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.
friend ::llvm::hash_code hash_value(const NamedAttribute &arg)
Allow access to internals to enable hashing.
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...
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.
Include the generated interface declarations.
This header declares functions that assit transformations in the MemRef dialect.
WalkOrder
Traversal order for region, block and operation walk utilities.
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
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 mlir::Attribute getFromVoidPointer(void *ptr)
static void * getAsVoidPointer(mlir::Attribute attr)
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 a storage user, like Type, is mutable or not.