@@ -75,16 +75,17 @@ void SPIRVToLLVMDbgTran::addDbgInfoVersion() {
7575 DEBUG_METADATA_VERSION);
7676}
7777
78- DIFile *SPIRVToLLVMDbgTran::getDIFile (
79- const std::string &FileName,
80- std::optional<DIFile::ChecksumInfo<StringRef>> CS) {
78+ DIFile *
79+ SPIRVToLLVMDbgTran::getDIFile (const std::string &FileName,
80+ std::optional<DIFile::ChecksumInfo<StringRef>> CS,
81+ std::optional<StringRef> Source) {
8182 return getOrInsert (FileMap, FileName, [=]() {
8283 SplitFileName Split (FileName);
8384 // Use the first builder from the map to crete DIFile since it's
8485 // relations with other debug metadata is not going through DICompileUnit
8586 if (!Split.BaseName .empty ())
8687 return BuilderMap.begin ()->second ->createFile (Split.BaseName , Split.Path ,
87- CS);
88+ CS, Source );
8889 return static_cast <DIFile *>(nullptr );
8990 });
9091}
@@ -134,6 +135,19 @@ const std::string &SPIRVToLLVMDbgTran::getString(const SPIRVId Id) {
134135 return String->getStr ();
135136}
136137
138+ const std::string
139+ SPIRVToLLVMDbgTran::getStringContinued (const SPIRVId Id,
140+ SPIRVExtInst *DebugInst) {
141+ std::string Str = BM->get <SPIRVString>(Id)->getStr ();
142+ using namespace SPIRVDebug ::Operand::SourceContinued;
143+ for (auto *I : DebugInst->getContinuedInstructions ()) {
144+ std::string TmpStr =
145+ BM->get <SPIRVString>(I->getArguments ()[TextIdx])->getStr ();
146+ Str.append (TmpStr);
147+ }
148+ return Str;
149+ }
150+
137151void SPIRVToLLVMDbgTran::transDbgInfo (const SPIRVValue *SV, Value *V) {
138152 // A constant sampler does not have a corresponding SPIRVInstruction.
139153 if (SV->getOpCode () == OpConstantSampler)
@@ -1327,6 +1341,7 @@ MDNode *SPIRVToLLVMDbgTran::transDebugInstImpl(const SPIRVExtInst *DebugInst) {
13271341
13281342 case SPIRVDebug::Operation: // To be translated with transExpression
13291343 case SPIRVDebug::Source: // To be used by other instructions
1344+ case SPIRVDebug::SourceContinued:
13301345 return nullptr ;
13311346
13321347 case SPIRVDebug::Expression:
@@ -1458,12 +1473,21 @@ DIFile *SPIRVToLLVMDbgTran::getFile(const SPIRVId SourceId) {
14581473 assert (Source->getExtOp () == SPIRVDebug::Source &&
14591474 " DebugSource instruction is expected" );
14601475 SPIRVWordVec SourceArgs = Source->getArguments ();
1461- assert (SourceArgs.size () == OperandCount && " Invalid number of operands" );
1462- std::string ChecksumStr =
1463- getDbgInst<SPIRVDebug::DebugInfoNone>(SourceArgs[TextIdx])
1464- ? " "
1465- : getString (SourceArgs[TextIdx]);
1466- return getDIFile (getString (SourceArgs[FileIdx]), ParseChecksum (ChecksumStr));
1476+ assert (SourceArgs.size () >= MinOperandCount && " Invalid number of operands" );
1477+ if (SourceArgs.size () == MinOperandCount)
1478+ return getDIFile (getString (SourceArgs[FileIdx]));
1479+
1480+ if (!isNonSemanticDebugInfo (Source->getExtSetKind ())) {
1481+ std::string ChecksumStr =
1482+ getDbgInst<SPIRVDebug::DebugInfoNone>(SourceArgs[TextIdx])
1483+ ? " "
1484+ : getString (SourceArgs[TextIdx]);
1485+ return getDIFile (getString (SourceArgs[FileIdx]),
1486+ ParseChecksum (ChecksumStr));
1487+ }
1488+
1489+ return getDIFile (getString (SourceArgs[FileIdx]), std::nullopt ,
1490+ getStringContinued (SourceArgs[TextIdx], Source));
14671491}
14681492
14691493DIBuilder &SPIRVToLLVMDbgTran::getDIBuilder (const SPIRVExtInst *DebugInst) {
0 commit comments