From bb4556d6874426e8dd73576cae8676e58deb492a Mon Sep 17 00:00:00 2001 From: Sergey Kozub Date: Thu, 5 Sep 2024 11:25:57 +0200 Subject: [PATCH] [MLIR] Use APFloat semantics to get floating type width --- mlir/lib/IR/BuiltinTypes.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/mlir/lib/IR/BuiltinTypes.cpp b/mlir/lib/IR/BuiltinTypes.cpp index 16b53efa55fb80..dfe3658eddfcec 100644 --- a/mlir/lib/IR/BuiltinTypes.cpp +++ b/mlir/lib/IR/BuiltinTypes.cpp @@ -91,21 +91,12 @@ IntegerType IntegerType::scaleElementBitwidth(unsigned scale) { //===----------------------------------------------------------------------===// unsigned FloatType::getWidth() { - if (llvm::isa(*this)) - return 8; - if (llvm::isa(*this)) - return 16; - if (llvm::isa(*this)) + // The actual width of TF32 is 19 bits. However, since it is a truncated + // version of Float32, we treat it as 32 bits in MLIR FloatType::getWidth + // for compatibility. + if (llvm::isa(*this)) return 32; - if (llvm::isa(*this)) - return 64; - if (llvm::isa(*this)) - return 80; - if (llvm::isa(*this)) - return 128; - llvm_unreachable("unexpected float type"); + return APFloat::semanticsSizeInBits(getFloatSemantics()); } /// Returns the floating semantics for the given type.