13 #ifndef MLIR_IR_ATTRIBUTESUPPORT_H
14 #define MLIR_IR_ATTRIBUTESUPPORT_H
19 #include "llvm/ADT/PointerIntPair.h"
20 #include "llvm/ADT/Twine.h"
46 T::getWalkImmediateSubElementsFn(),
47 T::getReplaceImmediateSubElementsFn(),
62 std::move(
hasTrait), walkImmediateSubElementsFn,
63 replaceImmediateSubElementsFn, typeID);
74 return interfaceMap.
lookup<T>();
80 return interfaceMap.
contains(interfaceID);
84 template <
template <
typename T>
class Trait>
86 return hasTraitFn(TypeID::get<Trait>());
111 : dialect(dialect), interfaceMap(std::move(interfaceMap)),
112 hasTraitFn(std::move(hasTraitFn)),
113 walkImmediateSubElementsFn(walkImmediateSubElementsFn),
114 replaceImmediateSubElementsFn(replaceImmediateSubElementsFn),
118 template <
typename ConcreteT,
typename BaseT,
typename StorageT,
119 typename UniquerT,
template <
typename T>
class... Traits>
151 class AttributeUniquer;
152 class DistinctAttributeUniquer;
165 assert(abstractAttribute &&
"Malformed attribute storage object.");
166 return *abstractAttribute;
173 abstractAttribute = &abstractAttr;
206 template <
typename T,
typename... Args>
209 std::forward<Args>(args)...);
215 template <
typename T,
typename... Args>
216 static std::enable_if_t<
217 !std::is_same<typename T::ImplType, AttributeStorage>::value, T>
221 llvm::report_fatal_error(
222 llvm::Twine(
"can't create Attribute '") + llvm::getTypeName<T>() +
223 "' because storage uniquer isn't initialized: the dialect was likely "
224 "not loaded, or the attribute wasn't added with addAttributes<...>() "
225 "in the Dialect::initialize() method.");
229 initializeAttributeStorage(storage, ctx, typeID);
233 static_cast<typename T::ImplType *
>(storage)->initialize(ctx);
235 typeID, std::forward<Args>(args)...);
240 template <
typename T>
241 static std::enable_if_t<
242 std::is_same<typename T::ImplType, AttributeStorage>::value, T>
246 llvm::report_fatal_error(
247 llvm::Twine(
"can't create Attribute '") + llvm::getTypeName<T>() +
248 "' because storage uniquer isn't initialized: the dialect was likely "
249 "not loaded, or the attribute wasn't added with addAttributes<...>() "
250 "in the Dialect::initialize() method.");
255 template <
typename T,
typename... Args>
258 assert(
impl &&
"cannot mutate null attribute");
260 std::forward<Args>(args)...);
264 template <
typename T>
266 registerAttribute<T>(ctx, T::getTypeID());
272 template <
typename T>
273 static std::enable_if_t<
274 !std::is_same<typename T::ImplType, AttributeStorage>::value>
282 template <
typename T>
283 static std::enable_if_t<
284 std::is_same<typename T::ImplType, AttributeStorage>::value>
289 initializeAttributeStorage(storage, ctx, typeID);
305 if constexpr (std::is_default_constructible_v<T>)
306 return failureOr.emplace();
This class contains all of the static information common to all instances of a registered Attribute.
function_ref< Attribute(Attribute, ArrayRef< Attribute >, ArrayRef< Type >)> ReplaceImmediateSubElementsFn
static AbstractAttribute get(Dialect &dialect, detail::InterfaceMap &&interfaceMap, HasTraitFn &&hasTrait, WalkImmediateSubElementsFn walkImmediateSubElementsFn, ReplaceImmediateSubElementsFn replaceImmediateSubElementsFn, TypeID typeID)
This method is used by Dialect objects to register attributes with custom TypeIDs.
llvm::unique_function< bool(TypeID) const > HasTraitFn
T::Concept * getInterface() const
Returns an instance of the concept object for the given interface if it was registered to this attrib...
static AbstractAttribute get(Dialect &dialect)
This method is used by Dialect objects when they register the list of attributes they contain.
static const AbstractAttribute & lookup(TypeID typeID, MLIRContext *context)
Look up the specified abstract attribute in the MLIRContext and return a reference to it.
TypeID getTypeID() const
Return the unique identifier representing the concrete attribute class.
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.
bool hasTrait(TypeID traitID) const
Returns true if the attribute has a particular trait.
Attribute replaceImmediateSubElements(Attribute attr, ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
Replace the immediate sub-elements of this attribute.
function_ref< void(Attribute, function_ref< void(Attribute)>, function_ref< void(Type)>)> WalkImmediateSubElementsFn
Dialect & getDialect() const
Return the dialect this attribute was registered to.
bool hasInterface(TypeID interfaceID) const
Returns true if the attribute has the interface with the given ID registered.
Base storage class appearing in an attribute.
void initializeAbstractAttribute(const AbstractAttribute &abstractAttr)
Set the abstract attribute for this storage instance.
const AbstractAttribute & getAbstractAttribute() const
Return the abstract descriptor for this attribute.
void initialize(MLIRContext *context)
Default initialization for attribute storage classes that require no additional initialization.
Attributes are known-constant values of operations.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
This class provides support for representing a failure result, or a valid value of type T.
MLIRContext is the top-level object for a collection of MLIR operations.
StorageUniquer & getAttributeUniquer()
Returns the storage uniquer used for constructing attribute storage instances.
This class acts as the base storage that all storage classes must derived from.
This is a utility allocator used to allocate memory for instances of derived types.
A utility class to get or create instances of "storage classes".
LogicalResult mutate(TypeID id, Storage *storage, Args &&...args)
Changes the mutable component of 'storage' by forwarding the trailing arguments to the 'mutate' funct...
void registerSingletonStorageType(TypeID id, function_ref< void(Storage *)> initFn)
Register a new singleton storage class, this is necessary to get the singletone instance.
bool isSingletonStorageInitialized(TypeID id)
Test if there is a singleton storage uniquer initialized for the provided TypeID.
Storage * get(function_ref< void(Storage *)> initFn, TypeID id, Args &&...args)
Gets a uniqued instance of 'Storage'.
bool isParametricStorageInitialized(TypeID id)
Test if there is a parametric storage uniquer initialized for the provided TypeID.
void registerParametricStorageType(TypeID id)
Register a new parametric storage class, this is necessary to create instances of this class type.
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...
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.
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.
static void registerAttribute(MLIRContext *ctx)
Register an attribute instance T with the uniquer.
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.
static T get(MLIRContext *ctx, Args &&...args)
Get an uniqued instance of an attribute T.
static LogicalResult mutate(MLIRContext *ctx, typename T::ImplType *impl, Args &&...args)
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.
A specialized attribute uniquer for distinct attributes that always allocates since the distinct attr...
This class provides an efficient mapping between a given Interface type, and a particular implementat...
bool contains(TypeID interfaceID) const
Returns true if the interface map contains an interface for the given id.
T::Concept * lookup() const
Returns an instance of the concept object for the given interface if it was registered to this map,...
Utility class for implementing users of storage classes uniqued by a StorageUniquer.
decltype(auto) unwrapForCustomParse(FailureOr< T > &failureOr)
This header declares functions that assist transformations in the MemRef dialect.
This class represents an efficient way to signal success or failure.