1// RUN: mlir-runner %s %if target={{s390x-.*}} %{ -argext-abi-check=false %} \ 2// RUN: | FileCheck %s 3// RUN: mlir-runner %s -e foo %if target={{s390x-.*}} %{ -argext-abi-check=false %} \ 4// RUN: | FileCheck -check-prefix=NOMAIN %s 5// RUN: mlir-runner %s --entry-point-result=i32 -e int32_main %if target={{s390x-.*}} \ 6// RUN: %{ -argext-abi-check=false %} | FileCheck -check-prefix=INT32MAIN %s 7// RUN: mlir-runner %s --entry-point-result=i64 -e int64_main %if target={{s390x-.*}} \ 8// RUN: %{ -argext-abi-check=false %} | FileCheck -check-prefix=INT64MAIN %s 9// RUN: mlir-runner %s -O3 %if target={{s390x-.*}} %{ -argext-abi-check=false %} \ 10// RUN: | FileCheck %s 11 12// RUN: cp %s %t 13// RUN: mlir-runner %t -dump-object-file %if target={{s390x-.*}} \ 14// RUN: %{ -argext-abi-check=false %} | FileCheck %t 15// RUN: ls %t.o 16// RUN: rm %t.o 17 18// RUN: mlir-runner %s -dump-object-file -object-filename=%T/test.o \ 19// RUN: %if target={{s390x-.*}} %{ -argext-abi-check=false %} | FileCheck %s 20// RUN: ls %T/test.o 21// RUN: rm %T/test.o 22 23// Declarations of C library functions. 24llvm.func @logbf(f32) -> f32 25llvm.func @malloc(i64) -> !llvm.ptr 26llvm.func @free(!llvm.ptr) 27 28// Check that a simple function with a nested call works. 29llvm.func @main() -> f32 { 30 %0 = llvm.mlir.constant(-4.200000e+02 : f32) : f32 31 %1 = llvm.call @logbf(%0) : (f32) -> f32 32 llvm.return %1 : f32 33} 34// CHECK: 8.000000e+00 35 36// Helper typed functions wrapping calls to "malloc" and "free". 37llvm.func @allocation() -> !llvm.ptr { 38 %0 = llvm.mlir.constant(4 : index) : i64 39 %1 = llvm.call @malloc(%0) : (i64) -> !llvm.ptr 40 llvm.return %1 : !llvm.ptr 41} 42llvm.func @deallocation(%arg0: !llvm.ptr) { 43 llvm.call @free(%arg0) : (!llvm.ptr) -> () 44 llvm.return 45} 46 47// Check that allocation and deallocation works, and that a custom entry point 48// works. 49llvm.func @foo() -> f32 { 50 %0 = llvm.call @allocation() : () -> !llvm.ptr 51 %1 = llvm.mlir.constant(0 : index) : i64 52 %2 = llvm.mlir.constant(1.234000e+03 : f32) : f32 53 %3 = llvm.getelementptr %0[%1] : (!llvm.ptr, i64) -> !llvm.ptr, f32 54 llvm.store %2, %3 : f32, !llvm.ptr 55 %4 = llvm.getelementptr %0[%1] : (!llvm.ptr, i64) -> !llvm.ptr, f32 56 %5 = llvm.load %4 : !llvm.ptr -> f32 57 llvm.call @deallocation(%0) : (!llvm.ptr) -> () 58 llvm.return %5 : f32 59} 60// NOMAIN: 1.234000e+03 61 62// Check that i32 return type works 63llvm.func @int32_main() -> i32 { 64 %0 = llvm.mlir.constant(42 : i32) : i32 65 llvm.return %0 : i32 66} 67// INT32MAIN: 42 68 69// Check that i64 return type works 70llvm.func @int64_main() -> i64 { 71 %0 = llvm.mlir.constant(42 : i64) : i64 72 llvm.return %0 : i64 73} 74// INT64MAIN: 42 75