Skip to content

Commit a763cc1

Browse files
committed
Add structural attr to AffineParallelOps
1 parent 0f127ab commit a763cc1

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

mlir/include/mlir/Dialect/Affine/IR/AffineOps.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ def AffineParallelOp : Affine_Op<"parallel", [ImplicitAffineTerminator]> {
549549
AffineMapAttr:$lowerBoundsMap,
550550
AffineMapAttr:$upperBoundsMap,
551551
I64ArrayAttr:$steps,
552+
OptionalAttr<UnitAttr>:$structural,
552553
Variadic<Index>:$mapOperands);
553554
let regions = (region SizedRegion<1>:$region);
554555

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,8 +2622,8 @@ struct AffineParallelRank0LoopRemover
26222622

26232623
LogicalResult matchAndRewrite(AffineParallelOp op,
26242624
PatternRewriter &rewriter) const override {
2625-
// Check that there are no induction variables
2626-
if (op.lowerBoundsMap().getNumResults() != 0)
2625+
// Check that there are no induction variables & op isn't structural
2626+
if (op.lowerBoundsMap().getNumResults() != 0 || op.getAttr("structural"))
26272627
return failure();
26282628
// Remove the affine.parallel wrapper, retain the body in the same location
26292629
auto &parentOps = rewriter.getInsertionBlock()->getOperations();

mlir/test/Dialect/Affine/canonicalize.mlir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,3 +619,17 @@ func @remove_rank0_affine_parallel(%out: memref<f32>) {
619619
}
620620
return
621621
}
622+
623+
// -----
624+
625+
// CHECK: func @keep_structural_affine_parallel(%[[OUT:.*]]: memref<f32>)
626+
func @keep_structural_affine_parallel(%out: memref<f32>) {
627+
// CHECK-NEXT: %[[CST:.*]] = constant
628+
%cst = constant 0.0 : f32
629+
// CHECK-NEXT: affine.parallel () = () to ()
630+
affine.parallel () = () to () {
631+
// CHECK-NEXT: affine.store %[[CST]], %[[OUT]][] : memref<f32>
632+
affine.store %cst, %out[] : memref<f32>
633+
} {structural}
634+
return
635+
}

0 commit comments

Comments
 (0)