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;
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);
98 llvm::sys::SmartRWMutex<true> blobMapLock;
103 llvm::StringMap<BlobEntry> blobMap;
128 blobManager = std::move(newBlobManager);
133 std::shared_ptr<DialectResourceBlobManager> blobManager;
140 template <
typename HandleT>
157 HandleT
insert(StringRef name, std::optional<AsmResourceBlob> blob = {}) {
159 cast<typename HandleT::Dialect>(getDialect()), name, std::move(blob));
166 if (
const auto *dialectHandle = dyn_cast<HandleT>(&handle)) {
167 if (
auto *blob = dialectHandle->getBlob())
168 provider.
buildBlob(dialectHandle->getKey(), *blob);
181 template <
typename DialectT>
184 DialectResourceBlobManager::BlobEntry,
206 assert(dialect &&
"dialect not registered");
208 auto *iface = dialect->template getRegisteredInterface<ManagerInterface>();
209 assert(iface &&
"dialect doesn't provide the blob manager interface?");
This class represents a CRTP base class for dialect resource handles.
DialectResourceBlobManager::BlobEntry * getResource()
Return the resource referenced by this handle.
AsmDialectResourceHandleBase(DialectResourceBlobManager::BlobEntry *resource, DialectT *dialect)
Construct a handle from a pointer to the resource.
This class represents an opaque handle to a dialect resource entry.
The following classes enable support for parsing and printing resources within MLIR assembly formats.
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.
The class represents an individual entry of a blob.
AsmResourceBlob * getBlob()
void setBlob(AsmResourceBlob &&newBlob)
Set the blob owned by this entry.
const AsmResourceBlob * getBlob() const
Return the blob owned by this entry if one has been initialized.
StringRef getKey() const
Return the key used to reference this blob.
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.
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.
const BlobEntry * lookup(StringRef name) const
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.
This class implements a dialect interface that provides common functionality for interacting with a r...
ResourceBlobManagerDialectInterface(Dialect *dialect)
DialectResourceBlobManager & getBlobManager()
Return the blob manager held by this interface.
void setBlobManager(std::shared_ptr< DialectResourceBlobManager > newBlobManager)
Set the blob manager held by this interface.
const DialectResourceBlobManager & getBlobManager() const
The base class used for all derived interface types.
This header declares functions that assit transformations in the MemRef dialect.
This class defines a dialect specific handle to a resource blob.
StringRef getKey() const
Return the human readable string key for this handle.
const AsmResourceBlob * getBlob() const
static ManagerInterface & getManagerInterface(MLIRContext *ctx)
Get the interface for the dialect that owns handles of this type.
AsmResourceBlob * getBlob()
Return the blob referenced by this handle if the underlying resource has been initialized.