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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Sep 10 01:50:37 PDT 2024


Author: Sergey Kozub
Date: 2024-09-10T10:50:34+02:00
New Revision: 083e25c1d4d9f1af1c4d62109067aecbb4dd2564

URL: https://github.com/llvm/llvm-project/commit/083e25c1d4d9f1af1c4d62109067aecbb4dd2564
DIFF: https://github.com/llvm/llvm-project/commit/083e25c1d4d9f1af1c4d62109067aecbb4dd2564.diff

LOG: [MLIR] [NFC] Use APFloat semantics to get floating type width (#107372)

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

Added: 
    

Modified: 
    mlir/lib/IR/BuiltinTypes.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/IR/BuiltinTypes.cpp b/mlir/lib/IR/BuiltinTypes.cpp
index 4d91d98a9ba896..e46b6a4a6bb693 100644
--- a/mlir/lib/IR/BuiltinTypes.cpp
+++ b/mlir/lib/IR/BuiltinTypes.cpp
@@ -91,23 +91,12 @@ IntegerType IntegerType::scaleElementBitwidth(unsigned scale) {
 //===----------------------------------------------------------------------===//
 
 unsigned FloatType::getWidth() {
-  if (llvm::isa<Float6E3M2FNType>(*this))
-    return 6;
-  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))
+  // 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<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 APFloat::semanticsSizeInBits(getFloatSemantics());
 }
 
 /// Returns the floating semantics for the given type.


        


More information about the Mlir-commits mailing list