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>
53 [[deprecated(
"Use mlir::isa<U>() instead")]]
55 template <
typename... Tys>
56 [[deprecated(
"Use mlir::isa_and_nonnull<U>() instead")]]
59 [[deprecated(
"Use mlir::dyn_cast<U>() instead")]]
62 [[deprecated(
"Use mlir::dyn_cast_or_null<U>() instead")]]
65 [[deprecated(
"Use mlir::cast<U>() instead")]]
77 return impl->getAbstractAttribute().getDialect();
82 void print(raw_ostream &os,
bool elideType =
false)
const;
83 void print(raw_ostream &os,
AsmState &state,
bool elideType =
false)
const;
101 template <
typename InterfaceT>
105 mlir::isa<InterfaceT>(*
this);
109 template <
template <
typename T>
class Trait>
116 return impl->getAbstractAttribute();
143 auto walk(WalkFns &&...walkFns) {
145 (walker.
addWalk(std::forward<WalkFns>(walkFns)), ...);
146 return walker.
walk<Order>(*this);
153 template <
typename... ReplacementFns>
154 auto replace(ReplacementFns &&...replacementFns) {
156 (replacer.
addReplacement(std::forward<ReplacementFns>(replacementFns)),
158 return replacer.
replace(*
this);
173 template <
typename... Tys>
175 return llvm::isa<Tys...>(*this);
178 template <
typename... Tys>
180 return llvm::isa_and_present<Tys...>(*this);
183 template <
typename U>
185 return llvm::dyn_cast<U>(*
this);
188 template <
typename U>
190 return llvm::dyn_cast_if_present<U>(*
this);
193 template <
typename U>
195 return llvm::cast<U>(*
this);
224 void setName(StringAttr newName);
228 assert(value &&
"expected valid attribute value");
238 return name == rhs.name && value == rhs.value;
247 friend DenseMapInfo<NamedAttribute>;
257 using AttrPairT = std::pair<Attribute, Attribute>;
264 template <
typename T>
266 walker.
walk(param.getName());
267 walker.
walk(param.getValue());
269 template <
typename T>
273 return T(cast<decltype(param.getName())>(paramRepls[0]), paramRepls[1]);
281 namespace AttributeTrait {
283 template <
typename ConcreteType,
template <
typename>
class TraitType>
293 template <
typename ConcreteType,
typename Traits>
296 AttributeTrait::TraitBase> {
311 llvm::getTypeName<ConcreteType>());
325 namespace AttributeTrait {
329 template <
typename ConcreteType>
335 template <
typename ConcreteType>
362 template <
typename T>
364 T, std::enable_if_t<std::is_base_of<mlir::Attribute, T>::value &&
365 !mlir::detail::IsInterface<T>::value>>
369 return T::getFromOpaquePointer(pointer);
373 return T::getFromOpaquePointer(pointer);
379 struct PointerLikeTypeTraits<
mlir::Attribute> {
386 static constexpr
int NumLowBitsAvailable = llvm::PointerLikeTypeTraits<
410 template <
typename To,
typename From>
412 std::enable_if_t<std::is_same_v<mlir::Attribute,
413 std::remove_const_t<From>> ||
414 std::is_base_of_v<mlir::Attribute, From>>>
427 if constexpr (std::is_base_of_v<To, From>) {
430 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.
This is an attribute/type replacer that is naively cached.
Attribute replace(Attribute attr)
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.
friend InterfaceBase
Allow access to 'getInterfaceFor'.
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.
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
void printStripped(raw_ostream &os) const
Print the attribute without dialect wrapping.
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 hasPromiseOrImplementsInterface()
Returns true if InterfaceT has been promised by the dialect or implemented.
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...
void addReplacement(ReplaceFn< Attribute > fn)
Register a replacement function for mapping a given attribute or type.
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.
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.
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 an attribute is a location or not.
This trait is used to determine if a storage user, like Type, is mutable or not.