10#include "llvm/ADT/SmallString.h"
16 if (!parser.parseOptionalKeyword(
"name")) {
18 if (parser.parseString(&str))
20 attr = parser.getBuilder().getStringAttr(str);
25 auto resultName = parser.getResultName(0).first;
26 if (!resultName.empty() &&
isdigit(resultName[0]))
28 attr = parser.getBuilder().getStringAttr(resultName);
33 SmallVector<Attribute> names;
34 unsigned resultIndex = 0;
35 while (resultIndex < parser.getNumResults()) {
36 auto resultName = parser.getResultName(resultIndex++).first;
37 if (!resultName.empty() &&
isdigit(resultName[0]))
39 names.push_back(parser.getBuilder().getStringAttr(resultName));
41 attr = parser.getBuilder().getArrayAttr(names);
46 NamedAttrList &
attrs) {
47 if (parser.parseOptionalAttrDict(
attrs))
55 if (
attrs.get(
"name"))
59 auto resultName = parser.getResultName(0).first;
60 if (!resultName.empty() &&
isdigit(resultName[0]))
62 auto nameAttr = parser.getBuilder().getStringAttr(resultName);
63 auto *
context = parser.getBuilder().getContext();
64 attrs.push_back({StringAttr::get(
context,
"name"), nameAttr});
75 SmallString<32> resultNameStr;
76 llvm::raw_svector_ostream tmpStream(resultNameStr);
77 printer.printOperand(op->getResult(0), tmpStream);
78 auto actualName = tmpStream.str().drop_front();
82 auto expectedName = attr.getValue();
84 if (actualName == expectedName ||
85 (expectedName.empty() &&
isdigit(actualName[0])))
88 printer <<
" name " << attr;
93 ArrayRef<StringRef> extraElides) {
94 SmallVector<StringRef, 2> elides(extraElides.begin(), extraElides.end());
96 printer.printOptionalAttrDict(
attrs.getValue(), elides);
100 DictionaryAttr
attrs,
101 SmallVectorImpl<StringRef> &elides) {
102 SmallString<32> resultNameStr;
103 llvm::raw_svector_ostream tmpStream(resultNameStr);
104 printer.printOperand(op->getResult(0), tmpStream);
105 auto actualName = tmpStream.str().drop_front();
106 auto expectedName =
attrs.getAs<StringAttr>(
"name").getValue();
108 if (actualName == expectedName ||
109 (expectedName.empty() &&
isdigit(actualName[0])))
110 elides.push_back(
"name");
115 if (parser.parseType(lhs))
119 if (parser.parseOptionalComma()) {
122 if (parser.parseType(rhs))
137 StringRef trueKeyword,
138 StringRef falseKeyword) {
139 if (succeeded(parser.parseOptionalKeyword(trueKeyword))) {
140 attr = BoolAttr::get(parser.getContext(),
true);
141 }
else if (succeeded(parser.parseOptionalKeyword(falseKeyword))) {
142 attr = BoolAttr::get(parser.getContext(),
false);
144 return parser.emitError(parser.getCurrentLocation())
145 <<
"expected keyword \"" << trueKeyword <<
"\" or \"" << falseKeyword
152 BoolAttr attr, StringRef trueKeyword,
153 StringRef falseKeyword) {
155 printer << trueKeyword;
157 printer << falseKeyword;
162 SmallVectorImpl<OpAsmParser::UnresolvedOperand> &operands, Type &resultType,
163 mlir::DenseBoolArrayAttr &inverted, NamedAttrList &attrDict) {
164 SmallVector<bool> inverts;
167 inverts.push_back(succeeded(parser.parseOptionalKeyword(
"not")));
168 operands.push_back(OpAsmParser::UnresolvedOperand());
170 if (parser.parseOperand(operands.back()))
172 if (parser.parseOptionalComma())
176 if (parser.parseOptionalAttrDict(attrDict) || parser.parseColon() ||
177 parser.parseCustomTypeWithFallback(resultType))
180 inverted = parser.getBuilder().getDenseBoolArrayAttr(inverts);
186 OperandRange operands,
188 mlir::DenseBoolArrayAttr inverted,
189 DictionaryAttr attrDict) {
191 llvm::interleaveComma(llvm::zip(inverted.asArrayRef(), operands), printer,
193 auto [invert, input] = pair;
198 printer.printOptionalAttrDict(attrDict.getValue(), {
"inverted"});
200 printer.printType(resultType);
static std::unique_ptr< Context > context
false return failure()
Parse an optional keyword or string and set instance into 'result'.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
ParseResult parseVariadicInvertibleOperands(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &operands, Type &resultType, mlir::DenseBoolArrayAttr &inverted, NamedAttrList &attrDict)
Parse a variadic list of operands that may be prefixed with an optional not keyword.
ParseResult parseKeywordBool(OpAsmParser &parser, BoolAttr &attr, StringRef trueKeyword, StringRef falseKeyword)
Parse a boolean as one of two keywords.
void printOptionalBinaryOpTypes(OpAsmPrinter &p, Operation *op, Type lhs, Type rhs)
Print/parse binary operands type only when types are different.
ParseResult parseImplicitSSANames(OpAsmParser &parser, ArrayAttr &attr)
Parse an array of implicit SSA name string attributes.
void elideImplicitSSAName(OpAsmPrinter &printer, Operation *op, DictionaryAttr attrs, SmallVectorImpl< StringRef > &elides)
Check if the name attribute in attrs matches the SSA name of the operation's first result.
void printVariadicInvertibleOperands(OpAsmPrinter &printer, Operation *op, OperandRange operands, Type resultType, mlir::DenseBoolArrayAttr inverted, DictionaryAttr attrDict)
Print a variadic list of operands that may be prefixed with an optional not keyword.
ParseResult parseImplicitSSAName(OpAsmParser &parser, StringAttr &attr)
Parse an implicit SSA name string attribute.
void printKeywordBool(OpAsmPrinter &printer, Operation *op, BoolAttr attr, StringRef trueKeyword, StringRef falseKeyword)
Print a boolean as one of two keywords.
bool inferImplicitSSAName(OpAsmParser &parser, NamedAttrList &attrs)
Ensure that attrs contains a name attribute by inferring its value from the SSA name of the operation...
void printImplicitSSANames(OpAsmPrinter &p, Operation *op, ArrayAttr attr)
Print an array of implicit SSA name string attributes.
void printImplicitSSAName(OpAsmPrinter &p, Operation *op, StringAttr attr)
Print an implicit SSA name string attribute.
ParseResult parseOptionalBinaryOpTypes(OpAsmParser &parser, Type &lhs, Type &rhs)