MLIR  20.0.0git
TypeParser.cpp
Go to the documentation of this file.
1 //===- TypeParser.cpp - MLIR Type Parser Implementation -------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the parser for the MLIR Types.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "Parser.h"
14 #include "mlir/IR/AffineMap.h"
17 #include "mlir/IR/BuiltinTypes.h"
18 #include "mlir/IR/OpDefinition.h"
19 #include "mlir/IR/TensorEncoding.h"
20 #include "mlir/IR/Types.h"
21 #include "mlir/Support/LLVM.h"
22 #include "llvm/ADT/STLExtras.h"
23 #include <cassert>
24 #include <cstdint>
25 #include <limits>
26 #include <optional>
27 
28 using namespace mlir;
29 using namespace mlir::detail;
30 
31 /// Optionally parse a type.
33  // There are many different starting tokens for a type, check them here.
34  switch (getToken().getKind()) {
35  case Token::l_paren:
36  case Token::kw_memref:
37  case Token::kw_tensor:
38  case Token::kw_complex:
39  case Token::kw_tuple:
40  case Token::kw_vector:
41  case Token::inttype:
42  case Token::kw_f8E5M2:
43  case Token::kw_f8E4M3:
44  case Token::kw_f8E4M3FN:
45  case Token::kw_f8E5M2FNUZ:
46  case Token::kw_f8E4M3FNUZ:
47  case Token::kw_f8E4M3B11FNUZ:
48  case Token::kw_bf16:
49  case Token::kw_f16:
50  case Token::kw_tf32:
51  case Token::kw_f32:
52  case Token::kw_f64:
53  case Token::kw_f80:
54  case Token::kw_f128:
55  case Token::kw_index:
56  case Token::kw_none:
57  case Token::exclamation_identifier:
58  return failure(!(type = parseType()));
59 
60  default:
61  return std::nullopt;
62  }
63 }
64 
65 /// Parse an arbitrary type.
66 ///
67 /// type ::= function-type
68 /// | non-function-type
69 ///
71  if (getToken().is(Token::l_paren))
72  return parseFunctionType();
73  return parseNonFunctionType();
74 }
75 
76 /// Parse a function result type.
77 ///
78 /// function-result-type ::= type-list-parens
79 /// | non-function-type
80 ///
82  if (getToken().is(Token::l_paren))
83  return parseTypeListParens(elements);
84 
86  if (!t)
87  return failure();
88  elements.push_back(t);
89  return success();
90 }
91 
92 /// Parse a list of types without an enclosing parenthesis. The list must have
93 /// at least one member.
94 ///
95 /// type-list-no-parens ::= type (`,` type)*
96 ///
98  auto parseElt = [&]() -> ParseResult {
99  auto elt = parseType();
100  elements.push_back(elt);
101  return elt ? success() : failure();
102  };
103 
104  return parseCommaSeparatedList(parseElt);
105 }
106 
107 /// Parse a parenthesized list of types.
108 ///
109 /// type-list-parens ::= `(` `)`
110 /// | `(` type-list-no-parens `)`
111 ///
113  if (parseToken(Token::l_paren, "expected '('"))
114  return failure();
115 
116  // Handle empty lists.
117  if (getToken().is(Token::r_paren))
118  return consumeToken(), success();
119 
120  if (parseTypeListNoParens(elements) ||
121  parseToken(Token::r_paren, "expected ')'"))
122  return failure();
123  return success();
124 }
125 
126 /// Parse a complex type.
127 ///
128 /// complex-type ::= `complex` `<` type `>`
129 ///
131  consumeToken(Token::kw_complex);
132 
133  // Parse the '<'.
134  if (parseToken(Token::less, "expected '<' in complex type"))
135  return nullptr;
136 
137  SMLoc elementTypeLoc = getToken().getLoc();
138  auto elementType = parseType();
139  if (!elementType ||
140  parseToken(Token::greater, "expected '>' in complex type"))
141  return nullptr;
142  if (!isa<FloatType>(elementType) && !isa<IntegerType>(elementType))
143  return emitError(elementTypeLoc, "invalid element type for complex"),
144  nullptr;
145 
146  return ComplexType::get(elementType);
147 }
148 
149 /// Parse a function type.
150 ///
151 /// function-type ::= type-list-parens `->` function-result-type
152 ///
154  assert(getToken().is(Token::l_paren));
155 
156  SmallVector<Type, 4> arguments, results;
157  if (parseTypeListParens(arguments) ||
158  parseToken(Token::arrow, "expected '->' in function type") ||
159  parseFunctionResultTypes(results))
160  return nullptr;
161 
162  return builder.getFunctionType(arguments, results);
163 }
164 
165 /// Parse a memref type.
166 ///
167 /// memref-type ::= ranked-memref-type | unranked-memref-type
168 ///
169 /// ranked-memref-type ::= `memref` `<` dimension-list-ranked type
170 /// (`,` layout-specification)? (`,` memory-space)? `>`
171 ///
172 /// unranked-memref-type ::= `memref` `<*x` type (`,` memory-space)? `>`
173 ///
174 /// stride-list ::= `[` (dimension (`,` dimension)*)? `]`
175 /// strided-layout ::= `offset:` dimension `,` `strides: ` stride-list
176 /// layout-specification ::= semi-affine-map | strided-layout | attribute
177 /// memory-space ::= integer-literal | attribute
178 ///
180  SMLoc loc = getToken().getLoc();
181  consumeToken(Token::kw_memref);
182 
183  if (parseToken(Token::less, "expected '<' in memref type"))
184  return nullptr;
185 
186  bool isUnranked;
187  SmallVector<int64_t, 4> dimensions;
188 
189  if (consumeIf(Token::star)) {
190  // This is an unranked memref type.
191  isUnranked = true;
192  if (parseXInDimensionList())
193  return nullptr;
194 
195  } else {
196  isUnranked = false;
197  if (parseDimensionListRanked(dimensions))
198  return nullptr;
199  }
200 
201  // Parse the element type.
202  auto typeLoc = getToken().getLoc();
203  auto elementType = parseType();
204  if (!elementType)
205  return nullptr;
206 
207  // Check that memref is formed from allowed types.
208  if (!BaseMemRefType::isValidElementType(elementType))
209  return emitError(typeLoc, "invalid memref element type"), nullptr;
210 
211  MemRefLayoutAttrInterface layout;
212  Attribute memorySpace;
213 
214  auto parseElt = [&]() -> ParseResult {
215  // Either it is MemRefLayoutAttrInterface or memory space attribute.
216  Attribute attr = parseAttribute();
217  if (!attr)
218  return failure();
219 
220  if (isa<MemRefLayoutAttrInterface>(attr)) {
221  layout = cast<MemRefLayoutAttrInterface>(attr);
222  } else if (memorySpace) {
223  return emitError("multiple memory spaces specified in memref type");
224  } else {
225  memorySpace = attr;
226  return success();
227  }
228 
229  if (isUnranked)
230  return emitError("cannot have affine map for unranked memref type");
231  if (memorySpace)
232  return emitError("expected memory space to be last in memref type");
233 
234  return success();
235  };
236 
237  // Parse a list of mappings and address space if present.
238  if (!consumeIf(Token::greater)) {
239  // Parse comma separated list of affine maps, followed by memory space.
240  if (parseToken(Token::comma, "expected ',' or '>' in memref type") ||
241  parseCommaSeparatedListUntil(Token::greater, parseElt,
242  /*allowEmptyList=*/false)) {
243  return nullptr;
244  }
245  }
246 
247  if (isUnranked)
248  return getChecked<UnrankedMemRefType>(loc, elementType, memorySpace);
249 
250  return getChecked<MemRefType>(loc, dimensions, elementType, layout,
251  memorySpace);
252 }
253 
254 /// Parse any type except the function type.
255 ///
256 /// non-function-type ::= integer-type
257 /// | index-type
258 /// | float-type
259 /// | extended-type
260 /// | vector-type
261 /// | tensor-type
262 /// | memref-type
263 /// | complex-type
264 /// | tuple-type
265 /// | none-type
266 ///
267 /// index-type ::= `index`
268 /// float-type ::= `f16` | `bf16` | `f32` | `f64` | `f80` | `f128`
269 /// none-type ::= `none`
270 ///
272  switch (getToken().getKind()) {
273  default:
274  return (emitWrongTokenError("expected non-function type"), nullptr);
275  case Token::kw_memref:
276  return parseMemRefType();
277  case Token::kw_tensor:
278  return parseTensorType();
279  case Token::kw_complex:
280  return parseComplexType();
281  case Token::kw_tuple:
282  return parseTupleType();
283  case Token::kw_vector:
284  return parseVectorType();
285  // integer-type
286  case Token::inttype: {
287  auto width = getToken().getIntTypeBitwidth();
288  if (!width.has_value())
289  return (emitError("invalid integer width"), nullptr);
290  if (*width > IntegerType::kMaxWidth) {
291  emitError(getToken().getLoc(), "integer bitwidth is limited to ")
292  << IntegerType::kMaxWidth << " bits";
293  return nullptr;
294  }
295 
296  IntegerType::SignednessSemantics signSemantics = IntegerType::Signless;
297  if (std::optional<bool> signedness = getToken().getIntTypeSignedness())
298  signSemantics = *signedness ? IntegerType::Signed : IntegerType::Unsigned;
299 
300  consumeToken(Token::inttype);
301  return IntegerType::get(getContext(), *width, signSemantics);
302  }
303 
304  // float-type
305  case Token::kw_f8E5M2:
306  consumeToken(Token::kw_f8E5M2);
307  return builder.getFloat8E5M2Type();
308  case Token::kw_f8E4M3:
309  consumeToken(Token::kw_f8E4M3);
310  return builder.getFloat8E4M3Type();
311  case Token::kw_f8E4M3FN:
312  consumeToken(Token::kw_f8E4M3FN);
313  return builder.getFloat8E4M3FNType();
314  case Token::kw_f8E5M2FNUZ:
315  consumeToken(Token::kw_f8E5M2FNUZ);
317  case Token::kw_f8E4M3FNUZ:
318  consumeToken(Token::kw_f8E4M3FNUZ);
320  case Token::kw_f8E4M3B11FNUZ:
321  consumeToken(Token::kw_f8E4M3B11FNUZ);
323  case Token::kw_bf16:
324  consumeToken(Token::kw_bf16);
325  return builder.getBF16Type();
326  case Token::kw_f16:
327  consumeToken(Token::kw_f16);
328  return builder.getF16Type();
329  case Token::kw_tf32:
330  consumeToken(Token::kw_tf32);
331  return builder.getTF32Type();
332  case Token::kw_f32:
333  consumeToken(Token::kw_f32);
334  return builder.getF32Type();
335  case Token::kw_f64:
336  consumeToken(Token::kw_f64);
337  return builder.getF64Type();
338  case Token::kw_f80:
339  consumeToken(Token::kw_f80);
340  return builder.getF80Type();
341  case Token::kw_f128:
342  consumeToken(Token::kw_f128);
343  return builder.getF128Type();
344 
345  // index-type
346  case Token::kw_index:
347  consumeToken(Token::kw_index);
348  return builder.getIndexType();
349 
350  // none-type
351  case Token::kw_none:
352  consumeToken(Token::kw_none);
353  return builder.getNoneType();
354 
355  // extended type
356  case Token::exclamation_identifier:
357  return parseExtendedType();
358 
359  // Handle completion of a dialect type.
360  case Token::code_complete:
361  if (getToken().isCodeCompletionFor(Token::exclamation_identifier))
362  return parseExtendedType();
363  return codeCompleteType();
364  }
365 }
366 
367 /// Parse a tensor type.
368 ///
369 /// tensor-type ::= `tensor` `<` dimension-list type `>`
370 /// dimension-list ::= dimension-list-ranked | `*x`
371 ///
373  consumeToken(Token::kw_tensor);
374 
375  if (parseToken(Token::less, "expected '<' in tensor type"))
376  return nullptr;
377 
378  bool isUnranked;
379  SmallVector<int64_t, 4> dimensions;
380 
381  if (consumeIf(Token::star)) {
382  // This is an unranked tensor type.
383  isUnranked = true;
384 
385  if (parseXInDimensionList())
386  return nullptr;
387 
388  } else {
389  isUnranked = false;
390  if (parseDimensionListRanked(dimensions))
391  return nullptr;
392  }
393 
394  // Parse the element type.
395  auto elementTypeLoc = getToken().getLoc();
396  auto elementType = parseType();
397 
398  // Parse an optional encoding attribute.
399  Attribute encoding;
400  if (consumeIf(Token::comma)) {
401  auto parseResult = parseOptionalAttribute(encoding);
402  if (parseResult.has_value()) {
403  if (failed(parseResult.value()))
404  return nullptr;
405  if (auto v = dyn_cast_or_null<VerifiableTensorEncoding>(encoding)) {
406  if (failed(v.verifyEncoding(dimensions, elementType,
407  [&] { return emitError(); })))
408  return nullptr;
409  }
410  }
411  }
412 
413  if (!elementType || parseToken(Token::greater, "expected '>' in tensor type"))
414  return nullptr;
415  if (!TensorType::isValidElementType(elementType))
416  return emitError(elementTypeLoc, "invalid tensor element type"), nullptr;
417 
418  if (isUnranked) {
419  if (encoding)
420  return emitError("cannot apply encoding to unranked tensor"), nullptr;
421  return UnrankedTensorType::get(elementType);
422  }
423  return RankedTensorType::get(dimensions, elementType, encoding);
424 }
425 
426 /// Parse a tuple type.
427 ///
428 /// tuple-type ::= `tuple` `<` (type (`,` type)*)? `>`
429 ///
431  consumeToken(Token::kw_tuple);
432 
433  // Parse the '<'.
434  if (parseToken(Token::less, "expected '<' in tuple type"))
435  return nullptr;
436 
437  // Check for an empty tuple by directly parsing '>'.
438  if (consumeIf(Token::greater))
439  return TupleType::get(getContext());
440 
441  // Parse the element types and the '>'.
442  SmallVector<Type, 4> types;
443  if (parseTypeListNoParens(types) ||
444  parseToken(Token::greater, "expected '>' in tuple type"))
445  return nullptr;
446 
447  return TupleType::get(getContext(), types);
448 }
449 
450 /// Parse a vector type.
451 ///
452 /// vector-type ::= `vector` `<` vector-dim-list vector-element-type `>`
453 /// vector-dim-list := (static-dim-list `x`)? (`[` static-dim-list `]` `x`)?
454 /// static-dim-list ::= decimal-literal (`x` decimal-literal)*
455 ///
457  consumeToken(Token::kw_vector);
458 
459  if (parseToken(Token::less, "expected '<' in vector type"))
460  return nullptr;
461 
462  SmallVector<int64_t, 4> dimensions;
463  SmallVector<bool, 4> scalableDims;
464  if (parseVectorDimensionList(dimensions, scalableDims))
465  return nullptr;
466  if (any_of(dimensions, [](int64_t i) { return i <= 0; }))
467  return emitError(getToken().getLoc(),
468  "vector types must have positive constant sizes"),
469  nullptr;
470 
471  // Parse the element type.
472  auto typeLoc = getToken().getLoc();
473  auto elementType = parseType();
474  if (!elementType || parseToken(Token::greater, "expected '>' in vector type"))
475  return nullptr;
476 
477  if (!VectorType::isValidElementType(elementType))
478  return emitError(typeLoc, "vector elements must be int/index/float type"),
479  nullptr;
480 
481  return VectorType::get(dimensions, elementType, scalableDims);
482 }
483 
484 /// Parse a dimension list in a vector type. This populates the dimension list.
485 /// For i-th dimension, `scalableDims[i]` contains either:
486 /// * `false` for a non-scalable dimension (e.g. `4`),
487 /// * `true` for a scalable dimension (e.g. `[4]`).
488 ///
489 /// vector-dim-list := (static-dim-list `x`)?
490 /// static-dim-list ::= static-dim (`x` static-dim)*
491 /// static-dim ::= (decimal-literal | `[` decimal-literal `]`)
492 ///
493 ParseResult
495  SmallVectorImpl<bool> &scalableDims) {
496  // If there is a set of fixed-length dimensions, consume it
497  while (getToken().is(Token::integer) || getToken().is(Token::l_square)) {
498  int64_t value;
499  bool scalable = consumeIf(Token::l_square);
500  if (parseIntegerInDimensionList(value))
501  return failure();
502  dimensions.push_back(value);
503  if (scalable) {
504  if (!consumeIf(Token::r_square))
505  return emitWrongTokenError("missing ']' closing scalable dimension");
506  }
507  scalableDims.push_back(scalable);
508  // Make sure we have an 'x' or something like 'xbf32'.
509  if (parseXInDimensionList())
510  return failure();
511  }
512 
513  return success();
514 }
515 
516 /// Parse a dimension list of a tensor or memref type. This populates the
517 /// dimension list, using ShapedType::kDynamic for the `?` dimensions if
518 /// `allowDynamic` is set and errors out on `?` otherwise. Parsing the trailing
519 /// `x` is configurable.
520 ///
521 /// dimension-list ::= eps | dimension (`x` dimension)*
522 /// dimension-list-with-trailing-x ::= (dimension `x`)*
523 /// dimension ::= `?` | decimal-literal
524 ///
525 /// When `allowDynamic` is not set, this is used to parse:
526 ///
527 /// static-dimension-list ::= eps | decimal-literal (`x` decimal-literal)*
528 /// static-dimension-list-with-trailing-x ::= (dimension `x`)*
529 ParseResult
531  bool allowDynamic, bool withTrailingX) {
532  auto parseDim = [&]() -> LogicalResult {
533  auto loc = getToken().getLoc();
534  if (consumeIf(Token::question)) {
535  if (!allowDynamic)
536  return emitError(loc, "expected static shape");
537  dimensions.push_back(ShapedType::kDynamic);
538  } else {
539  int64_t value;
540  if (failed(parseIntegerInDimensionList(value)))
541  return failure();
542  dimensions.push_back(value);
543  }
544  return success();
545  };
546 
547  if (withTrailingX) {
548  while (getToken().isAny(Token::integer, Token::question)) {
549  if (failed(parseDim()) || failed(parseXInDimensionList()))
550  return failure();
551  }
552  return success();
553  }
554 
555  if (getToken().isAny(Token::integer, Token::question)) {
556  if (failed(parseDim()))
557  return failure();
558  while (getToken().is(Token::bare_identifier) &&
559  getTokenSpelling()[0] == 'x') {
560  if (failed(parseXInDimensionList()) || failed(parseDim()))
561  return failure();
562  }
563  }
564  return success();
565 }
566 
567 ParseResult Parser::parseIntegerInDimensionList(int64_t &value) {
568  // Hexadecimal integer literals (starting with `0x`) are not allowed in
569  // aggregate type declarations. Therefore, `0xf32` should be processed as
570  // a sequence of separate elements `0`, `x`, `f32`.
571  if (getTokenSpelling().size() > 1 && getTokenSpelling()[1] == 'x') {
572  // We can get here only if the token is an integer literal. Hexadecimal
573  // integer literals can only start with `0x` (`1x` wouldn't lex as a
574  // literal, just `1` would, at which point we don't get into this
575  // branch).
576  assert(getTokenSpelling()[0] == '0' && "invalid integer literal");
577  value = 0;
578  state.lex.resetPointer(getTokenSpelling().data() + 1);
579  consumeToken();
580  } else {
581  // Make sure this integer value is in bound and valid.
582  std::optional<uint64_t> dimension = getToken().getUInt64IntegerValue();
583  if (!dimension ||
584  *dimension > (uint64_t)std::numeric_limits<int64_t>::max())
585  return emitError("invalid dimension");
586  value = (int64_t)*dimension;
587  consumeToken(Token::integer);
588  }
589  return success();
590 }
591 
592 /// Parse an 'x' token in a dimension list, handling the case where the x is
593 /// juxtaposed with an element type, as in "xf32", leaving the "f32" as the next
594 /// token.
596  if (getToken().isNot(Token::bare_identifier) || getTokenSpelling()[0] != 'x')
597  return emitWrongTokenError("expected 'x' in dimension list");
598 
599  // If we had a prefix of 'x', lex the next token immediately after the 'x'.
600  if (getTokenSpelling().size() != 1)
601  state.lex.resetPointer(getTokenSpelling().data() + 1);
602 
603  // Consume the 'x'.
604  consumeToken(Token::bare_identifier);
605 
606  return success();
607 }
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
Attributes are known-constant values of operations.
Definition: Attributes.h:25
static bool isValidElementType(Type type)
Return true if the specified element type is ok in a memref.
Definition: BuiltinTypes.h:406
FloatType getFloat8E5M2Type()
Definition: Builders.cpp:37
FloatType getF80Type()
Definition: Builders.cpp:71
FloatType getF128Type()
Definition: Builders.cpp:73
FloatType getF32Type()
Definition: Builders.cpp:67
FloatType getTF32Type()
Definition: Builders.cpp:65
FloatType getFloat8E4M3B11FNUZType()
Definition: Builders.cpp:57
FunctionType getFunctionType(TypeRange inputs, TypeRange results)
Definition: Builders.cpp:100
NoneType getNoneType()
Definition: Builders.cpp:108
FloatType getFloat8E4M3Type()
Definition: Builders.cpp:41
FloatType getF16Type()
Definition: Builders.cpp:63
FloatType getBF16Type()
Definition: Builders.cpp:61
FloatType getFloat8E4M3FNType()
Definition: Builders.cpp:45
FloatType getFloat8E4M3FNUZType()
Definition: Builders.cpp:53
IndexType getIndexType()
Definition: Builders.cpp:75
FloatType getFloat8E5M2FNUZType()
Definition: Builders.cpp:49
FloatType getF64Type()
Definition: Builders.cpp:69
void resetPointer(const char *newPointer)
Change the position of the lexer cursor.
Definition: Lexer.h:38
This class implements Optional functionality for ParseResult.
Definition: OpDefinition.h:39
static bool isValidElementType(Type type)
Return true if the specified element type is ok in a tensor.
SMLoc getLoc() const
Definition: Token.cpp:24
static std::optional< uint64_t > getUInt64IntegerValue(StringRef spelling)
For an integer token, return its value as an uint64_t.
Definition: Token.cpp:45
std::optional< unsigned > getIntTypeBitwidth() const
For an inttype token, return its bitwidth.
Definition: Token.cpp:64
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
ParseResult parseXInDimensionList()
Parse an 'x' token in a dimension list, handling the case where the x is juxtaposed with an element t...
Definition: TypeParser.cpp:595
OptionalParseResult parseOptionalType(Type &type)
Optionally parse a type.
Definition: TypeParser.cpp:32
ParseResult parseToken(Token::Kind expectedToken, const Twine &message)
Consume the specified token if present and return success.
Definition: Parser.cpp:267
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.
Definition: Parser.cpp:173
Builder builder
Definition: Parser.h:30
Type parseType()
Parse an arbitrary type.
Definition: TypeParser.cpp:70
ParseResult parseTypeListParens(SmallVectorImpl< Type > &elements)
Parse a parenthesized list of types.
Definition: TypeParser.cpp:112
ParseResult parseVectorDimensionList(SmallVectorImpl< int64_t > &dimensions, SmallVectorImpl< bool > &scalableDims)
Parse a dimension list in a vector type.
Definition: TypeParser.cpp:494
Type parseMemRefType()
Parse a memref type.
Definition: TypeParser.cpp:179
Type parseNonFunctionType()
Parse a non function type.
Definition: TypeParser.cpp:271
Type codeCompleteType()
Definition: Parser.cpp:502
Type parseExtendedType()
Parse an extended type.
Type parseTupleType()
Parse a tuple type.
Definition: TypeParser.cpp:430
InFlightDiagnostic emitError(const Twine &message={})
Emit an error and return failure.
Definition: Parser.cpp:192
ParserState & state
The Parser is subclassed and reinstantiated.
Definition: Parser.h:355
Attribute parseAttribute(Type type={})
Parse an arbitrary attribute with an optional type.
StringRef getTokenSpelling() const
Definition: Parser.h:103
void consumeToken()
Advance the current lexer onto the next token.
Definition: Parser.h:118
ParseResult parseIntegerInDimensionList(int64_t &value)
Definition: TypeParser.cpp:567
Type parseComplexType()
Parse a complex type.
Definition: TypeParser.cpp:130
ParseResult parseDimensionListRanked(SmallVectorImpl< int64_t > &dimensions, bool allowDynamic=true, bool withTrailingX=true)
Parse a dimension list of a tensor or memref type.
Definition: TypeParser.cpp:530
ParseResult parseFunctionResultTypes(SmallVectorImpl< Type > &elements)
Parse a function result type.
Definition: TypeParser.cpp:81
MLIRContext * getContext() const
Definition: Parser.h:37
InFlightDiagnostic emitWrongTokenError(const Twine &message={})
Emit an error about a "wrong token".
Definition: Parser.cpp:215
ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())
Parse a list of comma-separated items with an optional delimiter.
Definition: Parser.cpp:84
VectorType parseVectorType()
Parse a vector type.
Definition: TypeParser.cpp:456
Type parseFunctionType()
Parse a function type.
Definition: TypeParser.cpp:153
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.
Definition: TypeParser.cpp:97
const Token & getToken() const
Return the current token the parser is inspecting.
Definition: Parser.h:102
Type parseTensorType()
Parse a tensor type.
Definition: TypeParser.cpp:372
bool consumeIf(Token::Kind kind)
If the current token has the specified kind, consume it and return true.
Definition: Parser.h:110
AttrTypeReplacer.
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
Lexer lex
The lexer for the source file we're parsing.
Definition: ParserState.h:66