[PATCH 60/79] Implement DebugLine and DebugNoLine (#2012)
authorLU-JOHN <111294400+LU-JOHN@users.noreply.github.com>
Fri, 9 Jun 2023 12:05:17 +0000 (07:05 -0500)
committerAndreas Beckmann <anbe@debian.org>
Thu, 14 Mar 2024 19:01:08 +0000 (20:01 +0100)
Implement DebugLine/DebugNoLine for NonSemantic.Shader.DebugInfo.100 and NonSemantic.Shader.DebugInfo.200.
Updated test/DebugInfo/NonSemantic/Shader200/DebugInfoStringType.ll to test these changes.

Gbp-Pq: Name 0060-Implement-DebugLine-and-DebugNoLine-2012.patch

14 files changed:
lib/SPIRV/LLVMToSPIRVDbgTran.cpp
lib/SPIRV/SPIRVToLLVMDbgTran.cpp
lib/SPIRV/libSPIRV/SPIRV.debug.h
lib/SPIRV/libSPIRV/SPIRVEntry.cpp
lib/SPIRV/libSPIRV/SPIRVEntry.h
lib/SPIRV/libSPIRV/SPIRVExtInst.h
lib/SPIRV/libSPIRV/SPIRVFunction.cpp
lib/SPIRV/libSPIRV/SPIRVModule.cpp
lib/SPIRV/libSPIRV/SPIRVModule.h
lib/SPIRV/libSPIRV/SPIRVStream.cpp
test/DebugInfo/NonSemantic/Shader200/DebugInfoStringType.ll
test/DebugInfo/NonSemantic/Shader200/DebugInfoSubrange.ll
test/DebugInfo/NonSemantic/Shader200/DebugInfoTargetFunction.ll
test/DebugInfo/NonSemantic/Shader200/DebugLinePriority.spt [new file with mode: 0644]

index 757fd8ed831927afcb5463735b67db7b517ede01..d3daa263e04907ba0b2e986bbb070820a201b15e 100644 (file)
@@ -233,8 +233,16 @@ void LLVMToSPIRVDbgTran::transLocationInfo() {
               V = VPrev;
             }
           }
-          BM->addLine(V, File ? File->getId() : getDebugInfoNone()->getId(),
-                      LineNo, Col);
+          if (BM->getDebugInfoEIS() ==
+                  SPIRVEIS_NonSemantic_Shader_DebugInfo_100 ||
+              BM->getDebugInfoEIS() ==
+                  SPIRVEIS_NonSemantic_Shader_DebugInfo_200)
+            BM->addDebugLine(V, getVoidTy(),
+                             File ? File->getId() : getDebugInfoNoneId(),
+                             LineNo, LineNo, Col, Col + 1);
+          else
+            BM->addLine(V, File ? File->getId() : getDebugInfoNoneId(), LineNo,
+                        Col);
         }
       } // Instructions
     }   // Basic Blocks
