My Project
Classes | Public Types | Public Member Functions | List of all members
mlir::OpAsmParser Class Referenceabstract

#include <OpImplementation.h>

Classes

struct  OperandType
 This is the representation of an operand reference. More...
 

Public Types

enum  Delimiter {
  Delimiter::None, Delimiter::Paren, Delimiter::Square, Delimiter::OptionalParen,
  Delimiter::OptionalSquare
}
 

Public Member Functions

virtual ~OpAsmParser ()
 
virtual InFlightDiagnostic emitError (llvm::SMLoc loc, const Twine &message={})=0
 Emit a diagnostic at the specified location and return failure. More...
 
virtual BuildergetBuilder () const =0
 
virtual llvm::SMLoc getCurrentLocation ()=0
 
ParseResult getCurrentLocation (llvm::SMLoc *loc)
 
virtual llvm::SMLoc getNameLoc () const =0
 Return the location of the original name token. More...
 
virtual OperationparseGenericOperation (Block *insertBlock, Block::iterator insertPt)=0
 
virtual ParseResult parseArrow ()=0
 Parse a '->' token. More...
 
virtual ParseResult parseOptionalArrow ()=0
 Parse a '->' token if present. More...
 
virtual ParseResult parseColon ()=0
 Parse a : token. More...
 
virtual ParseResult parseOptionalColon ()=0
 Parse a : token if present. More...
 
virtual ParseResult parseComma ()=0
 Parse a , token. More...
 
virtual ParseResult parseOptionalComma ()=0
 Parse a , token if present. More...
 
virtual ParseResult parseEqual ()=0
 Parse a = token. More...
 
virtual ParseResult parseLess ()=0
 Parse a '<' token. More...
 
virtual ParseResult parseGreater ()=0
 Parse a '>' token. More...
 
ParseResult parseKeyword (StringRef keyword, const Twine &msg="")
 Parse a given keyword. More...
 
ParseResult parseKeyword (StringRef *keyword)
 Parse a keyword into 'keyword'. More...
 
virtual ParseResult parseOptionalKeyword (StringRef keyword)=0
 Parse the given keyword if present. More...
 
virtual ParseResult parseOptionalKeyword (StringRef *keyword)=0
 Parse a keyword, if present, into 'keyword'. More...
 
virtual ParseResult parseLParen ()=0
 Parse a ( token. More...
 
virtual ParseResult parseOptionalLParen ()=0
 Parse a ( token if present. More...
 
virtual ParseResult parseRParen ()=0
 Parse a ) token. More...
 
virtual ParseResult parseOptionalRParen ()=0
 Parse a ) token if present. More...
 
virtual ParseResult parseLSquare ()=0
 Parse a [ token. More...
 
virtual ParseResult parseOptionalLSquare ()=0
 Parse a [ token if present. More...
 
virtual ParseResult parseRSquare ()=0
 Parse a ] token. More...
 
virtual ParseResult parseOptionalRSquare ()=0
 Parse a ] token if present. More...
 
virtual ParseResult parseOptionalEllipsis ()=0
 Parse a ... token if present;. More...
 
ParseResult parseAttribute (Attribute &result, StringRef attrName, SmallVectorImpl< NamedAttribute > &attrs)
 
template<typename AttrType >
ParseResult parseAttribute (AttrType &result, StringRef attrName, SmallVectorImpl< NamedAttribute > &attrs)
 Parse an attribute of a specific kind and type. More...
 
virtual ParseResult parseAttribute (Attribute &result, Type type, StringRef attrName, SmallVectorImpl< NamedAttribute > &attrs)=0
 
template<typename AttrType >
ParseResult parseAttribute (AttrType &result, Type type, StringRef attrName, SmallVectorImpl< NamedAttribute > &attrs)
 Parse an attribute of a specific kind and type. More...
 
virtual ParseResult parseOptionalAttrDict (SmallVectorImpl< NamedAttribute > &result)=0
 Parse a named dictionary into 'result' if it is present. More...
 
virtual ParseResult parseOptionalAttrDictWithKeyword (SmallVectorImpl< NamedAttribute > &result)=0
 
ParseResult parseSymbolName (StringAttr &result, StringRef attrName, SmallVectorImpl< NamedAttribute > &attrs)
 
virtual ParseResult parseOptionalSymbolName (StringAttr &result, StringRef attrName, SmallVectorImpl< NamedAttribute > &attrs)=0
 
virtual ParseResult parseOperand (OperandType &result)=0
 Parse a single operand. More...
 
virtual ParseResult parseOperandList (SmallVectorImpl< OperandType > &result, int requiredOperandCount=-1, Delimiter delimiter=Delimiter::None)=0
 
ParseResult parseOperandList (SmallVectorImpl< OperandType > &result, Delimiter delimiter)
 
virtual ParseResult parseTrailingOperandList (SmallVectorImpl< OperandType > &result, int requiredOperandCount=-1, Delimiter delimiter=Delimiter::None)=0
 
ParseResult parseTrailingOperandList (SmallVectorImpl< OperandType > &result, Delimiter delimiter)
 
virtual ParseResult resolveOperand (const OperandType &operand, Type type, SmallVectorImpl< Value > &result)=0
 Resolve an operand to an SSA value, emitting an error on failure. More...
 
ParseResult resolveOperands (ArrayRef< OperandType > operands, Type type, SmallVectorImpl< Value > &result)
 
ParseResult resolveOperands (ArrayRef< OperandType > operands, ArrayRef< Type > types, llvm::SMLoc loc, SmallVectorImpl< Value > &result)
 
virtual ParseResult parseAffineMapOfSSAIds (SmallVectorImpl< OperandType > &operands, Attribute &map, StringRef attrName, SmallVectorImpl< NamedAttribute > &attrs)=0
 
virtual ParseResult parseRegion (Region &region, ArrayRef< OperandType > arguments, ArrayRef< Type > argTypes, bool enableNameShadowing=false)=0
 
virtual ParseResult parseOptionalRegion (Region &region, ArrayRef< OperandType > arguments, ArrayRef< Type > argTypes, bool enableNameShadowing=false)=0
 Parses a region if present. More...
 
virtual ParseResult parseRegionArgument (OperandType &argument)=0
 
virtual ParseResult parseRegionArgumentList (SmallVectorImpl< OperandType > &result, int requiredOperandCount=-1, Delimiter delimiter=Delimiter::None)=0
 
virtual ParseResult parseRegionArgumentList (SmallVectorImpl< OperandType > &result, Delimiter delimiter)
 
virtual ParseResult parseOptionalRegionArgument (OperandType &argument)=0
 Parse a region argument if present. More...
 
virtual ParseResult parseSuccessorAndUseList (Block *&dest, SmallVectorImpl< Value > &operands)=0
 Parse a single operation successor and its operand list. More...
 
virtual ParseResult parseType (Type &result)=0
 Parse a type. More...
 
virtual ParseResult parseOptionalArrowTypeList (SmallVectorImpl< Type > &result)=0
 Parse an optional arrow followed by a type list. More...
 
virtual ParseResult parseColonType (Type &result)=0
 Parse a colon followed by a type. More...
 
template<typename TypeType >
ParseResult parseColonType (TypeType &result)
 Parse a colon followed by a type of a specific kind, e.g. a FunctionType. More...
 
virtual ParseResult parseColonTypeList (SmallVectorImpl< Type > &result)=0
 Parse a colon followed by a type list, which must have at least one type. More...
 
virtual ParseResult parseOptionalColonTypeList (SmallVectorImpl< Type > &result)=0
 
ParseResult parseKeywordType (const char *keyword, Type &result)
 Parse a keyword followed by a type. More...
 
ParseResult addTypeToList (Type type, SmallVectorImpl< Type > &result)
 
ParseResult addTypesToList (ArrayRef< Type > types, SmallVectorImpl< Type > &result)
 

Detailed Description

The OpAsmParser has methods for interacting with the asm parser: parsing things from it, emitting errors etc. It has an intentionally high-level API that is designed to reduce/constrain syntax innovation in individual operations.

For example, consider an op like this:

x = load p[%1, %2] : memref<...>

The "%x = load" tokens are already parsed and therefore invisible to the custom op parser. This can be supported by calling parseOperandList to parse the p, then calling parseOperandList with a SquareDelimiter to parse the indices, then calling parseColonTypeList to parse the result type.

Member Enumeration Documentation

◆ Delimiter

These are the supported delimiters around operand lists and region argument lists, used by parseOperandList and parseRegionArgumentList.

Enumerator
None 

Zero or more operands with no delimiters.

Paren 

Parens surrounding zero or more operands.

Square 

Square brackets surrounding zero or more operands.

OptionalParen 

Parens supporting zero or more operands, or nothing.

OptionalSquare 

Square brackets supporting zero or more ops, or nothing.

Constructor & Destructor Documentation

◆ ~OpAsmParser()

OpAsmParser::~OpAsmParser ( )
virtual

Member Function Documentation

◆ addTypesToList()

ParseResult mlir::OpAsmParser::addTypesToList ( ArrayRef< Type types,
SmallVectorImpl< Type > &  result 
)
inline

Add the specified types to the end of the specified type list and return success. This is a helper designed to allow parse methods to be simple and chain through || operators.

◆ addTypeToList()

ParseResult mlir::OpAsmParser::addTypeToList ( Type  type,
SmallVectorImpl< Type > &  result 
)
inline

Add the specified type to the end of the specified type list and return success. This is a helper designed to allow parse methods to be simple and chain through || operators.

◆ emitError()

virtual InFlightDiagnostic mlir::OpAsmParser::emitError ( llvm::SMLoc  loc,
const Twine &  message = {} 
)
pure virtual

Emit a diagnostic at the specified location and return failure.

◆ getBuilder()

virtual Builder& mlir::OpAsmParser::getBuilder ( ) const
pure virtual

Return a builder which provides useful access to MLIRContext, global objects like types and attributes.

◆ getCurrentLocation() [1/2]

virtual llvm::SMLoc mlir::OpAsmParser::getCurrentLocation ( )
pure virtual

Get the location of the next token and store it into the argument. This always succeeds.

◆ getCurrentLocation() [2/2]

ParseResult mlir::OpAsmParser::getCurrentLocation ( llvm::SMLoc *  loc)
inline

◆ getNameLoc()

virtual llvm::SMLoc mlir::OpAsmParser::getNameLoc ( ) const
pure virtual

Return the location of the original name token.

◆ parseAffineMapOfSSAIds()

virtual ParseResult mlir::OpAsmParser::parseAffineMapOfSSAIds ( SmallVectorImpl< OperandType > &  operands,
Attribute map,
StringRef  attrName,
SmallVectorImpl< NamedAttribute > &  attrs 
)
pure virtual

Parses an affine map attribute where dims and symbols are SSA operands. Operand values must come from single-result sources, and be valid dimensions/symbol identifiers according to mlir::isValidDim/Symbol.

◆ parseArrow()

virtual ParseResult mlir::OpAsmParser::parseArrow ( )
pure virtual

Parse a '->' token.

◆ parseAttribute() [1/4]

ParseResult mlir::OpAsmParser::parseAttribute ( Attribute result,
StringRef  attrName,
SmallVectorImpl< NamedAttribute > &  attrs 
)
inline

Parse an arbitrary attribute and return it in result. This also adds the attribute to the specified attribute list with the specified name.

◆ parseAttribute() [2/4]

template<typename AttrType >
ParseResult mlir::OpAsmParser::parseAttribute ( AttrType &  result,
StringRef  attrName,
SmallVectorImpl< NamedAttribute > &  attrs 
)
inline

Parse an attribute of a specific kind and type.

◆ parseAttribute() [3/4]

virtual ParseResult mlir::OpAsmParser::parseAttribute ( Attribute result,
Type  type,
StringRef  attrName,
SmallVectorImpl< NamedAttribute > &  attrs 
)
pure virtual

Parse an arbitrary attribute of a given type and return it in result. This also adds the attribute to the specified attribute list with the specified name.

◆ parseAttribute() [4/4]

template<typename AttrType >
ParseResult mlir::OpAsmParser::parseAttribute ( AttrType &  result,
Type  type,
StringRef  attrName,
SmallVectorImpl< NamedAttribute > &  attrs 
)
inline

Parse an attribute of a specific kind and type.

◆ parseColon()

virtual ParseResult mlir::OpAsmParser::parseColon ( )
pure virtual

Parse a : token.

◆ parseColonType() [1/2]

virtual ParseResult mlir::OpAsmParser::parseColonType ( Type result)
pure virtual

Parse a colon followed by a type.

◆ parseColonType() [2/2]

template<typename TypeType >
ParseResult mlir::OpAsmParser::parseColonType ( TypeType &  result)
inline

Parse a colon followed by a type of a specific kind, e.g. a FunctionType.

◆ parseColonTypeList()

virtual ParseResult mlir::OpAsmParser::parseColonTypeList ( SmallVectorImpl< Type > &  result)
pure virtual

Parse a colon followed by a type list, which must have at least one type.

◆ parseComma()

virtual ParseResult mlir::OpAsmParser::parseComma ( )
pure virtual

Parse a , token.

◆ parseEqual()

virtual ParseResult mlir::OpAsmParser::parseEqual ( )
pure virtual

Parse a = token.

◆ parseGenericOperation()

virtual Operation* mlir::OpAsmParser::parseGenericOperation ( Block insertBlock,
Block::iterator  insertPt 
)
pure virtual

Parse an operation in its generic form. The parsed operation is parsed in the current context and inserted in the provided block and insertion point. The results produced by this operation aren't mapped to any named value in the parser. Returns nullptr on failure.

◆ parseGreater()

virtual ParseResult mlir::OpAsmParser::parseGreater ( )
pure virtual

Parse a '>' token.

◆ parseKeyword() [1/2]

ParseResult mlir::OpAsmParser::parseKeyword ( StringRef  keyword,
const Twine &  msg = "" 
)
inline

Parse a given keyword.

◆ parseKeyword() [2/2]

ParseResult mlir::OpAsmParser::parseKeyword ( StringRef *  keyword)
inline

Parse a keyword into 'keyword'.

◆ parseKeywordType()

ParseResult mlir::OpAsmParser::parseKeywordType ( const char *  keyword,
Type result 
)
inline

Parse a keyword followed by a type.

◆ parseLess()

virtual ParseResult mlir::OpAsmParser::parseLess ( )
pure virtual

Parse a '<' token.

◆ parseLParen()

virtual ParseResult mlir::OpAsmParser::parseLParen ( )
pure virtual

Parse a ( token.

◆ parseLSquare()

virtual ParseResult mlir::OpAsmParser::parseLSquare ( )
pure virtual

Parse a [ token.

◆ parseOperand()

virtual ParseResult mlir::OpAsmParser::parseOperand ( OperandType result)
pure virtual

Parse a single operand.

◆ parseOperandList() [1/2]

virtual ParseResult mlir::OpAsmParser::parseOperandList ( SmallVectorImpl< OperandType > &  result,
int  requiredOperandCount = -1,
Delimiter  delimiter = Delimiter::None 
)
pure virtual

Parse zero or more SSA comma-separated operand references with a specified surrounding delimiter, and an optional required operand count.

◆ parseOperandList() [2/2]

ParseResult mlir::OpAsmParser::parseOperandList ( SmallVectorImpl< OperandType > &  result,
Delimiter  delimiter 
)
inline

◆ parseOptionalArrow()

virtual ParseResult mlir::OpAsmParser::parseOptionalArrow ( )
pure virtual

Parse a '->' token if present.

◆ parseOptionalArrowTypeList()

virtual ParseResult mlir::OpAsmParser::parseOptionalArrowTypeList ( SmallVectorImpl< Type > &  result)
pure virtual

Parse an optional arrow followed by a type list.

◆ parseOptionalAttrDict()

virtual ParseResult mlir::OpAsmParser::parseOptionalAttrDict ( SmallVectorImpl< NamedAttribute > &  result)
pure virtual

Parse a named dictionary into 'result' if it is present.

◆ parseOptionalAttrDictWithKeyword()

virtual ParseResult mlir::OpAsmParser::parseOptionalAttrDictWithKeyword ( SmallVectorImpl< NamedAttribute > &  result)
pure virtual

Parse a named dictionary into 'result' if the attributes keyword is present.

◆ parseOptionalColon()

virtual ParseResult mlir::OpAsmParser::parseOptionalColon ( )
pure virtual

Parse a : token if present.

◆ parseOptionalColonTypeList()

virtual ParseResult mlir::OpAsmParser::parseOptionalColonTypeList ( SmallVectorImpl< Type > &  result)
pure virtual

Parse an optional colon followed by a type list, which if present must have at least one type.

◆ parseOptionalComma()

virtual ParseResult mlir::OpAsmParser::parseOptionalComma ( )
pure virtual

Parse a , token if present.

◆ parseOptionalEllipsis()

virtual ParseResult mlir::OpAsmParser::parseOptionalEllipsis ( )
pure virtual

Parse a ... token if present;.

◆ parseOptionalKeyword() [1/2]

virtual ParseResult mlir::OpAsmParser::parseOptionalKeyword ( StringRef  keyword)
pure virtual

Parse the given keyword if present.

◆ parseOptionalKeyword() [2/2]

virtual ParseResult mlir::OpAsmParser::parseOptionalKeyword ( StringRef *  keyword)
pure virtual

Parse a keyword, if present, into 'keyword'.

◆ parseOptionalLParen()

virtual ParseResult mlir::OpAsmParser::parseOptionalLParen ( )
pure virtual

Parse a ( token if present.

◆ parseOptionalLSquare()

virtual ParseResult mlir::OpAsmParser::parseOptionalLSquare ( )
pure virtual

Parse a [ token if present.

◆ parseOptionalRegion()

virtual ParseResult mlir::OpAsmParser::parseOptionalRegion ( Region region,
ArrayRef< OperandType arguments,
ArrayRef< Type argTypes,
bool  enableNameShadowing = false 
)
pure virtual

Parses a region if present.

◆ parseOptionalRegionArgument()

virtual ParseResult mlir::OpAsmParser::parseOptionalRegionArgument ( OperandType argument)
pure virtual

Parse a region argument if present.

◆ parseOptionalRParen()

virtual ParseResult mlir::OpAsmParser::parseOptionalRParen ( )
pure virtual

Parse a ) token if present.

◆ parseOptionalRSquare()

virtual ParseResult mlir::OpAsmParser::parseOptionalRSquare ( )
pure virtual

Parse a ] token if present.

◆ parseOptionalSymbolName()

virtual ParseResult mlir::OpAsmParser::parseOptionalSymbolName ( StringAttr result,
StringRef  attrName,
SmallVectorImpl< NamedAttribute > &  attrs 
)
pure virtual

Parse an optional -identifier and store it (without the '@' symbol) in a string attribute named 'attrName'.

◆ parseRegion()

virtual ParseResult mlir::OpAsmParser::parseRegion ( Region region,
ArrayRef< OperandType arguments,
ArrayRef< Type argTypes,
bool  enableNameShadowing = false 
)
pure virtual

Parses a region. Any parsed blocks are appended to "region" and must be moved to the op regions after the op is created. The first block of the region takes "arguments" of types "argTypes". If "enableNameShadowing" is set to true, the argument names are allowed to shadow the names of other existing SSA values defined above the region scope. "enableNameShadowing" can only be set to true for regions attached to operations that are "IsolatedFromAbove".

◆ parseRegionArgument()

virtual ParseResult mlir::OpAsmParser::parseRegionArgument ( OperandType argument)
pure virtual

Parse a region argument, this argument is resolved when calling 'parseRegion'.

◆ parseRegionArgumentList() [1/2]

virtual ParseResult mlir::OpAsmParser::parseRegionArgumentList ( SmallVectorImpl< OperandType > &  result,
int  requiredOperandCount = -1,
Delimiter  delimiter = Delimiter::None 
)
pure virtual

Parse zero or more region arguments with a specified surrounding delimiter, and an optional required argument count. Region arguments define new values; so this also checks if values with the same names have not been defined yet.

◆ parseRegionArgumentList() [2/2]

virtual ParseResult mlir::OpAsmParser::parseRegionArgumentList ( SmallVectorImpl< OperandType > &  result,
Delimiter  delimiter 
)
inlinevirtual

◆ parseRParen()

virtual ParseResult mlir::OpAsmParser::parseRParen ( )
pure virtual

Parse a ) token.

◆ parseRSquare()

virtual ParseResult mlir::OpAsmParser::parseRSquare ( )
pure virtual

Parse a ] token.

◆ parseSuccessorAndUseList()

virtual ParseResult mlir::OpAsmParser::parseSuccessorAndUseList ( Block *&  dest,
SmallVectorImpl< Value > &  operands 
)
pure virtual

Parse a single operation successor and its operand list.

◆ parseSymbolName()

ParseResult mlir::OpAsmParser::parseSymbolName ( StringAttr result,
StringRef  attrName,
SmallVectorImpl< NamedAttribute > &  attrs 
)
inline

Parse an -identifier and store it (without the '@' symbol) in a string attribute named 'attrName'.

◆ parseTrailingOperandList() [1/2]

virtual ParseResult mlir::OpAsmParser::parseTrailingOperandList ( SmallVectorImpl< OperandType > &  result,
int  requiredOperandCount = -1,
Delimiter  delimiter = Delimiter::None 
)
pure virtual

Parse zero or more trailing SSA comma-separated trailing operand references with a specified surrounding delimiter, and an optional required operand count. A leading comma is expected before the operands.

◆ parseTrailingOperandList() [2/2]

ParseResult mlir::OpAsmParser::parseTrailingOperandList ( SmallVectorImpl< OperandType > &  result,
Delimiter  delimiter 
)
inline

◆ parseType()

virtual ParseResult mlir::OpAsmParser::parseType ( Type result)
pure virtual

Parse a type.

◆ resolveOperand()

virtual ParseResult mlir::OpAsmParser::resolveOperand ( const OperandType operand,
Type  type,
SmallVectorImpl< Value > &  result 
)
pure virtual

Resolve an operand to an SSA value, emitting an error on failure.

◆ resolveOperands() [1/2]

ParseResult mlir::OpAsmParser::resolveOperands ( ArrayRef< OperandType operands,
Type  type,
SmallVectorImpl< Value > &  result 
)
inline

Resolve a list of operands to SSA values, emitting an error on failure, or appending the results to the list on success. This method should be used when all operands have the same type.

◆ resolveOperands() [2/2]

ParseResult mlir::OpAsmParser::resolveOperands ( ArrayRef< OperandType operands,
ArrayRef< Type types,
llvm::SMLoc  loc,
SmallVectorImpl< Value > &  result 
)
inline

Resolve a list of operands and a list of operand types to SSA values, emitting an error and returning failure, or appending the results to the list on success.


The documentation for this class was generated from the following files: