[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / mlir / test / mlir-cpu-runner / simple.mlir
blob2734e499b6cab35c6a47603d5562d155411a7058
1 // RUN: mlir-cpu-runner %s | FileCheck %s
2 // RUN: mlir-cpu-runner %s -e foo | FileCheck -check-prefix=NOMAIN %s
3 // RUN: mlir-cpu-runner %s --entry-point-result=i32 -e int32_main | FileCheck -check-prefix=INT32MAIN %s
4 // RUN: mlir-cpu-runner %s --entry-point-result=i64 -e int64_main | FileCheck -check-prefix=INT64MAIN %s
5 // RUN: mlir-cpu-runner %s -O3 | FileCheck %s
7 // RUN: cp %s %t
8 // RUN: mlir-cpu-runner %t -dump-object-file | FileCheck %t
9 // RUN: ls %t.o
10 // RUN: rm %t.o
12 // RUN: mlir-cpu-runner %s -dump-object-file -object-filename=%T/test.o | FileCheck %s
13 // RUN: ls %T/test.o
14 // RUN: rm %T/test.o
16 // Declarations of C library functions.
17 llvm.func @logbf(f32) -> f32
18 llvm.func @malloc(i64) -> !llvm.ptr<i8>
19 llvm.func @free(!llvm.ptr<i8>)
21 // Check that a simple function with a nested call works.
22 llvm.func @main() -> f32 {
23   %0 = llvm.mlir.constant(-4.200000e+02 : f32) : f32
24   %1 = llvm.call @logbf(%0) : (f32) -> f32
25   llvm.return %1 : f32
27 // CHECK: 8.000000e+00
29 // Helper typed functions wrapping calls to "malloc" and "free".
30 llvm.func @allocation() -> !llvm.ptr<f32> {
31   %0 = llvm.mlir.constant(4 : index) : i64
32   %1 = llvm.call @malloc(%0) : (i64) -> !llvm.ptr<i8>
33   %2 = llvm.bitcast %1 : !llvm.ptr<i8> to !llvm.ptr<f32>
34   llvm.return %2 : !llvm.ptr<f32>
36 llvm.func @deallocation(%arg0: !llvm.ptr<f32>) {
37   %0 = llvm.bitcast %arg0 : !llvm.ptr<f32> to !llvm.ptr<i8>
38   llvm.call @free(%0) : (!llvm.ptr<i8>) -> ()
39   llvm.return
42 // Check that allocation and deallocation works, and that a custom entry point
43 // works.
44 llvm.func @foo() -> f32 {
45   %0 = llvm.call @allocation() : () -> !llvm.ptr<f32>
46   %1 = llvm.mlir.constant(0 : index) : i64
47   %2 = llvm.mlir.constant(1.234000e+03 : f32) : f32
48   %3 = llvm.getelementptr %0[%1] : (!llvm.ptr<f32>, i64) -> !llvm.ptr<f32>
49   llvm.store %2, %3 : !llvm.ptr<f32>
50   %4 = llvm.getelementptr %0[%1] : (!llvm.ptr<f32>, i64) -> !llvm.ptr<f32>
51   %5 = llvm.load %4 : !llvm.ptr<f32>
52   llvm.call @deallocation(%0) : (!llvm.ptr<f32>) -> ()
53   llvm.return %5 : f32
55 // NOMAIN: 1.234000e+03
57 // Check that i32 return type works
58 llvm.func @int32_main() -> i32 {
59   %0 = llvm.mlir.constant(42 : i32) : i32
60   llvm.return %0 : i32
62 // INT32MAIN: 42
64 // Check that i64 return type works
65 llvm.func @int64_main() -> i64 {
66   %0 = llvm.mlir.constant(42 : i64) : i64
67   llvm.return %0 : i64
69 // INT64MAIN: 42