[Mlir-commits] [mlir] 215b5ce - [mlir] Add a function to print C-strings to RunnerUtils.cpp.
Alexander Belyaev
llvmlistbot at llvm.org
Mon Mar 21 05:09:32 PDT 2022
Author: Alexander Belyaev
Date: 2022-03-21T13:09:09+01:00
New Revision: 215b5ce628c2abe75c3ff6672e9cf8a9c7bd6092
URL: https://github.com/llvm/llvm-project/commit/215b5ce628c2abe75c3ff6672e9cf8a9c7bd6092
DIFF: https://github.com/llvm/llvm-project/commit/215b5ce628c2abe75c3ff6672e9cf8a9c7bd6092.diff
LOG: [mlir] Add a function to print C-strings to RunnerUtils.cpp.
Differential Revision: https://reviews.llvm.org/D122066
Added:
mlir/test/mlir-cpu-runner/print.mlir
Modified:
mlir/lib/ExecutionEngine/RunnerUtils.cpp
Removed:
################################################################################
diff --git a/mlir/lib/ExecutionEngine/RunnerUtils.cpp b/mlir/lib/ExecutionEngine/RunnerUtils.cpp
index 3abd00d0f06d6..6c96d1fa065b1 100644
--- a/mlir/lib/ExecutionEngine/RunnerUtils.cpp
+++ b/mlir/lib/ExecutionEngine/RunnerUtils.cpp
@@ -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);
diff --git a/mlir/test/mlir-cpu-runner/print.mlir b/mlir/test/mlir-cpu-runner/print.mlir
new file mode 100644
index 0000000000000..7b25015f228a4
--- /dev/null
+++ b/mlir/test/mlir-cpu-runner/print.mlir
@@ -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
More information about the Mlir-commits
mailing list