Skip to content

Commit 083e25c

Browse files
authored
[MLIR] [NFC] Use APFloat semantics to get floating type width (#107372)
As suggested in the comments of #105573
1 parent 918222b commit 083e25c

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

mlir/lib/IR/BuiltinTypes.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,12 @@ IntegerType IntegerType::scaleElementBitwidth(unsigned scale) {
9191
//===----------------------------------------------------------------------===//
9292

9393
unsigned FloatType::getWidth() {
94-
if (llvm::isa<Float6E3M2FNType>(*this))
95-
return 6;
96-
if (llvm::isa<Float8E5M2Type, Float8E4M3Type, Float8E4M3FNType,
97-
Float8E5M2FNUZType, Float8E4M3FNUZType, Float8E4M3B11FNUZType,
98-
Float8E3M4Type>(*this))
99-
return 8;
100-
if (llvm::isa<Float16Type, BFloat16Type>(*this))
101-
return 16;
102-
if (llvm::isa<Float32Type, FloatTF32Type>(*this))
94+
// The actual width of TF32 is 19 bits. However, since it is a truncated
95+
// version of Float32, we treat it as 32 bits in MLIR FloatType::getWidth
96+
// for compatibility.
97+
if (llvm::isa<FloatTF32Type>(*this))
10398
return 32;
104-
if (llvm::isa<Float64Type>(*this))
105-
return 64;
106-
if (llvm::isa<Float80Type>(*this))
107-
return 80;
108-
if (llvm::isa<Float128Type>(*this))
109-
return 128;
110-
llvm_unreachable("unexpected float type");
99+
return APFloat::semanticsSizeInBits(getFloatSemantics());
111100
}
112101

113102
/// Returns the floating semantics for the given type.

0 commit comments

Comments
 (0)