[llvm] Add support for DFP IR type. (PR #69718)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 23 19:32:37 PDT 2023


https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/69718

>From ebb406fcf6c438e04c955cb75ecba392f7abcecd Mon Sep 17 00:00:00 2001
From: Ammarguellat <zahira.ammarguellat at intel.com>
Date: Fri, 20 Oct 2023 05:54:53 -0700
Subject: [PATCH 1/4] Add support for DFP IR type.

---
 llvm/docs/BitCodeFormat.rst               | 24 +++++++++++++++++++++++
 llvm/docs/LangRef.rst                     |  9 +++++++++
 llvm/include/llvm-c/Core.h                | 21 ++++++++++++++++++++
 llvm/include/llvm/Bitcode/LLVMBitCodes.h  |  4 ++++
 llvm/include/llvm/IR/DataLayout.h         |  3 +++
 llvm/include/llvm/IR/IRBuilder.h          | 15 ++++++++++++++
 llvm/include/llvm/IR/Type.h               | 18 +++++++++++++++++
 llvm/lib/AsmParser/LLLexer.cpp            |  6 ++++++
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp |  9 +++++++++
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp |  9 +++++++++
 llvm/lib/IR/AsmWriter.cpp                 |  9 +++++++++
 llvm/lib/IR/Core.cpp                      |  6 ++++++
 llvm/lib/IR/LLVMContextImpl.cpp           |  6 ++++--
 llvm/lib/IR/LLVMContextImpl.h             |  5 +++--
 llvm/lib/IR/Type.cpp                      | 18 +++++++++++++++++
 llvm/test/Assembler/dfp.ll                | 16 +++++++++++++++
 16 files changed, 174 insertions(+), 4 deletions(-)
 create mode 100644 llvm/test/Assembler/dfp.ll

diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst
index 70be73abef19d6d..d83f2927a8fe001 100644
--- a/llvm/docs/BitCodeFormat.rst
+++ b/llvm/docs/BitCodeFormat.rst
@@ -1360,6 +1360,30 @@ The operand fields are
 
 .. _CONSTANTS_BLOCK:
 
+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 Contents
 ------------------------
 
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index f542e70bcfee810..37c2de43ab36de3 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -3660,9 +3660,15 @@ Floating-Point Types
    * - ``float``
      - 32-bit floating-point value
 
+   * - ``decimal32``
+     - 32-bit decimal floating-point value
+
    * - ``double``
      - 64-bit floating-point value
 
+   * - ``decimal64``
+     - 64-bit decimal floating-point value
+
    * - ``fp128``
      - 128-bit floating-point value (113-bit significand)
 
@@ -3672,6 +3678,9 @@ Floating-Point Types
    * - ``ppc_fp128``
      - 128-bit floating-point value (two 64-bits)
 
+   * - ``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 7ee46cac43042a1..101ca5588b4da40 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 52e76356a892e45..d19978a08207bd6 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 b3633b67b9debda..6a95519f18e0297 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 ef86eefdf33b834..5e27acedd0540ef 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -541,11 +541,26 @@ class IRBuilderBase {
     return Type::getFloatTy(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 floating point value.
   Type *getDoubleTy() {
     return Type::getDoubleTy(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 c12e899d58fa834..4341f50799dabc9 100644
--- a/llvm/include/llvm/IR/Type.h
+++ b/llvm/include/llvm/IR/Type.h
@@ -56,10 +56,13 @@ class Type {
     HalfTyID = 0,  ///< 16-bit floating point type
     BFloatTyID,    ///< 16-bit floating point type (7-bit significand)
     FloatTyID,     ///< 32-bit floating point type
+    Decimal32TyID, ///< 32-bit decimal floating point type
     DoubleTyID,    ///< 64-bit floating point type
+    Decimal64TyID, ///< 64-bit decimal floating point type
     X86_FP80TyID,  ///< 80-bit floating point type (X87)
     FP128TyID,     ///< 128-bit floating point type (112-bit significand)
     PPC_FP128TyID, ///< 128-bit floating point type (two 64-bits, PowerPC)
+    Decimal128TyID,///< 128-bit decimal floating point type
     VoidTyID,      ///< type with no size
     LabelTyID,     ///< Labels
     MetadataTyID,  ///< Metadata
@@ -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 466bdebc001f589..6756bdd9b21a8bc 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,6 +987,9 @@ lltok::Kind LLLexer::LexIdentifier() {
 ///    HexPPC128Constant 0xM[0-9A-Fa-f]+
 ///    HexHalfConstant   0xH[0-9A-Fa-f]+
 ///    HexBFloatConstant 0xR[0-9A-Fa-f]+
+///    HexDecimal32Constant 0xR[0-9A-Fa-f]+
+///    HexDecimal64Constant 0xR[0-9A-Fa-f]+
+///    HexDecimal128Constant 0xR[0-9A-Fa-f]+
 lltok::Kind LLLexer::Lex0x() {
   CurPtr = TokStart + 2;
 
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 1d1ec988a93d847..d96e9d2d6aedaa3 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 f53fbd73667762c..97b790b08008aea 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -972,10 +972,19 @@ void ModuleBitcodeWriter::writeTypeTable() {
     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;
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index e190d82127908db..a9a705e8cc8e8e0 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -549,10 +549,19 @@ void TypePrinting::print(Type *Ty, raw_ostream &OS) {
   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;
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 17093fa0ac4ee1e..3108533bafd0fde 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 2076eeed9417691..746f08020fc06cb 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<DiagnosticHandler>()),
       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 4cc3f8da6b75b5d..306b266f4397fb9 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -1520,9 +1520,10 @@ class LLVMContextImpl {
   ConstantInt *TheFalseVal = nullptr;
 
   // Basic type instances.
-  Type VoidTy, LabelTy, HalfTy, BFloatTy, FloatTy, DoubleTy, MetadataTy,
+  Type VoidTy, LabelTy, HalfTy, BFloatTy, FloatTy, Decimal32Ty, DoubleTy,
+      Decimal64Ty, MetadataTy,
       TokenTy;
-  Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy, X86_AMXTy;
+  Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, Decimal128Ty, X86_MMXTy, X86_AMXTy;
   IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
 
   std::unique_ptr<ConstantTokenNone> TheNoneToken;
diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 97febcd99b4114f..0e0e501409817d0 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -39,10 +39,16 @@ 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 +181,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:
@@ -207,9 +216,15 @@ int Type::getFPMantissaWidth() const {
   if (getTypeID() == HalfTyID) return 11;
   if (getTypeID() == BFloatTyID) return 8;
   if (getTypeID() == FloatTyID) return 24;
+  // TODO - Does this depend on the encoding format used (BID or DPD)?
+  if (getTypeID() == Decimal32TyID) return 20;
   if (getTypeID() == DoubleTyID) return 53;
+  // TODO - Does this depend on the encoding format used (BID or DPD)?
+  if (getTypeID() == Decimal64TyID) return 50;
   if (getTypeID() == X86_FP80TyID) return 64;
   if (getTypeID() == FP128TyID) return 113;
+  // TODO - Does this depend on the encoding format used (BID or DPD)?
+  if (getTypeID() == Decimal128TyID) return 110;
   assert(getTypeID() == PPC_FP128TyID && "unknown fp type");
   return -1;
 }
@@ -236,12 +251,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 000000000000000..8f93eef6836cbc2
--- /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
+}

>From f0ef74fca21895733a303a5ac9ea52b5f2a42284 Mon Sep 17 00:00:00 2001
From: Ammarguellat <zahira.ammarguellat at intel.com>
Date: Fri, 20 Oct 2023 06:32:39 -0700
Subject: [PATCH 2/4] Fixed BitCodeFormat.rst format.

---
 llvm/docs/BitCodeFormat.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst
index d83f2927a8fe001..df1a2898201cd26 100644
--- a/llvm/docs/BitCodeFormat.rst
+++ b/llvm/docs/BitCodeFormat.rst
@@ -1361,7 +1361,7 @@ The operand fields are
 .. _CONSTANTS_BLOCK:
 
 TYPE_CODE_DECIMAL32 Record
-^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 ``[DECIMAL32]``
 
@@ -1369,7 +1369,7 @@ The ``DECIMAL32`` record (code 27) adds a ``decimal32`` (32-bit
 decimal floating point) type to the type table.
 
 TYPE_CODE_DECIMAL64 Record
-^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 ``[DECIMAL64]``
 
@@ -1377,7 +1377,7 @@ The ``DECIMAL64`` record (code 28) adds a ``decimal64`` (64-bit
 decimal floating point) type to the type table.
 
 TYPE_CODE_DECIMAL128 Record
-^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 ``[DECIMAL128]``
 

>From 583eea1ec8e74beeceffa75cf3745f56f45b8ee2 Mon Sep 17 00:00:00 2001
From: Ammarguellat <zahira.ammarguellat at intel.com>
Date: Mon, 23 Oct 2023 12:14:16 -0700
Subject: [PATCH 3/4] Addressed review comments.

---
 llvm/docs/BitCodeFormat.rst               |  4 +--
 llvm/docs/LangRef.rst                     | 12 +++----
 llvm/include/llvm/IR/IRBuilder.h          | 10 +++---
 llvm/include/llvm/IR/Type.h               |  2 +-
 llvm/lib/AsmParser/LLLexer.cpp            | 10 ++++--
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 38 ++++++++++-------------
 llvm/lib/IR/AsmWriter.cpp                 | 38 ++++++++++-------------
 llvm/lib/IR/LLVMContextImpl.h             |  5 ++-
 llvm/lib/IR/Type.cpp                      | 19 ++++--------
 9 files changed, 61 insertions(+), 77 deletions(-)

diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst
index df1a2898201cd26..2a91f64e2a6e00b 100644
--- a/llvm/docs/BitCodeFormat.rst
+++ b/llvm/docs/BitCodeFormat.rst
@@ -1358,8 +1358,6 @@ The operand fields are
 
 * *int_params*: Numbers that correspond to the integer parameters.
 
-.. _CONSTANTS_BLOCK:
-
 TYPE_CODE_DECIMAL32 Record
 ^^^^^^^^^^^^^^^^^^^^^^^^^^
 
@@ -1384,6 +1382,8 @@ TYPE_CODE_DECIMAL128 Record
 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 37c2de43ab36de3..e545f575f72b5f5 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -3660,15 +3660,9 @@ Floating-Point Types
    * - ``float``
      - 32-bit floating-point value
 
-   * - ``decimal32``
-     - 32-bit decimal floating-point value
-
    * - ``double``
      - 64-bit floating-point value
 
-   * - ``decimal64``
-     - 64-bit decimal floating-point value
-
    * - ``fp128``
      - 128-bit floating-point value (113-bit significand)
 
@@ -3678,6 +3672,12 @@ 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
 
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 5e27acedd0540ef..ccae847c1cf8caa 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -541,16 +541,16 @@ class IRBuilderBase {
     return Type::getFloatTy(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 floating point value.
   Type *getDoubleTy() {
     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);
diff --git a/llvm/include/llvm/IR/Type.h b/llvm/include/llvm/IR/Type.h
index 4341f50799dabc9..016114a07d83f15 100644
--- a/llvm/include/llvm/IR/Type.h
+++ b/llvm/include/llvm/IR/Type.h
@@ -55,8 +55,8 @@ class Type {
     // PrimitiveTypes
     HalfTyID = 0,  ///< 16-bit floating point type
     BFloatTyID,    ///< 16-bit floating point type (7-bit significand)
-    FloatTyID,     ///< 32-bit floating point type
     Decimal32TyID, ///< 32-bit decimal floating point type
+    FloatTyID,     ///< 32-bit floating point type
     DoubleTyID,    ///< 64-bit floating point type
     Decimal64TyID, ///< 64-bit decimal floating point type
     X86_FP80TyID,  ///< 80-bit floating point type (X87)
diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp
index 6756bdd9b21a8bc..90034e3280cf1cc 100644
--- a/llvm/lib/AsmParser/LLLexer.cpp
+++ b/llvm/lib/AsmParser/LLLexer.cpp
@@ -987,12 +987,16 @@ lltok::Kind LLLexer::LexIdentifier() {
 ///    HexPPC128Constant 0xM[0-9A-Fa-f]+
 ///    HexHalfConstant   0xH[0-9A-Fa-f]+
 ///    HexBFloatConstant 0xR[0-9A-Fa-f]+
-///    HexDecimal32Constant 0xR[0-9A-Fa-f]+
-///    HexDecimal64Constant 0xR[0-9A-Fa-f]+
-///    HexDecimal128Constant 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/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 97b790b08008aea..07894bad94cde88 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -968,28 +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::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::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 a9a705e8cc8e8e0..c6de85a805b4090 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -545,28 +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::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::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<IntegerType>(Ty)->getBitWidth();
     return;
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index 306b266f4397fb9..03cad1480396303 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -1520,9 +1520,8 @@ class LLVMContextImpl {
   ConstantInt *TheFalseVal = nullptr;
 
   // Basic type instances.
-  Type VoidTy, LabelTy, HalfTy, BFloatTy, FloatTy, Decimal32Ty, DoubleTy,
-      Decimal64Ty, MetadataTy,
-      TokenTy;
+  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;
 
diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 0e0e501409817d0..37b469b3253dbfa 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -39,16 +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 Decimal32TyID:  return getDecimal32Ty(C);
   case DoubleTyID    : return getDoubleTy(C);
-  case Decimal64TyID:
-    return getDecimal64Ty(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 Decimal128TyID: return getDecimal128Ty(C);
   case LabelTyID     : return getLabelTy(C);
   case MetadataTyID  : return getMetadataTy(C);
   case X86_MMXTyID   : return getX86_MMXTy(C);
@@ -216,16 +213,12 @@ int Type::getFPMantissaWidth() const {
   if (getTypeID() == HalfTyID) return 11;
   if (getTypeID() == BFloatTyID) return 8;
   if (getTypeID() == FloatTyID) return 24;
-  // TODO - Does this depend on the encoding format used (BID or DPD)?
-  if (getTypeID() == Decimal32TyID) return 20;
   if (getTypeID() == DoubleTyID) return 53;
-  // TODO - Does this depend on the encoding format used (BID or DPD)?
-  if (getTypeID() == Decimal64TyID) return 50;
   if (getTypeID() == X86_FP80TyID) return 64;
   if (getTypeID() == FP128TyID) return 113;
-  // TODO - Does this depend on the encoding format used (BID or DPD)?
-  if (getTypeID() == Decimal128TyID) return 110;
-  assert(getTypeID() == PPC_FP128TyID && "unknown fp type");
+  assert((getTypeID() == PPC_FP128TyID || getTypeID() == Decimal32TyID ||
+          getTypeID() == Decimal64TyID || getTypeID() == FP128TyID) &&
+         "unknown fp type");
   return -1;
 }
 

>From a15d72bda27a4c10fb122e15c94d52b9dda25587 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <agrossman154 at yahoo.com>
Date: Mon, 23 Oct 2023 19:06:49 -0700
Subject: [PATCH 4/4] [Github] Add repository to PR checkout in docs action

This patch makes actions/checkout use the forked repository to prevent
issues where the action is unable to find the merge base.
---
 .github/workflows/docs.yml | 95 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)
 create mode 100644 .github/workflows/docs.yml

diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
new file mode 100644
index 000000000000000..4cd0844bba80eb6
--- /dev/null
+++ b/.github/workflows/docs.yml
@@ -0,0 +1,95 @@
+# LLVM Documentation CI
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+name: "Test documentation build"
+
+permissions:
+  contents: read
+
+on:
+  push:
+    branches:
+      - 'main'
+    paths:
+      - 'llvm/docs/**'
+      - 'clang/docs/**'
+      - 'clang-tools-extra/docs/**'
+      - 'lldb/docs/**'
+  pull_request:
+    paths:
+      - 'llvm/docs/**'
+      - 'clang/docs/**'
+      - 'clang-tools-extra/docs/**'
+      - 'lldb/docs/**'
+
+jobs:
+  check-docs-build:
+    name: "Test documentation build"
+    runs-on: ubuntu-latest
+    steps:
+      # Fetch all the commits in a pull request + 1 so that the
+      # docs-changed-subprojects step won't pull them in itself in an extremely
+      # slow manner.
+      - name: Calculate number of commits to fetch (PR)
+        if: ${{ github.event_name == 'pull_request' }} 
+        run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"
+      - name: Fetch LLVM sources (PR)
+        if: ${{ github.event_name == 'pull_request' }}
+        uses: actions/checkout at v4
+        with:
+          fetch-depth: ${{ env.PR_FETCH_DEPTH }}
+          repository: ${{ github.event.pull_request.head.repo.full_name }}
+      - name: Fetch LLVM sources (push)
+        if: ${{ github.event_name == 'push' }}
+        uses: actions/checkout at v4
+        with:
+          fetch-depth: 1
+      - name: Get subprojects that have doc changes
+        id: docs-changed-subprojects
+        uses: tj-actions/changed-files at v39
+        with:
+          files_yaml: |
+            llvm:
+              - 'llvm/docs/**'
+            clang:
+              - 'clang/docs/**'
+            clang-tools-extra:
+              - 'clang-tools-extra/docs/**'
+            lldb:
+              - 'lldb/docs/**'
+      - name: Setup Python env
+        uses: actions/setup-python at v4
+        with:
+          python-version: '3.11'
+          cache: 'pip'
+          cache-dependency-path: 'llvm/docs/requirements.txt'
+      - name: Install python dependencies
+        run: pip install -r llvm/docs/requirements.txt
+      - name: Install system dependencies
+        run: |
+          sudo apt-get update
+          # swig and graphviz are lldb specific dependencies
+          sudo apt-get install -y cmake ninja-build swig graphviz
+      - name: Build LLVM docs
+        if: steps.docs-changed-subprojects.outputs.llvm_any_changed == 'true'
+        run: |
+          cmake -B llvm-build -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_SPHINX=ON ./llvm
+          TZ=UTC ninja -C llvm-build docs-llvm-html docs-llvm-man
+      - name: Build Clang docs
+        if: steps.docs-changed-subprojects.outputs.clang_any_changed == 'true'
+        run: |
+          cmake -B clang-build -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_ENABLE_SPHINX=ON ./llvm
+          TZ=UTC ninja -C clang-build docs-clang-html docs-clang-man
+      - name: Build clang-tools-extra docs
+        if: steps.docs-changed-subprojects.outputs.clang-tools-extra_any_changed == 'true'
+        run: |
+          cmake -B clang-tools-extra-build -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DLLVM_ENABLE_SPHINX=ON ./llvm
+          TZ=UTC ninja -C clang-tools-extra-build docs-clang-tools-html docs-clang-tools-man
+      - name: Build LLDB docs
+        if: steps.docs-changed-subprojects.outputs.lldb_any_changed == 'true'
+        run: |
+          cmake -B lldb-build -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;lldb" -DLLVM_ENABLE_SPHINX=ON ./llvm
+          TZ=UTC ninja -C lldb-build docs-lldb-html docs-lldb-man
+



More information about the llvm-commits mailing list