Add a utility method to MLIRContext get a registered dialect with the derived type instead of the string name. The derived dialect type must provide a static 'getDialectNamespace' method.

This means that we can now do something like:
      ctx->getRegisteredDialect<LLVMDialect>();

    as opposed to:
      static_cast<LLVMDialect *>(ctx->getRegisteredDialect("llvm");

--

PiperOrigin-RevId: 247989896
This commit is contained in:
River Riddle
2019-05-13 12:42:25 -07:00
committed by Mehdi Amini
parent d39a30626e
commit bc5c7378b2
7 changed files with 21 additions and 16 deletions

View File

@@ -409,11 +409,10 @@ bool ModuleTranslation::convertFunctions() {
}
std::unique_ptr<llvm::Module> ModuleTranslation::prepareLLVMModule(Module &m) {
Dialect *dialect = m.getContext()->getRegisteredDialect("llvm");
auto *dialect = m.getContext()->getRegisteredDialect<LLVM::LLVMDialect>();
assert(dialect && "LLVM dialect must be registered");
auto *llvmDialect = static_cast<LLVM::LLVMDialect *>(dialect);
auto llvmModule = llvm::CloneModule(llvmDialect->getLLVMModule());
auto llvmModule = llvm::CloneModule(dialect->getLLVMModule());
if (!llvmModule)
return nullptr;