[mlir] avoid exposing mutable DialectRegistry from MLIRContext
authorAlex Zinenko <zinenko@google.com>
Wed, 10 Feb 2021 09:11:50 +0000 (10:11 +0100)
committerAlex Zinenko <zinenko@google.com>
Wed, 10 Feb 2021 11:07:34 +0000 (12:07 +0100)
commit2996a8d67553b9d469e01215b49bb1af17ad6d1e
tree7a72125c31dd6b0e52b22a2ee0b2c0f5f8adf72f
parent3da51522fb4f72b7d4619f2dfd454bb3073ab460
[mlir] avoid exposing mutable DialectRegistry from MLIRContext

MLIRContext allows its users to access directly to the DialectRegistry it
contains. While sometimes useful for registering additional dialects on an
already existing context, this breaks the encapsulation by essentially giving
raw accesses to a part of the context's internal state. Remove this mutable
access and instead provide a method to append a given DialectRegistry to the
one already contained in the context. Also provide a shortcut mechanism to
construct a context from an already existing registry, which seems to be a
common use case in the wild. Keep read-only access to the registry contained in
the context in case it needs to be copied or used for constructing another
context.

With this change, DialectRegistry is no longer concerned with loading the
dialects and deciding whether to invoke delayed interface registration. Loading
is concentrated in the MLIRContext, and the functionality of the registry
better reflects its name.

Depends On D96137

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D96331
15 files changed:
flang/tools/tco/tco.cpp
mlir/include/mlir/CAPI/Registration.h
mlir/include/mlir/IR/Dialect.h
mlir/include/mlir/IR/MLIRContext.h
mlir/include/mlir/InitAllDialects.h
mlir/lib/CAPI/Registration/Registration.cpp
mlir/lib/ExecutionEngine/JitRunner.cpp
mlir/lib/IR/Dialect.cpp
mlir/lib/IR/MLIRContext.cpp
mlir/lib/Pass/Pass.cpp
mlir/lib/Support/MlirOptMain.cpp
mlir/lib/Target/SPIRV/TranslateRegistration.cpp
mlir/lib/Translation/Translation.cpp
mlir/tools/mlir-reduce/mlir-reduce.cpp
mlir/unittests/IR/DialectTest.cpp