@@ -343,6 +343,12 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgEntryImpl(const MDNode *MDN) {
343343 case dwarf::DW_TAG_imported_declaration:
344344 return transDbgImportedEntry (cast<DIImportedEntity>(DIEntry));
345345
346+ case dwarf::DW_TAG_module: {
347+ if (BM->isAllowedToUseExtension (ExtensionID::SPV_INTEL_debug_module))
348+ return transDbgModule (cast<DIModule>(DIEntry));
349+ return getDebugInfoNone ();
350+ }
351+
346352 default :
347353 return getDebugInfoNone ();
348354 }
@@ -812,9 +818,10 @@ LLVMToSPIRVDbgTran::transDbgGlobalVariable(const DIGlobalVariable *GV) {
812818 // Parent scope
813819 DIScope *Context = GV->getScope ();
814820 SPIRVEntry *Parent = SPIRVCU;
815- // Global variable may be declared in scope of a namespace or it may be a
816- // static variable declared in scope of a function
817- if (Context && (isa<DINamespace>(Context) || isa<DISubprogram>(Context)))
821+ // Global variable may be declared in scope of a namespace or imported module,
822+ // it may also be a static variable declared in scope of a function.
823+ if (Context && (isa<DINamespace>(Context) || isa<DISubprogram>(Context) ||
824+ isa<DIModule>(Context)))
818825 Parent = transDbgEntry (Context);
819826 Ops[ParentIdx] = Parent->getId ();
820827
@@ -1035,3 +1042,20 @@ LLVMToSPIRVDbgTran::transDbgImportedEntry(const DIImportedEntity *IE) {
10351042 Ops[ParentIdx] = getScope (IE->getScope ())->getId ();
10361043 return BM->addDebugInfo (SPIRVDebug::ImportedEntity, getVoidTy (), Ops);
10371044}
1045+
1046+ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgModule (const DIModule *Module) {
1047+ using namespace SPIRVDebug ::Operand::ModuleINTEL;
1048+ SPIRVWordVec Ops (OperandCount);
1049+ Ops[NameIdx] = BM->getString (Module->getName ().str ())->getId ();
1050+ Ops[SourceIdx] = getSource (Module->getFile ())->getId ();
1051+ Ops[LineIdx] = Module->getLineNo ();
1052+ Ops[ParentIdx] = getScope (Module->getScope ())->getId ();
1053+ Ops[ConfigMacrosIdx] =
1054+ BM->getString (Module->getConfigurationMacros ().str ())->getId ();
1055+ Ops[IncludePathIdx] = BM->getString (Module->getIncludePath ().str ())->getId ();
1056+ Ops[ApiNotesIdx] = BM->getString (Module->getAPINotesFile ().str ())->getId ();
1057+ Ops[IsDeclIdx] = Module->getIsDecl ();
1058+ BM->addExtension (ExtensionID::SPV_INTEL_debug_module);
1059+ BM->addCapability (spv::internal::CapabilityDebugInfoModuleINTEL);
1060+ return BM->addDebugInfo (SPIRVDebug::ModuleINTEL, getVoidTy (), Ops);
1061+ }
0 commit comments