[Mlir-commits] [mlir] 7b00c80 - Add a global flag to disable the global dialect registry "process wise"

Mehdi Amini llvmlistbot at llvm.org
Thu Aug 27 20:17:26 PDT 2020


Author: Mehdi Amini
Date: 2020-08-28T03:17:15Z
New Revision: 7b00c80888f8fd42b07be0fd23bf3b475b6ae207

URL: https://github.com/llvm/llvm-project/commit/7b00c80888f8fd42b07be0fd23bf3b475b6ae207
DIFF: https://github.com/llvm/llvm-project/commit/7b00c80888f8fd42b07be0fd23bf3b475b6ae207.diff

LOG: Add a global flag to disable the global dialect registry "process wise"

This is intended to ease the transition for client with a lot of
dependencies. It'll be removed in the coming weeks.

Differential Revision: https://reviews.llvm.org/D86755

Added: 
    

Modified: 
    mlir/include/mlir/IR/Dialect.h
    mlir/lib/IR/Dialect.cpp
    mlir/lib/IR/MLIRContext.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/Dialect.h b/mlir/include/mlir/IR/Dialect.h
index 0fe1a7f29724..36571b9cbde9 100644
--- a/mlir/include/mlir/IR/Dialect.h
+++ b/mlir/include/mlir/IR/Dialect.h
@@ -287,10 +287,17 @@ class DialectRegistry {
 /// 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
index 09fc998f9aa6..b3b1c9166d77 100644
--- a/mlir/lib/IR/Dialect.cpp
+++ b/mlir/lib/IR/Dialect.cpp
@@ -23,13 +23,22 @@ using namespace detail;
 DialectAsmParser::~DialectAsmParser() {}
 
 //===----------------------------------------------------------------------===//
-// Dialect Registration
+// Dialect Registration (DEPRECATED)
 //===----------------------------------------------------------------------===//
 
 /// Registry for all dialect allocation functions.
 static llvm::ManagedStatic<DialectRegistry> 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
index 61dafc3e39f8..1d81fde69e4c 100644
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -517,6 +517,8 @@ MLIRContext::getOrLoadDialect(StringRef dialectNamespace, TypeID dialectID,
 }
 
 void MLIRContext::loadAllGloballyRegisteredDialects() {
+  if (!isGlobalDialectRegistryEnabled())
+    return;
   getGlobalDialectRegistry().loadAll(this);
 }
 


        


More information about the Mlir-commits mailing list