From ba92dadf05c50d53e6bc7345f081e0a5f540b01e Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Sat, 15 Aug 2020 07:33:59 +0000 Subject: [PATCH] Revert "Separate the Registration from Loading dialects in the Context" This was landed by accident, will reland with the right comments addressed from the reviews. Also revert dependent build fixes. --- flang/unittests/Lower/OpenMPLoweringTest.cpp | 3 +- .../standalone/standalone-opt/standalone-opt.cpp | 2 +- mlir/examples/toy/Ch2/toyc.cpp | 7 +- mlir/examples/toy/Ch3/toyc.cpp | 6 +- mlir/examples/toy/Ch4/toyc.cpp | 6 +- mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp | 4 - mlir/examples/toy/Ch5/toyc.cpp | 6 +- mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp | 4 - mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp | 4 - mlir/examples/toy/Ch6/toyc.cpp | 6 +- mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp | 4 - mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp | 4 - mlir/examples/toy/Ch7/toyc.cpp | 6 +- mlir/include/mlir-c/IR.h | 6 -- mlir/include/mlir/Conversion/Passes.td | 26 ------- mlir/include/mlir/Dialect/Affine/Passes.td | 1 - mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h | 1 - mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td | 5 -- mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h | 1 - mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td | 1 - mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.h | 1 - mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td | 1 - mlir/include/mlir/Dialect/Linalg/Passes.td | 8 -- mlir/include/mlir/Dialect/SCF/Passes.td | 1 - mlir/include/mlir/IR/Dialect.h | 83 ++++----------------- mlir/include/mlir/IR/FunctionSupport.h | 4 +- mlir/include/mlir/IR/MLIRContext.h | 54 ++++---------- mlir/include/mlir/IR/OpBase.td | 5 -- mlir/include/mlir/InitAllDialects.h | 43 +++++------ mlir/include/mlir/Pass/Pass.h | 8 -- mlir/include/mlir/Pass/PassBase.td | 3 - mlir/include/mlir/Pass/PassManager.h | 14 ---- mlir/include/mlir/Support/MlirOptMain.h | 7 +- mlir/include/mlir/TableGen/Dialect.h | 8 +- mlir/include/mlir/TableGen/Pass.h | 4 - mlir/include/mlir/Transforms/Passes.td | 2 - mlir/lib/CAPI/IR/IR.cpp | 7 +- .../ConvertGPULaunchFuncToVulkanLaunchFunc.cpp | 1 - mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp | 1 - mlir/lib/Conversion/PassDetail.h | 32 -------- .../Conversion/StandardToLLVM/StandardToLLVM.cpp | 2 +- .../StandardToSPIRV/LegalizeStandardForSPIRV.cpp | 1 - mlir/lib/Dialect/Affine/Transforms/PassDetail.h | 10 --- mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp | 1 - mlir/lib/Dialect/Linalg/Transforms/PassDetail.h | 9 --- mlir/lib/Dialect/SCF/Transforms/PassDetail.h | 5 -- mlir/lib/Dialect/SDBM/SDBMExpr.cpp | 2 +- mlir/lib/ExecutionEngine/JitRunner.cpp | 4 +- mlir/lib/IR/Dialect.cpp | 33 ++++---- mlir/lib/IR/MLIRContext.cpp | 87 ++++++++-------------- mlir/lib/IR/Operation.cpp | 2 +- mlir/lib/IR/Verifier.cpp | 4 +- mlir/lib/Parser/AttributeParser.cpp | 10 +-- mlir/lib/Parser/DialectSymbolParser.cpp | 7 +- mlir/lib/Parser/Parser.cpp | 41 +++------- mlir/lib/Pass/Pass.cpp | 27 ------- mlir/lib/Pass/PassDetail.h | 4 - mlir/lib/Support/MlirOptMain.cpp | 14 +--- mlir/lib/TableGen/Dialect.cpp | 9 --- mlir/lib/TableGen/Pass.cpp | 5 -- mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp | 1 - mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 5 +- mlir/lib/Transforms/PassDetail.h | 7 -- mlir/test/CAPI/ir.c | 1 - mlir/test/EDSC/builder-api-test.cpp | 14 ++-- mlir/test/SDBM/sdbm-api-test.cpp | 9 +-- .../lib/Dialect/Affine/TestVectorizationUtils.cpp | 4 - mlir/test/lib/Dialect/SPIRV/TestAvailability.cpp | 2 +- mlir/test/lib/Dialect/Test/TestPatterns.cpp | 4 - mlir/test/lib/Transforms/TestAllReduceLowering.cpp | 4 - mlir/test/lib/Transforms/TestBufferPlacement.cpp | 4 - .../test/lib/Transforms/TestGpuMemoryPromotion.cpp | 8 -- mlir/test/lib/Transforms/TestLinalgHoisting.cpp | 4 - mlir/test/lib/Transforms/TestLinalgTransforms.cpp | 9 --- mlir/test/lib/Transforms/TestVectorTransforms.cpp | 10 --- mlir/test/mlir-opt/commandline.mlir | 2 +- .../mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp | 2 +- mlir/tools/mlir-opt/mlir-opt.cpp | 9 ++- mlir/tools/mlir-tblgen/DialectGen.cpp | 20 +---- mlir/tools/mlir-tblgen/PassGen.cpp | 21 +----- mlir/tools/mlir-translate/mlir-translate.cpp | 3 +- .../Dialect/Quant/QuantizationUtilsTest.cpp | 15 ++-- .../Dialect/SPIRV/DeserializationTest.cpp | 3 +- mlir/unittests/Dialect/SPIRV/SerializationTest.cpp | 5 +- mlir/unittests/IR/AttributeTest.cpp | 32 ++++---- mlir/unittests/IR/DialectTest.cpp | 6 +- mlir/unittests/IR/OperationSupportTest.cpp | 8 +- mlir/unittests/Pass/AnalysisManagerTest.cpp | 8 +- mlir/unittests/SDBM/SDBMTest.cpp | 7 +- mlir/unittests/TableGen/OpBuildGen.cpp | 9 +-- mlir/unittests/TableGen/StructsGenTest.cpp | 2 +- 91 files changed, 214 insertions(+), 691 deletions(-) diff --git a/flang/unittests/Lower/OpenMPLoweringTest.cpp b/flang/unittests/Lower/OpenMPLoweringTest.cpp index 4c23845..ad6fe73 100644 --- a/flang/unittests/Lower/OpenMPLoweringTest.cpp +++ b/flang/unittests/Lower/OpenMPLoweringTest.cpp @@ -15,7 +15,8 @@ class OpenMPLoweringTest : public testing::Test { protected: void SetUp() override { - ctx.getOrLoadDialect(); + mlir::registerDialect(); + mlir::registerAllDialects(&ctx); mlirOpBuilder.reset(new mlir::OpBuilder(&ctx)); } diff --git a/mlir/examples/standalone/standalone-opt/standalone-opt.cpp b/mlir/examples/standalone/standalone-opt/standalone-opt.cpp index eb624b3..5c99058 100644 --- a/mlir/examples/standalone/standalone-opt/standalone-opt.cpp +++ b/mlir/examples/standalone/standalone-opt/standalone-opt.cpp @@ -76,7 +76,7 @@ int main(int argc, char **argv) { if (showDialects) { mlir::MLIRContext context; llvm::outs() << "Registered Dialects:\n"; - for (mlir::Dialect *dialect : context.getLoadedDialects()) { + for (mlir::Dialect *dialect : context.getRegisteredDialects()) { llvm::outs() << dialect->getNamespace() << "\n"; } return 0; diff --git a/mlir/examples/toy/Ch2/toyc.cpp b/mlir/examples/toy/Ch2/toyc.cpp index 99232d8..d0880ce 100644 --- a/mlir/examples/toy/Ch2/toyc.cpp +++ b/mlir/examples/toy/Ch2/toyc.cpp @@ -68,9 +68,10 @@ std::unique_ptr parseInputFile(llvm::StringRef filename) { } int dumpMLIR() { - mlir::MLIRContext context(/*loadAllDialects=*/false); - // Load our Dialect in this MLIR Context. - context.getOrLoadDialect(); + // Register our Dialect with MLIR. + mlir::registerDialect(); + + mlir::MLIRContext context; // Handle '.toy' input to the compiler. if (inputType != InputType::MLIR && diff --git a/mlir/examples/toy/Ch3/toyc.cpp b/mlir/examples/toy/Ch3/toyc.cpp index d0430ce..f9d5631 100644 --- a/mlir/examples/toy/Ch3/toyc.cpp +++ b/mlir/examples/toy/Ch3/toyc.cpp @@ -102,10 +102,10 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, } int dumpMLIR() { - mlir::MLIRContext context(/*loadAllDialects=*/false); - // Load our Dialect in this MLIR Context. - context.getOrLoadDialect(); + // Register our Dialect with MLIR. + mlir::registerDialect(); + mlir::MLIRContext context; mlir::OwningModuleRef module; llvm::SourceMgr sourceMgr; mlir::SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, &context); diff --git a/mlir/examples/toy/Ch4/toyc.cpp b/mlir/examples/toy/Ch4/toyc.cpp index 9f95887..e11f35c 100644 --- a/mlir/examples/toy/Ch4/toyc.cpp +++ b/mlir/examples/toy/Ch4/toyc.cpp @@ -103,10 +103,10 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, } int dumpMLIR() { - mlir::MLIRContext context(/*loadAllDialects=*/false); - // Load our Dialect in this MLIR Context. - context.getOrLoadDialect(); + // Register our Dialect with MLIR. + mlir::registerDialect(); + mlir::MLIRContext context; mlir::OwningModuleRef module; llvm::SourceMgr sourceMgr; mlir::SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, &context); diff --git a/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp index 1077fc9..3097681 100644 --- a/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp +++ b/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp @@ -256,10 +256,6 @@ struct TransposeOpLowering : public ConversionPattern { namespace { struct ToyToAffineLoweringPass : public PassWrapper { - void getDependentDialects(DialectRegistry ®istry) const override { - registry.insert(); - registry.insert(); - } void runOnFunction() final; }; } // end anonymous namespace. diff --git a/mlir/examples/toy/Ch5/toyc.cpp b/mlir/examples/toy/Ch5/toyc.cpp index 16faac0..ed04969 100644 --- a/mlir/examples/toy/Ch5/toyc.cpp +++ b/mlir/examples/toy/Ch5/toyc.cpp @@ -106,10 +106,10 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, } int dumpMLIR() { - mlir::MLIRContext context(/*loadAllDialects=*/false); - // Load our Dialect in this MLIR Context. - context.getOrLoadDialect(); + // Register our Dialect with MLIR. + mlir::registerDialect(); + mlir::MLIRContext context; mlir::OwningModuleRef module; llvm::SourceMgr sourceMgr; mlir::SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, &context); diff --git a/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp index 9ff9eb4..cac3415 100644 --- a/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp +++ b/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp @@ -255,10 +255,6 @@ struct TransposeOpLowering : public ConversionPattern { namespace { struct ToyToAffineLoweringPass : public PassWrapper { - void getDependentDialects(DialectRegistry ®istry) const override { - registry.insert(); - registry.insert(); - } void runOnFunction() final; }; } // end anonymous namespace. diff --git a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp index 8020fb3..74b32dc 100644 --- a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp +++ b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp @@ -159,10 +159,6 @@ private: namespace { struct ToyToLLVMLoweringPass : public PassWrapper> { - void getDependentDialects(DialectRegistry ®istry) const override { - registry.insert(); - registry.insert(); - } void runOnOperation() final; }; } // end anonymous namespace diff --git a/mlir/examples/toy/Ch6/toyc.cpp b/mlir/examples/toy/Ch6/toyc.cpp index 9504a38..bdcdf1a 100644 --- a/mlir/examples/toy/Ch6/toyc.cpp +++ b/mlir/examples/toy/Ch6/toyc.cpp @@ -255,10 +255,10 @@ int main(int argc, char **argv) { // If we aren't dumping the AST, then we are compiling with/to MLIR. - mlir::MLIRContext context(/*loadAllDialects=*/false); - // Load our Dialect in this MLIR Context. - context.getOrLoadDialect(); + // Register our Dialect with MLIR. + mlir::registerDialect(); + mlir::MLIRContext context; mlir::OwningModuleRef module; if (int error = loadAndProcessMLIR(context, module)) return error; diff --git a/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp index 1077fc9..3097681 100644 --- a/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp +++ b/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp @@ -256,10 +256,6 @@ struct TransposeOpLowering : public ConversionPattern { namespace { struct ToyToAffineLoweringPass : public PassWrapper { - void getDependentDialects(DialectRegistry ®istry) const override { - registry.insert(); - registry.insert(); - } void runOnFunction() final; }; } // end anonymous namespace. diff --git a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp index 8020fb3..74b32dc 100644 --- a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp +++ b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp @@ -159,10 +159,6 @@ private: namespace { struct ToyToLLVMLoweringPass : public PassWrapper> { - void getDependentDialects(DialectRegistry ®istry) const override { - registry.insert(); - registry.insert(); - } void runOnOperation() final; }; } // end anonymous namespace diff --git a/mlir/examples/toy/Ch7/toyc.cpp b/mlir/examples/toy/Ch7/toyc.cpp index cb3b455..c1cc207 100644 --- a/mlir/examples/toy/Ch7/toyc.cpp +++ b/mlir/examples/toy/Ch7/toyc.cpp @@ -256,10 +256,10 @@ int main(int argc, char **argv) { // If we aren't dumping the AST, then we are compiling with/to MLIR. - mlir::MLIRContext context(/*loadAllDialects=*/false); - // Load our Dialect in this MLIR Context. - context.getOrLoadDialect(); + // Register our Dialect with MLIR. + mlir::registerDialect(); + mlir::MLIRContext context; mlir::OwningModuleRef module; if (int error = loadAndProcessMLIR(context, module)) return error; diff --git a/mlir/include/mlir-c/IR.h b/mlir/include/mlir-c/IR.h index f9ec4d1..6b5be2d 100644 --- a/mlir/include/mlir-c/IR.h +++ b/mlir/include/mlir-c/IR.h @@ -90,12 +90,6 @@ MlirContext mlirContextCreate(); /** Takes an MLIR context owned by the caller and destroys it. */ void mlirContextDestroy(MlirContext context); -/** Load all the globally registered dialects in the provided context. - * TODO: remove the concept of globally registered dialect by exposing the - * DialectRegistry. - */ -void mlirContextLoadAllDialects(MlirContext context); - /*============================================================================*/ /* Location API. */ /*============================================================================*/ diff --git a/mlir/include/mlir/Conversion/Passes.td b/mlir/include/mlir/Conversion/Passes.td index 0c40bb3..4d4fe06 100644 --- a/mlir/include/mlir/Conversion/Passes.td +++ b/mlir/include/mlir/Conversion/Passes.td @@ -66,11 +66,6 @@ def ConvertAffineToStandard : Pass<"lower-affine"> { `affine.apply`. }]; let constructor = "mlir::createLowerAffinePass()"; - let dependentDialects = [ - "scf::SCFDialect", - "StandardOpsDialect", - "vector::VectorDialect" - ]; } //===----------------------------------------------------------------------===// @@ -81,7 +76,6 @@ def ConvertAVX512ToLLVM : Pass<"convert-avx512-to-llvm", "ModuleOp"> { let summary = "Convert the operations from the avx512 dialect into the LLVM " "dialect"; let constructor = "mlir::createConvertAVX512ToLLVMPass()"; - let dependentDialects = ["LLVM::LLVMDialect", "LLVM::LLVMAVX512Dialect"]; } //===----------------------------------------------------------------------===// @@ -104,7 +98,6 @@ def GpuToLLVMConversionPass : Pass<"gpu-to-llvm", "ModuleOp"> { def ConvertGpuOpsToNVVMOps : Pass<"convert-gpu-to-nvvm", "gpu::GPUModuleOp"> { let summary = "Generate NVVM operations for gpu operations"; let constructor = "mlir::createLowerGpuOpsToNVVMOpsPass()"; - let dependentDialects = ["NVVM::NVVMDialect"]; let options = [ Option<"indexBitwidth", "index-bitwidth", "unsigned", /*default=kDeriveIndexBitwidthFromDataLayout*/"0", @@ -119,7 +112,6 @@ def ConvertGpuOpsToNVVMOps : Pass<"convert-gpu-to-nvvm", "gpu::GPUModuleOp"> { def ConvertGpuOpsToROCDLOps : Pass<"convert-gpu-to-rocdl", "gpu::GPUModuleOp"> { let summary = "Generate ROCDL operations for gpu operations"; let constructor = "mlir::createLowerGpuOpsToROCDLOpsPass()"; - let dependentDialects = ["ROCDL::ROCDLDialect"]; let options = [ Option<"indexBitwidth", "index-bitwidth", "unsigned", /*default=kDeriveIndexBitwidthFromDataLayout*/"0", @@ -134,7 +126,6 @@ def ConvertGpuOpsToROCDLOps : Pass<"convert-gpu-to-rocdl", "gpu::GPUModuleOp"> { def ConvertGPUToSPIRV : Pass<"convert-gpu-to-spirv", "ModuleOp"> { let summary = "Convert GPU dialect to SPIR-V dialect"; let constructor = "mlir::createConvertGPUToSPIRVPass()"; - let dependentDialects = ["spirv::SPIRVDialect"]; } //===----------------------------------------------------------------------===// @@ -145,7 +136,6 @@ def ConvertGpuLaunchFuncToVulkanLaunchFunc : Pass<"convert-gpu-launch-to-vulkan-launch", "ModuleOp"> { let summary = "Convert gpu.launch_func to vulkanLaunch external call"; let constructor = "mlir::createConvertGpuLaunchFuncToVulkanLaunchFuncPass()"; - let dependentDialects = ["spirv::SPIRVDialect"]; } def ConvertVulkanLaunchFuncToVulkanCalls @@ -153,7 +143,6 @@ def ConvertVulkanLaunchFuncToVulkanCalls let summary = "Convert vulkanLaunch external call to Vulkan runtime external " "calls"; let constructor = "mlir::createConvertVulkanLaunchFuncToVulkanCallsPass()"; - let dependentDialects = ["LLVM::LLVMDialect"]; } //===----------------------------------------------------------------------===// @@ -164,7 +153,6 @@ def ConvertLinalgToLLVM : Pass<"convert-linalg-to-llvm", "ModuleOp"> { let summary = "Convert the operations from the linalg dialect into the LLVM " "dialect"; let constructor = "mlir::createConvertLinalgToLLVMPass()"; - let dependentDialects = ["scf::SCFDialect", "LLVM::LLVMDialect"]; } //===----------------------------------------------------------------------===// @@ -175,7 +163,6 @@ def ConvertLinalgToStandard : Pass<"convert-linalg-to-std", "ModuleOp"> { let summary = "Convert the operations from the linalg dialect into the " "Standard dialect"; let constructor = "mlir::createConvertLinalgToStandardPass()"; - let dependentDialects = ["StandardOpsDialect"]; } //===----------------------------------------------------------------------===// @@ -185,7 +172,6 @@ def ConvertLinalgToStandard : Pass<"convert-linalg-to-std", "ModuleOp"> { def ConvertLinalgToSPIRV : Pass<"convert-linalg-to-spirv", "ModuleOp"> { let summary = "Convert Linalg ops to SPIR-V ops"; let constructor = "mlir::createLinalgToSPIRVPass()"; - let dependentDialects = ["spirv::SPIRVDialect"]; } //===----------------------------------------------------------------------===// @@ -196,7 +182,6 @@ def SCFToStandard : Pass<"convert-scf-to-std"> { let summary = "Convert SCF dialect to Standard dialect, replacing structured" " control flow with a CFG"; let constructor = "mlir::createLowerToCFGPass()"; - let dependentDialects = ["StandardOpsDialect"]; } //===----------------------------------------------------------------------===// @@ -206,7 +191,6 @@ def SCFToStandard : Pass<"convert-scf-to-std"> { def ConvertAffineForToGPU : FunctionPass<"convert-affine-for-to-gpu"> { let summary = "Convert top-level AffineFor Ops to GPU kernels"; let constructor = "mlir::createAffineForToGPUPass()"; - let dependentDialects = ["gpu::GPUDialect"]; let options = [ Option<"numBlockDims", "gpu-block-dims", "unsigned", /*default=*/"1u", "Number of GPU block dimensions for mapping">, @@ -218,7 +202,6 @@ def ConvertAffineForToGPU : FunctionPass<"convert-affine-for-to-gpu"> { def ConvertParallelLoopToGpu : Pass<"convert-parallel-loops-to-gpu"> { let summary = "Convert mapped scf.parallel ops to gpu launch operations"; let constructor = "mlir::createParallelLoopToGpuPass()"; - let dependentDialects = ["AffineDialect", "gpu::GPUDialect"]; } //===----------------------------------------------------------------------===// @@ -229,7 +212,6 @@ def ConvertShapeToStandard : Pass<"convert-shape-to-std", "ModuleOp"> { let summary = "Convert operations from the shape dialect into the standard " "dialect"; let constructor = "mlir::createConvertShapeToStandardPass()"; - let dependentDialects = ["StandardOpsDialect"]; } //===----------------------------------------------------------------------===// @@ -239,7 +221,6 @@ def ConvertShapeToStandard : Pass<"convert-shape-to-std", "ModuleOp"> { def ConvertShapeToSCF : FunctionPass<"convert-shape-to-scf"> { let summary = "Convert operations from the shape dialect to the SCF dialect"; let constructor = "mlir::createConvertShapeToSCFPass()"; - let dependentDialects = ["scf::SCFDialect"]; } //===----------------------------------------------------------------------===// @@ -249,7 +230,6 @@ def ConvertShapeToSCF : FunctionPass<"convert-shape-to-scf"> { def ConvertSPIRVToLLVM : Pass<"convert-spirv-to-llvm", "ModuleOp"> { let summary = "Convert SPIR-V dialect to LLVM dialect"; let constructor = "mlir::createConvertSPIRVToLLVMPass()"; - let dependentDialects = ["LLVM::LLVMDialect"]; } //===----------------------------------------------------------------------===// @@ -284,7 +264,6 @@ def ConvertStandardToLLVM : Pass<"convert-std-to-llvm", "ModuleOp"> { LLVM IR types. }]; let constructor = "mlir::createLowerToLLVMPass()"; - let dependentDialects = ["LLVM::LLVMDialect"]; let options = [ Option<"useAlignedAlloc", "use-aligned-alloc", "bool", /*default=*/"false", "Use aligned_alloc in place of malloc for heap allocations">, @@ -308,13 +287,11 @@ def ConvertStandardToLLVM : Pass<"convert-std-to-llvm", "ModuleOp"> { def LegalizeStandardForSPIRV : Pass<"legalize-std-for-spirv"> { let summary = "Legalize standard ops for SPIR-V lowering"; let constructor = "mlir::createLegalizeStdOpsForSPIRVLoweringPass()"; - let dependentDialects = ["spirv::SPIRVDialect"]; } def ConvertStandardToSPIRV : Pass<"convert-std-to-spirv", "ModuleOp"> { let summary = "Convert Standard Ops to SPIR-V dialect"; let constructor = "mlir::createConvertStandardToSPIRVPass()"; - let dependentDialects = ["spirv::SPIRVDialect"]; } //===----------------------------------------------------------------------===// @@ -325,7 +302,6 @@ def ConvertVectorToSCF : FunctionPass<"convert-vector-to-scf"> { let summary = "Lower the operations from the vector dialect into the SCF " "dialect"; let constructor = "mlir::createConvertVectorToSCFPass()"; - let dependentDialects = ["AffineDialect", "scf::SCFDialect"]; let options = [ Option<"fullUnroll", "full-unroll", "bool", /*default=*/"false", "Perform full unrolling when converting vector transfers to SCF">, @@ -340,7 +316,6 @@ def ConvertVectorToLLVM : Pass<"convert-vector-to-llvm", "ModuleOp"> { let summary = "Lower the operations from the vector dialect into the LLVM " "dialect"; let constructor = "mlir::createConvertVectorToLLVMPass()"; - let dependentDialects = ["LLVM::LLVMDialect"]; let options = [ Option<"reassociateFPReductions", "reassociate-fp-reductions", "bool", /*default=*/"false", @@ -356,7 +331,6 @@ def ConvertVectorToROCDL : Pass<"convert-vector-to-rocdl", "ModuleOp"> { let summary = "Lower the operations from the vector dialect into the ROCDL " "dialect"; let constructor = "mlir::createConvertVectorToROCDLPass()"; - let dependentDialects = ["ROCDL::ROCDLDialect"]; } #endif // MLIR_CONVERSION_PASSES diff --git a/mlir/include/mlir/Dialect/Affine/Passes.td b/mlir/include/mlir/Dialect/Affine/Passes.td index f43fabd..8106400 100644 --- a/mlir/include/mlir/Dialect/Affine/Passes.td +++ b/mlir/include/mlir/Dialect/Affine/Passes.td @@ -94,7 +94,6 @@ def AffineLoopUnrollAndJam : FunctionPass<"affine-loop-unroll-jam"> { def AffineVectorize : FunctionPass<"affine-super-vectorize"> { let summary = "Vectorize to a target independent n-D vector abstraction"; let constructor = "mlir::createSuperVectorizePass()"; - let dependentDialects = ["vector::VectorDialect"]; let options = [ ListOption<"vectorSizes", "virtual-vector-size", "int64_t", "Specify an n-D virtual vector size for vectorization", diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h index 2f465f0..04700f0 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h @@ -15,7 +15,6 @@ #define MLIR_DIALECT_LLVMIR_LLVMDIALECT_H_ #include "mlir/Dialect/LLVMIR/LLVMTypes.h" -#include "mlir/Dialect/OpenMP/OpenMPDialect.h" #include "mlir/IR/Dialect.h" #include "mlir/IR/Function.h" #include "mlir/IR/OpDefinition.h" diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td index 2617a2d..d21f5bc 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td @@ -19,11 +19,6 @@ include "mlir/IR/OpBase.td" def LLVM_Dialect : Dialect { let name = "llvm"; let cppNamespace = "LLVM"; - - /// FIXME: at the moment this is a dependency of the translation to LLVM IR, - /// not really one of this dialect per-se. - let dependentDialects = [ "omp::OpenMPDialect" ]; - let hasRegionArgAttrVerify = 1; let extraClassDeclaration = [{ ~LLVMDialect(); diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h b/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h index 9cc5314..86d437c 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h +++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h @@ -14,7 +14,6 @@ #ifndef MLIR_DIALECT_LLVMIR_NVVMDIALECT_H_ #define MLIR_DIALECT_LLVMIR_NVVMDIALECT_H_ -#include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/IR/Dialect.h" #include "mlir/IR/OpDefinition.h" #include "mlir/Interfaces/SideEffectInterfaces.h" diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td index 0e5bc16..5f022e32 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td @@ -23,7 +23,6 @@ include "mlir/Interfaces/SideEffectInterfaces.td" def NVVM_Dialect : Dialect { let name = "nvvm"; let cppNamespace = "NVVM"; - let dependentDialects = [ "LLVM::LLVMDialect" ]; } //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.h b/mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.h index eb40373..bf761c3 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.h +++ b/mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.h @@ -22,7 +22,6 @@ #ifndef MLIR_DIALECT_LLVMIR_ROCDLDIALECT_H_ #define MLIR_DIALECT_LLVMIR_ROCDLDIALECT_H_ -#include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/IR/Dialect.h" #include "mlir/IR/OpDefinition.h" #include "mlir/Interfaces/SideEffectInterfaces.h" diff --git a/mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td b/mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td index f9aca5a..0cd1169 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td @@ -23,7 +23,6 @@ include "mlir/Interfaces/SideEffectInterfaces.td" def ROCDL_Dialect : Dialect { let name = "rocdl"; let cppNamespace = "ROCDL"; - let dependentDialects = [ "LLVM::LLVMDialect" ]; } //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/Dialect/Linalg/Passes.td b/mlir/include/mlir/Dialect/Linalg/Passes.td index dcf4b5e..11f12ad 100644 --- a/mlir/include/mlir/Dialect/Linalg/Passes.td +++ b/mlir/include/mlir/Dialect/Linalg/Passes.td @@ -30,20 +30,17 @@ def LinalgFusion : FunctionPass<"linalg-fusion"> { def LinalgFusionOfTensorOps : Pass<"linalg-fusion-for-tensor-ops"> { let summary = "Fuse operations on RankedTensorType in linalg dialect"; let constructor = "mlir::createLinalgFusionOfTensorOpsPass()"; - let dependentDialects = ["AffineDialect"]; } def LinalgLowerToAffineLoops : FunctionPass<"convert-linalg-to-affine-loops"> { let summary = "Lower the operations from the linalg dialect into affine " "loops"; let constructor = "mlir::createConvertLinalgToAffineLoopsPass()"; - let dependentDialects = ["AffineDialect"]; } def LinalgLowerToLoops : FunctionPass<"convert-linalg-to-loops"> { let summary = "Lower the operations from the linalg dialect into loops"; let constructor = "mlir::createConvertLinalgToLoopsPass()"; - let dependentDialects = ["scf::SCFDialect", "AffineDialect"]; } def LinalgOnTensorsToBuffers : Pass<"convert-linalg-on-tensors-to-buffers", "ModuleOp"> { @@ -57,7 +54,6 @@ def LinalgLowerToParallelLoops let summary = "Lower the operations from the linalg dialect into parallel " "loops"; let constructor = "mlir::createConvertLinalgToParallelLoopsPass()"; - let dependentDialects = ["AffineDialect", "scf::SCFDialect"]; } def LinalgPromotion : FunctionPass<"linalg-promote-subviews"> { @@ -74,9 +70,6 @@ def LinalgPromotion : FunctionPass<"linalg-promote-subviews"> { def LinalgTiling : FunctionPass<"linalg-tile"> { let summary = "Tile operations in the linalg dialect"; let constructor = "mlir::createLinalgTilingPass()"; - let dependentDialects = [ - "AffineDialect", "scf::SCFDialect" - ]; let options = [ ListOption<"tileSizes", "linalg-tile-sizes", "int64_t", "Test generation of dynamic promoted buffers", @@ -93,7 +86,6 @@ def LinalgTilingToParallelLoops "Test generation of dynamic promoted buffers", "llvm::cl::ZeroOrMore, llvm::cl::MiscFlags::CommaSeparated"> ]; - let dependentDialects = ["AffineDialect", "scf::SCFDialect"]; } #endif // MLIR_DIALECT_LINALG_PASSES diff --git a/mlir/include/mlir/Dialect/SCF/Passes.td b/mlir/include/mlir/Dialect/SCF/Passes.td index 6f3cf0e..483d0ba 100644 --- a/mlir/include/mlir/Dialect/SCF/Passes.td +++ b/mlir/include/mlir/Dialect/SCF/Passes.td @@ -36,7 +36,6 @@ def SCFParallelLoopTiling : FunctionPass<"parallel-loop-tiling"> { "Factors to tile parallel loops by", "llvm::cl::ZeroOrMore, llvm::cl::MiscFlags::CommaSeparated"> ]; - let dependentDialects = ["AffineDialect"]; } #endif // MLIR_DIALECT_SCF_PASSES diff --git a/mlir/include/mlir/IR/Dialect.h b/mlir/include/mlir/IR/Dialect.h index d00d86db..4f9e4cb 100644 --- a/mlir/include/mlir/IR/Dialect.h +++ b/mlir/include/mlir/IR/Dialect.h @@ -16,8 +16,6 @@ #include "mlir/IR/OperationSupport.h" #include "mlir/Support/TypeID.h" -#include - namespace mlir { class DialectAsmParser; class DialectAsmPrinter; @@ -25,7 +23,7 @@ class DialectInterface; class OpBuilder; class Type; -using DialectAllocatorFunction = std::function; +using DialectAllocatorFunction = std::function; /// Dialects are groups of MLIR operations and behavior associated with the /// entire group. For example, hooks into other systems for constant folding, @@ -214,81 +212,30 @@ private: /// A collection of registered dialect interfaces. DenseMap> registeredInterfaces; + /// Registers a specific dialect creation function with the global registry. + /// Used through the registerDialect template. + /// Registrations are deduplicated by dialect TypeID and only the first + /// registration will be used. + static void + registerDialectAllocator(TypeID typeID, + const DialectAllocatorFunction &function); + template friend void registerDialect(); friend class MLIRContext; }; -/// The DialectRegistry maps a dialect namespace to a constructor for the -/// matching dialect. -/// This allows for decoupling the list of dialects "available" from the -/// dialects loaded in the Context. The parser in particular will lazily load -/// dialects in in the Context as operations are encountered. -class DialectRegistry { - using MapTy = - std::map>; - -public: - template void insert() { - insert(TypeID::get(), - ConcreteDialect::getDialectNamespace(), - static_cast(([](MLIRContext *ctx) { - // Just allocate the dialect, the context - // takes ownership of it. - return ctx->getOrLoadDialect(); - }))); - } - - /// Add a new dialect constructor to the registry. - void insert(TypeID typeID, StringRef name, DialectAllocatorFunction ctor); - - /// Load a dialect for this namespace in the provided context. - Dialect *loadByName(StringRef name, MLIRContext *context); - - // Register all dialects available in the current registry with the registry - // in the provided context. - void appendTo(DialectRegistry &destination) { - for (const auto &name_and_registration_it : registry) - destination.insert(name_and_registration_it.second.first, - name_and_registration_it.first, - name_and_registration_it.second.second); - } - // Load all dialects available in the registry in the provided context. - void loadAll(MLIRContext *context) { - for (const auto &name_and_registration_it : registry) - name_and_registration_it.second.second(context); - } - - MapTy::const_iterator begin() const { return registry.begin(); } - MapTy::const_iterator end() const { return registry.end(); } - -private: - MapTy registry; -}; - -/// Deprecated: this provides a global registry for convenience, while we're -/// transitionning the registration mechanism to a stateless approach. -DialectRegistry &getGlobalDialectRegistry(); - -/// Registers all dialects from the global registries with the -/// specified MLIRContext. This won't load the dialects in the context, -/// but only make them available for lazy loading by name. +/// Registers all dialects and hooks from the global registries with the +/// specified MLIRContext. /// Note: This method is not thread-safe. -inline void registerAllDialects(MLIRContext *context) { - getGlobalDialectRegistry().appendTo(context->getDialectRegistry()); -} - -/// Register and return the dialect with the given namespace in the provided -/// context. Returns nullptr is there is no constructor registered for this -/// dialect. -inline Dialect *registerDialect(StringRef name, MLIRContext *context) { - return getGlobalDialectRegistry().loadByName(name, context); -} +void registerAllDialects(MLIRContext *context); /// Utility to register a dialect. Client can register their dialect with the /// global registry by calling registerDialect(); /// Note: This method is not thread-safe. template void registerDialect() { - getGlobalDialectRegistry().insert(); + Dialect::registerDialectAllocator( + TypeID::get(), + [](MLIRContext *ctx) { ctx->getOrCreateDialect(); }); } /// DialectRegistration provides a global initializer that registers a Dialect diff --git a/mlir/include/mlir/IR/FunctionSupport.h b/mlir/include/mlir/IR/FunctionSupport.h index 3d467cd..7e281f3 100644 --- a/mlir/include/mlir/IR/FunctionSupport.h +++ b/mlir/include/mlir/IR/FunctionSupport.h @@ -428,7 +428,7 @@ LogicalResult FunctionLike::verifyTrait(Operation *op) { if (!attr.first.strref().contains('.')) return funcOp.emitOpError("arguments may only have dialect attributes"); auto dialectNamePair = attr.first.strref().split('.'); - if (auto *dialect = ctx->getLoadedDialect(dialectNamePair.first)) { + if (auto *dialect = ctx->getRegisteredDialect(dialectNamePair.first)) { if (failed(dialect->verifyRegionArgAttribute(op, /*regionIndex=*/0, /*argIndex=*/i, attr))) return failure(); @@ -444,7 +444,7 @@ LogicalResult FunctionLike::verifyTrait(Operation *op) { if (!attr.first.strref().contains('.')) return funcOp.emitOpError("results may only have dialect attributes"); auto dialectNamePair = attr.first.strref().split('.'); - if (auto *dialect = ctx->getLoadedDialect(dialectNamePair.first)) { + if (auto *dialect = ctx->getRegisteredDialect(dialectNamePair.first)) { if (failed(dialect->verifyRegionResultAttribute(op, /*regionIndex=*/0, /*resultIndex=*/i, attr))) diff --git a/mlir/include/mlir/IR/MLIRContext.h b/mlir/include/mlir/IR/MLIRContext.h index d406c30..0192a8a 100644 --- a/mlir/include/mlir/IR/MLIRContext.h +++ b/mlir/include/mlir/IR/MLIRContext.h @@ -19,12 +19,10 @@ namespace mlir { class AbstractOperation; class DiagnosticEngine; class Dialect; -class DialectRegistry; class InFlightDiagnostic; class Location; class MLIRContextImpl; class StorageUniquer; -DialectRegistry &getGlobalDialectRegistry(); /// MLIRContext is the top-level object for a collection of MLIR modules. It /// holds immortal uniqued objects like types, and the tables used to unique @@ -36,54 +34,34 @@ DialectRegistry &getGlobalDialectRegistry(); /// class MLIRContext { public: - /// Create a new Context. - /// The loadAllDialects parameters allows to load all dialects from the global - /// registry on Context construction. It is deprecated and will be removed - /// soon. - explicit MLIRContext(bool loadAllDialects = true); + explicit MLIRContext(); ~MLIRContext(); - /// Return information about all IR dialects loaded in the context. - std::vector getLoadedDialects(); - - /// Return the dialect registry associated with this context. - DialectRegistry &getDialectRegistry(); - - /// Return information about all available dialects in the registry in this - /// context. - std::vector getAvailableDialects(); + /// Return information about all registered IR dialects. + std::vector getRegisteredDialects(); /// Get a registered IR dialect with the given namespace. If an exact match is /// not found, then return nullptr. - Dialect *getLoadedDialect(StringRef name); + Dialect *getRegisteredDialect(StringRef name); /// Get a registered IR dialect for the given derived dialect type. The /// derived type must provide a static 'getDialectNamespace' method. - template T *getLoadedDialect() { - return static_cast(getLoadedDialect(T::getDialectNamespace())); + template T *getRegisteredDialect() { + return static_cast(getRegisteredDialect(T::getDialectNamespace())); } /// Get (or create) a dialect for the given derived dialect type. The derived /// type must provide a static 'getDialectNamespace' method. - template T *getOrLoadDialect() { - return static_cast( - getOrLoadDialect(T::getDialectNamespace(), TypeID::get(), [this]() { + template + T *getOrCreateDialect() { + return static_cast(getOrCreateDialect( + T::getDialectNamespace(), TypeID::get(), [this]() { std::unique_ptr dialect(new T(this)); + dialect->dialectID = TypeID::get(); return dialect; })); } - /// Deprecated: load all globally registered dialects into this context. - /// This method will be removed soon, it can be used temporarily as we're - /// phasing out the global registry. - void loadAllGloballyRegisteredDialects(); - - /// Get (or create) a dialect for the given derived dialect name. - /// The dialect will be loaded from the registry if no dialect is found. - /// If no dialect is loaded for this name and none is available in the - /// registry, returns nullptr. - Dialect *getOrLoadDialect(StringRef name); - /// Return true if we allow to create operation for unregistered dialects. bool allowsUnregisteredDialects(); @@ -145,12 +123,10 @@ private: const std::unique_ptr impl; /// Get a dialect for the provided namespace and TypeID: abort the program if - /// a dialect exist for this namespace with different TypeID. If a dialect has - /// not been loaded for this namespace/TypeID yet, use the provided ctor to - /// create one on the fly and load it. Returns a pointer to the dialect owned - /// by the context. - Dialect *getOrLoadDialect(StringRef dialectNamespace, TypeID dialectID, - function_ref()> ctor); + /// a dialect exist for this namespace with different TypeID. Returns a + /// pointer to the dialect owned by the context. + Dialect *getOrCreateDialect(StringRef dialectNamespace, TypeID dialectID, + function_ref()> ctor); MLIRContext(const MLIRContext &) = delete; void operator=(const MLIRContext &) = delete; diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index a28410f..9cc57a6 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -244,11 +244,6 @@ class Dialect { // The description of the dialect. string description = ?; - // A list of dialects this dialect will load on construction as dependencies. - // These are dialects that this dialect may involved in canonicalization - // pattern or interfaces. - list dependentDialects = []; - // The C++ namespace that ops of this dialect should be placed into. // // By default, uses the name of the dialect as the only namespace. To avoid diff --git a/mlir/include/mlir/InitAllDialects.h b/mlir/include/mlir/InitAllDialects.h index a456616..b76b26f 100644 --- a/mlir/include/mlir/InitAllDialects.h +++ b/mlir/include/mlir/InitAllDialects.h @@ -35,32 +35,29 @@ namespace mlir { -// Add all the MLIR dialects to the provided registry. -inline void registerAllDialects(DialectRegistry ®istry) { - registry.insert(); - registry.insert(); - registry.insert(); - registry.insert(); - registry.insert(); - registry.insert(); - registry.insert(); - registry.insert(); - registry.insert(); - registry.insert(); - registry.insert(); - registry.insert(); - registry.insert(); - registry.insert(); - registry.insert(); - registry.insert(); - registry.insert(); -} - // This function should be called before creating any MLIRContext if one expect // all the possible dialects to be made available to the context automatically. inline void registerAllDialects() { - static bool init_once = - ([]() { registerAllDialects(getGlobalDialectRegistry()); }(), true); + static bool init_once = []() { + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + return true; + }(); (void)init_once; } } // namespace mlir diff --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h index ea361ae..7c0f9bd 100644 --- a/mlir/include/mlir/Pass/Pass.h +++ b/mlir/include/mlir/Pass/Pass.h @@ -9,7 +9,6 @@ #ifndef MLIR_PASS_PASS_H #define MLIR_PASS_PASS_H -#include "mlir/IR/Dialect.h" #include "mlir/IR/Function.h" #include "mlir/Pass/AnalysisManager.h" #include "mlir/Pass/PassRegistry.h" @@ -58,13 +57,6 @@ public: /// Returns the derived pass name. virtual StringRef getName() const = 0; - /// Register dependent dialects for the current pass. - /// A pass is expected to register the dialects it will create operations for, - /// other than dialect that exists in the input. For example, a pass that - /// converts from Linalg to Affine would register the Affine dialect but does - /// not need to register Linalg. - virtual void getDependentDialects(DialectRegistry ®istry) const {} - /// Returns the command line argument used when registering this pass. Return /// an empty string if one does not exist. virtual StringRef getArgument() const { diff --git a/mlir/include/mlir/Pass/PassBase.td b/mlir/include/mlir/Pass/PassBase.td index 749d042..54b4403 100644 --- a/mlir/include/mlir/Pass/PassBase.td +++ b/mlir/include/mlir/Pass/PassBase.td @@ -78,9 +78,6 @@ class PassBase { // A C++ constructor call to create an instance of this pass. code constructor = [{}]; - // A list of dialects this pass may produce operations in. - list dependentDialects = []; - // A set of options provided by this pass. list