MLIR 22.0.0git
mlir::StorageUniquer Class Reference

A utility class to get or create instances of "storage classes". More...

#include "mlir/Support/StorageUniquer.h"

Inheritance diagram for mlir::StorageUniquer:

Classes

class  BaseStorage
 This class acts as the base storage that all storage classes must derived from. More...
class  StorageAllocator
 This is a utility allocator used to allocate memory for instances of derived types. More...

Public Member Functions

 StorageUniquer ()
 ~StorageUniquer ()
void disableMultithreading (bool disable=true)
 Set the flag specifying if multi-threading is disabled within the uniquer.
template<typename Storage>
void registerParametricStorageType (TypeID id)
 Register a new parametric storage class, this is necessary to create instances of this class type.
template<typename Storage>
void registerParametricStorageType ()
 Utility override when the storage type represents the type id.
template<typename Storage>
void registerSingletonStorageType (TypeID id, function_ref< void(Storage *)> initFn)
 Register a new singleton storage class, this is necessary to get the singletone instance.
template<typename Storage>
void registerSingletonStorageType (TypeID id)
template<typename Storage>
void registerSingletonStorageType (function_ref< void(Storage *)> initFn={})
 Utility override when the storage type represents the type id.
template<typename Storage, typename... Args>
Storage * get (function_ref< void(Storage *)> initFn, TypeID id, Args &&...args)
 Gets a uniqued instance of 'Storage'.
template<typename Storage, typename... Args>
Storage * get (function_ref< void(Storage *)> initFn, Args &&...args)
 Utility override when the storage type represents the type id.
template<typename Storage>
Storage * get (TypeID id)
 Gets a uniqued instance of 'Storage' which is a singleton storage type.
template<typename Storage>
Storage * get ()
 Utility override when the storage type represents the type id.
bool isSingletonStorageInitialized (TypeID id)
 Test if there is a singleton storage uniquer initialized for the provided TypeID.
bool isParametricStorageInitialized (TypeID id)
 Test if there is a parametric storage uniquer initialized for the provided TypeID.
template<typename Storage, typename... Args>
LogicalResult mutate (TypeID id, Storage *storage, Args &&...args)
 Changes the mutable component of 'storage' by forwarding the trailing arguments to the 'mutate' function of the derived class.

Detailed Description

A utility class to get or create instances of "storage classes".

These storage classes must derive from 'StorageUniquer::BaseStorage'.

For non-parametric storage classes, i.e. singleton classes, nothing else is needed. Instances of these classes can be created by calling get without trailing arguments.

Otherwise, the parametric storage classes may be created with get, and must respect the following:

  • Define a type alias, KeyTy, to a type that uniquely identifies the instance of the storage class.
    • The key type must be constructible from the values passed into the getComplex call.
    • If the KeyTy does not have an llvm::DenseMapInfo specialization, the storage class must define a hashing method: 'static unsigned hashKey(const KeyTy &)'
  • Provide a method, 'bool operator==(const KeyTy &) const', to compare the storage instance against an instance of the key type.
  • Provide a static construction method: 'DerivedStorage *construct(StorageAllocator &, const KeyTy &key)' that builds a unique instance of the derived storage. The arguments to this function are an allocator to store any uniqued data and the key type for this storage.
  • Provide a cleanup method: 'void cleanup()' that is called when erasing a storage instance. This should cleanup any fields of the storage as necessary and not attempt to free the memory of the storage itself.

Storage classes may have an optional mutable component, which must not take part in the unique immutable key. In this case, storage classes may be mutated with mutate and must additionally respect the following:

  • Provide a mutation method: 'LogicalResult mutate(StorageAllocator &, <...>)' that is called when mutating a storage instance. The first argument is an allocator to store any mutable data, and the remaining arguments are forwarded from the call site. The storage can be mutated at any time after creation. Care must be taken to avoid excessive mutation since the allocated storage can keep containing previous states. The return value of the function is used to indicate whether the mutation was successful, e.g., to limit the number of mutations or enable deferred one-time assignment of the mutable component.

All storage classes must be registered with the uniquer via registerParametricStorageType or registerSingletonStorageType using an appropriate unique TypeID for the storage class.

Definition at line 82 of file StorageUniquer.h.

Constructor & Destructor Documentation

◆ StorageUniquer()

StorageUniquer::StorageUniquer ( )

Definition at line 361 of file StorageUniquer.cpp.

◆ ~StorageUniquer()

StorageUniquer::~StorageUniquer ( )
default

Member Function Documentation

◆ disableMultithreading()

void StorageUniquer::disableMultithreading ( bool disable = true)

Set the flag specifying if multi-threading is disabled within the uniquer.

Definition at line 365 of file StorageUniquer.cpp.

◆ get() [1/4]

