xref: /llvm-project/mlir/test/Dialect/Bufferization/Transforms/lower-deallocations-func.mlir (revision f0b0c02504899c1bc00c6e6428e7aebe9ea5beb1)
1// RUN: mlir-opt -verify-diagnostics --pass-pipeline="builtin.module(func.func(bufferization-lower-deallocations))" -split-input-file %s | FileCheck %s
2
3// CHECK-NOT: func @deallocHelper
4// CHECK-LABEL: func @conversion_dealloc_simple
5// CHECK-SAME: [[ARG0:%.+]]: memref<2xf32>
6// CHECK-SAME: [[ARG1:%.+]]: i1
7func.func @conversion_dealloc_simple(%arg0: memref<2xf32>, %arg1: i1) {
8  bufferization.dealloc (%arg0 : memref<2xf32>) if (%arg1)
9  return
10}
11
12//      CHECK: scf.if [[ARG1]] {
13// CHECK-NEXT:   memref.dealloc [[ARG0]] : memref<2xf32>
14// CHECK-NEXT: }
15// CHECK-NEXT: return
16
17// -----
18
19func.func @conversion_dealloc_multiple_memrefs_and_retained(%arg0: memref<2xf32>, %arg1: memref<5xf32>, %arg2: memref<1xf32>, %arg3: i1, %arg4: i1, %arg5: memref<2xf32>) -> (i1, i1) {
20  // expected-error @below {{library function required for generic lowering, but cannot be automatically inserted when operating on functions}}
21  // expected-error @below {{failed to legalize operation 'bufferization.dealloc' that was explicitly marked illegal}}
22  %0:2 = bufferization.dealloc (%arg0, %arg1 : memref<2xf32>, memref<5xf32>) if (%arg3, %arg4) retain (%arg2, %arg5 : memref<1xf32>, memref<2xf32>)
23  return %0#0, %0#1 : i1, i1
24}
25