[PATCH 18/79] [Backport to 15] Initial support NonSemantic.Kernel.DebugInfo.100 ...
authorViktoria Maximova <viktoria.maksimova@intel.com>
Mon, 20 Feb 2023 22:22:05 +0000 (14:22 -0800)
committerAndreas Beckmann <anbe@debian.org>
Thu, 8 Feb 2024 21:48:18 +0000 (22:48 +0100)
This patch implements the initial support for the new debug specification NonSemantic.Kernel.DebugInfo.100.
It also introduces support for the new debug instruction DISubrange.

Spec: KhronosGroup/SPIRV-Registry#186

Gbp-Pq: Name 0018-Backport-to-15-Initial-support-NonSemantic.Kernel.De.patch

17 files changed:
include/LLVMSPIRVOpts.h
lib/SPIRV/LLVMToSPIRVDbgTran.cpp
lib/SPIRV/LLVMToSPIRVDbgTran.h
lib/SPIRV/SPIRVReader.cpp
lib/SPIRV/SPIRVToLLVMDbgTran.cpp
lib/SPIRV/SPIRVToLLVMDbgTran.h
lib/SPIRV/libSPIRV/SPIRV.debug.h
lib/SPIRV/libSPIRV/SPIRVEnum.h
lib/SPIRV/libSPIRV/SPIRVExtInst.h
lib/SPIRV/libSPIRV/SPIRVFunction.cpp
lib/SPIRV/libSPIRV/SPIRVInstruction.h
lib/SPIRV/libSPIRV/SPIRVModule.cpp
lib/SPIRV/libSPIRV/SPIRVModule.h
test/DebugInfo/DebugInfoSubrange.ll [deleted file]
test/DebugInfo/NonSemanticKernel100/DebugInfoSubrange.ll [new file with mode: 0644]
test/DebugInfo/OpenCL100/DebugInfoSubrange.ll [new file with mode: 0644]
tools/llvm-spirv/llvm-spirv.cpp

index 8c73b644f0f5c48361f804e0e4d3073ab7fb93f6..8c14037774fcf58ee2a942eebd96b32c747de1f3 100644 (file)
@@ -80,7 +80,11 @@ enum class BIsRepresentation : uint32_t { OpenCL12, OpenCL20, SPIRVFriendlyIR };
 
 enum class FPContractMode : uint32_t { On, Off, Fast };
 
