[Mlir-commits] [mlir] [mlir][IR] Turn `FloatType` into a type interface (PR #118891)
River Riddle
llvmlistbot at llvm.org
Mon Dec 16 00:19:02 PST 2024
================
@@ -19,6 +20,34 @@ using namespace mlir::detail;
#include "mlir/IR/BuiltinTypeInterfaces.cpp.inc"
+//===----------------------------------------------------------------------===//
+// FloatType
+//===----------------------------------------------------------------------===//
+
+unsigned FloatType::getWidth() {
+ return APFloat::semanticsSizeInBits(getFloatSemantics());
+}
+
+FloatType FloatType::scaleElementBitwidth(unsigned scale) {
+ if (!scale)
+ return FloatType();
+ MLIRContext *ctx = getContext();
+ if (isF16() || isBF16()) {
+ if (scale == 2)
+ return FloatType::getF32(ctx);
+ if (scale == 4)
+ return FloatType::getF64(ctx);
+ }
+ if (isF32())
+ if (scale == 2)
+ return FloatType::getF64(ctx);
+ return FloatType();
+}
----------------
River707 wrote:
I'd expect this to be an interface method that is implemented by the F16/BF16/F32 types, not something on the interface itself (those methods should be general.,
https://github.com/llvm/llvm-project/pull/118891
More information about the Mlir-commits
mailing list