[Mlir-commits] [mlir] 18fc42f - [mlir][LLVMIR] Add a support for boolean type arguments conversion
Ahmed Taei
llvmlistbot at llvm.org
Fri Mar 13 14:44:17 PDT 2020
Author: Ahmed Taei
Date: 2020-03-13T14:40:26-07:00
New Revision: 18fc42fa3370447f25d877c3100ca4f4194937df
URL: https://github.com/llvm/llvm-project/commit/18fc42fa3370447f25d877c3100ca4f4194937df
DIFF: https://github.com/llvm/llvm-project/commit/18fc42fa3370447f25d877c3100ca4f4194937df.diff
LOG: [mlir][LLVMIR] Add a support for boolean type arguments conversion
Summary:
Otherwise this will fail translating ops with boolean arguments and
added test will fail.
Reviewers: nicolasvasilache, rriddle
Subscribers: mehdi_amini, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D76159
Added:
Modified:
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
mlir/test/Target/llvmir.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 11078e7fa52a..2c3a68fa1081 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -94,6 +94,8 @@ llvm::Constant *ModuleTranslation::getLLVMConstant(llvm::Type *llvmType,
}
if (auto intAttr = attr.dyn_cast<IntegerAttr>())
return llvm::ConstantInt::get(llvmType, intAttr.getValue());
+ if (auto boolAttr = attr.dyn_cast<BoolAttr>())
+ return llvm::ConstantInt::get(llvmType, boolAttr.getValue());
if (auto floatAttr = attr.dyn_cast<FloatAttr>())
return llvm::ConstantFP::get(llvmType, floatAttr.getValue());
if (auto funcAttr = attr.dyn_cast<FlatSymbolRefAttr>())
diff --git a/mlir/test/Target/llvmir.mlir b/mlir/test/Target/llvmir.mlir
index 9e0e8c247e20..7f202b39a471 100644
--- a/mlir/test/Target/llvmir.mlir
+++ b/mlir/test/Target/llvmir.mlir
@@ -1177,7 +1177,16 @@ llvm.func @callFreezeOp(%x : !llvm.i32) {
// CHECK: freeze i32 %{{[0-9]+}}
%0 = llvm.freeze %x : !llvm.i32
%1 = llvm.mlir.undef : !llvm.i32
- // CHECK: freeze i32 undef
+ // CHECK: freeze i32 undef
%2 = llvm.freeze %1 : !llvm.i32
llvm.return
-}
\ No newline at end of file
+}
+
+// CHECK-LABEL: @boolConstArg
+llvm.func @boolConstArg() -> !llvm.i1 {
+ // CHECK: ret i1 false
+ %0 = llvm.mlir.constant(true) : !llvm.i1
+ %1 = llvm.mlir.constant(false) : !llvm.i1
+ %2 = llvm.and %0, %1 : !llvm.i1
+ llvm.return %2 : !llvm.i1
+}
More information about the Mlir-commits
mailing list