1 // RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-arith-to-llvm),finalize-memref-to-llvm,convert-func-to-llvm,reconcile-unrealized-casts)" | mlir-cpu-runner -e main -entry-point-result=void -shared-libs=%mlir_runner_utils,%mlir_c_runner_utils | FileCheck %s
3 func.func private @printMemrefF32(memref<*xf32>) attributes { llvm.emit_c_interface }
4 func.func private @printMemrefI32(memref<*xi32>) attributes { llvm.emit_c_interface }
5 func.func private @printNewline() -> ()
7 memref.global "private" @gv0 : memref<4xf32> = dense<[0.0, 1.0, 2.0, 3.0]>
8 func.func @test1DMemref() {
9 %0 = memref.get_global @gv0 : memref<4xf32>
10 %U = memref.cast %0 : memref<4xf32> to memref<*xf32>
14 // CHECK: strides = [1]
15 // CHECK: [0, 1, 2, 3]
16 call @printMemrefF32(%U) : (memref<*xf32>) -> ()
17 call @printNewline() : () -> ()
19 // Overwrite some of the elements.
20 %c0 = arith.constant 0 : index
21 %c2 = arith.constant 2 : index
22 %fp0 = arith.constant 4.0 : f32
23 %fp1 = arith.constant 5.0 : f32
24 memref.store %fp0, %0[%c0] : memref<4xf32>
25 memref.store %fp1, %0[%c2] : memref<4xf32>
29 // CHECK: strides = [1]
30 // CHECK: [4, 1, 5, 3]
31 call @printMemrefF32(%U) : (memref<*xf32>) -> ()
32 call @printNewline() : () -> ()
36 memref.global constant @gv1 : memref<3x2xi32> = dense<[[0, 1],[2, 3],[4, 5]]>
37 func.func @testConstantMemref() {
38 %0 = memref.get_global @gv1 : memref<3x2xi32>
39 %U = memref.cast %0 : memref<3x2xi32> to memref<*xi32>
42 // CHECK: sizes = [3, 2]
43 // CHECK: strides = [2, 1]
47 call @printMemrefI32(%U) : (memref<*xi32>) -> ()
48 call @printNewline() : () -> ()
52 memref.global "private" @gv2 : memref<4x2xf32> = dense<[[0.0, 1.0], [2.0, 3.0], [4.0, 5.0], [6.0, 7.0]]>
53 func.func @test2DMemref() {
54 %0 = memref.get_global @gv2 : memref<4x2xf32>
55 %U = memref.cast %0 : memref<4x2xf32> to memref<*xf32>
58 // CHECK: sizes = [4, 2]
59 // CHECK: strides = [2, 1]
64 call @printMemrefF32(%U) : (memref<*xf32>) -> ()
65 call @printNewline() : () -> ()
67 // Overwrite the 1.0 (at index [0, 1]) with 10.0
68 %c0 = arith.constant 0 : index
69 %c1 = arith.constant 1 : index
70 %fp10 = arith.constant 10.0 : f32
71 memref.store %fp10, %0[%c0, %c1] : memref<4x2xf32>
74 // CHECK: sizes = [4, 2]
75 // CHECK: strides = [2, 1]
80 call @printMemrefF32(%U) : (memref<*xf32>) -> ()
81 call @printNewline() : () -> ()
85 memref.global @gv3 : memref<i32> = dense<11>
86 func.func @testScalarMemref() {
87 %0 = memref.get_global @gv3 : memref<i32>
88 %U = memref.cast %0 : memref<i32> to memref<*xi32>
92 // CHECK: strides = []
94 call @printMemrefI32(%U) : (memref<*xi32>) -> ()
95 call @printNewline() : () -> ()
99 func.func @main() -> () {
100 call @test1DMemref() : () -> ()
101 call @testConstantMemref() : () -> ()
102 call @test2DMemref() : () -> ()
103 call @testScalarMemref() : () -> ()