[clang] [flang] [mlir] [mlir][ODS] Generate hooks that register the attributes and types of a dialect (PR #243481)
Markus Böck via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 23 00:35:32 PST 2026
https://github.com/zero9178 updated https://github.com/llvm/llvm-project/pull/243481
>From 93fe6e1aeb084f5634cfcf0ccdfa7dd27da65a2a Mon Sep 17 00:00:00 2001
From: Markus Boeck <mboeck at nvidia.com>
Date: Tue, 17 Nov 2026 11:05:02 +0000
Subject: [PATCH 1/4] [mlir][ODS] Generate hooks that register the attributes
and types of a dialect
Dialects registered their generated attributes and types by expanding
`GET_ATTRDEF_LIST` (or `GET_TYPEDEF_LIST`) into the template arguments
of `addAttributes` (or `addTypes`).
This requires each and every type and attribute and their storage classes' to be defined at the callsite and is generally boilerplate that exists in most dialects.
This PR introduces a single registration hook that is generated by ODS and should be called from dialects' `initialize` method instead. The implementation of the hook now performs the registration.
The motivation and further advantage of this approach is that we can then also change the implementation of the registration method in ODS while keeping API compatibility. This is required for partitioning of attributes and types e.g. (https://github.com/llvm/llvm-project/pull/241935).
Docs have been updated to advise users to use the new registration method. However, no upstream dialect beyond the test dialect has been switched nor is the old method of registration planned to be deprecated as it is still useful in some contexts (e.g., extendible dialects or C++ defined types and attributes).
Co-authored-by: Claude <noreply at anthropic.com>
---
.../DefiningDialects/AttributesAndTypes.md | 23 +++++++------
mlir/include/mlir/IR/AttributeSupport.h | 13 ++++++++
mlir/include/mlir/IR/Dialect.h | 2 ++
mlir/include/mlir/IR/TypeSupport.h | 13 ++++++++
mlir/lib/IR/MLIRContext.cpp | 13 ++++++++
mlir/test/lib/Dialect/Test/TestAttributes.cpp | 5 +--
mlir/test/lib/Dialect/Test/TestTypes.cpp | 6 ++--
mlir/test/mlir-tblgen/attrdefs.td | 8 +++++
mlir/test/mlir-tblgen/typedefs.td | 10 ++++++
mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp | 33 +++++++++++++++++++
10 files changed, 106 insertions(+), 20 deletions(-)
diff --git a/mlir/docs/DefiningDialects/AttributesAndTypes.md b/mlir/docs/DefiningDialects/AttributesAndTypes.md
index d0dd8a0cf2aa00..44abe29de9a916 100644
--- a/mlir/docs/DefiningDialects/AttributesAndTypes.md
+++ b/mlir/docs/DefiningDialects/AttributesAndTypes.md
@@ -1234,22 +1234,21 @@ generates an `getAlias` implementation using the Attribute or Type's mnemonic.
### Registering with the Dialect
Once the attributes and types have been defined, they must then be registered
-with the parent `Dialect`. This is done via the `addAttributes` and `addTypes`
-methods. Note that when registering, the full definition of the storage classes
-must be visible.
+with the parent `Dialect`. The generated definitions define
+`register<DialectClass>Attributes` (or `register<DialectClass>Types`), which
+registers all attributes (or types) of the generated file. Since registering
+requires the full definition of the storage classes, it is a `static` function,
+which can be called in the compilation unit that includes the definitions:
```c++
-void MyDialect::initialize() {
- /// Add the defined attributes to the dialect.
- addAttributes<
-#define GET_ATTRDEF_LIST
+#define GET_ATTRDEF_CLASSES
#include "MyDialect/Attributes.cpp.inc"
- >();
- /// Add the defined types to the dialect.
- addTypes<
-#define GET_TYPEDEF_LIST
+#define GET_TYPEDEF_CLASSES
#include "MyDialect/Types.cpp.inc"
- >();
+
+void MyDialect::initialize() {
+ registerMyDialectAttributes(this);
+ registerMyDialectTypes(this);
}
```
diff --git a/mlir/include/mlir/IR/AttributeSupport.h b/mlir/include/mlir/IR/AttributeSupport.h
index 9f36ee4aae2783..45ef62198fafeb 100644
--- a/mlir/include/mlir/IR/AttributeSupport.h
+++ b/mlir/include/mlir/IR/AttributeSupport.h
@@ -53,6 +53,10 @@ class AbstractAttribute {
T::getTypeID(), T::name);
}
+ /// Register the attribute `T` with `dialect`.
+ template <typename T>
+ static void insert(Dialect &dialect);
+
/// This method is used by Dialect objects to register attributes with
/// custom TypeIDs.
/// The use of this method is in general discouraged in favor of
@@ -111,6 +115,10 @@ class AbstractAttribute {
StringRef getName() const { return name; }
private:
+ /// Registers `attrInfo` with `dialect` and returns the context of `dialect`.
+ /// This is the part of `insert<T>` that requires the definition of `Dialect`.
+ static MLIRContext *insert(Dialect &dialect, AbstractAttribute &&attrInfo);
+
AbstractAttribute(Dialect &dialect, detail::InterfaceMap &&interfaceMap,
HasTraitFn &&hasTraitFn,
WalkImmediateSubElementsFn walkImmediateSubElementsFn,
@@ -322,6 +330,11 @@ decltype(auto) unwrapForCustomParse(FailureOr<T> &failureOr) {
} // namespace detail
+template <typename T>
+void AbstractAttribute::insert(Dialect &dialect) {
+ MLIRContext *context = insert(dialect, get<T>(dialect));
+ detail::AttributeUniquer::registerAttribute<T>(context);
+}
} // namespace mlir
#endif
diff --git a/mlir/include/mlir/IR/Dialect.h b/mlir/include/mlir/IR/Dialect.h
index fb24a6895dabdc..8e0ecc9d379625 100644
--- a/mlir/include/mlir/IR/Dialect.h
+++ b/mlir/include/mlir/IR/Dialect.h
@@ -367,6 +367,8 @@ class Dialect {
/// to provide an implementation for.
DenseSet<std::pair<TypeID, TypeID>> unresolvedPromisedInterfaces;
+ friend class AbstractAttribute;
+ friend class AbstractType;
friend class DialectRegistry;
friend class MLIRContext;
};
diff --git a/mlir/include/mlir/IR/TypeSupport.h b/mlir/include/mlir/IR/TypeSupport.h
index 36ef696ba4f6fb..084eb5c81840b9 100644
--- a/mlir/include/mlir/IR/TypeSupport.h
+++ b/mlir/include/mlir/IR/TypeSupport.h
@@ -54,6 +54,10 @@ class AbstractType {
T::name);
}
+ /// Register the type `T` with `dialect`.
+ template <typename T>
+ static void insert(Dialect &dialect);
+
/// This method is used by Dialect objects to register types with
/// custom TypeIDs.
/// The use of this method is in general discouraged in favor of
@@ -110,6 +114,10 @@ class AbstractType {
StringRef getName() const { return name; }
private:
+ /// Registers `typeInfo` with `dialect` and returns the context of `dialect`.
+ /// This is the part of `insert<T>` that requires the definition of `Dialect`.
+ static MLIRContext *insert(Dialect &dialect, AbstractType &&typeInfo);
+
AbstractType(Dialect &dialect, detail::InterfaceMap &&interfaceMap,
HasTraitFn &&hasTrait,
WalkImmediateSubElementsFn walkImmediateSubElementsFn,
@@ -295,6 +303,11 @@ struct TypeUniquer {
};
} // namespace detail
+template <typename T>
+void AbstractType::insert(Dialect &dialect) {
+ MLIRContext *context = insert(dialect, get<T>(dialect));
+ detail::TypeUniquer::registerType<T>(context);
+}
} // namespace mlir
#endif
diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp
index d8abff14be05f2..d4169aba5f6f59 100644
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -889,6 +889,19 @@ void Dialect::addAttribute(TypeID typeID, AbstractAttribute &&attrInfo) {
newInfo->getName() + " is already registered.");
}
+MLIRContext *AbstractAttribute::insert(Dialect &dialect,
+ AbstractAttribute &&attrInfo) {
+ TypeID typeID = attrInfo.getTypeID();
+ dialect.addAttribute(typeID, std::move(attrInfo));
+ return dialect.getContext();
+}
+
+MLIRContext *AbstractType::insert(Dialect &dialect, AbstractType &&typeInfo) {
+ TypeID typeID = typeInfo.getTypeID();
+ dialect.addType(typeID, std::move(typeInfo));
+ return dialect.getContext();
+}
+
//===----------------------------------------------------------------------===//
// AbstractAttribute
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/lib/Dialect/Test/TestAttributes.cpp b/mlir/test/lib/Dialect/Test/TestAttributes.cpp
index 14d89ed5edc554..d86a32af6c39a7 100644
--- a/mlir/test/lib/Dialect/Test/TestAttributes.cpp
+++ b/mlir/test/lib/Dialect/Test/TestAttributes.cpp
@@ -604,10 +604,7 @@ mlir::AffineMap TestMemRefLayoutAttr::getAffineMap() const {
//===----------------------------------------------------------------------===//
void TestDialect::registerAttributes() {
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "TestAttrDefs.cpp.inc"
- >();
+ registerTestDialectAttributes(this);
registerDynamicAttr(getDynamicSingletonAttr(this));
registerDynamicAttr(getDynamicPairAttr(this));
registerDynamicAttr(getDynamicCustomAssemblyFormatAttr(this));
diff --git a/mlir/test/lib/Dialect/Test/TestTypes.cpp b/mlir/test/lib/Dialect/Test/TestTypes.cpp
index b290fd06e6a72b..9410d5e2aa9226 100644
--- a/mlir/test/lib/Dialect/Test/TestTypes.cpp
+++ b/mlir/test/lib/Dialect/Test/TestTypes.cpp
@@ -417,10 +417,8 @@ struct PtrElementModel
} // namespace
void TestDialect::registerTypes() {
- addTypes<TestRecursiveType,
-#define GET_TYPEDEF_LIST
-#include "TestTypeDefs.cpp.inc"
- >();
+ addTypes<TestRecursiveType>();
+ registerTestDialectTypes(this);
SimpleAType::attachInterface<PtrElementModel>(*getContext());
registerDynamicType(getSingletonDynamicType(this));
diff --git a/mlir/test/mlir-tblgen/attrdefs.td b/mlir/test/mlir-tblgen/attrdefs.td
index 046bb53858be05..69baa712b5bafc 100644
--- a/mlir/test/mlir-tblgen/attrdefs.td
+++ b/mlir/test/mlir-tblgen/attrdefs.td
@@ -204,3 +204,11 @@ def J_CustomStorageCtorAttr : AttrDef<Test_Dialect, "CustomStorageCtorAttr"> {
// DEF-LABEL: struct CustomStorageCtorAttrAttrStorage : public ::mlir::AttributeStorage
// DEF: static CustomStorageCtorAttrAttrStorage *construct
// DEF-SAME: (::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey);
+
+// The registration hook registers every attribute.
+// DEF: class TestDialect;
+// DEF-NEXT: {{\[\[}}maybe_unused{{\]\]}} static void registerTestDialectAttributes(TestDialect *dialect) {
+// DEF-NEXT: ::mlir::AbstractAttribute::insert<IndexAttr>(*dialect);
+// DEF-NEXT: ::mlir::AbstractAttribute::insert<SimpleAAttr>(*dialect);
+// DEF: ::mlir::AbstractAttribute::insert<CustomStorageCtorAttrAttr>(*dialect);
+// DEF-NEXT: }
diff --git a/mlir/test/mlir-tblgen/typedefs.td b/mlir/test/mlir-tblgen/typedefs.td
index b9e3a7954e361d..30bded77d24085 100644
--- a/mlir/test/mlir-tblgen/typedefs.td
+++ b/mlir/test/mlir-tblgen/typedefs.td
@@ -153,3 +153,13 @@ def E_IntegerType : TestType<"Integer"> {
// DECL-NEXT: /// Return true if this is an unsigned integer type.
// DECL-NEXT: bool isUnsigned() const { return getSignedness() == Unsigned; }
}
+
+// The registration hook registers every type.
+// DEF: class TestDialect;
+// DEF-NEXT: {{\[\[}}maybe_unused{{\]\]}} static void registerTestDialectTypes(TestDialect *dialect) {
+// DEF-NEXT: ::mlir::AbstractType::insert<SimpleAType>(*dialect);
+// DEF-NEXT: ::mlir::AbstractType::insert<CompoundAType>(*dialect);
+// DEF-NEXT: ::mlir::AbstractType::insert<IndexType>(*dialect);
+// DEF-NEXT: ::mlir::AbstractType::insert<SingleParameterType>(*dialect);
+// DEF-NEXT: ::mlir::AbstractType::insert<IntegerType>(*dialect);
+// DEF-NEXT: }
diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
index 790bc393b08f48..97f95a1c0aafdc 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
@@ -867,6 +867,12 @@ class DefGenerator {
/// Emit the code to dispatch between different defs during parsing/printing.
void emitParsePrintDispatch(ArrayRef<AttrOrTypeDef> defs);
+ /// Returns the name of the function that registers the defs of `dialect`.
+ std::string getRegistrationHookName(const Dialect &dialect) const;
+
+ /// Emit the definition of the hook that registers `defs` with their dialect.
+ void emitRegistrationHook(ArrayRef<AttrOrTypeDef> defs);
+
/// The set of def records to emit.
std::vector<const Record *> defRecords;
/// The attribute or type class to emit.
@@ -1193,6 +1199,32 @@ void DefGenerator::emitParsePrintDispatch(ArrayRef<AttrOrTypeDef> defs) {
printer.writeDeclTo(indentedOs);
}
+std::string
+DefGenerator::getRegistrationHookName(const Dialect &dialect) const {
+ return strfmt("register{0}{1}s", dialect.getCppClassName(), valueType);
+}
+
+/// Emit the hook that registers the defs with their dialect. Since registering
+/// requires the definitions of the storage classes, the hook is a static
+/// function.
+void DefGenerator::emitRegistrationHook(ArrayRef<AttrOrTypeDef> defs) {
+ Dialect dialect = defs.front().getDialect();
+ std::string dialectClass = dialect.getCppClassName();
+ DialectNamespaceEmitter ns(os, dialect);
+ // TODO: Ideally, the hook would be non-static, so that callers do not have to
+ // be in the same TU as the registration function. This is currently blocked
+ // by dialects defining their attributes and types across multiple TUs (e.g.
+ // the transform dialect and its extensions), whose hooks would cause
+ // multiple definition errors.
+ os << "class " << dialectClass << ";\n"
+ << llvm::formatv("[[maybe_unused]] static void {0}({1} *dialect) {{\n",
+ getRegistrationHookName(dialect), dialectClass);
+ for (const AttrOrTypeDef &def : defs)
+ os << llvm::formatv(" ::mlir::Abstract{0}::insert<{1}>(*dialect);\n",
+ valueType, def.getCppClassName());
+ os << "}\n";
+}
+
/// Headers declaring the C++ constructs used by every generated attribute or
/// type definition, beyond those already included by the declarations.
static constexpr StringRef attrOrTypeDefIncludes[] = {
@@ -1232,6 +1264,7 @@ bool DefGenerator::emitDefs(StringRef selectedDialect) {
<< def.getDialect().getCppNamespace() << "::" << def.getCppClassName()
<< ")\n";
}
+ emitRegistrationHook(defs);
Dialect firstDialect = defs.front().getDialect();
>From cdeb4bfc2eabf7c45e21f0cbe9c2dcc279786751 Mon Sep 17 00:00:00 2001
From: Markus Boeck <mboeck at nvidia.com>
Date: Fri, 20 Nov 2026 14:45:24 +0000
Subject: [PATCH 2/4] address review comments
---
.../clang/CIR/Dialect/IR/CIRDialect.td | 7 +-
clang/lib/CIR/Dialect/IR/CIRAttrs.cpp | 11 --
clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 2 -
clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 15 ---
.../flang/Optimizer/Dialect/CUF/CUFDialect.td | 8 +-
.../flang/Optimizer/Dialect/FIRDialect.td | 2 +
.../flang/Optimizer/HLFIR/HLFIROpBase.td | 2 +-
.../Dialect/CUF/Attributes/CUFAttr.cpp | 5 -
.../lib/Optimizer/Dialect/CUF/CUFDialect.cpp | 1 -
flang/lib/Optimizer/Dialect/FIRAttr.cpp | 5 +-
flang/lib/Optimizer/Dialect/FIRType.cpp | 5 -
flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp | 4 -
.../DefiningDialects/AttributesAndTypes.md | 46 +++++---
mlir/docs/DefiningDialects/_index.md | 12 ++-
.../include/Standalone/StandaloneDialect.td | 6 +-
.../lib/Standalone/StandaloneDialect.cpp | 1 -
.../lib/Standalone/StandaloneTypes.cpp | 7 --
.../mlir/Dialect/AMDGPU/IR/AMDGPUBase.td | 8 +-
.../mlir/Dialect/Arith/IR/ArithBase.td | 2 +-
mlir/include/mlir/Dialect/ArmSME/IR/ArmSME.td | 2 +-
.../mlir/Dialect/Async/IR/AsyncDialect.td | 2 +-
.../mlir/Dialect/Complex/IR/ComplexBase.td | 2 +-
mlir/include/mlir/Dialect/DLTI/DLTIBase.td | 2 +-
.../mlir/Dialect/EmitC/IR/EmitCBase.td | 4 +-
mlir/include/mlir/Dialect/IRDL/IR/IRDL.td | 4 +-
.../mlir/Dialect/Index/IR/IndexDialect.td | 4 +-
.../mlir/Dialect/LLVMIR/LLVMDialect.td | 10 +-
.../mlir/Dialect/LLVMIR/NVVMDialect.td | 6 +-
.../mlir/Dialect/LLVMIR/ROCDLDialect.td | 2 +-
mlir/include/mlir/Dialect/LLVMIR/XeVMOps.td | 2 +-
.../mlir/Dialect/Linalg/IR/LinalgBase.td | 2 +-
.../Dialect/MLProgram/IR/MLProgramBase.td | 4 +-
mlir/include/mlir/Dialect/MPI/IR/MPI.td | 4 +-
mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td | 4 +-
.../mlir/Dialect/OpenACC/OpenACCBase.td | 4 +-
.../mlir/Dialect/OpenMP/OpenMPDialect.td | 4 +-
.../include/mlir/Dialect/PDL/IR/PDLDialect.td | 6 +-
.../include/mlir/Dialect/Ptr/IR/PtrDialect.td | 4 +-
.../include/mlir/Dialect/SMT/IR/SMTDialect.td | 9 +-
.../mlir/Dialect/SPIRV/IR/SPIRVBase.td | 2 +
.../mlir/Dialect/Shape/IR/ShapeBase.td | 2 +-
.../mlir/Dialect/Shard/IR/ShardBase.td | 4 +-
.../SparseTensor/IR/SparseTensorBase.td | 4 +-
.../mlir/Dialect/Tosa/IR/TosaOpBase.td | 4 +-
mlir/include/mlir/Dialect/UB/IR/UBOps.td | 2 +-
mlir/include/mlir/Dialect/Vector/IR/Vector.td | 2 +-
.../mlir/Dialect/WasmSSA/IR/WasmSSABase.td | 2 +-
mlir/include/mlir/Dialect/X86/X86.td | 2 +-
.../mlir/Dialect/XeGPU/IR/XeGPUDialect.td | 4 +-
mlir/include/mlir/IR/BuiltinDialect.td | 9 +-
mlir/include/mlir/IR/CMakeLists.txt | 6 +-
mlir/include/mlir/IR/DialectBase.td | 24 ++++-
mlir/include/mlir/TableGen/Dialect.h | 8 ++
mlir/lib/Dialect/AMDGPU/IR/AMDGPUAttrs.cpp | 7 --
mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp | 2 -
mlir/lib/Dialect/AMDGPU/IR/AMDGPUTypes.cpp | 7 --
mlir/lib/Dialect/Arith/IR/ArithDialect.cpp | 4 -
mlir/lib/Dialect/ArmSME/IR/ArmSME.cpp | 5 -
mlir/lib/Dialect/Async/IR/Async.cpp | 4 -
.../lib/Dialect/Complex/IR/ComplexDialect.cpp | 4 -
mlir/lib/Dialect/DLTI/DLTI.cpp | 4 -
mlir/lib/Dialect/EmitC/IR/EmitC.cpp | 8 --
mlir/lib/Dialect/IRDL/IR/IRDL.cpp | 8 --
mlir/lib/Dialect/Index/IR/IndexAttrs.cpp | 11 --
mlir/lib/Dialect/Index/IR/IndexDialect.cpp | 1 -
mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp | 12 ---
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 2 -
mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp | 12 ---
mlir/lib/Dialect/LLVMIR/IR/NVVMAttributes.cpp | 11 --
mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp | 1 -
mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp | 5 -
mlir/lib/Dialect/LLVMIR/IR/XeVMDialect.cpp | 5 -
mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp | 4 -
.../Dialect/MLProgram/IR/MLProgramDialect.cpp | 10 --
mlir/lib/Dialect/MPI/IR/MPI.cpp | 10 --
mlir/lib/Dialect/NVGPU/IR/NVGPUDialect.cpp | 8 --
mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp | 9 --
mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp | 9 --
mlir/lib/Dialect/PDL/IR/PDL.cpp | 1 -
mlir/lib/Dialect/PDL/IR/PDLTypes.cpp | 11 --
mlir/lib/Dialect/Ptr/IR/PtrDialect.cpp | 8 --
mlir/lib/Dialect/SMT/IR/SMTAttributes.cpp | 7 --
mlir/lib/Dialect/SMT/IR/SMTDialect.cpp | 2 -
mlir/lib/Dialect/SMT/IR/SMTTypes.cpp | 7 --
mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp | 4 -
mlir/lib/Dialect/Shape/IR/Shape.cpp | 4 -
mlir/lib/Dialect/Shard/IR/ShardOps.cpp | 8 --
.../SparseTensor/IR/SparseTensorDialect.cpp | 8 --
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp | 8 --
mlir/lib/Dialect/UB/IR/UBOps.cpp | 4 -
mlir/lib/Dialect/Vector/IR/VectorOps.cpp | 5 -
.../lib/Dialect/WasmSSA/IR/WasmSSADialect.cpp | 4 -
mlir/lib/Dialect/X86/IR/X86Dialect.cpp | 5 -
mlir/lib/Dialect/XeGPU/IR/XeGPUDialect.cpp | 8 --
mlir/lib/IR/BuiltinAttributes.cpp | 12 ---
mlir/lib/IR/BuiltinDialect.cpp | 10 +-
mlir/lib/IR/BuiltinTypes.cpp | 11 --
mlir/lib/IR/Location.cpp | 11 --
mlir/lib/TableGen/Dialect.cpp | 8 ++
mlir/test/lib/Dialect/Test/TestAttributes.cpp | 1 -
mlir/test/lib/Dialect/Test/TestDialect.td | 3 +-
mlir/test/lib/Dialect/Test/TestTypes.cpp | 1 -
mlir/test/mlir-tblgen/attrdefs.td | 14 ++-
mlir/test/mlir-tblgen/dialect-initialize.td | 100 +++++++++++++++++
mlir/test/mlir-tblgen/typedefs.td | 14 ++-
mlir/test/python/lib/PythonTestDialect.cpp | 8 --
mlir/test/python/python_test_ops.td | 4 +-
mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp | 102 +++++++++++++-----
mlir/tools/mlir-tblgen/DialectGen.cpp | 47 +++++---
mlir/tools/mlir-tblgen/DialectGenUtilities.h | 9 ++
110 files changed, 396 insertions(+), 521 deletions(-)
create mode 100644 mlir/test/mlir-tblgen/dialect-initialize.td
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRDialect.td b/clang/include/clang/CIR/Dialect/IR/CIRDialect.td
index 28b5663c23c49a..ed70839ca24434 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRDialect.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRDialect.td
@@ -25,7 +25,9 @@ def CIR_Dialect : Dialect {
let cppNamespace = "::cir";
- let useDefaultAttributePrinterParser = 1;
+ let hasAttributes = 1;
+ let hasTypes = 1;
+ let useDefaultTypePrinterParser = 0;
let hasOperationAttrVerify = 1;
let hasRegionArgAttrVerify = 1;
@@ -156,9 +158,6 @@ def CIR_Dialect : Dialect {
static llvm::StringRef getOpenCLSPIRVersionAttrName() { return "cir.cl.spir.version"; }
static llvm::StringRef getDefaultTlsModelAttrName() { return "cir.default_tls_model"; }
- void registerAttributes();
- void registerTypes();
-
mlir::Type parseType(mlir::DialectAsmParser &parser) const override;
void printType(mlir::Type type,
mlir::DialectAsmPrinter &printer) const override;
diff --git a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp
index 77ad3c65f9f5ab..5113e29370ce54 100644
--- a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp
@@ -1220,14 +1220,3 @@ RecordLayoutAttr cir::getRecordLayout(mlir::ModuleOp mod,
assert(attr && "record layout entry missing for named record");
return attr;
}
-
-//===----------------------------------------------------------------------===//
-// CIR Dialect
-//===----------------------------------------------------------------------===//
-
-void CIRDialect::registerAttributes() {
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "clang/CIR/Dialect/IR/CIROpsAttributes.cpp.inc"
- >();
-}
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 7e511dbaddff09..602ff86e300c77 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -100,8 +100,6 @@ struct CIROpAsmDialectInterface : public OpAsmDialectInterface {
} // namespace
void cir::CIRDialect::initialize() {
- registerTypes();
- registerAttributes();
registerCIRDialectOperations(this);
addInterfaces<CIROpAsmDialectInterface>();
detail::addBytecodeInterface(this);
diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
index 6fcdd35331ef3b..7ad987f0981fb5 100644
--- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
@@ -1911,18 +1911,3 @@ mlir::LogicalResult cir::PointerType::verify(
return success();
}
-
-//===----------------------------------------------------------------------===//
-// CIR Dialect
-//===----------------------------------------------------------------------===//
-
-void CIRDialect::registerTypes() {
- // Register tablegen'd types.
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "clang/CIR/Dialect/IR/CIROpsTypes.cpp.inc"
- >();
-
- // Register raw C++ types.
- // TODO(CIR) addTypes<RecordType>();
-}
diff --git a/flang/include/flang/Optimizer/Dialect/CUF/CUFDialect.td b/flang/include/flang/Optimizer/Dialect/CUF/CUFDialect.td
index 4bdabef713353c..2ea42f2af00f70 100644
--- a/flang/include/flang/Optimizer/Dialect/CUF/CUFDialect.td
+++ b/flang/include/flang/Optimizer/Dialect/CUF/CUFDialect.td
@@ -29,15 +29,9 @@ def CUFDialect : Dialect {
the FIR types and are tightly coupled with FIR and HLFIR.
}];
- let useDefaultAttributePrinterParser = 1;
+ let hasAttributes = 1;
let cppNamespace = "::cuf";
let dependentDialects = ["fir::FIROpsDialect"];
-
- let extraClassDeclaration = [{
- private:
- // Register the CUF Attributes.
- void registerAttributes();
- }];
}
#endif // FORTRAN_DIALECT_CUF_CUFDIALECT
diff --git a/flang/include/flang/Optimizer/Dialect/FIRDialect.td b/flang/include/flang/Optimizer/Dialect/FIRDialect.td
index 65857997f57de9..cca64ec49da308 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRDialect.td
+++ b/flang/include/flang/Optimizer/Dialect/FIRDialect.td
@@ -25,6 +25,8 @@ def FIROpsDialect : Dialect {
let name = "fir";
let useStrictPropertiesInAssemblyFormat = 1;
let cppNamespace = "::fir";
+ let hasAttributes = 1;
+ let hasTypes = 1;
let useDefaultTypePrinterParser = 0;
let useDefaultAttributePrinterParser = 0;
let hasConstantMaterializer = 1;
diff --git a/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td b/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td
index b13585d349eb15..a358b47091b84c 100644
--- a/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td
+++ b/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td
@@ -39,7 +39,7 @@ def hlfir_Dialect : Dialect {
into sequence of lower level FIR operations operating on memory.
}];
- let useDefaultTypePrinterParser = 1;
+ let hasTypes = 1;
let cppNamespace = "hlfir";
let dependentDialects = ["fir::FIROpsDialect"];
}
diff --git a/flang/lib/Optimizer/Dialect/CUF/Attributes/CUFAttr.cpp b/flang/lib/Optimizer/Dialect/CUF/Attributes/CUFAttr.cpp
index 2ef6a700c0d885..c070d6e9f35eb9 100644
--- a/flang/lib/Optimizer/Dialect/CUF/Attributes/CUFAttr.cpp
+++ b/flang/lib/Optimizer/Dialect/CUF/Attributes/CUFAttr.cpp
@@ -21,11 +21,6 @@
namespace cuf {
-void CUFDialect::registerAttributes() {
- addAttributes<ClusterDimsAttr, DataAttributeAttr, DataTransferKindAttr,
- LaunchBoundsAttr, LaunchConfigAttr, ProcAttributeAttr>();
-}
-
cuf::DataAttributeAttr getDataAttr(mlir::Operation *op) {
if (!op)
return {};
diff --git a/flang/lib/Optimizer/Dialect/CUF/CUFDialect.cpp b/flang/lib/Optimizer/Dialect/CUF/CUFDialect.cpp
index 47d3636df4f9f7..d2f3a97d037319 100644
--- a/flang/lib/Optimizer/Dialect/CUF/CUFDialect.cpp
+++ b/flang/lib/Optimizer/Dialect/CUF/CUFDialect.cpp
@@ -17,7 +17,6 @@
#include "flang/Optimizer/Dialect/CUF/CUFDialect.cpp.inc"
void cuf::CUFDialect::initialize() {
- registerAttributes();
addOperations<
#define GET_OP_LIST
#include "flang/Optimizer/Dialect/CUF/CUFOps.cpp.inc"
diff --git a/flang/lib/Optimizer/Dialect/FIRAttr.cpp b/flang/lib/Optimizer/Dialect/FIRAttr.cpp
index 4eab02d992e5b0..c13a2c3f73998f 100644
--- a/flang/lib/Optimizer/Dialect/FIRAttr.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRAttr.cpp
@@ -295,8 +295,5 @@ void fir::printFirAttribute(FIROpsDialect *dialect, mlir::Attribute attr,
void FIROpsDialect::registerAttributes() {
addAttributes<ClosedIntervalAttr, ExactTypeAttr, LowerBoundAttr,
- PointIntervalAttr, RealAttr, SubclassAttr, UpperBoundAttr,
-#define GET_ATTRDEF_LIST
-#include "flang/Optimizer/Dialect/FIRAttr.cpp.inc"
- >();
+ PointIntervalAttr, RealAttr, SubclassAttr, UpperBoundAttr>();
}
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 59557c51fc1497..7b87a1154df568 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -1625,11 +1625,6 @@ bool BaseBoxType::isCoarray() const {
//===----------------------------------------------------------------------===//
void FIROpsDialect::registerTypes() {
- addTypes<BoxType, BoxCharType, BoxProcType, CharacterType, ClassType,
- FieldType, HeapType, fir::IntegerType, LenType, LogicalType,
- LLVMPointerType, PointerType, RecordType, ReferenceType,
- SequenceType, ShapeType, ShapeShiftType, ShiftType, SliceType,
- TypeDescType, fir::VectorType, fir::DummyScopeType>();
fir::ReferenceType::attachInterface<
OpenMPPointerLikeModel<fir::ReferenceType>>(*getContext());
fir::PointerType::attachInterface<OpenMPPointerLikeModel<fir::PointerType>>(
diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp
index 5a49b11eb3fc29..7ecf300706dd54 100644
--- a/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp
+++ b/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp
@@ -31,10 +31,6 @@
#include "flang/Optimizer/HLFIR/HLFIRAttributes.cpp.inc"
void hlfir::hlfirDialect::initialize() {
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "flang/Optimizer/HLFIR/HLFIRTypes.cpp.inc"
- >();
addOperations<
#define GET_OP_LIST
#include "flang/Optimizer/HLFIR/HLFIROps.cpp.inc"
diff --git a/mlir/docs/DefiningDialects/AttributesAndTypes.md b/mlir/docs/DefiningDialects/AttributesAndTypes.md
index 44abe29de9a916..a13a44fc302095 100644
--- a/mlir/docs/DefiningDialects/AttributesAndTypes.md
+++ b/mlir/docs/DefiningDialects/AttributesAndTypes.md
@@ -1234,21 +1234,43 @@ generates an `getAlias` implementation using the Attribute or Type's mnemonic.
### Registering with the Dialect
Once the attributes and types have been defined, they must then be registered
-with the parent `Dialect`. The generated definitions define
-`register<DialectClass>Attributes` (or `register<DialectClass>Types`), which
-registers all attributes (or types) of the generated file. Since registering
-requires the full definition of the storage classes, it is a `static` function,
-which can be called in the compilation unit that includes the definitions:
+with the parent `Dialect`. A dialect defining attributes (or types) in ODS
+should set its `hasAttributes` (or `hasTypes`) field:
-```c++
-#define GET_ATTRDEF_CLASSES
-#include "MyDialect/Attributes.cpp.inc"
+```tablegen
+def MyDialect : Dialect {
+ ...
+ let hasAttributes = 1;
+ let hasTypes = 1;
+}
+```
-#define GET_TYPEDEF_CLASSES
-#include "MyDialect/Types.cpp.inc"
+The generated declarations then declare `register<DialectClass>Attributes` (or
+`register<DialectClass>Types`), which registers all attributes (or types) of the
+generated file. It is defined alongside the attribute (or type) classes in the
+generated definitions and called by the dialect constructor by default.
+`hasAttributes` (or `hasTypes`) defaults to `0` and provides the default of
+`useDefaultAttributeRegistration` (or `useDefaultTypeRegistration`), which
+controls the above, and of `useDefaultAttributePrinterParser` (or
+`useDefaultTypePrinterParser`). A dialect whose
+`useDefaultAttributeRegistration` (or `useDefaultTypeRegistration`) is `0` gets
+no hook and must register its attributes (or types) itself, e.g. if registering
+them requires more than their definitions:
+
+```c++
void MyDialect::initialize() {
- registerMyDialectAttributes(this);
- registerMyDialectTypes(this);
+ addAttributes<
+#define GET_ATTRDEF_LIST
+#include "MyDialect/Attributes.cpp.inc"
+ >();
}
```
+
+If the attributes (or types) of a dialect are generated into more than one
+file, e.g. by dialect extensions, each file must name its hook differently to
+avoid multiple definitions. `-attrdefs-registration-name=<Name>` (or
+`-typedefs-registration-name=<Name>`) names the hook
+`register<Name>Attributes` (or `register<Name>Types`). The option must be
+passed to both the declaration and the definition generator. Hooks with a
+custom name are never called by the generated dialect constructor.
diff --git a/mlir/docs/DefiningDialects/_index.md b/mlir/docs/DefiningDialects/_index.md
index 22d067c0a66f6b..79afc19cddff87 100644
--- a/mlir/docs/DefiningDialects/_index.md
+++ b/mlir/docs/DefiningDialects/_index.md
@@ -80,6 +80,12 @@ void MyDialect::initialize() {
}
```
+If the dialect sets `hasAttributes` (or `hasTypes`), the generated constructor
+registers the attributes (or types) of the dialect defined in ODS before calling
+`initialize` (see
+[Registering with the Dialect](AttributesAndTypes.md/#registering-with-the-dialect)).
+These must therefore not be added again in `initialize`.
+
### Documentation
The `summary` and `description` fields allow for providing user documentation
@@ -299,8 +305,10 @@ explicitly handle the parsing and printing of each individual attribute or type
the dialect. If all of the attributes and types of the dialect provide a mnemonic,
however, these methods may be autogenerated by using the
`useDefaultAttributePrinterParser` and `useDefaultTypePrinterParser` fields. By default,
-these fields are set to `1`(enabled), meaning that if a dialect needs to explicitly handle the
-parser and printer of its Attributes and Types it should set these to `0` as necessary.
+these fields take the values of the `hasAttributes` and `hasTypes` fields respectively,
+which default to `0`. If a dialect sets `hasAttributes` or `hasTypes` but needs to
+explicitly handle the parser and printer of its attributes or types, it should set these
+to `0` as necessary.
### Dialect-wide Canonicalization Patterns
diff --git a/mlir/examples/standalone/include/Standalone/StandaloneDialect.td b/mlir/examples/standalone/include/Standalone/StandaloneDialect.td
index 598a8dfe35f3bc..f0c9f8b851024f 100644
--- a/mlir/examples/standalone/include/Standalone/StandaloneDialect.td
+++ b/mlir/examples/standalone/include/Standalone/StandaloneDialect.td
@@ -24,11 +24,7 @@ def Standalone_Dialect : Dialect {
working inside of the LLVM source tree.
}];
let cppNamespace = "::mlir::standalone";
-
- let useDefaultTypePrinterParser = 1;
- let extraClassDeclaration = [{
- void registerTypes();
- }];
+ let hasTypes = 1;
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/examples/standalone/lib/Standalone/StandaloneDialect.cpp b/mlir/examples/standalone/lib/Standalone/StandaloneDialect.cpp
index 1ea69f9059321e..1dbfa209f2df44 100644
--- a/mlir/examples/standalone/lib/Standalone/StandaloneDialect.cpp
+++ b/mlir/examples/standalone/lib/Standalone/StandaloneDialect.cpp
@@ -24,5 +24,4 @@ void StandaloneDialect::initialize() {
#define GET_OP_LIST
#include "Standalone/StandaloneOps.cpp.inc"
>();
- registerTypes();
}
diff --git a/mlir/examples/standalone/lib/Standalone/StandaloneTypes.cpp b/mlir/examples/standalone/lib/Standalone/StandaloneTypes.cpp
index 4ce4e00150f641..14f60c3c0027b5 100644
--- a/mlir/examples/standalone/lib/Standalone/StandaloneTypes.cpp
+++ b/mlir/examples/standalone/lib/Standalone/StandaloneTypes.cpp
@@ -17,10 +17,3 @@ using namespace mlir::standalone;
#define GET_TYPEDEF_CLASSES
#include "Standalone/StandaloneOpsTypes.cpp.inc"
-
-void StandaloneDialect::registerTypes() {
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "Standalone/StandaloneOpsTypes.cpp.inc"
- >();
-}
diff --git a/mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPUBase.td b/mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPUBase.td
index 639dbf6b4a128b..0f9a6585eaec9b 100644
--- a/mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPUBase.td
+++ b/mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPUBase.td
@@ -114,12 +114,8 @@ def AMDGPU_Dialect : Dialect {
"arith::ArithDialect",
"gpu::GPUDialect"
];
- let useDefaultAttributePrinterParser = 1;
- let useDefaultTypePrinterParser = 1;
- let extraClassDeclaration = [{
- void registerAttributes();
- void registerTypes();
- }];
+ let hasAttributes = 1;
+ let hasTypes = 1;
}
#endif // MLIR_DIALECT_AMDGPU_IR_AMDGPUBASE_TD
diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td b/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
index 0c05c4db79bed6..f60fded781b0a7 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
@@ -39,7 +39,7 @@ def Arith_Dialect : Dialect {
}];
let hasConstantMaterializer = 1;
- let useDefaultAttributePrinterParser = 1;
+ let hasAttributes = 1;
}
// The predicate indicates the type of the comparison to perform:
diff --git a/mlir/include/mlir/Dialect/ArmSME/IR/ArmSME.td b/mlir/include/mlir/Dialect/ArmSME/IR/ArmSME.td
index ffafb2569310ed..2de1ee79a997b4 100644
--- a/mlir/include/mlir/Dialect/ArmSME/IR/ArmSME.td
+++ b/mlir/include/mlir/Dialect/ArmSME/IR/ArmSME.td
@@ -35,7 +35,7 @@ def ArmSME_Dialect : Dialect {
}];
let dependentDialects = ["scf::SCFDialect", "vector::VectorDialect",
"memref::MemRefDialect"];
- let useDefaultAttributePrinterParser = 1;
+ let hasAttributes = 1;
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/Dialect/Async/IR/AsyncDialect.td b/mlir/include/mlir/Dialect/Async/IR/AsyncDialect.td
index eb1d76a180fe24..af0b607860148b 100644
--- a/mlir/include/mlir/Dialect/Async/IR/AsyncDialect.td
+++ b/mlir/include/mlir/Dialect/Async/IR/AsyncDialect.td
@@ -28,7 +28,7 @@ def AsyncDialect : Dialect {
This dialect contains operations for modeling asynchronous execution.
}];
- let useDefaultTypePrinterParser = 1;
+ let hasTypes = 1;
let extraClassDeclaration = [{
/// The name of a unit attribute on funcs that are allowed to have a
diff --git a/mlir/include/mlir/Dialect/Complex/IR/ComplexBase.td b/mlir/include/mlir/Dialect/Complex/IR/ComplexBase.td
index c8af498f448295..4d18f033860f31 100644
--- a/mlir/include/mlir/Dialect/Complex/IR/ComplexBase.td
+++ b/mlir/include/mlir/Dialect/Complex/IR/ComplexBase.td
@@ -22,7 +22,7 @@ def Complex_Dialect : Dialect {
let dependentDialects = ["arith::ArithDialect"];
let hasConstantMaterializer = 1;
- let useDefaultAttributePrinterParser = 1;
+ let hasAttributes = 1;
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/Dialect/DLTI/DLTIBase.td b/mlir/include/mlir/Dialect/DLTI/DLTIBase.td
index 3754f3699c7fdc..17782481955e6a 100644
--- a/mlir/include/mlir/Dialect/DLTI/DLTIBase.td
+++ b/mlir/include/mlir/Dialect/DLTI/DLTIBase.td
@@ -75,7 +75,7 @@ def DLTI_Dialect : Dialect {
kDataLayoutLegalIntWidthsKey = "dlti.legal_int_widths";
}];
- let useDefaultAttributePrinterParser = 1;
+ let hasAttributes = 1;
}
def HasDefaultDLTIDataLayout : NativeOpTrait<"HasDefaultDLTIDataLayout"> {
diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitCBase.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitCBase.td
index 375dbcbce1d036..42d807e2c976df 100644
--- a/mlir/include/mlir/Dialect/EmitC/IR/EmitCBase.td
+++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitCBase.td
@@ -29,8 +29,8 @@ def EmitC_Dialect : Dialect {
}];
let hasConstantMaterializer = 1;
- let useDefaultTypePrinterParser = 1;
- let useDefaultAttributePrinterParser = 1;
+ let hasTypes = 1;
+ let hasAttributes = 1;
}
#endif // MLIR_DIALECT_EMITC_IR_EMITCBASE
diff --git a/mlir/include/mlir/Dialect/IRDL/IR/IRDL.td b/mlir/include/mlir/Dialect/IRDL/IR/IRDL.td
index e822969fc575eb..38aae9b72ddae2 100644
--- a/mlir/include/mlir/Dialect/IRDL/IR/IRDL.td
+++ b/mlir/include/mlir/Dialect/IRDL/IR/IRDL.td
@@ -69,8 +69,8 @@ def IRDL_Dialect : Dialect {
attribute. The rationale of this is to simplify the dialect.
}];
- let useDefaultAttributePrinterParser = 1;
- let useDefaultTypePrinterParser = 1;
+ let hasAttributes = 1;
+ let hasTypes = 1;
let name = "irdl";
let cppNamespace = "::mlir::irdl";
diff --git a/mlir/include/mlir/Dialect/Index/IR/IndexDialect.td b/mlir/include/mlir/Dialect/Index/IR/IndexDialect.td
index be0fea79ee3920..2815828544c38b 100644
--- a/mlir/include/mlir/Dialect/Index/IR/IndexDialect.td
+++ b/mlir/include/mlir/Dialect/Index/IR/IndexDialect.td
@@ -75,14 +75,12 @@ def IndexDialect : Dialect {
let cppNamespace = "::mlir::index";
let extraClassDeclaration = [{
- /// Register all dialect attributes.
- void registerAttributes();
/// Register all dialect operations.
void registerOperations();
}];
let hasConstantMaterializer = 1;
- let useDefaultAttributePrinterParser = 1;
+ let hasAttributes = 1;
}
#endif // INDEX_DIALECT
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.td
index fbfb74176b0096..9e713510cf95c2 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.td
@@ -16,7 +16,9 @@ def LLVM_Dialect : Dialect {
let cppNamespace = "::mlir::LLVM";
let hasConstantMaterializer = 1;
- let useDefaultAttributePrinterParser = 1;
+ let hasAttributes = 1;
+ let hasTypes = 1;
+ let useDefaultTypePrinterParser = 0;
let hasRegionArgAttrVerify = 1;
let hasRegionResultAttrVerify = 1;
let hasOperationAttrVerify = 1;
@@ -125,16 +127,10 @@ def LLVM_Dialect : Dialect {
Type paramType,
NamedAttribute paramAttr);
- /// Register all types.
- void registerTypes();
-
/// A cache storing compatible LLVM types that have been verified. This
/// can save us lots of verification time if there are many occurrences
/// of some deeply-nested aggregate types in the program.
ThreadLocalCache<DenseSet<Type>> compatibleTypes;
-
- /// Register the attributes of this dialect.
- void registerAttributes();
}];
}
diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.td b/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.td
index 48480bc2daacb7..ed279c0dc7ba75 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.td
@@ -86,13 +86,9 @@ def NVVM_Dialect : Dialect {
unsigned regionIndex,
unsigned argIndex,
NamedAttribute argAttr) override;
-
- private:
- /// Register the attributes of this dialect.
- void registerAttributes();
}];
- let useDefaultAttributePrinterParser = 1;
+ let hasAttributes = 1;
}
#endif // NVVMIR_DIALECT
diff --git a/mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.td b/mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.td
index f16cd824fa40ed..0779bf420d248e 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.td
@@ -174,7 +174,7 @@ def ROCDL_Dialect : Dialect {
"::mlir::UnitAttr":$ignore_denormal_mode
);
- let useDefaultAttributePrinterParser = 1;
+ let hasAttributes = 1;
}
#endif // ROCDLIR_DIALECT
diff --git a/mlir/include/mlir/Dialect/LLVMIR/XeVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/XeVMOps.td
index 2aa818824db0f4..f9e1df311388f3 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/XeVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/XeVMOps.td
@@ -36,7 +36,7 @@ def XeVM_Dialect : Dialect {
}
}];
- let useDefaultAttributePrinterParser = 1;
+ let hasAttributes = 1;
}
class XeVM_Attr<string attrName, string attrMnemonic, list<Trait> traits = []>
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgBase.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgBase.td
index 85857d3c11206b..b1550e5b6fa21e 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgBase.td
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgBase.td
@@ -42,7 +42,7 @@ def Linalg_Dialect : Dialect {
"memref::MemRefDialect",
"tensor::TensorDialect",
];
- let useDefaultAttributePrinterParser = 1;
+ let hasAttributes = 1;
let hasCanonicalizer = 1;
let hasOperationAttrVerify = 1;
let hasConstantMaterializer = 1;
diff --git a/mlir/include/mlir/Dialect/MLProgram/IR/MLProgramBase.td b/mlir/include/mlir/Dialect/MLProgram/IR/MLProgramBase.td
index a585059020eaf6..9e0189fa043c31 100644
--- a/mlir/include/mlir/Dialect/MLProgram/IR/MLProgramBase.td
+++ b/mlir/include/mlir/Dialect/MLProgram/IR/MLProgramBase.td
@@ -27,8 +27,8 @@ def MLProgram_Dialect : Dialect {
it is recommended to inquire further prior to using this dialect.
}];
- let useDefaultAttributePrinterParser = 1;
- let useDefaultTypePrinterParser = 1;
+ let hasAttributes = 1;
+ let hasTypes = 1;
}
#endif // MLPROGRAM_BASE
diff --git a/mlir/include/mlir/Dialect/MPI/IR/MPI.td b/mlir/include/mlir/Dialect/MPI/IR/MPI.td
index ba422273d5354d..5524b244a5e2ea 100644
--- a/mlir/include/mlir/Dialect/MPI/IR/MPI.td
+++ b/mlir/include/mlir/Dialect/MPI/IR/MPI.td
@@ -34,8 +34,8 @@ def MPI_Dialect : Dialect {
[OpenMPI online documentation](https://www.open-mpi.org/doc/current/).
}];
- let useDefaultAttributePrinterParser = 1;
- let useDefaultTypePrinterParser = 1;
+ let hasAttributes = 1;
+ let hasTypes = 1;
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td b/mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td
index 1c0d7bd1113ea6..0c91ae7e87a47d 100644
--- a/mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td
+++ b/mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td
@@ -28,8 +28,8 @@ def NVGPU_Dialect : Dialect {
and Vector for memory and target-specific register operands, respectively.
}];
- let useDefaultTypePrinterParser = 1;
- let useDefaultAttributePrinterParser = 1;
+ let hasTypes = 1;
+ let hasAttributes = 1;
let extraClassDeclaration = [{
/// Return true if the given MemRefType has an integer address
diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCBase.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCBase.td
index d18e5d28eb3091..a64978a4e22992 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCBase.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCBase.td
@@ -18,8 +18,8 @@ include "mlir/IR/AttrTypeBase.td"
def OpenACC_Dialect : Dialect {
let name = "acc";
- let useDefaultAttributePrinterParser = 1;
- let useDefaultTypePrinterParser = 1;
+ let hasAttributes = 1;
+ let hasTypes = 1;
let cppNamespace = "::mlir::acc";
}
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPDialect.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPDialect.td
index 2dfee7120e82af..f5bd2b5b2ac40b 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPDialect.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPDialect.td
@@ -15,8 +15,8 @@ def OpenMP_Dialect : Dialect {
let name = "omp";
let cppNamespace = "::mlir::omp";
let dependentDialects = ["::mlir::LLVM::LLVMDialect, ::mlir::func::FuncDialect"];
- let useDefaultAttributePrinterParser = 1;
- let useDefaultTypePrinterParser = 1;
+ let hasAttributes = 1;
+ let hasTypes = 1;
let hasOperationAttrVerify = 1;
}
diff --git a/mlir/include/mlir/Dialect/PDL/IR/PDLDialect.td b/mlir/include/mlir/Dialect/PDL/IR/PDLDialect.td
index d405bec26634c5..3c93a78c7f2c18 100644
--- a/mlir/include/mlir/Dialect/PDL/IR/PDLDialect.td
+++ b/mlir/include/mlir/Dialect/PDL/IR/PDLDialect.td
@@ -64,11 +64,7 @@ def PDL_Dialect : Dialect {
let name = "pdl";
let cppNamespace = "::mlir::pdl";
-
- let useDefaultTypePrinterParser = 1;
- let extraClassDeclaration = [{
- void registerTypes();
- }];
+ let hasTypes = 1;
}
#endif // MLIR_DIALECT_PDL_IR_PDLDIALECT
diff --git a/mlir/include/mlir/Dialect/Ptr/IR/PtrDialect.td b/mlir/include/mlir/Dialect/Ptr/IR/PtrDialect.td
index 6b9c76e4c78e9b..2c84781e05a11b 100644
--- a/mlir/include/mlir/Dialect/Ptr/IR/PtrDialect.td
+++ b/mlir/include/mlir/Dialect/Ptr/IR/PtrDialect.td
@@ -34,8 +34,8 @@ def Ptr_Dialect : Dialect {
considered a target-specific property.
}];
let cppNamespace = "::mlir::ptr";
- let useDefaultTypePrinterParser = 1;
- let useDefaultAttributePrinterParser = 1;
+ let hasTypes = 1;
+ let hasAttributes = 1;
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/Dialect/SMT/IR/SMTDialect.td b/mlir/include/mlir/Dialect/SMT/IR/SMTDialect.td
index 00f170659946ef..09b10d5b4abe20 100644
--- a/mlir/include/mlir/Dialect/SMT/IR/SMTDialect.td
+++ b/mlir/include/mlir/Dialect/SMT/IR/SMTDialect.td
@@ -16,15 +16,10 @@ def SMTDialect : Dialect {
let summary = "a dialect that models satisfiability modulo theories";
let cppNamespace = "mlir::smt";
- let useDefaultAttributePrinterParser = 1;
- let useDefaultTypePrinterParser = 1;
+ let hasAttributes = 1;
+ let hasTypes = 1;
let hasConstantMaterializer = 1;
-
- let extraClassDeclaration = [{
- void registerAttributes();
- void registerTypes();
- }];
}
#endif // MLIR_DIALECT_SMT_IR_SMTDIALECT_TD
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td
index 22391c8afff3ca..255ea332e8c4b0 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td
@@ -47,6 +47,8 @@ def SPIRV_Dialect : Dialect {
}];
let cppNamespace = "::mlir::spirv";
+ let hasAttributes = 1;
+ let useDefaultAttributePrinterParser = 0;
let useDefaultTypePrinterParser = 1;
let hasConstantMaterializer = 1;
let hasOperationAttrVerify = 1;
diff --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
index fb4af69bf50f34..435b3f746d72c5 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
@@ -38,7 +38,7 @@ def ShapeDialect : Dialect {
let cppNamespace = "::mlir::shape";
let dependentDialects = ["arith::ArithDialect", "tensor::TensorDialect"];
- let useDefaultTypePrinterParser = 1;
+ let hasTypes = 1;
let hasConstantMaterializer = 1;
let hasOperationAttrVerify = 1;
}
diff --git a/mlir/include/mlir/Dialect/Shard/IR/ShardBase.td b/mlir/include/mlir/Dialect/Shard/IR/ShardBase.td
index 0bb0687e6ff6a6..c51ccd90082073 100644
--- a/mlir/include/mlir/Dialect/Shard/IR/ShardBase.td
+++ b/mlir/include/mlir/Dialect/Shard/IR/ShardBase.td
@@ -31,8 +31,8 @@ def Shard_Dialect : Dialect {
"arith::ArithDialect" // For materializeConstant()
];
- let useDefaultAttributePrinterParser = 1;
- let useDefaultTypePrinterParser = 1;
+ let hasAttributes = 1;
+ let hasTypes = 1;
let hasConstantMaterializer = 1;
}
diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorBase.td b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorBase.td
index 74e6783e260faf..e4c120799f3dbe 100644
--- a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorBase.td
+++ b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorBase.td
@@ -88,8 +88,8 @@ def SparseTensor_Dialect : Dialect {
PhD thesis, MIT, February, 2020.
}];
- let useDefaultAttributePrinterParser = 1;
- let useDefaultTypePrinterParser = 1;
+ let hasAttributes = 1;
+ let hasTypes = 1;
let hasConstantMaterializer = 1;
}
diff --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaOpBase.td b/mlir/include/mlir/Dialect/Tosa/IR/TosaOpBase.td
index af7c7b778e2fe7..484272fefa4b59 100644
--- a/mlir/include/mlir/Dialect/Tosa/IR/TosaOpBase.td
+++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaOpBase.td
@@ -51,8 +51,8 @@ def Tosa_Dialect : Dialect {
let cppNamespace = "mlir::tosa";
let hasConstantMaterializer = 1;
- let useDefaultAttributePrinterParser = 1;
- let useDefaultTypePrinterParser = 1;
+ let hasAttributes = 1;
+ let hasTypes = 1;
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/Dialect/UB/IR/UBOps.td b/mlir/include/mlir/Dialect/UB/IR/UBOps.td
index 2c3c9b1b2686c2..e8cf1a0e17b672 100644
--- a/mlir/include/mlir/Dialect/UB/IR/UBOps.td
+++ b/mlir/include/mlir/Dialect/UB/IR/UBOps.td
@@ -19,7 +19,7 @@ def UB_Dialect : Dialect {
let cppNamespace = "::mlir::ub";
let hasConstantMaterializer = 1;
- let useDefaultAttributePrinterParser = 1;
+ let hasAttributes = 1;
}
// Base class for UB dialect attributes.
diff --git a/mlir/include/mlir/Dialect/Vector/IR/Vector.td b/mlir/include/mlir/Dialect/Vector/IR/Vector.td
index 45ebb7e83d8d48..24820baf72c224 100644
--- a/mlir/include/mlir/Dialect/Vector/IR/Vector.td
+++ b/mlir/include/mlir/Dialect/Vector/IR/Vector.td
@@ -19,7 +19,7 @@ def Vector_Dialect : Dialect {
let name = "vector";
let cppNamespace = "::mlir::vector";
- let useDefaultAttributePrinterParser = 1;
+ let hasAttributes = 1;
let hasConstantMaterializer = 1;
let hasCanonicalizer = 1;
let dependentDialects = [
diff --git a/mlir/include/mlir/Dialect/WasmSSA/IR/WasmSSABase.td b/mlir/include/mlir/Dialect/WasmSSA/IR/WasmSSABase.td
index f2777a7b155edd..8d8ee156f88cc9 100644
--- a/mlir/include/mlir/Dialect/WasmSSA/IR/WasmSSABase.td
+++ b/mlir/include/mlir/Dialect/WasmSSA/IR/WasmSSABase.td
@@ -19,7 +19,7 @@ def WasmSSA_Dialect : Dialect {
The `wasmssa` dialect is intended to represent WebAssembly
modules in SSA form for easier manipulation.
}];
- let useDefaultTypePrinterParser = true;
+ let hasTypes = 1;
}
#endif //WasmSSA_BASE
diff --git a/mlir/include/mlir/Dialect/X86/X86.td b/mlir/include/mlir/Dialect/X86/X86.td
index 39a85366cc4f78..2d88ac1368c7cb 100644
--- a/mlir/include/mlir/Dialect/X86/X86.td
+++ b/mlir/include/mlir/Dialect/X86/X86.td
@@ -27,7 +27,7 @@ def X86_Dialect : Dialect {
let name = "x86";
let cppNamespace = "::mlir::x86";
- let useDefaultTypePrinterParser = 1;
+ let hasTypes = 1;
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/Dialect/XeGPU/IR/XeGPUDialect.td b/mlir/include/mlir/Dialect/XeGPU/IR/XeGPUDialect.td
index b1490c7742a269..0225d8410544cf 100644
--- a/mlir/include/mlir/Dialect/XeGPU/IR/XeGPUDialect.td
+++ b/mlir/include/mlir/Dialect/XeGPU/IR/XeGPUDialect.td
@@ -34,8 +34,8 @@ def XeGPU_Dialect : Dialect {
let dependentDialects = ["arith::ArithDialect"];
- let useDefaultTypePrinterParser = true;
- let useDefaultAttributePrinterParser = true;
+ let hasTypes = 1;
+ let hasAttributes = 1;
let extraClassDeclaration = [{
/// Checks if the given memref type represents shared local memory (SLM).
diff --git a/mlir/include/mlir/IR/BuiltinDialect.td b/mlir/include/mlir/IR/BuiltinDialect.td
index c770dd50f3622a..f470749e7e5a28 100644
--- a/mlir/include/mlir/IR/BuiltinDialect.td
+++ b/mlir/include/mlir/IR/BuiltinDialect.td
@@ -21,6 +21,8 @@ def Builtin_Dialect : Dialect {
"A dialect containing the builtin Attributes, Operations, and Types";
let name = "builtin";
let cppNamespace = "::mlir";
+ let hasAttributes = 1;
+ let hasTypes = 1;
let useDefaultAttributePrinterParser = 0;
let useDefaultTypePrinterParser = 0;
let extraClassDeclaration = [{
@@ -28,13 +30,6 @@ def Builtin_Dialect : Dialect {
void setVersion(std::optional<BuiltinDialectVersion> v) { version = v; }
private:
- // Register the builtin Attributes.
- void registerAttributes();
- // Register the builtin Location Attributes.
- void registerLocationAttributes();
- // Register the builtin Types.
- void registerTypes();
-
std::optional<BuiltinDialectVersion> version;
}];
diff --git a/mlir/include/mlir/IR/CMakeLists.txt b/mlir/include/mlir/IR/CMakeLists.txt
index 15518901b901ab..7d8bfcb03324a8 100644
--- a/mlir/include/mlir/IR/CMakeLists.txt
+++ b/mlir/include/mlir/IR/CMakeLists.txt
@@ -35,8 +35,10 @@ mlir_tablegen(BuiltinDialectBytecode.cpp.inc -gen-bytecode -bytecode-dialect="Bu
add_mlir_generic_tablegen_target(MLIRBuiltinDialectBytecodeIncGen)
set(LLVM_TARGET_DEFINITIONS BuiltinLocationAttributes.td)
-mlir_tablegen(BuiltinLocationAttributes.h.inc -gen-attrdef-decls)
-mlir_tablegen(BuiltinLocationAttributes.cpp.inc -gen-attrdef-defs)
+mlir_tablegen(BuiltinLocationAttributes.h.inc -gen-attrdef-decls
+ -attrdefs-registration-name=BuiltinLocation)
+mlir_tablegen(BuiltinLocationAttributes.cpp.inc -gen-attrdef-defs
+ -attrdefs-registration-name=BuiltinLocation)
add_mlir_generic_tablegen_target(MLIRBuiltinLocationAttributesIncGen)
set(LLVM_TARGET_DEFINITIONS BuiltinOps.td)
diff --git a/mlir/include/mlir/IR/DialectBase.td b/mlir/include/mlir/IR/DialectBase.td
index 046aaf13c6a11a..40ac36777950f3 100644
--- a/mlir/include/mlir/IR/DialectBase.td
+++ b/mlir/include/mlir/IR/DialectBase.td
@@ -82,17 +82,37 @@ class Dialect {
// If this dialect overrides the hook for op interface fallback.
bit hasOperationInterfaceFallback = 0;
+ // If this dialect has attributes defined in ODS. Provides the default of
+ // `useDefaultAttributeRegistration` and `useDefaultAttributePrinterParser`.
+ bit hasAttributes = 0;
+
+ // If this dialect has types defined in ODS. Provides the default of
+ // `useDefaultTypeRegistration` and `useDefaultTypePrinterParser`.
+ bit hasTypes = 0;
+
+ // If the generated dialect constructor should register the attributes defined
+ // in ODS by calling `register<DialectClass>Attributes`.
+ // The definition is usually provided by the attribute definitions
+ // generator (`-gen-attrdef-defs`).
+ bit useDefaultAttributeRegistration = hasAttributes;
+
+ // If the generated dialect constructor should register the types defined in
+ // ODS by calling `register<DialectClass>Types`.
+ // The definition is usually provided by the type definitions generator
+ // (`-gen-typedef-defs`).
+ bit useDefaultTypeRegistration = hasTypes;
+
// If this dialect should use default generated attribute parser boilerplate.
// When set, ODS will generate declarations for the attribute parsing and
// printing hooks in the dialect and default implementations that dispatch to
// each individual attribute directly.
- bit useDefaultAttributePrinterParser = 0;
+ bit useDefaultAttributePrinterParser = hasAttributes;
// If this dialect should use default generated type parser boilerplate:
// When set, ODS will generate declarations for the type parsing and printing
// hooks in the dialect and default implementations that dispatch to each
// individual type directly.
- bit useDefaultTypePrinterParser = 0;
+ bit useDefaultTypePrinterParser = hasTypes;
// If this dialect overrides the hook for canonicalization patterns.
bit hasCanonicalizer = 0;
diff --git a/mlir/include/mlir/TableGen/Dialect.h b/mlir/include/mlir/TableGen/Dialect.h
index 68230196b17cc0..d9de59636bb809 100644
--- a/mlir/include/mlir/TableGen/Dialect.h
+++ b/mlir/include/mlir/TableGen/Dialect.h
@@ -80,6 +80,14 @@ class Dialect {
/// Returns true if this dialect has fallback interfaces for its operations.
bool hasOperationInterfaceFallback() const;
+ /// Returns true if the generated dialect constructor should register the
+ /// attributes of this dialect defined in ODS.
+ bool useDefaultAttributeRegistration() const;
+
+ /// Returns true if the generated dialect constructor should register the
+ /// types of this dialect defined in ODS.
+ bool useDefaultTypeRegistration() const;
+
/// Returns true if this dialect should generate the default dispatch for
/// attribute printing/parsing.
bool useDefaultAttributePrinterParser() const;
diff --git a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUAttrs.cpp b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUAttrs.cpp
index f37f9ab8bc1d0d..e8ccd6f09caa74 100644
--- a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUAttrs.cpp
+++ b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUAttrs.cpp
@@ -14,10 +14,3 @@
#define GET_ATTRDEF_CLASSES
#include "mlir/Dialect/AMDGPU/IR/AMDGPUAttrs.cpp.inc"
-
-void mlir::amdgpu::AMDGPUDialect::registerAttributes() {
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/AMDGPU/IR/AMDGPUAttrs.cpp.inc"
- >();
-}
diff --git a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp
index 92e05b397c0996..5facbb4636b55f 100644
--- a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp
+++ b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp
@@ -39,8 +39,6 @@ void AMDGPUDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/AMDGPU/IR/AMDGPU.cpp.inc"
>();
- registerTypes();
- registerAttributes();
addInterfaces<AMDGPUInlinerInterface>();
declarePromisedInterfaces<
memref::IndexedAccessOpInterface, TransposeLoadOp, GlobalTransposeLoadOp,
diff --git a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUTypes.cpp b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUTypes.cpp
index c144a2b9283e43..7d55d09c4a152f 100644
--- a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUTypes.cpp
+++ b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUTypes.cpp
@@ -14,10 +14,3 @@
#define GET_TYPEDEF_CLASSES
#include "mlir/Dialect/AMDGPU/IR/AMDGPUTypes.cpp.inc"
-
-void mlir::amdgpu::AMDGPUDialect::registerTypes() {
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/AMDGPU/IR/AMDGPUTypes.cpp.inc"
- >();
-}
diff --git a/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp b/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp
index 774e63b9575c18..2dd8453d7d6bb2 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp
@@ -42,10 +42,6 @@ void arith::ArithDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/Arith/IR/ArithOps.cpp.inc"
>();
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/Arith/IR/ArithOpsAttributes.cpp.inc"
- >();
addInterfaces<ArithInlinerInterface>();
declarePromisedInterface<ConvertToEmitCPatternInterface, ArithDialect>();
declarePromisedInterface<ConvertToLLVMPatternInterface, ArithDialect>();
diff --git a/mlir/lib/Dialect/ArmSME/IR/ArmSME.cpp b/mlir/lib/Dialect/ArmSME/IR/ArmSME.cpp
index 3557221397428a..e526af70be9836 100644
--- a/mlir/lib/Dialect/ArmSME/IR/ArmSME.cpp
+++ b/mlir/lib/Dialect/ArmSME/IR/ArmSME.cpp
@@ -64,11 +64,6 @@ LogicalResult TileStoreOp::verify() {
}
void ArmSMEDialect::initialize() {
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/ArmSME/IR/ArmSMEAttrDefs.cpp.inc"
- >();
-
addOperations<
#define GET_OP_LIST
#include "mlir/Dialect/ArmSME/IR/ArmSMEOps.cpp.inc"
diff --git a/mlir/lib/Dialect/Async/IR/Async.cpp b/mlir/lib/Dialect/Async/IR/Async.cpp
index 69d940eaad7b03..3866c44dafc697 100644
--- a/mlir/lib/Dialect/Async/IR/Async.cpp
+++ b/mlir/lib/Dialect/Async/IR/Async.cpp
@@ -20,10 +20,6 @@ void AsyncDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/Async/IR/AsyncOps.cpp.inc"
>();
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/Async/IR/AsyncOpsTypes.cpp.inc"
- >();
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp b/mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp
index 296f8de1b781ac..bd5bef7ed24e41 100644
--- a/mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp
+++ b/mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp
@@ -33,10 +33,6 @@ void complex::ComplexDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/Complex/IR/ComplexOps.cpp.inc"
>();
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/Complex/IR/ComplexAttributes.cpp.inc"
- >();
declarePromisedInterface<ConvertToLLVMPatternInterface, ComplexDialect>();
addInterfaces<ComplexInlinerInterface>();
}
diff --git a/mlir/lib/Dialect/DLTI/DLTI.cpp b/mlir/lib/Dialect/DLTI/DLTI.cpp
index e8824f599aabcb..b0945070c1e761 100644
--- a/mlir/lib/Dialect/DLTI/DLTI.cpp
+++ b/mlir/lib/Dialect/DLTI/DLTI.cpp
@@ -697,10 +697,6 @@ class TargetDataLayoutInterface : public DataLayoutDialectInterface {
} // namespace
void DLTIDialect::initialize() {
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/DLTI/DLTIAttrs.cpp.inc"
- >();
addInterfaces<TargetDataLayoutInterface>();
ModuleOp::attachInterface<ModuleDLTIQueryOpInterface>(*getContext());
}
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index 2359a6caf0cec7..8db19f867e23e4 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -33,14 +33,6 @@ void EmitCDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/EmitC/IR/EmitC.cpp.inc"
>();
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/EmitC/IR/EmitCTypes.cpp.inc"
- >();
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/EmitC/IR/EmitCAttributes.cpp.inc"
- >();
}
/// Materialize a single constant operation from a given attribute value with
diff --git a/mlir/lib/Dialect/IRDL/IR/IRDL.cpp b/mlir/lib/Dialect/IRDL/IR/IRDL.cpp
index 10319687cd134b..8ddd71ebc0d3ea 100644
--- a/mlir/lib/Dialect/IRDL/IR/IRDL.cpp
+++ b/mlir/lib/Dialect/IRDL/IR/IRDL.cpp
@@ -39,14 +39,6 @@ void IRDLDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/IRDL/IR/IRDLOps.cpp.inc"
>();
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/IRDL/IR/IRDLTypesGen.cpp.inc"
- >();
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/IRDL/IR/IRDLAttributes.cpp.inc"
- >();
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/Index/IR/IndexAttrs.cpp b/mlir/lib/Dialect/Index/IR/IndexAttrs.cpp
index cd288544852402..ed3dc98b403112 100644
--- a/mlir/lib/Dialect/Index/IR/IndexAttrs.cpp
+++ b/mlir/lib/Dialect/Index/IR/IndexAttrs.cpp
@@ -15,17 +15,6 @@
using namespace mlir;
using namespace mlir::index;
-//===----------------------------------------------------------------------===//
-// IndexDialect
-//===----------------------------------------------------------------------===//
-
-void IndexDialect::registerAttributes() {
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/Index/IR/IndexAttrs.cpp.inc"
- >();
-}
-
//===----------------------------------------------------------------------===//
// ODS-Generated Declarations
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/Index/IR/IndexDialect.cpp b/mlir/lib/Dialect/Index/IR/IndexDialect.cpp
index 887e8e1ae78b6c..101b647048b2cb 100644
--- a/mlir/lib/Dialect/Index/IR/IndexDialect.cpp
+++ b/mlir/lib/Dialect/Index/IR/IndexDialect.cpp
@@ -30,7 +30,6 @@ struct IndexInlinerInterface : public DialectInlinerInterface {
} // namespace
void IndexDialect::initialize() {
- registerAttributes();
registerOperations();
addInterfaces<IndexInlinerInterface>();
declarePromisedInterface<ConvertToLLVMPatternInterface, IndexDialect>();
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
index 91c6dfc65d94ae..21e2e83640274a 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
@@ -51,18 +51,6 @@ static void printSourceLanguage(AsmPrinter &printer,
#define GET_ATTRDEF_CLASSES
#include "mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.cpp.inc"
-//===----------------------------------------------------------------------===//
-// LLVMDialect registration
-//===----------------------------------------------------------------------===//
-
-void LLVMDialect::registerAttributes() {
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.cpp.inc"
-
- >();
-}
-
//===----------------------------------------------------------------------===//
// AddressSpaceAttr
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 6a359a9e42a5d0..d9c1cc24a053f6 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -45,14 +45,12 @@ struct LLVMSCFToControlFlowInterface : SCFToControlFlowDialectInterface {
void LLVMDialect::initialize() {
addInterfaces<LLVMSCFToControlFlowInterface>();
- registerAttributes();
// clang-format off
addTypes<LLVMVoidType,
LLVMLabelType,
LLVMMetadataType>();
// clang-format on
- registerTypes();
registerLLVMDialectOperations(this);
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp
index 0cc0439ca905af..faed215d50e831 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp
@@ -1032,18 +1032,6 @@ llvm::TypeSize mlir::LLVM::getPrimitiveTypeSizeInBits(Type type) {
});
}
-//===----------------------------------------------------------------------===//
-// LLVMDialect
-//===----------------------------------------------------------------------===//
-
-void LLVMDialect::registerTypes() {
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/LLVMIR/LLVMTypes.cpp.inc"
-
- >();
-}
-
Type LLVMDialect::parseType(DialectAsmParser &parser) const {
return detail::parseType(parser);
}
diff --git a/mlir/lib/Dialect/LLVMIR/IR/NVVMAttributes.cpp b/mlir/lib/Dialect/LLVMIR/IR/NVVMAttributes.cpp
index 11fa232e3e5eba..396afda625f600 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/NVVMAttributes.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/NVVMAttributes.cpp
@@ -154,14 +154,3 @@ LogicalResult NVVMTargetAttr::verifyTarget(Operation *gpuModule) {
#define GET_ATTRDEF_CLASSES
#include "mlir/Dialect/LLVMIR/NVVMOpsAttributes.cpp.inc"
-
-//===----------------------------------------------------------------------===//
-// NVVMDialect attribute registration
-//===----------------------------------------------------------------------===//
-
-void NVVMDialect::registerAttributes() {
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/LLVMIR/NVVMOpsAttributes.cpp.inc"
- >();
-}
diff --git a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
index c954bc3e40d8a3..9b0e1540d0fc4d 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
@@ -7542,7 +7542,6 @@ struct NVVMInlinerInterface final : DialectInlinerInterface {
// TODO: This should be the llvm.nvvm dialect once this is supported.
void NVVMDialect::initialize() {
registerNVVMDialectOperations(this);
- registerAttributes();
// Support unknown operations because not all NVVM operations are
// registered.
diff --git a/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
index 331a41ab29ab8a..0456c4ec55ad73 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
@@ -53,11 +53,6 @@ struct ROCDLInlinerInterface final : DialectInlinerInterface {
void ROCDLDialect::initialize() {
registerROCDLDialectOperations(this);
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/LLVMIR/ROCDLOpsAttributes.cpp.inc"
- >();
-
// Support unknown operations because not all ROCDL operations are registered.
allowUnknownOperations();
addInterfaces<ROCDLInlinerInterface>();
diff --git a/mlir/lib/Dialect/LLVMIR/IR/XeVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/XeVMDialect.cpp
index 884947bcf1c092..2ee4ef75e6620a 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/XeVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/XeVMDialect.cpp
@@ -553,11 +553,6 @@ void XeVMDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/LLVMIR/XeVMOps.cpp.inc"
>();
-
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/LLVMIR/XeVMOpsAttributes.cpp.inc"
- >();
declarePromisedInterface<mlir::gpu::TargetAttrInterface,
mlir::xevm::XeVMTargetAttr>();
}
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
index ad693c757211da..9a0d37f60befcd 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
@@ -91,10 +91,6 @@ addNamedOpBuilders(llvm::StringMap<LinalgDialect::RegionBuilderFunType> &map) {
}
void mlir::linalg::LinalgDialect::initialize() {
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/Linalg/IR/LinalgOpsAttrDefs.cpp.inc"
- >();
addOperations<
#define GET_OP_LIST
#include "mlir/Dialect/Linalg/IR/LinalgOps.cpp.inc"
diff --git a/mlir/lib/Dialect/MLProgram/IR/MLProgramDialect.cpp b/mlir/lib/Dialect/MLProgram/IR/MLProgramDialect.cpp
index f46d197fcdaf9b..f9ac89fae59783 100644
--- a/mlir/lib/Dialect/MLProgram/IR/MLProgramDialect.cpp
+++ b/mlir/lib/Dialect/MLProgram/IR/MLProgramDialect.cpp
@@ -41,16 +41,6 @@ struct MLProgramOpAsmDialectInterface : public OpAsmDialectInterface {
} // namespace
void ml_program::MLProgramDialect::initialize() {
-#define GET_ATTRDEF_LIST
- addAttributes<
-#include "mlir/Dialect/MLProgram/IR/MLProgramAttributes.cpp.inc"
- >();
-
-#define GET_TYPEDEF_LIST
- addTypes<
-#include "mlir/Dialect/MLProgram/IR/MLProgramTypes.cpp.inc"
- >();
-
addOperations<
#define GET_OP_LIST
#include "mlir/Dialect/MLProgram/IR/MLProgramOps.cpp.inc"
diff --git a/mlir/lib/Dialect/MPI/IR/MPI.cpp b/mlir/lib/Dialect/MPI/IR/MPI.cpp
index eb36a894b820a3..6c979e16f45017 100644
--- a/mlir/lib/Dialect/MPI/IR/MPI.cpp
+++ b/mlir/lib/Dialect/MPI/IR/MPI.cpp
@@ -24,16 +24,6 @@ void MPIDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/MPI/IR/MPIOps.cpp.inc"
>();
-
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/MPI/IR/MPITypesGen.cpp.inc"
- >();
-
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/MPI/IR/MPIAttrDefs.cpp.inc"
- >();
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/NVGPU/IR/NVGPUDialect.cpp b/mlir/lib/Dialect/NVGPU/IR/NVGPUDialect.cpp
index 1fdc773f2cab99..e795dac2c61912 100644
--- a/mlir/lib/Dialect/NVGPU/IR/NVGPUDialect.cpp
+++ b/mlir/lib/Dialect/NVGPU/IR/NVGPUDialect.cpp
@@ -27,14 +27,6 @@ using namespace mlir::nvgpu;
#include "mlir/Dialect/NVGPU/IR/NVGPUDialect.cpp.inc"
void NVGPUDialect::initialize() {
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/NVGPU/IR/NVGPUTypeDefs.cpp.inc"
- >();
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/NVGPU/IR/NVGPUAttrDefs.cpp.inc"
- >();
addOperations<
#define GET_OP_LIST
#include "mlir/Dialect/NVGPU/IR/NVGPUOps.cpp.inc"
diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
index 5961ccc01ad7ff..d43f51a4106c75 100644
--- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
+++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
@@ -133,15 +133,6 @@ void OpenACCDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/OpenACC/OpenACCOps.cpp.inc"
>();
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/OpenACC/OpenACCOpsAttributes.cpp.inc"
- >();
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/OpenACC/OpenACCOpsTypes.cpp.inc"
- >();
-
PrivateType::attachInterface<PrivateTypePointerLikeModel>(*getContext());
}
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index a879abfc0a3102..8c05150b7c31fe 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -308,15 +308,6 @@ void OpenMPDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc"
>();
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc"
- >();
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/OpenMP/OpenMPOpsTypes.cpp.inc"
- >();
-
declarePromisedInterface<ConvertToLLVMPatternInterface, OpenMPDialect>();
MemRefType::attachInterface<MemRefPointerLikeModel>(*getContext());
diff --git a/mlir/lib/Dialect/PDL/IR/PDL.cpp b/mlir/lib/Dialect/PDL/IR/PDL.cpp
index 634e26aaba7d62..4ff2b09cc83bb3 100644
--- a/mlir/lib/Dialect/PDL/IR/PDL.cpp
+++ b/mlir/lib/Dialect/PDL/IR/PDL.cpp
@@ -27,7 +27,6 @@ void PDLDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/PDL/IR/PDLOps.cpp.inc"
>();
- registerTypes();
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/PDL/IR/PDLTypes.cpp b/mlir/lib/Dialect/PDL/IR/PDLTypes.cpp
index 6508acc62dc9ee..1b4054e5e997a9 100644
--- a/mlir/lib/Dialect/PDL/IR/PDLTypes.cpp
+++ b/mlir/lib/Dialect/PDL/IR/PDLTypes.cpp
@@ -19,17 +19,6 @@ using namespace mlir::pdl;
#define GET_TYPEDEF_CLASSES
#include "mlir/Dialect/PDL/IR/PDLOpsTypes.cpp.inc"
-//===----------------------------------------------------------------------===//
-// PDLDialect
-//===----------------------------------------------------------------------===//
-
-void PDLDialect::registerTypes() {
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/PDL/IR/PDLOpsTypes.cpp.inc"
- >();
-}
-
static Type parsePDLType(AsmParser &parser) {
StringRef typeTag;
{
diff --git a/mlir/lib/Dialect/Ptr/IR/PtrDialect.cpp b/mlir/lib/Dialect/Ptr/IR/PtrDialect.cpp
index 49cfa557947ce4..d280e02928dd6a 100644
--- a/mlir/lib/Dialect/Ptr/IR/PtrDialect.cpp
+++ b/mlir/lib/Dialect/Ptr/IR/PtrDialect.cpp
@@ -27,14 +27,6 @@ void PtrDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/Ptr/IR/PtrOps.cpp.inc"
>();
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/Ptr/IR/PtrOpsAttrs.cpp.inc"
- >();
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/Ptr/IR/PtrOpsTypes.cpp.inc"
- >();
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/SMT/IR/SMTAttributes.cpp b/mlir/lib/Dialect/SMT/IR/SMTAttributes.cpp
index 2b833d7ea2c6f6..065bcecd6375bb 100644
--- a/mlir/lib/Dialect/SMT/IR/SMTAttributes.cpp
+++ b/mlir/lib/Dialect/SMT/IR/SMTAttributes.cpp
@@ -152,10 +152,3 @@ Type BitVectorAttr::getType() const {
#define GET_ATTRDEF_CLASSES
#include "mlir/Dialect/SMT/IR/SMTAttributes.cpp.inc"
-
-void SMTDialect::registerAttributes() {
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/SMT/IR/SMTAttributes.cpp.inc"
- >();
-}
diff --git a/mlir/lib/Dialect/SMT/IR/SMTDialect.cpp b/mlir/lib/Dialect/SMT/IR/SMTDialect.cpp
index 48c0b1ed8e14f9..c647a5ff6acd81 100644
--- a/mlir/lib/Dialect/SMT/IR/SMTDialect.cpp
+++ b/mlir/lib/Dialect/SMT/IR/SMTDialect.cpp
@@ -15,8 +15,6 @@ using namespace mlir;
using namespace smt;
void SMTDialect::initialize() {
- registerAttributes();
- registerTypes();
addOperations<
#define GET_OP_LIST
#include "mlir/Dialect/SMT/IR/SMT.cpp.inc"
diff --git a/mlir/lib/Dialect/SMT/IR/SMTTypes.cpp b/mlir/lib/Dialect/SMT/IR/SMTTypes.cpp
index 4347e95bf9171e..bb415817087293 100644
--- a/mlir/lib/Dialect/SMT/IR/SMTTypes.cpp
+++ b/mlir/lib/Dialect/SMT/IR/SMTTypes.cpp
@@ -31,13 +31,6 @@ static void printDomainTypes(mlir::AsmPrinter &printer,
#define GET_TYPEDEF_CLASSES
#include "mlir/Dialect/SMT/IR/SMTTypes.cpp.inc"
-void SMTDialect::registerTypes() {
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/SMT/IR/SMTTypes.cpp.inc"
- >();
-}
-
bool smt::isAnyNonFuncSMTValueType(Type type) {
return isAnySMTValueType(type) && !isa<SMTFuncType>(type);
}
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp
index d5045daff8e79c..4fae582acb0a0d 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp
@@ -687,8 +687,4 @@ void SPIRVDialect::printAttribute(Attribute attr,
void spirv::SPIRVDialect::registerAttributes() {
addAttributes<InterfaceVarABIAttr, TargetEnvAttr, VerCapExtAttr>();
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.cpp.inc"
- >();
}
diff --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp
index f974b2abf89ac9..4f702243814b7b 100644
--- a/mlir/lib/Dialect/Shape/IR/Shape.cpp
+++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp
@@ -131,10 +131,6 @@ void ShapeDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/Shape/IR/ShapeOps.cpp.inc"
>();
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/Shape/IR/ShapeOpsTypes.cpp.inc"
- >();
addInterfaces<ShapeInlinerInterface>();
// Allow unknown operations during prototyping and testing. As the dialect is
// still evolving it makes it simple to start with an unregistered ops and
diff --git a/mlir/lib/Dialect/Shard/IR/ShardOps.cpp b/mlir/lib/Dialect/Shard/IR/ShardOps.cpp
index 4bfd84faa059a7..f4e39b1cb90c03 100644
--- a/mlir/lib/Dialect/Shard/IR/ShardOps.cpp
+++ b/mlir/lib/Dialect/Shard/IR/ShardOps.cpp
@@ -122,14 +122,6 @@ void ShardDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/Shard/IR/ShardOps.cpp.inc"
>();
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/Shard/IR/ShardAttributes.cpp.inc"
- >();
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/Shard/IR/ShardTypes.cpp.inc"
- >();
addInterface<ShardInlinerinterface>();
}
diff --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
index 598ba1bbddf655..50ee69f102ceaf 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
@@ -2824,14 +2824,6 @@ Operation *SparseTensorDialect::materializeConstant(OpBuilder &builder,
}
void SparseTensorDialect::initialize() {
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.cpp.inc"
- >();
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/SparseTensor/IR/SparseTensorTypes.cpp.inc"
- >();
addOperations<
#define GET_OP_LIST
#include "mlir/Dialect/SparseTensor/IR/SparseTensorOps.cpp.inc"
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index 2818767a0b69e3..c2426e8c2d31a1 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -150,18 +150,10 @@ RankedTensorType mlir::tosa::getVariableType(tosa::VariableOp variableOp) {
//===----------------------------------------------------------------------===//
void TosaDialect::initialize() {
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/Tosa/IR/TosaOpsTypesBase.cpp.inc"
- >();
addOperations<
#define GET_OP_LIST
#include "mlir/Dialect/Tosa/IR/TosaOps.cpp.inc"
>();
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/Tosa/IR/TosaAttributes.cpp.inc"
- >();
addInterfaces<TosaDialectBytecodeInterface, TosaInlinerInterface>();
declarePromisedInterfaces<
shard::ShardingInterface, ClampOp, SigmoidOp, TanhOp, AddOp,
diff --git a/mlir/lib/Dialect/UB/IR/UBOps.cpp b/mlir/lib/Dialect/UB/IR/UBOps.cpp
index ec854367987672..075e12d4e52a09 100644
--- a/mlir/lib/Dialect/UB/IR/UBOps.cpp
+++ b/mlir/lib/Dialect/UB/IR/UBOps.cpp
@@ -39,10 +39,6 @@ void UBDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/UB/IR/UBOps.cpp.inc"
>();
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/UB/IR/UBOpsAttributes.cpp.inc"
- >();
addInterfaces<UBInlinerInterface>();
declarePromisedInterface<ConvertToLLVMPatternInterface, UBDialect>();
}
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index deb03593a50a80..035bc215b67c2c 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -560,11 +560,6 @@ struct VectorInlinerInterface : public DialectInlinerInterface {
} // namespace
void VectorDialect::initialize() {
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/Dialect/Vector/IR/VectorAttributes.cpp.inc"
- >();
-
addOperations<
#define GET_OP_LIST
#include "mlir/Dialect/Vector/IR/VectorOps.cpp.inc"
diff --git a/mlir/lib/Dialect/WasmSSA/IR/WasmSSADialect.cpp b/mlir/lib/Dialect/WasmSSA/IR/WasmSSADialect.cpp
index 8981150b553441..ad0a6581bb0160 100644
--- a/mlir/lib/Dialect/WasmSSA/IR/WasmSSADialect.cpp
+++ b/mlir/lib/Dialect/WasmSSA/IR/WasmSSADialect.cpp
@@ -27,8 +27,4 @@ void wasmssa::WasmSSADialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/WasmSSA/IR/WasmSSAOps.cpp.inc"
>();
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/WasmSSA/IR/WasmSSAOpsTypes.cpp.inc"
- >();
}
diff --git a/mlir/lib/Dialect/X86/IR/X86Dialect.cpp b/mlir/lib/Dialect/X86/IR/X86Dialect.cpp
index 05e50cbf3e44fb..e5ab4c00f7b083 100644
--- a/mlir/lib/Dialect/X86/IR/X86Dialect.cpp
+++ b/mlir/lib/Dialect/X86/IR/X86Dialect.cpp
@@ -25,11 +25,6 @@ using namespace mlir;
#include "mlir/Dialect/X86/X86Dialect.cpp.inc"
void x86::X86Dialect::initialize() {
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/Dialect/X86/X86Types.cpp.inc"
- >();
-
addOperations<
#define GET_OP_LIST
#include "mlir/Dialect/X86/X86.cpp.inc"
diff --git a/mlir/lib/Dialect/XeGPU/IR/XeGPUDialect.cpp b/mlir/lib/Dialect/XeGPU/IR/XeGPUDialect.cpp
index 6579d64833f5b7..a8d732786ea6ca 100644
--- a/mlir/lib/Dialect/XeGPU/IR/XeGPUDialect.cpp
+++ b/mlir/lib/Dialect/XeGPU/IR/XeGPUDialect.cpp
@@ -25,18 +25,10 @@ namespace mlir {
namespace xegpu {
void XeGPUDialect::initialize() {
- addTypes<
-#define GET_TYPEDEF_LIST
-#include <mlir/Dialect/XeGPU/IR/XeGPUTypes.cpp.inc>
- >();
addOperations<
#define GET_OP_LIST
#include <mlir/Dialect/XeGPU/IR/XeGPU.cpp.inc>
>();
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include <mlir/Dialect/XeGPU/IR/XeGPUAttrs.cpp.inc>
- >();
}
#define GET_OP_INTERFACE_CLASSES
#include "mlir/Dialect/XeGPU/IR/XeGPUOpInterface.cpp.inc"
diff --git a/mlir/lib/IR/BuiltinAttributes.cpp b/mlir/lib/IR/BuiltinAttributes.cpp
index f4a9ef2881ae8d..ccaeb3c6638650 100644
--- a/mlir/lib/IR/BuiltinAttributes.cpp
+++ b/mlir/lib/IR/BuiltinAttributes.cpp
@@ -37,18 +37,6 @@ using namespace mlir::detail;
#define GET_ATTRDEF_CLASSES
#include "mlir/IR/BuiltinAttributes.cpp.inc"
-//===----------------------------------------------------------------------===//
-// BuiltinDialect
-//===----------------------------------------------------------------------===//
-
-void BuiltinDialect::registerAttributes() {
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/IR/BuiltinAttributes.cpp.inc"
- >();
- addAttributes<DistinctAttr>();
-}
-
//===----------------------------------------------------------------------===//
// DictionaryAttr
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/IR/BuiltinDialect.cpp b/mlir/lib/IR/BuiltinDialect.cpp
index 080b79c36a2e41..2852612d8e5270 100644
--- a/mlir/lib/IR/BuiltinDialect.cpp
+++ b/mlir/lib/IR/BuiltinDialect.cpp
@@ -12,11 +12,13 @@
//===----------------------------------------------------------------------===//
#include "mlir/IR/BuiltinDialect.h"
+#include "AttributeDetail.h"
#include "BuiltinDialectBytecode.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/DialectResourceBlobManager.h"
+#include "mlir/IR/Location.h"
#include "mlir/IR/OpImplementation.h"
#include "mlir/IR/TypeRange.h"
@@ -104,9 +106,11 @@ struct BuiltinOpAsmDialectInterface : public OpAsmDialectInterface {
void BuiltinDialect::initialize() {
setVersion(BuiltinDialectVersion::getCurrentVersion());
- registerTypes();
- registerAttributes();
- registerLocationAttributes();
+ // `DistinctAttr` is defined in C++, and the location attributes are generated
+ // into a separate file, so neither is registered by the generated
+ // constructor.
+ addAttributes<DistinctAttr>();
+ registerBuiltinLocationAttributes(this);
addOperations<
#define GET_OP_LIST
#include "mlir/IR/BuiltinOps.cpp.inc"
diff --git a/mlir/lib/IR/BuiltinTypes.cpp b/mlir/lib/IR/BuiltinTypes.cpp
index 2ab8d870606161..fce995ba11a993 100644
--- a/mlir/lib/IR/BuiltinTypes.cpp
+++ b/mlir/lib/IR/BuiltinTypes.cpp
@@ -40,17 +40,6 @@ namespace mlir {
#include "mlir/IR/BuiltinTypeConstraints.cpp.inc"
} // namespace mlir
-//===----------------------------------------------------------------------===//
-// BuiltinDialect
-//===----------------------------------------------------------------------===//
-
-void BuiltinDialect::registerTypes() {
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "mlir/IR/BuiltinTypes.cpp.inc"
- >();
-}
-
//===----------------------------------------------------------------------===//
/// ComplexType
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/IR/Location.cpp b/mlir/lib/IR/Location.cpp
index 65dcff100b1553..c58bbf78807f3a 100644
--- a/mlir/lib/IR/Location.cpp
+++ b/mlir/lib/IR/Location.cpp
@@ -245,14 +245,3 @@ Location FusedLoc::get(ArrayRef<Location> locs, Attribute metadata,
return Base::get(context, locs, metadata);
}
-
-//===----------------------------------------------------------------------===//
-// BuiltinDialect
-//===----------------------------------------------------------------------===//
-
-void BuiltinDialect::registerLocationAttributes() {
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "mlir/IR/BuiltinLocationAttributes.cpp.inc"
- >();
-}
diff --git a/mlir/lib/TableGen/Dialect.cpp b/mlir/lib/TableGen/Dialect.cpp
index 84530bfa4f6fd2..75df9df4c2184e 100644
--- a/mlir/lib/TableGen/Dialect.cpp
+++ b/mlir/lib/TableGen/Dialect.cpp
@@ -94,6 +94,14 @@ bool Dialect::hasOperationInterfaceFallback() const {
return def->getValueAsBit("hasOperationInterfaceFallback");
}
+bool Dialect::useDefaultAttributeRegistration() const {
+ return def->getValueAsBit("useDefaultAttributeRegistration");
+}
+
+bool Dialect::useDefaultTypeRegistration() const {
+ return def->getValueAsBit("useDefaultTypeRegistration");
+}
+
bool Dialect::useDefaultAttributePrinterParser() const {
return def->getValueAsBit("useDefaultAttributePrinterParser");
}
diff --git a/mlir/test/lib/Dialect/Test/TestAttributes.cpp b/mlir/test/lib/Dialect/Test/TestAttributes.cpp
index d86a32af6c39a7..dea61ab9802755 100644
--- a/mlir/test/lib/Dialect/Test/TestAttributes.cpp
+++ b/mlir/test/lib/Dialect/Test/TestAttributes.cpp
@@ -604,7 +604,6 @@ mlir::AffineMap TestMemRefLayoutAttr::getAffineMap() const {
//===----------------------------------------------------------------------===//
void TestDialect::registerAttributes() {
- registerTestDialectAttributes(this);
registerDynamicAttr(getDynamicSingletonAttr(this));
registerDynamicAttr(getDynamicPairAttr(this));
registerDynamicAttr(getDynamicCustomAssemblyFormatAttr(this));
diff --git a/mlir/test/lib/Dialect/Test/TestDialect.td b/mlir/test/lib/Dialect/Test/TestDialect.td
index 37a263f1d10b8b..ed68142abc6dc4 100644
--- a/mlir/test/lib/Dialect/Test/TestDialect.td
+++ b/mlir/test/lib/Dialect/Test/TestDialect.td
@@ -21,8 +21,9 @@ def Test_Dialect : Dialect {
let hasRegionResultAttrVerify = 1;
let hasOperationInterfaceFallback = 1;
let hasNonDefaultDestructor = 1;
+ let hasTypes = 1;
let useDefaultTypePrinterParser = 0;
- let useDefaultAttributePrinterParser = 1;
+ let hasAttributes = 1;
let isExtensible = 1;
let dependentDialects = [
"::mlir::DLTIDialect",
diff --git a/mlir/test/lib/Dialect/Test/TestTypes.cpp b/mlir/test/lib/Dialect/Test/TestTypes.cpp
index 9410d5e2aa9226..1cb506a353adff 100644
--- a/mlir/test/lib/Dialect/Test/TestTypes.cpp
+++ b/mlir/test/lib/Dialect/Test/TestTypes.cpp
@@ -418,7 +418,6 @@ struct PtrElementModel
void TestDialect::registerTypes() {
addTypes<TestRecursiveType>();
- registerTestDialectTypes(this);
SimpleAType::attachInterface<PtrElementModel>(*getContext());
registerDynamicType(getSingletonDynamicType(this));
diff --git a/mlir/test/mlir-tblgen/attrdefs.td b/mlir/test/mlir-tblgen/attrdefs.td
index 69baa712b5bafc..17e547766af15a 100644
--- a/mlir/test/mlir-tblgen/attrdefs.td
+++ b/mlir/test/mlir-tblgen/attrdefs.td
@@ -1,5 +1,7 @@
// RUN: mlir-tblgen -gen-attrdef-decls -I %S/../../include %s | FileCheck %s --check-prefix=DECL
// RUN: mlir-tblgen -gen-attrdef-defs -I %S/../../include %s | FileCheck %s --check-prefix=DEF
+// RUN: mlir-tblgen -gen-attrdef-decls -attrdefs-registration-name=Ext -I %S/../../include %s | FileCheck %s --check-prefix=NAME
+// RUN: mlir-tblgen -gen-attrdef-defs -attrdefs-registration-name=Ext -I %S/../../include %s | FileCheck %s --check-prefix=NAME
include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/OpBase.td"
@@ -40,6 +42,7 @@ def Test_Dialect: Dialect {
// DEF-NOT: TestDialect
let name = "TestDialect";
let cppNamespace = "::test";
+ let useDefaultAttributeRegistration = 1;
}
class TestAttr<string name> : AttrDef<Test_Dialect, name> { }
@@ -206,9 +209,16 @@ def J_CustomStorageCtorAttr : AttrDef<Test_Dialect, "CustomStorageCtorAttr"> {
// DEF-SAME: (::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey);
// The registration hook registers every attribute.
-// DEF: class TestDialect;
-// DEF-NEXT: {{\[\[}}maybe_unused{{\]\]}} static void registerTestDialectAttributes(TestDialect *dialect) {
+// DECL: class TestDialect;
+// DECL-NEXT: /// Registers the attributes defined in this file with `dialect`.
+// DECL-NEXT: void registerTestDialectAttributes(TestDialect *dialect);
+// DECL-EMPTY:
+// DECL-NEXT: } // namespace test
+
+// DEF: void registerTestDialectAttributes(TestDialect *dialect) {
// DEF-NEXT: ::mlir::AbstractAttribute::insert<IndexAttr>(*dialect);
// DEF-NEXT: ::mlir::AbstractAttribute::insert<SimpleAAttr>(*dialect);
// DEF: ::mlir::AbstractAttribute::insert<CustomStorageCtorAttrAttr>(*dialect);
// DEF-NEXT: }
+
+// NAME: void registerExtAttributes(TestDialect *dialect)
diff --git a/mlir/test/mlir-tblgen/dialect-initialize.td b/mlir/test/mlir-tblgen/dialect-initialize.td
new file mode 100644
index 00000000000000..940d4d18dedfca
--- /dev/null
+++ b/mlir/test/mlir-tblgen/dialect-initialize.td
@@ -0,0 +1,100 @@
+// RUN: mlir-tblgen -gen-dialect-decls -dialect=both -I %S/../../include %s | FileCheck %s --check-prefix=BOTH-DECL
+// RUN: mlir-tblgen -gen-dialect-defs -dialect=both -I %S/../../include %s | FileCheck %s --check-prefix=BOTH
+// RUN: mlir-tblgen -gen-dialect-decls -dialect=attrs -I %S/../../include %s | FileCheck %s --check-prefix=ATTRS-DECL
+// RUN: mlir-tblgen -gen-dialect-defs -dialect=attrs -I %S/../../include %s | FileCheck %s --check-prefix=ATTRS
+// RUN: mlir-tblgen -gen-dialect-decls -dialect=custom -I %S/../../include %s | FileCheck %s --check-prefix=CUSTOM-DECL
+// RUN: mlir-tblgen -gen-dialect-defs -dialect=custom -I %S/../../include %s | FileCheck %s --check-prefix=CUSTOM
+// RUN: mlir-tblgen -gen-attrdef-defs -attrdefs-dialect=custom -I %S/../../include %s | FileCheck %s --check-prefix=CUSTOM-ATTRS
+// RUN: mlir-tblgen -gen-typedef-decls -typedefs-dialect=custom -I %S/../../include %s | FileCheck %s --check-prefix=CUSTOM-TYPES
+// RUN: mlir-tblgen -gen-typedef-defs -typedefs-dialect=custom -I %S/../../include %s | FileCheck %s --check-prefix=CUSTOM-TYPES
+// RUN: mlir-tblgen -gen-dialect-decls -dialect=none -I %S/../../include %s | FileCheck %s --check-prefix=NONE-DECL
+// RUN: mlir-tblgen -gen-dialect-defs -dialect=none -I %S/../../include %s | FileCheck %s --check-prefix=NONE
+// RUN: mlir-tblgen -gen-attrdef-decls -attrdefs-dialect=none -I %S/../../include %s | FileCheck %s --check-prefix=NONE-HOOK
+// RUN: mlir-tblgen -gen-attrdef-defs -attrdefs-dialect=none -I %S/../../include %s | FileCheck %s --check-prefix=NONE-HOOK
+
+include "mlir/IR/AttrTypeBase.td"
+
+// `hasAttributes` (or `hasTypes`) provides the default of
+// `useDefaultAttributeRegistration` and `useDefaultAttributePrinterParser` (or
+// their type counterparts). The constructor registers the attributes and types
+// independently of whether the dialect has a custom destructor.
+
+def Both_Dialect : Dialect {
+ let name = "both";
+ let cppNamespace = "::both";
+ let hasAttributes = 1;
+ let hasTypes = 1;
+ let hasNonDefaultDestructor = 1;
+ let dependentDialects = ["::foo::FooDialect"];
+}
+
+// BOTH-DECL: /// Parse an attribute registered to this dialect.
+// BOTH-DECL: /// Parse a type registered to this dialect.
+
+// BOTH: void registerBothDialectAttributes(BothDialect *dialect);
+// BOTH-NEXT: void registerBothDialectTypes(BothDialect *dialect);
+// BOTH: BothDialect::BothDialect(::mlir::MLIRContext *context)
+// BOTH: getContext()->loadDialect<::foo::FooDialect>();
+// BOTH-NEXT: registerBothDialectAttributes(this);
+// BOTH-NEXT: registerBothDialectTypes(this);
+// BOTH-NEXT: initialize();
+// BOTH-NEXT: }
+// BOTH-NOT: ~BothDialect
+
+def Attrs_Dialect : Dialect {
+ let name = "attrs";
+ let cppNamespace = "::attrs";
+ let hasAttributes = 1;
+}
+
+// ATTRS-DECL: /// Parse an attribute registered to this dialect.
+// ATTRS-DECL-NOT: /// Parse a type registered to this dialect.
+
+// ATTRS-NOT: Types
+// ATTRS: void registerAttrsDialectAttributes(AttrsDialect *dialect);
+// ATTRS: AttrsDialect::AttrsDialect(::mlir::MLIRContext *context)
+// ATTRS: registerAttrsDialectAttributes(this);
+// ATTRS-NEXT: initialize();
+// ATTRS-NEXT: }
+// ATTRS: AttrsDialect::~AttrsDialect() = default;
+// ATTRS-NOT: Types
+
+// The `use` flags override the default provided by `hasAttributes` and
+// `hasTypes`. The registration hook is only generated for the dialect's default
+// registration.
+
+def Custom_Dialect : Dialect {
+ let name = "custom";
+ let cppNamespace = "::custom";
+ let hasAttributes = 1;
+ let hasTypes = 1;
+ let useDefaultAttributePrinterParser = 0;
+ let useDefaultTypeRegistration = 0;
+}
+def Custom_Attr : AttrDef<Custom_Dialect, "Foo"> { let mnemonic = "foo"; }
+def Custom_Type : TypeDef<Custom_Dialect, "Bar"> { let mnemonic = "bar"; }
+
+// CUSTOM-DECL-NOT: /// Parse an attribute registered to this dialect.
+// CUSTOM-DECL: /// Parse a type registered to this dialect.
+
+// CUSTOM-NOT: Types
+// CUSTOM: registerCustomDialectAttributes(this);
+// CUSTOM-NEXT: initialize();
+// CUSTOM-NOT: Types
+
+// CUSTOM-ATTRS: void registerCustomDialectAttributes(CustomDialect *dialect) {
+// CUSTOM-TYPES-NOT: registerCustomDialectTypes
+
+// By default, nothing is registered and no hook is generated, even if the
+// definitions are visible.
+
+def None_Dialect : Dialect {
+ let name = "none";
+ let cppNamespace = "::none";
+}
+def None_Attr : AttrDef<None_Dialect, "Foo"> { let mnemonic = "foo"; }
+def None_Type : TypeDef<None_Dialect, "Bar"> { let mnemonic = "bar"; }
+
+// NONE-DECL-NOT: registered to this dialect
+// NONE-NOT: register
+// NONE-HOOK-NOT: registerNoneDialectAttributes
diff --git a/mlir/test/mlir-tblgen/typedefs.td b/mlir/test/mlir-tblgen/typedefs.td
index 30bded77d24085..7cbd0086e750c6 100644
--- a/mlir/test/mlir-tblgen/typedefs.td
+++ b/mlir/test/mlir-tblgen/typedefs.td
@@ -1,5 +1,7 @@
// RUN: mlir-tblgen -gen-typedef-decls -I %S/../../include %s | FileCheck %s --check-prefix=DECL
// RUN: mlir-tblgen -gen-typedef-defs -I %S/../../include %s | FileCheck %s --check-prefix=DEF
+// RUN: mlir-tblgen -gen-typedef-decls -typedefs-registration-name=Ext -I %S/../../include %s | FileCheck %s --check-prefix=NAME
+// RUN: mlir-tblgen -gen-typedef-defs -typedefs-registration-name=Ext -I %S/../../include %s | FileCheck %s --check-prefix=NAME
include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/OpBase.td"
@@ -39,6 +41,7 @@ def Test_Dialect: Dialect {
// DECL-NOT: TestDialect
let name = "TestDialect";
let cppNamespace = "::test";
+ let useDefaultTypeRegistration = 1;
}
class TestType<string name> : TypeDef<Test_Dialect, name> { }
@@ -155,11 +158,18 @@ def E_IntegerType : TestType<"Integer"> {
}
// The registration hook registers every type.
-// DEF: class TestDialect;
-// DEF-NEXT: {{\[\[}}maybe_unused{{\]\]}} static void registerTestDialectTypes(TestDialect *dialect) {
+// DECL: class TestDialect;
+// DECL-NEXT: /// Registers the types defined in this file with `dialect`.
+// DECL-NEXT: void registerTestDialectTypes(TestDialect *dialect);
+// DECL-EMPTY:
+// DECL-NEXT: } // namespace test
+
+// DEF: void registerTestDialectTypes(TestDialect *dialect) {
// DEF-NEXT: ::mlir::AbstractType::insert<SimpleAType>(*dialect);
// DEF-NEXT: ::mlir::AbstractType::insert<CompoundAType>(*dialect);
// DEF-NEXT: ::mlir::AbstractType::insert<IndexType>(*dialect);
// DEF-NEXT: ::mlir::AbstractType::insert<SingleParameterType>(*dialect);
// DEF-NEXT: ::mlir::AbstractType::insert<IntegerType>(*dialect);
// DEF-NEXT: }
+
+// NAME: void registerExtTypes(TestDialect *dialect)
diff --git a/mlir/test/python/lib/PythonTestDialect.cpp b/mlir/test/python/lib/PythonTestDialect.cpp
index a0ff31504c6918..783645b10887bc 100644
--- a/mlir/test/python/lib/PythonTestDialect.cpp
+++ b/mlir/test/python/lib/PythonTestDialect.cpp
@@ -28,14 +28,6 @@ void PythonTestDialect::initialize() {
#define GET_OP_LIST
#include "PythonTestOps.cpp.inc"
>();
- addAttributes<
-#define GET_ATTRDEF_LIST
-#include "PythonTestAttributes.cpp.inc"
- >();
- addTypes<
-#define GET_TYPEDEF_LIST
-#include "PythonTestTypes.cpp.inc"
- >();
}
} // namespace python_test
diff --git a/mlir/test/python/python_test_ops.td b/mlir/test/python/python_test_ops.td
index aabd6c22efb1f7..2c2ea8f1e9e993 100644
--- a/mlir/test/python/python_test_ops.td
+++ b/mlir/test/python/python_test_ops.td
@@ -17,8 +17,8 @@ def Python_Test_Dialect : Dialect {
let name = "python_test";
let cppNamespace = "python_test";
- let useDefaultTypePrinterParser = 1;
- let useDefaultAttributePrinterParser = 1;
+ let hasTypes = 1;
+ let hasAttributes = 1;
}
class TestType<string name, string typeMnemonic>
diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
index 97f95a1c0aafdc..c8f0557530cdc2 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
@@ -8,6 +8,7 @@
#include "AttrOrTypeFormatGen.h"
#include "CppGenUtilities.h"
+#include "DialectGenUtilities.h"
#include "mlir/TableGen/AttrOrTypeDef.h"
#include "mlir/TableGen/Class.h"
#include "mlir/TableGen/Format.h"
@@ -848,8 +849,14 @@ namespace {
/// This struct is the base generator used when processing tablegen interfaces.
class DefGenerator {
public:
- bool emitDecls(StringRef selectedDialect);
- bool emitDefs(StringRef selectedDialect);
+ /// Emit the declarations of the defs of `selectedDialect`. The registration
+ /// hook is named after `registrationName`, or after the dialect class if
+ /// empty.
+ bool emitDecls(StringRef selectedDialect, StringRef registrationName);
+ /// Emit the definitions of the defs of `selectedDialect`. The registration
+ /// hook is named after `registrationName`, or after the dialect class if
+ /// empty.
+ bool emitDefs(StringRef selectedDialect, StringRef registrationName);
protected:
DefGenerator(ArrayRef<const Record *> defs, raw_ostream &os,
@@ -867,11 +874,17 @@ class DefGenerator {
/// Emit the code to dispatch between different defs during parsing/printing.
void emitParsePrintDispatch(ArrayRef<AttrOrTypeDef> defs);
- /// Returns the name of the function that registers the defs of `dialect`.
- std::string getRegistrationHookName(const Dialect &dialect) const;
+ /// Returns true if the dialect of `defs` registers them with the generated
+ /// registration hook. Otherwise, no hook is generated.
+ bool hasRegistrationHook(ArrayRef<AttrOrTypeDef> defs) const;
+
+ /// Emit the declaration of the hook that registers `defs` with their dialect.
+ void emitRegistrationHookDecl(raw_ostream &os, ArrayRef<AttrOrTypeDef> defs,
+ StringRef registrationName);
/// Emit the definition of the hook that registers `defs` with their dialect.
- void emitRegistrationHook(ArrayRef<AttrOrTypeDef> defs);
+ void emitRegistrationHookDef(ArrayRef<AttrOrTypeDef> defs,
+ StringRef registrationName);
/// The set of def records to emit.
std::vector<const Record *> defRecords;
@@ -914,7 +927,8 @@ class AsmPrinter;
} // namespace mlir
)";
-bool DefGenerator::emitDecls(StringRef selectedDialect) {
+bool DefGenerator::emitDecls(StringRef selectedDialect,
+ StringRef registrationName) {
emitSourceFileHeader((defType + "Def Declarations").str(), os);
llvm::IfDefEmitter scope(os, "GET_" + defType.upper() + "DEF_CLASSES");
@@ -944,6 +958,9 @@ bool DefGenerator::emitDecls(StringRef selectedDialect) {
gen.emitDecl(declOs);
llvm::append_range(includes, gen.getRequiredIncludes());
}
+
+ if (hasRegistrationHook(defs))
+ emitRegistrationHookDecl(declOs, defs, registrationName);
}
tblgen::emitIncludes(os, includes);
@@ -1199,26 +1216,39 @@ void DefGenerator::emitParsePrintDispatch(ArrayRef<AttrOrTypeDef> defs) {
printer.writeDeclTo(indentedOs);
}
-std::string
-DefGenerator::getRegistrationHookName(const Dialect &dialect) const {
- return strfmt("register{0}{1}s", dialect.getCppClassName(), valueType);
+bool DefGenerator::hasRegistrationHook(ArrayRef<AttrOrTypeDef> defs) const {
+ Dialect dialect = defs.front().getDialect();
+ return isAttrGenerator ? dialect.useDefaultAttributeRegistration()
+ : dialect.useDefaultTypeRegistration();
}
-/// Emit the hook that registers the defs with their dialect. Since registering
-/// requires the definitions of the storage classes, the hook is a static
-/// function.
-void DefGenerator::emitRegistrationHook(ArrayRef<AttrOrTypeDef> defs) {
+void DefGenerator::emitRegistrationHookDecl(raw_ostream &os,
+ ArrayRef<AttrOrTypeDef> defs,
+ StringRef registrationName) {
Dialect dialect = defs.front().getDialect();
std::string dialectClass = dialect.getCppClassName();
- DialectNamespaceEmitter ns(os, dialect);
- // TODO: Ideally, the hook would be non-static, so that callers do not have to
- // be in the same TU as the registration function. This is currently blocked
- // by dialects defining their attributes and types across multiple TUs (e.g.
- // the transform dialect and its extensions), whose hooks would cause
- // multiple definition errors.
os << "class " << dialectClass << ";\n"
- << llvm::formatv("[[maybe_unused]] static void {0}({1} *dialect) {{\n",
- getRegistrationHookName(dialect), dialectClass);
+ << llvm::formatv("/// Registers the {0}s defined in this file with "
+ "`dialect`.\n",
+ valueType.lower())
+ << llvm::formatv("void {0}({1} *dialect);\n",
+ getAttrOrTypeRegistrationHookName(dialect, valueType,
+ registrationName),
+ dialectClass);
+}
+
+/// Emit the hook that registers the defs with their dialect. Registering
+/// requires the definitions of the storage classes, so the hook is defined
+/// alongside the defs. Every set of defs of a dialect must hence use a distinct
+/// `registrationName` (e.g. the defs of dialect extensions).
+void DefGenerator::emitRegistrationHookDef(ArrayRef<AttrOrTypeDef> defs,
+ StringRef registrationName) {
+ Dialect dialect = defs.front().getDialect();
+ DialectNamespaceEmitter ns(os, dialect);
+ os << llvm::formatv(
+ "void {0}({1} *dialect) {{\n",
+ getAttrOrTypeRegistrationHookName(dialect, valueType, registrationName),
+ dialect.getCppClassName());
for (const AttrOrTypeDef &def : defs)
os << llvm::formatv(" ::mlir::Abstract{0}::insert<{1}>(*dialect);\n",
valueType, def.getCppClassName());
@@ -1240,7 +1270,8 @@ static constexpr StringRef attrOrTypeDefIncludes[] = {
"mlir/IR/OpImplementation.h",
};
-bool DefGenerator::emitDefs(StringRef selectedDialect) {
+bool DefGenerator::emitDefs(StringRef selectedDialect,
+ StringRef registrationName) {
emitSourceFileHeader((defType + "Def Definitions").str(), os);
SmallVector<AttrOrTypeDef, 16> defs;
@@ -1264,7 +1295,8 @@ bool DefGenerator::emitDefs(StringRef selectedDialect) {
<< def.getDialect().getCppNamespace() << "::" << def.getCppClassName()
<< ")\n";
}
- emitRegistrationHook(defs);
+ if (hasRegistrationHook(defs))
+ emitRegistrationHookDef(defs, registrationName);
Dialect firstDialect = defs.front().getDialect();
@@ -1403,18 +1435,26 @@ static llvm::cl::opt<std::string>
attrDialect("attrdefs-dialect",
llvm::cl::desc("Generate attributes for this dialect"),
llvm::cl::cat(attrdefGenCat), llvm::cl::CommaSeparated);
+static llvm::cl::opt<std::string> attrRegistrationName(
+ "attrdefs-registration-name",
+ llvm::cl::desc("Name the attribute registration hook "
+ "'register<name>Attributes' instead of using the dialect "
+ "class name. Required to generate attributes of a dialect "
+ "in more than one file, e.g. for dialect extensions"),
+ llvm::cl::cat(attrdefGenCat));
static mlir::GenRegistration
genAttrDefs("gen-attrdef-defs", "Generate AttrDef definitions",
[](const RecordKeeper &records, raw_ostream &os) {
AttrDefGenerator generator(records, os);
- return generator.emitDefs(attrDialect);
+ return generator.emitDefs(attrDialect, attrRegistrationName);
});
static mlir::GenRegistration
genAttrDecls("gen-attrdef-decls", "Generate AttrDef declarations",
[](const RecordKeeper &records, raw_ostream &os) {
AttrDefGenerator generator(records, os);
- return generator.emitDecls(attrDialect);
+ return generator.emitDecls(attrDialect,
+ attrRegistrationName);
});
static mlir::GenRegistration
@@ -1441,18 +1481,26 @@ static llvm::cl::opt<std::string>
typeDialect("typedefs-dialect",
llvm::cl::desc("Generate types for this dialect"),
llvm::cl::cat(typedefGenCat), llvm::cl::CommaSeparated);
+static llvm::cl::opt<std::string> typeRegistrationName(
+ "typedefs-registration-name",
+ llvm::cl::desc("Name the type registration hook 'register<name>Types' "
+ "instead of using the dialect class name. Required to "
+ "generate types of a dialect in more than one file, e.g. "
+ "for dialect extensions"),
+ llvm::cl::cat(typedefGenCat));
static mlir::GenRegistration
genTypeDefs("gen-typedef-defs", "Generate TypeDef definitions",
[](const RecordKeeper &records, raw_ostream &os) {
TypeDefGenerator generator(records, os);
- return generator.emitDefs(typeDialect);
+ return generator.emitDefs(typeDialect, typeRegistrationName);
});
static mlir::GenRegistration
genTypeDecls("gen-typedef-decls", "Generate TypeDef declarations",
[](const RecordKeeper &records, raw_ostream &os) {
TypeDefGenerator generator(records, os);
- return generator.emitDecls(typeDialect);
+ return generator.emitDecls(typeDialect,
+ typeRegistrationName);
});
static mlir::GenRegistration
diff --git a/mlir/tools/mlir-tblgen/DialectGen.cpp b/mlir/tools/mlir-tblgen/DialectGen.cpp
index a1633174cbdfa7..567305f71b99cb 100644
--- a/mlir/tools/mlir-tblgen/DialectGen.cpp
+++ b/mlir/tools/mlir-tblgen/DialectGen.cpp
@@ -80,6 +80,15 @@ tblgen::findDialectToGenerate(ArrayRef<Dialect> dialects) {
return *dialectIt;
}
+std::string tblgen::getAttrOrTypeRegistrationHookName(
+ const Dialect &dialect, StringRef valueType, StringRef registrationName) {
+ return llvm::formatv("register{0}{1}s",
+ registrationName.empty() ? dialect.getCppClassName()
+ : registrationName.str(),
+ valueType)
+ .str();
+}
+
//===----------------------------------------------------------------------===//
// GEN: Dialect declarations
//===----------------------------------------------------------------------===//
@@ -323,7 +332,8 @@ static bool emitDialectDecls(const RecordKeeper &records, raw_ostream &os) {
///
/// {0}: The name of the dialect class.
/// {1}: Initialization code that is emitted in the ctor body before calling
-/// initialize(), such as dependent dialect registration.
+/// initialize(), such as dependent dialect registration and the
+/// registration of the attributes and types generated by ODS.
/// {2}: The dialect parent class.
/// {3}: Extra members to initialize
static const char *const dialectConstructorStr = R"(
@@ -356,18 +366,24 @@ static void emitDialectDef(Dialect &dialect, const RecordKeeper &records,
// Emit all nested namespaces.
DialectNamespaceEmitter nsEmitter(os, dialect);
- /// Build the list of dependent dialects.
- std::string dependentDialectRegistrations;
- {
- llvm::raw_string_ostream dialectsOs(dependentDialectRegistrations);
- llvm::interleave(
- dialect.getDependentDialects(), dialectsOs,
- [&](StringRef dependentDialect) {
- dialectsOs << llvm::formatv(dialectRegistrationTemplate,
- dependentDialect);
- },
- "\n ");
- }
+ // Build the initialization code: the registration of the dependent dialects
+ // and of the attributes and types generated by ODS, whose registration hooks
+ // are defined alongside the generated attribute and type definitions.
+ SmallVector<std::string> hooks;
+ if (dialect.useDefaultAttributeRegistration())
+ hooks.push_back(getAttrOrTypeRegistrationHookName(dialect, "Attribute"));
+ if (dialect.useDefaultTypeRegistration())
+ hooks.push_back(getAttrOrTypeRegistrationHookName(dialect, "Type"));
+ for (const std::string &hook : hooks)
+ os << llvm::formatv("void {0}({1} *dialect);\n", hook, cppClassName);
+
+ SmallVector<std::string> initStatements;
+ for (StringRef dependentDialect : dialect.getDependentDialects())
+ initStatements.push_back(
+ llvm::formatv(dialectRegistrationTemplate, dependentDialect).str());
+ for (const std::string &hook : hooks)
+ initStatements.push_back(llvm::formatv("{0}(this);", hook).str());
+ std::string initCode = llvm::join(initStatements, "\n ");
// Emit the constructor and destructor.
StringRef superClassName =
@@ -385,9 +401,8 @@ static void emitDialectDef(Dialect &dialect, const RecordKeeper &records,
os << ", " << camelName << "AttrName(context)";
}
- os << llvm::formatv(dialectConstructorStr, cppClassName,
- dependentDialectRegistrations, superClassName,
- discardableAttributesInit);
+ os << llvm::formatv(dialectConstructorStr, cppClassName, initCode,
+ superClassName, discardableAttributesInit);
if (!dialect.hasNonDefaultDestructor())
os << llvm::formatv(dialectDestructorStr, cppClassName);
}
diff --git a/mlir/tools/mlir-tblgen/DialectGenUtilities.h b/mlir/tools/mlir-tblgen/DialectGenUtilities.h
index 979a9d67b40470..43a57de68b7f01 100644
--- a/mlir/tools/mlir-tblgen/DialectGenUtilities.h
+++ b/mlir/tools/mlir-tblgen/DialectGenUtilities.h
@@ -10,6 +10,7 @@
#define MLIR_TOOLS_MLIRTBLGEN_DIALECTGENUTILITIES_H_
#include "mlir/Support/LLVM.h"
+#include <string>
namespace mlir {
namespace tblgen {
@@ -18,6 +19,14 @@ class Dialect;
/// Find the dialect selected by the user to generate for. Returns std::nullopt
/// if no dialect was found, or if more than one potential dialect was found.
std::optional<Dialect> findDialectToGenerate(ArrayRef<Dialect> dialects);
+
+/// Returns the name of the generated function that registers the attributes
+/// (if `valueType` is "Attribute") or types (if `valueType` is "Type") of
+/// `dialect`. The name contains `registrationName`, or the dialect class name
+/// if empty.
+std::string getAttrOrTypeRegistrationHookName(const Dialect &dialect,
+ StringRef valueType,
+ StringRef registrationName = {});
} // namespace tblgen
} // namespace mlir
>From b2f2da5262a44fa0e8a430d6943e6cd424466eb3 Mon Sep 17 00:00:00 2001
From: Markus Boeck <mboeck at nvidia.com>
Date: Fri, 20 Nov 2026 14:53:30 +0000
Subject: [PATCH 3/4] forgotten header
---
mlir/tools/mlir-tblgen/DialectGenUtilities.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/mlir/tools/mlir-tblgen/DialectGenUtilities.h b/mlir/tools/mlir-tblgen/DialectGenUtilities.h
index 43a57de68b7f01..41ba99358dcbc8 100644
--- a/mlir/tools/mlir-tblgen/DialectGenUtilities.h
+++ b/mlir/tools/mlir-tblgen/DialectGenUtilities.h
@@ -10,6 +10,7 @@
#define MLIR_TOOLS_MLIRTBLGEN_DIALECTGENUTILITIES_H_
#include "mlir/Support/LLVM.h"
+#include "llvm/ADT/StringRef.h"
#include <string>
namespace mlir {
>From 68edb541acf48978f23daf16ec1cabcc2e58ffd0 Mon Sep 17 00:00:00 2001
From: Markus Boeck <mboeck at nvidia.com>
Date: Mon, 23 Nov 2026 08:35:13 +0000
Subject: [PATCH 4/4] address review comments
---
mlir/test/mlir-tblgen/attrdefs.td | 2 --
mlir/test/mlir-tblgen/typedefs.td | 2 --
mlir/tools/mlir-tblgen/DialectGen.cpp | 11 ++++++-----
3 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/mlir/test/mlir-tblgen/attrdefs.td b/mlir/test/mlir-tblgen/attrdefs.td
index 17e547766af15a..f93ccfbb33c06f 100644
--- a/mlir/test/mlir-tblgen/attrdefs.td
+++ b/mlir/test/mlir-tblgen/attrdefs.td
@@ -212,8 +212,6 @@ def J_CustomStorageCtorAttr : AttrDef<Test_Dialect, "CustomStorageCtorAttr"> {
// DECL: class TestDialect;
// DECL-NEXT: /// Registers the attributes defined in this file with `dialect`.
// DECL-NEXT: void registerTestDialectAttributes(TestDialect *dialect);
-// DECL-EMPTY:
-// DECL-NEXT: } // namespace test
// DEF: void registerTestDialectAttributes(TestDialect *dialect) {
// DEF-NEXT: ::mlir::AbstractAttribute::insert<IndexAttr>(*dialect);
diff --git a/mlir/test/mlir-tblgen/typedefs.td b/mlir/test/mlir-tblgen/typedefs.td
index 7cbd0086e750c6..73d1d7da8c54ae 100644
--- a/mlir/test/mlir-tblgen/typedefs.td
+++ b/mlir/test/mlir-tblgen/typedefs.td
@@ -161,8 +161,6 @@ def E_IntegerType : TestType<"Integer"> {
// DECL: class TestDialect;
// DECL-NEXT: /// Registers the types defined in this file with `dialect`.
// DECL-NEXT: void registerTestDialectTypes(TestDialect *dialect);
-// DECL-EMPTY:
-// DECL-NEXT: } // namespace test
// DEF: void registerTestDialectTypes(TestDialect *dialect) {
// DEF-NEXT: ::mlir::AbstractType::insert<SimpleAType>(*dialect);
diff --git a/mlir/tools/mlir-tblgen/DialectGen.cpp b/mlir/tools/mlir-tblgen/DialectGen.cpp
index 567305f71b99cb..0148de6a44b377 100644
--- a/mlir/tools/mlir-tblgen/DialectGen.cpp
+++ b/mlir/tools/mlir-tblgen/DialectGen.cpp
@@ -377,13 +377,14 @@ static void emitDialectDef(Dialect &dialect, const RecordKeeper &records,
for (const std::string &hook : hooks)
os << llvm::formatv("void {0}({1} *dialect);\n", hook, cppClassName);
- SmallVector<std::string> initStatements;
+ std::string initCode;
+ llvm::raw_string_ostream initOs(initCode);
+ llvm::ListSeparator sep("\n ");
for (StringRef dependentDialect : dialect.getDependentDialects())
- initStatements.push_back(
- llvm::formatv(dialectRegistrationTemplate, dependentDialect).str());
+ initOs << sep
+ << llvm::formatv(dialectRegistrationTemplate, dependentDialect);
for (const std::string &hook : hooks)
- initStatements.push_back(llvm::formatv("{0}(this);", hook).str());
- std::string initCode = llvm::join(initStatements, "\n ");
+ initOs << sep << hook << "(this);";
// Emit the constructor and destructor.
StringRef superClassName =
More information about the cfe-commits
mailing list