[Mlir-commits] [mlir] [mlir][IR] Turn `FloatType` into a type interface (PR #118891)

Matthias Springer llvmlistbot at llvm.org
Mon Dec 16 01:51:04 PST 2024


================
@@ -16,6 +16,65 @@
 
 include "mlir/IR/OpBase.td"
 
+def FloatTypeInterface : TypeInterface<"FloatType"> {
+  let cppNamespace = "::mlir";
+  let description = [{
+    This type interface should be implemented by all floating-point types. It
+    defines the LLVM APFloat semantics and provides a few helper functions.
+  }];
+
+  let methods = [
+    InterfaceMethod<
+      /*desc=*/[{
+        Returns the APFloat semantics for this floating-point type.
+      }],
+      /*retTy=*/"const ::llvm::fltSemantics &",
+      /*methodName=*/"getFloatSemantics",
+      /*args=*/(ins)
+    >,
+    InterfaceMethod<
+      /*desc=*/[{
+        Returns a float type with bitwidth scaled by `scale`. Returns a "null"
+        float type if the scaled element type cannot be represented.
+      }],
+      /*retTy=*/"::mlir::FloatType",
+      /*methodName=*/"scaleElementBitwidth",
+      /*args=*/(ins "unsigned":$scale),
+      /*methodBody=*/"",
+      /*defaultImplementation=*/"return ::mlir::FloatType();"
+    >
+  ];
+
+  let extraClassDeclaration = [{
+    // Convenience factories.
----------------
matthias-springer wrote:

Note: I think these should also be removed, but that's a larger change because existing code uses them a lot. (And it's unclear what to use instead. Maybe `builder.getF32Type()` etc...)

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


More information about the Mlir-commits mailing list