Skip to content

Commit 460adfa

Browse files
committed
[mlir][vector] Standardize base Naming Across Vector Ops (NFC)
This change standardizes the naming convention for the argument representing the value to read from or write to in Vector ops that interface with Tensors or MemRefs. Specifically, it ensures that all such ops use the name `base` (i.e., the base address or location to which offsets are applied). Updated operations: * vector.transfer_read * vector.transfer_write For reference, these ops already use base: * vector.load, vector.store, vector.scatter, vector.gather, vector.expandload, vector.compressstore, vector.maskedstore, vector.maskedload This is a non-functional change (NFC) and does not alter the semantics of these operations. Implements #131602
1 parent 77f8335 commit 460adfa

29 files changed

+231
-257
lines changed

mlir/include/mlir/Dialect/Vector/IR/VectorOps.td

Lines changed: 48 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,23 +1263,20 @@ def Vector_ExtractStridedSliceOp :
12631263

12641264
// TODO: Tighten semantics so that masks and inbounds can't be used
12651265
// simultaneously within the same transfer op.
1266-
def Vector_TransferReadOp :
1267-
Vector_Op<"transfer_read", [
1268-
DeclareOpInterfaceMethods<VectorTransferOpInterface>,
1269-
DeclareOpInterfaceMethods<VectorUnrollOpInterface, ["getShapeForUnroll"]>,
1270-
DeclareOpInterfaceMethods<MaskableOpInterface>,
1271-
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
1272-
DeclareOpInterfaceMethods<ConditionallySpeculatable>,
1273-
AttrSizedOperandSegments,
1274-
DestinationStyleOpInterface
1275-
]>,
1276-
Arguments<(ins AnyShaped:$source,
1277-
Variadic<Index>:$indices,
1278-
AffineMapAttr:$permutation_map,
1279-
AnyType:$padding,
1280-
Optional<VectorOfNonZeroRankOf<[I1]>>:$mask,
1281-
BoolArrayAttr:$in_bounds)>,
1282-
Results<(outs AnyVectorOfAnyRank:$vector)> {
1266+
def Vector_TransferReadOp
1267+
: Vector_Op<"transfer_read",
1268+
[DeclareOpInterfaceMethods<VectorTransferOpInterface>,
1269+
DeclareOpInterfaceMethods<
1270+
VectorUnrollOpInterface, ["getShapeForUnroll"]>,
1271+
DeclareOpInterfaceMethods<MaskableOpInterface>,
1272+
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
1273+
DeclareOpInterfaceMethods<ConditionallySpeculatable>,
1274+
AttrSizedOperandSegments, DestinationStyleOpInterface]>,
1275+
Arguments<(ins AnyShaped:$base, Variadic<Index>:$indices,
1276+
AffineMapAttr:$permutation_map, AnyType:$padding,
1277+
Optional<VectorOfNonZeroRankOf<[I1]>>:$mask,
1278+
BoolArrayAttr:$in_bounds)>,
1279+
Results<(outs AnyVectorOfAnyRank:$vector)> {
12831280

12841281
let summary = "Reads a supervector from memory into an SSA vector value.";
12851282

@@ -1468,30 +1465,25 @@ def Vector_TransferReadOp :
14681465
}];
14691466

