9 #ifndef MLIR_IR_ATTRIBUTES_H 10 #define MLIR_IR_ATTRIBUTES_H 13 #include "llvm/Support/PointerLikeTypeTraits.h" 27 template <
typename ConcreteType,
typename BaseType,
typename StorageType,
28 template <
typename T>
class... Traits>
38 : impl(const_cast<
ImplType *>(impl)) {}
45 explicit operator bool()
const {
return impl; }
49 template <
typename U>
bool isa()
const;
50 template <
typename First,
typename Second,
typename... Rest>
52 template <
typename First,
typename... Rest>
54 template <
typename U> U
dyn_cast()
const;
56 template <
typename U> U
cast()
const;
73 return impl->getAbstractAttribute().getDialect();
77 void print(raw_ostream &os)
const;
84 return Attribute(reinterpret_cast<const ImplType *>(ptr));
90 template <
template <
typename T>
class Trait>
97 return impl->getAbstractAttribute();
110 assert(
impl &&
"isa<> used on a null attribute.");
111 return U::classof(*
this);
114 template <
typename First,
typename Second,
typename... Rest>
116 return isa<First>() || isa<Second, Rest...>();
119 template <
typename First,
typename... Rest>
121 return impl &&
isa<First, Rest...>();
125 return isa<U>() ? U(
impl) : U(
nullptr);
128 return (
impl && isa<U>()) ? U(
impl) : U(
nullptr);
149 StringAttr getName()
const;
155 Dialect *getNameDialect()
const;
161 void setName(StringAttr newName);
165 assert(value &&
"expected valid attribute value");
175 return name == rhs.name && value == rhs.value;
194 using AttrPairT = std::pair<Attribute, Attribute>;
202 namespace AttributeTrait {
204 template <
typename ConcreteType,
template <
typename>
class TraitType>
214 template <
typename ConcreteType,
typename Traits>
217 AttributeTrait::TraitBase> {
241 namespace AttributeTrait {
242 template <
typename ConcreteType>
254 return mlir::Attribute(static_cast<mlir::Attribute::ImplType *>(pointer));
258 return mlir::Attribute(static_cast<mlir::Attribute::ImplType *>(pointer));
267 template <
typename T>
269 T, std::enable_if_t<std::is_base_of<mlir::Attribute, T>::value>>
273 return T::getFromOpaquePointer(pointer);
277 return T::getFromOpaquePointer(pointer);
289 static constexpr
int NumLowBitsAvailable = llvm::PointerLikeTypeTraits<
TODO: Remove this file when SCCP and integer range analysis have been ported to the new framework...
static bool isEqual(mlir::NamedAttribute lhs, mlir::NamedAttribute rhs)
bool operator<(Fraction x, Fraction y)
static void * getAsVoidPointer(mlir::Attribute attr)
This class represents the base of an attribute interface.
U dyn_cast_or_null() const
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Attribute getValue() const
Return the value of the attribute.
const void * getAsOpaquePointer() const
Get an opaque pointer to the attribute.
T::Concept * getInterface() const
Returns an instance of the concept object for the given interface if it was registered to this attrib...
static bool classof(Attribute)
typename Traits::Concept Concept
bool isa_and_nonnull() const
This class represents an abstract interface.
bool operator!=(const NamedAttribute &rhs) const
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
static constexpr const bool value
bool hasTrait() const
Returns true if the attribute has a particular trait.
This class provides an efficient unique identifier for a specific C++ type.
NamedAttribute represents a combination of a name and an Attribute value.
static mlir::Attribute getTombstoneKey()
static mlir::NamedAttribute getEmptyKey()
Dialect & getDialect() const
Get the dialect this attribute is registered to.
MLIRContext * getContext() const
Return the context this attribute belongs to.
friend ::llvm::hash_code hash_value(Attribute arg)
Attributes are known-constant values of operations.
Attribute(const ImplType *impl)
This trait is used to determine if a storage user, like Type, is mutable or not.
bool operator==(const NamedAttribute &rhs) const
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
bool operator==(Attribute other) const
void print(raw_ostream &os) const
Print the attribute.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
void setValue(Attribute newValue)
Set the value of this attribute.
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
static mlir::Attribute getEmptyKey()
Type getType() const
Return the type of this attribute.
bool operator!=(Attribute other) const
Utility class for implementing users of storage classes uniqued by a StorageUniquer.
MLIRContext is the top-level object for a collection of MLIR operations.
static bool isEqual(mlir::Attribute LHS, mlir::Attribute RHS)
Base storage class appearing in an attribute.
const AbstractTy & getAbstractAttribute() const
Return the abstract descriptor for this attribute.
static unsigned getHashValue(mlir::Attribute val)
static unsigned getHashValue(mlir::NamedAttribute val)
static T getTombstoneKey()
Helper class for implementing traits for storage classes.
static mlir::NamedAttribute getTombstoneKey()
TypeID getTypeID()
Return a unique identifier for the concrete attribute type.
This class contains all of the static information common to all instances of a registered Attribute...
static mlir::Attribute getFromVoidPointer(void *ptr)
static Attribute getFromOpaquePointer(const void *ptr)
Construct an attribute from the opaque pointer representation.
Attribute & operator=(const Attribute &other)=default
bool hasTrait()
Returns true if the type was registered with a particular trait.