diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp index fb3fba663bab..2030e0b66999 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.getContext(), kind); + return TYPE::get(parser.getBuilder().getContext(), kind); } template @@ -117,7 +117,8 @@ mlir::Type fir::parseFirType(FIROpsDialect *dialect, if (parser.parseKeyword(&typeTag)) return {}; mlir::Type genType; - auto parseResult = generatedTypeParser(parser, typeTag, genType); + auto parseResult = generatedTypeParser(parser.getBuilder().getContext(), + parser, typeTag, genType); if (parseResult.hasValue()) return genType; parser.emitError(parser.getNameLoc(), "unknown fir type: ") << typeTag; @@ -258,11 +259,12 @@ bool fir::isa_unknown_size_box(mlir::Type t) { //===----------------------------------------------------------------------===// // `boxproc` `<` return-type `>` -mlir::Type BoxProcType::parse(mlir::DialectAsmParser &parser) { +mlir::Type BoxProcType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { mlir::Type ty; if (parser.parseLess() || parser.parseType(ty) || parser.parseGreater()) return {}; - return get(parser.getContext(), ty); + return get(context, ty); } void fir::BoxProcType::print(mlir::DialectAsmPrinter &printer) const { @@ -291,7 +293,8 @@ static bool cannotBePointerOrHeapElementType(mlir::Type eleTy) { //===----------------------------------------------------------------------===// // `box` `<` type (',' affine-map)? `>` -mlir::Type fir::BoxType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::BoxType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { mlir::Type ofTy; if (parser.parseLess() || parser.parseType(ofTy)) return {}; @@ -327,7 +330,8 @@ fir::BoxType::verify(llvm::function_ref emitError, // BoxCharType //===----------------------------------------------------------------------===// -mlir::Type fir::BoxCharType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::BoxCharType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { return parseKindSingleton(parser); } @@ -349,7 +353,8 @@ CharacterType fir::BoxCharType::getEleTy() const { //===----------------------------------------------------------------------===// // `char` `<` kind [`,` `len`] `>` -mlir::Type fir::CharacterType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::CharacterType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { int kind = 0; if (parser.parseLess() || parser.parseInteger(kind)) return {}; @@ -363,7 +368,7 @@ mlir::Type fir::CharacterType::parse(mlir::DialectAsmParser &parser) { } if (parser.parseGreater()) return {}; - return get(parser.getContext(), kind, len); + return get(context, kind, len); } void fir::CharacterType::print(mlir::DialectAsmPrinter &printer) const { @@ -383,7 +388,8 @@ void fir::CharacterType::print(mlir::DialectAsmPrinter &printer) const { // ComplexType //===----------------------------------------------------------------------===// -mlir::Type fir::ComplexType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::ComplexType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { return parseKindSingleton(parser); } @@ -400,7 +406,8 @@ mlir::Type fir::ComplexType::getElementType() const { //===----------------------------------------------------------------------===// // `heap` `<` type `>` -mlir::Type fir::HeapType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::HeapType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { return parseTypeSingleton(parser); } @@ -422,7 +429,8 @@ fir::HeapType::verify(llvm::function_ref emitError, //===----------------------------------------------------------------------===// // `int` `<` kind `>` -mlir::Type fir::IntegerType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::IntegerType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { return parseKindSingleton(parser); } @@ -435,7 +443,8 @@ void fir::IntegerType::print(mlir::DialectAsmPrinter &printer) const { //===----------------------------------------------------------------------===// // `logical` `<` kind `>` -mlir::Type fir::LogicalType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::LogicalType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { return parseKindSingleton(parser); } @@ -448,7 +457,8 @@ void fir::LogicalType::print(mlir::DialectAsmPrinter &printer) const { //===----------------------------------------------------------------------===// // `ptr` `<` type `>` -mlir::Type fir::PointerType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::PointerType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { return parseTypeSingleton(parser); } @@ -469,7 +479,8 @@ mlir::LogicalResult fir::PointerType::verify( //===----------------------------------------------------------------------===// // `real` `<` kind `>` -mlir::Type fir::RealType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::RealType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { return parseKindSingleton(parser); } @@ -492,11 +503,12 @@ fir::RealType::verify(llvm::function_ref emitError, // `type` `<` name // (`(` id `:` type (`,` id `:` type)* `)`)? // (`{` id `:` type (`,` id `:` type)* `}`)? '>' -mlir::Type fir::RecordType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::RecordType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { llvm::StringRef name; if (parser.parseLess() || parser.parseKeyword(&name)) return {}; - RecordType result = RecordType::get(parser.getContext(), name); + RecordType result = RecordType::get(parser.getBuilder().getContext(), name); RecordType::TypeList lenParamList; if (!parser.parseOptionalLParen()) { @@ -619,7 +631,8 @@ unsigned fir::RecordType::getFieldIndex(llvm::StringRef ident) { //===----------------------------------------------------------------------===// // `ref` `<` type `>` -mlir::Type fir::ReferenceType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::ReferenceType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { return parseTypeSingleton(parser); } @@ -642,7 +655,8 @@ mlir::LogicalResult fir::ReferenceType::verify( // `array` `<` `*` | bounds (`x` bounds)* `:` type (',' affine-map)? `>` // bounds ::= `?` | int-lit -mlir::Type fir::SequenceType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::SequenceType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { if (parser.parseLess()) return {}; SequenceType::Shape shape; @@ -661,7 +675,7 @@ mlir::Type fir::SequenceType::parse(mlir::DialectAsmParser &parser) { parser.emitError(parser.getNameLoc(), "expecting affine map"); return {}; } - return SequenceType::get(parser.getContext(), shape, eleTy, map); + return SequenceType::get(context, shape, eleTy, map); } void fir::SequenceType::print(mlir::DialectAsmPrinter &printer) const { @@ -731,7 +745,8 @@ mlir::LogicalResult fir::SequenceType::verify( // ShapeType //===----------------------------------------------------------------------===// -mlir::Type fir::ShapeType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::ShapeType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { return parseRankSingleton(parser); } @@ -743,7 +758,8 @@ void fir::ShapeType::print(mlir::DialectAsmPrinter &printer) const { // ShapeShiftType //===----------------------------------------------------------------------===// -mlir::Type fir::ShapeShiftType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::ShapeShiftType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { return parseRankSingleton(parser); } @@ -755,7 +771,8 @@ void fir::ShapeShiftType::print(mlir::DialectAsmPrinter &printer) const { // ShiftType //===----------------------------------------------------------------------===// -mlir::Type fir::ShiftType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::ShiftType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { return parseRankSingleton(parser); } @@ -768,7 +785,8 @@ void fir::ShiftType::print(mlir::DialectAsmPrinter &printer) const { //===----------------------------------------------------------------------===// // `slice` `<` rank `>` -mlir::Type fir::SliceType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::SliceType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { return parseRankSingleton(parser); } @@ -781,7 +799,8 @@ void fir::SliceType::print(mlir::DialectAsmPrinter &printer) const { //===----------------------------------------------------------------------===// // `tdesc` `<` type `>` -mlir::Type fir::TypeDescType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::TypeDescType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { return parseTypeSingleton(parser); } @@ -805,7 +824,8 @@ mlir::LogicalResult fir::TypeDescType::verify( //===----------------------------------------------------------------------===// // `vector` `<` len `:` type `>` -mlir::Type fir::VectorType::parse(mlir::DialectAsmParser &parser) { +mlir::Type fir::VectorType::parse(mlir::MLIRContext *context, + 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 a368a290f40a..ca6fc1bab1f8 100644 --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/mlir/include/mlir/IR/OpImplementation.h @@ -18,6 +18,7 @@ #include "mlir/IR/OpDefinition.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/SMLoc.h" +#include "llvm/Support/raw_ostream.h" namespace mlir { @@ -322,8 +323,6 @@ 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 485cc5e9d879..4e1cf4c57f6b 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.getContext()) - : getAffineSymbolExpr(pos, parser.getContext())); + ? getAffineDimExpr(pos, parser.getBuilder().getContext()) + : getAffineSymbolExpr(pos, parser.getBuilder().getContext())); } } } @@ -3276,7 +3276,7 @@ static ParseResult parseAffineMapWithMinMax(OpAsmParser &parser, Builder &builder = parser.getBuilder(); auto flatMap = AffineMap::get(totalNumDims, totalNumSyms, flatExprs, - parser.getContext()); + parser.getBuilder().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 64ffec015948..6a89c4ea57bf 100644 --- a/mlir/lib/Dialect/ArmSVE/IR/ArmSVEDialect.cpp +++ b/mlir/lib/Dialect/ArmSVE/IR/ArmSVEDialect.cpp @@ -55,7 +55,8 @@ Type ArmSVEDialect::parseType(DialectAsmParser &parser) const { llvm::SMLoc typeLoc = parser.getCurrentLocation(); { Type genType; - auto parseResult = generatedTypeParser(parser, "vector", genType); + auto parseResult = generatedTypeParser(parser.getBuilder().getContext(), + 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 8728c4a8b440..d21ff1fef3a2 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::DialectAsmParser &parser) { +Type ValueType::parse(mlir::MLIRContext *, mlir::DialectAsmParser &parser) { Type ty; if (parser.parseLess() || parser.parseType(ty) || parser.parseGreater()) { parser.emitError(parser.getNameLoc(), "failed to parse async value type"); @@ -366,7 +366,8 @@ Type AsyncDialect::parseType(DialectAsmParser &parser) const { if (parser.parseKeyword(&typeTag)) return Type(); Type genType; - auto parseResult = generatedTypeParser(parser, typeTag, genType); + auto parseResult = generatedTypeParser(parser.getBuilder().getContext(), + 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 87fbe2585a6c..c6ae79227cd0 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.getContext(), {}); + return get(parser.getBuilder().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.getContext(), entries); + parser.getBuilder().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 aaf1d49edad1..4350f6c813e2 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.getContext())); + UnitAttr::get(parser.getBuilder().getContext())); return success(); } @@ -166,7 +166,8 @@ static ParseResult parseIncludeOp(OpAsmParser &parser, OperationState &result) { #define GET_ATTRDEF_CLASSES #include "mlir/Dialect/EmitC/IR/EmitCAttributes.cpp.inc" -Attribute emitc::OpaqueAttr::parse(DialectAsmParser &parser, Type type) { +Attribute emitc::OpaqueAttr::parse(MLIRContext *context, + DialectAsmParser &parser, Type type) { if (parser.parseLess()) return Attribute(); std::string value; @@ -177,7 +178,7 @@ Attribute emitc::OpaqueAttr::parse(DialectAsmParser &parser, Type type) { } if (parser.parseGreater()) return Attribute(); - return get(parser.getContext(), value); + return get(context, value); } Attribute EmitCDialect::parseAttribute(DialectAsmParser &parser, @@ -188,7 +189,7 @@ Attribute EmitCDialect::parseAttribute(DialectAsmParser &parser, return Attribute(); Attribute genAttr; OptionalParseResult parseResult = - generatedAttributeParser(parser, mnemonic, type, genAttr); + generatedAttributeParser(getContext(), parser, mnemonic, type, genAttr); if (parseResult.hasValue()) return genAttr; parser.emitError(typeLoc, "unknown attribute in EmitC dialect"); @@ -213,7 +214,7 @@ void emitc::OpaqueAttr::print(DialectAsmPrinter &printer) const { #define GET_TYPEDEF_CLASSES #include "mlir/Dialect/EmitC/IR/EmitCTypes.cpp.inc" -Type emitc::OpaqueType::parse(DialectAsmParser &parser) { +Type emitc::OpaqueType::parse(MLIRContext *context, DialectAsmParser &parser) { if (parser.parseLess()) return Type(); std::string value; @@ -224,7 +225,7 @@ Type emitc::OpaqueType::parse(DialectAsmParser &parser) { } if (parser.parseGreater()) return Type(); - return get(parser.getContext(), value); + return get(context, value); } Type EmitCDialect::parseType(DialectAsmParser &parser) const { @@ -234,7 +235,7 @@ Type EmitCDialect::parseType(DialectAsmParser &parser) const { return Type(); Type genType; OptionalParseResult parseResult = - generatedTypeParser(parser, mnemonic, genType); + generatedTypeParser(getContext(), 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 2b5259b3447f..18eec0e195ec 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.getContext(); + MLIRContext *ctx = parser.getBuilder().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.getContext(); + MLIRContext *context = parser.getBuilder().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.getContext(), + LinkageAttr::get(parser.getBuilder().getContext(), parseOptionalLLVMKeyword( parser, result, LLVM::Linkage::External))); @@ -2374,7 +2374,8 @@ void FMFAttr::print(DialectAsmPrinter &printer) const { printer << ">"; } -Attribute FMFAttr::parse(DialectAsmParser &parser, Type type) { +Attribute FMFAttr::parse(MLIRContext *context, DialectAsmParser &parser, + Type type) { if (failed(parser.parseLess())) return {}; @@ -2399,7 +2400,7 @@ Attribute FMFAttr::parse(DialectAsmParser &parser, Type type) { return {}; } - return FMFAttr::get(parser.getContext(), flags); + return FMFAttr::get(parser.getBuilder().getContext(), flags); } void LinkageAttr::print(DialectAsmPrinter &printer) const { @@ -2411,7 +2412,8 @@ void LinkageAttr::print(DialectAsmPrinter &printer) const { printer << ">"; } -Attribute LinkageAttr::parse(DialectAsmParser &parser, Type type) { +Attribute LinkageAttr::parse(MLIRContext *context, DialectAsmParser &parser, + Type type) { StringRef elemName; if (parser.parseLess() || parser.parseKeyword(&elemName) || parser.parseGreater()) @@ -2422,7 +2424,7 @@ Attribute LinkageAttr::parse(DialectAsmParser &parser, Type type) { return {}; } Linkage linkage = *elem; - return LinkageAttr::get(parser.getContext(), linkage); + return LinkageAttr::get(context, linkage); } LoopOptionsAttrBuilder::LoopOptionsAttrBuilder(LoopOptionsAttr attr) @@ -2537,7 +2539,8 @@ void LoopOptionsAttr::print(DialectAsmPrinter &printer) const { printer << ">"; } -Attribute LoopOptionsAttr::parse(DialectAsmParser &parser, Type type) { +Attribute LoopOptionsAttr::parse(MLIRContext *context, DialectAsmParser &parser, + Type type) { if (failed(parser.parseLess())) return {}; @@ -2590,7 +2593,7 @@ Attribute LoopOptionsAttr::parse(DialectAsmParser &parser, Type type) { return {}; llvm::sort(options, llvm::less_first()); - return get(parser.getContext(), options); + return get(parser.getBuilder().getContext(), options); } Attribute LLVMDialect::parseAttribute(DialectAsmParser &parser, @@ -2604,7 +2607,8 @@ Attribute LLVMDialect::parseAttribute(DialectAsmParser &parser, return {}; { Attribute attr; - auto parseResult = generatedAttributeParser(parser, attrKind, type, attr); + auto parseResult = + generatedAttributeParser(getContext(), 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 312f6867585b..acf0328f4878 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.getContext(); + MLIRContext *ctx = parser.getBuilder().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 6cf166f41cd1..9420d60d8ba8 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.getContext(), 32); + auto int32Ty = IntegerType::get(parser.getBuilder().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.getContext(); + MLIRContext *context = parser.getBuilder().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 7f145b373f90..fcce8902d840 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.getContext(); + MLIRContext *context = parser.getBuilder().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.getContext(); + MLIRContext *context = parser.getBuilder().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 a1cded4d705f..7dd6bd90c78b 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.getContext()); + OpBuilder opBuilder(parser.getBuilder().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.getContext()); + OpBuilder opBuilder(parser.getBuilder().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.getContext()); + OpBuilder opBuilder(parser.getBuilder().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 2908e6b7c192..5c588c3533e4 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.getContext()); + initialValue = UnitAttr::get(parser.getBuilder().getContext()); return success(); } diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp index 35754f19adb4..94be8c252a34 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.getContext()); + auto attr = UnitAttr::get(parser.getBuilder().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.getContext()); + auto attr = UnitAttr::get(parser.getBuilder().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 956b075ab126..20f013af246f 100644 --- a/mlir/lib/Dialect/PDL/IR/PDLTypes.cpp +++ b/mlir/lib/Dialect/PDL/IR/PDLTypes.cpp @@ -39,7 +39,8 @@ static Type parsePDLType(DialectAsmParser &parser) { return Type(); { Type genType; - auto parseResult = generatedTypeParser(parser, typeTag, genType); + auto parseResult = generatedTypeParser(parser.getBuilder().getContext(), + parser, typeTag, genType); if (parseResult.hasValue()) return genType; } @@ -74,7 +75,7 @@ bool PDLType::classof(Type type) { // RangeType //===----------------------------------------------------------------------===// -Type RangeType::parse(DialectAsmParser &parser) { +Type RangeType::parse(MLIRContext *context, 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 898d0637c622..900251f8ad7b 100644 --- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp @@ -321,7 +321,8 @@ static ParseResult parseImageOperands(OpAsmParser &parser, if (parseEnumStrAttr(imageOperands, parser)) return failure(); - attr = spirv::ImageOperandsAttr::get(parser.getContext(), imageOperands); + attr = spirv::ImageOperandsAttr::get(parser.getBuilder().getContext(), + imageOperands); return parser.parseRSquare(); } @@ -3589,7 +3590,7 @@ static ParseResult parseSpecConstantOperationOp(OpAsmParser &parser, if (!wrappedOp) return failure(); - OpBuilder builder(parser.getContext()); + OpBuilder builder(parser.getBuilder().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 4e63f57c4ddf..a25a4b7346f0 100644 --- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp +++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp @@ -38,7 +38,8 @@ static bool acceptBitWidth(unsigned bitWidth) { } } -Attribute SparseTensorEncodingAttr::parse(DialectAsmParser &parser, Type type) { +Attribute SparseTensorEncodingAttr::parse(MLIRContext *context, + DialectAsmParser &parser, Type type) { if (failed(parser.parseLess())) return {}; // Parse the data as a dictionary. @@ -112,8 +113,8 @@ Attribute SparseTensorEncodingAttr::parse(DialectAsmParser &parser, Type type) { } } // Construct struct-like storage for attribute. - return parser.getChecked(parser.getContext(), dlt, - map, ptr, ind); + return parser.getChecked(context, dlt, map, ptr, + ind); } void SparseTensorEncodingAttr::print(DialectAsmPrinter &printer) const { @@ -297,7 +298,8 @@ Attribute SparseTensorDialect::parseAttribute(DialectAsmParser &parser, if (failed(parser.parseKeyword(&attrTag))) return Attribute(); Attribute attr; - auto parseResult = generatedAttributeParser(parser, attrTag, type, attr); + auto parseResult = + generatedAttributeParser(getContext(), 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 4857bebe0a65..4ce8011bb7fe 100644 --- a/mlir/lib/Dialect/Vector/VectorOps.cpp +++ b/mlir/lib/Dialect/Vector/VectorOps.cpp @@ -187,7 +187,8 @@ Attribute CombiningKindAttr::parse(DialectAsmParser &parser) { if (failed(parser.parseGreater())) return {}; - return CombiningKindAttr::get(kind.getValue(), parser.getContext()); + return CombiningKindAttr::get(kind.getValue(), + parser.getBuilder().getContext()); } Attribute VectorDialect::parseAttribute(DialectAsmParser &parser, diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index fe9348a81426..881892d5bc25 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -1093,8 +1093,6 @@ 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 29b702323856..3cc2c81fee48 100644 --- a/mlir/test/lib/Dialect/Test/TestAttributes.cpp +++ b/mlir/test/lib/Dialect/Test/TestAttributes.cpp @@ -27,12 +27,13 @@ using namespace test; // AttrWithSelfTypeParamAttr //===----------------------------------------------------------------------===// -Attribute AttrWithSelfTypeParamAttr::parse(DialectAsmParser &parser, +Attribute AttrWithSelfTypeParamAttr::parse(MLIRContext *context, + DialectAsmParser &parser, Type type) { Type selfType; if (parser.parseType(selfType)) return Attribute(); - return get(parser.getContext(), selfType); + return get(context, selfType); } void AttrWithSelfTypeParamAttr::print(DialectAsmPrinter &printer) const { @@ -43,11 +44,12 @@ void AttrWithSelfTypeParamAttr::print(DialectAsmPrinter &printer) const { // AttrWithTypeBuilderAttr //===----------------------------------------------------------------------===// -Attribute AttrWithTypeBuilderAttr::parse(DialectAsmParser &parser, Type type) { +Attribute AttrWithTypeBuilderAttr::parse(MLIRContext *context, + DialectAsmParser &parser, Type type) { IntegerAttr element; if (parser.parseAttribute(element)) return Attribute(); - return get(parser.getContext(), element); + return get(context, element); } void AttrWithTypeBuilderAttr::print(DialectAsmPrinter &printer) const { @@ -58,7 +60,8 @@ void AttrWithTypeBuilderAttr::print(DialectAsmPrinter &printer) const { // CompoundAAttr //===----------------------------------------------------------------------===// -Attribute CompoundAAttr::parse(DialectAsmParser &parser, Type type) { +Attribute CompoundAAttr::parse(MLIRContext *context, DialectAsmParser &parser, + Type type) { int widthOfSomething; Type oneType; SmallVector arrayOfInts; @@ -76,7 +79,7 @@ Attribute CompoundAAttr::parse(DialectAsmParser &parser, Type type) { if (parser.parseRSquare() || parser.parseGreater()) return Attribute(); - return get(parser.getContext(), widthOfSomething, oneType, arrayOfInts); + return get(context, widthOfSomething, oneType, arrayOfInts); } void CompoundAAttr::print(DialectAsmPrinter &printer) const { @@ -90,7 +93,8 @@ void CompoundAAttr::print(DialectAsmPrinter &printer) const { // CompoundAAttr //===----------------------------------------------------------------------===// -Attribute TestI64ElementsAttr::parse(DialectAsmParser &parser, Type type) { +Attribute TestI64ElementsAttr::parse(MLIRContext *context, + DialectAsmParser &parser, Type type) { SmallVector elements; if (parser.parseLess() || parser.parseLSquare()) return Attribute(); @@ -104,7 +108,7 @@ Attribute TestI64ElementsAttr::parse(DialectAsmParser &parser, Type type) { if (parser.parseRSquare() || parser.parseGreater()) return Attribute(); return parser.getChecked( - parser.getContext(), type.cast(), elements); + context, type.cast(), elements); } void TestI64ElementsAttr::print(DialectAsmPrinter &printer) const { @@ -154,7 +158,8 @@ Attribute TestDialect::parseAttribute(DialectAsmParser &parser, return Attribute(); { Attribute attr; - auto parseResult = generatedAttributeParser(parser, attrTag, type, attr); + auto parseResult = + generatedAttributeParser(getContext(), 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 a0f88452b3d1..5fc3bdb40107 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.getContext()); + OpBuilder builder(parser.getBuilder().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 9d618ce1aad6..960fbbb5348c 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(DialectAsmParser &parser) { +Type CompoundAType::parse(MLIRContext *ctxt, DialectAsmParser &parser) { int widthOfSomething; Type oneType; SmallVector arrayOfInts; @@ -107,7 +107,7 @@ Type CompoundAType::parse(DialectAsmParser &parser) { if (parser.parseRSquare() || parser.parseGreater()) return Type(); - return get(parser.getContext(), widthOfSomething, oneType, arrayOfInts); + return get(ctxt, 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(DialectAsmParser &parser) { +Type TestTypeWithLayoutType::parse(MLIRContext *ctx, DialectAsmParser &parser) { unsigned val; if (parser.parseLess() || parser.parseInteger(val) || parser.parseGreater()) return Type(); - return TestTypeWithLayoutType::get(parser.getContext(), val); + return TestTypeWithLayoutType::get(ctx, val); } void TestTypeWithLayoutType::print(DialectAsmPrinter &printer) const { @@ -236,14 +236,15 @@ void TestDialect::registerTypes() { SimpleAType::attachInterface(*getContext()); } -static Type parseTestType(DialectAsmParser &parser, SetVector &stack) { +static Type parseTestType(MLIRContext *ctxt, DialectAsmParser &parser, + SetVector &stack) { StringRef typeTag; if (failed(parser.parseKeyword(&typeTag))) return Type(); { Type genType; - auto parseResult = generatedTypeParser(parser, typeTag, genType); + auto parseResult = generatedTypeParser(ctxt, parser, typeTag, genType); if (parseResult.hasValue()) return genType; } @@ -256,7 +257,7 @@ static Type parseTestType(DialectAsmParser &parser, SetVector &stack) { StringRef name; if (parser.parseLess() || parser.parseKeyword(&name)) return Type(); - auto rec = TestRecursiveType::get(parser.getContext(), name); + auto rec = TestRecursiveType::get(parser.getBuilder().getContext(), name); // If this type already has been parsed above in the stack, expect just the // name. @@ -270,7 +271,7 @@ static Type parseTestType(DialectAsmParser &parser, SetVector &stack) { if (failed(parser.parseComma())) return Type(); stack.insert(rec); - Type subtype = parseTestType(parser, stack); + Type subtype = parseTestType(ctxt, parser, stack); stack.pop_back(); if (!subtype || failed(parser.parseGreater()) || failed(rec.setBody(subtype))) return Type(); @@ -280,7 +281,7 @@ static Type parseTestType(DialectAsmParser &parser, SetVector &stack) { Type TestDialect::parseType(DialectAsmParser &parser) const { SetVector stack; - return parseTestType(parser, stack); + return parseTestType(getContext(), 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 cb0cc72e6822..7954fe382242 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( +// DEF-LABEL: ::mlir::OptionalParseResult generatedAttributeParser(::mlir::MLIRContext *context, // 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(parser, type); +// DEF-NEXT: value = ::test::CompoundAAttr::parse(context, parser, type); // DEF-NEXT: return ::mlir::success(!!value); // DEF-NEXT: } // DEF-NEXT: if (mnemonic == ::test::IndexAttr::getMnemonic()) { -// DEF-NEXT: value = ::test::IndexAttr::parse(parser, type); +// DEF-NEXT: value = ::test::IndexAttr::parse(context, 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( -// DECL-SAME: ::mlir::DialectAsmParser &parser, ::mlir::Type type); +// DECL: static ::mlir::Attribute parse(::mlir::MLIRContext *context, +// DECL-NEXT: ::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( -// DECL-SAME: ::mlir::DialectAsmParser &parser, ::mlir::Type type); +// DECL: static ::mlir::Attribute parse(::mlir::MLIRContext *context, +// DECL-NEXT: ::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 766d93808b75..cffc0ec58faf 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( +// DEF-LABEL: ::mlir::OptionalParseResult generatedTypeParser(::mlir::MLIRContext *context, // 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(parser); +// DEF-NEXT: value = ::test::CompoundAType::parse(context, parser); // DEF-NEXT: return ::mlir::success(!!value); // DEF-NEXT: } // DEF-NEXT: if (mnemonic == ::test::IndexType::getMnemonic()) { -// DEF-NEXT: value = ::test::IndexType::parse(parser); +// DEF-NEXT: value = ::test::IndexType::parse(context, parser); // DEF-NEXT: return ::mlir::success(!!value); // DEF: return {}; @@ -71,7 +71,8 @@ def B_CompoundTypeA : TestType<"CompoundA"> { // DECL: static constexpr ::llvm::StringLiteral getMnemonic() { // DECL: return ::llvm::StringLiteral("cmpnd_a"); // DECL: } -// DECL: static ::mlir::Type parse(::mlir::DialectAsmParser &parser); +// DECL: static ::mlir::Type parse(::mlir::MLIRContext *context, +// DECL-NEXT: ::mlir::DialectAsmParser &parser); // DECL: void print(::mlir::DialectAsmPrinter &printer) const; // DECL: int getWidthOfSomething() const; // DECL: ::test::SimpleTypeA getExampleTdType() const; @@ -90,7 +91,8 @@ def C_IndexType : TestType<"Index"> { // DECL: static constexpr ::llvm::StringLiteral getMnemonic() { // DECL: return ::llvm::StringLiteral("index"); // DECL: } -// DECL: static ::mlir::Type parse(::mlir::DialectAsmParser &parser); +// DECL: static ::mlir::Type parse(::mlir::MLIRContext *context, +// DECL-NEXT: ::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 a1b0836a55d7..d254d78c6881 100644 --- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp +++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp @@ -244,7 +244,8 @@ 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::DialectAsmParser &parser{1}); + static ::mlir::{0} parse(::mlir::MLIRContext *context, + ::mlir::DialectAsmParser &parser{1}); void print(::mlir::DialectAsmPrinter &printer) const; )"; @@ -483,7 +484,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( +static ::mlir::OptionalParseResult generated{0}Parser(::mlir::MLIRContext *context, ::mlir::DialectAsmParser &parser, ::llvm::StringRef mnemonic{1}, ::mlir::{0} &value) {{ @@ -719,11 +720,10 @@ 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", "parser.getContext()"); + fmtCtxt.addSubst("_parser", "parser").addSubst("_ctxt", "context"); // The mnenomic must be defined so the dispatcher knows how to dispatch. - os << llvm::formatv("::mlir::{0} {1}::parse(" + os << llvm::formatv("::mlir::{0} {1}::parse(::mlir::MLIRContext *context, " "::mlir::DialectAsmParser &parser", valueType, def.getCppClassName()); if (isAttrGenerator) { @@ -894,12 +894,11 @@ 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(parser.getContext());\n"; - os << " return ::mlir::success(!!value);\n }\n"; + os << "get(context);\n return ::mlir::success(!!value);\n }\n"; continue; } - os << "parse(parser" << (isAttrGenerator ? ", type" : "") + os << "parse(context, 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 bffd161fb7ee..ad35217c5f9f 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.getContext()"); + fmtContext.addSubst("_ctxt", "parser.getBuilder().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 90f8e7629fe7..ebf3153844e4 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.getContext(), {}); + return CustomDataLayoutSpec::get(parser.getBuilder().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.getContext(), entries); + return CustomDataLayoutSpec::get(parser.getBuilder().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.getContext()); + return SingleQueryType::get(parser.getBuilder().getContext()); } };