Skip to content

Commit 8685244

Browse files
committed
[mlir][affine] allow iter args as valid dims
that is effectivevely a revert of 7aabf47 for mlir/lib/Dialect/Affine/IR/AffineOps.cpp As iter args can be used as a dims is some situations. For example in [heir PolynomialToModArith](https://github.com/google/heir/blob/main/lib/Dialect/Polynomial/Conversions/PolynomialToModArith/PolynomialToModArith.cpp#L1036) `rootExp`` and `batchSize`` are iter args that are being used as dims and from the point of internal loops they are fixed.
1 parent 60d0bc1 commit 8685244

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

mlir/lib/Dialect/Affine/IR/AffineOps.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,10 @@ bool mlir::affine::isValidDim(Value value) {
294294
return isValidDim(value, getAffineScope(defOp));
295295

296296
// This value has to be a block argument for an op that has the
297-
// `AffineScope` trait or an induction var of an affine.for or
298-
// affine.parallel.
299-
if (isAffineInductionVar(value))
300-
return true;
297+
// `AffineScope` trait or for an affine.for or affine.parallel.
301298
auto *parentOp = llvm::cast<BlockArgument>(value).getOwner()->getParentOp();
302-
return parentOp && parentOp->hasTrait<OpTrait::AffineScope>();
299+
return parentOp && (parentOp->hasTrait<OpTrait::AffineScope>() ||
300+
isa<AffineForOp, AffineParallelOp>(parentOp));
303301
}
304302

305303
// Value can be used as a dimension id iff it meets one of the following
@@ -318,9 +316,10 @@ bool mlir::affine::isValidDim(Value value, Region *region) {
318316

319317
auto *op = value.getDefiningOp();
320318
if (!op) {
321-
// This value has to be an induction var for an affine.for or an
319+
// This value has to be a block argument for an affine.for or an
322320
// affine.parallel.
323-
return isAffineInductionVar(value);
321+
auto *parentOp = llvm::cast<BlockArgument>(value).getOwner()->getParentOp();
322+
return isa<AffineForOp, AffineParallelOp>(parentOp);
324323
}
325324

326325
// Affine apply operation is ok if all of its operands are ok.

mlir/test/Dialect/Affine/raise-memref.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func.func @symbols(%N : index) {
112112
// CHECK: %[[lhs5:.*]] = arith.addf %[[lhs]], %[[lhs4]]
113113
// CHECK: %[[lhs6:.*]] = arith.addi %[[a4]], %[[cst1]]
114114
// CHECK: affine.store %[[lhs5]], %{{.*}}[%[[a1]], symbol(%arg0) + 1] :
115-
// CHECK: memref.store %[[lhs5]], %{{.*}}[%[[a1]], %[[lhs6]]] :
115+
// CHECK: affine.store %[[lhs5]], %{{.*}}[%[[a1]], %arg4 + 1] :
116116
// CHECK: %[[lhs7:.*]] = "ab.v"
117117
// CHECK: memref.store %[[lhs5]], %{{.*}}[%[[a1]], %[[lhs7]]] :
118118
// CHECK: affine.yield %[[lhs6]]

0 commit comments

Comments
 (0)