diff --git a/mlir/include/mlir/Parser/Parser.h b/mlir/include/mlir/Parser/Parser.h --- a/mlir/include/mlir/Parser/Parser.h +++ b/mlir/include/mlir/Parser/Parser.h @@ -73,6 +73,26 @@ } } // namespace detail +/// This class represents a configuration for the MLIR assembly parser. It +/// contains all of the necessary state to parse a textual MLIR source file. +class AsmParserConfig { +public: + AsmParserConfig(MLIRContext *context, AsmParserState *asmState = nullptr) + : context(context), asmState(asmState) { + assert(context && "expected valid MLIR context"); + } + + /// Return the MLIRContext to be used when parsing. + MLIRContext *getContext() const { return context; } + + /// Return asm parser state to be used when parsing. + AsmParserState *getAsmParserState() const { return asmState; } + +private: + MLIRContext *context; + AsmParserState *asmState; +}; + /// This parses the file specified by the indicated SourceMgr and appends parsed /// operations to the given block. If the block is non-empty, the operations are /// placed before the current terminator. If parsing is successful, success is @@ -84,9 +104,8 @@ /// SSA uses and definitions). `asmState` should only be provided if this /// detailed information is desired. LogicalResult parseSourceFile(const llvm::SourceMgr &sourceMgr, Block *block, - MLIRContext *context, - LocationAttr *sourceFileLoc = nullptr, - AsmParserState *asmState = nullptr); + const AsmParserConfig &config, + LocationAttr *sourceFileLoc = nullptr); /// This parses the file specified by the indicated filename and appends parsed /// operations to the given block. If the block is non-empty, the operations are @@ -95,8 +114,8 @@ /// registered in the context, and failure is returned. If `sourceFileLoc` is /// non-null, it is populated with a file location representing the start of the /// source file that is being parsed. -LogicalResult parseSourceFile(llvm::StringRef filename, Block *block, - MLIRContext *context, +LogicalResult parseSourceFile(StringRef filename, Block *block, + const AsmParserConfig &config, LocationAttr *sourceFileLoc = nullptr); /// This parses the file specified by the indicated filename using the provided @@ -109,11 +128,9 @@ /// `asmState` is non-null, it is populated with detailed information about the /// parsed IR (including exact locations for SSA uses and definitions). /// `asmState` should only be provided if this detailed information is desired. -LogicalResult parseSourceFile(llvm::StringRef filename, - llvm::SourceMgr &sourceMgr, Block *block, - MLIRContext *context, - LocationAttr *sourceFileLoc = nullptr, - AsmParserState *asmState = nullptr); +LogicalResult parseSourceFile(StringRef filename, llvm::SourceMgr &sourceMgr, + Block *block, const AsmParserConfig &config, + LocationAttr *sourceFileLoc = nullptr); /// This parses the IR string and appends parsed operations to the given block. /// If the block is non-empty, the operations are placed before the current @@ -122,10 +139,26 @@ /// context, and failure is returned. If `sourceFileLoc` is non-null, it is /// populated with a file location representing the start of the source file /// that is being parsed. -LogicalResult parseSourceString(llvm::StringRef sourceStr, Block *block, - MLIRContext *context, +LogicalResult parseSourceString(StringRef sourceStr, Block *block, + const AsmParserConfig &config, LocationAttr *sourceFileLoc = nullptr); +namespace detail { +/// The internal implementation of the templated `parseSourceFile` methods +/// below, that simply forwards to the non-templated version. +template +inline OwningOpRef parseSourceFile(const AsmParserConfig &config, + ParserArgs &&...args) { + LocationAttr sourceFileLoc; + Block block; + if (failed(parseSourceFile(std::forward(args)..., &block, config, + &sourceFileLoc))) + return OwningOpRef(); + return detail::constructContainerOpForParserIfNecessary( + &block, config.getContext(), sourceFileLoc); +} +} // namespace detail + /// This parses the file specified by the indicated SourceMgr. If the source IR /// contained a single instance of `ContainerOpT`, it is returned. Otherwise, a /// new instance of `ContainerOpT` is constructed containing all of the parsed @@ -136,13 +169,9 @@ /// `SingleBlockImplicitTerminator` trait. template inline OwningOpRef -parseSourceFile(const llvm::SourceMgr &sourceMgr, MLIRContext *context) { - LocationAttr sourceFileLoc; - Block block; - if (failed(parseSourceFile(sourceMgr, &block, context, &sourceFileLoc))) - return OwningOpRef(); - return detail::constructContainerOpForParserIfNecessary( - &block, context, sourceFileLoc); +parseSourceFile(const llvm::SourceMgr &sourceMgr, + const AsmParserConfig &config) { + return detail::parseSourceFile(config, sourceMgr); } /// This parses the file specified by the indicated filename. If the source IR @@ -154,14 +183,9 @@ /// containing a single block, and must implement the /// `SingleBlockImplicitTerminator` trait. template -inline OwningOpRef parseSourceFile(llvm::StringRef filename, - MLIRContext *context) { - LocationAttr sourceFileLoc; - Block block; - if (failed(parseSourceFile(filename, &block, context, &sourceFileLoc))) - return OwningOpRef(); - return detail::constructContainerOpForParserIfNecessary( - &block, context, sourceFileLoc); +inline OwningOpRef +parseSourceFile(StringRef filename, const AsmParserConfig &config) { + return detail::parseSourceFile(config, filename); } /// This parses the file specified by the indicated filename using the provided @@ -173,16 +197,10 @@ /// required to have a single region containing a single block, and must /// implement the `SingleBlockImplicitTerminator` trait. template -inline OwningOpRef parseSourceFile(llvm::StringRef filename, - llvm::SourceMgr &sourceMgr, - MLIRContext *context) { - LocationAttr sourceFileLoc; - Block block; - if (failed(parseSourceFile(filename, sourceMgr, &block, context, - &sourceFileLoc))) - return OwningOpRef(); - return detail::constructContainerOpForParserIfNecessary( - &block, context, sourceFileLoc); +inline OwningOpRef +parseSourceFile(llvm::StringRef filename, llvm::SourceMgr &sourceMgr, + const AsmParserConfig &config) { + return detail::parseSourceFile(config, filename, sourceMgr); } /// This parses the provided string containing MLIR. If the source IR contained @@ -194,14 +212,14 @@ /// containing a single block, and must implement the /// `SingleBlockImplicitTerminator` trait. template -inline OwningOpRef parseSourceString(llvm::StringRef sourceStr, - MLIRContext *context) { +inline OwningOpRef +parseSourceString(StringRef sourceStr, const AsmParserConfig &config) { LocationAttr sourceFileLoc; Block block; - if (failed(parseSourceString(sourceStr, &block, context, &sourceFileLoc))) + if (failed(parseSourceString(sourceStr, &block, config, &sourceFileLoc))) return OwningOpRef(); return detail::constructContainerOpForParserIfNecessary( - &block, context, sourceFileLoc); + &block, config.getContext(), sourceFileLoc); } /// This parses a single MLIR attribute to an MLIR context if it was valid. If diff --git a/mlir/lib/Parser/AffineParser.cpp b/mlir/lib/Parser/AffineParser.cpp --- a/mlir/lib/Parser/AffineParser.cpp +++ b/mlir/lib/Parser/AffineParser.cpp @@ -718,7 +718,8 @@ /*RequiresNullTerminator=*/false); sourceMgr.AddNewSourceBuffer(std::move(memBuffer), SMLoc()); SymbolState symbolState; - ParserState state(sourceMgr, context, symbolState, /*asmState=*/nullptr); + AsmParserConfig config(context); + ParserState state(sourceMgr, config, symbolState); Parser parser(state); raw_ostream &os = printDiagnosticInfo ? llvm::errs() : llvm::nulls(); diff --git a/mlir/lib/Parser/AsmParserImpl.h b/mlir/lib/Parser/AsmParserImpl.h --- a/mlir/lib/Parser/AsmParserImpl.h +++ b/mlir/lib/Parser/AsmParserImpl.h @@ -432,10 +432,8 @@ // If we are populating the assembly parser state, record this as a symbol // reference. - if (parser.getState().asmState) { - parser.getState().asmState->addUses(SymbolRefAttr::get(result), - atToken.getLocRange()); - } + if (auto *asmState = parser.getState().config.getAsmParserState()) + asmState->addUses(SymbolRefAttr::get(result), atToken.getLocRange()); return success(); } diff --git a/mlir/lib/Parser/AttributeParser.cpp b/mlir/lib/Parser/AttributeParser.cpp --- a/mlir/lib/Parser/AttributeParser.cpp +++ b/mlir/lib/Parser/AttributeParser.cpp @@ -156,7 +156,7 @@ // When populating the parser state, this is a list of locations for all of // the nested references. SmallVector referenceLocations; - if (state.asmState) + if (state.config.getAsmParserState()) referenceLocations.push_back(getToken().getLocRange()); // Parse the top-level reference. @@ -185,7 +185,7 @@ // If we are populating the assembly state, add the location for this // reference. - if (state.asmState) + if (state.config.getAsmParserState()) referenceLocations.push_back(getToken().getLocRange()); std::string nameStr = getToken().getSymbolReference(); @@ -196,8 +196,8 @@ SymbolRefAttr::get(getContext(), nameStr, nestedRefs); // If we are populating the assembly state, record this symbol reference. - if (state.asmState) - state.asmState->addUses(symbolRefAttr, referenceLocations); + if (auto *asmState = state.config.getAsmParserState()) + asmState->addUses(symbolRefAttr, referenceLocations); return symbolRefAttr; } diff --git a/mlir/lib/Parser/DialectSymbolParser.cpp b/mlir/lib/Parser/DialectSymbolParser.cpp --- a/mlir/lib/Parser/DialectSymbolParser.cpp +++ b/mlir/lib/Parser/DialectSymbolParser.cpp @@ -199,7 +199,7 @@ /// parsing failed, nullptr is returned. The number of bytes read from the input /// string is returned in 'numRead'. template -static T parseSymbol(StringRef inputStr, MLIRContext *context, +static T parseSymbol(StringRef inputStr, const AsmParserConfig &config, SymbolState &symbolState, ParserFn &&parserFn, size_t *numRead = nullptr) { SourceMgr sourceMgr; @@ -207,7 +207,7 @@ inputStr, /*BufferName=*/"", /*RequiresNullTerminator=*/false); sourceMgr.AddNewSourceBuffer(std::move(memBuffer), SMLoc()); - ParserState state(sourceMgr, context, symbolState, /*asmState=*/nullptr); + ParserState state(sourceMgr, config, symbolState); Parser parser(state); Token startTok = parser.getToken(); @@ -237,10 +237,10 @@ /// attribute-alias ::= `#` alias-name /// Attribute Parser::parseExtendedAttr(Type type) { + MLIRContext *context = getContext(); Attribute attr = parseExtendedSymbol( *this, Token::hash_identifier, state.symbols.attributeAliasDefinitions, - [&](StringRef dialectName, StringRef symbolData, - SMLoc loc) -> Attribute { + [&](StringRef dialectName, StringRef symbolData, SMLoc loc) -> Attribute { // Parse an optional trailing colon type. Type attrType = type; if (consumeIf(Token::colon) && !(attrType = parseType())) @@ -250,7 +250,7 @@ if (Dialect *dialect = builder.getContext()->getOrLoadDialect(dialectName)) { return parseSymbol( - symbolData, state.context, state.symbols, [&](Parser &parser) { + symbolData, context, state.symbols, [&](Parser &parser) { CustomDialectAsmParser customParser(symbolData, parser); return dialect->parseAttribute(customParser, attrType); }); @@ -259,8 +259,8 @@ // Otherwise, form a new opaque attribute. return OpaqueAttr::getChecked( [&] { return emitError(loc); }, - StringAttr::get(state.context, dialectName), symbolData, - attrType ? attrType : NoneType::get(state.context)); + StringAttr::get(context, dialectName), symbolData, + attrType ? attrType : NoneType::get(context)); }); // Ensure that the attribute has the same type as requested. @@ -280,25 +280,25 @@ /// type-alias ::= `!` alias-name /// Type Parser::parseExtendedType() { + MLIRContext *context = getContext(); return parseExtendedSymbol( *this, Token::exclamation_identifier, state.symbols.typeAliasDefinitions, - [&](StringRef dialectName, StringRef symbolData, - SMLoc loc) -> Type { + [&](StringRef dialectName, StringRef symbolData, SMLoc loc) -> Type { // If we found a registered dialect, then ask it to parse the type. - auto *dialect = state.context->getOrLoadDialect(dialectName); + auto *dialect = context->getOrLoadDialect(dialectName); if (dialect) { return parseSymbol( - symbolData, state.context, state.symbols, [&](Parser &parser) { + symbolData, context, state.symbols, [&](Parser &parser) { CustomDialectAsmParser customParser(symbolData, parser); return dialect->parseType(customParser); }); } // Otherwise, form a new opaque type. - return OpaqueType::getChecked( - [&] { return emitError(loc); }, - StringAttr::get(state.context, dialectName), symbolData); + return OpaqueType::getChecked([&] { return emitError(loc); }, + StringAttr::get(context, dialectName), + symbolData); }); } diff --git a/mlir/lib/Parser/Parser.h b/mlir/lib/Parser/Parser.h --- a/mlir/lib/Parser/Parser.h +++ b/mlir/lib/Parser/Parser.h @@ -28,11 +28,12 @@ Builder builder; - Parser(ParserState &state) : builder(state.context), state(state) {} + Parser(ParserState &state) + : builder(state.config.getContext()), state(state) {} // Helper methods to get stuff from the parser-global state. ParserState &getState() const { return state; } - MLIRContext *getContext() const { return state.context; } + MLIRContext *getContext() const { return builder.getContext(); } const llvm::SourceMgr &getSourceMgr() { return state.lex.getSourceMgr(); } /// Parse a comma-separated list of elements up until the specified end token. diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -560,8 +560,8 @@ pushSSANameScope(/*isIsolated=*/true); // If we are populating the parser state, prepare it for parsing. - if (state.asmState) - state.asmState->initialize(topLevelOp); + if (auto *asmState = state.config.getAsmParserState()) + asmState->initialize(topLevelOp); } OperationParser::~OperationParser() { @@ -642,8 +642,8 @@ return failure(); // If we are populating the parser state, finalize the top-level operation. - if (state.asmState) - state.asmState->finalize(topLevelOp); + if (auto *asmState = state.config.getAsmParserState()) + asmState->finalize(topLevelOp); return success(); } @@ -730,8 +730,8 @@ // If a definition of the value already exists, replace it in the assembly // state. - if (state.asmState) - state.asmState->refineDefinition(existing, value); + if (auto *asmState = state.config.getAsmParserState()) + asmState->refineDefinition(existing, value); } /// Record this definition for the current scope. @@ -793,8 +793,8 @@ // Functor used to record the use of the given value if the assembly state // field is populated. auto maybeRecordUse = [&](Value value) { - if (state.asmState) - state.asmState->addUses(value, useInfo.location); + if (auto *asmState = state.config.getAsmParserState()) + asmState->addUses(value, useInfo.location); return value; }; @@ -991,7 +991,7 @@ << numExpectedResults << " to bind"; // Add this operation to the assembly state if it was provided to populate. - if (state.asmState) { + if (auto *asmState = state.config.getAsmParserState()) { unsigned resultIt = 0; SmallVector> asmResultGroups; asmResultGroups.reserve(resultIDs.size()); @@ -999,9 +999,9 @@ asmResultGroups.emplace_back(resultIt, std::get<2>(record)); resultIt += std::get<1>(record); } - state.asmState->finalizeOperationDefinition( - op, nameTok.getLocRange(), /*endLoc=*/getToken().getLoc(), - asmResultGroups); + asmState->finalizeOperationDefinition(op, nameTok.getLocRange(), + /*endLoc=*/getToken().getLoc(), + asmResultGroups); } // Add definitions for each of the result groups. @@ -1015,9 +1015,9 @@ } // Add this operation to the assembly state if it was provided to populate. - } else if (state.asmState) { - state.asmState->finalizeOperationDefinition(op, nameTok.getLocRange(), - /*endLoc=*/getToken().getLoc()); + } else if (auto *asmState = state.config.getAsmParserState()) { + asmState->finalizeOperationDefinition(op, nameTok.getLocRange(), + /*endLoc=*/getToken().getLoc()); } return success(); @@ -1204,8 +1204,8 @@ } // If we are populating the parser state, start a new operation definition. - if (state.asmState) - state.asmState->startOperationDefinition(result.name); + if (auto *asmState = state.config.getAsmParserState()) + asmState->startOperationDefinition(result.name); if (parseGenericOperationAfterOpName(result)) return nullptr; @@ -1229,9 +1229,9 @@ // If we are populating the parser asm state, finalize this operation // definition. - if (state.asmState) - state.asmState->finalizeOperationDefinition(op, nameToken.getLocRange(), - /*endLoc=*/getToken().getLoc()); + if (auto *asmState = state.config.getAsmParserState()) + asmState->finalizeOperationDefinition(op, nameToken.getLocRange(), + /*endLoc=*/getToken().getLoc()); return op; } @@ -1714,8 +1714,8 @@ OperationState opState(srcLocation, *opNameInfo); // If we are populating the parser state, start a new operation definition. - if (state.asmState) - state.asmState->startOperationDefinition(opState.name); + if (auto *asmState = state.config.getAsmParserState()) + asmState->startOperationDefinition(opState.name); // Have the op implementation take a crack and parsing this. CleanupOpStateRegions guard{opState}; @@ -1804,8 +1804,8 @@ return failure(); // If we are populating the parser state, start a new region definition. - if (state.asmState) - state.asmState->startRegionDefinition(); + if (auto *asmState = state.config.getAsmParserState()) + asmState->startRegionDefinition(); // Parse the region body. if ((!entryArguments.empty() || getToken().isNot(Token::r_brace)) && @@ -1816,8 +1816,8 @@ consumeToken(Token::r_brace); // If we are populating the parser state, finalize this region. - if (state.asmState) - state.asmState->finalizeRegionDefinition(); + if (auto *asmState = state.config.getAsmParserState()) + asmState->finalizeRegionDefinition(); return success(); } @@ -1837,8 +1837,9 @@ // If this block is not defined in the source file, add a definition for it // now in the assembly state. Blocks with a name will be defined when the name // is parsed. - if (state.asmState && getToken().isNot(Token::caret_identifier)) - state.asmState->addDefinition(block, startLoc); + if (state.config.getAsmParserState() && + getToken().isNot(Token::caret_identifier)) + state.config.getAsmParserState()->addDefinition(block, startLoc); // Add arguments to the entry block if we had the form with explicit names. if (!entryArguments.empty() && !entryArguments[0].ssaName.name.empty()) { @@ -1863,8 +1864,8 @@ BlockArgument arg = block->addArgument(entryArg.type, loc); // Add a definition of this arg to the assembly state if provided. - if (state.asmState) - state.asmState->addDefinition(arg, argInfo.location); + if (auto *asmState = state.config.getAsmParserState()) + asmState->addDefinition(arg, argInfo.location); // Record the definition for this argument. if (addDefinition(argInfo, arg)) @@ -1949,8 +1950,8 @@ } // Populate the high level assembly state if necessary. - if (state.asmState) - state.asmState->addDefinition(blockAndLoc.block, nameLoc); + if (auto *asmState = state.config.getAsmParserState()) + asmState->addDefinition(blockAndLoc.block, nameLoc); block = blockAndLoc.block; @@ -1991,8 +1992,8 @@ } // Populate the high level assembly state if necessary. - if (state.asmState) - state.asmState->addUses(blockDef.block, loc); + if (auto *asmState = state.config.getAsmParserState()) + asmState->addUses(blockDef.block, loc); return blockDef.block; } @@ -2040,8 +2041,8 @@ // Mark this block argument definition in the parser state if it was // provided. - if (state.asmState) - state.asmState->addDefinition(arg, useInfo.location); + if (auto *asmState = state.config.getAsmParserState()) + asmState->addDefinition(arg, useInfo.location); return addDefinition(useInfo, arg); }); @@ -2186,50 +2187,49 @@ //===----------------------------------------------------------------------===// LogicalResult mlir::parseSourceFile(const llvm::SourceMgr &sourceMgr, - Block *block, MLIRContext *context, - LocationAttr *sourceFileLoc, - AsmParserState *asmState) { + Block *block, const AsmParserConfig &config, + LocationAttr *sourceFileLoc) { const auto *sourceBuf = sourceMgr.getMemoryBuffer(sourceMgr.getMainFileID()); - Location parserLoc = FileLineColLoc::get( - context, sourceBuf->getBufferIdentifier(), /*line=*/0, /*column=*/0); + Location parserLoc = + FileLineColLoc::get(config.getContext(), sourceBuf->getBufferIdentifier(), + /*line=*/0, /*column=*/0); if (sourceFileLoc) *sourceFileLoc = parserLoc; SymbolState aliasState; - ParserState state(sourceMgr, context, aliasState, asmState); + ParserState state(sourceMgr, config, aliasState); return TopLevelOperationParser(state).parse(block, parserLoc); } LogicalResult mlir::parseSourceFile(llvm::StringRef filename, Block *block, - MLIRContext *context, + const AsmParserConfig &config, LocationAttr *sourceFileLoc) { llvm::SourceMgr sourceMgr; - return parseSourceFile(filename, sourceMgr, block, context, sourceFileLoc); + return parseSourceFile(filename, sourceMgr, block, config, sourceFileLoc); } LogicalResult mlir::parseSourceFile(llvm::StringRef filename, llvm::SourceMgr &sourceMgr, Block *block, - MLIRContext *context, - LocationAttr *sourceFileLoc, - AsmParserState *asmState) { + const AsmParserConfig &config, + LocationAttr *sourceFileLoc) { if (sourceMgr.getNumBuffers() != 0) { // TODO: Extend to support multiple buffers. - return emitError(mlir::UnknownLoc::get(context), + return emitError(mlir::UnknownLoc::get(config.getContext()), "only main buffer parsed at the moment"); } auto fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(filename); if (std::error_code error = fileOrErr.getError()) - return emitError(mlir::UnknownLoc::get(context), + return emitError(mlir::UnknownLoc::get(config.getContext()), "could not open input file " + filename); // Load the MLIR source file. sourceMgr.AddNewSourceBuffer(std::move(*fileOrErr), SMLoc()); - return parseSourceFile(sourceMgr, block, context, sourceFileLoc, asmState); + return parseSourceFile(sourceMgr, block, config, sourceFileLoc); } LogicalResult mlir::parseSourceString(llvm::StringRef sourceStr, Block *block, - MLIRContext *context, + const AsmParserConfig &config, LocationAttr *sourceFileLoc) { auto memBuffer = MemoryBuffer::getMemBuffer(sourceStr); if (!memBuffer) @@ -2237,5 +2237,5 @@ SourceMgr sourceMgr; sourceMgr.AddNewSourceBuffer(std::move(memBuffer), SMLoc()); - return parseSourceFile(sourceMgr, block, context, sourceFileLoc); + return parseSourceFile(sourceMgr, block, config, sourceFileLoc); } diff --git a/mlir/lib/Parser/ParserState.h b/mlir/lib/Parser/ParserState.h --- a/mlir/lib/Parser/ParserState.h +++ b/mlir/lib/Parser/ParserState.h @@ -47,11 +47,11 @@ /// This class refers to all of the state maintained globally by the parser, /// such as the current lexer position etc. struct ParserState { - ParserState(const llvm::SourceMgr &sourceMgr, MLIRContext *ctx, - SymbolState &symbols, AsmParserState *asmState) - : context(ctx), lex(sourceMgr, ctx), curToken(lex.lexToken()), - symbols(symbols), parserDepth(symbols.nestedParserLocs.size()), - asmState(asmState) { + ParserState(const llvm::SourceMgr &sourceMgr, const AsmParserConfig &config, + SymbolState &symbols) + : config(config), lex(sourceMgr, config.getContext()), + curToken(lex.lexToken()), symbols(symbols), + parserDepth(symbols.nestedParserLocs.size()) { // Set the top level lexer for the symbol state if one doesn't exist. if (!symbols.topLevelLexer) symbols.topLevelLexer = &lex; @@ -64,8 +64,8 @@ ParserState(const ParserState &) = delete; void operator=(const ParserState &) = delete; - /// The context we're parsing into. - MLIRContext *const context; + /// The configuration of the parser. + const AsmParserConfig &config; /// The lexer for the source file we're parsing. Lexer lex; @@ -79,10 +79,6 @@ /// The depth of this parser in the nested parsing stack. size_t parserDepth; - /// An optional pointer to a struct containing high level parser state to be - /// populated during parsing. - AsmParserState *asmState; - // Contains the stack of default dialect to use when parsing regions. // A new dialect get pushed to the stack before parsing regions nested // under an operation implementing `OpAsmOpInterface`, and diff --git a/mlir/lib/Parser/TypeParser.cpp b/mlir/lib/Parser/TypeParser.cpp --- a/mlir/lib/Parser/TypeParser.cpp +++ b/mlir/lib/Parser/TypeParser.cpp @@ -232,8 +232,7 @@ if (failed(parseStridedLayout(offset, strides))) return failure(); // Construct strided affine map. - AffineMap map = - makeStridedLinearLayoutMap(strides, offset, state.context); + AffineMap map = makeStridedLinearLayoutMap(strides, offset, getContext()); layout = AffineMapAttr::get(map); } else { // Either it is MemRefLayoutAttrInterface or memory space attribute. diff --git a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp --- a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp +++ b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp @@ -307,8 +307,8 @@ } sourceMgr.AddNewSourceBuffer(std::move(memBuffer), SMLoc()); - if (failed(parseSourceFile(sourceMgr, &parsedIR, &context, nullptr, - &asmState))) { + if (failed(parseSourceFile(sourceMgr, &parsedIR, + AsmParserConfig(&context, &asmState)))) { // If parsing failed, clear out any of the current state. parsedIR.clear(); asmState = AsmParserState();