-enum class DebugInfoEIS : uint32_t { SPIRV_Debug, OpenCL_DebugInfo_100 };
+enum class DebugInfoEIS : uint32_t {
+  SPIRV_Debug,
+  OpenCL_DebugInfo_100,
+  NonSemantic_Kernel_DebugInfo_100
+};
 
 /// \brief Helper class to manage SPIR-V translation
 class TranslatorOpts {
index 411bed3b00e4494778fed02dd7df14698f5029f5..d6da1a82bab414b76292c175dbb86394588630e0 100644 (file)
@@ -277,6 +277,12 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgEntryImpl(const MDNode *MDN) {
     case dwarf::DW_TAG_array_type:
       return transDbgArrayType(cast<DICompositeType>(DIEntry));
 
+    case dwarf::DW_TAG_subrange_type:
+      if (BM->getDebugInfoEIS() == SPIRVEIS_NonSemantic_Kernel_DebugInfo_100)
+        return transDbgSubrangeType(cast<DISubrange>(DIEntry));
+      else
+        return getDebugInfoNone();
+
     case dwarf::DW_TAG_const_type:
     case dwarf::DW_TAG_restrict_type:
     case dwarf::DW_TAG_volatile_type:
@@ -552,6 +558,14 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgQualifiedType(const DIDerivedType *QT) {
 }
 
 SPIRVEntry *LLVMToSPIRVDbgTran::transDbgArrayType(const DICompositeType *AT) {
+  if (BM->getDebugInfoEIS() == SPIRVEIS_NonSemantic_Kernel_DebugInfo_100)
+    return transDbgArrayTypeNonSemantic(AT);
+
+  return transDbgArrayTypeOpenCL(AT);
+}
+
+SPIRVEntry *
+LLVMToSPIRVDbgTran::transDbgArrayTypeOpenCL(const DICompositeType *AT) {
   using namespace SPIRVDebug::Operand::TypeArray;
   SPIRVWordVec Ops(MinOperandCount);
   SPIRVEntry *Base = transDbgEntry(AT->getBaseType());
@@ -594,6 +608,80 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgArrayType(const DICompositeType *AT) {
   return BM->addDebugInfo(SPIRVDebug::TypeArray, getVoidTy(), Ops);
 }
 
+SPIRVEntry *
+LLVMToSPIRVDbgTran::transDbgArrayTypeNonSemantic(const DICompositeType *AT) {
+  using namespace SPIRVDebug::Operand::TypeArray;
+  SPIRVWordVec Ops(MinOperandCount);
+  SPIRVEntry *Base = transDbgEntry(AT->getBaseType());
+  Ops[BaseTypeIdx] = Base->getId();
+
+  DINodeArray AR(AT->getElements());
+  // For N-dimensianal arrays AR.getNumElements() == N
+  const unsigned N = AR.size();
+  Ops.resize(SubrangesIdx + N);
+  for (unsigned I = 0; I < N; ++I) {
+    DISubrange *SR = cast<DISubrange>(AR[I]);
+    ConstantInt *Count = SR->getCount().get<ConstantInt *>();
+    if (AT->isVector()) {
+      assert(N == 1 && "Multidimensional vector is not expected!");
+      Ops[ComponentCountIdx] = static_cast<SPIRVWord>(Count->getZExtValue());
+      return BM->addDebugInfo(SPIRVDebug::TypeVector, getVoidTy(), Ops);
+    }
+    Ops[SubrangesIdx + I] = transDbgEntry(SR)->getId();
+  }
+  return BM->addDebugInfo(SPIRVDebug::TypeArray, getVoidTy(), Ops);
+}
+
+SPIRVEntry *LLVMToSPIRVDbgTran::transDbgSubrangeType(const DISubrange *ST) {
+  using namespace SPIRVDebug::Operand::TypeSubrange;
+  SPIRVWordVec Ops(OperandCount);
+  auto TransOperand = [&Ops, this, ST](int Idx) -> void {
+    Metadata *RawNode = nullptr;
+    switch (Idx) {
+    case LowerBoundIdx:
+      RawNode = ST->getRawLowerBound();
+      break;
+    case UpperBoundIdx:
+      RawNode = ST->getRawUpperBound();
+      break;
+    case CountIdx:
+      RawNode = ST->getRawCountNode();
+      break;
+    case StrideIdx:
+      RawNode = ST->getRawStride();
+      break;
+    }
+    if (!RawNode) {
+      Ops[Idx] = getDebugInfoNoneId();
+      return;
+    }
+    if (auto *Node = dyn_cast<MDNode>(RawNode)) {
+      Ops[Idx] = transDbgEntry(Node)->getId();
+    } else {
+      ConstantInt *IntNode = nullptr;
+      switch (Idx) {
+      case LowerBoundIdx:
+        IntNode = ST->getLowerBound().get<ConstantInt *>();
+        break;
+      case UpperBoundIdx:
+        IntNode = ST->getUpperBound().get<ConstantInt *>();
+        break;
+      case CountIdx:
+        IntNode = ST->getCount().get<ConstantInt *>();
+        break;
+      case StrideIdx:
+        IntNode = ST->getStride().get<ConstantInt *>();
+        break;
+      }
+      Ops[Idx] = IntNode ? SPIRVWriter->transValue(IntNode, nullptr)->getId()
+                         : getDebugInfoNoneId();
+    }
+  };
+  for (int Idx = CountIdx; Idx < OperandCount; ++Idx)
+    TransOperand(Idx);
+  return BM->addDebugInfo(SPIRVDebug::TypeSubrange, getVoidTy(), Ops);
+}
+
 SPIRVEntry *LLVMToSPIRVDbgTran::transDbgTypeDef(const DIDerivedType *DT) {
   using namespace SPIRVDebug::Operand::Typedef;
   SPIRVWordVec Ops(OperandCount);
index 03d62a2d795e1b41b34a37a3d2bd62a5eeacb86f..7793403ca34154cb78d3a7cfbef945c6baa913fd 100644 (file)
@@ -105,6 +105,9 @@ private:
   SPIRVEntry *transDbgPointerType(const DIDerivedType *PT);
   SPIRVEntry *transDbgQualifiedType(const DIDerivedType *QT);
   SPIRVEntry *transDbgArrayType(const DICompositeType *AT);
+  SPIRVEntry *transDbgArrayTypeOpenCL(const DICompositeType *AT);
+  SPIRVEntry *transDbgArrayTypeNonSemantic(const DICompositeType *AT);
+  SPIRVEntry *transDbgSubrangeType(const DISubrange *ST);
   SPIRVEntry *transDbgTypeDef(const DIDerivedType *D);
   SPIRVEntry *transDbgSubroutineType(const DISubroutineType *FT);
   SPIRVEntry *transDbgEnumType(const DICompositeType *ET);
index 6a84d54d52560e6423e5e8fadb71238e7ba05f69..b998abcdc01be92cd7dc34119bf657620e0a2493 100644 (file)
@@ -2376,6 +2376,7 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
       return mapValue(BV, transOCLBuiltinFromExtInst(ExtInst, BB));
     case SPIRVEIS_Debug:
     case SPIRVEIS_OpenCL_DebugInfo_100:
+    case SPIRVEIS_NonSemantic_Kernel_DebugInfo_100:
       return mapValue(BV, DbgTran->transDebugIntrinsic(ExtInst, BB));
     default:
       llvm_unreachable("Unknown extended instruction set!");
index ec396e685cea8745e17213e133da4c930eb1dddf..94c3616f0dee753954e90bdad1e41d00594bc163 100644 (file)
@@ -91,7 +91,8 @@ SPIRVExtInst *SPIRVToLLVMDbgTran::getDbgInst(const SPIRVId Id) {
   if (isa<OpExtInst>(E)) {
     SPIRVExtInst *EI = static_cast<SPIRVExtInst *>(E);
     if (EI->getExtSetKind() == SPIRV::SPIRVEIS_Debug ||
-        EI->getExtSetKind() == SPIRV::SPIRVEIS_OpenCL_DebugInfo_100)
+        EI->getExtSetKind() == SPIRV::SPIRVEIS_OpenCL_DebugInfo_100 ||
+        EI->getExtSetKind() == SPIRV::SPIRVEIS_NonSemantic_Kernel_DebugInfo_100)
       return EI;
   }
   return nullptr;
@@ -193,6 +194,14 @@ DIType *SPIRVToLLVMDbgTran::transTypePointer(const SPIRVExtInst *DebugInst) {
 
 DICompositeType *
 SPIRVToLLVMDbgTran::transTypeArray(const SPIRVExtInst *DebugInst) {
+  if (DebugInst->getExtSetKind() == SPIRVEIS_NonSemantic_Kernel_DebugInfo_100)
+    return transTypeArrayNonSemantic(DebugInst);
+
+  return transTypeArrayOpenCL(DebugInst);
+}
+
+DICompositeType *
+SPIRVToLLVMDbgTran::transTypeArrayOpenCL(const SPIRVExtInst *DebugInst) {
   using namespace SPIRVDebug::Operand::TypeArray;
   const SPIRVWordVec &Ops = DebugInst->getArguments();
   assert(Ops.size() >= MinOperandCount && "Invalid number of operands");
@@ -247,6 +256,28 @@ SPIRVToLLVMDbgTran::transTypeArray(const SPIRVExtInst *DebugInst) {
   return Builder.createArrayType(Size, 0 /*align*/, BaseTy, SubscriptArray);
 }
 
+DICompositeType *
+SPIRVToLLVMDbgTran::transTypeArrayNonSemantic(const SPIRVExtInst *DebugInst) {
+  using namespace SPIRVDebug::Operand::TypeArray;
+  const SPIRVWordVec &Ops = DebugInst->getArguments();
+  assert(Ops.size() >= MinOperandCount && "Invalid number of operands");
+  DIType *BaseTy =
+      transDebugInst<DIType>(BM->get<SPIRVExtInst>(Ops[BaseTypeIdx]));
+  size_t TotalCount = 1;
+  SmallVector<llvm::Metadata *, 8> Subscripts;
+  if (DebugInst->getExtOp() == SPIRVDebug::TypeArray) {
+    for (size_t I = SubrangesIdx; I < Ops.size(); ++I) {
+      auto *SR = transDebugInst<DISubrange>(BM->get<SPIRVExtInst>(Ops[I]));
+      if (auto *Count = SR->getCount().get<ConstantInt *>())
+        TotalCount *= Count->getZExtValue() > 0 ? Count->getZExtValue() : 0;
+      Subscripts.push_back(SR);
+    }
+  }
+  DINodeArray SubscriptArray = Builder.getOrCreateArray(Subscripts);
+  size_t Size = getDerivedSizeInBits(BaseTy) * TotalCount;
+  return Builder.createArrayType(Size, 0 /*align*/, BaseTy, SubscriptArray);
+}
+
 DICompositeType *
 SPIRVToLLVMDbgTran::transTypeVector(const SPIRVExtInst *DebugInst) {
   using namespace SPIRVDebug::Operand::TypeVector;
@@ -287,6 +318,8 @@ SPIRVToLLVMDbgTran::transTypeComposite(const SPIRVExtInst *DebugInst) {
   SPIRVEntry *SizeEntry = BM->getEntry(Ops[SizeIdx]);
   if (!(SizeEntry->isExtInst(SPIRVEIS_Debug, SPIRVDebug::DebugInfoNone) ||
         SizeEntry->isExtInst(SPIRVEIS_OpenCL_DebugInfo_100,
+                             SPIRVDebug::DebugInfoNone) ||
+        SizeEntry->isExtInst(SPIRVEIS_NonSemantic_Kernel_DebugInfo_100,
                              SPIRVDebug::DebugInfoNone))) {
     Size = BM->get<SPIRVConstant>(Ops[SizeIdx])->getZExtIntValue();
   }
@@ -342,6 +375,36 @@ SPIRVToLLVMDbgTran::transTypeComposite(const SPIRVExtInst *DebugInst) {
   return CT;
 }
 
+DISubrange *
+SPIRVToLLVMDbgTran::transTypeSubrange(const SPIRVExtInst *DebugInst) {
+  using namespace SPIRVDebug::Operand::TypeSubrange;
+  const SPIRVWordVec &Ops = DebugInst->getArguments();
+  assert(Ops.size() == OperandCount && "Invalid number of operands");
+  std::vector<Metadata *> TranslatedOps(OperandCount, nullptr);
+  auto TransOperand = [&Ops, &TranslatedOps, this](int Idx) -> void {
+    if (!getDbgInst<SPIRVDebug::DebugInfoNone>(Ops[Idx])) {
+      if (auto *GlobalVar = getDbgInst<SPIRVDebug::GlobalVariable>(Ops[Idx])) {
+        TranslatedOps[Idx] =
+            cast<Metadata>(transDebugInst<DIGlobalVariable>(GlobalVar));
+      } else if (auto *LocalVar =
+                     getDbgInst<SPIRVDebug::LocalVariable>(Ops[Idx])) {
+        TranslatedOps[Idx] =
+            cast<Metadata>(transDebugInst<DILocalVariable>(LocalVar));
+      } else if (auto *Expr = getDbgInst<SPIRVDebug::Expression>(Ops[Idx])) {
+        TranslatedOps[Idx] = cast<Metadata>(transDebugInst<DIExpression>(Expr));
+      } else if (auto *Const = BM->get<SPIRVConstant>(Ops[Idx])) {
+        int64_t ConstantAsInt = static_cast<int64_t>(Const->getZExtIntValue());
+        TranslatedOps[Idx] = cast<Metadata>(ConstantAsMetadata::get(
+            ConstantInt::get(M->getContext(), APInt(64, ConstantAsInt))));
+      }
+    }
+  };
+  for (int Idx = CountIdx; Idx < OperandCount; ++Idx)
+    TransOperand(Idx);
+  return Builder.getOrCreateSubrange(TranslatedOps[0], TranslatedOps[1],
+                                     TranslatedOps[2], TranslatedOps[3]);
+}
+
 DINode *SPIRVToLLVMDbgTran::transTypeMember(const SPIRVExtInst *DebugInst) {
   using namespace SPIRVDebug::Operand::TypeMember;
   const SPIRVWordVec &Ops = DebugInst->getArguments();
@@ -888,6 +951,9 @@ MDNode *SPIRVToLLVMDbgTran::transDebugInstImpl(const SPIRVExtInst *DebugInst) {
   case SPIRVDebug::TypeArray:
     return transTypeArray(DebugInst);
 
+  case SPIRVDebug::TypeSubrange:
+    return transTypeSubrange(DebugInst);
+
   case SPIRVDebug::TypeVector:
     return transTypeVector(DebugInst);
 
index a95c99cb37d34e3f62575bd6727eab9844776115..3a0f78d45363e03cfa36ea4b9d8286c4cb8bc752 100644 (file)
@@ -70,7 +70,9 @@ public:
   template <typename T = MDNode>
   T *transDebugInst(const SPIRVExtInst *DebugInst) {
     assert((DebugInst->getExtSetKind() == SPIRVEIS_Debug ||
-            DebugInst->getExtSetKind() == SPIRVEIS_OpenCL_DebugInfo_100) &&
+            DebugInst->getExtSetKind() == SPIRVEIS_OpenCL_DebugInfo_100 ||
+            DebugInst->getExtSetKind() ==
+                SPIRVEIS_NonSemantic_Kernel_DebugInfo_100) &&
            "Unexpected extended instruction set");
     auto It = DebugInstCache.find(DebugInst);
     if (It != DebugInstCache.end())
@@ -107,11 +109,15 @@ private:
   DIType *transTypePointer(const SPIRVExtInst *DebugInst);
 
   DICompositeType *transTypeArray(const SPIRVExtInst *DebugInst);
+  DICompositeType *transTypeArrayOpenCL(const SPIRVExtInst *DebugInst);
+  DICompositeType *transTypeArrayNonSemantic(const SPIRVExtInst *DebugInst);
 
   DICompositeType *transTypeVector(const SPIRVExtInst *DebugInst);
 
   DICompositeType *transTypeComposite(const SPIRVExtInst *DebugInst);
 
+  DISubrange *transTypeSubrange(const SPIRVExtInst *DebugInst);
+
   DINode *transTypeMember(const SPIRVExtInst *DebugInst);
 
   DINode *transTypeEnum(const SPIRVExtInst *DebugInst);
index 026a308376372f9a9dc80b6a5a70e7faef3270d1..007783cbf982b37b8d177b428acab64d865f207a 100644 (file)
@@ -50,7 +50,8 @@ enum Instruction {
   ImportedEntity                = 34,
   Source                        = 35,
   ModuleINTEL                   = 36,
-  InstCount                     = 37
+  InstCount                     = 37,
+  TypeSubrange                  = 110
 };
 
 enum Flag {
@@ -323,12 +324,23 @@ namespace TypeArray {
 enum {
   BaseTypeIdx       = 0,
   ComponentCountIdx = 1,
+  SubrangesIdx      = 1,
   MinOperandCount   = 2
 };
 }
 
 namespace TypeVector = TypeArray;
 
+namespace TypeSubrange {
+enum {
+  CountIdx        = 0,
+  LowerBoundIdx   = 1,
+  UpperBoundIdx   = 2,
+  StrideIdx       = 3,
+  OperandCount    = 4
+};
+}
+
 namespace Typedef {
 enum {
   NameIdx      = 0,
index 3695fd565e5e5fdb3beb6d302041c0af1fc13aeb..4e4cbf8248906ad95357b61391778bda90dc2892 100644 (file)
@@ -78,6 +78,7 @@ enum SPIRVExtInstSetKind {
   SPIRVEIS_OpenCL,
   SPIRVEIS_Debug,
   SPIRVEIS_OpenCL_DebugInfo_100,
+  SPIRVEIS_NonSemantic_Kernel_DebugInfo_100,
   SPIRVEIS_Count,
 };
 
@@ -129,6 +130,8 @@ template <> inline void SPIRVMap<SPIRVExtInstSetKind, std::string>::init() {
   add(SPIRVEIS_OpenCL, "OpenCL.std");
   add(SPIRVEIS_Debug, "SPIRV.debug");
   add(SPIRVEIS_OpenCL_DebugInfo_100, "OpenCL.DebugInfo.100");
+  add(SPIRVEIS_NonSemantic_Kernel_DebugInfo_100,
+      "NonSemantic.Kernel.DebugInfo.100");
 }
 typedef SPIRVMap<SPIRVExtInstSetKind, std::string> SPIRVBuiltinSetNameMap;
 
index 9f1aa91a964741f9baa567824cd443c415efa7a4..245552900c52e6bc5b1c1283fddeb0a8c1f8d335 100644 (file)
@@ -239,6 +239,7 @@ template <> inline void SPIRVMap<SPIRVDebugExtOpKind, std::string>::init() {
       "DebugTemplateTemplateParameter");
   add(SPIRVDebug::TypeTemplate, "DebugTemplate");
   add(SPIRVDebug::TypePtrToMember, "DebugTypePtrToMember,");
+  add(SPIRVDebug::TypeSubrange, "DebugTypeSubrange");
   add(SPIRVDebug::Inheritance, "DebugInheritance");
   add(SPIRVDebug::Function, "DebugFunction");
   add(SPIRVDebug::FunctionDecl, "DebugFunctionDecl");
index da1ba0dfbc676bd41935f4903165b000fe3bc726..c91a6506937360f6b9840c4311f72cd0b07908db 100644 (file)
@@ -161,10 +161,14 @@ bool SPIRVFunction::decodeBB(SPIRVDecoder &Decoder) {
       Module->add(Inst);
     } else {
       if (Inst->isExtInst(SPIRVEIS_Debug, SPIRVDebug::Scope) ||
-          Inst->isExtInst(SPIRVEIS_OpenCL_DebugInfo_100, SPIRVDebug::Scope)) {
+          Inst->isExtInst(SPIRVEIS_OpenCL_DebugInfo_100, SPIRVDebug::Scope) ||
+          Inst->isExtInst(SPIRVEIS_NonSemantic_Kernel_DebugInfo_100,
+                          SPIRVDebug::Scope)) {
         DebugScope = Inst;
       } else if (Inst->isExtInst(SPIRVEIS_Debug, SPIRVDebug::NoScope) ||
                  Inst->isExtInst(SPIRVEIS_OpenCL_DebugInfo_100,
+                                 SPIRVDebug::NoScope) ||
+                 Inst->isExtInst(SPIRVEIS_NonSemantic_Kernel_DebugInfo_100,
                                  SPIRVDebug::NoScope)) {
         DebugScope = nullptr;
       } else {
index cd91461c28a0c39e9591169adc7b6c723cf64aee..69a12ca614f6105d48b99756c9ef4bfe6c8730af 100644 (file)
@@ -1761,7 +1761,8 @@ public:
     assert(Module && "Invalid module");
     ExtSetKind = Module->getBuiltinSet(ExtSetId);
     assert((ExtSetKind == SPIRVEIS_OpenCL || ExtSetKind == SPIRVEIS_Debug ||
-            ExtSetKind == SPIRVEIS_OpenCL_DebugInfo_100) &&
+            ExtSetKind == SPIRVEIS_OpenCL_DebugInfo_100 ||
+            ExtSetKind == SPIRVEIS_NonSemantic_Kernel_DebugInfo_100) &&
            "not supported");
   }
   void encode(spv_ostream &O) const override {
@@ -1772,6 +1773,7 @@ public:
       break;
     case SPIRVEIS_Debug:
     case SPIRVEIS_OpenCL_DebugInfo_100:
+    case SPIRVEIS_NonSemantic_Kernel_DebugInfo_100:
       getEncoder(O) << ExtOpDebug;
       break;
     default:
@@ -1789,6 +1791,7 @@ public:
       break;
     case SPIRVEIS_Debug:
     case SPIRVEIS_OpenCL_DebugInfo_100:
+    case SPIRVEIS_NonSemantic_Kernel_DebugInfo_100:
       getDecoder(I) >> ExtOpDebug;
       break;
     default:
index b5c14cbe5baf769b2d1d6c57ac408d70b8ff1d5c..cc64266b62151062a4b3ebd5d22fd8b8eb89603b 100644 (file)
@@ -642,7 +642,8 @@ void SPIRVModuleImpl::layoutEntry(SPIRVEntry *E) {
   case OpExtInst: {
     SPIRVExtInst *EI = static_cast<SPIRVExtInst *>(E);
     if ((EI->getExtSetKind() == SPIRVEIS_Debug ||
-         EI->getExtSetKind() == SPIRVEIS_OpenCL_DebugInfo_100) &&
+         EI->getExtSetKind() == SPIRVEIS_OpenCL_DebugInfo_100 ||
+         EI->getExtSetKind() == SPIRVEIS_NonSemantic_Kernel_DebugInfo_100) &&
         EI->getExtOp() != SPIRVDebug::Declare &&
         EI->getExtOp() != SPIRVDebug::Value &&
         EI->getExtOp() != SPIRVDebug::Scope &&
index a8c154453be33a64ab7ecbe274ba39cbdbcd8514..2ec832c0adfacbc25f265bf7bf3d335180eb2fc5 100644 (file)
@@ -528,6 +528,8 @@ public:
       return SPIRVEIS_Debug;
     case DebugInfoEIS::OpenCL_DebugInfo_100:
       return SPIRVEIS_OpenCL_DebugInfo_100;
+    case DebugInfoEIS::NonSemantic_Kernel_DebugInfo_100:
+      return SPIRVEIS_NonSemantic_Kernel_DebugInfo_100;
     }
     assert(false && "Unexpected debug info EIS!");
     return SPIRVEIS_Debug;
diff --git a/test/DebugInfo/DebugInfoSubrange.ll b/test/DebugInfo/DebugInfoSubrange.ll
deleted file mode 100644 (file)
index 27c8108..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-; RUN: llvm-as %s -o %t.bc
-; RUN: llvm-spirv -spirv-text %t.bc -o %t.spt
-; RUN: FileCheck < %t.spt %s -check-prefix=CHECK-SPIRV
-
-; RUN: llvm-spirv -to-binary %t.spt -o %t.spv
-; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
-; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
-; RUN: FileCheck < %t.rev.ll %s -check-prefix=CHECK-LLVM
-
-; CHECK-SPIRV: String [[#VarNameId:]] "A$1$upperbound"
-; CHECK-SPIRV: [[#FuncNameId:]] "random_fill_sp"
-; CHECK-SPIRV: TypeInt [[#TypeInt64Id:]] 64 0
-; CHECK-SPIRV: Constant [[#TypeInt64Id]] [[#LowerBoundId:]] 1 0
-; CHECK-SPIRV: Constant [[#TypeInt64Id]] [[#NegativeCount:]] 4294967295 4294967295
-
-; CHECK-SPIRV: [[#DbgFuncId:]] [[#]] DebugFunction [[#FuncNameId]]
-; CHECK-SPIRV: [[#DbgTemplateId:]] [[#]] DebugTemplate [[#DbgFuncId]]
-; CHECK-SPIRV: [[#]] [[#DbgLocVarId:]] [[#]] DebugLocalVariable [[#VarNameId]] [[#]] [[#]] [[#]] [[#]] [[#DbgTemplateId]]
-; CHECK-SPIRV: DebugTypeArray [[#]] [[#DbgLocVarId]] [[#LowerBoundId]]
-
-; CHECK-SPIRV: [[#DbgExprId:]] [[#]] DebugExpression
-; CHECK-SPIRV: DebugTypeArray [[#]] [[#DbgExprId]] [[#DbgExprId]]
-
-; CHECK-SPIRV: DebugTypeArray [[#]] [[#NegativeCount]] [[#]]
-
-; CHECK-LLVM: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[#BaseType:]], size: 32, elements: ![[#Subrange1:]])
-; CHECK-LLVM: [[#BaseType]] = !DIBasicType(name: "REAL*4", size: 32, encoding: DW_ATE_float)
-; CHECK-LLVM: [[#Subrange1]] = !{![[#Subrange2:]]}
-; CHECK-LLVM: [[#Subrange2:]] = !DISubrange(lowerBound: 1, upperBound: ![[#UpperBound:]])
-; CHECK-LLVM: [[#UpperBound]] = !DILocalVariable(name: "A$1$upperbound"
-
-; CHECK-LLVM: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[#]], size: 32, elements: ![[#SubrangeExpr1:]])
-; CHECK-LLVM: [[#SubrangeExpr1]] = !{![[#SubrangeExpr2:]]}
-; CHECK-LLVM: ![[#SubrangeExpr2]] = !DISubrange(lowerBound: !DIExpression(), upperBound: !DIExpression())
-
-; CHECK-LLVM: !DISubrange(count: 1000, lowerBound: 1)
-
-; CHECK-LLVM: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[#BaseType:]], elements: ![[#Subrage:]])
-; CHECK-LLVM: ![[#BaseType]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-; CHECK-LLVM: ![[#Subrage]] = !{![[#Subrage:]]}
-; CHECK-LLVM: ![[#Subrage]] = !DISubrange(count: -1
-
-; ModuleID = 'DebugInfoSubrangeUpperBound.bc'
-target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024"
-target triple = "spir64-unknown-unknown"
-
-%structtype = type { [72 x i1] }
-%"QNCA_a0$float" = type { float addrspace(4)*, i64, i64, i64, i64, i64, [1 x %structtype2] }
-%structtype2 = type { i64, i64, i64 }
-
-; Function Attrs: noinline nounwind
-define spir_kernel void @__omp_offloading_811_198142f_random_fill_sp_l25(i32 addrspace(1)* noalias %0, %structtype* byval(%structtype) %"ascast$val", [1000 x i32] addrspace(1)* noalias %"ascastB$val") #0 !kernel_arg_addr_space !9 !kernel_arg_access_qual !10 !kernel_arg_type !11 !kernel_arg_type_qual !12 !kernel_arg_base_type !11 {
-newFuncRoot:
-  %.ascast = bitcast %structtype* %"ascast$val" to %"QNCA_a0$float"*
-  call void @llvm.dbg.value(metadata %"QNCA_a0$float"* %.ascast, metadata !13, metadata !DIExpression(DW_OP_deref)), !dbg !27
-  call void @llvm.dbg.value(metadata %"QNCA_a0$float"* %.ascast, metadata !28, metadata !DIExpression(DW_OP_deref)), !dbg !42
-  call void @llvm.dbg.value(metadata [1000 x i32] addrspace(1)* %"ascastB$val", metadata !47, metadata !DIExpression(DW_OP_deref)), !dbg !51
-  call void @llvm.dbg.value(metadata i32 addrspace(1)* %0, metadata !54, metadata !DIExpression(DW_OP_deref)), !dbg !59
-  ret void
-}
-
-; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
-declare void @llvm.dbg.value(metadata, metadata, metadata) #1
-
-attributes #0 = { noinline nounwind }
-attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
-
-!llvm.module.flags = !{!0, !1}
-!llvm.dbg.cu = !{!2}
-!spirv.MemoryModel = !{!4}
-!opencl.enable.FP_CONTRACT = !{}
-!spirv.Source = !{!5}
-!opencl.spir.version = !{!6}
-!opencl.ocl.version = !{!6}
-!opencl.used.extensions = !{!7}
-!opencl.used.optional.core.features = !{!7}
-!spirv.Generator = !{!8}
-
-!0 = !{i32 7, !"Dwarf Version", i32 4}
-!1 = !{i32 2, !"Debug Info Version", i32 3}
-!2 = distinct !DICompileUnit(language: DW_LANG_OpenCL, file: !3, producer: "Fortran", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
-!3 = !DIFile(filename: "f.f90", directory: "Fortran")
-!4 = !{i32 2, i32 2}
-!5 = !{i32 4, i32 200000}
-!6 = !{i32 2, i32 0}
-!7 = !{}
-!8 = !{i16 6, i16 14}
-!9 = !{i32 0}
-!10 = !{!"none"}
-!11 = !{!"structtype"}
-!12 = !{!""}
-!13 = !DILocalVariable(name: "a", scope: !14, file: !3, line: 15, type: !18)
-!14 = distinct !DISubprogram(name: "random_fill_sp.DIR.OMP.TARGET.8.split.split.split.split", scope: null, file: !3, line: 25, type: !15, scopeLine: 25, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2, templateParams: !7, retainedNodes: !17)
-!15 = !DISubroutineType(types: !16)
-!16 = !{null}
-!17 = !{!13}
-!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
-!19 = !DICompositeType(tag: DW_TAG_array_type, baseType: !20, size: 32, elements: !21)
-!20 = !DIBasicType(name: "REAL*4", size: 32, encoding: DW_ATE_float)
-!21 = !{!22}
-!22 = !DISubrange(lowerBound: 1, upperBound: !23)
-!23 = !DILocalVariable(name: "A$1$upperbound", scope: !24, type: !26, flags: DIFlagArtificial)
-!24 = distinct !DISubprogram(name: "random_fill_sp", linkageName: "random_fill_sp", scope: null, file: !3, line: 15, type: !15, scopeLine: 15, spFlags: DISPFlagDefinition, unit: !2, templateParams: !7, retainedNodes: !25)
-!25 = !{!23}
-!26 = !DIBasicType(name: "INTEGER*8", size: 64, encoding: DW_ATE_signed)
-!27 = !DILocation(line: 15, column: 67, scope: !14)
-!28 = !DILocalVariable(name: "a", scope: !29, file: !3, line: 15, type: !33)
-!29 = distinct !DISubprogram(name: "random_fill_sp.DIR.OMP.TARGET.8.split.split.split.split", scope: null, file: !3, line: 25, type: !30, scopeLine: 25, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2, templateParams: !7, retainedNodes: !32)
-!30 = !DISubroutineType(types: !31)
-!31 = !{null}
-!32 = !{!28}
-!33 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !34, size: 64)
-!34 = !DICompositeType(tag: DW_TAG_array_type, baseType: !35, size: 32, elements: !36)
-!35 = !DIBasicType(name: "REAL*4", size: 32, encoding: DW_ATE_float)
-!36 = !{!37}
-!37 = !DISubrange(lowerBound: !DIExpression(), upperBound: !DIExpression())
-!38 = !DILocalVariable(name: "A$1$upperbound", scope: !39, type: !41, flags: DIFlagArtificial)
-!39 = distinct !DISubprogram(name: "random_fill_sp", linkageName: "random_fill_sp", scope: null, file: !3, line: 15, type: !30, scopeLine: 15, spFlags: DISPFlagDefinition, unit: !2, templateParams: !7, retainedNodes: !40)
-!40 = !{!38}
-!41 = !DIBasicType(name: "INTEGER*8", size: 64, encoding: DW_ATE_signed)
-!42 = !DILocation(line: 15, column: 67, scope: !29)
-!43 = !DIBasicType(name: "INTEGER*4", size: 32, encoding: DW_ATE_signed)
-!44 = !{}
-!45 = !DISubroutineType(types: !44)
-!46 = distinct !DISubprogram(name: "test_target_map_array_default_IP_test_array_map_no_map_type_.DIR.OMP.TARGET.340.split", scope: !3, file: !3, line: 32, type: !45, scopeLine: 32, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2)
-!47 = !DILocalVariable(name: "compute_array", scope: !46, file: !3, line: 27, type: !48)
-!48 = !DICompositeType(tag: DW_TAG_array_type, baseType: !43, elements: !49)
-!49 = !{!50}
-!50 = !DISubrange(count: 1000, lowerBound: 1)
-!51 = !DILocation(line: 27, column: 24, scope: !46)
-!52 = distinct !DISubprogram(name: "test", scope: !3, file: !3, line: 51, type: !53, scopeLine: 51, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2)
-!53 = !DISubroutineType(types: !7)
-!54 = !DILocalVariable(name: "isHost", scope: !52, file: !3, line: 34, type: !55)
-!55 = !DICompositeType(tag: DW_TAG_array_type, baseType: !56, elements: !57)
-!56 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-!57 = !{!58}
-!58 = !DISubrange(count: -1)
-!59 = !DILocation(line: 34, column: 33, scope: !52)
diff --git a/test/DebugInfo/NonSemanticKernel100/DebugInfoSubrange.ll b/test/DebugInfo/NonSemanticKernel100/DebugInfoSubrange.ll
new file mode 100644 (file)
index 0000000..0a901ae
--- /dev/null
@@ -0,0 +1,128 @@
+; RUN: llvm-as %s -o %t.bc
+; RUN: llvm-spirv -spirv-text %t.bc -o %t.spt --spirv-debug-info-version=nonsemantic-kernel-100
+; RUN: FileCheck < %t.spt %s -check-prefix=CHECK-SPIRV
+; RUN: llvm-spirv -to-binary %t.spt -o %t.spv
+
+; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
+; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
+; RUN: FileCheck < %t.rev.ll %s -check-prefix=CHECK-LLVM
+
+; CHECK-SPIRV: ExtInstImport [[#EISId:]] "NonSemantic.Kernel.DebugInfo.100"
+
+; CHECK-SPIRV: String [[#LocalVarNameId:]] "A$1$upperbound"
+; CHECK-SPIRV: TypeInt [[#TyInt64Id:]] 64 0
+; CHECK-SPIRV-DAG: Constant [[#TyInt64Id]] [[#Constant1Id:]] 1 0
+; CHECK-SPIRV-DAG: Constant [[#TyInt64Id]] [[#Constant1000Id:]] 1000 0
+; CHECK-SPIRV: [[#DINoneId:]] [[#EISId]] DebugInfoNone
+
+; CHECK-SPIRV: [[#DebugFuncId:]] [[#EISId]] DebugFunction
+; CHECK-SPIRV: [[#DebugTemplate:]] [[#EISId]] DebugTemplate [[#DebugFuncId]]
+; CHECK-SPIRV: [[#LocalVarId:]] [[#EISId]] DebugLocalVariable [[#LocalVarNameId]] [[#]] [[#]] [[#]] [[#]] [[#DebugTemplate]]
+; CHECK-SPIRV: [[#EISId]] DebugTypeSubrange [[#DINoneId]] [[#Constant1Id]] [[#LocalVarId]]  [[#DINoneId]]
+
+; CHECK-SPIRV: [[#DIExprId:]] [[#EISId]] DebugExpression
+; CHECK-SPIRV: [[#EISId]] DebugTypeSubrange [[#DINoneId]] [[#DIExprId]] [[#DIExprId]] [[#DINoneId]]
+
+; CHECK-SPIRV: [[#EISId]] DebugTypeSubrange [[#Constant1000Id]] [[#Constant1Id]] [[#DINoneId]] [[#DINoneId]]
+
+; CHECK-LLVM: [[#Subrange1:]] = !DISubrange(lowerBound: 1, upperBound: ![[#UpperBound:]])
+; CHECK-LLVM: [[#UpperBound]] = !DILocalVariable(name: "A$1$upperbound"
+; CHECK-LLVM: !DISubrange(lowerBound: !DIExpression(), upperBound: !DIExpression())
+; CHECK-LLVM: !DISubrange(count: 1000, lowerBound: 1)
+
+; ModuleID = 'DebugInfoSubrangeUpperBound.bc'
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024"
+target triple = "spir64-unknown-unknown"
+
+%structtype = type { [72 x i1] }
+%"QNCA_a0$float" = type { float addrspace(4)*, i64, i64, i64, i64, i64, [1 x %structtype2] }
+%structtype2 = type { i64, i64, i64 }
+
+; Function Attrs: noinline nounwind
+define spir_kernel void @__omp_offloading_811_198142f_random_fill_sp_l25(i32 addrspace(1)* noalias %0, %structtype* byval(%structtype) %"ascast$val", [1000 x i32] addrspace(1)* noalias %"ascastB$val") #0 !kernel_arg_addr_space !9 !kernel_arg_access_qual !10 !kernel_arg_type !11 !kernel_arg_type_qual !12 !kernel_arg_base_type !11 {
+newFuncRoot:
+  %.ascast = bitcast %structtype* %"ascast$val" to %"QNCA_a0$float"*
+  call void @llvm.dbg.value(metadata %"QNCA_a0$float"* %.ascast, metadata !13, metadata !DIExpression(DW_OP_deref)), !dbg !27
+  call void @llvm.dbg.value(metadata %"QNCA_a0$float"* %.ascast, metadata !28, metadata !DIExpression(DW_OP_deref)), !dbg !42
+  call void @llvm.dbg.value(metadata [1000 x i32] addrspace(1)* %"ascastB$val", metadata !47, metadata !DIExpression(DW_OP_deref)), !dbg !51
+  call void @llvm.dbg.value(metadata i32 addrspace(1)* %0, metadata !54, metadata !DIExpression(DW_OP_deref)), !dbg !59
+  ret void
+}
+
+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.value(metadata, metadata, metadata) #1
+
+attributes #0 = { noinline nounwind }
+attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
+
+!llvm.module.flags = !{!0, !1}
+!llvm.dbg.cu = !{!2}
+!spirv.MemoryModel = !{!4}
+!opencl.enable.FP_CONTRACT = !{}
+!spirv.Source = !{!5}
+!opencl.spir.version = !{!6}
+!opencl.ocl.version = !{!6}
+!opencl.used.extensions = !{!7}
+!opencl.used.optional.core.features = !{!7}
+!spirv.Generator = !{!8}
+
+!0 = !{i32 7, !"Dwarf Version", i32 4}
+!1 = !{i32 2, !"Debug Info Version", i32 3}
+!2 = distinct !DICompileUnit(language: DW_LANG_OpenCL, file: !3, producer: "Fortran", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
+!3 = !DIFile(filename: "f.f90", directory: "Fortran")
+!4 = !{i32 2, i32 2}
+!5 = !{i32 4, i32 200000}
+!6 = !{i32 2, i32 0}
+!7 = !{}
+!8 = !{i16 6, i16 14}
+!9 = !{i32 0}
+!10 = !{!"none"}
+!11 = !{!"structtype"}
+!12 = !{!""}
+!13 = !DILocalVariable(name: "a", scope: !14, file: !3, line: 15, type: !18)
+!14 = distinct !DISubprogram(name: "random_fill_sp.DIR.OMP.TARGET.8.split.split.split.split", scope: null, file: !3, line: 25, type: !15, scopeLine: 25, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2, templateParams: !7, retainedNodes: !17)
+!15 = !DISubroutineType(types: !16)
+!16 = !{null}
+!17 = !{!13}
+!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
+!19 = !DICompositeType(tag: DW_TAG_array_type, baseType: !20, size: 32, elements: !21)
+!20 = !DIBasicType(name: "REAL*4", size: 32, encoding: DW_ATE_float)
+!21 = !{!22}
+!22 = !DISubrange(lowerBound: 1, upperBound: !23)
+!23 = !DILocalVariable(name: "A$1$upperbound", scope: !24, type: !26, flags: DIFlagArtificial)
+!24 = distinct !DISubprogram(name: "random_fill_sp", linkageName: "random_fill_sp", scope: null, file: !3, line: 15, type: !15, scopeLine: 15, spFlags: DISPFlagDefinition, unit: !2, templateParams: !7, retainedNodes: !25)
+!25 = !{!23}
+!26 = !DIBasicType(name: "INTEGER*8", size: 64, encoding: DW_ATE_signed)
+!27 = !DILocation(line: 15, column: 67, scope: !14)
+!28 = !DILocalVariable(name: "a", scope: !29, file: !3, line: 15, type: !33)
+!29 = distinct !DISubprogram(name: "random_fill_sp.DIR.OMP.TARGET.8.split.split.split.split", scope: null, file: !3, line: 25, type: !30, scopeLine: 25, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2, templateParams: !7, retainedNodes: !32)
+!30 = !DISubroutineType(types: !31)
+!31 = !{null}
+!32 = !{!28}
+!33 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !34, size: 64)
+!34 = !DICompositeType(tag: DW_TAG_array_type, baseType: !35, size: 32, elements: !36)
+!35 = !DIBasicType(name: "REAL*4", size: 32, encoding: DW_ATE_float)
+!36 = !{!37}
+!37 = !DISubrange(lowerBound: !DIExpression(), upperBound: !DIExpression())
+!38 = !DILocalVariable(name: "A$1$upperbound", scope: !39, type: !41, flags: DIFlagArtificial)
+!39 = distinct !DISubprogram(name: "random_fill_sp", linkageName: "random_fill_sp", scope: null, file: !3, line: 15, type: !30, scopeLine: 15, spFlags: DISPFlagDefinition, unit: !2, templateParams: !7, retainedNodes: !40)
+!40 = !{!38}
+!41 = !DIBasicType(name: "INTEGER*8", size: 64, encoding: DW_ATE_signed)
+!42 = !DILocation(line: 15, column: 67, scope: !29)
+!43 = !DIBasicType(name: "INTEGER*4", size: 32, encoding: DW_ATE_signed)
+!44 = !{}
+!45 = !DISubroutineType(types: !44)
+!46 = distinct !DISubprogram(name: "test_target_map_array_default_IP_test_array_map_no_map_type_.DIR.OMP.TARGET.340.split", scope: !3, file: !3, line: 32, type: !45, scopeLine: 32, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2)
+!47 = !DILocalVariable(name: "compute_array", scope: !46, file: !3, line: 27, type: !48)
+!48 = !DICompositeType(tag: DW_TAG_array_type, baseType: !43, elements: !49)
+!49 = !{!50}
+!50 = !DISubrange(count: 1000, lowerBound: 1)
+!51 = !DILocation(line: 27, column: 24, scope: !46)
+!52 = distinct !DISubprogram(name: "test", scope: !3, file: !3, line: 51, type: !53, scopeLine: 51, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2)
+!53 = !DISubroutineType(types: !7)
+!54 = !DILocalVariable(name: "isHost", scope: !52, file: !3, line: 34, type: !55)
+!55 = !DICompositeType(tag: DW_TAG_array_type, baseType: !56, elements: !57)
+!56 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!57 = !{!58}
+!58 = !DISubrange(count: -1)
+!59 = !DILocation(line: 34, column: 33, scope: !52)
diff --git a/test/DebugInfo/OpenCL100/DebugInfoSubrange.ll b/test/DebugInfo/OpenCL100/DebugInfoSubrange.ll
new file mode 100644 (file)
index 0000000..27c8108
--- /dev/null
@@ -0,0 +1,138 @@
+; RUN: llvm-as %s -o %t.bc
+; RUN: llvm-spirv -spirv-text %t.bc -o %t.spt
+; RUN: FileCheck < %t.spt %s -check-prefix=CHECK-SPIRV
+
+; RUN: llvm-spirv -to-binary %t.spt -o %t.spv
+; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
+; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
+; RUN: FileCheck < %t.rev.ll %s -check-prefix=CHECK-LLVM
+
+; CHECK-SPIRV: String [[#VarNameId:]] "A$1$upperbound"
+; CHECK-SPIRV: [[#FuncNameId:]] "random_fill_sp"
+; CHECK-SPIRV: TypeInt [[#TypeInt64Id:]] 64 0
+; CHECK-SPIRV: Constant [[#TypeInt64Id]] [[#LowerBoundId:]] 1 0
+; CHECK-SPIRV: Constant [[#TypeInt64Id]] [[#NegativeCount:]] 4294967295 4294967295
+
+; CHECK-SPIRV: [[#DbgFuncId:]] [[#]] DebugFunction [[#FuncNameId]]
+; CHECK-SPIRV: [[#DbgTemplateId:]] [[#]] DebugTemplate [[#DbgFuncId]]
+; CHECK-SPIRV: [[#]] [[#DbgLocVarId:]] [[#]] DebugLocalVariable [[#VarNameId]] [[#]] [[#]] [[#]] [[#]] [[#DbgTemplateId]]
+; CHECK-SPIRV: DebugTypeArray [[#]] [[#DbgLocVarId]] [[#LowerBoundId]]
+
+; CHECK-SPIRV: [[#DbgExprId:]] [[#]] DebugExpression
+; CHECK-SPIRV: DebugTypeArray [[#]] [[#DbgExprId]] [[#DbgExprId]]
+
+; CHECK-SPIRV: DebugTypeArray [[#]] [[#NegativeCount]] [[#]]
+
+; CHECK-LLVM: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[#BaseType:]], size: 32, elements: ![[#Subrange1:]])
+; CHECK-LLVM: [[#BaseType]] = !DIBasicType(name: "REAL*4", size: 32, encoding: DW_ATE_float)
+; CHECK-LLVM: [[#Subrange1]] = !{![[#Subrange2:]]}
+; CHECK-LLVM: [[#Subrange2:]] = !DISubrange(lowerBound: 1, upperBound: ![[#UpperBound:]])
+; CHECK-LLVM: [[#UpperBound]] = !DILocalVariable(name: "A$1$upperbound"
+
+; CHECK-LLVM: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[#]], size: 32, elements: ![[#SubrangeExpr1:]])
+; CHECK-LLVM: [[#SubrangeExpr1]] = !{![[#SubrangeExpr2:]]}
+; CHECK-LLVM: ![[#SubrangeExpr2]] = !DISubrange(lowerBound: !DIExpression(), upperBound: !DIExpression())
+
+; CHECK-LLVM: !DISubrange(count: 1000, lowerBound: 1)
+
+; CHECK-LLVM: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[#BaseType:]], elements: ![[#Subrage:]])
+; CHECK-LLVM: ![[#BaseType]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+; CHECK-LLVM: ![[#Subrage]] = !{![[#Subrage:]]}
+; CHECK-LLVM: ![[#Subrage]] = !DISubrange(count: -1
+
+; ModuleID = 'DebugInfoSubrangeUpperBound.bc'
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024"
+target triple = "spir64-unknown-unknown"
+
+%structtype = type { [72 x i1] }
+%"QNCA_a0$float" = type { float addrspace(4)*, i64, i64, i64, i64, i64, [1 x %structtype2] }
+%structtype2 = type { i64, i64, i64 }
+
+; Function Attrs: noinline nounwind
+define spir_kernel void @__omp_offloading_811_198142f_random_fill_sp_l25(i32 addrspace(1)* noalias %0, %structtype* byval(%structtype) %"ascast$val", [1000 x i32] addrspace(1)* noalias %"ascastB$val") #0 !kernel_arg_addr_space !9 !kernel_arg_access_qual !10 !kernel_arg_type !11 !kernel_arg_type_qual !12 !kernel_arg_base_type !11 {
+newFuncRoot:
+  %.ascast = bitcast %structtype* %"ascast$val" to %"QNCA_a0$float"*
+  call void @llvm.dbg.value(metadata %"QNCA_a0$float"* %.ascast, metadata !13, metadata !DIExpression(DW_OP_deref)), !dbg !27
+  call void @llvm.dbg.value(metadata %"QNCA_a0$float"* %.ascast, metadata !28, metadata !DIExpression(DW_OP_deref)), !dbg !42
+  call void @llvm.dbg.value(metadata [1000 x i32] addrspace(1)* %"ascastB$val", metadata !47, metadata !DIExpression(DW_OP_deref)), !dbg !51
+  call void @llvm.dbg.value(metadata i32 addrspace(1)* %0, metadata !54, metadata !DIExpression(DW_OP_deref)), !dbg !59
+  ret void
+}
+
+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.value(metadata, metadata, metadata) #1
+
+attributes #0 = { noinline nounwind }
+attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
+
+!llvm.module.flags = !{!0, !1}
+!llvm.dbg.cu = !{!2}
+!spirv.MemoryModel = !{!4}
+!opencl.enable.FP_CONTRACT = !{}
+!spirv.Source = !{!5}
+!opencl.spir.version = !{!6}
+!opencl.ocl.version = !{!6}
+!opencl.used.extensions = !{!7}
+!opencl.used.optional.core.features = !{!7}
+!spirv.Generator = !{!8}
+
+!0 = !{i32 7, !"Dwarf Version", i32 4}
+!1 = !{i32 2, !"Debug Info Version", i32 3}
+!2 = distinct !DICompileUnit(language: DW_LANG_OpenCL, file: !3, producer: "Fortran", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
+!3 = !DIFile(filename: "f.f90", directory: "Fortran")
+!4 = !{i32 2, i32 2}
+!5 = !{i32 4, i32 200000}
+!6 = !{i32 2, i32 0}
+!7 = !{}
+!8 = !{i16 6, i16 14}
+!9 = !{i32 0}
+!10 = !{!"none"}
+!11 = !{!"structtype"}
+!12 = !{!""}
+!13 = !DILocalVariable(name: "a", scope: !14, file: !3, line: 15, type: !18)
+!14 = distinct !DISubprogram(name: "random_fill_sp.DIR.OMP.TARGET.8.split.split.split.split", scope: null, file: !3, line: 25, type: !15, scopeLine: 25, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2, templateParams: !7, retainedNodes: !17)
+!15 = !DISubroutineType(types: !16)
+!16 = !{null}
+!17 = !{!13}
+!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
+!19 = !DICompositeType(tag: DW_TAG_array_type, baseType: !20, size: 32, elements: !21)
+!20 = !DIBasicType(name: "REAL*4", size: 32, encoding: DW_ATE_float)
+!21 = !{!22}
+!22 = !DISubrange(lowerBound: 1, upperBound: !23)
+!23 = !DILocalVariable(name: "A$1$upperbound", scope: !24, type: !26, flags: DIFlagArtificial)
+!24 = distinct !DISubprogram(name: "random_fill_sp", linkageName: "random_fill_sp", scope: null, file: !3, line: 15, type: !15, scopeLine: 15, spFlags: DISPFlagDefinition, unit: !2, templateParams: !7, retainedNodes: !25)
+!25 = !{!23}
+!26 = !DIBasicType(name: "INTEGER*8", size: 64, encoding: DW_ATE_signed)
+!27 = !DILocation(line: 15, column: 67, scope: !14)
+!28 = !DILocalVariable(name: "a", scope: !29, file: !3, line: 15, type: !33)
+!29 = distinct !DISubprogram(name: "random_fill_sp.DIR.OMP.TARGET.8.split.split.split.split", scope: null, file: !3, line: 25, type: !30, scopeLine: 25, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2, templateParams: !7, retainedNodes: !32)
+!30 = !DISubroutineType(types: !31)
+!31 = !{null}
+!32 = !{!28}
+!33 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !34, size: 64)
+!34 = !DICompositeType(tag: DW_TAG_array_type, baseType: !35, size: 32, elements: !36)
+!35 = !DIBasicType(name: "REAL*4", size: 32, encoding: DW_ATE_float)
+!36 = !{!37}
+!37 = !DISubrange(lowerBound: !DIExpression(), upperBound: !DIExpression())
+!38 = !DILocalVariable(name: "A$1$upperbound", scope: !39, type: !41, flags: DIFlagArtificial)
+!39 = distinct !DISubprogram(name: "random_fill_sp", linkageName: "random_fill_sp", scope: null, file: !3, line: 15, type: !30, scopeLine: 15, spFlags: DISPFlagDefinition, unit: !2, templateParams: !7, retainedNodes: !40)
+!40 = !{!38}
+!41 = !DIBasicType(name: "INTEGER*8", size: 64, encoding: DW_ATE_signed)
+!42 = !DILocation(line: 15, column: 67, scope: !29)
+!43 = !DIBasicType(name: "INTEGER*4", size: 32, encoding: DW_ATE_signed)
+!44 = !{}
+!45 = !DISubroutineType(types: !44)
+!46 = distinct !DISubprogram(name: "test_target_map_array_default_IP_test_array_map_no_map_type_.DIR.OMP.TARGET.340.split", scope: !3, file: !3, line: 32, type: !45, scopeLine: 32, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2)
+!47 = !DILocalVariable(name: "compute_array", scope: !46, file: !3, line: 27, type: !48)
+!48 = !DICompositeType(tag: DW_TAG_array_type, baseType: !43, elements: !49)
+!49 = !{!50}
+!50 = !DISubrange(count: 1000, lowerBound: 1)
+!51 = !DILocation(line: 27, column: 24, scope: !46)
+!52 = distinct !DISubprogram(name: "test", scope: !3, file: !3, line: 51, type: !53, scopeLine: 51, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2)
+!53 = !DISubroutineType(types: !7)
+!54 = !DILocalVariable(name: "isHost", scope: !52, file: !3, line: 34, type: !55)
+!55 = !DICompositeType(tag: DW_TAG_array_type, baseType: !56, elements: !57)
+!56 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!57 = !{!58}
+!58 = !DISubrange(count: -1)
+!59 = !DILocation(line: 34, column: 33, scope: !52)
index cbc775390b5e3d76ca8c55bc310048aec2cb7d88..60254ac47a21c1d51ae3ef178d3e00eb3c797023 100644 (file)
@@ -225,7 +225,14 @@ static cl::opt<SPIRV::DebugInfoEIS> DebugEIS(
         clEnumValN(SPIRV::DebugInfoEIS::OpenCL_DebugInfo_100, "ocl-100",
                    "Emit debug info compliant with the OpenCL.DebugInfo.100 "
                    "extended instruction set. This version of SPIR-V debug "
-                   "info format is compatible with the SPIRV-Tools")));
+                   "info format is compatible with the SPIRV-Tools"),
+        clEnumValN(
+            SPIRV::DebugInfoEIS::NonSemantic_Kernel_DebugInfo_100,
+            "nonsemantic-kernel-100",
+            "Emit debug info compliant with the "
+            "NonSemantic.Kernel.DebugInfo.100 extended instruction set. This "
+            "version of SPIR-V debug info format is compatible with the rules "
+            "regarding non-semantic instruction sets.")));
 
 static cl::opt<bool> SPIRVReplaceLLVMFmulAddWithOpenCLMad(
     "spirv-replace-fmuladd-with-ocl-mad",
@@ -715,6 +722,9 @@ int main(int Ac, char **Av) {
                 "affects translation from LLVM IR to SPIR-V";
     } else {
       Opts.setDebugInfoEIS(DebugEIS);
+      if (DebugEIS.getValue() ==
+          SPIRV::DebugInfoEIS::NonSemantic_Kernel_DebugInfo_100)
+        Opts.setAllowExtraDIExpressionsEnabled(true);
     }
   }