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
This commit is contained in:
Mehdi Amini 2020-08-31 22:39:39 +00:00
parent 474a5a6654
commit f54914081f
3 changed files with 22 additions and 3 deletions

View file

@ -31,7 +31,7 @@ static llvm::ManagedStatic<DialectRegistry> 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;
}

View file

@ -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}

View file

@ -32,6 +32,10 @@
using namespace mlir;
namespace mlir {
void registerTestDialect(DialectRegistry &);
}
static llvm::cl::opt<std::string> inputFilename(llvm::cl::Positional,
llvm::cl::Required,
llvm::cl::desc("<input file>"));
@ -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");