[mlir] [VectorOps] Included i1 support for vector.print
authoraartbik <ajcbik@google.com>
Thu, 30 Apr 2020 19:47:38 +0000 (12:47 -0700)
committeraartbik <ajcbik@google.com>
Thu, 30 Apr 2020 21:56:26 +0000 (14:56 -0700)
Summary:
Added boolean support to vector.print.
Useful for upcoming "mask" tests.

Reviewers: ftynse, nicolasvasilache, andydavis1

Reviewed By: andydavis1

Subscribers: mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, grosul1, frgossen, Kayjukh, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79198

mlir/include/mlir/ExecutionEngine/CRunnerUtils.h
mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
mlir/lib/ExecutionEngine/CRunnerUtils.cpp
mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir

index 020c66e..8155820 100644 (file)
@@ -167,6 +167,7 @@ struct UnrankedMemRefType {
 //===----------------------------------------------------------------------===//
 // Small runtime support "lib" for vector.print lowering during codegen.
 //===----------------------------------------------------------------------===//
+extern "C" MLIR_CRUNNERUTILS_EXPORT void print_i1(bool b);
 extern "C" MLIR_CRUNNERUTILS_EXPORT void print_i32(int32_t i);
 extern "C" MLIR_CRUNNERUTILS_EXPORT void print_i64(int64_t l);
 extern "C" MLIR_CRUNNERUTILS_EXPORT void print_f32(float f);
index 341ccfa..dec9321 100644 (file)
@@ -925,7 +925,9 @@ public:
     Type eltType = vectorType ? vectorType.getElementType() : printType;
     int64_t rank = vectorType ? vectorType.getRank() : 0;
     Operation *printer;
-    if (eltType.isSignlessInteger(32))
+    if (eltType.isSignlessInteger(1))
+      printer = getPrintI1(op);
+    else if (eltType.isSignlessInteger(32))
       printer = getPrintI32(op);
     else if (eltType.isSignlessInteger(64))
       printer = getPrintI64(op);
@@ -992,6 +994,11 @@ private:
   }
 
   // Helpers for method names.
+  Operation *getPrintI1(Operation *op) const {
+    LLVM::LLVMDialect *dialect = typeConverter.getDialect();
+    return getPrint(op, dialect, "print_i1",
+                    LLVM::LLVMType::getInt1Ty(dialect));
+  }
   Operation *getPrintI32(Operation *op) const {
     LLVM::LLVMDialect *dialect = typeConverter.getDialect();
     return getPrint(op, dialect, "print_i32",
index ad5be24..11d6c6d 100644 (file)
@@ -23,6 +23,7 @@
 // By providing elementary printing methods only, this
 // library can remain fully unaware of low-level implementation
 // details of our vectors. Also useful for direct LLVM IR output.
+extern "C" void print_i1(bool b) { fputc(b ? '1' : '0', stdout); }
 extern "C" void print_i32(int32_t i) { fprintf(stdout, "%" PRId32, i); }
 extern "C" void print_i64(int64_t l) { fprintf(stdout, "%" PRId64, l); }
 extern "C" void print_f32(float f) { fprintf(stdout, "%g", f); }
index ac454bf..8ecd404 100644 (file)
@@ -418,6 +418,15 @@ func @vector_type_cast(%arg0: memref<8x8x8xf32>) -> memref<vector<8x8x8xf32>> {
 //       CHECK:   llvm.mlir.constant(0 : index
 //       CHECK:   llvm.insertvalue {{.*}}[2] : !llvm<"{ [8 x [8 x <8 x float>]]*, [8 x [8 x <8 x float>]]*, i64 }">
 
+func @vector_print_scalar_i1(%arg0: i1) {
+  vector.print %arg0 : i1
+  return
+}
+// CHECK-LABEL: llvm.func @vector_print_scalar_i1(
+// CHECK-SAME: %[[A:.*]]: !llvm.i1)
+//       CHECK:    llvm.call @print_i1(%[[A]]) : (!llvm.i1) -> ()
+//       CHECK:    llvm.call @print_newline() : () -> ()
+
 func @vector_print_scalar_i32(%arg0: i32) {
   vector.print %arg0 : i32
   return