Skip to content

Commit cf0173d

Browse files
committed
[mlir] Add better support for f80 and f128
Add builtin f80 and f128 following @schweitz proposition https://llvm.discourse.group/t/rfc-adding-better-support-for-higher-precision-floating-point/2526/5 Reviewed By: ftynse, rriddle Differential Revision: https://reviews.llvm.org/D94737
1 parent 46aa3c6 commit cf0173d

26 files changed

+110
-55
lines changed

mlir/docs/ConversionToLLVMDialect.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ following conversions are currently implemented:
2929
- `f16` converts to `f16`
3030
- `f32` converts to `f32`
3131
- `f64` converts to `f64`
32+
- `f80` converts to `f80`
33+
- `f128` converts to `f128`
3234

3335
### Index Type
3436

mlir/docs/Dialects/LLVM.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ LLVM dialect accepts a subset of built-in types that are referred to as _LLVM
214214
dialect-compatible types_. The following types are compatible:
215215

216216
- Signless integers - `iN` (`IntegerType`).
217-
- Floating point types - `bfloat`, `half`, `float`, `double` (`FloatType`).
217+
- Floating point types - `bfloat`, `half`, `float`, `double` , `f80`, `f128`
218+
(`FloatType`).
218219
- 1D vectors of signless integers or floating point types - `vector<NxT>`
219220
(`VectorType`).
220221

@@ -228,9 +229,6 @@ compatibility check.
228229
The following non-parametric types derived from the LLVM IR are available in the
229230
LLVM dialect:
230231

231-
- `!llvm.fp128` (`LLVMFP128Type`) - 128-bit floating-point value as per
232-
IEEE-754-2008.
233-
- `!llvm.x86_fp80` (`LLVMX86FP80Type`) - 80-bit floating-point value (x87).
234232
- `!llvm.x86_mmx` (`LLVMX86MMXType`) - value held in an MMX register on x86
235233
machine.
236234
- `!llvm.ppc_fp128` (`LLVMPPCFP128Type`) - 128-bit floating-point value (two

mlir/docs/LangRef.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ Syntax:
850850

851851
```
852852
// Floating point.
853-
float-type ::= `f16` | `bf16` | `f32` | `f64`
853+
float-type ::= `f16` | `bf16` | `f32` | `f64` | `f80` | `f128`
854854
```
855855

856856
MLIR supports float types of certain widths that are widely used as indicated

mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ struct LLVMStructTypeStorage;
3636
struct LLVMTypeAndSizeStorage;
3737
} // namespace detail
3838

39-
class LLVMFP128Type;
40-
class LLVMX86FP80Type;
41-
4239
//===----------------------------------------------------------------------===//
4340
// Trivial types.
4441
//===----------------------------------------------------------------------===//
@@ -51,8 +48,6 @@ class LLVMX86FP80Type;
5148
}
5249

5350
DEFINE_TRIVIAL_LLVM_TYPE(LLVMVoidType);
54-
DEFINE_TRIVIAL_LLVM_TYPE(LLVMFP128Type);
55-
DEFINE_TRIVIAL_LLVM_TYPE(LLVMX86FP80Type);
5651
DEFINE_TRIVIAL_LLVM_TYPE(LLVMPPCFP128Type);
5752
DEFINE_TRIVIAL_LLVM_TYPE(LLVMX86MMXType);
5853
DEFINE_TRIVIAL_LLVM_TYPE(LLVMTokenType);

mlir/include/mlir/IR/Builders.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class Builder {
6666
FloatType getF16Type();
6767
FloatType getF32Type();
6868
FloatType getF64Type();
69+
FloatType getF80Type();
70+
FloatType getF128Type();
6971

7072
IndexType getIndexType();
7173

mlir/include/mlir/IR/BuiltinTypes.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class FloatType : public Type {
5151
static FloatType getF16(MLIRContext *ctx);
5252
static FloatType getF32(MLIRContext *ctx);
5353
static FloatType getF64(MLIRContext *ctx);
54+
static FloatType getF80(MLIRContext *ctx);
55+
static FloatType getF128(MLIRContext *ctx);
5456

5557
/// Methods for support type inquiry through isa, cast, and dyn_cast.
5658
static bool classof(Type type);
@@ -439,7 +441,8 @@ inline bool BaseMemRefType::isValidElementType(Type type) {
439441
}
440442

441443
inline bool FloatType::classof(Type type) {
442-
return type.isa<BFloat16Type, Float16Type, Float32Type, Float64Type>();
444+
return type.isa<BFloat16Type, Float16Type, Float32Type, Float64Type,
445+
Float80Type, Float128Type>();
443446
}
444447

445448
inline FloatType FloatType::getBF16(MLIRContext *ctx) {
@@ -458,6 +461,14 @@ inline FloatType FloatType::getF64(MLIRContext *ctx) {
458461
return Float64Type::get(ctx);
459462
}
460463

464+
inline FloatType FloatType::getF80(MLIRContext *ctx) {
465+
return Float80Type::get(ctx);
466+
}
467+
468+
inline FloatType FloatType::getF128(MLIRContext *ctx) {
469+
return Float128Type::get(ctx);
470+
}
471+
461472
inline bool ShapedType::classof(Type type) {
462473
return type.isa<RankedTensorType, VectorType, UnrankedTensorType,
463474
UnrankedMemRefType, MemRefType>();

mlir/include/mlir/IR/BuiltinTypes.td

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ def Builtin_Float64 : Builtin_FloatType<"Float64"> {
101101
let summary = "64-bit floating-point type";
102102
}
103103

104+
//===----------------------------------------------------------------------===//
105+
// Float80Type
106+
107+
def Builtin_Float80 : Builtin_FloatType<"Float80"> {
108+
let summary = "80-bit floating-point type";
109+
}
110+
111+
//===----------------------------------------------------------------------===//
112+
// Float128Type
113+
114+
def Builtin_Float128 : Builtin_FloatType<"Float128"> {
115+
let summary = "128-bit floating-point type";
116+
}
117+
104118
//===----------------------------------------------------------------------===//
105119
// FunctionType
106120
//===----------------------------------------------------------------------===//

mlir/include/mlir/IR/OpBase.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ class FloatOfWidths<list<int> widths> :
466466
def F16 : F<16>;
467467
def F32 : F<32>;
468468
def F64 : F<64>;
469+
def F80 : F<80>;
470+
def F128 : F<128>;
469471

470472
def BF16 : Type<CPred<"$_self.isBF16()">, "bfloat16 type">,
471473
BuildableType<"$_builder.getBF16Type()">;

mlir/include/mlir/IR/Types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ class Type {
118118
bool isF16() const;
119119
bool isF32() const;
120120
bool isF64() const;
121+
bool isF80() const;
122+
bool isF128() const;
121123

122124
/// Return true if this is an integer type with the specified width.
123125
bool isInteger(unsigned width) const;

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,8 +2042,6 @@ void LLVMDialect::initialize() {
20422042

20432043
// clang-format off
20442044
addTypes<LLVMVoidType,
2045-
LLVMFP128Type,
2046-
LLVMX86FP80Type,
20472045
LLVMPPCFP128Type,
20482046
LLVMX86MMXType,
20492047
LLVMTokenType,

0 commit comments

Comments
 (0)