From f54914081fd43fa5aca92df6630723be902adebd Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Mon, 31 Aug 2020 22:39:39 +0000 Subject: [PATCH] Fix mlir-reduce to explicitly register dialects and disable the global dialect registry by default Clients who rely on the Context loading dialects from the global registry can call `mlir::enableGlobalDialectRegistry(true);` before creating an MLIRContext Differential Revision: https://reviews.llvm.org/D86897 --- mlir/lib/IR/Dialect.cpp | 2 +- mlir/tools/mlir-reduce/CMakeLists.txt | 12 ++++++++++++ mlir/tools/mlir-reduce/mlir-reduce.cpp | 11 +++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/mlir/lib/IR/Dialect.cpp b/mlir/lib/IR/Dialect.cpp index b3b1c916..f356e82 100644 --- a/mlir/lib/IR/Dialect.cpp +++ b/mlir/lib/IR/Dialect.cpp @@ -31,7 +31,7 @@ static llvm::ManagedStatic dialectRegistry; DialectRegistry &mlir::getGlobalDialectRegistry() { return *dialectRegistry; } // Note: deprecated, will be removed soon. -static bool isGlobalDialectRegistryEnabledFlag = true; +static bool isGlobalDialectRegistryEnabledFlag = false; void mlir::enableGlobalDialectRegistry(bool enable) { isGlobalDialectRegistryEnabledFlag = enable; } diff --git a/mlir/tools/mlir-reduce/CMakeLists.txt b/mlir/tools/mlir-reduce/CMakeLists.txt index 8262dc9..958c2c9 100644 --- a/mlir/tools/mlir-reduce/CMakeLists.txt +++ b/mlir/tools/mlir-reduce/CMakeLists.txt @@ -13,6 +13,18 @@ set(LLVM_LINK_COMPONENTS TransformUtils ) +if(MLIR_INCLUDE_TESTS) + set(test_libs + MLIRAffineTransformsTestPasses + MLIRSPIRVTestPasses + MLIRTestDialect + MLIRTestIR + MLIRTestPass + MLIRTestReducer + MLIRTestTransforms + ) +endif() + set(LIBS ${dialect_libs} ${conversion_libs} diff --git a/mlir/tools/mlir-reduce/mlir-reduce.cpp b/mlir/tools/mlir-reduce/mlir-reduce.cpp index e60aa2f..3397bfc 100644 --- a/mlir/tools/mlir-reduce/mlir-reduce.cpp +++ b/mlir/tools/mlir-reduce/mlir-reduce.cpp @@ -32,6 +32,10 @@ using namespace mlir; +namespace mlir { +void registerTestDialect(DialectRegistry &); +} + static llvm::cl::opt inputFilename(llvm::cl::Positional, llvm::cl::Required, llvm::cl::desc("")); @@ -85,9 +89,12 @@ int main(int argc, char **argv) { llvm::report_fatal_error(errorMessage); mlir::MLIRContext context; - mlir::OwningModuleRef moduleRef; - context.allowUnregisteredDialects(true); + registerAllDialects(context.getDialectRegistry()); +#ifdef MLIR_INCLUDE_TESTS + mlir::registerTestDialect(context.getDialectRegistry()); +#endif + mlir::OwningModuleRef moduleRef; if (failed(loadModule(context, moduleRef, inputFilename))) llvm::report_fatal_error("Input test case can't be parsed"); -- 2.7.4