forked from OSchip/llvm-project
Add more explicit error message when creating a type or attribute for an unregistered dialect (NFC)
Differential Revision: https://reviews.llvm.org/D87177
This commit is contained in:
parent
d0ccfcb040
commit
97e77ac0ed
|
@ -16,6 +16,7 @@
|
|||
#include "mlir/IR/MLIRContext.h"
|
||||
#include "mlir/IR/StorageUniquerSupport.h"
|
||||
#include "llvm/ADT/PointerIntPair.h"
|
||||
#include "llvm/ADT/Twine.h"
|
||||
|
||||
namespace mlir {
|
||||
class MLIRContext;
|
||||
|
@ -142,6 +143,14 @@ public:
|
|||
static typename std::enable_if_t<
|
||||
!std::is_same<typename T::ImplType, AttributeStorage>::value, T>
|
||||
get(MLIRContext *ctx, Args &&...args) {
|
||||
#ifndef NDEBUG
|
||||
if (!ctx->getAttributeUniquer().isParametricStorageInitialized(
|
||||
T::getTypeID()))
|
||||
llvm::report_fatal_error(llvm::Twine("can't create Attribute '") +
|
||||
llvm::getTypeName<T>() +
|
||||
"' because storage uniquer isn't initialized: "
|
||||
"the dialect was likely not loaded.");
|
||||
#endif
|
||||
return ctx->getAttributeUniquer().get<typename T::ImplType>(
|
||||
[ctx](AttributeStorage *storage) {
|
||||
initializeAttributeStorage(storage, ctx, T::getTypeID());
|
||||
|
@ -153,6 +162,14 @@ public:
|
|||
static typename std::enable_if_t<
|
||||
std::is_same<typename T::ImplType, AttributeStorage>::value, T>
|
||||
get(MLIRContext *ctx) {
|
||||
#ifndef NDEBUG
|
||||
if (!ctx->getAttributeUniquer().isSingletonStorageInitialized(
|
||||
T::getTypeID()))
|
||||
llvm::report_fatal_error(llvm::Twine("can't create Attribute '") +
|
||||
llvm::getTypeName<T>() +
|
||||
"' because storage uniquer isn't initialized: "
|
||||
"the dialect was likely not loaded.");
|
||||
#endif
|
||||
return ctx->getAttributeUniquer().get<typename T::ImplType>(T::getTypeID());
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "mlir/IR/MLIRContext.h"
|
||||
#include "mlir/IR/StorageUniquerSupport.h"
|
||||
#include "llvm/ADT/Twine.h"
|
||||
|
||||
namespace mlir {
|
||||
class Dialect;
|
||||
|
@ -126,6 +127,13 @@ struct TypeUniquer {
|
|||
static typename std::enable_if_t<
|
||||
!std::is_same<typename T::ImplType, TypeStorage>::value, T>
|
||||
get(MLIRContext *ctx, Args &&...args) {
|
||||
#ifndef NDEBUG
|
||||
if (!ctx->getTypeUniquer().isParametricStorageInitialized(T::getTypeID()))
|
||||
llvm::report_fatal_error(llvm::Twine("can't create type '") +
|
||||
llvm::getTypeName<T>() +
|
||||
"' because storage uniquer isn't initialized: "
|
||||
"the dialect was likely not loaded.");
|
||||
#endif
|
||||
return ctx->getTypeUniquer().get<typename T::ImplType>(
|
||||
[&](TypeStorage *storage) {
|
||||
storage->initialize(AbstractType::lookup(T::getTypeID(), ctx));
|
||||
|
@ -137,6 +145,13 @@ struct TypeUniquer {
|
|||
static typename std::enable_if_t<
|
||||
std::is_same<typename T::ImplType, TypeStorage>::value, T>
|
||||
get(MLIRContext *ctx) {
|
||||
#ifndef NDEBUG
|
||||
if (!ctx->getTypeUniquer().isSingletonStorageInitialized(T::getTypeID()))
|
||||
llvm::report_fatal_error(llvm::Twine("can't create type '") +
|
||||
llvm::getTypeName<T>() +
|
||||
"' because storage uniquer isn't initialized: "
|
||||
"the dialect was likely not loaded.");
|
||||
#endif
|
||||
return ctx->getTypeUniquer().get<typename T::ImplType>(T::getTypeID());
|
||||
}
|
||||
|
||||
|
|
|
@ -210,6 +210,16 @@ public:
|
|||
return get<Storage>(TypeID::get<Storage>());
|
||||
}
|
||||
|
||||
/// Test if there is a singleton storage uniquer initialized for the provided
|
||||
/// TypeID. This is only useful for debugging/diagnostic purpose: the uniquer
|
||||
/// is initialized when a dialect is loaded.
|
||||
bool isSingletonStorageInitialized(TypeID id);
|
||||
|
||||
/// Test if there is a parametric storage uniquer initialized for the provided
|
||||
/// TypeID. This is only useful for debugging/diagnostic purpose: the uniquer
|
||||
/// is initialized when a dialect is loaded.
|
||||
bool isParametricStorageInitialized(TypeID id);
|
||||
|
||||
/// Changes the mutable component of 'storage' by forwarding the trailing
|
||||
/// arguments to the 'mutate' function of the derived class.
|
||||
template <typename Storage, typename... Args>
|
||||
|
|
|
@ -89,6 +89,9 @@ struct StorageUniquerImpl {
|
|||
// Parametric Storage
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
||||
/// Check if an instance of a parametric storage class exists.
|
||||
bool hasParametricStorage(TypeID id) { return parametricUniquers.count(id); }
|
||||
|
||||
/// Get or create an instance of a parametric type.
|
||||
BaseStorage *
|
||||
getOrCreate(TypeID id, unsigned hashValue,
|
||||
|
@ -176,6 +179,9 @@ struct StorageUniquerImpl {
|
|||
return singletonInstance;
|
||||
}
|
||||
|
||||
/// Check if an instance of a singleton storage class exists.
|
||||
bool hasSingleton(TypeID id) { return singletonInstances.count(id); }
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Instance Storage
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
@ -227,6 +233,16 @@ auto StorageUniquer::getSingletonImpl(TypeID id) -> BaseStorage * {
|
|||
return impl->getSingleton(id);
|
||||
}
|
||||
|
||||
/// Test is the storage singleton is initialized.
|
||||
bool StorageUniquer::isSingletonStorageInitialized(TypeID id) {
|
||||
return impl->hasSingleton(id);
|
||||
}
|
||||
|
||||
/// Test is the parametric storage is initialized.
|
||||
bool StorageUniquer::isParametricStorageInitialized(TypeID id) {
|
||||
return impl->hasParametricStorage(id);
|
||||
}
|
||||
|
||||
/// Implementation for registering an instance of a derived type with default
|
||||
/// storage.
|
||||
void StorageUniquer::registerSingletonImpl(
|
||||
|
|
Loading…
Reference in New Issue