1 // RUN: mlir-opt -buffer-results-to-out-params -split-input-file -verify-diagnostics %s | FileCheck %s
3 // CHECK-LABEL: func @basic(
4 // CHECK-SAME: %[[ARG:.*]]: memref<f32>) {
5 // CHECK: %[[RESULT:.*]] = "test.source"() : () -> memref<f32>
6 // CHECK: memref.copy %[[RESULT]], %[[ARG]] : memref<f32> to memref<f32>
9 func.func @basic() -> (memref<f32>) {
10 %0 = "test.source"() : () -> (memref<f32>)
11 return %0 : memref<f32>
14 // CHECK-LABEL: func @presence_of_existing_arguments(
15 // CHECK-SAME: %[[ARG0:.*]]: memref<1xf32>,
16 // CHECK-SAME: %[[ARG1:.*]]: memref<2xf32>) {
17 // CHECK: %[[RESULT:.*]] = "test.source"() : () -> memref<2xf32>
18 // CHECK: memref.copy %[[RESULT]], %[[ARG1]] : memref<2xf32> to memref<2xf32>
21 func.func @presence_of_existing_arguments(%arg0: memref<1xf32>) -> (memref<2xf32>) {
22 %0 = "test.source"() : () -> (memref<2xf32>)
23 return %0 : memref<2xf32>
26 // CHECK-LABEL: func @multiple_results(
27 // CHECK-SAME: %[[ARG0:.*]]: memref<1xf32>,
28 // CHECK-SAME: %[[ARG1:.*]]: memref<2xf32>) {
29 // CHECK: %[[RESULTS:.*]]:2 = "test.source"() : () -> (memref<1xf32>, memref<2xf32>)
30 // CHECK: memref.copy %[[RESULTS]]#0, %[[ARG0]] : memref<1xf32> to memref<1xf32>
31 // CHECK: memref.copy %[[RESULTS]]#1, %[[ARG1]] : memref<2xf32> to memref<2xf32>
34 func.func @multiple_results() -> (memref<1xf32>, memref<2xf32>) {
35 %0, %1 = "test.source"() : () -> (memref<1xf32>, memref<2xf32>)
36 return %0, %1 : memref<1xf32>, memref<2xf32>
39 // CHECK-LABEL: func @non_memref_types(
40 // CHECK-SAME: %[[OUTPARAM:.*]]: memref<f32>) -> (i1, i32) {
41 // CHECK: %[[RESULT1:.*]]:3 = "test.source"() : () -> (i1, memref<f32>, i32)
42 // CHECK: memref.copy %[[RESULT1]]#1, %[[OUTPARAM]] : memref<f32> to memref<f32>
43 // CHECK: return %[[RESULT1]]#0, %[[RESULT1]]#2 : i1, i32
45 func.func @non_memref_types() -> (i1, memref<f32>, i32) {
46 %0, %1, %2 = "test.source"() : () -> (i1, memref<f32>, i32)
47 return %0, %1, %2 : i1, memref<f32>, i32
50 // CHECK: func private @external_function(memref<f32>)
51 func.func private @external_function() -> (memref<f32>)
52 // CHECK: func private @result_attrs(memref<f32> {test.some_attr})
53 func.func private @result_attrs() -> (memref<f32> {test.some_attr})
54 // CHECK: func private @mixed_result_attrs(memref<1xf32>, memref<2xf32> {test.some_attr}, memref<3xf32>)
55 func.func private @mixed_result_attrs() -> (memref<1xf32>, memref<2xf32> {test.some_attr}, memref<3xf32>)
59 // CHECK-LABEL: func private @callee(memref<1xf32>)
60 func.func private @callee() -> memref<1xf32>
62 // CHECK-LABEL: func @call_basic() {
63 // CHECK: %[[OUTPARAM:.*]] = memref.alloc() : memref<1xf32>
64 // CHECK: call @callee(%[[OUTPARAM]]) : (memref<1xf32>) -> ()
65 // CHECK: "test.sink"(%[[OUTPARAM]]) : (memref<1xf32>) -> ()
68 func.func @call_basic() {
69 %0 = call @callee() : () -> memref<1xf32>
70 "test.sink"(%0) : (memref<1xf32>) -> ()
76 // CHECK-LABEL: func private @callee(memref<1xf32>, memref<2xf32>)
77 func.func private @callee() -> (memref<1xf32>, memref<2xf32>)
79 // CHECK-LABEL: func @call_multiple_result() {
80 // CHECK: %[[RESULT0:.*]] = memref.alloc() : memref<1xf32>
81 // CHECK: %[[RESULT1:.*]] = memref.alloc() : memref<2xf32>
82 // CHECK: call @callee(%[[RESULT0]], %[[RESULT1]]) : (memref<1xf32>, memref<2xf32>) -> ()
83 // CHECK: "test.sink"(%[[RESULT0]], %[[RESULT1]]) : (memref<1xf32>, memref<2xf32>) -> ()
85 func.func @call_multiple_result() {
86 %0, %1 = call @callee() : () -> (memref<1xf32>, memref<2xf32>)
87 "test.sink"(%0, %1) : (memref<1xf32>, memref<2xf32>) -> ()
92 // CHECK-LABEL: func private @callee(memref<1xf32>) -> (i1, i32)
93 func.func private @callee() -> (i1, memref<1xf32>, i32)
95 // CHECK-LABEL: func @call_non_memref_result() {
96 // CHECK: %[[RESULT0:.*]] = memref.alloc() : memref<1xf32>
97 // CHECK: %[[NON_MEMREF_RESULTS:.*]]:2 = call @callee(%[[RESULT0]]) : (memref<1xf32>) -> (i1, i32)
98 // CHECK: "test.sink"(%[[NON_MEMREF_RESULTS]]#0, %[[RESULT0]], %[[NON_MEMREF_RESULTS]]#1) : (i1, memref<1xf32>, i32) -> ()
100 func.func @call_non_memref_result() {
101 %0, %1, %2 = call @callee() : () -> (i1, memref<1xf32>, i32)
102 "test.sink"(%0, %1, %2) : (i1, memref<1xf32>, i32) -> ()
107 func.func private @callee() -> (memref<?xf32>)
109 func.func @call_non_memref_result() {
110 // expected-error @+1 {{cannot create out param for dynamically shaped result}}
111 %0 = call @callee() : () -> (memref<?xf32>)
112 "test.sink"(%0) : (memref<?xf32>) -> ()