[mlir] enable delayed registration of dialect interfaces
authorAlex Zinenko <zinenko@google.com>
Wed, 10 Feb 2021 09:11:40 +0000 (10:11 +0100)
committerAlex Zinenko <zinenko@google.com>
Wed, 10 Feb 2021 11:07:32 +0000 (12:07 +0100)
commit3da51522fb4f72b7d4619f2dfd454bb3073ab460
tree537189494b4d751fa0a7a5d6e4b4a0bf1b502595
parenta3c74d6d53fcaf53ac0969dcc7a9ab6dd5c9a9f5
[mlir] enable delayed registration of dialect interfaces

This introduces a mechanism to register interfaces for a dialect without making
the dialect itself depend on the interface. The registration request happens on
DialectRegistry and, if the dialect has not been loaded yet, the actual
registration is delayed until the dialect is loaded. It requires
DialectRegistry to become aware of the context that contains it and the context
to expose methods for querying if a dialect is loaded.

This mechanism will enable a simple extension mechanism for dialects that can
have interfaces defined outside of the dialect code. It is particularly helpful
for, e.g., translation to LLVM IR where we don't want the dialect itself to
depend on LLVM IR libraries.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D96137
mlir/include/mlir/IR/Dialect.h
mlir/lib/IR/Dialect.cpp
mlir/lib/IR/MLIRContext.cpp
mlir/lib/Support/MlirOptMain.cpp
mlir/unittests/IR/DialectTest.cpp