diff --git a/mlir/include/mlir/IR/Dialect.h b/mlir/include/mlir/IR/Dialect.h --- a/mlir/include/mlir/IR/Dialect.h +++ b/mlir/include/mlir/IR/Dialect.h @@ -287,10 +287,17 @@ /// transitionning the registration mechanism to a stateless approach. DialectRegistry &getGlobalDialectRegistry(); +/// This controls globally whether the dialect registry is / isn't enabled. +/// This is deprecated and only intended to help the transition. It'll be +/// removed soon. +void enableGlobalDialectRegistry(bool); +bool isGlobalDialectRegistryEnabled(); + /// Registers all dialects from the global registries with the /// specified MLIRContext. This won't load the dialects in the context, /// but only make them available for lazy loading by name. /// Note: This method is not thread-safe. +/// Deprecated: this method will be deleted soon. void registerAllDialects(MLIRContext *context); /// Register and return the dialect with the given namespace in the provided diff --git a/mlir/lib/IR/Dialect.cpp b/mlir/lib/IR/Dialect.cpp --- a/mlir/lib/IR/Dialect.cpp +++ b/mlir/lib/IR/Dialect.cpp @@ -23,13 +23,22 @@ DialectAsmParser::~DialectAsmParser() {} //===----------------------------------------------------------------------===// -// Dialect Registration +// Dialect Registration (DEPRECATED) //===----------------------------------------------------------------------===// /// Registry for all dialect allocation functions. static llvm::ManagedStatic dialectRegistry; DialectRegistry &mlir::getGlobalDialectRegistry() { return *dialectRegistry; } +// Note: deprecated, will be removed soon. +static bool isGlobalDialectRegistryEnabledFlag = true; +void mlir::enableGlobalDialectRegistry(bool enable) { + isGlobalDialectRegistryEnabledFlag = enable; +} +bool mlir::isGlobalDialectRegistryEnabled() { + return isGlobalDialectRegistryEnabledFlag; +} + void mlir::registerAllDialects(MLIRContext *context) { dialectRegistry->appendTo(context->getDialectRegistry()); } diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp --- a/mlir/lib/IR/MLIRContext.cpp +++ b/mlir/lib/IR/MLIRContext.cpp @@ -517,6 +517,8 @@ } void MLIRContext::loadAllGloballyRegisteredDialects() { + if (!isGlobalDialectRegistryEnabled()) + return; getGlobalDialectRegistry().loadAll(this); }