llvm-project/mlir/lib/IR
Mehdi Amini e1de2b7550 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;
  mlir::registerDialect<mlir::standalone::StandaloneDialect>();
  mlir::registerDialect<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>()
2020-08-18 21:14:39 +00:00
..
AffineExpr.cpp [mlir] Refactor StorageUniquer to require registration of possible storage types 2020-08-07 13:43:24 -07:00
AffineExprDetail.h Mass update the MLIR license header to mention "Part of the LLVM project" 2020-01-26 03:58:30 +00:00
AffineMap.cpp [mlir] Added support for symbols inside linalg.generic and map concatenation 2020-07-20 19:20:47 +02:00
AffineMapDetail.h Mass update the MLIR license header to mention "Part of the LLVM project" 2020-01-26 03:58:30 +00:00
AsmPrinter.cpp [mlir] Fix printing of unranked memrefs in non-default memory space 2020-08-18 09:32:35 +02:00
AttributeDetail.h [mlir][NFC] Remove usernames and google bug numbers from TODO comments. 2020-07-07 01:40:52 -07:00
Attributes.cpp [mlir][Type] Remove the remaining usages of Type::getKind in preparation for its removal 2020-08-12 19:33:58 -07:00
Block.cpp [mlir][Standard] Add a canonicalization to simplify cond_br when the successors are identical 2020-04-23 04:42:02 -07:00
Builders.cpp [mlir][Type] Remove the remaining usages of Type::getKind in preparation for its removal 2020-08-12 19:33:58 -07:00
CMakeLists.txt [MLIR] Change FunctionType::get() and TupleType::get() to use TypeRange 2020-08-04 12:43:40 -07:00
Diagnostics.cpp [mlir][Attribute] Remove usages of Attribute::getKind 2020-08-07 13:43:25 -07:00
Dialect.cpp Separate the Registration from Loading dialects in the Context 2020-08-18 21:14:39 +00:00
Dominance.cpp [MLIR] Add RegionKindInterface 2020-07-15 14:27:05 -07:00
Function.cpp [MLIR] Combine the 2 overloads of FuncOp::build() into one. 2020-07-07 18:22:22 -07:00
FunctionImplementation.cpp [MLIR] Add argument related API to Region 2020-07-14 09:28:29 -07:00
IntegerSet.cpp [MLIR][NFC] drop some unnecessary includes 2020-03-27 09:17:27 +05:30
IntegerSetDetail.h Mass update the MLIR license header to mention "Part of the LLVM project" 2020-01-26 03:58:30 +00:00
Location.cpp [mlir][Attribute] Remove usages of Attribute::getKind 2020-08-07 13:43:25 -07:00
LocationDetail.h [mlir][NFC] Refactor ClassID into a TypeID class. 2020-04-10 23:52:33 -07:00
MLIRContext.cpp Separate the Registration from Loading dialects in the Context 2020-08-18 21:14:39 +00:00
Module.cpp [MLIR] Add a NoRegionArguments trait 2020-07-06 09:05:38 -07:00
Operation.cpp Separate the Registration from Loading dialects in the Context 2020-08-18 21:14:39 +00:00
OperationSupport.cpp [MLIR] Change FunctionType::get() and TupleType::get() to use TypeRange 2020-08-04 12:43:40 -07:00
PatternMatch.cpp [mlir] Allow for patterns to match any root kind. 2020-06-18 13:58:47 -07:00
Region.cpp [NFC] Add getArgumentTypes() to Region 2020-07-28 18:27:42 -07:00
RegionKindInterface.cpp [MLIR] Add RegionKindInterface 2020-07-15 14:27:05 -07:00
StandardTypes.cpp Improve error message when constructing a Tensor with an invalid element type (NFC) 2020-08-17 20:40:32 +00:00
SymbolTable.cpp [MLIR] Add variadic isa<> for Type, Value, and Attribute 2020-06-29 15:04:48 -07:00
TypeDetail.h [mlir][Types] Remove the subclass data from Type 2020-08-07 13:43:25 -07:00
TypeRange.cpp [MLIR] Change FunctionType::get() and TupleType::get() to use TypeRange 2020-08-04 12:43:40 -07:00
TypeUtilities.cpp Eliminate all uses of Identifier::is() in the source tree, this doesn't remove the definition of it (yet). NFC. 2020-04-13 11:49:31 -07:00
Types.cpp [mlir][Types] Remove the subclass data from Type 2020-08-07 13:43:25 -07:00
Value.cpp [mlir][DialectConversion] Enable deeper integration of type conversions 2020-07-23 19:40:31 -07:00
Verifier.cpp Separate the Registration from Loading dialects in the Context 2020-08-18 21:14:39 +00:00
Visitors.cpp [mlir][NFC] Remove usernames and google bug numbers from TODO comments. 2020-07-07 01:40:52 -07:00