14701467
let builders = [
1471-
/// 1. Builder that sets padding to zero and an empty mask (variant with attrs).
1472-
OpBuilder<(ins "VectorType":$vectorType,
1473-
"Value":$source,
1474-
"ValueRange":$indices,
1475-
"AffineMapAttr":$permutationMapAttr,
1476-
"ArrayAttr":$inBoundsAttr)>,
1477-
/// 2. Builder that sets padding to zero and an empty mask (variant without attrs).
1478-
OpBuilder<(ins "VectorType":$vectorType,
1479-
"Value":$source,
1480-
"ValueRange":$indices,
1481-
"AffineMap":$permutationMap,
1482-
CArg<"std::optional<ArrayRef<bool>>", "::std::nullopt">:$inBounds)>,
1483-
/// 3. Builder that sets permutation map to 'getMinorIdentityMap'.
1484-
OpBuilder<(ins "VectorType":$vectorType,
1485-
"Value":$source,
1486-
"ValueRange":$indices,
1487-
"Value":$padding,
1488-
CArg<"std::optional<ArrayRef<bool>>", "::std::nullopt">:$inBounds)>,
1489-
/// 4. Builder that sets padding to zero and permutation map to
1490-
/// 'getMinorIdentityMap'.
1491-
OpBuilder<(ins "VectorType":$vectorType,
1492-
"Value":$source,
1493-
"ValueRange":$indices,
1494-
CArg<"std::optional<ArrayRef<bool>>", "::std::nullopt">:$inBounds)>,
1468+
/// 1. Builder that sets padding to zero and an empty mask (variant with
1469+
/// attrs).
1470+
OpBuilder<(ins "VectorType":$vectorType, "Value":$base,
1471+
"ValueRange":$indices, "AffineMapAttr":$permutationMapAttr,
1472+
"ArrayAttr":$inBoundsAttr)>,
1473+
/// 2. Builder that sets padding to zero and an empty mask (variant
1474+
/// without attrs).
1475+
OpBuilder<(ins "VectorType":$vectorType, "Value":$base,
1476+
"ValueRange":$indices, "AffineMap":$permutationMap,
1477+
CArg<"std::optional<ArrayRef<bool>>", "::std::nullopt">:$inBounds)>,
1478+
/// 3. Builder that sets permutation map to 'getMinorIdentityMap'.
1479+
OpBuilder<(ins "VectorType":$vectorType, "Value":$base,
1480+
"ValueRange":$indices, "Value":$padding,
1481+
CArg<"std::optional<ArrayRef<bool>>", "::std::nullopt">:$inBounds)>,
1482+
/// 4. Builder that sets padding to zero and permutation map to
1483+
/// 'getMinorIdentityMap'.
1484+
OpBuilder<(ins "VectorType":$vectorType, "Value":$base,
1485+
"ValueRange":$indices,
1486+
CArg<"std::optional<ArrayRef<bool>>", "::std::nullopt">:$inBounds)>,
14951487
];
14961488