template<typename Storage>
Storage * mlir::StorageUniquer::get ( )
inline

Utility override when the storage type represents the type id.

Definition at line 235 of file StorageUniquer.h.

References get(), and mlir::TypeID::get().

Referenced by get(), and get().

◆ get() [2/4]

template<typename Storage, typename... Args>
Storage * mlir::StorageUniquer::get ( function_ref< void(Storage *)> initFn,
Args &&... args )
inline

Utility override when the storage type represents the type id.

Definition at line 222 of file StorageUniquer.h.

References get(), and mlir::TypeID::get().

◆ get() [3/4]

template<typename Storage, typename... Args>
Storage * mlir::StorageUniquer::get ( function_ref< void(Storage *)> initFn,
TypeID id,
Args &&... args )
inline

◆ get() [4/4]

template<typename Storage>
Storage * mlir::StorageUniquer::get ( TypeID id)
inline

Gets a uniqued instance of 'Storage' which is a singleton storage type.

'id' is the type id used when registering the storage instance.

Definition at line 230 of file StorageUniquer.h.

◆ isParametricStorageInitialized()

bool StorageUniquer::isParametricStorageInitialized ( TypeID id)

Test if there is a parametric storage uniquer initialized for the provided TypeID.

Test is the parametric storage is initialized.

This is only useful for debugging/diagnostic purpose: the uniquer is initialized when a dialect is loaded.

Definition at line 398 of file StorageUniquer.cpp.

Referenced by mlir::detail::AttributeUniquer::getWithTypeID(), and mlir::detail::TypeUniquer::getWithTypeID().

◆ isSingletonStorageInitialized()

bool StorageUniquer::isSingletonStorageInitialized ( TypeID id)

Test if there is a singleton storage uniquer initialized for the provided TypeID.

Test is the storage singleton is initialized.

This is only useful for debugging/diagnostic purpose: the uniquer is initialized when a dialect is loaded.

Definition at line 393 of file StorageUniquer.cpp.

Referenced by mlir::detail::AttributeUniquer::getWithTypeID(), and mlir::detail::TypeUniquer::getWithTypeID().

◆ mutate()

template<typename Storage, typename... Args>
LogicalResult mlir::StorageUniquer::mutate ( TypeID id,
Storage * storage,
Args &&... args )
inline

Changes the mutable component of 'storage' by forwarding the trailing arguments to the 'mutate' function of the derived class.

Definition at line 252 of file StorageUniquer.h.

Referenced by mlir::detail::AttributeUniquer::mutate(), and mlir::detail::TypeUniquer::mutate().

◆ registerParametricStorageType() [1/2]

template<typename Storage>
void mlir::StorageUniquer::registerParametricStorageType ( )
inline

Utility override when the storage type represents the type id.

Definition at line 160 of file StorageUniquer.h.

References mlir::TypeID::get(), and registerParametricStorageType().

Referenced by mlir::pdl_to_pdl_interp::PredicateUniquer::PredicateUniquer(), and registerParametricStorageType().

◆ registerParametricStorageType() [2/2]

template<typename Storage>
void mlir::StorageUniquer::registerParametricStorageType ( TypeID id)
inline

Register a new parametric storage class, this is necessary to create instances of this class type.

id is the type identifier that will be used to identify this type when creating instances of it via 'get'.

Definition at line 149 of file StorageUniquer.h.

Referenced by mlir::detail::AttributeUniquer::registerAttribute(), and mlir::detail::TypeUniquer::registerType().

◆ registerSingletonStorageType() [1/3]

template<typename Storage>
void mlir::StorageUniquer::registerSingletonStorageType ( function_ref< void(Storage *)> initFn = {})
inline

Utility override when the storage type represents the type id.

Definition at line 185 of file StorageUniquer.h.

◆ registerSingletonStorageType() [2/3]

template<typename Storage>
void mlir::StorageUniquer::registerSingletonStorageType ( TypeID id)
inline

Definition at line 180 of file StorageUniquer.h.

References registerSingletonStorageType().

◆ registerSingletonStorageType() [3/3]

template<typename Storage>
void mlir::StorageUniquer::registerSingletonStorageType ( TypeID id,
function_ref< void(Storage *)> initFn )
inline

Register a new singleton storage class, this is necessary to get the singletone instance.

id is the type identifier that will be used to access the singleton instance via 'get'. An optional initialization function may also be provided to initialize the newly created storage instance, and used when the singleton instance is created.

Definition at line 169 of file StorageUniquer.h.

Referenced by mlir::pdl_to_pdl_interp::PredicateUniquer::PredicateUniquer(), mlir::detail::AttributeUniquer::registerAttribute(), registerSingletonStorageType(), and mlir::detail::TypeUniquer::registerType().


The documentation for this class was generated from the following files: