35 case Token::kw_memref:
36 case Token::kw_tensor:
37 case Token::kw_complex:
39 case Token::kw_vector:
41 case Token::kw_f4E2M1FN:
42 case Token::kw_f6E2M3FN:
43 case Token::kw_f6E3M2FN:
44 case Token::kw_f8E5M2:
45 case Token::kw_f8E4M3:
46 case Token::kw_f8E4M3FN:
47 case Token::kw_f8E5M2FNUZ:
48 case Token::kw_f8E4M3FNUZ:
49 case Token::kw_f8E4M3B11FNUZ:
50 case Token::kw_f8E3M4:
51 case Token::kw_f8E8M0FNU:
52 case Token::kw_f8E5M3FNU:
64 case Token::exclamation_identifier:
95 elements.push_back(t);
105 auto parseElt = [&]() -> ParseResult {
107 elements.push_back(elt);
108 return elt ?
success() : failure();
120 if (
parseToken(Token::l_paren,
"expected '('"))
141 if (
parseToken(Token::less,
"expected '<' in complex type"))
147 parseToken(Token::greater,
"expected '>' in complex type"))
149 if (!isa<FloatType>(elementType) && !isa<IntegerType>(elementType))
150 return emitError(elementTypeLoc,
"invalid element type for complex"),
153 return ComplexType::get(elementType);
161 assert(
getToken().is(Token::l_paren));
165 parseToken(Token::arrow,
"expected '->' in function type") ||
169 return builder.getFunctionType(arguments, results);
190 if (
parseToken(Token::less,
"expected '<' in memref type"))
216 return emitError(typeLoc,
"invalid memref element type"),
nullptr;
218 MemRefLayoutAttrInterface layout;
221 auto parseElt = [&]() -> ParseResult {
227 if (isa<MemRefLayoutAttrInterface>(attr)) {
228 layout = cast<MemRefLayoutAttrInterface>(attr);
229 }
else if (memorySpace) {
230 return emitError(
"multiple memory spaces specified in memref type");
237 return emitError(
"cannot have affine map for unranked memref type");
239 return emitError(
"expected memory space to be last in memref type");
247 if (
parseToken(Token::comma,
"expected ',' or '>' in memref type") ||
282 case Token::kw_memref:
284 case Token::kw_tensor:
286 case Token::kw_complex:
288 case Token::kw_tuple:
290 case Token::kw_vector:
293 case Token::inttype: {
295 if (!width.has_value())
296 return (
emitError(
"invalid integer width"),
nullptr);
297 if (*width > IntegerType::kMaxWidth) {
299 << IntegerType::kMaxWidth <<
" bits";
303 IntegerType::SignednessSemantics signSemantics = IntegerType::Signless;
304 if (std::optional<bool> signedness =
getToken().getIntTypeSignedness())
305 signSemantics = *signedness ? IntegerType::Signed : IntegerType::Unsigned;
308 return IntegerType::get(
getContext(), *width, signSemantics);
312 case Token::kw_f4E2M1FN:
314 return builder.getType<Float4E2M1FNType>();
315 case Token::kw_f6E2M3FN:
317 return builder.getType<Float6E2M3FNType>();
318 case Token::kw_f6E3M2FN:
320 return builder.getType<Float6E3M2FNType>();
321 case Token::kw_f8E5M2:
323 return builder.getType<Float8E5M2Type>();
324 case Token::kw_f8E4M3:
326 return builder.getType<Float8E4M3Type>();
327 case Token::kw_f8E4M3FN:
329 return builder.getType<Float8E4M3FNType>();
330 case Token::kw_f8E5M2FNUZ:
332 return builder.getType<Float8E5M2FNUZType>();
333 case Token::kw_f8E4M3FNUZ:
335 return builder.getType<Float8E4M3FNUZType>();
336 case Token::kw_f8E4M3B11FNUZ:
338 return builder.getType<Float8E4M3B11FNUZType>();
339 case Token::kw_f8E3M4:
341 return builder.getType<Float8E3M4Type>();
342 case Token::kw_f8E8M0FNU:
344 return builder.getType<Float8E8M0FNUType>();
345 case Token::kw_f8E5M3FNU:
347 return builder.getType<Float8E5M3FNUType>();
350 return builder.getType<BFloat16Type>();
353 return builder.getType<Float16Type>();
356 return builder.getType<FloatTF32Type>();
359 return builder.getType<Float32Type>();
362 return builder.getType<Float64Type>();
365 return builder.getType<Float80Type>();
368 return builder.getType<Float128Type>();
371 case Token::kw_index:
377 return builder.getType<MXI8Type>();
385 case Token::kw_token:
387 return builder.getType<TokenType>();
390 case Token::exclamation_identifier:
394 case Token::code_complete:
395 if (
getToken().isCodeCompletionFor(Token::exclamation_identifier))
409 if (
parseToken(Token::less,
"expected '<' in tensor type"))
436 if (parseResult.has_value()) {
437 if (failed(parseResult.value()))
439 if (
auto v = dyn_cast_or_null<VerifiableTensorEncoding>(encoding)) {
440 if (failed(v.verifyEncoding(dimensions, elementType,
441 [&] { return emitError(); })))
447 if (!elementType ||
parseToken(Token::greater,
"expected '>' in tensor type"))
450 return emitError(elementTypeLoc,
"invalid tensor element type"),
nullptr;
454 return emitError(
"cannot apply encoding to unranked tensor"),
nullptr;
455 return UnrankedTensorType::get(elementType);
457 return RankedTensorType::get(dimensions, elementType, encoding);
468 if (
parseToken(Token::less,
"expected '<' in tuple type"))
478 parseToken(Token::greater,
"expected '>' in tuple type"))
494 if (
parseToken(Token::less,
"expected '<' in vector type"))
505 if (!elementType ||
parseToken(Token::greater,
"expected '>' in vector type"))
526 bool scalable =
consumeIf(Token::l_square);
529 dimensions.push_back(value);
534 scalableDims.push_back(scalable);
558 bool allowDynamic,
bool withTrailingX) {
559 auto parseDim = [&]() -> LogicalResult {
563 return emitError(loc,
"expected static shape");
564 dimensions.push_back(ShapedType::kDynamic);
569 dimensions.push_back(value);
575 while (
getToken().isAny(Token::integer, Token::question)) {
582 if (
getToken().isAny(Token::integer, Token::question)) {
583 if (failed(parseDim()))
585 while (
getToken().is(Token::bare_identifier) &&
611 *dimension > (uint64_t)std::numeric_limits<int64_t>::max())
Attributes are known-constant values of operations.
static bool isValidElementType(Type type)
Return true if the specified element type is ok in a memref.
This class implements Optional functionality for ParseResult.
static bool isValidElementType(Type type)
Return true if the specified element type is ok in a tensor.
static std::optional< uint64_t > getUInt64IntegerValue(StringRef spelling)
For an integer token, return its value as an uint64_t.
std::optional< unsigned > getIntTypeBitwidth() const
For an inttype token, return its bitwidth.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
ParseResult parseXInDimensionList()
Parse an 'x' token in a dimension list, handling the case where the x is juxtaposed with an element t...
T getChecked(SMLoc loc, ParamsT &&...params)
Invoke the getChecked method of the given Attribute or Type class, using the provided location to emi...
OptionalParseResult parseOptionalType(Type &type)
Optionally parse a type.
ParseResult parseToken(Token::Kind expectedToken, const Twine &message)
Consume the specified token if present and return success.
ParseResult parseCommaSeparatedListUntil(Token::Kind rightToken, function_ref< ParseResult()> parseElement, bool allowEmptyList=true)
Parse a comma-separated list of elements up until the specified end token.
Type parseType()
Parse an arbitrary type.
ParseResult parseTypeListParens(SmallVectorImpl< Type > &elements)
Parse a parenthesized list of types.
ParseResult parseVectorDimensionList(SmallVectorImpl< int64_t > &dimensions, SmallVectorImpl< bool > &scalableDims)
Parse a dimension list in a vector type.
Type parseMemRefType()
Parse a memref type.
Type parseNonFunctionType()
Parse a non function type.
Type parseExtendedType()
Parse an extended type.
Type parseTupleType()
Parse a tuple type.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error and return failure.
ParserState & state
The Parser is subclassed and reinstantiated.
Attribute parseAttribute(Type type={})
Parse an arbitrary attribute with an optional type.
StringRef getTokenSpelling() const
void consumeToken()
Advance the current lexer onto the next token.
ParseResult parseIntegerInDimensionList(int64_t &value)
Type parseComplexType()
Parse a complex type.
ParseResult parseDimensionListRanked(SmallVectorImpl< int64_t > &dimensions, bool allowDynamic=true, bool withTrailingX=true)
Parse a dimension list of a tensor or memref type.
ParseResult parseFunctionResultTypes(SmallVectorImpl< Type > &elements)
Parse a function result type.
InFlightDiagnostic emitWrongTokenError(const Twine &message={})
Emit an error about a "wrong token".
ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())
Parse a list of comma-separated items with an optional delimiter.
VectorType parseVectorType()
Parse a vector type.
Type parseFunctionType()
Parse a function type.
OptionalParseResult parseOptionalAttribute(Attribute &attribute, Type type={})
Parse an optional attribute with the provided type.
ParseResult parseTypeListNoParens(SmallVectorImpl< Type > &elements)
Parse a list of types without an enclosing parenthesis.
const Token & getToken() const
Return the current token the parser is inspecting.
MLIRContext * getContext() const
Type parseTensorType()
Parse a tensor type.
bool consumeIf(Token::Kind kind)
If the current token has the specified kind, consume it and return true.
Include the generated interface declarations.