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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Sep 5 02:27:55 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core

@llvm/pr-subscribers-mlir

Author: Sergey Kozub (sergey-kozub)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/107372.diff


1 Files Affected:

- (modified) mlir/lib/IR/BuiltinTypes.cpp (+2-14) 


``````````diff
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.

``````````

</details>


https://github.com/llvm/llvm-project/pull/107372


More information about the Mlir-commits mailing list