14971489
let extraClassDeclaration = [{
@@ -1511,23 +1503,20 @@ def Vector_TransferReadOp :
15111503

15121504
// TODO: Tighten semantics so that masks and inbounds can't be used
15131505
// simultaneously within the same transfer op.
1514-
def Vector_TransferWriteOp :
1515-
Vector_Op<"transfer_write", [
1516-
DeclareOpInterfaceMethods<VectorTransferOpInterface>,
1517-
DeclareOpInterfaceMethods<VectorUnrollOpInterface, ["getShapeForUnroll"]>,
1518-
DeclareOpInterfaceMethods<MaskableOpInterface>,
1519-
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
1520-
DeclareOpInterfaceMethods<ConditionallySpeculatable>,
1521-
AttrSizedOperandSegments,
1522-
DestinationStyleOpInterface
1523-
]>,
1524-
Arguments<(ins AnyVectorOfAnyRank:$valueToStore,
1525-
AnyShaped:$source,
1526-
Variadic<Index>:$indices,
1527-
AffineMapAttr:$permutation_map,
1528-
Optional<VectorOfNonZeroRankOf<[I1]>>:$mask,
1529-
BoolArrayAttr:$in_bounds)>,
1530-
Results<(outs Optional<AnyRankedTensor>:$result)> {
1506+
def Vector_TransferWriteOp
1507+
: Vector_Op<"transfer_write",
1508+
[DeclareOpInterfaceMethods<VectorTransferOpInterface>,
1509+
DeclareOpInterfaceMethods<
1510+
VectorUnrollOpInterface, ["getShapeForUnroll"]>,
1511+
DeclareOpInterfaceMethods<MaskableOpInterface>,
1512+
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
1513+
DeclareOpInterfaceMethods<ConditionallySpeculatable>,
1514+
AttrSizedOperandSegments, DestinationStyleOpInterface]>,
1515+
Arguments<(ins AnyVectorOfAnyRank:$valueToStore, AnyShaped:$base,
1516+
Variadic<Index>:$indices, AffineMapAttr:$permutation_map,
1517+
Optional<VectorOfNonZeroRankOf<[I1]>>:$mask,
1518+
BoolArrayAttr:$in_bounds)>,
1519+
Results<(outs Optional<AnyRankedTensor>:$result)> {
15311520

15321521
let summary = "The vector.transfer_write op writes a supervector to memory.";
15331522

@@ -1663,7 +1652,7 @@ def Vector_TransferWriteOp :
16631652
/// ops of other dialects.
16641653
Value getValue() { return getVector(); }
16651654

1666-
MutableOperandRange getDpsInitsMutable() { return getSourceMutable(); }
1655+
MutableOperandRange getDpsInitsMutable() { return getBaseMutable(); }
16671656
}];
16681657

16691658
let hasFolder = 1;

mlir/include/mlir/Interfaces/VectorInterfaces.td

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -75,75 +75,66 @@ def VectorTransferOpInterface : OpInterface<"VectorTransferOpInterface"> {
7575
}];
7676
let cppNamespace = "::mlir";
7777

78-
let methods = [
79-
InterfaceMethod<
80-
/*desc=*/[{
78+
let methods = [InterfaceMethod<
79+
/*desc=*/[{
8180
Return the `in_bounds` attribute name.
8281
}],
83-
/*retTy=*/"::mlir::StringRef",
84-
/*methodName=*/"getInBoundsAttrName",
85-
/*args=*/(ins)
86-
>,
87-
InterfaceMethod<
88-
/*desc=*/[{
82+
/*retTy=*/"::mlir::StringRef",
83+
/*methodName=*/"getInBoundsAttrName",
84+
/*args=*/(ins)>,
85+
InterfaceMethod<
86+
/*desc=*/[{
8987
Return the `permutation_map` attribute name.
9088
}],
91-
/*retTy=*/"::mlir::StringRef",
92-
/*methodName=*/"getPermutationMapAttrName",
93-
/*args=*/(ins)
94-
>,
95-
InterfaceMethod<
96-
/*desc=*/[{
89+
/*retTy=*/"::mlir::StringRef",
90+
/*methodName=*/"getPermutationMapAttrName",
91+
/*args=*/(ins)>,
92+
InterfaceMethod<
93+
/*desc=*/[{
9794
Return the optional in_bounds attribute that specifies for each vector
9895
dimension whether it is in-bounds or not. (Broadcast dimensions are
9996
always in-bounds).
10097
}],
101-
/*retTy=*/"::mlir::ArrayAttr",
102-
/*methodName=*/"getInBounds",
103-
/*args=*/(ins)
104-
>,
105-
InterfaceMethod<
106-
/*desc=*/[{
98+
/*retTy=*/"::mlir::ArrayAttr",
99+
/*methodName=*/"getInBounds",
100+
/*args=*/(ins)>,
101+
InterfaceMethod<
102+
/*desc=*/[{
107103
Return the memref or ranked tensor operand that this operation operates
108104
on. In case of a "read" operation, that's the source from which the
109105
operation reads. In case of a "write" operation, that's the destination
110106
into which the operation writes.
111-
TODO: Change name of operand, which is not accurate for xfer_write.
112107
}],
113-
/*retTy=*/"::mlir::Value",
114-
/*methodName=*/"getSource",
115-
/*args=*/(ins)
116-
>,
117-
InterfaceMethod<
118-
/*desc=*/[{
108+
/*retTy=*/"::mlir::Value",
109+
/*methodName=*/"getBase",
110+
/*args=*/(ins)>,
111+
InterfaceMethod<
112+
/*desc=*/[{
119113
Return the vector that this operation operates on. In case of a "read",
120114
that's the vector OpResult. In case of a "write", that's the vector
121115
operand value that is written by the op.
122116
}],
123-
/*retTy=*/"::mlir::Value",
124-
/*methodName=*/"getVector",
125-
/*args=*/(ins)
126-
>,
127-
InterfaceMethod<
128-
/*desc=*/[{
117+
/*retTy=*/"::mlir::Value",
118+
/*methodName=*/"getVector",
119+
/*args=*/(ins)>,
120+
InterfaceMethod<
121+
/*desc=*/[{
129122
Return the type of the vector that this operation operates on.
130123
}],
131-
/*retTy=*/"::mlir::VectorType",
132-
/*methodName=*/"getVectorType",
133-
/*args=*/(ins)
134-
>,
135-
InterfaceMethod<
136-
/*desc=*/[{
124+
/*retTy=*/"::mlir::VectorType",
125+
/*methodName=*/"getVectorType",
126+
/*args=*/(ins)>,
127+
InterfaceMethod<
128+
/*desc=*/[{
137129
Return the indices that specify the starting offsets into the source
138130
operand. The starting offsets are guaranteed to be in-bounds.
139131
}],
140-
/*retTy=*/"::mlir::OperandRange",
141-
/*methodName=*/"getIndices",
142-
/*args=*/(ins)
143-
>,
132+
/*retTy=*/"::mlir::OperandRange",
133+
/*methodName=*/"getIndices",
134+
/*args=*/(ins)>,
144135

145-
InterfaceMethod<
146-
/*desc=*/[{
136+
InterfaceMethod<
137+
/*desc=*/[{
147138
Return the permutation map that describes the mapping of vector
148139
dimensions to source dimensions, as well as broadcast dimensions.
149140

@@ -162,20 +153,17 @@ def VectorTransferOpInterface : OpInterface<"VectorTransferOpInterface"> {
162153
: memref<?x?xvector<4x3xf32>>, vector<1x1x4x3xf32>
163154
```
164155
}],
165-
/*retTy=*/"::mlir::AffineMap",
166-
/*methodName=*/"getPermutationMap",
167-
/*args=*/(ins)
168-
>,
169-
InterfaceMethod<
170-
/*desc=*/[{
156+
/*retTy=*/"::mlir::AffineMap",
157+
/*methodName=*/"getPermutationMap",
158+
/*args=*/(ins)>,
159+
InterfaceMethod<
160+
/*desc=*/[{
171161
Return the mask operand if the op has a mask. Otherwise, return an
172162
empty value.
173163
}],
174-
/*retTy=*/"Value",
175-
/*methodName=*/"getMask",
176-
/*args=*/(ins)
177-
>
178-
];
164+
/*retTy=*/"Value",
165+
/*methodName=*/"getMask",
166+
/*args=*/(ins)>];
179167

180168
let extraSharedClassDeclaration = [{
181169
/// Return a vector of all in_bounds values as booleans (one per vector
@@ -203,7 +191,7 @@ def VectorTransferOpInterface : OpInterface<"VectorTransferOpInterface"> {
203191

204192
/// Return the shaped type of the "source" operand value.
205193
::mlir::ShapedType getShapedType() {
206-
return ::llvm::cast<::mlir::ShapedType>($_op.getSource().getType());
194+
return ::llvm::cast<::mlir::ShapedType>($_op.getBase().getType());
207195
}
208196

209197
/// Return the number of dimensions that participate in the permutation map.

mlir/lib/Conversion/VectorToArmSME/VectorToArmSME.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct TransferReadToArmSMELowering
5858
return rewriter.notifyMatchFailure(transferReadOp,
5959
"not a valid vector type for SME");
6060

61-
if (!llvm::isa<MemRefType>(transferReadOp.getSource().getType()))
61+
if (!llvm::isa<MemRefType>(transferReadOp.getBase().getType()))
6262
return rewriter.notifyMatchFailure(transferReadOp, "not a memref source");
6363

6464
// Out-of-bounds dims are not supported.
@@ -84,7 +84,7 @@ struct TransferReadToArmSMELowering
8484
auto mask = transferReadOp.getMask();
8585
auto padding = mask ? transferReadOp.getPadding() : nullptr;
8686
rewriter.replaceOpWithNewOp<arm_sme::TileLoadOp>(
87-
transferReadOp, vectorType, transferReadOp.getSource(),
87+
transferReadOp, vectorType, transferReadOp.getBase(),
8888
transferReadOp.getIndices(), padding, mask, layout);
8989

9090
return success();
@@ -128,7 +128,7 @@ struct TransferWriteToArmSMELowering
128128
if (!arm_sme::isValidSMETileVectorType(vType))
129129
return failure();
130130

131-
if (!llvm::isa<MemRefType>(writeOp.getSource().getType()))
131+
if (!llvm::isa<MemRefType>(writeOp.getBase().getType()))
132132
return failure();
133133

134134
// Out-of-bounds dims are not supported.
@@ -149,7 +149,7 @@ struct TransferWriteToArmSMELowering
149149
: arm_sme::TileSliceLayout::Horizontal;
150150

151151
rewriter.replaceOpWithNewOp<arm_sme::TileStoreOp>(
152-
writeOp, writeOp.getVector(), writeOp.getSource(), writeOp.getIndices(),
152+
writeOp, writeOp.getVector(), writeOp.getBase(), writeOp.getIndices(),
153153
writeOp.getMask(), layout);
154154
return success();
155155
}
@@ -686,7 +686,7 @@ struct FoldTransferWriteOfExtractTileSlice
686686

687687
LogicalResult matchAndRewrite(vector::TransferWriteOp writeOp,
688688
PatternRewriter &rewriter) const final {
689-
if (!isa<MemRefType>(writeOp.getSource().getType()))
689+
if (!isa<MemRefType>(writeOp.getBase().getType()))
690690
return rewriter.notifyMatchFailure(writeOp, "destination not a memref");
691691

692692
if (writeOp.hasOutOfBoundsDim())
@@ -713,7 +713,7 @@ struct FoldTransferWriteOfExtractTileSlice
713713

714714
rewriter.replaceOpWithNewOp<arm_sme::StoreTileSliceOp>(
715715
writeOp, extractTileSlice.getTile(),
716-
extractTileSlice.getTileSliceIndex(), mask, writeOp.getSource(),
716+
extractTileSlice.getTileSliceIndex(), mask, writeOp.getBase(),
717717
writeOp.getIndices(), extractTileSlice.getLayout());
718718
return success();
719719
}

0 commit comments

Comments
 (0)