@@ -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 }
@@ -813,9 +819,10 @@ LLVMToSPIRVDbgTran::transDbgGlobalVariable(const DIGlobalVariable *GV) {
813819 // Parent scope
814820 DIScope *Context = GV->getScope ();
815821 SPIRVEntry *Parent = SPIRVCU;
816- // Global variable may be declared in scope of a namespace or it may be a
817- // static variable declared in scope of a function
818- if (Context && (isa<DINamespace>(Context) || isa<DISubprogram>(Context)))
822+ // Global variable may be declared in scope of a namespace or imported module,
823+ // it may also be a static variable declared in scope of a function.
824+ if (Context && (isa<DINamespace>(Context) || isa<DISubprogram>(Context) ||
825+ isa<DIModule>(Context)))
819826 Parent = transDbgEntry (Context);
820827 Ops[ParentIdx] = Parent->getId ();
821828
@@ -1036,3 +1043,20 @@ LLVMToSPIRVDbgTran::transDbgImportedEntry(const DIImportedEntity *IE) {
10361043 Ops[ParentIdx] = getScope (IE->getScope ())->getId ();
10371044 return BM->addDebugInfo (SPIRVDebug::ImportedEntity, getVoidTy (), Ops);
10381045}
1046+
1047+ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgModule (const DIModule *Module) {
1048+ using namespace SPIRVDebug ::Operand::ModuleINTEL;
1049+ SPIRVWordVec Ops (OperandCount);
1050+ Ops[NameIdx] = BM->getString (Module->getName ().str ())->getId ();
1051+ Ops[SourceIdx] = getSource (Module->getFile ())->getId ();
1052+ Ops[LineIdx] = Module->getLineNo ();
1053+ Ops[ParentIdx] = getScope (Module->getScope ())->getId ();
1054+ Ops[ConfigMacrosIdx] =
1055+ BM->getString (Module->getConfigurationMacros ().str ())->getId ();
1056+ Ops[IncludePathIdx] = BM->getString (Module->getIncludePath ().str ())->getId ();
1057+ Ops[ApiNotesIdx] = BM->getString (Module->getAPINotesFile ().str ())->getId ();
1058+ Ops[IsDeclIdx] = Module->getIsDecl ();
1059+ BM->addExtension (ExtensionID::SPV_INTEL_debug_module);
1060+ BM->addCapability (spv::internal::CapabilityDebugInfoModuleINTEL);
1061+ return BM->addDebugInfo (SPIRVDebug::ModuleINTEL, getVoidTy (), Ops);
1062+ }
0 commit comments