xref: /llvm-project/mlir/test/Conversion/FuncToLLVM/emit-c-wrappers-for-external-callers.mlir (revision fcb9a8a5eeeba0823a8cd3d364acf4b04b6dc7ab)
1// RUN: mlir-opt -llvm-request-c-wrappers -convert-func-to-llvm %s | FileCheck %s
2
3// CHECK: llvm.func @res_attrs_with_memref_return() -> (!llvm.struct{{.*}} {test.returnOne})
4// CHECK-LABEL: llvm.func @_mlir_ciface_res_attrs_with_memref_return
5// CHECK-NOT: test.returnOne
6func.func @res_attrs_with_memref_return() -> (memref<f32> {test.returnOne}) {
7  %0 = memref.alloc() : memref<f32>
8  return %0 : memref<f32>
9}
10
11// CHECK: llvm.func @res_attrs_with_value_return() -> (f32 {test.returnOne = 1 : i64})
12// CHECK-LABEL: llvm.func @_mlir_ciface_res_attrs_with_value_return
13// CHECK-SAME: -> (f32 {test.returnOne = 1 : i64})
14func.func @res_attrs_with_value_return() -> (f32 {test.returnOne = 1}) {
15  %0 = arith.constant 1.00 : f32
16  return %0 : f32
17}
18
19// CHECK: llvm.func @multiple_return() -> !llvm.struct<{{.*}}>
20// CHECK-LABEL: llvm.func @_mlir_ciface_multiple_return
21// CHECK-SAME: !llvm.ptr
22// CHECK-NOT: test.returnOne
23// CHECK-NOT: test.returnTwo
24// CHECK-NOT: test.returnThree
25func.func @multiple_return() -> (memref<f32> {test.returnOne = 1}, f32 {test.returnTwo = 2, test.returnThree = 3}) {
26  %0 = memref.alloc() : memref<f32>
27  %1 = arith.constant 1.00 : f32
28  return %0, %1 : memref<f32>, f32
29}
30
31// CHECK: llvm.func @multiple_return_missing_res_attr() -> !llvm.struct<{{.*}}>
32// CHECK-LABEL: llvm.func @_mlir_ciface_multiple_return_missing_res_attr
33// CHECK-SAME: !llvm.ptr
34// CHECK-NOT: test.returnOne
35// CHECK-NOT: test.returnTwo
36// CHECK-NOT: test.returnThree
37func.func @multiple_return_missing_res_attr() -> (memref<f32> {test.returnOne = 1}, i64, f32 {test.returnTwo = 2, test.returnThree = 3}) {
38  %0 = memref.alloc() : memref<f32>
39  %1 = arith.constant 2 : i64
40  %2 = arith.constant 1.00 : f32
41  return %0, %1, %2 : memref<f32>, i64, f32
42}
43
44// CHECK: llvm.func @one_arg_attr_no_res_attrs_with_memref_return({{.*}}) -> !llvm.struct{{.*}}
45// CHECK-LABEL: llvm.func @_mlir_ciface_one_arg_attr_no_res_attrs_with_memref_return
46// CHECK-SAME: !llvm.ptr
47// CHECK-SAME: !llvm.ptr
48// CHECK-SAME: {test.argOne = 1 : i64})
49func.func @one_arg_attr_no_res_attrs_with_memref_return(%arg0: memref<f32> {test.argOne = 1}) -> memref<f32> {
50  %0 = memref.alloc() : memref<f32>
51  return %0 : memref<f32>
52}
53
54// CHECK: llvm.func @one_arg_attr_one_res_attr_with_memref_return({{.*}}) -> (!llvm.struct<{{.*}}> {test.returnOne = 1 : i64})
55// CHECK-LABEL: llvm.func @_mlir_ciface_one_arg_attr_one_res_attr_with_memref_return
56// CHECK-SAME: !llvm.ptr
57// CHECK-NOT: test.returnOne
58// CHECK-SAME: !llvm.ptr
59// CHECK-SAME: {test.argOne = 1 : i64})
60func.func @one_arg_attr_one_res_attr_with_memref_return(%arg0: memref<f32> {test.argOne = 1}) -> (memref<f32> {test.returnOne = 1}) {
61  %0 = memref.alloc() : memref<f32>
62  return %0 : memref<f32>
63}
64
65// CHECK: llvm.func @one_arg_attr_one_res_attr_with_value_return({{.*}}) -> (f32 {test.returnOne = 1 : i64})
66// CHECK-LABEL: llvm.func @_mlir_ciface_one_arg_attr_one_res_attr_with_value_return
67// CHECK-SAME: !llvm.ptr
68// CHECK-SAME: {test.argOne = 1 : i64})
69// CHECK-SAME: -> (f32 {test.returnOne = 1 : i64})
70func.func @one_arg_attr_one_res_attr_with_value_return(%arg0: memref<f32> {test.argOne = 1}) -> (f32 {test.returnOne = 1}) {
71  %0 = arith.constant 1.00 : f32
72  return %0 : f32
73}
74
75// CHECK: llvm.func @multiple_arg_attr_multiple_res_attr({{.*}}) -> !llvm.struct<{{.*}}>
76// CHECK-LABEL: llvm.func @_mlir_ciface_multiple_arg_attr_multiple_res_attr
77// CHECK-SAME: !llvm.ptr
78// CHECK-NOT: test.returnOne
79// CHECK-NOT: test.returnTwo
80// CHECK-SAME: !llvm.ptr
81// CHECK-SAME: {test.argZero = 0 : i64}
82// CHECK-SAME: f32
83// CHECK-SAME: i32 {test.argTwo = 2 : i64})
84func.func @multiple_arg_attr_multiple_res_attr(%arg0: memref<f32> {test.argZero = 0}, %arg1: f32, %arg2: i32 {test.argTwo = 2}) -> (f32, memref<i32> {test.returnOne = 1}, i32 {test.returnTwo = 2}) {
85  %0 = arith.constant 1.00 : f32
86  %1 = memref.alloc() : memref<i32>
87  %2 = arith.constant 2 : i32
88  return %0, %1, %2 : f32, memref<i32>, i32
89}
90
91// CHECK: llvm.func @drop_linkage_attr() -> (!llvm.struct{{.*}} {test.returnOne})
92// CHECK-LABEL: llvm.func @_mlir_ciface_drop_linkage_attr
93// CHECK-SAME: !llvm.ptr
94// CHECK-NOT: llvm.linkage
95func.func @drop_linkage_attr() -> (memref<f32> {test.returnOne}) attributes { llvm.linkage = #llvm.linkage<external> } {
96  %0 = memref.alloc() : memref<f32>
97  return %0 : memref<f32>
98}
99