1 // RUN: mlir-opt -pass-pipeline="builtin.module(func.func(convert-arith-to-llvm),convert-func-to-llvm,reconcile-unrealized-casts)" -split-input-file %s | FileCheck %s
2 // RUN: mlir-opt -pass-pipeline="builtin.module(func.func(convert-arith-to-llvm),convert-func-to-llvm{use-bare-ptr-memref-call-conv=1},reconcile-unrealized-casts)" -split-input-file %s | FileCheck %s --check-prefix=BAREPTR
4 // BAREPTR-LABEL: func @check_noalias
5 // BAREPTR-SAME: %{{.*}}: !llvm.ptr {llvm.noalias}, %{{.*}}: !llvm.ptr {llvm.noalias}
6 func.func @check_noalias(%static : memref<2xf32> {llvm.noalias}, %other : memref<2xf32> {llvm.noalias}) {
12 // CHECK-LABEL: func @check_strided_memref_arguments(
13 // CHECK-COUNT-2: !llvm.ptr
15 // CHECK-COUNT-2: !llvm.ptr
17 // CHECK-COUNT-2: !llvm.ptr
19 func.func @check_strided_memref_arguments(%static: memref<10x20xf32, affine_map<(i,j)->(20 * i + j + 1)>>,
20 %dynamic : memref<?x?xf32, affine_map<(i,j)[M]->(M * i + j + 1)>>,
21 %mixed : memref<10x?xf32, affine_map<(i,j)[M]->(M * i + j + 1)>>) {
27 // CHECK-LABEL: func @memref_index
28 // CHECK-SAME: %arg0: !llvm.ptr, %arg1: !llvm.ptr,
29 // CHECK-SAME: %arg2: i64, %arg3: i64, %arg4: i64)
30 // CHECK-SAME: -> !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
31 // CHECK32-LABEL: func @memref_index
32 // CHECK32-SAME: %arg0: !llvm.ptr, %arg1: !llvm.ptr,
33 // CHECK32-SAME: %arg2: i32, %arg3: i32, %arg4: i32)
34 // CHECK32-SAME: -> !llvm.struct<(ptr, ptr, i32, array<1 x i32>, array<1 x i32>)>
35 func.func @memref_index(%arg0: memref<32xindex>) -> memref<32xindex> {
36 return %arg0 : memref<32xindex>
41 // CHECK-LABEL: func @check_arguments
42 // CHECK-COUNT-2: !llvm.ptr
44 // CHECK-COUNT-2: !llvm.ptr
46 // CHECK-COUNT-2: !llvm.ptr
48 func.func @check_arguments(%static: memref<10x20xf32>, %dynamic : memref<?x?xf32>, %mixed : memref<10x?xf32>) {
54 // Unranked memrefs are currently not supported in the bare-ptr calling
55 // convention. Check that the conversion to the LLVM-IR dialect doesn't happen
56 // in the presence of unranked memrefs when using such a calling convention.
58 // BAREPTR: func private @hoo(memref<*xi8>) -> memref<*xi8>
59 func.func private @hoo(memref<*xi8>) -> memref<*xi8>
61 // BAREPTR-LABEL: func @check_unranked_memref_func_call(%{{.*}}: memref<*xi8>) -> memref<*xi8>
62 func.func @check_unranked_memref_func_call(%in: memref<*xi8>) -> memref<*xi8> {
63 // BAREPTR-NEXT: call @hoo(%{{.*}}) : (memref<*xi8>) -> memref<*xi8>
64 %res = call @hoo(%in) : (memref<*xi8>) -> memref<*xi8>
65 // BAREPTR-NEXT: return %{{.*}} : memref<*xi8>
66 return %res : memref<*xi8>
71 // Should not convert memrefs with unsupported types in any convention.
73 // CHECK: @unsupported_memref_element_type
74 // CHECK-SAME: memref<
75 // CHECK-NOT: !llvm.struct
76 // BAREPTR: @unsupported_memref_element_type
77 // BAREPTR-SAME: memref<
78 // BAREPTR-NOT: !llvm.ptr
79 func.func private @unsupported_memref_element_type() -> memref<42 x !test.memref_element>
81 // CHECK: @unsupported_unranked_memref_element_type
82 // CHECK-SAME: memref<
83 // CHECK-NOT: !llvm.struct
84 // BAREPTR: @unsupported_unranked_memref_element_type
85 // BAREPTR-SAME: memref<
86 // BAREPTR-NOT: !llvm.ptr
87 func.func private @unsupported_unranked_memref_element_type() -> memref<* x !test.memref_element>
91 // BAREPTR: llvm.func @goo(f32) -> f32
92 func.func private @goo(f32) -> f32
94 // BAREPTR-LABEL: func @check_scalar_func_call
95 // BAREPTR-SAME: %[[in:.*]]: f32)
96 func.func @check_scalar_func_call(%in : f32) {
97 // BAREPTR-NEXT: %[[call:.*]] = llvm.call @goo(%[[in]]) : (f32) -> f32
98 %res = call @goo(%in) : (f32) -> (f32)
104 !base_type = memref<64xi32, 201>
106 // CHECK-LABEL: func @loop_carried
107 // BAREPTR-LABEL: func @loop_carried
108 func.func @loop_carried(%arg0 : index, %arg1 : index, %arg2 : index, %base0 : !base_type, %base1 : !base_type) -> (!base_type, !base_type) {
109 // This test checks that in the BAREPTR case, the branch arguments only forward the descriptor.
110 // This test was lowered from a simple scf.for that swaps 2 memref iter_args.
111 // BAREPTR: llvm.br ^bb1(%{{.*}}, %{{.*}}, %{{.*}} : i64, !llvm.struct<(ptr<201>, ptr<201>, i64, array<1 x i64>, array<1 x i64>)>, !llvm.struct<(ptr<201>, ptr<201>, i64, array<1 x i64>, array<1 x i64>)>)
112 cf.br ^bb1(%arg0, %base0, %base1 : index, memref<64xi32, 201>, memref<64xi32, 201>)
114 // BAREPTR-NEXT: ^bb1
115 // BAREPTR-NEXT: llvm.icmp
116 // BAREPTR-NEXT: llvm.cond_br %{{.*}}, ^bb2, ^bb3
117 ^bb1(%0: index, %1: memref<64xi32, 201>, %2: memref<64xi32, 201>): // 2 preds: ^bb0, ^bb2
118 %3 = arith.cmpi slt, %0, %arg1 : index
119 cf.cond_br %3, ^bb2, ^bb3
121 %4 = arith.addi %0, %arg2 : index
122 cf.br ^bb1(%4, %2, %1 : index, memref<64xi32, 201>, memref<64xi32, 201>)
124 return %1, %2 : memref<64xi32, 201>, memref<64xi32, 201>