[Mlir-commits] [mlir] [MLIR] Use APFloat semantics to get floating type width (PR #107372)

Sergey Kozub llvmlistbot at llvm.org
Thu Sep 5 02:27:24 PDT 2024


https://github.com/sergey-kozub created https://github.com/llvm/llvm-project/pull/107372

As suggested in the comments of https://github.com/llvm/llvm-project/pull/105573

>From 7102cae44901d671be55d102046bc95df7e6ac6c Mon Sep 17 00:00:00 2001
From: Sergey Kozub <skozub at nvidia.com>
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 | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/mlir/lib/IR/BuiltinTypes.cpp b/mlir/lib/IR/BuiltinTypes.cpp
index 16b53efa55fb80..58f83333b00c20 100644
--- a/mlir/lib/IR/BuiltinTypes.cpp
+++ b/mlir/lib/IR/BuiltinTypes.cpp
@@ -91,21 +91,9 @@ IntegerType IntegerType::scaleElementBitwidth(unsigned scale) {
 //===----------------------------------------------------------------------===//
 
 unsigned FloatType::getWidth() {
-  if (llvm::isa<Float8E5M2Type, Float8E4M3Type, Float8E4M3FNType,
-                Float8E5M2FNUZType, Float8E4M3FNUZType, Float8E4M3B11FNUZType,
-                Float8E3M4Type>(*this))
-    return 8;
-  if (llvm::isa<Float16Type, BFloat16Type>(*this))
-    return 16;
-  if (llvm::isa<Float32Type, FloatTF32Type>(*this))
+  if (llvm::isa<FloatTF32Type>(*this))
     return 32;
-  if (llvm::isa<Float64Type>(*this))
-    return 64;
-  if (llvm::isa<Float80Type>(*this))
-    return 80;
-  if (llvm::isa<Float128Type>(*this))
-    return 128;
-  llvm_unreachable("unexpected float type");
+  return getFloatSemantics().sizeInBits;
 }
 
 /// Returns the floating semantics for the given type.



More information about the Mlir-commits mailing list