llvm-project/mlir
Mehdi Amini f9dc2b7079 Separate the Registration from Loading dialects in the Context
This changes the behavior of constructing MLIRContext to no longer load globally
registered dialects on construction. Instead Dialects are only loaded explicitly
on demand:
- the Parser is lazily loading Dialects in the context as it encounters them
during parsing. This is the only purpose for registering dialects and not load
them in the context.
- Passes are expected to declare the dialects they will create entity from
(Operations, Attributes, or Types), and the PassManager is loading Dialects into
the Context when starting a pipeline.

This changes simplifies the configuration of the registration: a compiler only
need to load the dialect for the IR it will emit, and the optimizer is
self-contained and load the required Dialects. For example in the Toy tutorial,
the compiler only needs to load the Toy dialect in the Context, all the others
(linalg, affine, std, LLVM, ...) are automatically loaded depending on the
optimization pipeline enabled.

To adjust to this change, stop using the existing dialect registration: the
global registry will be removed soon.

1) For passes, you need to override the method:

virtual void getDependentDialects(DialectRegistry &registry) const {}

and registery on the provided registry any dialect that this pass can produce.
Passes defined in TableGen can provide this list in the dependentDialects list
field.

2) For dialects, on construction you can register dependent dialects using the
provided MLIRContext: `context.getOrLoadDialect<DialectName>()`
This is useful if a dialect may canonicalize or have interfaces involving
another dialect.

3) For loading IR, dialect that can be in the input file must be explicitly
registered with the context. `MlirOptMain()` is taking an explicit registry for
this purpose. See how the standalone-opt.cpp example is setup:

  mlir::DialectRegistry registry;
  registry.insert<mlir::standalone::StandaloneDialect>();
  registry.insert<mlir::StandardOpsDialect>();

Only operations from these two dialects can be in the input file. To include all
of the dialects in MLIR Core, you can populate the registry this way:

  mlir::registerAllDialects(registry);

4) For `mlir-translate` callback, as well as frontend, Dialects can be loaded in
the context before emitting the IR: context.getOrLoadDialect<ToyDialect>()

Differential Revision: https://reviews.llvm.org/D85622
2020-08-19 01:19:03 +00:00
..
cmake/modules [mlir] Make mlir_check_link_libraries() work with interface libraries 2020-08-14 11:39:04 -07:00
docs [mlir] Update the documentation for defining types 2020-08-18 18:02:20 -07:00
examples Separate the Registration from Loading dialects in the Context 2020-08-19 01:19:03 +00:00
include Separate the Registration from Loading dialects in the Context 2020-08-19 01:19:03 +00:00
integration_test [mlir] [VectorOps] Add masked load/store operations to Vector dialect 2020-08-05 16:45:24 -07:00
lib Separate the Registration from Loading dialects in the Context 2020-08-19 01:19:03 +00:00
test Separate the Registration from Loading dialects in the Context 2020-08-19 01:19:03 +00:00
tools Separate the Registration from Loading dialects in the Context 2020-08-19 01:19:03 +00:00
unittests Separate the Registration from Loading dialects in the Context 2020-08-19 01:19:03 +00:00
utils [mlir][NFC] Remove usernames and google bug numbers from TODO comments. 2020-07-07 01:40:52 -07:00
.clang-format
.clang-tidy Fix MLIR clang-tidy: when tweaking it does not inherit from the parent 2020-03-07 17:44:21 +00:00
CMakeLists.txt [mlir] Initial version of C APIs 2020-08-05 15:04:08 +02:00
LICENSE.TXT Add the Apache2 with LLVM exceptions license to MLIR 2019-12-24 00:58:06 -08:00
README.md mlir README.md: Fix the syntax 2019-12-24 13:31:07 +01:00

README.md

Multi-Level Intermediate Representation

See https://mlir.llvm.org/ for more information.