1 // RUN: mlir-opt -convert-std-to-llvm -split-input-file -verify-diagnostics %s | FileCheck %s
3 //CHECK: llvm.func @second_order_arg(!llvm.ptr<func<void ()>>)
4 func private @second_order_arg(%arg0 : () -> ())
6 //CHECK: llvm.func @second_order_result() -> !llvm.ptr<func<void ()>>
7 func private @second_order_result() -> (() -> ())
9 //CHECK: llvm.func @second_order_multi_result() -> !llvm.struct<(ptr<func<i32 ()>>, ptr<func<i64 ()>>, ptr<func<f32 ()>>)>
10 func private @second_order_multi_result() -> (() -> (i32), () -> (i64), () -> (f32))
12 //CHECK: llvm.func @third_order(!llvm.ptr<func<ptr<func<void ()>> (ptr<func<void ()>>)>>) -> !llvm.ptr<func<ptr<func<void ()>> (ptr<func<void ()>>)>>
13 func private @third_order(%arg0 : (() -> ()) -> (() -> ())) -> ((() -> ()) -> (() -> ()))
15 //CHECK: llvm.func @fifth_order_left(!llvm.ptr<func<void (ptr<func<void (ptr<func<void (ptr<func<void ()>>)>>)>>)>>)
16 func private @fifth_order_left(%arg0: (((() -> ()) -> ()) -> ()) -> ())
18 //CHECK: llvm.func @fifth_order_right(!llvm.ptr<func<ptr<func<ptr<func<ptr<func<void ()>> ()>> ()>> ()>>)
19 func private @fifth_order_right(%arg0: () -> (() -> (() -> (() -> ()))))
21 // Check that memrefs are converted to argument packs if appear as function arguments.
22 // CHECK: llvm.func @memref_call_conv(!llvm.ptr<f32>, !llvm.ptr<f32>, i64, i64, i64)
23 func private @memref_call_conv(%arg0: memref<?xf32>)
25 // Same in nested functions.
26 // CHECK: llvm.func @memref_call_conv_nested(!llvm.ptr<func<void (ptr<f32>, ptr<f32>, i64, i64, i64)>>)
27 func private @memref_call_conv_nested(%arg0: (memref<?xf32>) -> ())
29 //CHECK-LABEL: llvm.func @pass_through(%arg0: !llvm.ptr<func<void ()>>) -> !llvm.ptr<func<void ()>> {
30 func @pass_through(%arg0: () -> ()) -> (() -> ()) {
31 // CHECK-NEXT: llvm.br ^bb1(%arg0 : !llvm.ptr<func<void ()>>)
32 br ^bb1(%arg0 : () -> ())
34 //CHECK-NEXT: ^bb1(%0: !llvm.ptr<func<void ()>>):
35 ^bb1(%bbarg: () -> ()):
36 // CHECK-NEXT: llvm.return %0 : !llvm.ptr<func<void ()>>
37 return %bbarg : () -> ()
40 // CHECK-LABEL: llvm.func extern_weak @llvmlinkage(i32)
41 func private @llvmlinkage(i32) attributes { "llvm.linkage" = #llvm.linkage<extern_weak> }
43 // CHECK-LABEL: llvm.func @body(i32)
44 func private @body(i32)
46 // CHECK-LABEL: llvm.func @indirect_const_call
47 // CHECK-SAME: (%[[ARG0:.*]]: i32) {
48 func @indirect_const_call(%arg0: i32) {
49 // CHECK-NEXT: %[[ADDR:.*]] = llvm.mlir.addressof @body : !llvm.ptr<func<void (i32)>>
50 %0 = constant @body : (i32) -> ()
51 // CHECK-NEXT: llvm.call %[[ADDR]](%[[ARG0:.*]]) : (i32) -> ()
52 call_indirect %0(%arg0) : (i32) -> ()
53 // CHECK-NEXT: llvm.return
57 // CHECK-LABEL: llvm.func @indirect_call(%arg0: !llvm.ptr<func<i32 (f32)>>, %arg1: f32) -> i32 {
58 func @indirect_call(%arg0: (f32) -> i32, %arg1: f32) -> i32 {
59 // CHECK-NEXT: %0 = llvm.call %arg0(%arg1) : (f32) -> i32
60 %0 = call_indirect %arg0(%arg1) : (f32) -> i32
61 // CHECK-NEXT: llvm.return %0 : i32
67 func private @badllvmlinkage(i32) attributes { "llvm.linkage" = 3 : i64 } // expected-error {{Contains llvm.linkage attribute not of type LLVM::LinkageAttr}}