index 42d6924f8d768bbd4894381e4c9cf103bf8ae4b4..6fffc4b176efcaa7ffa80d3acf4151ae5d35c878 100644 (file)
@@ -1513,7 +1513,16 @@ DebugLoc SPIRVToLLVMDbgTran::transDebugScope(const SPIRVInstruction *Inst) {
   unsigned Col = 0;
   MDNode *Scope = nullptr;
   MDNode *InlinedAt = nullptr;
-  if (auto L = Inst->getLine()) {
+
+  // If DebugLine and OpLine are both active give DebugLine priority
+  if (auto DL = Inst->getDebugLine()) {
+    using namespace SPIRVDebug::Operand::DebugLine;
+    SPIRVWordVec DebugLineArgs = DL->getArguments();
+    Line =
+        getConstantValueOrLiteral(DebugLineArgs, StartIdx, DL->getExtSetKind());
+    Col = getConstantValueOrLiteral(DebugLineArgs, ColumnStartIdx,
+                                    DL->getExtSetKind());
+  } else if (auto L = Inst->getLine()) {
     Line = L->getLine();
     Col = L->getColumn();
   }
index 723a0b140c2fbbd8ef195c615fbc96fede6f9f2b..4f3ce3780f983d7023305ad16fb515398056fd17 100644 (file)
@@ -57,6 +57,8 @@ enum Instruction {
   InstCount                     = 37,
   FunctionDefinition            = 101,
   SourceContinued               = 102,
+  DebugLine                     = 103,
+  DebugNoLine                   = 104,
   BuildIdentifier               = 105,
   StoragePath                   = 106,
   EntryPoint                    = 107,
@@ -627,6 +629,23 @@ enum {
 };
 }
 
+namespace DebugLine {
+enum {
+  SourceIdx      = 0,
+  StartIdx       = 1,
+  EndIdx         = 2,
+  ColumnStartIdx = 3,
+  ColumnEndIdx   = 4,
+  OperandCount   = 5
+};
+}
+
+namespace DebugNoLine {
+enum {
+  OperandCount = 0
+};
+}
+
 namespace EntryPoint {
 enum {
   EntryPointIdx        = 0,
index 919567a7cdd2a4e12973bf977f2358ba6780808e..5ee1081b65e7d5e2256c9f68702861edf9225fa6 100644 (file)
@@ -175,7 +175,7 @@ void SPIRVEntry::encodeLine(spv_ostream &O) const {
   if (!Module)
     return;
   const std::shared_ptr<const SPIRVLine> &CurrLine = Module->getCurrentLine();
-  if (Line && ((CurrLine && *Line != *CurrLine) || !CurrLine)) {
+  if (Line && (!CurrLine || *Line != *CurrLine)) {
     O << *Line;
     Module->setCurrentLine(Line);
   }
@@ -183,8 +183,43 @@ void SPIRVEntry::encodeLine(spv_ostream &O) const {
     Module->setCurrentLine(nullptr);
 }
 
+namespace {
+bool isDebugLineEqual(const SPIRVExtInst &DL1, const SPIRVExtInst &DL2) {
+  std::vector<SPIRVWord> DL1Args = DL1.getArguments();
+  std::vector<SPIRVWord> DL2Args = DL2.getArguments();
+
+  using namespace SPIRVDebug::Operand::DebugLine;
+  assert(DL1Args.size() == OperandCount && DL2Args.size() == OperandCount &&
+         "Invalid number of operands");
+  return DL1Args[SourceIdx] == DL2Args[SourceIdx] &&
+         DL1Args[StartIdx] == DL2Args[StartIdx] &&
+         DL1Args[EndIdx] == DL2Args[EndIdx] &&
+         DL1Args[ColumnStartIdx] == DL2Args[ColumnStartIdx] &&
+         DL1Args[ColumnEndIdx] == DL2Args[ColumnEndIdx];
+}
+} // namespace
+
+void SPIRVEntry::encodeDebugLine(spv_ostream &O) const {
+  if (!Module)
+    return;
+  const std::shared_ptr<const SPIRVExtInst> &CurrDebugLine =
+      Module->getCurrentDebugLine();
+  if (DebugLine &&
+      (!CurrDebugLine || !isDebugLineEqual(*DebugLine, *CurrDebugLine))) {
+    O << *DebugLine;
+    Module->setCurrentDebugLine(DebugLine);
+  }
+  if (isEndOfBlock() ||
+      isExtInst(SPIRVEIS_NonSemantic_Shader_DebugInfo_100,
+                SPIRVDebug::DebugNoLine) ||
+      isExtInst(SPIRVEIS_NonSemantic_Shader_DebugInfo_200,
+                SPIRVDebug::DebugNoLine))
+    Module->setCurrentDebugLine(nullptr);
+}
+
 void SPIRVEntry::encodeAll(spv_ostream &O) const {
   encodeLine(O);
+  encodeDebugLine(O);
   encodeWordCountOpCode(O);
   encode(O);
   encodeChildren(O);
@@ -301,6 +336,11 @@ void SPIRVEntry::setLine(const std::shared_ptr<const SPIRVLine> &L) {
   SPIRVDBG(if (L) spvdbgs() << "[setLine] " << *L << '\n';)
 }
 
+void SPIRVEntry::setDebugLine(const std::shared_ptr<const SPIRVExtInst> &DL) {
+  DebugLine = DL;
+  SPIRVDBG(if (DL) spvdbgs() << "[setDebugLine] " << *DL << '\n';)
+}
+
 void SPIRVEntry::addMemberDecorate(SPIRVMemberDecorate *Dec) {
   assert(canHaveMemberDecorates() &&
          MemberDecorates.find(Dec->getPair()) == MemberDecorates.end());
@@ -631,8 +671,6 @@ void SPIRVLine::encode(spv_ostream &O) const {
 
 void SPIRVLine::decode(std::istream &I) {
   getDecoder(I) >> FileName >> Line >> Column;
-  std::shared_ptr<const SPIRVLine> L(this);
-  Module->setCurrentLine(L);
 }
 
 void SPIRVLine::validate() const {
index b43cd892cb9f5847bc450efa463ae57c2a828c2a..f497c95dab97839b5def12ec3f39846371441225 100644 (file)
@@ -289,6 +289,7 @@ public:
     return Id;
   }
   std::shared_ptr<const SPIRVLine> getLine() const { return Line; }
+  std::shared_ptr<const SPIRVExtInst> getDebugLine() const { return DebugLine; }
   SPIRVLinkageTypeKind getLinkageType() const;
   Op getOpCode() const { return OpCode; }
   SPIRVModule *getModule() const { return Module; }
@@ -358,6 +359,7 @@ public:
   void setHasNoId() { Attrib |= SPIRVEA_NOID; }
   void setId(SPIRVId TheId) { Id = TheId; }
   void setLine(const std::shared_ptr<const SPIRVLine> &L);
+  void setDebugLine(const std::shared_ptr<const SPIRVExtInst> &DL);
   void setLinkageType(SPIRVLinkageTypeKind);
   void setModule(SPIRVModule *TheModule);
   void setName(const std::string &TheName);
@@ -384,6 +386,7 @@ public:
   friend spv_ostream &operator<<(spv_ostream &O, const SPIRVEntry &E);
   friend std::istream &operator>>(std::istream &I, SPIRVEntry &E);
   virtual void encodeLine(spv_ostream &O) const;
+  virtual void encodeDebugLine(spv_ostream &O) const;
   virtual void encodeAll(spv_ostream &O) const;
   virtual void encodeName(spv_ostream &O) const;
   virtual void encodeChildren(spv_ostream &O) const;
@@ -448,6 +451,7 @@ protected:
   DecorateIdMapType DecorateIds;
   MemberDecorateMapType MemberDecorates;
   std::shared_ptr<const SPIRVLine> Line;
+  std::shared_ptr<const SPIRVExtInst> DebugLine;
 };
 
 class SPIRVEntryNoIdGeneric : public SPIRVEntry {
index 315f73f03ed2f103bafb41cda4fa9436afceed4c..e278726f58c2b1baa83fdf85f24f4882805a3e2d 100644 (file)
@@ -262,6 +262,8 @@ template <> inline void SPIRVMap<SPIRVDebugExtOpKind, std::string>::init() {
   add(SPIRVDebug::Operation, "DebugOperation");
   add(SPIRVDebug::FunctionDefinition, "DebugFunctionDefinition");
   add(SPIRVDebug::SourceContinued, "DebugSourceContinued");
+  add(SPIRVDebug::DebugLine, "DebugLine");
+  add(SPIRVDebug::DebugNoLine, "DebugNoLine");
   add(SPIRVDebug::EntryPoint, "DebugEntryPoint");
   add(SPIRVDebug::BuildIdentifier, "DebugBuildIdentifier");
   add(SPIRVDebug::StoragePath, "DebugStoragePath");
index 8a339297c128c5f5e94e8572a874dbff37a4c09b..37698fa8fa7638146694afd903cdcfebf2a18285 100644 (file)
@@ -143,7 +143,8 @@ bool SPIRVFunction::decodeBB(SPIRVDecoder &Decoder) {
     SPIRVEntry *Entry = Decoder.getEntry();
 
     if (Decoder.OpCode == OpLine) {
-      Module->add(Entry);
+      std::shared_ptr<const SPIRVLine> L(static_cast<SPIRVLine *>(Entry));
+      Module->setCurrentLine(L);
       continue;
     }
 
@@ -159,6 +160,17 @@ bool SPIRVFunction::decodeBB(SPIRVDecoder &Decoder) {
     assert(Inst);
     if (Inst->getOpCode() == OpUndef) {
       Module->add(Inst);
+    } else if (Inst->isExtInst(SPIRVEIS_NonSemantic_Shader_DebugInfo_100,
+                               SPIRVDebug::DebugNoLine) ||
+               Inst->isExtInst(SPIRVEIS_NonSemantic_Shader_DebugInfo_200,
+                               SPIRVDebug::DebugNoLine)) {
+      continue;
+    } else if (Inst->isExtInst(SPIRVEIS_NonSemantic_Shader_DebugInfo_100,
+                               SPIRVDebug::DebugLine) ||
+               Inst->isExtInst(SPIRVEIS_NonSemantic_Shader_DebugInfo_200,
+                               SPIRVDebug::DebugLine)) {
+      std::shared_ptr<const SPIRVExtInst> DL(static_cast<SPIRVExtInst *>(Inst));
+      Module->setCurrentDebugLine(DL);
     } else {
       if (Inst->isExtInst(SPIRVEIS_Debug, SPIRVDebug::Scope) ||
           Inst->isExtInst(SPIRVEIS_OpenCL_DebugInfo_100, SPIRVDebug::Scope) ||
index dbfcd9f24de5e54501ab476a45857a6a85360452..df64f16749c5d8e018625cf94c19e4edfacd60f0 100644 (file)
@@ -186,6 +186,13 @@ public:
                SPIRVWord Column) override;
   const std::shared_ptr<const SPIRVLine> &getCurrentLine() const override;
   void setCurrentLine(const std::shared_ptr<const SPIRVLine> &Line) override;
+  void addDebugLine(SPIRVEntry *E, SPIRVType *TheType, SPIRVId FileNameId,
+                    SPIRVWord LineStart, SPIRVWord LineEnd,
+                    SPIRVWord ColumnStart, SPIRVWord ColumnEnd) override;
+  const std::shared_ptr<const SPIRVExtInst> &
+  getCurrentDebugLine() const override;
+  void setCurrentDebugLine(
+      const std::shared_ptr<const SPIRVExtInst> &DebugLine) override;
   void addCapability(SPIRVCapabilityKind) override;
   void addCapabilityInternal(SPIRVCapabilityKind) override;
   void addExtension(ExtensionID) override;
@@ -293,6 +300,8 @@ public:
                                const std::vector<SPIRVValue *> &,
                                SPIRVBasicBlock *,
                                SPIRVInstruction * = nullptr) override;
+  SPIRVEntry *createDebugInfo(SPIRVWord, SPIRVType *TheType,
+                              const std::vector<SPIRVWord> &) override;
   SPIRVEntry *addDebugInfo(SPIRVWord, SPIRVType *TheType,
                            const std::vector<SPIRVWord> &) override;
   SPIRVEntry *addModuleProcessed(const std::string &) override;
@@ -506,6 +515,7 @@ private:
   SPIRVStringVec StringVec;
   SPIRVMemberNameVec MemberNameVec;
   std::shared_ptr<const SPIRVLine> CurrentLine;
+  std::shared_ptr<const SPIRVExtInst> CurrentDebugLine;
   SPIRVDecorateVec DecorateVec;
   SPIRVDecGroupVec DecGroupVec;
   SPIRVGroupDecVec GroupDecVec;
@@ -558,6 +568,60 @@ void SPIRVModuleImpl::addLine(SPIRVEntry *E, SPIRVId FileNameId, SPIRVWord Line,
   E->setLine(CurrentLine);
 }
 
+const std::shared_ptr<const SPIRVExtInst> &
+SPIRVModuleImpl::getCurrentDebugLine() const {
+  return CurrentDebugLine;
+}
+
+void SPIRVModuleImpl::setCurrentDebugLine(
+    const std::shared_ptr<const SPIRVExtInst> &DebugLine) {
+  CurrentDebugLine = DebugLine;
+}
+
+namespace {
+bool isDebugLineEqual(const SPIRVExtInst &CurrentDebugLine, SPIRVId FileNameId,
+                      SPIRVId LineStartId, SPIRVId LineEndId,
+                      SPIRVId ColumnStartId, SPIRVId ColumnEndId) {
+  assert(CurrentDebugLine.getExtOp() == SPIRVDebug::DebugLine);
+  const std::vector<SPIRVWord> CurrentDebugLineArgs =
+      CurrentDebugLine.getArguments();
+
+  using namespace SPIRVDebug::Operand::DebugLine;
+  return CurrentDebugLineArgs[SourceIdx] == FileNameId &&
+         CurrentDebugLineArgs[StartIdx] == LineStartId &&
+         CurrentDebugLineArgs[EndIdx] == LineEndId &&
+         CurrentDebugLineArgs[ColumnStartIdx] == ColumnStartId &&
+         CurrentDebugLineArgs[ColumnEndIdx] == ColumnEndId;
+}
+} // namespace
+
+void SPIRVModuleImpl::addDebugLine(SPIRVEntry *E, SPIRVType *TheType,
+                                   SPIRVId FileNameId, SPIRVWord LineStart,
+                                   SPIRVWord LineEnd, SPIRVWord ColumnStart,
+                                   SPIRVWord ColumnEnd) {
+  if (!(CurrentDebugLine &&
+        isDebugLineEqual(*CurrentDebugLine, FileNameId,
+                         getLiteralAsConstant(LineStart)->getId(),
+                         getLiteralAsConstant(LineEnd)->getId(),
+                         getLiteralAsConstant(ColumnStart)->getId(),
+                         getLiteralAsConstant(ColumnEnd)->getId()))) {
+    using namespace SPIRVDebug::Operand::DebugLine;
+
+    std::vector<SPIRVWord> DebugLineOps(OperandCount);
+    DebugLineOps[SourceIdx] = FileNameId;
+    DebugLineOps[StartIdx] = getLiteralAsConstant(LineStart)->getId();
+    DebugLineOps[EndIdx] = getLiteralAsConstant(LineEnd)->getId();
+    DebugLineOps[ColumnStartIdx] = getLiteralAsConstant(ColumnStart)->getId();
+    DebugLineOps[ColumnEndIdx] = getLiteralAsConstant(ColumnEnd)->getId();
+
+    CurrentDebugLine.reset(static_cast<SPIRVExtInst *>(
+        createDebugInfo(SPIRVDebug::DebugLine, TheType, DebugLineOps)));
+  }
+
+  assert(E && "invalid entry");
+  E->setDebugLine(CurrentDebugLine);
+}
+
 SPIRVValue *SPIRVModuleImpl::addSamplerConstant(SPIRVType *TheType,
                                                 SPIRVWord AddrMode,
                                                 SPIRVWord ParametricMode,
@@ -1298,11 +1362,16 @@ SPIRVInstruction *SPIRVModuleImpl::addExtInst(
       InsertBefore);
 }
 
+SPIRVEntry *
+SPIRVModuleImpl::createDebugInfo(SPIRVWord InstId, SPIRVType *TheType,
+                                 const std::vector<SPIRVWord> &Args) {
+  return new SPIRVExtInst(this, getId(), TheType, SPIRVEIS_OpenCL_DebugInfo_100,
+                          ExtInstSetIds[getDebugInfoEIS()], InstId, Args);
+}
+
 SPIRVEntry *SPIRVModuleImpl::addDebugInfo(SPIRVWord InstId, SPIRVType *TheType,
                                           const std::vector<SPIRVWord> &Args) {
-  return addEntry(
-      new SPIRVExtInst(this, getId(), TheType, SPIRVEIS_OpenCL_DebugInfo_100,
-                       ExtInstSetIds[getDebugInfoEIS()], InstId, Args));
+  return addEntry(createDebugInfo(InstId, TheType, Args));
 }
 
 SPIRVEntry *SPIRVModuleImpl::addModuleProcessed(const std::string &Process) {
@@ -1825,6 +1894,7 @@ spv_ostream &operator<<(spv_ostream &O, SPIRVModule &M) {
   SPIRVModuleImpl &MI = *static_cast<SPIRVModuleImpl *>(&M);
   // Start tracking of the current line with no line
   MI.CurrentLine.reset();
+  MI.CurrentDebugLine.reset();
 
   SPIRVEncoder Encoder(O);
   Encoder << MagicNumber << MI.SPIRVVersion
index 0241f9145a52c6aae63e39b34c998bdd24043451..b7a09cfd5ecccb159640873cccd5438172912581 100644 (file)
@@ -198,6 +198,14 @@ public:
                        SPIRVWord Column) = 0;
   virtual const std::shared_ptr<const SPIRVLine> &getCurrentLine() const = 0;
   virtual void setCurrentLine(const std::shared_ptr<const SPIRVLine> &) = 0;
+  virtual void addDebugLine(SPIRVEntry *E, SPIRVType *TheType,
+                            SPIRVId FileNameId, SPIRVWord LineStart,
+                            SPIRVWord LineEnd, SPIRVWord ColumnStart,
+                            SPIRVWord ColumnEnd) = 0;
+  virtual const std::shared_ptr<const SPIRVExtInst> &
+  getCurrentDebugLine() const = 0;
+  virtual void
+  setCurrentDebugLine(const std::shared_ptr<const SPIRVExtInst> &) = 0;
   virtual const SPIRVDecorateGeneric *addDecorate(SPIRVDecorateGeneric *) = 0;
   virtual SPIRVDecorationGroup *addDecorationGroup() = 0;
   virtual SPIRVDecorationGroup *
@@ -307,6 +315,8 @@ public:
                                        const std::vector<SPIRVValue *> &,
                                        SPIRVBasicBlock *,
                                        SPIRVInstruction * = nullptr) = 0;
+  virtual SPIRVEntry *createDebugInfo(SPIRVWord, SPIRVType *,
+                                      const std::vector<SPIRVWord> &) = 0;
   virtual SPIRVEntry *addDebugInfo(SPIRVWord, SPIRVType *,
                                    const std::vector<SPIRVWord> &) = 0;
   virtual SPIRVEntry *addModuleProcessed(const std::string &) = 0;
index 18fef3dad147b924124dfa82db4bea12d805baa8..b30dbe2f3439f7c83888c5960a7deb1a43c2950e 100644 (file)
@@ -245,9 +245,21 @@ SPIRVEntry *SPIRVDecoder::getEntry() {
   Entry->setWordCount(WordCount);
   if (OpCode != OpLine)
     Entry->setLine(M.getCurrentLine());
+  if (!Entry->isExtInst(SPIRVEIS_NonSemantic_Shader_DebugInfo_100,
+                        SPIRVDebug::DebugLine) &&
+      !Entry->isExtInst(SPIRVEIS_NonSemantic_Shader_DebugInfo_200,
+                        SPIRVDebug::DebugLine))
+    Entry->setDebugLine(M.getCurrentDebugLine());
+
   IS >> *Entry;
   if (Entry->isEndOfBlock() || OpCode == OpNoLine)
     M.setCurrentLine(nullptr);
+  if (Entry->isEndOfBlock() ||
+      Entry->isExtInst(SPIRVEIS_NonSemantic_Shader_DebugInfo_100,
+                       SPIRVDebug::DebugNoLine) ||
+      Entry->isExtInst(SPIRVEIS_NonSemantic_Shader_DebugInfo_200,
+                       SPIRVDebug::DebugNoLine))
+    M.setCurrentDebugLine(nullptr);
 
   if (OpExtension == OpCode) {
     auto *OpExt = static_cast<SPIRVExtension *>(Entry);
index 7b82c1dfe051e06af0e7cc55ed04b9d0e6b26a77..5506128a6d702d6868df3c1218522ec4d4f6b1f8 100644 (file)
 ; CHECK-SPIRV: String [[#StrChar2:]] "CHARACTER_2"
 ; CHECK-SPIRV: String [[#StrChar3:]] "CHARACTER_3"
 ; CHECK-SPIRV: TypeInt [[#TypeInt:]] 32 0
-; CHECK-SPIRV: Constant [[#TypeInt]] [[#ConstZero:]] 0
-; CHECK-SPIRV: Constant [[#TypeInt]] [[#Const80:]] 80
+; CHECK-SPIRV-DAG: Constant [[#TypeInt]] [[#ConstZero:]] 0{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TypeInt]] [[#Const1:]] 1{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TypeInt]] [[#Const2:]] 2{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TypeInt]] [[#Const6:]] 6{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TypeInt]] [[#Const7:]] 7{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TypeInt]] [[#Const9:]] 9{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TypeInt]] [[#Const12:]] 12{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TypeInt]] [[#Const23:]] 23{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TypeInt]] [[#Const24:]] 24{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TypeInt]] [[#Const27:]] 27{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TypeInt]] [[#Const28:]] 28{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TypeInt]] [[#Const36:]] 36{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TypeInt]] [[#Const37:]] 37{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TypeInt]] [[#Const80:]] 80{{[[:space:]]}}
 ; CHECK-SPIRV: TypeVoid [[#TypeVoid:]]
 
 ; CHECK-SPIRV: [[#DINoneId:]] [[#EISId]] DebugInfoNone
 ; CHECK-SPIRV-COUNT-4: [[#LengthAddrVar2:]] [[#EISId]] DebugLocalVariable
 ; CHECK-SPIRV-NEXT: [[#EISId]] DebugTypeString [[#StrChar2]] [[#DINoneId]] [[#DINoneId]] [[#ConstZero]] [[#LengthAddrVar2]]
 
-; CHECK-LLVM: !DICompileUnit(language: DW_LANG_Fortran95
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Const6]] [[#Const6]] [[#Const23]] [[#Const24]]
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#ConstZero]] [[#ConstZero]] [[#ConstZero]] [[#Const1]]
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Const9]] [[#Const9]] [[#Const27]] [[#Const28]]
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Const9]] [[#Const9]] [[#Const36]] [[#Const37]]
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Const7]] [[#Const7]] [[#Const1]] [[#Const2]]
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#ConstZero]] [[#ConstZero]] [[#ConstZero]] [[#Const1]]
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Const9]] [[#Const9]] [[#Const27]] [[#Const28]]
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Const9]] [[#Const9]] [[#Const36]] [[#Const37]]
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Const12]] [[#Const12]] [[#Const1]] [[#Const2]]
+
+; CHECK-LLVM-DAG: !DICompileUnit(language: DW_LANG_Fortran95
+; CHECK-LLVM-DAG: ![[#Scope_hello_world:]] = distinct !DISubprogram(name: "hello_world", linkageName: "MAIN__"
+; CHECK-LLVM-DAG: !DILocation(line: 6, column: 23, scope: ![[#Scope_hello_world]]
 ; CHECK-LLVM-DAG: !DIStringType(name: "CHARACTER_1", size: 80)
 ; CHECK-LLVM-DAG: !DIStringType(name: ".str.GREETING", stringLengthExpression: !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 8), stringLocationExpression: !DIExpression(DW_OP_push_object_address, DW_OP_deref))
-; CHECK-LLVM-DAG: ![[#Scope:]] = distinct !DISubprogram(name: "print_greeting", linkageName: "print_greeting_"
-; CHECK-LLVM-DAG: ![[#StrLenMD:]] = !DILocalVariable(name: "STRING1.len", scope: ![[#Scope]]
+; CHECK-LLVM-DAG: ![[#Scope_print_greeting:]] = distinct !DISubprogram(name: "print_greeting", linkageName: "print_greeting_"
+; CHECK-LLVM-DAG: ![[#StrLenMD:]] = !DILocalVariable(name: "STRING1.len", scope: ![[#Scope_print_greeting]]
 ; CHECK-LLVM-DAG: !DIStringType(name: "CHARACTER_2", stringLength: ![[#StrLenMD]])
-; CHECK-LLVM-DAG: ![[#StrLenMD1:]] = !DILocalVariable(name: "STRING2.len", scope: ![[#Scope]]
+; CHECK-LLVM-DAG: ![[#StrLenMD1:]] = !DILocalVariable(name: "STRING2.len", scope: ![[#Scope_print_greeting]]
 ; CHECK-LLVM-DAG: !DIStringType(name: "CHARACTER_3", stringLength: ![[#StrLenMD1]])
+; CHECK-LLVM: !DILocation(line: 9, column: 27, scope: ![[#Scope_print_greeting]]
+; CHECK-LLVM-NEXT: !DILocation(line: 9, column: 36, scope: ![[#Scope_print_greeting]]
+; CHECK-LLVM-NEXT: !DILocation(line: 7, column: 1, scope: ![[#Scope_hello_world]]
+; CHECK-LLVM-NEXT: !DILocation(line: 0, scope: ![[#Scope_print_greeting]]
+; CHECK-LLVM-NEXT: !DILocation(line: 9, column: 27, scope: ![[#Scope_print_greeting]]
+; CHECK-LLVM-NEXT: !DILocation(line: 9, column: 36, scope: ![[#Scope_print_greeting]]
+; CHECK-LLVM-NEXT: !DILocation(line: 12, column: 1, scope: ![[#Scope_print_greeting]]
 
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "spir64-unknown-unknown"
index 3bb29f080cc4c5af578784e94d233165897675b6..f3317e088b6cbe5dd32bd537930d4c469353c915 100644 (file)
 ; CHECK-SPIRV: ExtInstImport [[#EISId:]] "NonSemantic.Shader.DebugInfo.200"
 
 ; CHECK-SPIRV: String [[#LocalVarNameId:]] "A$1$upperbound"
-; CHECK-SPIRV: TypeInt [[#TyInt64Id:]] 64 0
+; CHECK-SPIRV-DAG: TypeInt [[#TyInt32Id:]] 32 0
+; CHECK-SPIRV-DAG: TypeInt [[#TyInt64Id:]] 64 0
+; CHECK-NOT: THIS LINE IS USED TO SEPARATE DAGs
+; CHECK-SPIRV-DAG: Constant [[#TyInt32Id]] [[#Constant15Id:]] 15{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TyInt32Id]] [[#Constant24Id:]] 24{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TyInt32Id]] [[#Constant25Id:]] 25{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TyInt32Id]] [[#Constant27Id:]] 27{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TyInt32Id]] [[#Constant33Id:]] 33{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TyInt32Id]] [[#Constant34Id:]] 34{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TyInt32Id]] [[#Constant67Id:]] 67{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TyInt32Id]] [[#Constant68Id:]] 68{{[[:space:]]}}
 ; CHECK-SPIRV-DAG: Constant [[#TyInt64Id]] [[#Constant1Id:]] 1 0
 ; CHECK-SPIRV-DAG: Constant [[#TyInt64Id]] [[#Constant1000Id:]] 1000 0
 ; CHECK-SPIRV: [[#DINoneId:]] [[#EISId]] DebugInfoNone
 
 ; CHECK-SPIRV: [[#EISId]] DebugTypeSubrange [[#Constant1000Id]] [[#Constant1Id]] [[#DINoneId]] [[#DINoneId]]
 
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Constant15Id]] [[#Constant15Id]] [[#Constant67Id]] [[#Constant68Id]]
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Constant27Id]] [[#Constant27Id]] [[#Constant24Id]] [[#Constant25Id]]
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Constant34Id]] [[#Constant34Id]] [[#Constant33Id]] [[#Constant34Id]]
+
+; CHECK-LLVM: ![[#Scope_A:]] = distinct !DISubprogram(name: "random_fill_sp.DIR.OMP.TARGET.8.split.split.split.split"
 ; CHECK-LLVM: [[#Subrange1:]] = !DISubrange(lowerBound: 1, upperBound: ![[#UpperBound:]])
 ; CHECK-LLVM: [[#UpperBound]] = !DILocalVariable(name: "A$1$upperbound"
+; CHECK-LLVM: !DILocation(line: 15, column: 67, scope: ![[#Scope_A]]
+; CHECK-LLVM: ![[#Scope_B:]] = distinct !DISubprogram(name: "random_fill_sp.DIR.OMP.TARGET.8.split.split.split.split"
 ; CHECK-LLVM: !DISubrange(lowerBound: !DIExpression(), upperBound: !DIExpression())
+; CHECK-LLVM: !DILocation(line: 15, column: 67, scope: ![[#Scope_B]]
+; CHECK-LLVM: ![[#Scope_C:]] = distinct !DISubprogram(name: "test_target_map_array_default_IP_test_array_map_no_map_type_.DIR.OMP.TARGET.340.split"
 ; CHECK-LLVM: !DISubrange(count: 1000, lowerBound: 1)
+; CHECK-LLVM: !DILocation(line: 27, column: 24, scope: ![[#Scope_C]]
+; CHECK-LLVM: ![[#Scope_D:]] = distinct !DISubprogram(name: "test"
+; CHECK-LLVM: !DILocation(line: 34, column: 33, scope: ![[#Scope_D]]
 
 ; 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"
index 074305afbee84df5b58fdb8db29966f740c58329..d2980cdf47e498c26c23014f02ac9d32cf063a3b 100644 (file)
 ; CHECK-SPIRV-DAG: String [[#Func:]] "foo_wrapper"
 ; CHECK-SPIRV-DAG: String [[#TargetFunc:]] "_Z3foov"
 
+; CHECK-SPIRV-DAG: TypeInt [[#TyInt32Id:]] 32 0
+; CHECK-SPIRV-DAG: Constant [[#TyInt32Id]] [[#Constant1Id:]] 1{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TyInt32Id]] [[#Constant2Id:]] 2{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TyInt32Id]] [[#Constant4Id:]] 4{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TyInt32Id]] [[#Constant5Id:]] 5{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TyInt32Id]] [[#Constant6Id:]] 6{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TyInt32Id]] [[#Constant8Id:]] 8{{[[:space:]]}}
+; CHECK-SPIRV-DAG: Constant [[#TyInt32Id]] [[#Constant9Id:]] 9{{[[:space:]]}}
+
 ; CHECK-SPIRV-DAG: ExtInst [[#]] [[#DebugNone:]] [[#]] DebugInfoNone
 ; CHECK-SPIRV-DAG: ExtInst [[#]] [[#]] [[#]] DebugFunction [[#Func]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#DebugNone]] [[#TargetFunc]]
 
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Constant4Id]] [[#Constant4Id]] [[#Constant5Id]] [[#Constant6Id]]
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Constant5Id]] [[#Constant5Id]] [[#Constant1Id]] [[#Constant2Id]]
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Constant8Id]] [[#Constant8Id]] [[#Constant5Id]] [[#Constant6Id]]
+; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Constant9Id]] [[#Constant9Id]] [[#Constant1Id]] [[#Constant2Id]]
+
 ; CHECK-LLVM: define spir_func void @_Z11foo_wrapperv() {{.*}} !dbg ![[#DbgSubProg:]] {
-; CHECK-LLVM: ![[#DbgSubProg]] = distinct !DISubprogram(name: "foo_wrapper", linkageName: "_Z11foo_wrapperv", scope: null, file: ![[#]], line: 3, type: ![[#]], scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: ![[#]], templateParams: ![[#]], retainedNodes: ![[#]], targetFuncName: "_Z3foov")
+; CHECK-LLVM: ![[#Scope_foo_wrapper:]] = distinct !DISubprogram(name: "foo_wrapper", linkageName: "_Z11foo_wrapperv", scope: null, file: ![[#]], line: 3, type: ![[#]], scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: ![[#]], templateParams: ![[#]], retainedNodes: ![[#]], targetFuncName: "_Z3foov")
+; CHECK-LLVM: !DILocation(line: 4, column: 5, scope: ![[#Scope_foo_wrapper]]
+; CHECK-LLVM: !DILocation(line: 5, column: 1, scope: ![[#Scope_foo_wrapper]]
+; CHECK-LLVM: ![[#Scope_boo:]] = distinct !DISubprogram(name: "boo", linkageName: "_Z3boov"
+; CHECK-LLVM: !DILocation(line: 8, column: 5, scope: ![[#Scope_boo]]
+; CHECK-LLVM: !DILocation(line: 9, column: 1, scope: ![[#Scope_boo]]
 
 ; ModuleID = 'example.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"
diff --git a/test/DebugInfo/NonSemantic/Shader200/DebugLinePriority.spt b/test/DebugInfo/NonSemantic/Shader200/DebugLinePriority.spt
new file mode 100644 (file)
index 0000000..55ed4a9
--- /dev/null
@@ -0,0 +1,89 @@
+; RUN: llvm-spirv -to-binary %s -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-LLVM: %[[#Var:]] = load i32, i32* @_ZN5Outer5Inner6globalE, align 4, !dbg ![[#LineLoc:]]
+; CHECK-LLVM: %inc = add nsw i32 %[[#Var]], 1, !dbg ![[#DebugLineLoc:]]
+; CHECK-LLVM: ![[#LineLoc]] = !DILocation(line: 357, column: 113, scope: ![[#Scope:]])
+; CHECK-LLVM: ![[#DebugLineLoc]] = !DILocation(line: 8, column: 16, scope: ![[#Scope]])
+
+119734787 66560 393230 54 0 
+2 Capability Addresses 
+2 Capability Linkage 
+2 Capability Kernel 
+8 Extension "SPV_KHR_non_semantic_info" 
+5 ExtInstImport 1 "OpenCL.std" 
+11 ExtInstImport 2 "NonSemantic.Shader.DebugInfo.200" 
+3 MemoryModel 2 2 
+10 String 14 "/path/to/inlined-namespace.cxx" 
+3 String 16 "0" 
+3 String 18 "" 
+4 String 23 "clang" 
+3 String 25 "int" 
+3 String 30 "foo" 
+4 String 31 "_Z3foov" 
+4 String 37 "Outer" 
+4 String 41 "Inner" 
+4 String 44 "global" 
+8 String 45 "_ZN5Outer5Inner6globalE" 
+3 Source 0 0 
+8 Name 6 "_ZN5Outer5Inner6globalE" 
+4 Name 9 "_Z3foov" 
+4 Name 10 "entry" 
+3 Name 13 "inc" 
+10 Decorate 6 LinkageAttributes "_ZN5Outer5Inner6globalE" Export 
+4 Decorate 6 Alignment 4 
+6 Decorate 9 LinkageAttributes "_Z3foov" Export 
+3 Decorate 13 NoSignedWrap 
+4 TypeInt 3 32 0 
+4 Constant 3 5 0 
+4 Constant 3 12 1 
+4 Constant 3 20 65536 
+4 Constant 3 21 4 
+4 Constant 3 22 217 
+4 Constant 3 26 32 
+4 Constant 3 32 7 
+4 Constant 3 33 136 
+4 Constant 3 46 3 
+4 Constant 3 47 8 
+4 Constant 3 50 16 
+4 Constant 3 52 9 
+4 TypePointer 4 7 3 
+2 TypeVoid 7 
+3 TypeFunction 8 7 
+2 TypeBool 38 
+5 Variable 4 6 7 5 
+3 ConstantTrue 38 39 
+3 ConstantFalse 38 42 
+
+6 ExtInst 7 15 2 DebugSource 14 
+7 ExtInst 7 17 2 DebugBuildIdentifier 16 12 
+6 ExtInst 7 19 2 DebugStoragePath 18 
+10 ExtInst 7 24 2 DebugCompilationUnit 20 21 15 22 23 
+8 ExtInst 7 27 2 DebugTypeBasic 25 26 21 
+5 ExtInst 7 28 2 DebugInfoNone 
+7 ExtInst 7 29 2 DebugTypeFunction 5 28 
+15 ExtInst 7 34 2 DebugFunction 30 29 15 32 5 24 31 33 32 28 
+6 ExtInst 7 36 2 DebugSource 18 
+11 ExtInst 7 40 2 DebugLexicalBlock 36 5 5 24 37 39 
+11 ExtInst 7 43 2 DebugLexicalBlock 36 5 5 40 41 42 
+14 ExtInst 7 48 2 DebugGlobalVariable 44 27 15 46 5 43 45 6 47 
+
+5 Function 7 9 2 8 
+
+2 Label 10 
+7 ExtInst 7 35 2 DebugFunctionDefinition 34 9
+6 ExtInst 7 49 2 DebugScope 34
+4 Line 14 357 113
+6 Load 3 11 6 2 4
+10 ExtInst 7 51 2 DebugLine 14 47 47 50 33
+5 IAdd 3 13 11 12
+5 ExtInst 7 511 2 DebugNoLine
+5 ISub 3 137 11 12
+1 NoLine
+5 Store 6 13 2 4 
+1 Return 
+
+1 FunctionEnd 
+