13 #ifndef MLIR_IR_ATTRIBUTESUPPORT_H 14 #define MLIR_IR_ATTRIBUTESUPPORT_H 19 #include "llvm/ADT/PointerIntPair.h" 20 #include "llvm/ADT/Twine.h" 34 using HasTraitFn = llvm::unique_function<bool(TypeID) const>;
56 std::move(hasTrait), typeID);
67 return interfaceMap.lookup<T>();
73 return interfaceMap.contains(interfaceID);
77 template <
template <
typename T>
class Trait>
79 return hasTraitFn(TypeID::get<Trait>());
91 : dialect(dialect), interfaceMap(std::move(interfaceMap)),
92 hasTraitFn(std::move(hasTrait)), typeID(typeID) {}
95 template <
typename ConcreteT,
typename BaseT,
typename StorageT,
96 typename UniquerT,
template <
typename T>
class... Traits>
122 class AttributeUniquer;
134 assert(abstractAttribute &&
"Malformed attribute storage object.");
135 return *abstractAttribute;
142 abstractAttribute = &abstractAttr;
175 template <
typename T,
typename... Args>
177 return getWithTypeID<T, Args...>(ctx, T::getTypeID(),
178 std::forward<Args>(args)...);
184 template <
typename T,
typename... Args>
185 static typename std::enable_if_t<
190 llvm::report_fatal_error(
191 llvm::Twine(
"can't create Attribute '") + llvm::getTypeName<T>() +
192 "' because storage uniquer isn't initialized: the dialect was likely " 193 "not loaded, or the attribute wasn't added with addAttributes<...>() " 194 "in the Dialect::initialize() method.");
198 initializeAttributeStorage(storage, ctx, typeID);
202 static_cast<typename T::ImplType *
>(storage)->initialize(ctx);
204 typeID, std::forward<Args>(args)...);
209 template <
typename T>
210 static typename std::enable_if_t<
215 llvm::report_fatal_error(
216 llvm::Twine(
"can't create Attribute '") + llvm::getTypeName<T>() +
217 "' because storage uniquer isn't initialized: the dialect was likely " 218 "not loaded, or the attribute wasn't added with addAttributes<...>() " 219 "in the Dialect::initialize() method.");
224 template <
typename T,
typename... Args>
227 assert(impl &&
"cannot mutate null attribute");
229 std::forward<Args>(args)...);
233 template <
typename T>
235 registerAttribute<T>(ctx, T::getTypeID());
241 template <
typename T>
242 static typename std::enable_if_t<
243 !std::is_same<typename T::ImplType, AttributeStorage>::value>
251 template <
typename T>
252 static typename std::enable_if_t<
253 std::is_same<typename T::ImplType, AttributeStorage>::value>
258 initializeAttributeStorage(storage, ctx, typeID);
Include the generated interface declarations.
TypeID getTypeID() const
Return the unique identifier representing the concrete attribute class.
Storage * get(function_ref< void(Storage *)> initFn, TypeID id, Args &&...args)
Gets a uniqued instance of 'Storage'.
llvm::unique_function< bool(TypeID) const > HasTraitFn
static std::enable_if_t< !std::is_same< typename T::ImplType, AttributeStorage >::value, T > getWithTypeID(MLIRContext *ctx, TypeID typeID, Args &&...args)
Get an uniqued instance of a parametric attribute T.
T::Concept * getInterface() const
Returns an instance of the concept object for the given interface if it was registered to this attrib...
This is a utility allocator used to allocate memory for instances of derived types.
static const AbstractAttribute & lookup(TypeID typeID, MLIRContext *context)
Look up the specified abstract attribute in the MLIRContext and return a reference to it...
Dialect & getDialect() const
Return the dialect this attribute was registered to.
An inlay hint that for a type annotation.
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.
static void registerAttribute(MLIRContext *ctx)
Register an attribute instance T with the uniquer.
This class represents an efficient way to signal success or failure.
bool isSingletonStorageInitialized(TypeID id)
Test if there is a singleton storage uniquer initialized for the provided TypeID. ...
This class provides an efficient mapping between a given Interface type, and a particular implementat...
static LogicalResult mutate(MLIRContext *ctx, typename T::ImplType *impl, Args &&...args)
void registerParametricStorageType(TypeID id)
Register a new parametric storage class, this is necessary to create instances of this class type...
LogicalResult mutate(TypeID id, Storage *storage, Args &&...args)
Changes the mutable component of 'storage' by forwarding the trailing arguments to the 'mutate' funct...
bool isParametricStorageInitialized(TypeID id)
Test if there is a parametric storage uniquer initialized for the provided TypeID.
static std::enable_if_t< std::is_same< typename T::ImplType, AttributeStorage >::value > registerAttribute(MLIRContext *ctx, TypeID typeID)
Register a singleton attribute instance T with the uniquer.
StorageUniquer & getAttributeUniquer()
Returns the storage uniquer used for constructing attribute storage instances.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
void initialize(MLIRContext *context)
Default initialization for attribute storage classes that require no additional initialization.
static std::enable_if_t< std::is_same< typename T::ImplType, AttributeStorage >::value, T > getWithTypeID(MLIRContext *ctx, TypeID typeID)
Get an uniqued instance of a singleton attribute T.
A utility class to get or create instances of "storage classes".
This class acts as the base storage that all storage classes must derived from.
bool hasTrait(TypeID traitID) const
Returns true if the attribute has a particular trait.
static std::enable_if_t< !std::is_same< typename T::ImplType, AttributeStorage >::value > registerAttribute(MLIRContext *ctx, TypeID typeID)
Register a parametric attribute instance T with the uniquer.
Utility class for implementing users of storage classes uniqued by a StorageUniquer.
const AbstractAttribute & getAbstractAttribute() const
Return the abstract descriptor for this attribute.
MLIRContext is the top-level object for a collection of MLIR operations.
void initializeAbstractAttribute(const AbstractAttribute &abstractAttr)
Set the abstract attribute for this storage instance.
Base storage class appearing in an attribute.
bool hasInterface(TypeID interfaceID) const
Returns true if the attribute has the interface with the given ID registered.
This class contains all of the static information common to all instances of a registered Attribute...
void registerSingletonStorageType(TypeID id, function_ref< void(Storage *)> initFn)
Register a new singleton storage class, this is necessary to get the singletone instance.