@@ -202,10 +202,10 @@ ParseResult mlir::parseDimAndSymbolList(OpAsmParser &parser,
202202 numDims = opInfos.size ();
203203
204204 // Parse the optional symbol operands.
205- auto affineIntTy = parser.getBuilder ().getIndexType ();
205+ auto indexTy = parser.getBuilder ().getIndexType ();
206206 if (parser.parseOperandList (opInfos,
207207 OpAsmParser::Delimiter::OptionalSquare) ||
208- parser.resolveOperands (opInfos, affineIntTy , operands))
208+ parser.resolveOperands (opInfos, indexTy , operands))
209209 return failure ();
210210 return success ();
211211}
@@ -1658,14 +1658,14 @@ static ParseResult parseExtractElementOp(OpAsmParser &parser,
16581658 SmallVector<OpAsmParser::OperandType, 4 > indexInfo;
16591659 ShapedType type;
16601660
1661- auto affineIntTy = parser.getBuilder ().getIndexType ();
1661+ auto indexTy = parser.getBuilder ().getIndexType ();
16621662 return failure (
16631663 parser.parseOperand (aggregateInfo) ||
16641664 parser.parseOperandList (indexInfo, OpAsmParser::Delimiter::Square) ||
16651665 parser.parseOptionalAttributeDict (result.attributes ) ||
16661666 parser.parseColonType (type) ||
16671667 parser.resolveOperand (aggregateInfo, type, result.operands ) ||
1668- parser.resolveOperands (indexInfo, affineIntTy , result.operands ) ||
1668+ parser.resolveOperands (indexInfo, indexTy , result.operands ) ||
16691669 parser.addTypeToList (type.getElementType (), result.types ));
16701670}
16711671
@@ -1739,14 +1739,14 @@ static ParseResult parseLoadOp(OpAsmParser &parser, OperationState &result) {
17391739 SmallVector<OpAsmParser::OperandType, 4 > indexInfo;
17401740 MemRefType type;
17411741
1742- auto affineIntTy = parser.getBuilder ().getIndexType ();
1742+ auto indexTy = parser.getBuilder ().getIndexType ();
17431743 return failure (
17441744 parser.parseOperand (memrefInfo) ||
17451745 parser.parseOperandList (indexInfo, OpAsmParser::Delimiter::Square) ||
17461746 parser.parseOptionalAttributeDict (result.attributes ) ||
17471747 parser.parseColonType (type) ||
17481748 parser.resolveOperand (memrefInfo, type, result.operands ) ||
1749- parser.resolveOperands (indexInfo, affineIntTy , result.operands ) ||
1749+ parser.resolveOperands (indexInfo, indexTy , result.operands ) ||
17501750 parser.addTypeToList (type.getElementType (), result.types ));
17511751}
17521752
@@ -2043,6 +2043,55 @@ static LogicalResult verify(SignExtendIOp op) {
20432043 return success ();
20442044}
20452045
2046+ // ===----------------------------------------------------------------------===//
2047+ // SplatOp
2048+ // ===----------------------------------------------------------------------===//
2049+
2050+ static void print (OpAsmPrinter &p, SplatOp op) {
2051+ p << " splat " << *op.getOperand ();
2052+ p.printOptionalAttrDict (op.getAttrs ());
2053+ p << " : " << op.getType ();
2054+ }
2055+
2056+ static ParseResult parseSplatOp (OpAsmParser &parser, OperationState &result) {
2057+ OpAsmParser::OperandType splatValueInfo;
2058+ ShapedType shapedType;
2059+
2060+ return failure (parser.parseOperand (splatValueInfo) ||
2061+ parser.parseOptionalAttributeDict (result.attributes ) ||
2062+ parser.parseColonType (shapedType) ||
2063+ parser.resolveOperand (splatValueInfo,
2064+ shapedType.getElementType (),
2065+ result.operands ) ||
2066+ parser.addTypeToList (shapedType, result.types ));
2067+ }
2068+
2069+ static LogicalResult verify (SplatOp op) {
2070+ // TODO: we could replace this by a trait.
2071+ if (op.getOperand ()->getType () !=
2072+ op.getType ().cast <ShapedType>().getElementType ())
2073+ return op.emitError (" operand should be of elemental type of result type" );
2074+
2075+ return success ();
2076+ }
2077+
2078+ // Constant folding hook for SplatOp.
2079+ OpFoldResult SplatOp::fold (ArrayRef<Attribute> operands) {
2080+ assert (operands.size () == 1 && " splat takes one operand" );
2081+
2082+ auto constOperand = operands.front ();
2083+ if (!constOperand ||
2084+ (!constOperand.isa <IntegerAttr>() && !constOperand.isa <FloatAttr>()))
2085+ return {};
2086+
2087+ auto shapedType = getType ().cast <ShapedType>();
2088+ assert (shapedType.getElementType () == constOperand.getType () &&
2089+ " incorrect input attribute type for folding" );
2090+
2091+ // SplatElementsAttr::get treats single value for second arg as being a splat.
2092+ return SplatElementsAttr::get (shapedType, {constOperand});
2093+ }
2094+
20462095// ===----------------------------------------------------------------------===//
20472096// StoreOp
20482097// ===----------------------------------------------------------------------===//
@@ -2062,7 +2111,7 @@ static ParseResult parseStoreOp(OpAsmParser &parser, OperationState &result) {
20622111 SmallVector<OpAsmParser::OperandType, 4 > indexInfo;
20632112 MemRefType memrefType;
20642113
2065- auto affineIntTy = parser.getBuilder ().getIndexType ();
2114+ auto indexTy = parser.getBuilder ().getIndexType ();
20662115 return failure (
20672116 parser.parseOperand (storeValueInfo) || parser.parseComma () ||
20682117 parser.parseOperand (memrefInfo) ||
@@ -2072,7 +2121,7 @@ static ParseResult parseStoreOp(OpAsmParser &parser, OperationState &result) {
20722121 parser.resolveOperand (storeValueInfo, memrefType.getElementType (),
20732122 result.operands ) ||
20742123 parser.resolveOperand (memrefInfo, memrefType, result.operands ) ||
2075- parser.resolveOperands (indexInfo, affineIntTy , result.operands ));
2124+ parser.resolveOperands (indexInfo, indexTy , result.operands ));
20762125}
20772126
20782127static LogicalResult verify (StoreOp op) {
0 commit comments