52 case Token::kw_affine_map: {
56 if (
parseToken(Token::less,
"expected '<' in affine map") ||
58 parseToken(Token::greater,
"expected '>' in affine map"))
60 return AffineMapAttr::get(map);
62 case Token::kw_affine_set: {
66 if (
parseToken(Token::less,
"expected '<' in integer set") ||
68 parseToken(Token::greater,
"expected '>' in integer set"))
70 return IntegerSetAttr::get(set);
74 case Token::l_square: {
77 auto parseElt = [&]() -> ParseResult {
79 return elements.back() ?
success() : failure();
84 return builder.getArrayAttr(elements);
90 return builder.getBoolAttr(
false);
93 return builder.getBoolAttr(
true);
100 case Token::kw_dense_resource:
104 case Token::kw_array:
108 case Token::l_brace: {
116 case Token::hash_identifier:
120 case Token::floatliteral:
128 if (
getToken().is(Token::floatliteral))
132 "expected constant integer or floating point value"),
137 case Token::kw_loc: {
141 if (
parseToken(Token::l_paren,
"expected '(' in inline location") ||
143 parseToken(Token::r_paren,
"expected ')' in inline location"))
149 case Token::kw_sparse:
153 case Token::kw_strided:
157 case Token::kw_distinct:
161 case Token::string: {
168 return type ? StringAttr::get(val, type)
173 case Token::at_identifier: {
178 referenceLocations.push_back(
getToken().getLocRange());
185 std::vector<FlatSymbolRefAttr> nestedRefs;
186 while (
getToken().is(Token::colon)) {
191 if (
getToken().isNot(Token::eof, Token::error)) {
192 state.lex.resetPointer(curPointer);
199 if (
getToken().isNot(Token::at_identifier)) {
200 emitError(curLoc,
"expected nested symbol reference identifier");
207 referenceLocations.push_back(
getToken().getLocRange());
211 nestedRefs.push_back(SymbolRefAttr::get(
getContext(), nameStr));
213 SymbolRefAttr symbolRefAttr =
214 SymbolRefAttr::get(
getContext(), nameStr, nestedRefs);
218 state.asmState->addUses(symbolRefAttr, referenceLocations);
219 return symbolRefAttr;
228 case Token::code_complete:
229 if (
getToken().isCodeCompletionFor(Token::hash_identifier))
248 case Token::at_identifier:
249 case Token::floatliteral:
251 case Token::hash_identifier:
252 case Token::kw_affine_map:
253 case Token::kw_affine_set:
254 case Token::kw_dense:
255 case Token::kw_dense_resource:
256 case Token::kw_false:
258 case Token::kw_sparse:
262 case Token::l_square:
266 return success(attribute !=
nullptr);
273 attribute = TypeAttr::get(type);
297 llvm::SmallDenseSet<StringAttr> seenKeys;
298 auto parseElt = [&]() -> ParseResult {
300 std::optional<StringAttr> nameId;
303 else if (
getToken().isAny(Token::bare_identifier, Token::inttype) ||
310 return emitError(
"expected valid attribute name");
312 if (!seenKeys.insert(*nameId).second)
314 << nameId->getValue() <<
"' in dictionary attribute";
318 auto splitName = nameId->strref().split(
'.');
319 if (!splitName.second.empty())
337 " in attribute dictionary");
353 if (!isa<FloatType>(type))
354 return (
emitError(
"floating point value not valid for specified type"),
358 std::optional<APFloat>
result;
362 return FloatAttr::get(type, *
result);
368 StringRef spelling) {
371 bool isHex = spelling.size() > 1 && spelling[1] ==
'x';
372 if (spelling.getAsInteger(isHex ? 0 : 10,
result))
376 unsigned width = type.
isIndex() ? IndexType::kInternalStorageBitWidth
379 if (width >
result.getBitWidth()) {
381 }
else if (width <
result.getBitWidth()) {
384 if (
result.countl_zero() <
result.getBitWidth() - width)
395 }
else if (isNegative) {
399 if (!
result.isSignBitSet())
422 type =
builder.getIntegerType(64);
427 if (
auto floatType = dyn_cast<FloatType>(type)) {
428 std::optional<APFloat>
result;
430 floatType.getFloatSemantics())))
432 return FloatAttr::get(floatType, *
result);
435 if (!isa<IntegerType, IndexType>(type))
436 return emitError(loc,
"integer literal not valid for specified type"),
441 "negative integer literal not valid for unsigned integer type");
447 return emitError(loc,
"integer constant out of range for attribute"),
449 return builder.getIntegerAttr(type, *apInt);
461 result = std::move(*value);
465 tok.
getLoc(),
"expected string containing hex digits starting with `0x`");
472class TensorLiteralParser {
474 TensorLiteralParser(Parser &p) : p(p) {}
478 ParseResult
parse(
bool allowHex);
482 DenseElementsAttr getAttr(SMLoc loc, ShapedType type);
484 ArrayRef<int64_t>
getShape()
const {
return shape; }
488 ParseResult getIntAttrElements(SMLoc loc, Type eltTy,
489 std::vector<APInt> &intValues);
492 ParseResult getFloatAttrElements(SMLoc loc, FloatType eltTy,
493 std::vector<APFloat> &floatValues);
496 DenseElementsAttr getStringAttr(SMLoc loc, ShapedType type, Type eltTy);
499 DenseElementsAttr getHexAttr(SMLoc loc, ShapedType type);
505 ParseResult parseElement();
513 ParseResult parseList(SmallVectorImpl<int64_t> &dims);
516 ParseResult parseHexElements();
521 SmallVector<int64_t, 4> shape;
524 std::vector<std::pair<bool, Token>> storage;
527 std::optional<Token> hexStorage;
533ParseResult TensorLiteralParser::parse(
bool allowHex) {
535 if (allowHex && p.getToken().is(Token::string)) {
536 hexStorage = p.getToken();
537 p.consumeToken(Token::string);
541 if (p.getToken().is(Token::l_square))
542 return parseList(shape);
543 return parseElement();
548DenseElementsAttr TensorLiteralParser::getAttr(SMLoc loc, ShapedType type) {
549 Type eltType = type.getElementType();
554 return getHexAttr(loc, type);
558 if (!shape.empty() &&
getShape() != type.getShape()) {
559 p.emitError(loc) <<
"inferred shape of elements literal ([" <<
getShape()
560 <<
"]) does not match type ([" << type.getShape() <<
"])";
565 if (!hexStorage && storage.empty() && type.getNumElements()) {
566 p.emitError(loc) <<
"parsed zero elements, but type (" << type
567 <<
") expected at least 1";
572 bool isComplex =
false;
573 if (ComplexType complexTy = dyn_cast<ComplexType>(eltType)) {
574 eltType = complexTy.getElementType();
578 bool isSplat = shape.empty() && type.getNumElements() != 0;
579 if (isSplat && storage.size() != 2) {
580 p.emitError(loc) <<
"parsed " << storage.size() <<
" elements, but type ("
581 << complexTy <<
") expected 2 elements";
584 if (!shape.empty() &&
585 storage.size() !=
static_cast<size_t>(type.getNumElements()) * 2) {
586 p.emitError(loc) <<
"parsed " << storage.size() <<
" elements, but type ("
587 << type <<
") expected " << type.getNumElements() * 2
595 std::vector<APInt> intValues;
596 if (
failed(getIntAttrElements(loc, eltType, intValues)))
600 auto complexData = llvm::ArrayRef(
602 intValues.size() / 2);
608 if (isa<MXI8Type>(eltType)) {
609 std::vector<APInt> intValues;
610 Type storageType = IntegerType::get(p.getContext(), 8);
611 if (
failed(getIntAttrElements(loc, storageType, intValues)))
613 SmallVector<Attribute> attrs;
614 attrs.reserve(intValues.size());
615 for (
const APInt &value : intValues)
616 attrs.push_back(IntegerAttr::get(storageType, value));
620 if (FloatType floatTy = dyn_cast<FloatType>(eltType)) {
621 std::vector<APFloat> floatValues;
622 if (
failed(getFloatAttrElements(loc, floatTy, floatValues)))
626 auto complexData = llvm::ArrayRef(
628 floatValues.size() / 2);
635 return getStringAttr(loc, type, type.getElementType());
640TensorLiteralParser::getIntAttrElements(SMLoc loc, Type eltTy,
641 std::vector<APInt> &intValues) {
642 intValues.reserve(storage.size());
644 for (
const auto &signAndToken : storage) {
645 bool isNegative = signAndToken.first;
646 const Token &token = signAndToken.second;
647 auto tokenLoc = token.
getLoc();
649 if (isNegative && isUintType) {
650 return p.emitError(tokenLoc)
651 <<
"expected unsigned integer elements, but parsed negative value";
655 if (token.
is(Token::floatliteral)) {
656 return p.emitError(tokenLoc)
657 <<
"expected integer elements, but parsed floating-point";
660 if (token.
is(Token::string)) {
661 return p.emitError(tokenLoc)
662 <<
"expected integer elements, but parsed string";
664 assert(token.
isAny(Token::integer, Token::kw_true, Token::kw_false) &&
665 "unexpected token type");
666 if (token.
isAny(Token::kw_true, Token::kw_false)) {
668 return p.emitError(tokenLoc)
669 <<
"expected i1 type for 'true' or 'false' values";
671 APInt apInt(1, token.
is(Token::kw_true),
false);
672 intValues.push_back(apInt);
677 std::optional<APInt> apInt =
680 return p.emitError(tokenLoc,
"integer constant out of range for type");
681 intValues.push_back(*apInt);
688TensorLiteralParser::getFloatAttrElements(SMLoc loc, FloatType eltTy,
689 std::vector<APFloat> &floatValues) {
690 floatValues.reserve(storage.size());
691 for (
const auto &signAndToken : storage) {
692 bool isNegative = signAndToken.first;
693 const Token &token = signAndToken.second;
694 std::optional<APFloat>
result;
695 if (
failed(p.parseFloatFromLiteral(
result, token, isNegative,
696 eltTy.getFloatSemantics())))
698 floatValues.push_back(*
result);
704DenseElementsAttr TensorLiteralParser::getStringAttr(SMLoc loc, ShapedType type,
706 if (hexStorage.has_value()) {
707 auto stringValue = hexStorage->getStringValue();
708 return DenseStringElementsAttr::get(type, {stringValue});
711 std::vector<std::string> stringValues;
712 std::vector<StringRef> stringRefValues;
713 stringValues.reserve(storage.size());
714 stringRefValues.reserve(storage.size());
716 for (
auto val : storage) {
717 if (!val.second.is(Token::string)) {
718 p.emitError(loc) <<
"expected string token, got "
719 << val.second.getSpelling();
722 stringValues.push_back(val.second.getStringValue());
723 stringRefValues.emplace_back(stringValues.back());
726 return DenseStringElementsAttr::get(type, stringRefValues);
730DenseElementsAttr TensorLiteralParser::getHexAttr(SMLoc loc, ShapedType type) {
731 Type elementType = type.getElementType();
733 !isa<ComplexType, MXI8Type>(elementType)) {
734 p.emitError(loc) <<
"expected floating-point, integer, complex, or mxi8 "
744 ArrayRef<char> rawData(data);
746 p.emitError(loc) <<
"elements hex data size is invalid for provided type: "
752 if (isa<MXI8Type>(elementType))
755 if (llvm::endianness::native == llvm::endianness::big) {
760 SmallVector<char, 64> outDataVec(rawData.size());
761 MutableArrayRef<char> convRawData(outDataVec);
762 DenseTypedElementsAttr::convertEndianOfArrayRefForBEmachine(
763 rawData, convRawData, type);
770ParseResult TensorLiteralParser::parseElement() {
771 switch (p.getToken().getKind()) {
774 case Token::kw_false:
775 case Token::floatliteral:
777 storage.emplace_back(
false, p.getToken());
783 p.consumeToken(Token::minus);
784 if (!p.getToken().isAny(Token::floatliteral, Token::integer))
785 return p.emitError(
"expected integer or floating point literal");
786 storage.emplace_back(
true, p.getToken());
791 storage.emplace_back(
false, p.getToken());
797 p.consumeToken(Token::l_paren);
798 if (parseElement() ||
799 p.parseToken(Token::comma,
"expected ',' between complex elements") ||
801 p.parseToken(Token::r_paren,
"expected ')' after complex elements"))
806 return p.emitError(
"expected element literal of primitive type");
818ParseResult TensorLiteralParser::parseList(SmallVectorImpl<int64_t> &dims) {
819 auto checkDims = [&](
const SmallVectorImpl<int64_t> &prevDims,
820 const SmallVectorImpl<int64_t> &newDims) -> ParseResult {
821 if (prevDims == newDims)
823 return p.emitError(
"tensor literal is invalid; ranks are not consistent "
828 SmallVector<int64_t, 4> newDims;
830 auto parseOneElement = [&]() -> ParseResult {
831 SmallVector<int64_t, 4> thisDims;
832 if (p.getToken().getKind() == Token::l_square) {
833 if (parseList(thisDims))
835 }
else if (parseElement()) {
840 return checkDims(newDims, thisDims);
845 if (p.parseCommaSeparatedList(Parser::Delimiter::Square, parseOneElement))
850 dims.push_back(size);
851 dims.append(newDims.begin(), newDims.end());
862class DenseArrayElementParser {
864 explicit DenseArrayElementParser(Type type) : type(type) {}
867 ParseResult parseIntegerElement(Parser &p);
870 ParseResult parseFloatElement(Parser &p);
873 DenseArrayAttr getAttr() {
return DenseArrayAttr::get(type, size, rawData); }
877 void append(
const APInt &data);
882 std::vector<char> rawData;
888void DenseArrayElementParser::append(
const APInt &data) {
889 if (data.getBitWidth()) {
890 assert(data.getBitWidth() % 8 == 0);
891 unsigned byteSize = data.getBitWidth() / 8;
892 size_t offset = rawData.size();
893 rawData.insert(rawData.end(), byteSize, 0);
894 llvm::StoreIntToMemory(
895 data,
reinterpret_cast<uint8_t *
>(rawData.data() + offset), byteSize);
900ParseResult DenseArrayElementParser::parseIntegerElement(
Parser &p) {
901 bool isNegative = p.
consumeIf(Token::minus);
904 std::optional<APInt> value;
907 if (!type.isInteger(1))
908 return p.
emitError(
"expected i1 type for 'true' or 'false' values");
909 value = APInt(8, p.
getToken().
is(Token::kw_true),
910 !type.isUnsignedInteger());
912 }
else if (p.
consumeIf(Token::integer)) {
913 if (type.isInteger(1))
914 return p.
emitError(
"expected 'true' or 'false' values for i1 type");
917 return p.
emitError(
"integer constant out of range");
919 return p.
emitError(
"expected integer literal");
925ParseResult DenseArrayElementParser::parseFloatElement(
Parser &p) {
926 bool isNegative = p.
consumeIf(Token::minus);
928 std::optional<APFloat> fromIntLit;
931 cast<FloatType>(type).getFloatSemantics())))
934 append(fromIntLit->bitcastToAPInt());
941 if (
parseToken(Token::less,
"expected '<' after 'array'"))
947 emitError(typeLoc,
"expected an integer or floating point type");
954 emitError(typeLoc,
"expected integer or float type, got: ") << eltType;
958 emitError(typeLoc,
"element type bitwidth must be a multiple of 8");
964 return DenseArrayAttr::get(eltType, 0, {});
966 if (
parseToken(Token::colon,
"expected ':' after dense array type"))
969 DenseArrayElementParser eltParser(eltType);
970 if (isa<IntegerType>(eltType)) {
972 [&] {
return eltParser.parseIntegerElement(*
this); }))
976 [&] {
return eltParser.parseFloatElement(*
this); }))
979 if (
parseToken(Token::greater,
"expected '>' to close an array attribute"))
981 return eltParser.getAttr();
1004 if (failed(*typeResult))
1007 auto shapedType = dyn_cast<ShapedType>(type);
1009 p.
emitError(typeLoc,
"expected a shaped type for dense elements");
1012 if (!shapedType.hasStaticShape()) {
1013 p.
emitError(typeLoc,
"dense elements type must have static shape");
1018 auto denseEltType = dyn_cast<DenseElementType>(shapedType.getElementType());
1019 if (!denseEltType) {
1021 "element type must implement DenseElementTypeInterface "
1022 "for type-first dense syntax");
1027 if (p.
parseToken(Token::colon,
"expected ':' after type in dense attribute"))
1034 auto parseSingleElement = [&]() -> ParseResult {
1038 if (failed(denseEltType.convertFromAttribute(elemAttr, rawData))) {
1039 p.
emitError(
"incompatible attribute for element type");
1049 if (remainingShape.empty())
1050 return parseSingleElement();
1053 int64_t expectedCount = remainingShape.front();
1057 auto parseOne = [&]() -> ParseResult {
1058 if (parseElements(innerShape))
1067 if (actualCount != expectedCount) {
1068 p.
emitError() <<
"expected " << expectedCount
1069 <<
" elements in dimension, got " << actualCount;
1078 if (parseSingleElement())
1080 }
else if (shapedType.getShape().empty()) {
1082 p.
emitError(loc,
"expected single element for scalar type, got list");
1086 if (parseElements(shapedType.getShape()))
1090 if (p.
parseToken(Token::greater,
"expected '>' to close dense attribute"))
1101 if (
parseToken(Token::less,
"expected '<' after 'dense'"))
1105 FailureOr<Attribute> typedResult =
1107 if (failed(typedResult))
1110 return *typedResult;
1114 TensorLiteralParser literalParser(*
this);
1116 if (literalParser.parse(
true) ||
1124 return literalParser.getAttr(attribLoc, type);
1130 if (
parseToken(Token::less,
"expected '<' after 'dense_resource'"))
1134 FailureOr<AsmDialectResourceHandle> rawHandle =
1136 if (failed(rawHandle) ||
parseToken(Token::greater,
"expected '>'"))
1139 auto *handle = dyn_cast<DenseResourceElementsHandle>(&*rawHandle);
1141 return emitError(loc,
"invalid `dense_resource` handle type"),
nullptr;
1144 SMLoc typeLoc = loc;
1151 ShapedType shapedType = dyn_cast<ShapedType>(attrType);
1153 emitError(typeLoc,
"`dense_resource` expected a shaped type");
1157 return DenseResourceElementsAttr::get(shapedType, *handle);
1168 if (
parseToken(Token::colon,
"expected ':'"))
1174 auto sType = dyn_cast<ShapedType>(type);
1176 emitError(loc,
"elements literal must be a shaped type");
1180 if (!sType.hasStaticShape()) {
1181 emitError(loc,
"elements literal type must have static shape");
1192 if (
parseToken(Token::less,
"Expected '<' after 'sparse'"))
1206 ShapedType indicesType =
1207 RankedTensorType::get({0, type.getRank()}, indiceEltType);
1208 ShapedType valuesType = RankedTensorType::get({0}, type.getElementType());
1217 TensorLiteralParser indiceParser(*
this);
1218 if (indiceParser.parse(
false))
1221 if (
parseToken(Token::comma,
"expected ','"))
1226 TensorLiteralParser valuesParser(*
this);
1227 if (valuesParser.parse(
true))
1230 if (
parseToken(Token::greater,
"expected '>'"))
1242 ShapedType indicesType;
1243 if (indiceParser.getShape().empty()) {
1244 indicesType = RankedTensorType::get({1, type.getRank()}, indiceEltType);
1247 indicesType = RankedTensorType::get(indiceParser.getShape(), indiceEltType);
1249 auto indices = indiceParser.getAttr(indicesLoc, indicesType);
1256 auto valuesEltType = type.getElementType();
1257 ShapedType valuesType =
1258 valuesParser.getShape().empty()
1259 ? RankedTensorType::get({indicesType.getDimSize(0)}, valuesEltType)
1260 : RankedTensorType::get(valuesParser.getShape(), valuesEltType);
1261 auto values = valuesParser.getAttr(valuesLoc, valuesType);
1272 auto errorEmitter = [&] {
return emitError(loc); };
1275 if (failed(
parseToken(Token::less,
"expected '<' after 'strided'")) ||
1276 failed(
parseToken(Token::l_square,
"expected '['")))
1282 auto parseStrideOrOffset = [&]() -> std::optional<int64_t> {
1284 return ShapedType::kDynamic;
1288 emitError(loc,
"expected a 64-bit signed integer or '?'");
1289 return std::nullopt;
1292 bool negative =
consumeIf(Token::minus);
1294 if (
getToken().is(Token::integer)) {
1297 *value >
static_cast<uint64_t
>(std::numeric_limits<int64_t>::max()))
1312 if (!
getToken().is(Token::r_square)) {
1314 std::optional<int64_t> stride = parseStrideOrOffset();
1317 strides.push_back(*stride);
1321 if (failed(
parseToken(Token::r_square,
"expected ']'")))
1326 if (failed(StridedLayoutAttr::verify(errorEmitter,
1329 return StridedLayoutAttr::get(
getContext(), 0, strides);
1332 if (failed(
parseToken(Token::comma,
"expected ','")) ||
1333 failed(
parseToken(Token::kw_offset,
"expected 'offset' after comma")) ||
1334 failed(
parseToken(Token::colon,
"expected ':' after 'offset'")))
1337 std::optional<int64_t> offset = parseStrideOrOffset();
1338 if (!offset || failed(
parseToken(Token::greater,
"expected '>'")))
1341 if (failed(StridedLayoutAttr::verify(errorEmitter, *offset, strides)))
1343 return StridedLayoutAttr::get(
getContext(), *offset, strides);
1355 if (
parseToken(Token::l_square,
"expected '[' after 'distinct'"))
1360 if (
parseToken(Token::integer,
"expected distinct ID"))
1364 emitError(
"expected an unsigned 64-bit integer");
1369 if (
parseToken(Token::r_square,
"expected ']' to close distinct ID") ||
1370 parseToken(Token::less,
"expected '<' after distinct ID"))
1374 if (
getToken().is(Token::greater)) {
1376 referencedAttr =
builder.getUnitAttr();
1379 if (!referencedAttr) {
1384 if (
parseToken(Token::greater,
"expected '>' to close distinct attribute"))
1392 state.symbols.distinctAttributes;
1393 auto it = distinctAttrs.find(*value);
1394 if (it == distinctAttrs.end()) {
1396 it = distinctAttrs.try_emplace(*value, distinctAttr).first;
1397 }
else if (it->getSecond().getReferencedAttr() != referencedAttr) {
1398 emitError(loc,
"referenced attribute does not match previous definition: ")
1399 << it->getSecond().getReferencedAttr();
1403 return it->getSecond();
static FailureOr< Attribute > parseDenseElementsAttrTyped(Parser &p, SMLoc loc)
Try to parse a dense elements attribute with the type-first syntax.
static std::optional< APInt > buildAttributeAPInt(Type type, bool isNegative, StringRef spelling)
Construct an APint from a parsed value, a known attribute type and sign.
static ParseResult parseElementAttrHexValues(Parser &parser, Token tok, std::string &result)
Parse elements values stored within a hex string.
static ArrayRef< int64_t > getShape(Type type)
Returns the shape of the given type.
static const llvm::fltSemantics * getFloatSemantics(TruncfSrcElemTypes etype)
Float semantics the element type attributes of xevm.truncf and xevm.extf stand for.
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Attributes are known-constant values of operations.
static DenseElementsAttr getFromRawBuffer(ShapedType type, ArrayRef< char > rawBuffer)
Construct a dense elements attribute from a raw buffer representing the data for this attribute.
static bool isValidRawBuffer(ShapedType type, ArrayRef< char > rawBuffer)
Returns true if the given buffer is a valid raw buffer for the given type.
static DenseElementsAttr get(ShapedType type, ArrayRef< Attribute > values)
Constructs a dense elements attribute from an array of element values.
An attribute that associates a referenced attribute with a unique identifier.
static DistinctAttr create(Attribute referencedAttr)
Creates a distinct attribute that associates a referenced attribute with a unique identifier.
An integer set representing a conjunction of one or more affine equalities and inequalities.
Location objects represent source locations information in MLIR.
T * getOrLoadDialect()
Get (or create) a dialect for the given derived dialect type.
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
DictionaryAttr getDictionary(MLIRContext *context) const
Return a dictionary attribute for the underlying dictionary.
void push_back(NamedAttribute newAttribute)
Add an attribute with the specified name.
This class implements Optional functionality for ParseResult.
bool has_value() const
Returns true if we contain a valid ParseResult value.
This represents a token in the MLIR syntax.
std::string getStringValue() const
Given a token containing a string literal, return its value, including removing the quote characters ...
std::string getSymbolReference() const
Given a token containing a symbol reference, return the unescaped string value.
static std::optional< uint64_t > getUInt64IntegerValue(StringRef spelling)
For an integer token, return its value as an uint64_t.
bool isAny(Kind k1, Kind k2) const
StringRef getSpelling() const
std::optional< std::string > getHexStringValue() const
Given a token containing a hex string literal, return its value or std::nullopt if the token does not...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
bool isSignedInteger() const
Return true if this is a signed integer type (with the specified width).
bool isIntOrIndexOrFloat() const
Return true if this is an integer (of any signedness), index, or float type.
bool isUnsignedInteger() const
Return true if this is an unsigned integer type (with the specified width).
bool isIntOrIndex() const
Return true if this is an integer (of any signedness) or an index type.
bool isInteger() const
Return true if this is an integer type (with the specified width).
bool isIntOrFloat() const
Return true if this is an integer (of any signedness) or a float type.
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
This class implement support for parsing global entities like attributes and types.
ParseResult parseFloatFromLiteral(std::optional< APFloat > &result, const Token &tok, bool isNegative, const llvm::fltSemantics &semantics)
Parse a floating point value from a literal.
Attribute parseDenseArrayAttr(Type type)
Parse a DenseArrayAttr.
Attribute parseStridedLayoutAttr()
Parse a strided layout attribute.
Attribute parseDecOrHexAttr(Type type, bool isNegative)
Parse a decimal or a hexadecimal literal, which can be either an integer or a float attribute.
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.
Attribute parseDenseElementsAttr(Type attrType)
Parse a dense elements attribute.
Attribute parseDenseResourceElementsAttr(Type attrType)
Parse a dense resource elements attribute.
ParseResult parseAffineMapReference(AffineMap &map)
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
FailureOr< AsmDialectResourceHandle > parseResourceHandle(const OpAsmDialectInterface *dialect, std::string &name)
Parse a handle to a dialect resource within the assembly format.
ParseResult parseLocationInstance(LocationAttr &loc)
Parse a raw location instance.
void consumeToken()
Advance the current lexer onto the next token.
Attribute codeCompleteAttribute()
ParseResult parseAttributeDict(NamedAttrList &attributes)
Parse an attribute dictionary.
Attribute parseDistinctAttr(Type type)
Parse a distinct attribute.
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.
Attribute parseSparseElementsAttr(Type attrType)
Parse a sparse elements attribute.
OptionalParseResult parseOptionalAttribute(Attribute &attribute, Type type={})
Parse an optional attribute with the provided type.
Attribute parseFloatAttr(Type type, bool isNegative)
Parse a float attribute.
ParseResult parseFloatFromIntegerLiteral(std::optional< APFloat > &result, const Token &tok, bool isNegative, const llvm::fltSemantics &semantics)
Parse a floating point value from an integer literal token.
ParseResult parseIntegerSetReference(IntegerSet &set)
const Token & getToken() const
Return the current token the parser is inspecting.
Attribute parseExtendedAttr(Type type)
Parse an extended attribute.
MLIRContext * getContext() const
ShapedType parseElementsLiteralType(SMLoc loc, Type type)
Shaped type for elements attribute.
bool consumeIf(Token::Kind kind)
If the current token has the specified kind, consume it and return true.
OptionalParseResult parseOptionalAttributeWithToken(Token::Kind kind, AttributeT &attr, Type type={})
Parse an optional attribute that is demarcated by a specific token.
QueryRef parse(llvm::StringRef line, const QuerySession &qs)
Include the generated interface declarations.
std::conditional_t< std::is_floating_point_v< T >, std::complex< T >, NonFloatComplex< T > > Complex
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap