[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / mlir / test / mlir-cpu-runner / bare-ptr-call-conv.mlir
blobb934480c923bfc0e5abf2f491206cf55c4dbba46
1 // RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-scf-to-cf,convert-arith-to-llvm),finalize-memref-to-llvm,convert-func-to-llvm{use-bare-ptr-memref-call-conv=1},reconcile-unrealized-casts)" | mlir-cpu-runner -shared-libs=%mlir_c_runner_utils -entry-point-result=void | FileCheck %s
3 // Verify bare pointer memref calling convention. `simple_add1_add2_test`
4 // gets two 2xf32 memrefs, adds 1.0f to the first one and 2.0f to the second
5 // one. 'main' calls 'simple_add1_add2_test' with {1, 1} and {2, 2} so {2, 2}
6 // and {4, 4} are the expected outputs.
8 func.func @simple_add1_add2_test(%arg0: memref<2xf32>, %arg1: memref<2xf32>) {
9   %c2 = arith.constant 2 : index
10   %c0 = arith.constant 0 : index
11   %c1 = arith.constant 1 : index
12   %cst = arith.constant 1.000000e+00 : f32
13   %cst_0 = arith.constant 2.000000e+00 : f32
14   scf.for %arg2 = %c0 to %c2 step %c1 {
15     %0 = memref.load %arg0[%arg2] : memref<2xf32>
16     %1 = arith.addf %0, %cst : f32
17     memref.store %1, %arg0[%arg2] : memref<2xf32>
18     // CHECK: 2, 2
20     %2 = memref.load %arg1[%arg2] : memref<2xf32>
21     %3 = arith.addf %1, %cst_0 : f32
22     memref.store %3, %arg1[%arg2] : memref<2xf32>
23     // CHECK-NEXT: 4, 4
24   }
25   return
28 // External declarations.
29 llvm.func @malloc(i64) -> !llvm.ptr<i8>
30 llvm.func @free(!llvm.ptr<i8>)
31 func.func private @printF32(%arg0: f32)
32 func.func private @printComma()
33 func.func private @printNewline()
35 func.func @main()
37   %c2 = arith.constant 2 : index
38   %c0 = arith.constant 0 : index
39   %c1 = arith.constant 1 : index
40   %cst = arith.constant 1.000000e+00 : f32
41   %cst_0 = arith.constant 2.000000e+00 : f32
42   %a = memref.alloc() : memref<2xf32>
43   %b = memref.alloc() : memref<2xf32>
44   scf.for %i = %c0 to %c2 step %c1 {
45     memref.store %cst, %a[%i] : memref<2xf32>
46     memref.store %cst, %b[%i] : memref<2xf32>
47   }
49   call @simple_add1_add2_test(%a, %b) : (memref<2xf32>, memref<2xf32>) -> ()
51   %l0 = memref.load %a[%c0] : memref<2xf32>
52   call @printF32(%l0) : (f32) -> ()
53   call @printComma() : () -> ()
54   %l1 = memref.load %a[%c1] : memref<2xf32>
55   call @printF32(%l1) : (f32) -> ()
56   call @printNewline() : () -> ()
58   %l2 = memref.load %b[%c0] : memref<2xf32>
59   call @printF32(%l2) : (f32) -> ()
60   call @printComma() : () -> ()
61   %l3 = memref.load %b[%c1] : memref<2xf32>
62   call @printF32(%l3) : (f32) -> ()
63   call @printNewline() : () -> ()
65   memref.dealloc %a : memref<2xf32>
66   memref.dealloc %b : memref<2xf32>
67   return