Skip to content

Commit 50b9077

Browse files
ddubov100joker-eph
andauthored
Added RecursiveMemoryEffects to ExecuteRegionOp (#164390)
Added RecursiveMemoryEffects to ExecuteRegionOp to be aligned to other ops with region and get appropriate support in all appropriate passes, which need RecursiveMemoryEffects. The added test in dealloc-memoryeffect-interface.mlir fails with error 'ops with unknown memory side effects are not supported' without RecursiveMemoryEffects. The updated test in one-shot-module-bufferize.mlir gets cleaned by DCE once the interface is added. Added func.call @foo():()->() which has effect to keep execute_region from being removed. --------- Co-authored-by: Mehdi Amini <[email protected]>
1 parent e12e0d3 commit 50b9077

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

mlir/include/mlir/Dialect/SCF/IR/SCFOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def ConditionOp : SCF_Op<"condition", [
7777
//===----------------------------------------------------------------------===//
7878

7979
def ExecuteRegionOp : SCF_Op<"execute_region", [
80-
DeclareOpInterfaceMethods<RegionBranchOpInterface>]> {
80+
DeclareOpInterfaceMethods<RegionBranchOpInterface>, RecursiveMemoryEffects]> {
8181
let summary = "operation that executes its region exactly once";
8282
let description = [{
8383
The `scf.execute_region` operation is used to allow multiple blocks within SCF

mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,24 @@ func.func @manual_deallocation(%c: i1, %f: f32, %idx: index) -> f32 {
156156
// CHECK: cf.assert %[[true]], "expected that the block does not have ownership"
157157
// CHECK: memref.dealloc %[[manual_alloc]]
158158
// CHECK: bufferization.dealloc (%[[managed_alloc]] : memref<5xf32>) if (%[[true]])
159+
160+
// -----
161+
162+
// CHECK-LABEL: func.func private @properly_creates_deallocations_in_execute_region(
163+
// CHECK: %[[true:.*]] = arith.constant true
164+
// CHECK: scf.execute_region no_inline {
165+
// CHECK: %[[alloc:.*]] = memref.alloc() {alignment = 64 : i64} : memref<1x63x378x16xui8>
166+
// CHECK: bufferization.dealloc (%[[alloc]] : memref<1x63x378x16xui8>) if (%[[true]])
167+
168+
func.func private @properly_creates_deallocations_in_execute_region(%arg1: memref<1x16x252x380xui8> ) -> (memref<1x250x378x16xui8> ) {
169+
%alloc = memref.alloc() {alignment = 64 : i64} : memref<1x250x378x16xui8>
170+
scf.execute_region no_inline {
171+
%subview = memref.subview %arg1[0, 0, 0, 0] [1, 16, 65, 380] [1, 1, 1, 1] : memref<1x16x252x380xui8> to memref<1x16x65x380xui8, strided<[1532160, 95760, 380, 1]>>
172+
%alloc_3 = memref.alloc() {alignment = 64 : i64} : memref<1x63x378x16xui8>
173+
test.buffer_based in(%subview: memref<1x16x65x380xui8, strided<[1532160, 95760, 380, 1]>>) out(%alloc_3: memref<1x63x378x16xui8>)
174+
%subview_7 = memref.subview %alloc[0, 0, 0, 0] [1, 63, 378, 16] [1, 1, 1, 1] : memref<1x250x378x16xui8> to memref<1x63x378x16xui8, strided<[1512000, 6048, 16, 1]>>
175+
test.copy(%alloc_3, %subview_7) : (memref<1x63x378x16xui8>, memref<1x63x378x16xui8, strided<[1512000, 6048, 16, 1]>>)
176+
scf.yield
177+
}
178+
return %alloc : memref<1x250x378x16xui8>
179+
}

mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize.mlir

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,19 @@ func.func private @execute_region_test(%t1 : tensor<?xf32>)
381381
// -----
382382

383383
// CHECK-LABEL: func @no_inline_execute_region_not_canonicalized
384-
func.func @no_inline_execute_region_not_canonicalized() {
385-
%c = arith.constant 42 : i32
386-
// CHECK: scf.execute_region
387-
// CHECK-SAME: no_inline
388-
%v = scf.execute_region -> i32 no_inline {
389-
scf.yield %c : i32
384+
module {
385+
func.func private @foo()->()
386+
func.func @no_inline_execute_region_not_canonicalized() {
387+
%c = arith.constant 42 : i32
388+
// CHECK: scf.execute_region
389+
// CHECK-SAME: no_inline
390+
%v = scf.execute_region -> i32 no_inline {
391+
func.call @foo():()->()
392+
scf.yield %c : i32
393+
}
394+
// CHECK: return
395+
return
390396
}
391-
// CHECK: return
392-
return
393397
}
394398

395399
// -----

0 commit comments

Comments
 (0)