Skip to content

Commit e13898a

Browse files
committed
fixup! fixup! fixup! fixup! [mlir][vector] Make the in_bounds attribute mandatory
Address comment from Diego and Han-Chung
1 parent 861a18f commit e13898a

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

mlir/include/mlir/IR/AffineMap.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ class AffineMap {
146146
/// affine map (d0, ..., dn) -> (dp, ..., dn) on the most minor dimensions.
147147
bool isMinorIdentity() const;
148148

149+
/// Returns the list of broadcast dimensions (i.e. dims indicated by value 0
150+
/// in the result).
151+
/// Ex:
152+
/// * (d0, d1, d2) -> (0, d1) gives [0]
153+
/// * (d0, d1, d2) -> (d2, d1) gives []
154+
/// * (d0, d1, d2, d4) -> (d0, 0, d1, 0) gives [1, 3]
155+
SmallVector<unsigned> getBroadcastDims() const;
156+
149157
/// Returns true if this affine map is a minor identity up to broadcasted
150158
/// dimensions which are indicated by value 0 in the result. If
151159
/// `broadcastedDims` is not null, it will be populated with the indices of
@@ -155,13 +163,6 @@ class AffineMap {
155163
bool isMinorIdentityWithBroadcasting(
156164
SmallVectorImpl<unsigned> *broadcastedDims = nullptr) const;
157165

158-
/// Returns the list of broadcast dimensions.
159-
/// Ex:
160-
/// * (d0, d1, d2) -> (0, d1) gives [0]
161-
/// * (d0, d1, d2) -> (d2, d1) gives []
162-
/// * (d0, d1, d2, d4) -> (d0, 0, d1, 0) gives [1, 3]
163-
SmallVector<unsigned> getBroadcastDims() const;
164-
165166
/// Return true if this affine map can be converted to a minor identity with
166167
/// broadcast by doing a permute. Return a permutation (there may be
167168
/// several) to apply to get to a minor identity with broadcasts.

mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ static Operation *vectorizeAffineLoad(AffineLoadOp loadOp,
12351235

12361236
auto transfer = state.builder.create<vector::TransferReadOp>(
12371237
loadOp.getLoc(), vectorType, loadOp.getMemRef(), indices, permutationMap,
1238-
ArrayRef<bool>(inBounds));
1238+
inBounds);
12391239

12401240
// Register replacement for future uses in the scope.
12411241
state.registerOpVectorReplacement(loadOp, transfer);

mlir/lib/Dialect/Vector/IR/VectorOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3958,7 +3958,7 @@ verifyTransferOp(VectorTransferOpInterface op, ShapedType shapedType,
39583958
"as permutation_map results: ")
39593959
<< AffineMapAttr::get(permutationMap)
39603960
<< " vs inBounds of size: " << inBounds.size();
3961-
for (unsigned int i = 0; i < permutationMap.getNumResults(); ++i)
3961+
for (unsigned int i = 0, e = permutationMap.getNumResults(); i < e; ++i)
39623962
if (isa<AffineConstantExpr>(permutationMap.getResult(i)) &&
39633963
!llvm::cast<BoolAttr>(inBounds.getValue()[i]).getValue())
39643964
return op->emitOpError("requires broadcast dimensions to be in-bounds");

mlir/lib/IR/AffineMap.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,19 @@ bool AffineMap::isMinorIdentity() const {
158158
getMinorIdentityMap(getNumDims(), getNumResults(), getContext());
159159
}
160160

161+
SmallVector<unsigned> AffineMap::getBroadcastDims() const {
162+
SmallVector<unsigned> broadcastedDims;
163+
for (const auto &[resIdx, expr] : llvm::enumerate(getResults())) {
164+
if (auto constExpr = dyn_cast<AffineConstantExpr>(expr)) {
165+
if (constExpr.getValue() != 0)
166+
continue;
167+
broadcastedDims.push_back(resIdx);
168+
}
169+
}
170+
171+
return broadcastedDims;
172+
}
173+
161174
/// Returns true if this affine map is a minor identity up to broadcasted
162175
/// dimensions which are indicated by value 0 in the result.
163176
bool AffineMap::isMinorIdentityWithBroadcasting(
@@ -187,22 +200,6 @@ bool AffineMap::isMinorIdentityWithBroadcasting(
187200
return true;
188201
}
189202

190-
SmallVector<unsigned> AffineMap::getBroadcastDims() const {
191-
SmallVector<unsigned> broadcastedDims = {};
192-
for (const auto &idxAndExpr : llvm::enumerate(getResults())) {
193-
unsigned resIdx = idxAndExpr.index();
194-
AffineExpr expr = idxAndExpr.value();
195-
if (auto constExpr = dyn_cast<AffineConstantExpr>(expr)) {
196-
// Each result may be either a constant 0 (broadcasted dimension).
197-
if (constExpr.getValue() != 0)
198-
continue;
199-
broadcastedDims.push_back(resIdx);
200-
}
201-
}
202-
203-
return broadcastedDims;
204-
}
205-
206203
/// Return true if this affine map can be converted to a minor identity with
207204
/// broadcast by doing a permute. Return a permutation (there may be
208205
/// several) to apply to get to a minor identity with broadcasts.

0 commit comments

Comments
 (0)