@@ -3758,7 +3758,7 @@ void ExtractStridedSliceOp::getCanonicalizationPatterns(
37583758void TransferReadOp::build (OpBuilder &builder, OperationState &result,
37593759 VectorType vectorType, Value source,
37603760 ValueRange indices, AffineMapAttr permutationMapAttr,
3761- /* optional*/ ArrayAttr inBoundsAttr) {
3761+ /* optional*/ DenseBoolArrayAttr inBoundsAttr) {
37623762 Type elemType = llvm::cast<ShapedType>(source.getType ()).getElementType ();
37633763 Value padding = builder.create <arith::ConstantOp>(
37643764 result.location , elemType, builder.getZeroAttr (elemType));
@@ -3773,8 +3773,8 @@ void TransferReadOp::build(OpBuilder &builder, OperationState &result,
37733773 std::optional<ArrayRef<bool >> inBounds) {
37743774 auto permutationMapAttr = AffineMapAttr::get (permutationMap);
37753775 auto inBoundsAttr = (inBounds && !inBounds.value ().empty ())
3776- ? builder.getBoolArrayAttr (inBounds.value ())
3777- : builder.getBoolArrayAttr (
3776+ ? builder.getDenseBoolArrayAttr (inBounds.value ())
3777+ : builder.getDenseBoolArrayAttr (
37783778 SmallVector<bool >(vectorType.getRank (), false ));
37793779 build (builder, result, vectorType, source, indices, permutationMapAttr,
37803780 inBoundsAttr);
@@ -3789,8 +3789,8 @@ void TransferReadOp::build(OpBuilder &builder, OperationState &result,
37893789 llvm::cast<ShapedType>(source.getType ()), vectorType);
37903790 auto permutationMapAttr = AffineMapAttr::get (permutationMap);
37913791 auto inBoundsAttr = (inBounds && !inBounds.value ().empty ())
3792- ? builder.getBoolArrayAttr (inBounds.value ())
3793- : builder.getBoolArrayAttr (
3792+ ? builder.getDenseBoolArrayAttr (inBounds.value ())
3793+ : builder.getDenseBoolArrayAttr (
37943794 SmallVector<bool >(vectorType.getRank (), false ));
37953795 build (builder, result, vectorType, source, indices, permutationMapAttr,
37963796 padding,
@@ -3842,7 +3842,7 @@ static LogicalResult
38423842verifyTransferOp (VectorTransferOpInterface op, ShapedType shapedType,
38433843 VectorType vectorType, VectorType maskType,
38443844 VectorType inferredMaskType, AffineMap permutationMap,
3845- ArrayAttr inBounds) {
3845+ ArrayRef< bool > inBounds) {
38463846 if (op->hasAttr (" masked" )) {
38473847 return op->emitOpError (" masked attribute has been removed. "
38483848 " Use in_bounds instead." );
@@ -3915,8 +3915,7 @@ verifyTransferOp(VectorTransferOpInterface op, ShapedType shapedType,
39153915 << AffineMapAttr::get (permutationMap)
39163916 << " vs inBounds of size: " << inBounds.size ();
39173917 for (unsigned int i = 0 , e = permutationMap.getNumResults (); i < e; ++i)
3918- if (isa<AffineConstantExpr>(permutationMap.getResult (i)) &&
3919- !llvm::cast<BoolAttr>(inBounds.getValue ()[i]).getValue ())
3918+ if (isa<AffineConstantExpr>(permutationMap.getResult (i)) && !inBounds[i])
39203919 return op->emitOpError (" requires broadcast dimensions to be in-bounds" );
39213920
39223921 return success ();
@@ -3930,7 +3929,25 @@ static void printTransferAttrs(OpAsmPrinter &p, VectorTransferOpInterface op) {
39303929 // Elide in_bounds attribute if all dims are out-of-bounds.
39313930 if (llvm::none_of (op.getInBoundsValues (), [](bool b) { return b; }))
39323931 elidedAttrs.push_back (op.getInBoundsAttrName ());
3933- p.printOptionalAttrDict (op->getAttrs (), elidedAttrs);
3932+ p.printOptionalAttrDict (op->getAttrs (), elidedAttrs,
3933+ [&](NamedAttribute attr) -> LogicalResult {
3934+ if (attr.getName () != op.getInBoundsAttrName ())
3935+ return failure ();
3936+ cast<DenseBoolArrayAttr>(attr.getValue ()).print (p);
3937+ return success ();
3938+ });
3939+ }
3940+
3941+ template <typename XferOp>
3942+ static ParseResult parseTransferAttrs (OpAsmParser &parser,
3943+ OperationState &result) {
3944+ auto inBoundsAttrName = XferOp::getInBoundsAttrName (result.name );
3945+ return parser.parseOptionalAttrDict (
3946+ result.attributes , [&](StringRef name) -> FailureOr<Attribute> {
3947+ if (name != inBoundsAttrName)
3948+ return failure ();
3949+ return DenseBoolArrayAttr::parse (parser, {});
3950+ });
39343951}
39353952
39363953void TransferReadOp::print (OpAsmPrinter &p) {
@@ -3972,7 +3989,7 @@ ParseResult TransferReadOp::parse(OpAsmParser &parser, OperationState &result) {
39723989 if (parser.parseOperand (maskInfo))
39733990 return failure ();
39743991 }
3975- if (parser. parseOptionalAttrDict ( result. attributes ) ||
3992+ if (parseTransferAttrs<TransferReadOp>(parser, result) ||
39763993 parser.getCurrentLocation (&typesLoc) || parser.parseColonTypeList (types))
39773994 return failure ();
39783995 if (types.size () != 2 )
@@ -3997,7 +4014,7 @@ ParseResult TransferReadOp::parse(OpAsmParser &parser, OperationState &result) {
39974014 Attribute inBoundsAttr = result.attributes .get (inBoundsAttrName);
39984015 if (!inBoundsAttr) {
39994016 result.addAttribute (inBoundsAttrName,
4000- builder.getBoolArrayAttr (
4017+ builder.getDenseBoolArrayAttr (
40014018 SmallVector<bool >(permMap.getNumResults (), false )));
40024019 }
40034020 if (parser.resolveOperand (sourceInfo, shapedType, result.operands ) ||
@@ -4125,7 +4142,7 @@ static LogicalResult foldTransferInBoundsAttribute(TransferOp op) {
41254142 return failure ();
41264143 // OpBuilder is only used as a helper to build an I64ArrayAttr.
41274144 OpBuilder b (op.getContext ());
4128- op.setInBoundsAttr (b.getBoolArrayAttr (newInBounds));
4145+ op.setInBoundsAttr (b.getDenseBoolArrayAttr (newInBounds));
41294146 return success ();
41304147}
41314148
@@ -4295,7 +4312,7 @@ void TransferWriteOp::build(OpBuilder &builder, OperationState &result,
42954312 Value vector, Value dest, ValueRange indices,
42964313 AffineMapAttr permutationMapAttr,
42974314 /* optional*/ Value mask,
4298- /* optional*/ ArrayAttr inBoundsAttr) {
4315+ /* optional*/ DenseBoolArrayAttr inBoundsAttr) {
42994316 Type resultType = llvm::dyn_cast<RankedTensorType>(dest.getType ());
43004317 build (builder, result, resultType, vector, dest, indices, permutationMapAttr,
43014318 mask, inBoundsAttr);
@@ -4305,7 +4322,7 @@ void TransferWriteOp::build(OpBuilder &builder, OperationState &result,
43054322void TransferWriteOp::build (OpBuilder &builder, OperationState &result,
43064323 Value vector, Value dest, ValueRange indices,
43074324 AffineMapAttr permutationMapAttr,
4308- /* optional*/ ArrayAttr inBoundsAttr) {
4325+ /* optional*/ DenseBoolArrayAttr inBoundsAttr) {
43094326 build (builder, result, vector, dest, indices, permutationMapAttr,
43104327 /* mask=*/ Value (), inBoundsAttr);
43114328}
@@ -4319,8 +4336,8 @@ void TransferWriteOp::build(OpBuilder &builder, OperationState &result,
43194336 auto permutationMapAttr = AffineMapAttr::get (permutationMap);
43204337 auto inBoundsAttr =
43214338 (inBounds && !inBounds.value ().empty ())
4322- ? builder.getBoolArrayAttr (inBounds.value ())
4323- : builder.getBoolArrayAttr (SmallVector<bool >(
4339+ ? builder.getDenseBoolArrayAttr (inBounds.value ())
4340+ : builder.getDenseBoolArrayAttr (SmallVector<bool >(
43244341 llvm::cast<VectorType>(vector.getType ()).getRank (), false ));
43254342 build (builder, result, vector, dest, indices, permutationMapAttr,
43264343 /* mask=*/ Value (), inBoundsAttr);
@@ -4352,7 +4369,7 @@ ParseResult TransferWriteOp::parse(OpAsmParser &parser,
43524369 ParseResult hasMask = parser.parseOptionalComma ();
43534370 if (hasMask.succeeded () && parser.parseOperand (maskInfo))
43544371 return failure ();
4355- if (parser. parseOptionalAttrDict ( result. attributes ) ||
4372+ if (parseTransferAttrs<TransferWriteOp>(parser, result) ||
43564373 parser.getCurrentLocation (&typesLoc) || parser.parseColonTypeList (types))
43574374 return failure ();
43584375 if (types.size () != 2 )
@@ -4378,7 +4395,7 @@ ParseResult TransferWriteOp::parse(OpAsmParser &parser,
43784395 Attribute inBoundsAttr = result.attributes .get (inBoundsAttrName);
43794396 if (!inBoundsAttr) {
43804397 result.addAttribute (inBoundsAttrName,
4381- builder.getBoolArrayAttr (
4398+ builder.getDenseBoolArrayAttr (
43824399 SmallVector<bool >(permMap.getNumResults (), false )));
43834400 }
43844401 if (parser.resolveOperand (vectorInfo, vectorType, result.operands ) ||
@@ -4731,7 +4748,7 @@ struct SwapExtractSliceOfTransferWrite
47314748 auto newTransferWriteOp = rewriter.create <TransferWriteOp>(
47324749 transferOp.getLoc (), transferOp.getVector (), newExtractOp.getResult (),
47334750 transferOp.getIndices (), transferOp.getPermutationMapAttr (),
4734- rewriter.getBoolArrayAttr (newInBounds));
4751+ rewriter.getDenseBoolArrayAttr (newInBounds));
47354752 rewriter.modifyOpInPlace (insertOp, [&]() {
47364753 insertOp.getSourceMutable ().assign (newTransferWriteOp.getResult ());
47374754 });
0 commit comments