1 // RUN: mlir-opt %s -convert-linalg-to-loops \
2 // RUN: -convert-scf-to-std \
3 // RUN: -convert-arith-to-llvm \
4 // RUN: -convert-linalg-to-llvm \
5 // RUN: -convert-memref-to-llvm \
6 // RUN: -convert-std-to-llvm \
7 // RUN: -reconcile-unrealized-casts | \
8 // RUN: mlir-cpu-runner -e main -entry-point-result=void \
9 // RUN: -shared-libs=%mlir_runner_utils_dir/libmlir_runner_utils%shlibext,%mlir_runner_utils_dir/libmlir_c_runner_utils%shlibext | FileCheck %s
12 // CHECK-SAME: sizes = [10, 3]
13 // CHECK-SAME: strides = [3, 1]
14 // CHECK-COUNT-10: [10, 10, 10]
17 // CHECK-SAME: sizes = [10, 3]
18 // CHECK-SAME: strides = [3, 1]
19 // CHECK-COUNT-10: [5, 5, 5]
22 // CHECK-SAME: sizes = [10, 3]
23 // CHECK-SAME: strides = [3, 1]
24 // CHECK-COUNT-10: [2, 2, 2]
27 // 122 is ASCII for 'z'.
31 // CHECK-SAME: sizes = [4, 3]
32 // CHECK-SAME: strides = [3, 1]
33 // CHECK-COUNT-4: [1, 1, 1]
36 // CHECK-SAME: sizes = [4, 3]
37 // CHECK-SAME: strides = [3, 1]
38 // CHECK-COUNT-4: [1, 1, 1]
41 // CHECK-SAME: sizes = [4, 3]
42 // CHECK-SAME: strides = [3, 1]
43 // CHECK-COUNT-4: [1, 1, 1]
45 %A = memref.alloc() : memref<10x3xf32, 0>
46 %f2 = arith.constant 2.00000e+00 : f32
47 %f5 = arith.constant 5.00000e+00 : f32
48 %f10 = arith.constant 10.00000e+00 : f32
50 %V = memref.cast %A : memref<10x3xf32, 0> to memref<?x?xf32>
51 linalg.fill(%f10, %V) : f32, memref<?x?xf32, 0>
52 %U = memref.cast %A : memref<10x3xf32, 0> to memref<*xf32>
53 call @print_memref_f32(%U) : (memref<*xf32>) -> ()
55 %V2 = memref.cast %U : memref<*xf32> to memref<?x?xf32>
56 linalg.fill(%f5, %V2) : f32, memref<?x?xf32, 0>
57 %U2 = memref.cast %V2 : memref<?x?xf32, 0> to memref<*xf32>
58 call @print_memref_f32(%U2) : (memref<*xf32>) -> ()
60 %V3 = memref.cast %V2 : memref<?x?xf32> to memref<*xf32>
61 %V4 = memref.cast %V3 : memref<*xf32> to memref<?x?xf32>
62 linalg.fill(%f2, %V4) : f32, memref<?x?xf32, 0>
63 %U3 = memref.cast %V2 : memref<?x?xf32> to memref<*xf32>
64 call @print_memref_f32(%U3) : (memref<*xf32>) -> ()
66 // 122 is ASCII for 'z'.
67 %i8_z = arith.constant 122 : i8
68 %I8 = memref.alloc() : memref<i8>
69 memref.store %i8_z, %I8[]: memref<i8>
70 %U4 = memref.cast %I8 : memref<i8> to memref<*xi8>
71 call @print_memref_i8(%U4) : (memref<*xi8>) -> ()
73 memref.dealloc %U4 : memref<*xi8>
74 memref.dealloc %A : memref<10x3xf32, 0>
76 call @return_var_memref_caller() : () -> ()
77 call @return_two_var_memref_caller() : () -> ()
78 call @dim_op_of_unranked() : () -> ()
82 func private @print_memref_i8(memref<*xi8>) attributes { llvm.emit_c_interface }
83 func private @print_memref_f32(memref<*xf32>) attributes { llvm.emit_c_interface }
85 func @return_two_var_memref_caller() {
86 %0 = memref.alloca() : memref<4x3xf32>
87 %c0f32 = arith.constant 1.0 : f32
88 linalg.fill(%c0f32, %0) : f32, memref<4x3xf32>
89 %1:2 = call @return_two_var_memref(%0) : (memref<4x3xf32>) -> (memref<*xf32>, memref<*xf32>)
90 call @print_memref_f32(%1#0) : (memref<*xf32>) -> ()
91 call @print_memref_f32(%1#1) : (memref<*xf32>) -> ()
95 func @return_two_var_memref(%arg0: memref<4x3xf32>) -> (memref<*xf32>, memref<*xf32>) {
96 %0 = memref.cast %arg0 : memref<4x3xf32> to memref<*xf32>
97 return %0, %0 : memref<*xf32>, memref<*xf32>
100 func @return_var_memref_caller() {
101 %0 = memref.alloca() : memref<4x3xf32>
102 %c0f32 = arith.constant 1.0 : f32
103 linalg.fill(%c0f32, %0) : f32, memref<4x3xf32>
104 %1 = call @return_var_memref(%0) : (memref<4x3xf32>) -> memref<*xf32>
105 call @print_memref_f32(%1) : (memref<*xf32>) -> ()
109 func @return_var_memref(%arg0: memref<4x3xf32>) -> memref<*xf32> {
110 %0 = memref.cast %arg0: memref<4x3xf32> to memref<*xf32>
111 return %0 : memref<*xf32>
114 func private @printU64(index) -> ()
115 func private @printNewline() -> ()
117 func @dim_op_of_unranked() {
118 %ranked = memref.alloca() : memref<4x3xf32>
119 %unranked = memref.cast %ranked: memref<4x3xf32> to memref<*xf32>
121 %c0 = arith.constant 0 : index
122 %dim_0 = memref.dim %unranked, %c0 : memref<*xf32>
123 call @printU64(%dim_0) : (index) -> ()
124 call @printNewline() : () -> ()
127 %c1 = arith.constant 1 : index
128 %dim_1 = memref.dim %unranked, %c1 : memref<*xf32>
129 call @printU64(%dim_1) : (index) -> ()
130 call @printNewline() : () -> ()