From 4b32f8bac40dcd1535bfe95757c3de0911bf6d1a Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 29 Sep 2021 17:47:08 -0700 Subject: [PATCH] [ODS/AsmParser] Don't pass MLIRContext with DialectAsmParser. The former is redundant because the later carries it as part of its builder. Add a getContext() helper method to DialectAsmParser to make this more convenient, and stop passing the context around explicitly. This simplifies ODS generated parser hooks for attrs and types. This resolves PR51985 Differential Revision: https://reviews.llvm.org/D110796 --- flang/lib/Optimizer/Dialect/FIRType.cpp | 70 ++++++++-------------- mlir/include/mlir/IR/OpImplementation.h | 3 +- mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 6 +- mlir/lib/Dialect/ArmSVE/IR/ArmSVEDialect.cpp | 3 +- mlir/lib/Dialect/Async/IR/Async.cpp | 5 +- mlir/lib/Dialect/DLTI/DLTI.cpp | 4 +- mlir/lib/Dialect/EmitC/IR/EmitC.cpp | 15 +++-- mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 24 ++++---- mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp | 2 +- mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp | 4 +- mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp | 4 +- mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp | 6 +- mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp | 2 +- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp | 4 +- mlir/lib/Dialect/PDL/IR/PDLTypes.cpp | 5 +- mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp | 5 +- .../SparseTensor/IR/SparseTensorDialect.cpp | 10 ++-- mlir/lib/Dialect/Vector/VectorOps.cpp | 3 +- mlir/lib/Parser/Parser.cpp | 2 + mlir/test/lib/Dialect/Test/TestAttributes.cpp | 23 +++---- mlir/test/lib/Dialect/Test/TestDialect.cpp | 2 +- mlir/test/lib/Dialect/Test/TestTypes.cpp | 19 +++--- mlir/test/mlir-tblgen/attrdefs.td | 14 ++--- mlir/test/mlir-tblgen/typedefs.td | 12 ++-- mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp | 15 ++--- mlir/tools/mlir-tblgen/OpFormatGen.cpp | 2 +- .../Interfaces/DataLayoutInterfacesTest.cpp | 6 +- 27 files changed, 117 insertions(+), 153 deletions(-) diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp index 2030e0b..fb3fba6 100644 --- a/flang/lib/Optimizer/Dialect/FIRType.cpp +++ b/flang/lib/Optimizer/Dialect/FIRType.cpp @@ -33,7 +33,7 @@ TYPE parseIntSingleton(mlir::DialectAsmParser &parser) { int kind = 0; if (parser.parseLess() || parser.parseInteger(kind) || parser.parseGreater()) return {}; - return TYPE::get(parser.getBuilder().getContext(), kind); + return TYPE::get(parser.getContext(), kind); } template @@ -117,8 +117,7 @@ mlir::Type fir::parseFirType(FIROpsDialect *dialect, if (parser.parseKeyword(&typeTag)) return {}; mlir::Type genType; - auto parseResult = generatedTypeParser(parser.getBuilder().getContext(), - parser, typeTag, genType); + auto parseResult = generatedTypeParser(parser, typeTag, genType); if (parseResult.hasValue()) return genType; parser.emitError(parser.getNameLoc(), "unknown fir type: ") << typeTag; @@ -259,12 +258,11 @@ bool fir::isa_unknown_size_box(mlir::Type t) { //===----------------------------------------------------------------------===// // `boxproc` `<` return-type `>` -mlir::Type BoxProcType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type BoxProcType::parse(mlir::DialectAsmParser &parser) { mlir::Type ty; if (parser.parseLess() || parser.parseType(ty) || parser.parseGreater()) return {}; - return get(context, ty); + return get(parser.getContext(), ty); } void fir::BoxProcType::print(mlir::DialectAsmPrinter &printer) const { @@ -293,8 +291,7 @@ static bool cannotBePointerOrHeapElementType(mlir::Type eleTy) { //===----------------------------------------------------------------------===// // `box` `<` type (',' affine-map)? `>` -mlir::Type fir::BoxType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::BoxType::parse(mlir::DialectAsmParser &parser) { mlir::Type ofTy; if (parser.parseLess() || parser.parseType(ofTy)) return {}; @@ -330,8 +327,7 @@ fir::BoxType::verify(llvm::function_ref emitError, // BoxCharType //===----------------------------------------------------------------------===// -mlir::Type fir::BoxCharType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::BoxCharType::parse(mlir::DialectAsmParser &parser) { return parseKindSingleton(parser); } @@ -353,8 +349,7 @@ CharacterType fir::BoxCharType::getEleTy() const { //===----------------------------------------------------------------------===// // `char` `<` kind [`,` `len`] `>` -mlir::Type fir::CharacterType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::CharacterType::parse(mlir::DialectAsmParser &parser) { int kind = 0; if (parser.parseLess() || parser.parseInteger(kind)) return {}; @@ -368,7 +363,7 @@ mlir::Type fir::CharacterType::parse(mlir::MLIRContext *context, } if (parser.parseGreater()) return {}; - return get(context, kind, len); + return get(parser.getContext(), kind, len); } void fir::CharacterType::print(mlir::DialectAsmPrinter &printer) const { @@ -388,8 +383,7 @@ void fir::CharacterType::print(mlir::DialectAsmPrinter &printer) const { // ComplexType //===----------------------------------------------------------------------===// -mlir::Type fir::ComplexType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::ComplexType::parse(mlir::DialectAsmParser &parser) { return parseKindSingleton(parser); } @@ -406,8 +400,7 @@ mlir::Type fir::ComplexType::getElementType() const { //===----------------------------------------------------------------------===// // `heap` `<` type `>` -mlir::Type fir::HeapType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::HeapType::parse(mlir::DialectAsmParser &parser) { return parseTypeSingleton(parser); } @@ -429,8 +422,7 @@ fir::HeapType::verify(llvm::function_ref emitError, //===----------------------------------------------------------------------===// // `int` `<` kind `>` -mlir::Type fir::IntegerType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::IntegerType::parse(mlir::DialectAsmParser &parser) { return parseKindSingleton(parser); } @@ -443,8 +435,7 @@ void fir::IntegerType::print(mlir::DialectAsmPrinter &printer) const { //===----------------------------------------------------------------------===// // `logical` `<` kind `>` -mlir::Type fir::LogicalType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::LogicalType::parse(mlir::DialectAsmParser &parser) { return parseKindSingleton(parser); } @@ -457,8 +448,7 @@ void fir::LogicalType::print(mlir::DialectAsmPrinter &printer) const { //===----------------------------------------------------------------------===// // `ptr` `<` type `>` -mlir::Type fir::PointerType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::PointerType::parse(mlir::DialectAsmParser &parser) { return parseTypeSingleton(parser); } @@ -479,8 +469,7 @@ mlir::LogicalResult fir::PointerType::verify( //===----------------------------------------------------------------------===// // `real` `<` kind `>` -mlir::Type fir::RealType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::RealType::parse(mlir::DialectAsmParser &parser) { return parseKindSingleton(parser); } @@ -503,12 +492,11 @@ fir::RealType::verify(llvm::function_ref emitError, // `type` `<` name // (`(` id `:` type (`,` id `:` type)* `)`)? // (`{` id `:` type (`,` id `:` type)* `}`)? '>' -mlir::Type fir::RecordType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::RecordType::parse(mlir::DialectAsmParser &parser) { llvm::StringRef name; if (parser.parseLess() || parser.parseKeyword(&name)) return {}; - RecordType result = RecordType::get(parser.getBuilder().getContext(), name); + RecordType result = RecordType::get(parser.getContext(), name); RecordType::TypeList lenParamList; if (!parser.parseOptionalLParen()) { @@ -631,8 +619,7 @@ unsigned fir::RecordType::getFieldIndex(llvm::StringRef ident) { //===----------------------------------------------------------------------===// // `ref` `<` type `>` -mlir::Type fir::ReferenceType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::ReferenceType::parse(mlir::DialectAsmParser &parser) { return parseTypeSingleton(parser); } @@ -655,8 +642,7 @@ mlir::LogicalResult fir::ReferenceType::verify( // `array` `<` `*` | bounds (`x` bounds)* `:` type (',' affine-map)? `>` // bounds ::= `?` | int-lit -mlir::Type fir::SequenceType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::SequenceType::parse(mlir::DialectAsmParser &parser) { if (parser.parseLess()) return {}; SequenceType::Shape shape; @@ -675,7 +661,7 @@ mlir::Type fir::SequenceType::parse(mlir::MLIRContext *context, parser.emitError(parser.getNameLoc(), "expecting affine map"); return {}; } - return SequenceType::get(context, shape, eleTy, map); + return SequenceType::get(parser.getContext(), shape, eleTy, map); } void fir::SequenceType::print(mlir::DialectAsmPrinter &printer) const { @@ -745,8 +731,7 @@ mlir::LogicalResult fir::SequenceType::verify( // ShapeType //===----------------------------------------------------------------------===// -mlir::Type fir::ShapeType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::ShapeType::parse(mlir::DialectAsmParser &parser) { return parseRankSingleton(parser); } @@ -758,8 +743,7 @@ void fir::ShapeType::print(mlir::DialectAsmPrinter &printer) const { // ShapeShiftType //===----------------------------------------------------------------------===// -mlir::Type fir::ShapeShiftType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::ShapeShiftType::parse(mlir::DialectAsmParser &parser) { return parseRankSingleton(parser); } @@ -771,8 +755,7 @@ void fir::ShapeShiftType::print(mlir::DialectAsmPrinter &printer) const { // ShiftType //===----------------------------------------------------------------------===// -mlir::Type fir::ShiftType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::ShiftType::parse(mlir::DialectAsmParser &parser) { return parseRankSingleton(parser); } @@ -785,8 +768,7 @@ void fir::ShiftType::print(mlir::DialectAsmPrinter &printer) const { //===----------------------------------------------------------------------===// // `slice` `<` rank `>` -mlir::Type fir::SliceType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::SliceType::parse(mlir::DialectAsmParser &parser) { return parseRankSingleton(parser); } @@ -799,8 +781,7 @@ void fir::SliceType::print(mlir::DialectAsmPrinter &printer) const { //===----------------------------------------------------------------------===// // `tdesc` `<` type `>` -mlir::Type fir::TypeDescType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::TypeDescType::parse(mlir::DialectAsmParser &parser) { return parseTypeSingleton(parser); } @@ -824,8 +805,7 @@ mlir::LogicalResult fir::TypeDescType::verify( //===----------------------------------------------------------------------===// // `vector` `<` len `:` type `>` -mlir::Type fir::VectorType::parse(mlir::MLIRContext *context, - mlir::DialectAsmParser &parser) { +mlir::Type fir::VectorType::parse(mlir::DialectAsmParser &parser) { int64_t len = 0; mlir::Type eleTy; if (parser.parseLess() || parser.parseInteger(len) || parser.parseColon() || diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h index ca6fc1b..a368a29 100644 --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/mlir/include/mlir/IR/OpImplementation.h @@ -18,7 +18,6 @@ #include "mlir/IR/OpDefinition.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/SMLoc.h" -#include "llvm/Support/raw_ostream.h" namespace mlir { @@ -323,6 +322,8 @@ public: AsmParser() = default; virtual ~AsmParser(); + MLIRContext *getContext() const; + /// Return the location of the original name token. virtual llvm::SMLoc getNameLoc() const = 0; diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp index 4e1cf4c..485cc5e 100644 --- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp +++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp @@ -3165,8 +3165,8 @@ static void deduplicateAndResolveOperands( uniqueOperands.push_back(operand); replacements.push_back( kind == AffineExprKind::DimId - ? getAffineDimExpr(pos, parser.getBuilder().getContext()) - : getAffineSymbolExpr(pos, parser.getBuilder().getContext())); + ? getAffineDimExpr(pos, parser.getContext()) + : getAffineSymbolExpr(pos, parser.getContext())); } } } @@ -3276,7 +3276,7 @@ static ParseResult parseAffineMapWithMinMax(OpAsmParser &parser, Builder &builder = parser.getBuilder(); auto flatMap = AffineMap::get(totalNumDims, totalNumSyms, flatExprs, - parser.getBuilder().getContext()); + parser.getContext()); flatMap = flatMap.replaceDimsAndSymbols( dimRplacements, symRepacements, dimOperands.size(), symOperands.size()); diff --git a/mlir/lib/Dialect/ArmSVE/IR/ArmSVEDialect.cpp b/mlir/lib/Dialect/ArmSVE/IR/ArmSVEDialect.cpp index 6a89c4e..64ffec0 100644 --- a/mlir/lib/Dialect/ArmSVE/IR/ArmSVEDialect.cpp +++ b/mlir/lib/Dialect/ArmSVE/IR/ArmSVEDialect.cpp @@ -55,8 +55,7 @@ Type ArmSVEDialect::parseType(DialectAsmParser &parser) const { llvm::SMLoc typeLoc = parser.getCurrentLocation(); { Type genType; - auto parseResult = generatedTypeParser(parser.getBuilder().getContext(), - parser, "vector", genType); + auto parseResult = generatedTypeParser(parser, "vector", genType); if (parseResult.hasValue()) return genType; } diff --git a/mlir/lib/Dialect/Async/IR/Async.cpp b/mlir/lib/Dialect/Async/IR/Async.cpp index d21ff1f..8728c4a 100644 --- a/mlir/lib/Dialect/Async/IR/Async.cpp +++ b/mlir/lib/Dialect/Async/IR/Async.cpp @@ -345,7 +345,7 @@ void ValueType::print(DialectAsmPrinter &printer) const { printer << '>'; } -Type ValueType::parse(mlir::MLIRContext *, mlir::DialectAsmParser &parser) { +Type ValueType::parse(mlir::DialectAsmParser &parser) { Type ty; if (parser.parseLess() || parser.parseType(ty) || parser.parseGreater()) { parser.emitError(parser.getNameLoc(), "failed to parse async value type"); @@ -366,8 +366,7 @@ Type AsyncDialect::parseType(DialectAsmParser &parser) const { if (parser.parseKeyword(&typeTag)) return Type(); Type genType; - auto parseResult = generatedTypeParser(parser.getBuilder().getContext(), - parser, typeTag, genType); + auto parseResult = generatedTypeParser(parser, typeTag, genType); if (parseResult.hasValue()) return genType; parser.emitError(parser.getNameLoc(), "unknown async type: ") << typeTag; diff --git a/mlir/lib/Dialect/DLTI/DLTI.cpp b/mlir/lib/Dialect/DLTI/DLTI.cpp index c6ae792..87fbe25 100644 --- a/mlir/lib/Dialect/DLTI/DLTI.cpp +++ b/mlir/lib/Dialect/DLTI/DLTI.cpp @@ -283,7 +283,7 @@ DataLayoutSpecAttr DataLayoutSpecAttr::parse(DialectAsmParser &parser) { // Empty spec. if (succeeded(parser.parseOptionalGreater())) - return get(parser.getBuilder().getContext(), {}); + return get(parser.getContext(), {}); SmallVector entries; do { @@ -295,7 +295,7 @@ DataLayoutSpecAttr DataLayoutSpecAttr::parse(DialectAsmParser &parser) { if (failed(parser.parseGreater())) return {}; return getChecked([&] { return parser.emitError(parser.getNameLoc()); }, - parser.getBuilder().getContext(), entries); + parser.getContext(), entries); } void DataLayoutSpecAttr::print(DialectAsmPrinter &os) const { diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp index 4350f6c..aaf1d49 100644 --- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp +++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp @@ -147,7 +147,7 @@ static ParseResult parseIncludeOp(OpAsmParser &parser, OperationState &result) { if (standardInclude) result.addAttribute("is_standard_include", - UnitAttr::get(parser.getBuilder().getContext())); + UnitAttr::get(parser.getContext())); return success(); } @@ -166,8 +166,7 @@ static ParseResult parseIncludeOp(OpAsmParser &parser, OperationState &result) { #define GET_ATTRDEF_CLASSES #include "mlir/Dialect/EmitC/IR/EmitCAttributes.cpp.inc" -Attribute emitc::OpaqueAttr::parse(MLIRContext *context, - DialectAsmParser &parser, Type type) { +Attribute emitc::OpaqueAttr::parse(DialectAsmParser &parser, Type type) { if (parser.parseLess()) return Attribute(); std::string value; @@ -178,7 +177,7 @@ Attribute emitc::OpaqueAttr::parse(MLIRContext *context, } if (parser.parseGreater()) return Attribute(); - return get(context, value); + return get(parser.getContext(), value); } Attribute EmitCDialect::parseAttribute(DialectAsmParser &parser, @@ -189,7 +188,7 @@ Attribute EmitCDialect::parseAttribute(DialectAsmParser &parser, return Attribute(); Attribute genAttr; OptionalParseResult parseResult = - generatedAttributeParser(getContext(), parser, mnemonic, type, genAttr); + generatedAttributeParser(parser, mnemonic, type, genAttr); if (parseResult.hasValue()) return genAttr; parser.emitError(typeLoc, "unknown attribute in EmitC dialect"); @@ -214,7 +213,7 @@ void emitc::OpaqueAttr::print(DialectAsmPrinter &printer) const { #define GET_TYPEDEF_CLASSES #include "mlir/Dialect/EmitC/IR/EmitCTypes.cpp.inc" -Type emitc::OpaqueType::parse(MLIRContext *context, DialectAsmParser &parser) { +Type emitc::OpaqueType::parse(DialectAsmParser &parser) { if (parser.parseLess()) return Type(); std::string value; @@ -225,7 +224,7 @@ Type emitc::OpaqueType::parse(MLIRContext *context, DialectAsmParser &parser) { } if (parser.parseGreater()) return Type(); - return get(context, value); + return get(parser.getContext(), value); } Type EmitCDialect::parseType(DialectAsmParser &parser) const { @@ -235,7 +234,7 @@ Type EmitCDialect::parseType(DialectAsmParser &parser) const { return Type(); Type genType; OptionalParseResult parseResult = - generatedTypeParser(getContext(), parser, mnemonic, genType); + generatedTypeParser(parser, mnemonic, genType); if (parseResult.hasValue()) return genType; parser.emitError(typeLoc, "unknown type in EmitC dialect"); diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp index 18eec0e..2b5259b 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -1491,7 +1491,7 @@ static RetTy parseOptionalLLVMKeyword(OpAsmParser &parser, // The type can be omitted for string attributes, in which case it will be // inferred from the value of the string as [strlen(value) x i8]. static ParseResult parseGlobalOp(OpAsmParser &parser, OperationState &result) { - MLIRContext *ctx = parser.getBuilder().getContext(); + MLIRContext *ctx = parser.getContext(); // Parse optional linkage, default to External. result.addAttribute(getLinkageAttrName(), LLVM::LinkageAttr::get( @@ -1530,7 +1530,7 @@ static ParseResult parseGlobalOp(OpAsmParser &parser, OperationState &result) { Region &initRegion = *result.addRegion(); if (types.empty()) { if (auto strAttr = value.dyn_cast_or_null()) { - MLIRContext *context = parser.getBuilder().getContext(); + MLIRContext *context = parser.getContext(); auto arrayType = LLVM::LLVMArrayType::get(IntegerType::get(context, 8), strAttr.getValue().size()); types.push_back(arrayType); @@ -1759,7 +1759,7 @@ static ParseResult parseLLVMFuncOp(OpAsmParser &parser, // Default to external linkage if no keyword is provided. result.addAttribute( getLinkageAttrName(), - LinkageAttr::get(parser.getBuilder().getContext(), + LinkageAttr::get(parser.getContext(), parseOptionalLLVMKeyword( parser, result, LLVM::Linkage::External))); @@ -2374,8 +2374,7 @@ void FMFAttr::print(DialectAsmPrinter &printer) const { printer << ">"; } -Attribute FMFAttr::parse(MLIRContext *context, DialectAsmParser &parser, - Type type) { +Attribute FMFAttr::parse(DialectAsmParser &parser, Type type) { if (failed(parser.parseLess())) return {}; @@ -2400,7 +2399,7 @@ Attribute FMFAttr::parse(MLIRContext *context, DialectAsmParser &parser, return {}; } - return FMFAttr::get(parser.getBuilder().getContext(), flags); + return FMFAttr::get(parser.getContext(), flags); } void LinkageAttr::print(DialectAsmPrinter &printer) const { @@ -2412,8 +2411,7 @@ void LinkageAttr::print(DialectAsmPrinter &printer) const { printer << ">"; } -Attribute LinkageAttr::parse(MLIRContext *context, DialectAsmParser &parser, - Type type) { +Attribute LinkageAttr::parse(DialectAsmParser &parser, Type type) { StringRef elemName; if (parser.parseLess() || parser.parseKeyword(&elemName) || parser.parseGreater()) @@ -2424,7 +2422,7 @@ Attribute LinkageAttr::parse(MLIRContext *context, DialectAsmParser &parser, return {}; } Linkage linkage = *elem; - return LinkageAttr::get(context, linkage); + return LinkageAttr::get(parser.getContext(), linkage); } LoopOptionsAttrBuilder::LoopOptionsAttrBuilder(LoopOptionsAttr attr) @@ -2539,8 +2537,7 @@ void LoopOptionsAttr::print(DialectAsmPrinter &printer) const { printer << ">"; } -Attribute LoopOptionsAttr::parse(MLIRContext *context, DialectAsmParser &parser, - Type type) { +Attribute LoopOptionsAttr::parse(DialectAsmParser &parser, Type type) { if (failed(parser.parseLess())) return {}; @@ -2593,7 +2590,7 @@ Attribute LoopOptionsAttr::parse(MLIRContext *context, DialectAsmParser &parser, return {}; llvm::sort(options, llvm::less_first()); - return get(parser.getBuilder().getContext(), options); + return get(parser.getContext(), options); } Attribute LLVMDialect::parseAttribute(DialectAsmParser &parser, @@ -2607,8 +2604,7 @@ Attribute LLVMDialect::parseAttribute(DialectAsmParser &parser, return {}; { Attribute attr; - auto parseResult = - generatedAttributeParser(getContext(), parser, attrKind, type, attr); + auto parseResult = generatedAttributeParser(parser, attrKind, type, attr); if (parseResult.hasValue()) return attr; } diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp index acf0328..312f686 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp @@ -438,7 +438,7 @@ static Type dispatchParse(DialectAsmParser &parser, bool allowAny = true) { if (failed(parser.parseKeyword(&key))) return Type(); - MLIRContext *ctx = parser.getBuilder().getContext(); + MLIRContext *ctx = parser.getContext(); return StringSwitch>(key) .Case("void", [&] { return LLVMVoidType::get(ctx); }) .Case("ppc_fp128", [&] { return LLVMPPCFP128Type::get(ctx); }) diff --git a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp index 9420d60..6cf166f 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp @@ -64,7 +64,7 @@ static ParseResult parseNVVMShflSyncBflyOp(OpAsmParser &parser, break; } - auto int32Ty = IntegerType::get(parser.getBuilder().getContext(), 32); + auto int32Ty = IntegerType::get(parser.getContext(), 32); return parser.resolveOperands(ops, {int32Ty, resultType, int32Ty, int32Ty}, parser.getNameLoc(), result.operands); } @@ -72,7 +72,7 @@ static ParseResult parseNVVMShflSyncBflyOp(OpAsmParser &parser, // ::= `llvm.nvvm.vote.ballot.sync %mask, %pred` : result_type static ParseResult parseNVVMVoteBallotOp(OpAsmParser &parser, OperationState &result) { - MLIRContext *context = parser.getBuilder().getContext(); + MLIRContext *context = parser.getContext(); auto int32Ty = IntegerType::get(context, 32); auto int1Ty = IntegerType::get(context, 1); diff --git a/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp index fcce890..7f145b3 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp @@ -47,7 +47,7 @@ static ParseResult parseROCDLMubufLoadOp(OpAsmParser &parser, parser.addTypeToList(type, result.types)) return failure(); - MLIRContext *context = parser.getBuilder().getContext(); + MLIRContext *context = parser.getContext(); auto int32Ty = IntegerType::get(context, 32); auto int1Ty = IntegerType::get(context, 1); auto i32x4Ty = LLVM::getFixedVectorType(int32Ty, 4); @@ -66,7 +66,7 @@ static ParseResult parseROCDLMubufStoreOp(OpAsmParser &parser, if (parser.parseOperandList(ops, 6) || parser.parseColonType(type)) return failure(); - MLIRContext *context = parser.getBuilder().getContext(); + MLIRContext *context = parser.getContext(); auto int32Ty = IntegerType::get(context, 32); auto int1Ty = IntegerType::get(context, 1); auto i32x4Ty = LLVM::getFixedVectorType(int32Ty, 4); diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp index 7dd6bd9..a1cded4 100644 --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -375,7 +375,7 @@ void CopyOp::build(OpBuilder &builder, OperationState &result, Value input, ParseResult parseCopyOpRegion(OpAsmParser &parser, Region &r, Type inputType, Type outputType) { - OpBuilder opBuilder(parser.getBuilder().getContext()); + OpBuilder opBuilder(parser.getContext()); fillStructuredOpRegion(opBuilder, r, TypeRange{inputType}, TypeRange{outputType}); return success(); @@ -470,7 +470,7 @@ void FillOp::build(OpBuilder &builder, OperationState &result, Value value, ParseResult parseFillOpRegion(OpAsmParser &parser, Region &r, Type valueType, Type outputType) { - OpBuilder opBuilder(parser.getBuilder().getContext()); + OpBuilder opBuilder(parser.getContext()); fillStructuredOpRegion(opBuilder, r, TypeRange{valueType}, TypeRange{outputType}); return success(); @@ -2934,7 +2934,7 @@ static ParseResult parseNamedStructuredOpRegion(OpAsmParser &parser, Region ®ion, TypeRange inputTypes, TypeRange outputTypes) { ParseResult res = success(); - OpBuilder opBuilder(parser.getBuilder().getContext()); + OpBuilder opBuilder(parser.getContext()); // Resolve `captures` into `capturedValues` at parse time so we can build the // region with captures. SmallVector capturedValues; diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp index 5c588c35..2908e6b 100644 --- a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp +++ b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp @@ -1137,7 +1137,7 @@ parseGlobalMemrefOpTypeAndInitialValue(OpAsmParser &parser, TypeAttr &typeAttr, return success(); if (succeeded(parser.parseOptionalKeyword("uninitialized"))) { - initialValue = UnitAttr::get(parser.getBuilder().getContext()); + initialValue = UnitAttr::get(parser.getContext()); return success(); } diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp index 94be8c2..35754f1 100644 --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -595,7 +595,7 @@ static ParseResult parseWsLoopOp(OpAsmParser &parser, OperationState &result) { return failure(); result.addAttribute("collapse_val", attr); } else if (keyword == "nowait") { - auto attr = UnitAttr::get(parser.getBuilder().getContext()); + auto attr = UnitAttr::get(parser.getContext()); result.addAttribute("nowait", attr); } else if (keyword == "ordered") { mlir::IntegerAttr attr; @@ -618,7 +618,7 @@ static ParseResult parseWsLoopOp(OpAsmParser &parser, OperationState &result) { auto attr = parser.getBuilder().getStringAttr(order); result.addAttribute("order", attr); } else if (keyword == "inclusive") { - auto attr = UnitAttr::get(parser.getBuilder().getContext()); + auto attr = UnitAttr::get(parser.getContext()); result.addAttribute("inclusive", attr); } else if (keyword == "reduction") { if (segments[reductionVarPos]) diff --git a/mlir/lib/Dialect/PDL/IR/PDLTypes.cpp b/mlir/lib/Dialect/PDL/IR/PDLTypes.cpp index 20f013a..956b075 100644 --- a/mlir/lib/Dialect/PDL/IR/PDLTypes.cpp +++ b/mlir/lib/Dialect/PDL/IR/PDLTypes.cpp @@ -39,8 +39,7 @@ static Type parsePDLType(DialectAsmParser &parser) { return Type(); { Type genType; - auto parseResult = generatedTypeParser(parser.getBuilder().getContext(), - parser, typeTag, genType); + auto parseResult = generatedTypeParser(parser, typeTag, genType); if (parseResult.hasValue()) return genType; } @@ -75,7 +74,7 @@ bool PDLType::classof(Type type) { // RangeType //===----------------------------------------------------------------------===// -Type RangeType::parse(MLIRContext *context, DialectAsmParser &parser) { +Type RangeType::parse(DialectAsmParser &parser) { if (parser.parseLess()) return Type(); diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp index 900251f..898d063 100644 --- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp @@ -321,8 +321,7 @@ static ParseResult parseImageOperands(OpAsmParser &parser, if (parseEnumStrAttr(imageOperands, parser)) return failure(); - attr = spirv::ImageOperandsAttr::get(parser.getBuilder().getContext(), - imageOperands); + attr = spirv::ImageOperandsAttr::get(parser.getContext(), imageOperands); return parser.parseRSquare(); } @@ -3590,7 +3589,7 @@ static ParseResult parseSpecConstantOperationOp(OpAsmParser &parser, if (!wrappedOp) return failure(); - OpBuilder builder(parser.getBuilder().getContext()); + OpBuilder builder(parser.getContext()); builder.setInsertionPointToEnd(&block); builder.create(wrappedOp->getLoc(), wrappedOp->getResult(0)); state.location = wrappedOp->getLoc(); diff --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp index a25a4b7..4e63f57 100644 --- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp +++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp @@ -38,8 +38,7 @@ static bool acceptBitWidth(unsigned bitWidth) { } } -Attribute SparseTensorEncodingAttr::parse(MLIRContext *context, - DialectAsmParser &parser, Type type) { +Attribute SparseTensorEncodingAttr::parse(DialectAsmParser &parser, Type type) { if (failed(parser.parseLess())) return {}; // Parse the data as a dictionary. @@ -113,8 +112,8 @@ Attribute SparseTensorEncodingAttr::parse(MLIRContext *context, } } // Construct struct-like storage for attribute. - return parser.getChecked(context, dlt, map, ptr, - ind); + return parser.getChecked(parser.getContext(), dlt, + map, ptr, ind); } void SparseTensorEncodingAttr::print(DialectAsmPrinter &printer) const { @@ -298,8 +297,7 @@ Attribute SparseTensorDialect::parseAttribute(DialectAsmParser &parser, if (failed(parser.parseKeyword(&attrTag))) return Attribute(); Attribute attr; - auto parseResult = - generatedAttributeParser(getContext(), parser, attrTag, type, attr); + auto parseResult = generatedAttributeParser(parser, attrTag, type, attr); if (parseResult.hasValue()) return attr; parser.emitError(parser.getNameLoc(), "unknown sparse tensor attribute"); diff --git a/mlir/lib/Dialect/Vector/VectorOps.cpp b/mlir/lib/Dialect/Vector/VectorOps.cpp index 4ce8011..4857beb 100644 --- a/mlir/lib/Dialect/Vector/VectorOps.cpp +++ b/mlir/lib/Dialect/Vector/VectorOps.cpp @@ -187,8 +187,7 @@ Attribute CombiningKindAttr::parse(DialectAsmParser &parser) { if (failed(parser.parseGreater())) return {}; - return CombiningKindAttr::get(kind.getValue(), - parser.getBuilder().getContext()); + return CombiningKindAttr::get(kind.getValue(), parser.getContext()); } Attribute VectorDialect::parseAttribute(DialectAsmParser &parser, diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index 881892d..fe9348a 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -1093,6 +1093,8 @@ Operation *OperationParser::parseGenericOperation(Block *insertBlock, return op; } +MLIRContext *AsmParser::getContext() const { return getBuilder().getContext(); } + namespace { class CustomOpAsmParser : public AsmParserImpl { public: diff --git a/mlir/test/lib/Dialect/Test/TestAttributes.cpp b/mlir/test/lib/Dialect/Test/TestAttributes.cpp index 3cc2c81..29b7023 100644 --- a/mlir/test/lib/Dialect/Test/TestAttributes.cpp +++ b/mlir/test/lib/Dialect/Test/TestAttributes.cpp @@ -27,13 +27,12 @@ using namespace test; // AttrWithSelfTypeParamAttr //===----------------------------------------------------------------------===// -Attribute AttrWithSelfTypeParamAttr::parse(MLIRContext *context, - DialectAsmParser &parser, +Attribute AttrWithSelfTypeParamAttr::parse(DialectAsmParser &parser, Type type) { Type selfType; if (parser.parseType(selfType)) return Attribute(); - return get(context, selfType); + return get(parser.getContext(), selfType); } void AttrWithSelfTypeParamAttr::print(DialectAsmPrinter &printer) const { @@ -44,12 +43,11 @@ void AttrWithSelfTypeParamAttr::print(DialectAsmPrinter &printer) const { // AttrWithTypeBuilderAttr //===----------------------------------------------------------------------===// -Attribute AttrWithTypeBuilderAttr::parse(MLIRContext *context, - DialectAsmParser &parser, Type type) { +Attribute AttrWithTypeBuilderAttr::parse(DialectAsmParser &parser, Type type) { IntegerAttr element; if (parser.parseAttribute(element)) return Attribute(); - return get(context, element); + return get(parser.getContext(), element); } void AttrWithTypeBuilderAttr::print(DialectAsmPrinter &printer) const { @@ -60,8 +58,7 @@ void AttrWithTypeBuilderAttr::print(DialectAsmPrinter &printer) const { // CompoundAAttr //===----------------------------------------------------------------------===// -Attribute CompoundAAttr::parse(MLIRContext *context, DialectAsmParser &parser, - Type type) { +Attribute CompoundAAttr::parse(DialectAsmParser &parser, Type type) { int widthOfSomething; Type oneType; SmallVector arrayOfInts; @@ -79,7 +76,7 @@ Attribute CompoundAAttr::parse(MLIRContext *context, DialectAsmParser &parser, if (parser.parseRSquare() || parser.parseGreater()) return Attribute(); - return get(context, widthOfSomething, oneType, arrayOfInts); + return get(parser.getContext(), widthOfSomething, oneType, arrayOfInts); } void CompoundAAttr::print(DialectAsmPrinter &printer) const { @@ -93,8 +90,7 @@ void CompoundAAttr::print(DialectAsmPrinter &printer) const { // CompoundAAttr //===----------------------------------------------------------------------===// -Attribute TestI64ElementsAttr::parse(MLIRContext *context, - DialectAsmParser &parser, Type type) { +Attribute TestI64ElementsAttr::parse(DialectAsmParser &parser, Type type) { SmallVector elements; if (parser.parseLess() || parser.parseLSquare()) return Attribute(); @@ -108,7 +104,7 @@ Attribute TestI64ElementsAttr::parse(MLIRContext *context, if (parser.parseRSquare() || parser.parseGreater()) return Attribute(); return parser.getChecked( - context, type.cast(), elements); + parser.getContext(), type.cast(), elements); } void TestI64ElementsAttr::print(DialectAsmPrinter &printer) const { @@ -158,8 +154,7 @@ Attribute TestDialect::parseAttribute(DialectAsmParser &parser, return Attribute(); { Attribute attr; - auto parseResult = - generatedAttributeParser(getContext(), parser, attrTag, type, attr); + auto parseResult = generatedAttributeParser(parser, attrTag, type, attr); if (parseResult.hasValue()) return attr; } diff --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp index 5fc3bdb..a0f8845 100644 --- a/mlir/test/lib/Dialect/Test/TestDialect.cpp +++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp @@ -691,7 +691,7 @@ static ParseResult parseWrappingRegionOp(OpAsmParser &parser, // Create a return terminator in the inner region, pass as operand to the // terminator the returned values from the wrapped operation. SmallVector return_operands(wrapped_op->getResults()); - OpBuilder builder(parser.getBuilder().getContext()); + OpBuilder builder(parser.getContext()); builder.setInsertionPointToEnd(&block); builder.create(wrapped_op->getLoc(), return_operands); diff --git a/mlir/test/lib/Dialect/Test/TestTypes.cpp b/mlir/test/lib/Dialect/Test/TestTypes.cpp index 960fbbb..9d618ce 100644 --- a/mlir/test/lib/Dialect/Test/TestTypes.cpp +++ b/mlir/test/lib/Dialect/Test/TestTypes.cpp @@ -88,7 +88,7 @@ static llvm::hash_code test::hash_value(const FieldInfo &fi) { // NOLINT // CompoundAType //===----------------------------------------------------------------------===// -Type CompoundAType::parse(MLIRContext *ctxt, DialectAsmParser &parser) { +Type CompoundAType::parse(DialectAsmParser &parser) { int widthOfSomething; Type oneType; SmallVector arrayOfInts; @@ -107,7 +107,7 @@ Type CompoundAType::parse(MLIRContext *ctxt, DialectAsmParser &parser) { if (parser.parseRSquare() || parser.parseGreater()) return Type(); - return get(ctxt, widthOfSomething, oneType, arrayOfInts); + return get(parser.getContext(), widthOfSomething, oneType, arrayOfInts); } void CompoundAType::print(DialectAsmPrinter &printer) const { printer << "cmpnd_a<" << getWidthOfSomething() << ", " << getOneType() @@ -143,11 +143,11 @@ void TestType::printTypeC(Location loc) const { // TestTypeWithLayout //===----------------------------------------------------------------------===// -Type TestTypeWithLayoutType::parse(MLIRContext *ctx, DialectAsmParser &parser) { +Type TestTypeWithLayoutType::parse(DialectAsmParser &parser) { unsigned val; if (parser.parseLess() || parser.parseInteger(val) || parser.parseGreater()) return Type(); - return TestTypeWithLayoutType::get(ctx, val); + return TestTypeWithLayoutType::get(parser.getContext(), val); } void TestTypeWithLayoutType::print(DialectAsmPrinter &printer) const { @@ -236,15 +236,14 @@ void TestDialect::registerTypes() { SimpleAType::attachInterface(*getContext()); } -static Type parseTestType(MLIRContext *ctxt, DialectAsmParser &parser, - SetVector &stack) { +static Type parseTestType(DialectAsmParser &parser, SetVector &stack) { StringRef typeTag; if (failed(parser.parseKeyword(&typeTag))) return Type(); { Type genType; - auto parseResult = generatedTypeParser(ctxt, parser, typeTag, genType); + auto parseResult = generatedTypeParser(parser, typeTag, genType); if (parseResult.hasValue()) return genType; } @@ -257,7 +256,7 @@ static Type parseTestType(MLIRContext *ctxt, DialectAsmParser &parser, StringRef name; if (parser.parseLess() || parser.parseKeyword(&name)) return Type(); - auto rec = TestRecursiveType::get(parser.getBuilder().getContext(), name); + auto rec = TestRecursiveType::get(parser.getContext(), name); // If this type already has been parsed above in the stack, expect just the // name. @@ -271,7 +270,7 @@ static Type parseTestType(MLIRContext *ctxt, DialectAsmParser &parser, if (failed(parser.parseComma())) return Type(); stack.insert(rec); - Type subtype = parseTestType(ctxt, parser, stack); + Type subtype = parseTestType(parser, stack); stack.pop_back(); if (!subtype || failed(parser.parseGreater()) || failed(rec.setBody(subtype))) return Type(); @@ -281,7 +280,7 @@ static Type parseTestType(MLIRContext *ctxt, DialectAsmParser &parser, Type TestDialect::parseType(DialectAsmParser &parser) const { SetVector stack; - return parseTestType(getContext(), parser, stack); + return parseTestType(parser, stack); } static void printTestType(Type type, DialectAsmPrinter &printer, diff --git a/mlir/test/mlir-tblgen/attrdefs.td b/mlir/test/mlir-tblgen/attrdefs.td index 7954fe3..cb0cc72 100644 --- a/mlir/test/mlir-tblgen/attrdefs.td +++ b/mlir/test/mlir-tblgen/attrdefs.td @@ -18,16 +18,16 @@ include "mlir/IR/OpBase.td" // DEF: ::test::IndexAttr, // DEF: ::test::SingleParameterAttr -// DEF-LABEL: ::mlir::OptionalParseResult generatedAttributeParser(::mlir::MLIRContext *context, +// DEF-LABEL: ::mlir::OptionalParseResult generatedAttributeParser( // DEF-NEXT: ::mlir::DialectAsmParser &parser, // DEF-NEXT: ::llvm::StringRef mnemonic, ::mlir::Type type, // DEF-NEXT: ::mlir::Attribute &value) { // DEF: if (mnemonic == ::test::CompoundAAttr::getMnemonic()) { -// DEF-NEXT: value = ::test::CompoundAAttr::parse(context, parser, type); +// DEF-NEXT: value = ::test::CompoundAAttr::parse(parser, type); // DEF-NEXT: return ::mlir::success(!!value); // DEF-NEXT: } // DEF-NEXT: if (mnemonic == ::test::IndexAttr::getMnemonic()) { -// DEF-NEXT: value = ::test::IndexAttr::parse(context, parser, type); +// DEF-NEXT: value = ::test::IndexAttr::parse(parser, type); // DEF-NEXT: return ::mlir::success(!!value); // DEF: return {}; @@ -66,8 +66,8 @@ def B_CompoundAttrA : TestAttr<"CompoundA"> { // DECL: static constexpr ::llvm::StringLiteral getMnemonic() { // DECL: return ::llvm::StringLiteral("cmpnd_a"); // DECL: } -// DECL: static ::mlir::Attribute parse(::mlir::MLIRContext *context, -// DECL-NEXT: ::mlir::DialectAsmParser &parser, ::mlir::Type type); +// DECL: static ::mlir::Attribute parse( +// DECL-SAME: ::mlir::DialectAsmParser &parser, ::mlir::Type type); // DECL: void print(::mlir::DialectAsmPrinter &printer) const; // DECL: int getWidthOfSomething() const; // DECL: ::test::SimpleTypeA getExampleTdType() const; @@ -110,8 +110,8 @@ def C_IndexAttr : TestAttr<"Index"> { // DECL: static constexpr ::llvm::StringLiteral getMnemonic() { // DECL: return ::llvm::StringLiteral("index"); // DECL: } -// DECL: static ::mlir::Attribute parse(::mlir::MLIRContext *context, -// DECL-NEXT: ::mlir::DialectAsmParser &parser, ::mlir::Type type); +// DECL: static ::mlir::Attribute parse( +// DECL-SAME: ::mlir::DialectAsmParser &parser, ::mlir::Type type); // DECL: void print(::mlir::DialectAsmPrinter &printer) const; } diff --git a/mlir/test/mlir-tblgen/typedefs.td b/mlir/test/mlir-tblgen/typedefs.td index cffc0ec..766d938 100644 --- a/mlir/test/mlir-tblgen/typedefs.td +++ b/mlir/test/mlir-tblgen/typedefs.td @@ -19,16 +19,16 @@ include "mlir/IR/OpBase.td" // DEF: ::test::SingleParameterType, // DEF: ::test::IntegerType -// DEF-LABEL: ::mlir::OptionalParseResult generatedTypeParser(::mlir::MLIRContext *context, +// DEF-LABEL: ::mlir::OptionalParseResult generatedTypeParser( // DEF-NEXT: ::mlir::DialectAsmParser &parser, // DEF-NEXT: ::llvm::StringRef mnemonic, // DEF-NEXT: ::mlir::Type &value) { // DEF: if (mnemonic == ::test::CompoundAType::getMnemonic()) { -// DEF-NEXT: value = ::test::CompoundAType::parse(context, parser); +// DEF-NEXT: value = ::test::CompoundAType::parse(parser); // DEF-NEXT: return ::mlir::success(!!value); // DEF-NEXT: } // DEF-NEXT: if (mnemonic == ::test::IndexType::getMnemonic()) { -// DEF-NEXT: value = ::test::IndexType::parse(context, parser); +// DEF-NEXT: value = ::test::IndexType::parse(parser); // DEF-NEXT: return ::mlir::success(!!value); // DEF: return {}; @@ -71,8 +71,7 @@ def B_CompoundTypeA : TestType<"CompoundA"> { // DECL: static constexpr ::llvm::StringLiteral getMnemonic() { // DECL: return ::llvm::StringLiteral("cmpnd_a"); // DECL: } -// DECL: static ::mlir::Type parse(::mlir::MLIRContext *context, -// DECL-NEXT: ::mlir::DialectAsmParser &parser); +// DECL: static ::mlir::Type parse(::mlir::DialectAsmParser &parser); // DECL: void print(::mlir::DialectAsmPrinter &printer) const; // DECL: int getWidthOfSomething() const; // DECL: ::test::SimpleTypeA getExampleTdType() const; @@ -91,8 +90,7 @@ def C_IndexType : TestType<"Index"> { // DECL: static constexpr ::llvm::StringLiteral getMnemonic() { // DECL: return ::llvm::StringLiteral("index"); // DECL: } -// DECL: static ::mlir::Type parse(::mlir::MLIRContext *context, -// DECL-NEXT: ::mlir::DialectAsmParser &parser); +// DECL: static ::mlir::Type parse(::mlir::DialectAsmParser &parser); // DECL: void print(::mlir::DialectAsmPrinter &printer) const; } diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp index d254d78..a1b0836 100644 --- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp +++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp @@ -244,8 +244,7 @@ static const char *const defDeclParametricBeginStr = R"( /// {0}: The name of the base value type, e.g. Attribute or Type. /// {1}: Extra parser parameters. static const char *const defDeclParsePrintStr = R"( - static ::mlir::{0} parse(::mlir::MLIRContext *context, - ::mlir::DialectAsmParser &parser{1}); + static ::mlir::{0} parse(::mlir::DialectAsmParser &parser{1}); void print(::mlir::DialectAsmPrinter &printer) const; )"; @@ -484,7 +483,7 @@ void DefGenerator::emitTypeDefList(ArrayRef defs) { /// {0}: The name of the base value type, e.g. Attribute or Type. /// {1}: Additional parser parameters. static const char *const defParserDispatchStartStr = R"( -static ::mlir::OptionalParseResult generated{0}Parser(::mlir::MLIRContext *context, +static ::mlir::OptionalParseResult generated{0}Parser( ::mlir::DialectAsmParser &parser, ::llvm::StringRef mnemonic{1}, ::mlir::{0} &value) {{ @@ -720,10 +719,11 @@ void DefGenerator::emitParsePrint(const AttrOrTypeDef &def) { // Emit the parser code, if specified. if (Optional parserCode = def.getParserCode()) { FmtContext fmtCtxt; - fmtCtxt.addSubst("_parser", "parser").addSubst("_ctxt", "context"); + fmtCtxt.addSubst("_parser", "parser") + .addSubst("_ctxt", "parser.getContext()"); // The mnenomic must be defined so the dispatcher knows how to dispatch. - os << llvm::formatv("::mlir::{0} {1}::parse(::mlir::MLIRContext *context, " + os << llvm::formatv("::mlir::{0} {1}::parse(" "::mlir::DialectAsmParser &parser", valueType, def.getCppClassName()); if (isAttrGenerator) { @@ -894,11 +894,12 @@ void DefGenerator::emitParsePrintDispatch(ArrayRef defs) { // If the def has no parameters and no parser code, just invoke a normal // `get`. if (def.getNumParameters() == 0 && !def.getParserCode()) { - os << "get(context);\n return ::mlir::success(!!value);\n }\n"; + os << "get(parser.getContext());\n"; + os << " return ::mlir::success(!!value);\n }\n"; continue; } - os << "parse(context, parser" << (isAttrGenerator ? ", type" : "") + os << "parse(parser" << (isAttrGenerator ? ", type" : "") << ");\n return ::mlir::success(!!value);\n }\n"; } } diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp index ad35217..bffd161 100644 --- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp +++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp @@ -1416,7 +1416,7 @@ void OperationFormat::genParserTypeResolution(Operator &op, } else if (const NamedTypeConstraint *var = resolver.getVariable()) { if (Optional tform = resolver.getVarTransformer()) { FmtContext fmtContext; - fmtContext.addSubst("_ctxt", "parser.getBuilder().getContext()"); + fmtContext.addSubst("_ctxt", "parser.getContext()"); if (var->isVariadic()) fmtContext.withSelf(var->name + "Types"); else diff --git a/mlir/unittests/Interfaces/DataLayoutInterfacesTest.cpp b/mlir/unittests/Interfaces/DataLayoutInterfacesTest.cpp index ebf3153..90f8e76 100644 --- a/mlir/unittests/Interfaces/DataLayoutInterfacesTest.cpp +++ b/mlir/unittests/Interfaces/DataLayoutInterfacesTest.cpp @@ -197,7 +197,7 @@ struct DLTestDialect : Dialect { (void)ok; assert(ok); if (succeeded(parser.parseOptionalGreater())) - return CustomDataLayoutSpec::get(parser.getBuilder().getContext(), {}); + return CustomDataLayoutSpec::get(parser.getContext(), {}); SmallVector entries; do { @@ -207,7 +207,7 @@ struct DLTestDialect : Dialect { } while (succeeded(parser.parseOptionalComma())); ok = succeeded(parser.parseGreater()); assert(ok); - return CustomDataLayoutSpec::get(parser.getBuilder().getContext(), entries); + return CustomDataLayoutSpec::get(parser.getContext(), entries); } void printType(Type type, DialectAsmPrinter &printer) const override { @@ -221,7 +221,7 @@ struct DLTestDialect : Dialect { bool ok = succeeded(parser.parseKeyword("single_query")); (void)ok; assert(ok); - return SingleQueryType::get(parser.getBuilder().getContext()); + return SingleQueryType::get(parser.getContext()); } }; -- 2.7.4