[mlir] Add a function to print C-strings to RunnerUtils.cpp.

Differential Revision: https://reviews.llvm.org/D122066
This commit is contained in:
Alexander Belyaev 2022-03-21 11:01:50 +01:00
parent 76cbfd949d
commit 215b5ce628
2 changed files with 21 additions and 0 deletions

View File

@ -106,6 +106,8 @@ extern "C" void print_memref_f64(int64_t rank, void *ptr) {
_mlir_ciface_print_memref_f64(&descriptor);
}
extern "C" void print_c_string(char *str) { printf("%s", str); }
extern "C" void
_mlir_ciface_print_memref_0d_f32(StridedMemRefType<float, 0> *M) {
impl::printMemRef(*M);

View File

@ -0,0 +1,19 @@
// RUN: mlir-opt %s -pass-pipeline="convert-func-to-llvm,reconcile-unrealized-casts" \
// RUN: | mlir-cpu-runner -e main -entry-point-result=void \
// RUN: -shared-libs=%mlir_runner_utils_dir/libmlir_runner_utils%shlibext,%mlir_runner_utils_dir/libmlir_c_runner_utils%shlibext \
// RUN: | FileCheck %s
llvm.mlir.global internal constant @str_global("String to print\0A")
llvm.func @print_c_string(!llvm.ptr<i8>)
func @main() {
%0 = llvm.mlir.addressof @str_global : !llvm.ptr<array<16 x i8>>
%1 = llvm.mlir.constant(0 : index) : i64
%2 = llvm.getelementptr %0[%1, %1]
: (!llvm.ptr<array<16 x i8>>, i64, i64) -> !llvm.ptr<i8>
llvm.call @print_c_string(%2) : (!llvm.ptr<i8>) -> ()
return
}
// CHECK: String to print