diff --git a/mlir/docs/ConversionToLLVMDialect.md b/mlir/docs/ConversionToLLVMDialect.md --- a/mlir/docs/ConversionToLLVMDialect.md +++ b/mlir/docs/ConversionToLLVMDialect.md @@ -29,6 +29,8 @@ - `f16` converts to `f16` - `f32` converts to `f32` - `f64` converts to `f64` +- `f80` converts to `f80` +- `f128` converts to `f128` ### Index Type diff --git a/mlir/docs/Dialects/LLVM.md b/mlir/docs/Dialects/LLVM.md --- a/mlir/docs/Dialects/LLVM.md +++ b/mlir/docs/Dialects/LLVM.md @@ -214,7 +214,8 @@ dialect-compatible types_. The following types are compatible: - Signless integers - `iN` (`IntegerType`). -- Floating point types - `bfloat`, `half`, `float`, `double` (`FloatType`). +- Floating point types - `bfloat`, `half`, `float`, `double` , `f80`, `f128` + (`FloatType`). - 1D vectors of signless integers or floating point types - `vector` (`VectorType`). @@ -228,9 +229,6 @@ The following non-parametric types derived from the LLVM IR are available in the LLVM dialect: -- `!llvm.fp128` (`LLVMFP128Type`) - 128-bit floating-point value as per - IEEE-754-2008. -- `!llvm.x86_fp80` (`LLVMX86FP80Type`) - 80-bit floating-point value (x87). - `!llvm.x86_mmx` (`LLVMX86MMXType`) - value held in an MMX register on x86 machine. - `!llvm.ppc_fp128` (`LLVMPPCFP128Type`) - 128-bit floating-point value (two diff --git a/mlir/docs/LangRef.md b/mlir/docs/LangRef.md --- a/mlir/docs/LangRef.md +++ b/mlir/docs/LangRef.md @@ -850,7 +850,7 @@ ``` // Floating point. -float-type ::= `f16` | `bf16` | `f32` | `f64` +float-type ::= `f16` | `bf16` | `f32` | `f64` | `f80` | `f128` ``` MLIR supports float types of certain widths that are widely used as indicated diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h b/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h @@ -36,9 +36,6 @@ struct LLVMTypeAndSizeStorage; } // namespace detail -class LLVMFP128Type; -class LLVMX86FP80Type; - //===----------------------------------------------------------------------===// // Trivial types. //===----------------------------------------------------------------------===// @@ -51,8 +48,6 @@ } DEFINE_TRIVIAL_LLVM_TYPE(LLVMVoidType); -DEFINE_TRIVIAL_LLVM_TYPE(LLVMFP128Type); -DEFINE_TRIVIAL_LLVM_TYPE(LLVMX86FP80Type); DEFINE_TRIVIAL_LLVM_TYPE(LLVMPPCFP128Type); DEFINE_TRIVIAL_LLVM_TYPE(LLVMX86MMXType); DEFINE_TRIVIAL_LLVM_TYPE(LLVMTokenType); diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h --- a/mlir/include/mlir/IR/Builders.h +++ b/mlir/include/mlir/IR/Builders.h @@ -66,6 +66,8 @@ FloatType getF16Type(); FloatType getF32Type(); FloatType getF64Type(); + FloatType getF80Type(); + FloatType getF128Type(); IndexType getIndexType(); diff --git a/mlir/include/mlir/IR/BuiltinTypes.h b/mlir/include/mlir/IR/BuiltinTypes.h --- a/mlir/include/mlir/IR/BuiltinTypes.h +++ b/mlir/include/mlir/IR/BuiltinTypes.h @@ -51,6 +51,8 @@ static FloatType getF16(MLIRContext *ctx); static FloatType getF32(MLIRContext *ctx); static FloatType getF64(MLIRContext *ctx); + static FloatType getF80(MLIRContext *ctx); + static FloatType getF128(MLIRContext *ctx); /// Methods for support type inquiry through isa, cast, and dyn_cast. static bool classof(Type type); @@ -439,7 +441,8 @@ } inline bool FloatType::classof(Type type) { - return type.isa(); + return type.isa(); } inline FloatType FloatType::getBF16(MLIRContext *ctx) { @@ -458,6 +461,14 @@ return Float64Type::get(ctx); } +inline FloatType FloatType::getF80(MLIRContext *ctx) { + return Float80Type::get(ctx); +} + +inline FloatType FloatType::getF128(MLIRContext *ctx) { + return Float128Type::get(ctx); +} + inline bool ShapedType::classof(Type type) { return type.isa(); diff --git a/mlir/include/mlir/IR/BuiltinTypes.td b/mlir/include/mlir/IR/BuiltinTypes.td --- a/mlir/include/mlir/IR/BuiltinTypes.td +++ b/mlir/include/mlir/IR/BuiltinTypes.td @@ -101,6 +101,20 @@ let summary = "64-bit floating-point type"; } +//===----------------------------------------------------------------------===// +// Float80Type + +def Builtin_Float80 : Builtin_FloatType<"Float80"> { + let summary = "80-bit floating-point type"; +} + +//===----------------------------------------------------------------------===// +// Float128Type + +def Builtin_Float128 : Builtin_FloatType<"Float128"> { + let summary = "128-bit floating-point type"; +} + //===----------------------------------------------------------------------===// // FunctionType //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -466,6 +466,8 @@ def F16 : F<16>; def F32 : F<32>; def F64 : F<64>; +def F80 : F<80>; +def F128 : F<128>; def BF16 : Type, "bfloat16 type">, BuildableType<"$_builder.getBF16Type()">; diff --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h --- a/mlir/include/mlir/IR/Types.h +++ b/mlir/include/mlir/IR/Types.h @@ -118,6 +118,8 @@ bool isF16() const; bool isF32() const; bool isF64() const; + bool isF80() const; + bool isF128() const; /// Return true if this is an integer type with the specified width. bool isInteger(unsigned width) const; diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -2042,8 +2042,6 @@ // clang-format off addTypes(type) .Case([&](Type) { return "void"; }) - .Case([&](Type) { return "fp128"; }) - .Case([&](Type) { return "x86_fp80"; }) .Case([&](Type) { return "ppc_fp128"; }) .Case([&](Type) { return "x86_mmx"; }) .Case([&](Type) { return "token"; }) @@ -460,8 +458,16 @@ emitWarning(loc) << "deprecated syntax, use f64 instead"; return Float64Type::get(ctx); }) - .Case("fp128", [&] { return LLVMFP128Type::get(ctx); }) - .Case("x86_fp80", [&] { return LLVMX86FP80Type::get(ctx); }) + .Case("fp128", + [&] { + emitWarning(loc) << "deprecated syntax, use f128 instead"; + return Float128Type::get(ctx); + }) + .Case("x86_fp80", + [&] { + emitWarning(loc) << "deprecated syntax, use f80 instead"; + return Float80Type::get(ctx); + }) .Case("ppc_fp128", [&] { return LLVMPPCFP128Type::get(ctx); }) .Case("x86_mmx", [&] { return LLVMX86MMXType::get(ctx); }) .Case("token", [&] { return LLVMTokenType::get(ctx); }) diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp @@ -272,8 +272,7 @@ } bool LLVMFixedVectorType::isValidElementType(Type type) { - return type - .isa(); + return type.isa(); } LogicalResult LLVMFixedVectorType::verifyConstructionInvariants( @@ -339,8 +338,9 @@ Float16Type, Float32Type, Float64Type, + Float80Type, + Float128Type, LLVMArrayType, - LLVMFP128Type, LLVMFunctionType, LLVMLabelType, LLVMMetadataType, @@ -351,7 +351,6 @@ LLVMFixedVectorType, LLVMScalableVectorType, LLVMVoidType, - LLVMX86FP80Type, LLVMX86MMXType >(); // clang-format on @@ -359,7 +358,7 @@ bool mlir::LLVM::isCompatibleFloatingPointType(Type type) { return type.isa(); + Float80Type, Float128Type, LLVMPPCFP128Type>(); } bool mlir::LLVM::isCompatibleVectorType(Type type) { @@ -372,8 +371,8 @@ Type elementType = vecType.getElementType(); if (auto intType = elementType.dyn_cast()) return intType.isSignless(); - return elementType - .isa(); + return elementType.isa(); } return false; } @@ -421,12 +420,12 @@ .Case([](Type) { return llvm::TypeSize::Fixed(32); }) .Case( [](Type) { return llvm::TypeSize::Fixed(64); }) + .Case([](Type) { return llvm::TypeSize::Fixed(80); }) + .Case([](Type) { return llvm::TypeSize::Fixed(128); }) .Case([](IntegerType intTy) { return llvm::TypeSize::Fixed(intTy.getWidth()); }) - .Case([](Type) { return llvm::TypeSize::Fixed(80); }) - .Case( - [](Type) { return llvm::TypeSize::Fixed(128); }) + .Case([](Type) { return llvm::TypeSize::Fixed(128); }) .Case([](LLVMFixedVectorType t) { llvm::TypeSize elementSize = getPrimitiveTypeSizeInBits(t.getElementType()); diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -1816,6 +1816,8 @@ .Case([&](Type) { os << "f16"; }) .Case([&](Type) { os << "f32"; }) .Case([&](Type) { os << "f64"; }) + .Case([&](Type) { os << "f80"; }) + .Case([&](Type) { os << "f128"; }) .Case([&](IntegerType integerTy) { if (integerTy.isSigned()) os << 's'; diff --git a/mlir/lib/IR/Builders.cpp b/mlir/lib/IR/Builders.cpp --- a/mlir/lib/IR/Builders.cpp +++ b/mlir/lib/IR/Builders.cpp @@ -50,6 +50,10 @@ FloatType Builder::getF64Type() { return FloatType::getF64(context); } +FloatType Builder::getF80Type() { return FloatType::getF80(context); } + +FloatType Builder::getF128Type() { return FloatType::getF128(context); } + IndexType Builder::getIndexType() { return IndexType::get(context); } IntegerType Builder::getI1Type() { return IntegerType::get(context, 1); } diff --git a/mlir/lib/IR/BuiltinDialect.cpp b/mlir/lib/IR/BuiltinDialect.cpp --- a/mlir/lib/IR/BuiltinDialect.cpp +++ b/mlir/lib/IR/BuiltinDialect.cpp @@ -50,9 +50,9 @@ void BuiltinDialect::initialize() { addTypes(); + Float80Type, Float128Type, FunctionType, IndexType, IntegerType, + MemRefType, UnrankedMemRefType, NoneType, OpaqueType, + RankedTensorType, TupleType, UnrankedTensorType, VectorType>(); addAttributes()) return 64; + if (isa()) + return 80; + if (isa()) + return 128; llvm_unreachable("unexpected float type"); } @@ -93,6 +97,10 @@ return APFloat::IEEEsingle(); if (isa()) return APFloat::IEEEdouble(); + if (isa()) + return APFloat::x87DoubleExtended(); + if (isa()) + return APFloat::IEEEquad(); llvm_unreachable("non-floating point type used"); } diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp --- a/mlir/lib/IR/MLIRContext.cpp +++ b/mlir/lib/IR/MLIRContext.cpp @@ -303,6 +303,8 @@ Float16Type f16Ty; Float32Type f32Ty; Float64Type f64Ty; + Float80Type f80Ty; + Float128Type f128Ty; IndexType indexTy; IntegerType int1Ty, int8Ty, int16Ty, int32Ty, int64Ty, int128Ty; NoneType noneType; @@ -351,6 +353,8 @@ impl->f16Ty = TypeUniquer::get(this); impl->f32Ty = TypeUniquer::get(this); impl->f64Ty = TypeUniquer::get(this); + impl->f80Ty = TypeUniquer::get(this); + impl->f128Ty = TypeUniquer::get(this); /// Index Type. impl->indexTy = TypeUniquer::get(this); /// Integer Types. @@ -739,6 +743,12 @@ Float64Type Float64Type::get(MLIRContext *context) { return context->getImpl().f64Ty; } +Float80Type Float80Type::get(MLIRContext *context) { + return context->getImpl().f80Ty; +} +Float128Type Float128Type::get(MLIRContext *context) { + return context->getImpl().f128Ty; +} /// Get an instance of the IndexType. IndexType IndexType::get(MLIRContext *context) { diff --git a/mlir/lib/IR/Types.cpp b/mlir/lib/IR/Types.cpp --- a/mlir/lib/IR/Types.cpp +++ b/mlir/lib/IR/Types.cpp @@ -26,6 +26,8 @@ bool Type::isF16() const { return isa(); } bool Type::isF32() const { return isa(); } bool Type::isF64() const { return isa(); } +bool Type::isF80() const { return isa(); } +bool Type::isF128() const { return isa(); } bool Type::isIndex() const { return isa(); } diff --git a/mlir/lib/Parser/TokenKinds.def b/mlir/lib/Parser/TokenKinds.def --- a/mlir/lib/Parser/TokenKinds.def +++ b/mlir/lib/Parser/TokenKinds.def @@ -85,6 +85,8 @@ TOK_KEYWORD(f16) TOK_KEYWORD(f32) TOK_KEYWORD(f64) +TOK_KEYWORD(f80) +TOK_KEYWORD(f128) TOK_KEYWORD(false) TOK_KEYWORD(floordiv) TOK_KEYWORD(for) diff --git a/mlir/lib/Parser/TypeParser.cpp b/mlir/lib/Parser/TypeParser.cpp --- a/mlir/lib/Parser/TypeParser.cpp +++ b/mlir/lib/Parser/TypeParser.cpp @@ -307,7 +307,7 @@ /// | none-type /// /// index-type ::= `index` -/// float-type ::= `f16` | `bf16` | `f32` | `f64` +/// float-type ::= `f16` | `bf16` | `f32` | `f64` | `f80` | `f128` /// none-type ::= `none` /// Type Parser::parseNonFunctionType() { @@ -356,6 +356,12 @@ case Token::kw_f64: consumeToken(Token::kw_f64); return builder.getF64Type(); + case Token::kw_f80: + consumeToken(Token::kw_f80); + return builder.getF80Type(); + case Token::kw_f128: + consumeToken(Token::kw_f128); + return builder.getF128Type(); // index-type case Token::kw_index: diff --git a/mlir/lib/Target/LLVMIR/TypeTranslation.cpp b/mlir/lib/Target/LLVMIR/TypeTranslation.cpp --- a/mlir/lib/Target/LLVMIR/TypeTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/TypeTranslation.cpp @@ -49,12 +49,12 @@ .Case([this](Float64Type) { return llvm::Type::getDoubleTy(context); }) - .Case([this](LLVM::LLVMFP128Type) { - return llvm::Type::getFP128Ty(context); - }) - .Case([this](LLVM::LLVMX86FP80Type) { + .Case([this](Float80Type) { return llvm::Type::getX86_FP80Ty(context); }) + .Case([this](Float128Type) { + return llvm::Type::getFP128Ty(context); + }) .Case([this](LLVM::LLVMPPCFP128Type) { return llvm::Type::getPPC_FP128Ty(context); }) @@ -230,9 +230,9 @@ if (type->isDoubleTy()) return Float64Type::get(&context); if (type->isFP128Ty()) - return LLVM::LLVMFP128Type::get(&context); + return Float128Type::get(&context); if (type->isX86_FP80Ty()) - return LLVM::LLVMX86FP80Type::get(&context); + return Float80Type::get(&context); if (type->isPPC_FP128Ty()) return LLVM::LLVMPPCFP128Type::get(&context); if (type->isX86_MMXTy()) diff --git a/mlir/test/Dialect/LLVMIR/roundtrip.mlir b/mlir/test/Dialect/LLVMIR/roundtrip.mlir --- a/mlir/test/Dialect/LLVMIR/roundtrip.mlir +++ b/mlir/test/Dialect/LLVMIR/roundtrip.mlir @@ -128,10 +128,10 @@ // Extended and Quad floating point // -// CHECK: %{{.*}} = llvm.fpext %[[FLOAT]] : f32 to !llvm.x86_fp80 -// CHECK: %{{.*}} = llvm.fpext %[[FLOAT]] : f32 to !llvm.fp128 - %27 = llvm.fpext %arg1 : f32 to !llvm.x86_fp80 - %28 = llvm.fpext %arg1 : f32 to !llvm.fp128 +// CHECK: %{{.*}} = llvm.fpext %[[FLOAT]] : f32 to f80 +// CHECK: %{{.*}} = llvm.fpext %[[FLOAT]] : f32 to f128 + %27 = llvm.fpext %arg1 : f32 to f80 + %28 = llvm.fpext %arg1 : f32 to f128 // CHECK: %{{.*}} = llvm.fneg %[[FLOAT]] : f32 %29 = llvm.fneg %arg1 : f32 diff --git a/mlir/test/Dialect/LLVMIR/types.mlir b/mlir/test/Dialect/LLVMIR/types.mlir --- a/mlir/test/Dialect/LLVMIR/types.mlir +++ b/mlir/test/Dialect/LLVMIR/types.mlir @@ -4,18 +4,6 @@ func @primitive() { // CHECK: !llvm.void "some.op"() : () -> !llvm.void - // CHECK: f16 - "some.op"() : () -> f16 - // CHECK: bf16 - "some.op"() : () -> bf16 - // CHECK: f32 - "some.op"() : () -> f32 - // CHECK: f64 - "some.op"() : () -> f64 - // CHECK: !llvm.fp128 - "some.op"() : () -> !llvm.fp128 - // CHECK: !llvm.x86_fp80 - "some.op"() : () -> !llvm.x86_fp80 // CHECK: !llvm.ppc_fp128 "some.op"() : () -> !llvm.ppc_fp128 // CHECK: !llvm.x86_mmx diff --git a/mlir/test/IR/parser.mlir b/mlir/test/IR/parser.mlir --- a/mlir/test/IR/parser.mlir +++ b/mlir/test/IR/parser.mlir @@ -67,6 +67,8 @@ // CHECK: func private @uint_types(ui2, ui4) -> (ui7, ui1023) func private @uint_types(ui2, ui4) -> (ui7, ui1023) +// CHECK: func private @float_types(f80, f128) +func private @float_types(f80, f128) // CHECK: func private @vectors(vector<1xf32>, vector<2x4xf32>) func private @vectors(vector<1 x f32>, vector<2x4xf32>) diff --git a/mlir/test/Target/llvmir-types.mlir b/mlir/test/Target/llvmir-types.mlir --- a/mlir/test/Target/llvmir-types.mlir +++ b/mlir/test/Target/llvmir-types.mlir @@ -15,9 +15,9 @@ // CHECK: declare double @return_double() llvm.func @return_double() -> f64 // CHECK: declare fp128 @return_fp128() -llvm.func @return_fp128() -> !llvm.fp128 +llvm.func @return_fp128() -> f128 // CHECK: declare x86_fp80 @return_x86_fp80() -llvm.func @return_x86_fp80() -> !llvm.x86_fp80 +llvm.func @return_x86_fp80() -> f80 // CHECK: declare ppc_fp128 @return_ppc_fp128() llvm.func @return_ppc_fp128() -> !llvm.ppc_fp128 // CHECK: declare x86_mmx @return_x86_mmx() diff --git a/mlir/utils/gdb-scripts/prettyprinters.py b/mlir/utils/gdb-scripts/prettyprinters.py --- a/mlir/utils/gdb-scripts/prettyprinters.py +++ b/mlir/utils/gdb-scripts/prettyprinters.py @@ -203,6 +203,8 @@ 'Float16Type', 'Float32Type', 'Float64Type', + 'Float80Type', + 'Float128Type', 'NoneType', 'VectorType', 'RankedTensorType',