diff --git a/mlir/include/mlir/IR/BuiltinDialect.td b/mlir/include/mlir/IR/BuiltinDialect.td --- a/mlir/include/mlir/IR/BuiltinDialect.td +++ b/mlir/include/mlir/IR/BuiltinDialect.td @@ -19,9 +19,10 @@ def Builtin_Dialect : Dialect { let summary = "A dialect containing the builtin Attributes, Operations, and Types"; - let name = "builtin"; let cppNamespace = "::mlir"; + let useDefaultAttributePrinterParser = 0; + let useDefaultTypePrinterParser = 0; let extraClassDeclaration = [{ private: // Register the builtin Attributes. diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -314,11 +314,11 @@ // If this dialect should use default generated attribute parser boilerplate: // it'll dispatch the parsing to every individual attributes directly. - bit useDefaultAttributePrinterParser = 0; + bit useDefaultAttributePrinterParser = 1; // If this dialect should use default generated type parser boilerplate: // it'll dispatch the parsing to every individual types directly. - bit useDefaultTypePrinterParser = 0; + bit useDefaultTypePrinterParser = 1; // If this dialect overrides the hook for canonicalization patterns. bit hasCanonicalizer = 0; diff --git a/mlir/lib/Dialect/Async/IR/Async.cpp b/mlir/lib/Dialect/Async/IR/Async.cpp --- a/mlir/lib/Dialect/Async/IR/Async.cpp +++ b/mlir/lib/Dialect/Async/IR/Async.cpp @@ -346,22 +346,3 @@ } return ValueType::get(ty); } - -/// Print a type registered to this dialect. -void AsyncDialect::printType(Type type, DialectAsmPrinter &os) const { - if (failed(generatedTypePrinter(type, os))) - llvm_unreachable("unexpected 'async' type kind"); -} - -/// Parse a type registered to this dialect. -Type AsyncDialect::parseType(DialectAsmParser &parser) const { - StringRef typeTag; - if (parser.parseKeyword(&typeTag)) - return Type(); - Type genType; - auto parseResult = generatedTypeParser(parser, typeTag, genType); - if (parseResult.hasValue()) - return genType; - parser.emitError(parser.getNameLoc(), "unknown async type: ") << typeTag; - return {}; -} diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp --- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp +++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp @@ -180,26 +180,6 @@ return get(parser.getContext(), value); } -Attribute EmitCDialect::parseAttribute(DialectAsmParser &parser, - Type type) const { - llvm::SMLoc typeLoc = parser.getCurrentLocation(); - StringRef mnemonic; - if (parser.parseKeyword(&mnemonic)) - return Attribute(); - Attribute genAttr; - OptionalParseResult parseResult = - generatedAttributeParser(parser, mnemonic, type, genAttr); - if (parseResult.hasValue()) - return genAttr; - parser.emitError(typeLoc, "unknown attribute in EmitC dialect"); - return Attribute(); -} - -void EmitCDialect::printAttribute(Attribute attr, DialectAsmPrinter &os) const { - if (failed(generatedAttributePrinter(attr, os))) - llvm_unreachable("unexpected 'EmitC' attribute kind"); -} - void emitc::OpaqueAttr::print(AsmPrinter &printer) const { printer << "<\""; llvm::printEscapedString(getValue(), printer.getStream()); diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -2906,28 +2906,3 @@ llvm::sort(options, llvm::less_first()); return get(parser.getContext(), options); } - -Attribute LLVMDialect::parseAttribute(DialectAsmParser &parser, - Type type) const { - if (type) { - parser.emitError(parser.getNameLoc(), "unexpected type"); - return {}; - } - StringRef attrKind; - if (parser.parseKeyword(&attrKind)) - return {}; - { - Attribute attr; - auto parseResult = generatedAttributeParser(parser, attrKind, type, attr); - if (parseResult.hasValue()) - return attr; - } - parser.emitError(parser.getNameLoc(), "unknown attribute type: ") << attrKind; - return {}; -} - -void LLVMDialect::printAttribute(Attribute attr, DialectAsmPrinter &os) const { - if (succeeded(generatedAttributePrinter(attr, os))) - return; - llvm_unreachable("Unknown attribute type"); -} diff --git a/mlir/lib/Dialect/PDL/IR/PDLTypes.cpp b/mlir/lib/Dialect/PDL/IR/PDLTypes.cpp --- a/mlir/lib/Dialect/PDL/IR/PDLTypes.cpp +++ b/mlir/lib/Dialect/PDL/IR/PDLTypes.cpp @@ -53,15 +53,6 @@ return Type(); } -Type PDLDialect::parseType(DialectAsmParser &parser) const { - return parsePDLType(parser); -} - -void PDLDialect::printType(Type type, DialectAsmPrinter &printer) const { - if (failed(generatedTypePrinter(type, printer))) - llvm_unreachable("unknown 'pdl' type"); -} - //===----------------------------------------------------------------------===// // PDL Types //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp --- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp +++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp @@ -346,22 +346,3 @@ #define GET_OP_CLASSES #include "mlir/Dialect/SparseTensor/IR/SparseTensorOps.cpp.inc" - -Attribute SparseTensorDialect::parseAttribute(DialectAsmParser &parser, - Type type) const { - StringRef attrTag; - if (failed(parser.parseKeyword(&attrTag))) - return Attribute(); - Attribute attr; - auto parseResult = generatedAttributeParser(parser, attrTag, type, attr); - if (parseResult.hasValue()) - return attr; - parser.emitError(parser.getNameLoc(), "unknown sparse tensor attribute"); - return Attribute(); -} - -void SparseTensorDialect::printAttribute(Attribute attr, - DialectAsmPrinter &printer) const { - if (succeeded(generatedAttributePrinter(attr, printer))) - return; -} diff --git a/mlir/lib/IR/BuiltinAttributes.cpp b/mlir/lib/IR/BuiltinAttributes.cpp --- a/mlir/lib/IR/BuiltinAttributes.cpp +++ b/mlir/lib/IR/BuiltinAttributes.cpp @@ -12,12 +12,14 @@ #include "mlir/IR/BuiltinDialect.h" #include "mlir/IR/Dialect.h" #include "mlir/IR/IntegerSet.h" +#include "mlir/IR/OpImplementation.h" #include "mlir/IR/Operation.h" #include "mlir/IR/SymbolTable.h" #include "mlir/IR/Types.h" #include "mlir/Interfaces/DecodeAttributesInterfaces.h" #include "llvm/ADT/APSInt.h" #include "llvm/ADT/Sequence.h" +#include "llvm/ADT/TypeSwitch.h" #include "llvm/Support/Endian.h" using namespace mlir; diff --git a/mlir/test/lib/Dialect/Test/TestDialect.td b/mlir/test/lib/Dialect/Test/TestDialect.td --- a/mlir/test/lib/Dialect/Test/TestDialect.td +++ b/mlir/test/lib/Dialect/Test/TestDialect.td @@ -22,7 +22,7 @@ let hasRegionResultAttrVerify = 1; let hasOperationInterfaceFallback = 1; let hasNonDefaultDestructor = 1; - let useDefaultAttributePrinterParser = 1; + let useDefaultTypePrinterParser = 0; let dependentDialects = ["::mlir::DLTIDialect"]; let extraClassDeclaration = [{ diff --git a/mlir/test/mlir-tblgen/attr-or-type-format.td b/mlir/test/mlir-tblgen/attr-or-type-format.td --- a/mlir/test/mlir-tblgen/attr-or-type-format.td +++ b/mlir/test/mlir-tblgen/attr-or-type-format.td @@ -7,6 +7,7 @@ def Test_Dialect : Dialect { let name = "TestDialect"; let cppNamespace = "::test"; + let useDefaultTypePrinterParser = 0; } class TestAttr : AttrDef; diff --git a/mlir/test/mlir-tblgen/typedefs.td b/mlir/test/mlir-tblgen/typedefs.td --- a/mlir/test/mlir-tblgen/typedefs.td +++ b/mlir/test/mlir-tblgen/typedefs.td @@ -34,7 +34,6 @@ def Test_Dialect: Dialect { // DECL-NOT: TestDialect -// DEF-NOT: TestDialect let name = "TestDialect"; let cppNamespace = "::test"; } diff --git a/mlir/tools/mlir-tblgen/DialectGen.cpp b/mlir/tools/mlir-tblgen/DialectGen.cpp --- a/mlir/tools/mlir-tblgen/DialectGen.cpp +++ b/mlir/tools/mlir-tblgen/DialectGen.cpp @@ -210,9 +210,9 @@ // Check for any attributes/types registered to this dialect. If there are, // add the hooks for parsing/printing. - if (!dialectAttrs.empty() || dialect.useDefaultAttributePrinterParser()) + if (!dialectAttrs.empty()) os << attrParserDecl; - if (!dialectTypes.empty() || dialect.useDefaultTypePrinterParser()) + if (!dialectTypes.empty()) os << typeParserDecl; // Add the decls for the various features of the dialect.