[mlir] [VectorOps] remove print_i1 from runtime support library

Summary:
The "i1" (viz. bool) type does not have a proper equivalent on the "C"
size. So, to avoid any ABIs issues, we simply use print_i32 on an i32
value of one or zero for true and false. This has the added advantage
that one less function needs to be implemented when porting the runtime
support library.

Reviewers: ftynse, bkramer, nicolasvasilache

Reviewed By: ftynse

Subscribers: mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, stephenneuendorffer, Joonsoo, grosul1, frgossen, Kayjukh, jurahul, msifontes

Tags: #mlir

Differential Revision: https://reviews.llvm.org/D82048
This commit is contained in:
aartbik
2020-06-18 10:48:56 -07:00
parent d96aac4354
commit c9eeeb3871
4 changed files with 17 additions and 12 deletions

View File

@@ -978,9 +978,7 @@ public:
Type eltType = vectorType ? vectorType.getElementType() : printType;
int64_t rank = vectorType ? vectorType.getRank() : 0;
Operation *printer;
if (eltType.isSignlessInteger(1))
printer = getPrintI1(op);
else if (eltType.isSignlessInteger(32))
if (eltType.isSignlessInteger(1) || eltType.isSignlessInteger(32))
printer = getPrintI32(op);
else if (eltType.isSignlessInteger(64))
printer = getPrintI64(op);
@@ -1004,6 +1002,17 @@ private:
int64_t rank) const {
Location loc = op->getLoc();
if (rank == 0) {
if (value.getType() ==
LLVM::LLVMType::getInt1Ty(typeConverter.getDialect())) {
// Convert i1 (bool) to i32 so we can use the print_i32 method.
// This avoids the need for a print_i1 method with an unclear ABI.
auto i32Type = LLVM::LLVMType::getInt32Ty(typeConverter.getDialect());
auto trueVal = rewriter.create<ConstantOp>(
loc, i32Type, rewriter.getI32IntegerAttr(1));
auto falseVal = rewriter.create<ConstantOp>(
loc, i32Type, rewriter.getI32IntegerAttr(0));
value = rewriter.create<SelectOp>(loc, value, trueVal, falseVal);
}
emitCall(rewriter, loc, printer, value);
return;
}
@@ -1047,11 +1056,6 @@ 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",