[Mlir-commits] [mlir] Added RecursiveMemoryEffects to ExecuteRegionOp (PR #164390)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Oct 27 08:28:53 PDT 2025
https://github.com/ddubov100 updated https://github.com/llvm/llvm-project/pull/164390
>From 15b97e69989ac82e20f14a7a509feea86cc7b8a9 Mon Sep 17 00:00:00 2001
From: dubov diana <ddubov at mobileye.com>
Date: Tue, 21 Oct 2025 13:30:10 +0300
Subject: [PATCH 1/4] Added RecursiveMemoryEffects to ExecuteRegionOp like all
other ops with region.
---
mlir/include/mlir/Dialect/SCF/IR/SCFOps.td | 2 +-
.../dealloc-memoryeffect-interface.mlir | 20 +++++++++++++++++++
.../Transforms/one-shot-module-bufferize.mlir | 20 +++++++++++--------
3 files changed, 33 insertions(+), 9 deletions(-)
diff --git a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
index fadd3fc10bfc4..66174ce0f7928 100644
--- a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
+++ b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
@@ -77,7 +77,7 @@ def ConditionOp : SCF_Op<"condition", [
//===----------------------------------------------------------------------===//
def ExecuteRegionOp : SCF_Op<"execute_region", [
- DeclareOpInterfaceMethods<RegionBranchOpInterface>]> {
+ DeclareOpInterfaceMethods<RegionBranchOpInterface>, RecursiveMemoryEffects]> {
let summary = "operation that executes its region exactly once";
let description = [{
The `scf.execute_region` operation is used to allow multiple blocks within SCF
diff --git a/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir b/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir
index 40a57b90c6e99..c92218a7689c1 100644
--- a/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir
+++ b/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir
@@ -156,3 +156,23 @@ func.func @manual_deallocation(%c: i1, %f: f32, %idx: index) -> f32 {
// CHECK: cf.assert %[[true]], "expected that the block does not have ownership"
// CHECK: memref.dealloc %[[manual_alloc]]
// CHECK: bufferization.dealloc (%[[managed_alloc]] : memref<5xf32>) if (%[[true]])
+
+// -----
+
+// CHECK: %[[true:.*]] = arith.constant true
+// CHECK: scf.execute_region no_inline {
+// CHECK: %[[alloc:.*]] = memref.alloc() {alignment = 64 : i64} : memref<1x63x378x16xui8>
+// CHECK: bufferization.dealloc (%[[alloc]] : memref<1x63x378x16xui8>) if (%[[true]])
+
+func.func private @properly_creats_deallocations_in_execute_region(%arg1: memref<1x16x252x380xui8> ) -> (memref<1x250x378x16xui8> ) {
+ %alloc = memref.alloc() {alignment = 64 : i64} : memref<1x250x378x16xui8>
+ scf.execute_region no_inline {
+ %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]>>
+ %alloc_3 = memref.alloc() {alignment = 64 : i64} : memref<1x63x378x16xui8>
+ test.buffer_based in(%subview: memref<1x16x65x380xui8, strided<[1532160, 95760, 380, 1]>>) out(%alloc_3: memref<1x63x378x16xui8>)
+ %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]>>
+ test.copy(%alloc_3, %subview_7) : (memref<1x63x378x16xui8>, memref<1x63x378x16xui8, strided<[1512000, 6048, 16, 1]>>)
+ scf.yield
+ }
+ return %alloc : memref<1x250x378x16xui8>
+}
\ No newline at end of file
diff --git a/mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize.mlir b/mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize.mlir
index d5f834bce9b83..8db1ebb87a1e5 100644
--- a/mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize.mlir
+++ b/mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize.mlir
@@ -381,15 +381,19 @@ func.func private @execute_region_test(%t1 : tensor<?xf32>)
// -----
// CHECK-LABEL: func @no_inline_execute_region_not_canonicalized
-func.func @no_inline_execute_region_not_canonicalized() {
- %c = arith.constant 42 : i32
- // CHECK: scf.execute_region
- // CHECK-SAME: no_inline
- %v = scf.execute_region -> i32 no_inline {
- scf.yield %c : i32
+module {
+ func.func private @foo()->()
+ func.func @no_inline_execute_region_not_canonicalized() {
+ %c = arith.constant 42 : i32
+ // CHECK: scf.execute_region
+ // CHECK-SAME: no_inline
+ %v = scf.execute_region -> i32 no_inline {
+ func.call @foo():()->()
+ scf.yield %c : i32
+ }
+ // CHECK: return
+ return
}
- // CHECK: return
- return
}
// -----
>From 65ce4232c506b6eb7d9d2564bf392e70d2168a25 Mon Sep 17 00:00:00 2001
From: ddubov100 <155631080+ddubov100 at users.noreply.github.com>
Date: Mon, 27 Oct 2025 17:28:22 +0200
Subject: [PATCH 2/4] Update
mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir
Co-authored-by: Mehdi Amini <joker.eph at gmail.com>
---
.../dealloc-memoryeffect-interface.mlir | 1 +
1 file changed, 1 insertion(+)
diff --git a/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir b/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir
index c92218a7689c1..4fceacdf37621 100644
--- a/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir
+++ b/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir
@@ -159,6 +159,7 @@ func.func @manual_deallocation(%c: i1, %f: f32, %idx: index) -> f32 {
// -----
+// CHECK-LABEL: func.func private @properly_creats_deallocations_in_execute_region(
// CHECK: %[[true:.*]] = arith.constant true
// CHECK: scf.execute_region no_inline {
// CHECK: %[[alloc:.*]] = memref.alloc() {alignment = 64 : i64} : memref<1x63x378x16xui8>
>From 6be3300521e3522bc7990d38ec3c973ad1725199 Mon Sep 17 00:00:00 2001
From: ddubov100 <155631080+ddubov100 at users.noreply.github.com>
Date: Mon, 27 Oct 2025 17:28:33 +0200
Subject: [PATCH 3/4] Update
mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir
Co-authored-by: Mehdi Amini <joker.eph at gmail.com>
---
.../dealloc-memoryeffect-interface.mlir | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir b/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir
index 4fceacdf37621..05c74239d851f 100644
--- a/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir
+++ b/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir
@@ -165,7 +165,7 @@ func.func @manual_deallocation(%c: i1, %f: f32, %idx: index) -> f32 {
// CHECK: %[[alloc:.*]] = memref.alloc() {alignment = 64 : i64} : memref<1x63x378x16xui8>
// CHECK: bufferization.dealloc (%[[alloc]] : memref<1x63x378x16xui8>) if (%[[true]])
-func.func private @properly_creats_deallocations_in_execute_region(%arg1: memref<1x16x252x380xui8> ) -> (memref<1x250x378x16xui8> ) {
+func.func private @properly_creates_deallocations_in_execute_region(%arg1: memref<1x16x252x380xui8> ) -> (memref<1x250x378x16xui8> ) {
%alloc = memref.alloc() {alignment = 64 : i64} : memref<1x250x378x16xui8>
scf.execute_region no_inline {
%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]>>
>From b34455da5d64ce92f75e84a4667018dd0eee750d Mon Sep 17 00:00:00 2001
From: ddubov100 <155631080+ddubov100 at users.noreply.github.com>
Date: Mon, 27 Oct 2025 17:28:44 +0200
Subject: [PATCH 4/4] Update
mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir
Co-authored-by: Mehdi Amini <joker.eph at gmail.com>
---
.../dealloc-memoryeffect-interface.mlir | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir b/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir
index 05c74239d851f..db502ddc8f9fb 100644
--- a/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir
+++ b/mlir/test/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation/dealloc-memoryeffect-interface.mlir
@@ -176,4 +176,4 @@ func.func private @properly_creates_deallocations_in_execute_region(%arg1: memre
scf.yield
}
return %alloc : memref<1x250x378x16xui8>
-}
\ No newline at end of file
+}
More information about the Mlir-commits
mailing list