@@ -291,12 +291,84 @@ static LogicalResult verify(ExtractElementOp op) {
291291 attr.getInt () > op.getVectorType ().getDimSize (en.index ()))
292292 return op.emitOpError (" expected position attribute #" )
293293 << (en.index () + 1 )
294- << " to be a positive integer smaller than the corresponding "
294+ << " to be a non-negative integer smaller than the corresponding "
295295 " vector dimension" ;
296296 }
297297 return success ();
298298}
299299
300+ // ===----------------------------------------------------------------------===//
301+ // InsertElementOp
302+ // ===----------------------------------------------------------------------===//
303+
304+ void InsertElementOp::build (Builder *builder, OperationState &result,
305+ Value *source, Value *dest,
306+ ArrayRef<int32_t > position) {
307+ result.addOperands ({source, dest});
308+ auto positionAttr = builder->getI32ArrayAttr (position);
309+ result.addTypes (dest->getType ());
310+ result.addAttribute (getPositionAttrName (), positionAttr);
311+ }
312+
313+ static void print (OpAsmPrinter &p, InsertElementOp op) {
314+ p << op.getOperationName () << " " << *op.source () << " , " << *op.dest ()
315+ << op.position ();
316+ p.printOptionalAttrDict (op.getAttrs (),
317+ {InsertElementOp::getPositionAttrName ()});
318+ p << " : " << op.getSourceType ();
319+ p << " into " << op.getDestVectorType ();
320+ }
321+
322+ static ParseResult parseInsertElementOp (OpAsmParser &parser,
323+ OperationState &result) {
324+ SmallVector<NamedAttribute, 4 > attrs;
325+ OpAsmParser::OperandType source, dest;
326+ Type sourceType;
327+ VectorType destType;
328+ Attribute attr;
329+ return failure (parser.parseOperand (source) || parser.parseComma () ||
330+ parser.parseOperand (dest) ||
331+ parser.parseAttribute (attr,
332+ InsertElementOp::getPositionAttrName (),
333+ result.attributes ) ||
334+ parser.parseOptionalAttrDict (attrs) ||
335+ parser.parseColonType (sourceType) ||
336+ parser.parseKeywordType (" into" , destType) ||
337+ parser.resolveOperand (source, sourceType, result.operands ) ||
338+ parser.resolveOperand (dest, destType, result.operands ) ||
339+ parser.addTypeToList (destType, result.types ));
340+ }
341+
342+ static LogicalResult verify (InsertElementOp op) {
343+ auto positionAttr = op.position ().getValue ();
344+ if (positionAttr.empty ())
345+ return op.emitOpError (" expected non-empty position attribute" );
346+ auto destVectorType = op.getDestVectorType ();
347+ if (positionAttr.size () > static_cast <unsigned >(destVectorType.getRank ()))
348+ return op.emitOpError (
349+ " expected position attribute of rank smaller than dest vector rank" );
350+ auto srcVectorType = op.getSourceType ().dyn_cast <VectorType>();
351+ if (srcVectorType &&
352+ (static_cast <unsigned >(srcVectorType.getRank ()) + positionAttr.size () !=
353+ static_cast <unsigned >(destVectorType.getRank ())))
354+ return op.emitOpError (" expected position attribute rank + source rank to "
355+ " match dest vector rank" );
356+ else if (!srcVectorType && (positionAttr.size () !=
357+ static_cast <unsigned >(destVectorType.getRank ())))
358+ return op.emitOpError (
359+ " expected position attribute rank to match the dest vector rank" );
360+ for (auto en : llvm::enumerate (positionAttr)) {
361+ auto attr = en.value ().dyn_cast <IntegerAttr>();
362+ if (!attr || attr.getInt () < 0 ||
363+ attr.getInt () > destVectorType.getDimSize (en.index ()))
364+ return op.emitOpError (" expected position attribute #" )
365+ << (en.index () + 1 )
366+ << " to be a non-negative integer smaller than the corresponding "
367+ " dest vector dimension" ;
368+ }
369+ return success ();
370+ }
371+
300372// ===----------------------------------------------------------------------===//
301373// StridedSliceOp
302374// ===----------------------------------------------------------------------===//
0 commit comments