Skip to content

Commit af8adea

Browse files
adstrawjbruestle
authored andcommitted
make Affine parallel and yield ops MemRefsNormalizable
Affine parallel ops may contain and yield results from MemRefsNormalizable ops in the loop body. Thus, both affine.parallel and affine.yield should have the MemRefsNormalizable trait. Reviewed By: bondhugula Differential Revision: https://reviews.llvm.org/D96821
1 parent 18b9fc4 commit af8adea

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def AffineMaxOp : AffineMinMaxOpBase<"max", [NoSideEffect]> {
592592

593593
def AffineParallelOp : Affine_Op<"parallel",
594594
[ImplicitAffineTerminator, RecursiveSideEffects,
595-
DeclareOpInterfaceMethods<LoopLikeOpInterface>]> {
595+
DeclareOpInterfaceMethods<LoopLikeOpInterface>, MemRefsNormalizable]> {
596596
let summary = "multi-index parallel band operation";
597597
let description = [{
598598
The "affine.parallel" operation represents a hyper-rectangular affine
@@ -842,7 +842,8 @@ def AffineStoreOp : AffineStoreOpBase<"store"> {
842842
let hasFolder = 1;
843843
}
844844

845-
def AffineYieldOp : Affine_Op<"yield", [NoSideEffect, Terminator, ReturnLike]> {
845+
def AffineYieldOp : Affine_Op<"yield", [NoSideEffect, Terminator, ReturnLike,
846+
MemRefsNormalizable]> {
846847
let summary = "Yield values to parent operation";
847848
let description = [{
848849
"affine.yield" yields zero or more SSA values from an affine op region and

mlir/lib/Transforms/NormalizeMemRefs.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,10 @@ Operation *NormalizeMemRefs::createOpResultsNormalized(FuncOp funcOp,
512512
// affine map, `oldOp` is returned without modification.
513513
if (resultTypeNormalized) {
514514
OpBuilder bb(oldOp);
515+
for (auto &oldRegion : oldOp->getRegions()) {
516+
Region *newRegion = result.addRegion();
517+
newRegion->takeBody(oldRegion);
518+
}
515519
return bb.createOperation(result);
516520
} else
517521
return oldOp;

mlir/test/Transforms/normalize-memrefs.mlir

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,16 @@ func @use_value_of_external(%A: memref<16xf64, #tile>, %B: f64) -> (memref<8xf64
319319
}
320320
// CHECK: %[[res:[0-9]+]] = call @external_func_B(%[[A]], %[[B]]) : (memref<4x4xf64>, f64) -> memref<2x4xf64>
321321
// CHECK: return %{{.*}} : memref<2x4xf64>
322+
323+
// CHECK-LABEL: func @affine_parallel_norm
324+
func @affine_parallel_norm() -> memref<8xf32, #tile> {
325+
%c = constant 23.0 : f32
326+
%a = alloc() : memref<8xf32, #tile>
327+
// CHECK: affine.parallel (%{{.*}}) = (0) to (8) reduce ("assign") -> (memref<2x4xf32>)
328+
%1 = affine.parallel (%i) = (0) to (8) reduce ("assign") -> memref<8xf32, #tile> {
329+
affine.store %c, %a[%i] : memref<8xf32, #tile>
330+
// CHECK: affine.yield %{{.*}} : memref<2x4xf32>
331+
affine.yield %a : memref<8xf32, #tile>
332+
}
333+
return %1 : memref<8xf32, #tile>
334+
}

0 commit comments

Comments
 (0)