llvm-project
67 строк · 2.1 Кб
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
6
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
11
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
15
16// Declarations of C library functions.
17llvm.func @logbf(f32) -> f32
18llvm.func @malloc(i64) -> !llvm.ptr
19llvm.func @free(!llvm.ptr)
20
21// Check that a simple function with a nested call works.
22llvm.func @main() -> f32 {
23%0 = llvm.mlir.constant(-4.200000e+02 : f32) : f32
24%1 = llvm.call @logbf(%0) : (f32) -> f32
25llvm.return %1 : f32
26}
27// CHECK: 8.000000e+00
28
29// Helper typed functions wrapping calls to "malloc" and "free".
30llvm.func @allocation() -> !llvm.ptr {
31%0 = llvm.mlir.constant(4 : index) : i64
32%1 = llvm.call @malloc(%0) : (i64) -> !llvm.ptr
33llvm.return %1 : !llvm.ptr
34}
35llvm.func @deallocation(%arg0: !llvm.ptr) {
36llvm.call @free(%arg0) : (!llvm.ptr) -> ()
37llvm.return
38}
39
40// Check that allocation and deallocation works, and that a custom entry point
41// works.
42llvm.func @foo() -> f32 {
43%0 = llvm.call @allocation() : () -> !llvm.ptr
44%1 = llvm.mlir.constant(0 : index) : i64
45%2 = llvm.mlir.constant(1.234000e+03 : f32) : f32
46%3 = llvm.getelementptr %0[%1] : (!llvm.ptr, i64) -> !llvm.ptr, f32
47llvm.store %2, %3 : f32, !llvm.ptr
48%4 = llvm.getelementptr %0[%1] : (!llvm.ptr, i64) -> !llvm.ptr, f32
49%5 = llvm.load %4 : !llvm.ptr -> f32
50llvm.call @deallocation(%0) : (!llvm.ptr) -> ()
51llvm.return %5 : f32
52}
53// NOMAIN: 1.234000e+03
54
55// Check that i32 return type works
56llvm.func @int32_main() -> i32 {
57%0 = llvm.mlir.constant(42 : i32) : i32
58llvm.return %0 : i32
59}
60// INT32MAIN: 42
61
62// Check that i64 return type works
63llvm.func @int64_main() -> i64 {
64%0 = llvm.mlir.constant(42 : i64) : i64
65llvm.return %0 : i64
66}
67// INT64MAIN: 42
68