15#ifndef MLIR_IR_DIALECTRESOURCEBLOBMANAGER_H
16#define MLIR_IR_DIALECTRESOURCEBLOBMANAGER_H
20#include "llvm/ADT/StringMap.h"
21#include "llvm/ADT/Twine.h"
22#include "llvm/Support/RWMutex.h"
23#include "llvm/Support/SMLoc.h"
39 StringRef
getKey()
const {
return key; }
56 void initialize(StringRef newKey, std::optional<AsmResourceBlob> newBlob) {
58 blob = std::move(newBlob);
65 std::optional<AsmResourceBlob> blob;
68 friend DialectResourceBlobManager;
69 friend class llvm::StringMapEntryStorage<BlobEntry>;
86 BlobEntry &
insert(StringRef name, std::optional<AsmResourceBlob> blob = {});
89 template <
typename HandleT>
90 HandleT
insert(
typename HandleT::Dialect *dialect, StringRef name,
91 std::optional<AsmResourceBlob> blob = {}) {
92 BlobEntry &entry =
insert(name, std::move(blob));
93 return HandleT(&entry, dialect);
103 mutable llvm::sys::SmartRWMutex<true> blobMapLock;
108 llvm::StringMap<BlobEntry> blobMap;
133 blobManager = std::move(newBlobManager);
138 std::shared_ptr<DialectResourceBlobManager> blobManager;
145template <
typename HandleT>
150 ResourceBlobManagerDialectInterface;
162 HandleT
insert(StringRef name, std::optional<AsmResourceBlob> blob = {}) {
164 cast<typename HandleT::Dialect>(
getDialect()), name, std::move(blob));
171 if (
const auto *dialectHandle = dyn_cast<HandleT>(&handle)) {
172 if (
auto *blob = dialectHandle->getBlob())
173 provider.
buildBlob(dialectHandle->getKey(), *blob);
186template <
typename DialectT>
189 DialectResourceBlobManager::BlobEntry,
211 assert(dialect &&
"dialect not registered");
213 auto *iface = dialect->template getRegisteredInterface<ManagerInterface>();
214 assert(iface &&
"dialect doesn't provide the blob manager interface?");
LogicalResult initialize(unsigned origNumLoops, ArrayRef< ReassociationIndices > foldedIterationDims)
AsmDialectResourceHandleBase(DialectResourceBlobManager::BlobEntry *resource, DialectT *dialect)
DialectResourceBlobManager::BlobEntry * getResource()
This class represents an opaque handle to a dialect resource entry.
This class represents a processed binary blob of data.
This class is used to build resource entries for use by the printer.
virtual void buildBlob(StringRef key, ArrayRef< char > data, uint32_t dataAlignment)=0
Build an resource entry represented by the given binary blob data.
Dialect * getDialect() const
Return the dialect that this interface represents.
detail::DialectInterfaceBase< ConcreteType, DialectInterface > Base
The base class used for all derived interface types.
The class represents an individual entry of a blob.
AsmResourceBlob * getBlob()
void setBlob(AsmResourceBlob &&newBlob)
Set the blob owned by this entry.
StringRef getKey() const
Return the key used to reference this blob.
const AsmResourceBlob * getBlob() const
Return the blob owned by this entry if one has been initialized.
This class defines a manager for dialect resource blobs.
HandleT insert(typename HandleT::Dialect *dialect, StringRef name, std::optional< AsmResourceBlob > blob={})
Insertion method that returns a dialect specific handle to the inserted entry.
void update(StringRef name, AsmResourceBlob &&newBlob)
Update the blob for the entry defined by the provided name.
const BlobEntry * lookup(StringRef name) const
void getBlobMap(llvm::function_ref< void(const llvm::StringMap< BlobEntry > &)> accessor) const
Provide access to all the registered blobs via a callable.
BlobEntry & insert(StringRef name, std::optional< AsmResourceBlob > blob={})
Insert a new entry with the provided name and optional blob data.
BlobEntry * lookup(StringRef name)
Return the blob registered for the given name, or nullptr if no blob is registered.
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.
T * getOrLoadDialect()
Get (or create) a dialect for the given derived dialect type.
This class provides a base class for dialects implementing the resource blob interface.
void update(StringRef name, AsmResourceBlob &&newBlob)
Update the blob for the entry defined by the provided name.
void buildResources(AsmResourceBuilder &provider, ArrayRef< AsmDialectResourceHandle > referencedResources)
Build resources for each of the referenced blobs within this manager.
HandleT insert(StringRef name, std::optional< AsmResourceBlob > blob={})
Insert a new resource blob entry with the provided name and optional blob data.
DialectResourceBlobManager & getBlobManager()
Return the blob manager held by this interface.
ResourceBlobManagerDialectInterface(Dialect *dialect)
const DialectResourceBlobManager & getBlobManager() const
void setBlobManager(std::shared_ptr< DialectResourceBlobManager > newBlobManager)
Set the blob manager held by this interface.
DialectInterfaceBase< ConcreteType, DialectInterface > Base
Include the generated interface declarations.
This class defines a dialect specific handle to a resource blob.
AsmResourceBlob * getBlob()
Return the blob referenced by this handle if the underlying resource has been initialized.
StringRef getKey() const
Return the human readable string key for this handle.
static ManagerInterface & getManagerInterface(MLIRContext *ctx)
Get the interface for the dialect that owns handles of this type.
const AsmResourceBlob * getBlob() const
ResourceBlobManagerDialectInterfaceBase< DialectResourceBlobHandle< BuiltinDialect > > ManagerInterface