diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst index 70be73abef19d..2a91f64e2a6e0 100644 --- a/llvm/docs/BitCodeFormat.rst +++ b/llvm/docs/BitCodeFormat.rst @@ -1358,6 +1358,30 @@ The operand fields are * *int_params*: Numbers that correspond to the integer parameters. +TYPE_CODE_DECIMAL32 Record +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +``[DECIMAL32]`` + +The ``DECIMAL32`` record (code 27) adds a ``decimal32`` (32-bit +decimal floating point) type to the type table. + +TYPE_CODE_DECIMAL64 Record +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +``[DECIMAL64]`` + +The ``DECIMAL64`` record (code 28) adds a ``decimal64`` (64-bit +decimal floating point) type to the type table. + +TYPE_CODE_DECIMAL128 Record +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +``[DECIMAL128]`` + +The ``DECIMAL128`` record (code 29) adds a ``decimal128`` (128-bit +decimal floating point) type to the type table. + .. _CONSTANTS_BLOCK: CONSTANTS_BLOCK Contents diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index f542e70bcfee8..e545f575f72b5 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -3672,6 +3672,15 @@ Floating-Point Types * - ``ppc_fp128`` - 128-bit floating-point value (two 64-bits) + * - ``decimal32`` + - 32-bit decimal floating-point value + + * - ``decimal64`` + - 64-bit decimal floating-point value + + * - ``decimal128`` + - 128-bit decimal floating-point value + The binary format of half, float, double, and fp128 correspond to the IEEE-754-2008 specifications for binary16, binary32, binary64, and binary128 respectively. diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h index 7ee46cac43042..101ca5588b4da 100644 --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -149,10 +149,13 @@ typedef enum { LLVMVoidTypeKind, /**< type with no size */ LLVMHalfTypeKind, /**< 16 bit floating point type */ LLVMFloatTypeKind, /**< 32 bit floating point type */ + LLVMDecimal32TypeKind, /**< 32 bit decimal floating point type */ LLVMDoubleTypeKind, /**< 64 bit floating point type */ + LLVMDecimal64TypeKind, /**< 64 bit decimal floating point type */ LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */ LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/ LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */ + LLVMDecimal128TypeKind,/**< 128 bit decimal floating point type */ LLVMLabelTypeKind, /**< Labels */ LLVMIntegerTypeKind, /**< Arbitrary bit width integers */ LLVMFunctionTypeKind, /**< Functions */ @@ -1269,11 +1272,21 @@ LLVMTypeRef LLVMBFloatTypeInContext(LLVMContextRef C); */ LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C); +/** + * Obtain a 32-bit decimal floating point type from a context. + */ +LLVMTypeRef LLVMDecimal32TypeInContext(LLVMContextRef C); + /** * Obtain a 64-bit floating point type from a context. */ LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C); +/** + * Obtain a 64-bit decimal floating point type from a context. + */ +LLVMTypeRef LLVMDecimal64TypeInContext(LLVMContextRef C); + /** * Obtain a 80-bit floating point type (X87) from a context. */ @@ -1290,6 +1303,11 @@ LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C); */ LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C); +/** + * Obtain a 128-bit decimal floating point type from a context. + */ +LLVMTypeRef LLVMDecimal128TypeInContext(LLVMContextRef C); + /** * Obtain a floating point type from the global context. * @@ -1298,10 +1316,13 @@ LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C); LLVMTypeRef LLVMHalfType(void); LLVMTypeRef LLVMBFloatType(void); LLVMTypeRef LLVMFloatType(void); +LLVMTypeRef LLVMDecimal32Type(void); LLVMTypeRef LLVMDoubleType(void); +LLVMTypeRef LLVMDecimal64Type(void); LLVMTypeRef LLVMX86FP80Type(void); LLVMTypeRef LLVMFP128Type(void); LLVMTypeRef LLVMPPCFP128Type(void); +LLVMTypeRef LLVMDecimal128Type(void); /** * @} diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index 52e76356a892e..d19978a08207b 100644 --- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h +++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h @@ -177,6 +177,10 @@ enum TypeCodes { TYPE_CODE_OPAQUE_POINTER = 25, // OPAQUE_POINTER: [addrspace] TYPE_CODE_TARGET_TYPE = 26, // TARGET_TYPE + + TYPE_CODE_DECIMAL32 = 27, // 32-bit decimal floating point + TYPE_CODE_DECIMAL64 = 28, // 64-bit decimal floating point + TYPE_CODE_DECIMAL128 = 29 // 128-bit decimal floating point }; enum OperandBundleTagCode { diff --git a/llvm/include/llvm/IR/DataLayout.h b/llvm/include/llvm/IR/DataLayout.h index b3633b67b9deb..6a95519f18e02 100644 --- a/llvm/include/llvm/IR/DataLayout.h +++ b/llvm/include/llvm/IR/DataLayout.h @@ -690,12 +690,15 @@ inline TypeSize DataLayout::getTypeSizeInBits(Type *Ty) const { case Type::BFloatTyID: return TypeSize::Fixed(16); case Type::FloatTyID: + case Type::Decimal32TyID: return TypeSize::Fixed(32); case Type::DoubleTyID: case Type::X86_MMXTyID: + case Type::Decimal64TyID: return TypeSize::Fixed(64); case Type::PPC_FP128TyID: case Type::FP128TyID: + case Type::Decimal128TyID: return TypeSize::Fixed(128); case Type::X86_AMXTyID: return TypeSize::Fixed(8192); diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h index ef86eefdf33b8..ccae847c1cf8c 100644 --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -546,6 +546,21 @@ class IRBuilderBase { return Type::getDoubleTy(Context); } + /// Fetch the type representing a 32-bit decimal floating point value. + Type *getDecimal32Ty() { + return Type::getDecimal32Ty(Context); + } + + /// Fetch the type representing a 64-bit decimal floating point value. + Type *getDecimal64Ty() { + return Type::getDecimal64Ty(Context); + } + + /// Fetch the type representing a 128-bit decimal floating point value. + Type *getDecimal128Ty() { + return Type::getDecimal128Ty(Context); + } + /// Fetch the type representing void. Type *getVoidTy() { return Type::getVoidTy(Context); diff --git a/llvm/include/llvm/IR/Type.h b/llvm/include/llvm/IR/Type.h index c12e899d58fa8..02cea61d3182f 100644 --- a/llvm/include/llvm/IR/Type.h +++ b/llvm/include/llvm/IR/Type.h @@ -55,9 +55,12 @@ class Type { // PrimitiveTypes HalfTyID = 0, ///< 16-bit floating point type BFloatTyID, ///< 16-bit floating point type (7-bit significand) + Decimal32TyID, ///< 32-bit decimal floating point type FloatTyID, ///< 32-bit floating point type + Decimal64TyID, ///< 64-bit decimal floating point type DoubleTyID, ///< 64-bit floating point type X86_FP80TyID, ///< 80-bit floating point type (X87) + Decimal128TyID, ///< 128-bit decimal floating point type FP128TyID, ///< 128-bit floating point type (112-bit significand) PPC_FP128TyID, ///< 128-bit floating point type (two 64-bits, PowerPC) VoidTyID, ///< type with no size @@ -165,6 +168,15 @@ class Type { /// Return true if this is powerpc long double. bool isPPC_FP128Ty() const { return getTypeID() == PPC_FP128TyID; } + /// Return true if this is 'decimal32'. + bool isDecimal32Ty() const { return getTypeID() == Decimal32TyID; } + + /// Return true if this is 'decimal64'. + bool isDecimal64Ty() const { return getTypeID() == Decimal64TyID; } + + /// Return true if this is 'decimal128'. + bool isDecimal128Ty() const { return getTypeID() == Decimal128TyID; } + /// Return true if this is a well-behaved IEEE-like type, which has a IEEE /// compatible layout as defined by isIEEE(), and does not have unnormal /// values @@ -175,6 +187,9 @@ class Type { case HalfTyID: case BFloatTyID: case FP128TyID: + case Decimal32TyID: + case Decimal64TyID: + case Decimal128TyID: return true; default: return false; @@ -448,11 +463,14 @@ class Type { static Type *getHalfTy(LLVMContext &C); static Type *getBFloatTy(LLVMContext &C); static Type *getFloatTy(LLVMContext &C); + static Type *getDecimal32Ty(LLVMContext &C); static Type *getDoubleTy(LLVMContext &C); + static Type *getDecimal64Ty(LLVMContext &C); static Type *getMetadataTy(LLVMContext &C); static Type *getX86_FP80Ty(LLVMContext &C); static Type *getFP128Ty(LLVMContext &C); static Type *getPPC_FP128Ty(LLVMContext &C); + static Type *getDecimal128Ty(LLVMContext &C); static Type *getX86_MMXTy(LLVMContext &C); static Type *getX86_AMXTy(LLVMContext &C); static Type *getTokenTy(LLVMContext &C); diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp index 466bdebc001f5..90034e3280cf1 100644 --- a/llvm/lib/AsmParser/LLLexer.cpp +++ b/llvm/lib/AsmParser/LLLexer.cpp @@ -816,10 +816,13 @@ lltok::Kind LLLexer::LexIdentifier() { TYPEKEYWORD("half", Type::getHalfTy(Context)); TYPEKEYWORD("bfloat", Type::getBFloatTy(Context)); TYPEKEYWORD("float", Type::getFloatTy(Context)); + TYPEKEYWORD("decimal32", Type::getDecimal32Ty(Context)); TYPEKEYWORD("double", Type::getDoubleTy(Context)); + TYPEKEYWORD("decimal64", Type::getDecimal64Ty(Context)); TYPEKEYWORD("x86_fp80", Type::getX86_FP80Ty(Context)); TYPEKEYWORD("fp128", Type::getFP128Ty(Context)); TYPEKEYWORD("ppc_fp128", Type::getPPC_FP128Ty(Context)); + TYPEKEYWORD("decimal128", Type::getDecimal128Ty(Context)); TYPEKEYWORD("label", Type::getLabelTy(Context)); TYPEKEYWORD("metadata", Type::getMetadataTy(Context)); TYPEKEYWORD("x86_mmx", Type::getX86_MMXTy(Context)); @@ -984,9 +987,16 @@ lltok::Kind LLLexer::LexIdentifier() { /// HexPPC128Constant 0xM[0-9A-Fa-f]+ /// HexHalfConstant 0xH[0-9A-Fa-f]+ /// HexBFloatConstant 0xR[0-9A-Fa-f]+ +/// FIXME: I have temporarily added these prefixes temporarly to mimic +/// the DFP attributes in C++. But this is just a placeholder for +/// the real prefix. +/// HexDecimal32Constant 0xSD[0-9A-Fa-f]+ +/// HexDecimal64Constant 0xDD[0-9A-Fa-f]+ +/// HexDecimal128Constant 0xTD[0-9A-Fa-f]+ lltok::Kind LLLexer::Lex0x() { CurPtr = TokStart + 2; + // TODO: Handle the DFP type here. char Kind; if ((CurPtr[0] >= 'K' && CurPtr[0] <= 'M') || CurPtr[0] == 'H' || CurPtr[0] == 'R') { diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 1d1ec988a93d8..d96e9d2d6aeda 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2306,9 +2306,15 @@ Error BitcodeReader::parseTypeTableBody() { case bitc::TYPE_CODE_FLOAT: // FLOAT ResultTy = Type::getFloatTy(Context); break; + case bitc::TYPE_CODE_DECIMAL32: // 32-bit DFP + ResultTy = Type::getDecimal32Ty(Context); + break; case bitc::TYPE_CODE_DOUBLE: // DOUBLE ResultTy = Type::getDoubleTy(Context); break; + case bitc::TYPE_CODE_DECIMAL64: // 64-bit DFP + ResultTy = Type::getDecimal64Ty(Context); + break; case bitc::TYPE_CODE_X86_FP80: // X86_FP80 ResultTy = Type::getX86_FP80Ty(Context); break; @@ -2318,6 +2324,9 @@ Error BitcodeReader::parseTypeTableBody() { case bitc::TYPE_CODE_PPC_FP128: // PPC_FP128 ResultTy = Type::getPPC_FP128Ty(Context); break; + case bitc::TYPE_CODE_DECIMAL128: // 128-bit DFP + ResultTy = Type::getDecimal128Ty(Context); + break; case bitc::TYPE_CODE_LABEL: // LABEL ResultTy = Type::getLabelTy(Context); break; diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index f53fbd7366776..07894bad94cde 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -968,19 +968,22 @@ void ModuleBitcodeWriter::writeTypeTable() { unsigned Code = 0; switch (T->getTypeID()) { - case Type::VoidTyID: Code = bitc::TYPE_CODE_VOID; break; - case Type::HalfTyID: Code = bitc::TYPE_CODE_HALF; break; - case Type::BFloatTyID: Code = bitc::TYPE_CODE_BFLOAT; break; - case Type::FloatTyID: Code = bitc::TYPE_CODE_FLOAT; break; - case Type::DoubleTyID: Code = bitc::TYPE_CODE_DOUBLE; break; - case Type::X86_FP80TyID: Code = bitc::TYPE_CODE_X86_FP80; break; - case Type::FP128TyID: Code = bitc::TYPE_CODE_FP128; break; - case Type::PPC_FP128TyID: Code = bitc::TYPE_CODE_PPC_FP128; break; - case Type::LabelTyID: Code = bitc::TYPE_CODE_LABEL; break; - case Type::MetadataTyID: Code = bitc::TYPE_CODE_METADATA; break; - case Type::X86_MMXTyID: Code = bitc::TYPE_CODE_X86_MMX; break; - case Type::X86_AMXTyID: Code = bitc::TYPE_CODE_X86_AMX; break; - case Type::TokenTyID: Code = bitc::TYPE_CODE_TOKEN; break; + case Type::VoidTyID: Code = bitc::TYPE_CODE_VOID; break; + case Type::HalfTyID: Code = bitc::TYPE_CODE_HALF; break; + case Type::BFloatTyID: Code = bitc::TYPE_CODE_BFLOAT; break; + case Type::FloatTyID: Code = bitc::TYPE_CODE_FLOAT; break; + case Type::Decimal32TyID: Code = bitc::TYPE_CODE_DECIMAL32; break; + case Type::DoubleTyID: Code = bitc::TYPE_CODE_DOUBLE; break; + case Type::Decimal64TyID: Code = bitc::TYPE_CODE_DECIMAL64; break; + case Type::X86_FP80TyID: Code = bitc::TYPE_CODE_X86_FP80; break; + case Type::FP128TyID: Code = bitc::TYPE_CODE_FP128; break; + case Type::PPC_FP128TyID: Code = bitc::TYPE_CODE_PPC_FP128; break; + case Type::Decimal128TyID: Code = bitc::TYPE_CODE_DECIMAL128; break; + case Type::LabelTyID: Code = bitc::TYPE_CODE_LABEL; break; + case Type::MetadataTyID: Code = bitc::TYPE_CODE_METADATA; break; + case Type::X86_MMXTyID: Code = bitc::TYPE_CODE_X86_MMX; break; + case Type::X86_AMXTyID: Code = bitc::TYPE_CODE_X86_AMX; break; + case Type::TokenTyID: Code = bitc::TYPE_CODE_TOKEN; break; case Type::IntegerTyID: // INTEGER: [width] Code = bitc::TYPE_CODE_INTEGER; diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index e190d82127908..c6de85a805b40 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -545,19 +545,22 @@ void TypePrinting::incorporateTypes() { /// names or up references to shorten the type name where possible. void TypePrinting::print(Type *Ty, raw_ostream &OS) { switch (Ty->getTypeID()) { - case Type::VoidTyID: OS << "void"; return; - case Type::HalfTyID: OS << "half"; return; - case Type::BFloatTyID: OS << "bfloat"; return; - case Type::FloatTyID: OS << "float"; return; - case Type::DoubleTyID: OS << "double"; return; - case Type::X86_FP80TyID: OS << "x86_fp80"; return; - case Type::FP128TyID: OS << "fp128"; return; - case Type::PPC_FP128TyID: OS << "ppc_fp128"; return; - case Type::LabelTyID: OS << "label"; return; - case Type::MetadataTyID: OS << "metadata"; return; - case Type::X86_MMXTyID: OS << "x86_mmx"; return; - case Type::X86_AMXTyID: OS << "x86_amx"; return; - case Type::TokenTyID: OS << "token"; return; + case Type::VoidTyID: OS << "void"; return; + case Type::HalfTyID: OS << "half"; return; + case Type::BFloatTyID: OS << "bfloat"; return; + case Type::FloatTyID: OS << "float"; return; + case Type::Decimal32TyID: OS << "decimal32"; return; + case Type::DoubleTyID: OS << "double"; return; + case Type::Decimal64TyID: OS << "decimal64"; return; + case Type::X86_FP80TyID: OS << "x86_fp80"; return; + case Type::FP128TyID: OS << "fp128"; return; + case Type::PPC_FP128TyID: OS << "ppc_fp128"; return; + case Type::Decimal128TyID: OS << "decimal128"; return; + case Type::LabelTyID: OS << "label"; return; + case Type::MetadataTyID: OS << "metadata"; return; + case Type::X86_MMXTyID: OS << "x86_mmx"; return; + case Type::X86_AMXTyID: OS << "x86_amx"; return; + case Type::TokenTyID: OS << "token"; return; case Type::IntegerTyID: OS << 'i' << cast(Ty)->getBitWidth(); return; diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 17093fa0ac4ee..3108533bafd0f 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -555,14 +555,20 @@ LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) { return LLVMBFloatTypeKind; case Type::FloatTyID: return LLVMFloatTypeKind; + case Type::Decimal32TyID: + return LLVMDecimal32TypeKind; case Type::DoubleTyID: return LLVMDoubleTypeKind; + case Type::Decimal64TyID: + return LLVMDecimal64TypeKind; case Type::X86_FP80TyID: return LLVMX86_FP80TypeKind; case Type::FP128TyID: return LLVMFP128TypeKind; case Type::PPC_FP128TyID: return LLVMPPC_FP128TypeKind; + case Type::Decimal128TyID: + return LLVMDecimal128TypeKind; case Type::LabelTyID: return LLVMLabelTypeKind; case Type::MetadataTyID: diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp index 2076eeed94176..746f08020fc06 100644 --- a/llvm/lib/IR/LLVMContextImpl.cpp +++ b/llvm/lib/IR/LLVMContextImpl.cpp @@ -37,10 +37,12 @@ LLVMContextImpl::LLVMContextImpl(LLVMContext &C) : DiagHandler(std::make_unique()), VoidTy(C, Type::VoidTyID), LabelTy(C, Type::LabelTyID), HalfTy(C, Type::HalfTyID), BFloatTy(C, Type::BFloatTyID), - FloatTy(C, Type::FloatTyID), DoubleTy(C, Type::DoubleTyID), + FloatTy(C, Type::FloatTyID), Decimal32Ty(C, Type::Decimal32TyID), + DoubleTy(C, Type::DoubleTyID), Decimal64Ty(C, Type::Decimal64TyID), MetadataTy(C, Type::MetadataTyID), TokenTy(C, Type::TokenTyID), X86_FP80Ty(C, Type::X86_FP80TyID), FP128Ty(C, Type::FP128TyID), - PPC_FP128Ty(C, Type::PPC_FP128TyID), X86_MMXTy(C, Type::X86_MMXTyID), + PPC_FP128Ty(C, Type::PPC_FP128TyID), + Decimal128Ty(C, Type::Decimal128TyID), X86_MMXTy(C, Type::X86_MMXTyID), X86_AMXTy(C, Type::X86_AMXTyID), Int1Ty(C, 1), Int8Ty(C, 8), Int16Ty(C, 16), Int32Ty(C, 32), Int64Ty(C, 64), Int128Ty(C, 128) {} diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h index 4cc3f8da6b75b..03cad14803963 100644 --- a/llvm/lib/IR/LLVMContextImpl.h +++ b/llvm/lib/IR/LLVMContextImpl.h @@ -1520,9 +1520,9 @@ class LLVMContextImpl { ConstantInt *TheFalseVal = nullptr; // Basic type instances. - Type VoidTy, LabelTy, HalfTy, BFloatTy, FloatTy, DoubleTy, MetadataTy, - TokenTy; - Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy, X86_AMXTy; + Type VoidTy, LabelTy, HalfTy, BFloatTy, FloatTy, Decimal32Ty, DoubleTy; + Type Decimal64Ty, MetadataTy, TokenTy; + Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, Decimal128Ty, X86_MMXTy, X86_AMXTy; IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty; std::unique_ptr TheNoneToken; diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp index 97febcd99b411..e7991cc8809ce 100644 --- a/llvm/lib/IR/Type.cpp +++ b/llvm/lib/IR/Type.cpp @@ -39,10 +39,13 @@ Type *Type::getPrimitiveType(LLVMContext &C, TypeID IDNumber) { case HalfTyID : return getHalfTy(C); case BFloatTyID : return getBFloatTy(C); case FloatTyID : return getFloatTy(C); + case Decimal32TyID: return getDecimal32Ty(C); case DoubleTyID : return getDoubleTy(C); + case Decimal64TyID: return getDecimal64Ty(C); case X86_FP80TyID : return getX86_FP80Ty(C); case FP128TyID : return getFP128Ty(C); case PPC_FP128TyID : return getPPC_FP128Ty(C); + case Decimal128TyID: return getDecimal128Ty(C); case LabelTyID : return getLabelTy(C); case MetadataTyID : return getMetadataTy(C); case X86_MMXTyID : return getX86_MMXTy(C); @@ -175,10 +178,13 @@ TypeSize Type::getPrimitiveSizeInBits() const { case Type::HalfTyID: return TypeSize::Fixed(16); case Type::BFloatTyID: return TypeSize::Fixed(16); case Type::FloatTyID: return TypeSize::Fixed(32); + case Decimal32TyID: return TypeSize::Fixed(32); case Type::DoubleTyID: return TypeSize::Fixed(64); + case Decimal64TyID: return TypeSize::Fixed(64); case Type::X86_FP80TyID: return TypeSize::Fixed(80); case Type::FP128TyID: return TypeSize::Fixed(128); case Type::PPC_FP128TyID: return TypeSize::Fixed(128); + case Decimal128TyID: return TypeSize::Fixed(128); case Type::X86_MMXTyID: return TypeSize::Fixed(64); case Type::X86_AMXTyID: return TypeSize::Fixed(8192); case Type::IntegerTyID: @@ -210,8 +216,13 @@ int Type::getFPMantissaWidth() const { if (getTypeID() == DoubleTyID) return 53; if (getTypeID() == X86_FP80TyID) return 64; if (getTypeID() == FP128TyID) return 113; - assert(getTypeID() == PPC_FP128TyID && "unknown fp type"); - return -1; + // See comment in the declaration of Type::getFPMantissaWidth(); + // it returns -1 if the FP type does not have a stable mantissa. + if (getTypeID() == Decimal32TyID) return -1; + if (getTypeID() == Decimal64TyID) return -1; + if (getTypeID() == FP128TyID) return -1; + if (getTypeID() == PPC_FP128TyID) return -1; + assert("unknown fp type"); } bool Type::isSizedDerivedType(SmallPtrSetImpl *Visited) const { @@ -236,12 +247,15 @@ Type *Type::getLabelTy(LLVMContext &C) { return &C.pImpl->LabelTy; } Type *Type::getHalfTy(LLVMContext &C) { return &C.pImpl->HalfTy; } Type *Type::getBFloatTy(LLVMContext &C) { return &C.pImpl->BFloatTy; } Type *Type::getFloatTy(LLVMContext &C) { return &C.pImpl->FloatTy; } +Type *Type::getDecimal32Ty(LLVMContext &C) { return &C.pImpl->Decimal32Ty; } Type *Type::getDoubleTy(LLVMContext &C) { return &C.pImpl->DoubleTy; } +Type *Type::getDecimal64Ty(LLVMContext &C) { return &C.pImpl->Decimal64Ty; } Type *Type::getMetadataTy(LLVMContext &C) { return &C.pImpl->MetadataTy; } Type *Type::getTokenTy(LLVMContext &C) { return &C.pImpl->TokenTy; } Type *Type::getX86_FP80Ty(LLVMContext &C) { return &C.pImpl->X86_FP80Ty; } Type *Type::getFP128Ty(LLVMContext &C) { return &C.pImpl->FP128Ty; } Type *Type::getPPC_FP128Ty(LLVMContext &C) { return &C.pImpl->PPC_FP128Ty; } +Type *Type::getDecimal128Ty(LLVMContext &C) { return &C.pImpl->Decimal128Ty; } Type *Type::getX86_MMXTy(LLVMContext &C) { return &C.pImpl->X86_MMXTy; } Type *Type::getX86_AMXTy(LLVMContext &C) { return &C.pImpl->X86_AMXTy; } diff --git a/llvm/test/Assembler/dfp.ll b/llvm/test/Assembler/dfp.ll new file mode 100644 index 0000000000000..8f93eef6836cb --- /dev/null +++ b/llvm/test/Assembler/dfp.ll @@ -0,0 +1,16 @@ +; RUN: llvm-as < %s | llvm-dis | FileCheck %s --check-prefix=ASSEM-DISASS + +define decimal32 @check_decimal32(decimal32 %A) { +; ASSEM-DISASS: ret decimal32 %A + ret decimal32 %A +} + +define decimal64 @check_decimal64(decimal64 %A) { +; ASSEM-DISASS: ret decimal64 %A + ret decimal64 %A +} + +define decimal128 @check_decimal128(decimal128 %A) { +; ASSEM-DISASS: ret decimal128 %A + ret decimal128 %A +}