[all-commits] [llvm/llvm-project] d14cf4: Separate the Registration from Loading dialects in...

Mehdi Amini via All-commits all-commits at lists.llvm.org
Tue Aug 18 16:25:38 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: d14cf45735b0d09d7d3caf0824779520dd20ef10
      https://github.com/llvm/llvm-project/commit/d14cf45735b0d09d7d3caf0824779520dd20ef10
  Author: Mehdi Amini <joker.eph at gmail.com>
  Date:   2020-08-18 (Tue, 18 Aug 2020)

  Changed paths:
    M mlir/examples/standalone/standalone-opt/standalone-opt.cpp
    M mlir/examples/standalone/test/Standalone/standalone-opt.mlir
    M mlir/examples/toy/Ch2/toyc.cpp
    M mlir/examples/toy/Ch3/toyc.cpp
    M mlir/examples/toy/Ch4/toyc.cpp
    M mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
    M mlir/examples/toy/Ch5/toyc.cpp
    M mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
    M mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
    M mlir/examples/toy/Ch6/toyc.cpp
    M mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
    M mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
    M mlir/examples/toy/Ch7/toyc.cpp
    M mlir/include/mlir-c/Registration.h
    M mlir/include/mlir/Conversion/Passes.td
    M mlir/include/mlir/Dialect/Affine/Passes.td
    M mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h
    M mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
    M mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h
    M mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
    M mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.h
    M mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td
    M mlir/include/mlir/Dialect/Linalg/Passes.td
    M mlir/include/mlir/Dialect/SCF/Passes.td
    M mlir/include/mlir/IR/Dialect.h
    M mlir/include/mlir/IR/FunctionSupport.h
    M mlir/include/mlir/IR/MLIRContext.h
    M mlir/include/mlir/IR/OpBase.td
    M mlir/include/mlir/InitAllDialects.h
    M mlir/include/mlir/InitAllTranslations.h
    M mlir/include/mlir/Pass/Pass.h
    M mlir/include/mlir/Pass/PassBase.td
    M mlir/include/mlir/Pass/PassManager.h
    M mlir/include/mlir/Support/MlirOptMain.h
    M mlir/include/mlir/TableGen/Dialect.h
    M mlir/include/mlir/TableGen/Pass.h
    M mlir/include/mlir/Transforms/Passes.td
    M mlir/lib/CAPI/IR/IR.cpp
    M mlir/lib/CAPI/Registration/Registration.cpp
    M mlir/lib/Conversion/GPUToVulkan/ConvertGPULaunchFuncToVulkanLaunchFunc.cpp
    M mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp
    M mlir/lib/Conversion/PassDetail.h
    M mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
    M mlir/lib/Conversion/StandardToSPIRV/LegalizeStandardForSPIRV.cpp
    M mlir/lib/Dialect/Affine/Transforms/PassDetail.h
    M mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
    M mlir/lib/Dialect/Linalg/Transforms/PassDetail.h
    M mlir/lib/Dialect/SCF/Transforms/PassDetail.h
    M mlir/lib/Dialect/SDBM/SDBMExpr.cpp
    M mlir/lib/ExecutionEngine/JitRunner.cpp
    M mlir/lib/IR/Dialect.cpp
    M mlir/lib/IR/MLIRContext.cpp
    M mlir/lib/IR/Operation.cpp
    M mlir/lib/IR/Verifier.cpp
    M mlir/lib/Parser/AttributeParser.cpp
    M mlir/lib/Parser/DialectSymbolParser.cpp
    M mlir/lib/Parser/Parser.cpp
    M mlir/lib/Pass/Pass.cpp
    M mlir/lib/Pass/PassDetail.h
    M mlir/lib/Support/MlirOptMain.cpp
    M mlir/lib/TableGen/Dialect.cpp
    M mlir/lib/TableGen/Pass.cpp
    M mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
    M mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
    M mlir/lib/Transforms/PassDetail.h
    M mlir/test/CAPI/ir.c
    M mlir/test/EDSC/builder-api-test.cpp
    M mlir/test/SDBM/sdbm-api-test.cpp
    M mlir/test/lib/Dialect/Affine/TestVectorizationUtils.cpp
    M mlir/test/lib/Dialect/SPIRV/TestAvailability.cpp
    M mlir/test/lib/Dialect/Test/TestDialect.cpp
    M mlir/test/lib/Dialect/Test/TestDialect.h
    M mlir/test/lib/Dialect/Test/TestPatterns.cpp
    M mlir/test/lib/Transforms/TestAllReduceLowering.cpp
    M mlir/test/lib/Transforms/TestBufferPlacement.cpp
    M mlir/test/lib/Transforms/TestGpuMemoryPromotion.cpp
    M mlir/test/lib/Transforms/TestLinalgHoisting.cpp
    M mlir/test/lib/Transforms/TestLinalgTransforms.cpp
    M mlir/test/lib/Transforms/TestVectorTransforms.cpp
    M mlir/test/mlir-opt/commandline.mlir
    M mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp
    M mlir/tools/mlir-opt/mlir-opt.cpp
    M mlir/tools/mlir-tblgen/DialectGen.cpp
    M mlir/tools/mlir-tblgen/PassGen.cpp
    M mlir/tools/mlir-translate/mlir-translate.cpp
    M mlir/unittests/Dialect/Quant/QuantizationUtilsTest.cpp
    M mlir/unittests/Dialect/SPIRV/DeserializationTest.cpp
    M mlir/unittests/Dialect/SPIRV/SerializationTest.cpp
    M mlir/unittests/IR/AttributeTest.cpp
    M mlir/unittests/IR/DialectTest.cpp
    M mlir/unittests/IR/OperationSupportTest.cpp
    M mlir/unittests/Pass/AnalysisManagerTest.cpp
    M mlir/unittests/SDBM/SDBMTest.cpp
    M mlir/unittests/TableGen/OpBuildGen.cpp
    M mlir/unittests/TableGen/StructsGenTest.cpp

  Log Message:
  -----------
  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




More information about the All-commits mailing list