llvm-project/mlir/lib/Transforms
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
..
Utils [MLIR] Support for ReturnOps in memref map layout normalization 2020-08-13 19:10:47 +05:30
BufferPlacement.cpp Remove spurious empty line at the beginning of source file (NFC) 2020-08-14 08:02:59 +00:00
CMakeLists.txt [MLIR] Introduce inter-procedural memref layout normalization 2020-07-30 18:12:56 +05:30
CSE.cpp [MLIR] Add RegionKindInterface 2020-07-15 14:27:05 -07:00
Canonicalizer.cpp [MLIR][NFC] applyPatternsGreedily -> applyPatternsAndFoldGreedily 2020-04-10 12:55:21 +05:30
CopyRemoval.cpp [mlir][NFC] Polish copy removal transform 2020-07-28 08:34:44 +02:00
DialectConversion.cpp [mlir][DialectConversion] Remove usage of std::distance to track position. 2020-08-03 10:06:05 -07:00
Inliner.cpp [mlir][NFC] Remove usernames and google bug numbers from TODO comments. 2020-07-07 01:40:52 -07:00
LocationSnapshot.cpp [mlir][Pass] Update the PassGen to generate base classes instead of utilities 2020-04-07 14:08:52 -07:00
LoopCoalescing.cpp [mlir] NFC: Rename LoopOps dialect to SCF (Structured Control Flow) 2020-05-11 15:04:27 +02:00
LoopFusion.cpp [MLIR][Affine] Fix createPrivateMemRef in affine fusion 2020-08-04 12:17:48 -07:00
LoopInvariantCodeMotion.cpp [NFC][MLIR] Undo anonymous namespace change from https://reviews.llvm.org/D82417 2020-06-23 20:21:42 -07:00
MemRefDataFlowOpt.cpp [MLIR] Vector store to load forwarding 2020-07-28 11:30:54 -07:00
NormalizeMemRefs.cpp [MLIR] Support for ReturnOps in memref map layout normalization 2020-08-13 19:10:47 +05:30
OpStats.cpp [mlir][Pass] Update the PassGen to generate base classes instead of utilities 2020-04-07 14:08:52 -07:00
ParallelLoopCollapsing.cpp [mlir] NFC: Rename LoopOps dialect to SCF (Structured Control Flow) 2020-05-11 15:04:27 +02:00
PassDetail.h Separate the Registration from Loading dialects in the Context 2020-08-18 21:14:39 +00:00
PipelineDataTransfer.cpp [mlir][NFC] Remove usernames and google bug numbers from TODO comments. 2020-07-07 01:40:52 -07:00
SCCP.cpp [MLIR] Add argument related API to Region 2020-07-14 09:28:29 -07:00
StripDebugInfo.cpp [mlir][Pass] Update the PassGen to generate base classes instead of utilities 2020-04-07 14:08:52 -07:00
SymbolDCE.cpp [mlir][Symbol] Change Symbol from a Trait into an OpInterface. 2020-04-27 13:04:49 -07:00
ViewOpGraph.cpp [NFC] Use llvm::hasSingleElement() in place of .size() == 1 2020-06-17 13:26:10 -07:00
ViewRegionGraph.cpp [mlir][Pass] Update the PassGen to generate base classes instead of utilities 2020-04-07 14:08:52 -07:00