@@ -217,6 +217,18 @@ SPIRVToLLVMDbgTran::transCompilationUnit(const SPIRVExtInst *DebugInst,
217
217
// TODO: Remove this workaround once we switch to NonSemantic.Shader.* debug
218
218
// info by default
219
219
auto Producer = findModuleProducer ();
220
+ assert (BuilderMap.size () != 0 && " No debug compile units" );
221
+ if (BuilderMap.size ()==1 )
222
+ // Only initialize once
223
+ setBuildIdentifierAndStoragePath ();
224
+
225
+ if (!StoragePath.empty ()) {
226
+ return BuilderMap[DebugInst->getId ()]->createCompileUnit (
227
+ SourceLang, getFile (Ops[SourceIdx]), Producer, false , " " , 0 ,
228
+ StoragePath, DICompileUnit::DebugEmissionKind::FullDebug,
229
+ BuildIdentifier);
230
+ }
231
+
220
232
return BuilderMap[DebugInst->getId ()]->createCompileUnit (
221
233
SourceLang, getFile (Ops[SourceIdx]), Producer, false , Flags, 0 );
222
234
}
@@ -398,8 +410,8 @@ SPIRVToLLVMDbgTran::transTypeArrayDynamic(const SPIRVExtInst *DebugInst) {
398
410
getDIBuilder (DebugInst).getOrCreateArray (Subscripts);
399
411
size_t Size = getDerivedSizeInBits (BaseTy) * TotalCount;
400
412
401
- auto TransOperand = [&](SPIRVWord Idx) -> PointerUnion<DIExpression *,
402
- DIVariable *> {
413
+ auto TransOperand =
414
+ [&](SPIRVWord Idx) -> PointerUnion<DIExpression *, DIVariable *> {
403
415
if (!getDbgInst<SPIRVDebug::DebugInfoNone>(Ops[Idx])) {
404
416
if (const auto *GV = getDbgInst<SPIRVDebug::GlobalVariable>(Ops[Idx]))
405
417
return transDebugInst<DIGlobalVariable>(GV);
@@ -1344,6 +1356,8 @@ MDNode *SPIRVToLLVMDbgTran::transDebugInstImpl(const SPIRVExtInst *DebugInst) {
1344
1356
case SPIRVDebug::Operation: // To be translated with transExpression
1345
1357
case SPIRVDebug::Source: // To be used by other instructions
1346
1358
case SPIRVDebug::SourceContinued:
1359
+ case SPIRVDebug::BuildIdentifier: // To be used by transCompilationUnit
1360
+ case SPIRVDebug::StoragePath: // To be used by transCompilationUnit
1347
1361
return nullptr ;
1348
1362
1349
1363
case SPIRVDebug::Expression:
@@ -1512,6 +1526,43 @@ DIFile *SPIRVToLLVMDbgTran::getFile(const SPIRVId SourceId) {
1512
1526
getStringSourceContinued (StrIdx, Source));
1513
1527
}
1514
1528
1529
+ void SPIRVToLLVMDbgTran::setBuildIdentifierAndStoragePath () {
1530
+ #ifndef NDEBUG
1531
+ bool FoundBuildIdentifier{false };
1532
+ bool FoundStoragePath{false };
1533
+ #endif
1534
+
1535
+ for (SPIRVExtInst *EI : BM->getDebugInstVec ()) {
1536
+ if (EI->getExtOp () == SPIRVDebug::BuildIdentifier) {
1537
+ using namespace SPIRVDebug ::Operand::BuildIdentifier;
1538
+ SPIRVWordVec BuildIdentifierArgs = EI->getArguments ();
1539
+ assert (BuildIdentifierArgs.size () == OperandCount &&
1540
+ " Invalid number of operands" );
1541
+ assert (!FoundBuildIdentifier &&
1542
+ " More than one BuildIdentifier instruction not allowed" );
1543
+ BuildIdentifier = strtoull (
1544
+ getString (BuildIdentifierArgs[IdentifierIdx]).c_str (), NULL , 10 );
1545
+ #ifndef NDEBUG
1546
+ FoundBuildIdentifier = true ;
1547
+ #endif
1548
+ } else if (EI->getExtOp () == SPIRVDebug::StoragePath) {
1549
+ using namespace SPIRVDebug ::Operand::StoragePath;
1550
+ SPIRVWordVec StoragePathArgs = EI->getArguments ();
1551
+ assert (StoragePathArgs.size () == OperandCount &&
1552
+ " Invalid number of operands" );
1553
+ assert (!FoundStoragePath &&
1554
+ " More than one StoragePath instruction not allowed" );
1555
+ StoragePath = getString (StoragePathArgs[PathIdx]);
1556
+ #ifndef NDEBUG
1557
+ FoundStoragePath = true ;
1558
+ #endif
1559
+ }
1560
+ }
1561
+ assert (((FoundBuildIdentifier && FoundStoragePath) ||
1562
+ (!FoundBuildIdentifier && !FoundStoragePath)) &&
1563
+ " BuildIdentifier and StoragePath must both be set or both unset" );
1564
+ }
1565
+
1515
1566
DIBuilder &SPIRVToLLVMDbgTran::getDIBuilder (const SPIRVExtInst *DebugInst) {
1516
1567
assert (BuilderMap.size () != 0 && " No debug compile units" );
1517
1568
if (BuilderMap.size () == 1 )
0 commit comments