1// RUN: mlir-opt -verify-diagnostics -ownership-based-buffer-deallocation \
2// RUN:   --buffer-deallocation-simplification -canonicalize -split-input-file %s | FileCheck %s
3
4// No ownership is assumed for ops that do not implement any interface and have
5// no memref operands.
6
7// CHECK-LABEL: func private @no_interface_no_operands(
8//  CHECK-NEXT:   %[[m:.*]] = bufferization.to_memref
9//  CHECK-NEXT:   %[[clone:.*]] = bufferization.clone %[[m]]
10//  CHECK-NEXT:   return %[[clone]]
11func.func private @no_interface_no_operands(%t : tensor<?x?x?xf16>) -> memref<?x?x?xf16> {
12  %0 = bufferization.to_memref %t : tensor<?x?x?xf16> to memref<?x?x?xf16>
13  return %0 : memref<?x?x?xf16>
14}
15
16// -----
17
18// If an op does not implement any interface but has memref operands, the
19// ownership of the memref results is computed from the operands.
20
21// CHECK-LABEL: func private @no_interface(
22//       CHECK:   %[[true:.*]] = arith.constant true
23//       CHECK:   %[[alloc:.*]] = memref.alloc
24//       CHECK:   %[[foo:.*]] = "test.forward_buffer"(%[[alloc]])
25//       CHECK:   %[[r:.*]] = bufferization.dealloc (%[[alloc]] : {{.*}}) if (%[[true]]) retain (%[[foo]] : {{.*}})
26//       CHECK:   return %[[foo]]
27func.func private @no_interface() -> memref<5xf32> {
28  %0 = memref.alloc() : memref<5xf32>
29  %1 = "test.forward_buffer"(%0) : (memref<5xf32>) -> (memref<5xf32>)
30  return %1 : memref<5xf32>
31}
32
33// -----
34
35func.func @no_side_effects() {
36  %0 = memref.alloc() : memref<5xf32>
37  // expected-error @below{{ops with unknown memory side effects are not supported}}
38  "test.unregistered_op_foo"(%0) : (memref<5xf32>) -> ()
39  return
40}
41
42// -----
43
44// Buffer deallocation should not emit any error here as the operation does not
45// operate on buffers and has known memory effect (write).
46func.func @no_buffer_semantics_with_write_effect(%v0: vector<9x6xf32>) {
47  vector.print %v0 : vector<9x6xf32>
48  return
49}
50