convert-funcs.mlir
2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// RUN: mlir-opt -convert-std-to-llvm %s | FileCheck %s
//CHECK: llvm.func @second_order_arg(!llvm<"void ()*">)
func @second_order_arg(%arg0 : () -> ())
//CHECK: llvm.func @second_order_result() -> !llvm<"void ()*">
func @second_order_result() -> (() -> ())
//CHECK: llvm.func @second_order_multi_result() -> !llvm<"{ i32 ()*, i64 ()*, float ()* }">
func @second_order_multi_result() -> (() -> (i32), () -> (i64), () -> (f32))
//CHECK: llvm.func @third_order(!llvm<"void ()* (void ()*)*">) -> !llvm<"void ()* (void ()*)*">
func @third_order(%arg0 : (() -> ()) -> (() -> ())) -> ((() -> ()) -> (() -> ()))
//CHECK: llvm.func @fifth_order_left(!llvm<"void (void (void (void ()*)*)*)*">)
func @fifth_order_left(%arg0: (((() -> ()) -> ()) -> ()) -> ())
//CHECK: llvm.func @fifth_order_right(!llvm<"void ()* ()* ()* ()*">)
func @fifth_order_right(%arg0: () -> (() -> (() -> (() -> ()))))
// Check that memrefs are converted to pointers-to-struct if appear as function arguments.
// CHECK: llvm.func @memref_call_conv(!llvm<"{ float*, float*, i64, [1 x i64], [1 x i64] }*">)
func @memref_call_conv(%arg0: memref<?xf32>)
// Same in nested functions.
// CHECK: llvm.func @memref_call_conv_nested(!llvm<"void ({ float*, float*, i64, [1 x i64], [1 x i64] }*)*">)
func @memref_call_conv_nested(%arg0: (memref<?xf32>) -> ())
//CHECK-LABEL: llvm.func @pass_through(%arg0: !llvm<"void ()*">) -> !llvm<"void ()*"> {
func @pass_through(%arg0: () -> ()) -> (() -> ()) {
// CHECK-NEXT: llvm.br ^bb1(%arg0 : !llvm<"void ()*">)
br ^bb1(%arg0 : () -> ())
//CHECK-NEXT: ^bb1(%0: !llvm<"void ()*">): // pred: ^bb0
^bb1(%bbarg: () -> ()):
// CHECK-NEXT: llvm.return %0 : !llvm<"void ()*">
return %bbarg : () -> ()
}
// CHECK-LABEL: llvm.func @body(!llvm.i32)
func @body(i32)
// CHECK-LABEL: llvm.func @indirect_const_call(%arg0: !llvm.i32) {
func @indirect_const_call(%arg0: i32) {
// CHECK-NEXT: %0 = llvm.mlir.constant(@body) : !llvm<"void (i32)*">
%0 = constant @body : (i32) -> ()
// CHECK-NEXT: llvm.call %0(%arg0) : (!llvm.i32) -> ()
call_indirect %0(%arg0) : (i32) -> ()
// CHECK-NEXT: llvm.return
return
}
// CHECK-LABEL: llvm.func @indirect_call(%arg0: !llvm<"i32 (float)*">, %arg1: !llvm.float) -> !llvm.i32 {
func @indirect_call(%arg0: (f32) -> i32, %arg1: f32) -> i32 {
// CHECK-NEXT: %0 = llvm.call %arg0(%arg1) : (!llvm.float) -> !llvm.i32
%0 = call_indirect %arg0(%arg1) : (f32) -> i32
// CHECK-NEXT: llvm.return %0 : !llvm.i32
return %0 : i32
}