diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 33 | ||||
-rw-r--r-- | llvm/lib/IR/DIBuilder.cpp | 13 | ||||
-rw-r--r-- | llvm/lib/IR/DebugInfo.cpp | 61 | ||||
-rw-r--r-- | llvm/lib/IR/Module.cpp | 14 |
4 files changed, 66 insertions, 55 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 296a799d33c..d9d265ef2b9 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -466,15 +466,18 @@ void DwarfDebug::beginModule() { const Module *M = MMI->getModule(); - NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu"); - if (!CU_Nodes) - return; - TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes); + TypeIdentifierMap = generateDITypeIdentifierMap(*M); + unsigned NumDebugCUs = 0; + for (DICompileUnit *CUNode : M->debug_compile_units()) { + (void)CUNode; + ++NumDebugCUs; + } - SingleCU = CU_Nodes->getNumOperands() == 1; + // Tell MMI whether we have debug info. + MMI->setDebugInfoAvailability(NumDebugCUs > 0); + SingleCU = NumDebugCUs == 1; - for (MDNode *N : CU_Nodes->operands()) { - auto *CUNode = cast<DICompileUnit>(N); + for (DICompileUnit *CUNode : M->debug_compile_units()) { DwarfCompileUnit &CU = constructDwarfCompileUnit(CUNode); for (auto *IE : CUNode->getImportedEntities()) CU.addImportedEntity(IE); @@ -500,9 +503,6 @@ void DwarfDebug::beginModule() { for (auto *IE : CUNode->getImportedEntities()) constructAndAddImportedEntityDIE(CU, IE); } - - // Tell MMI that we have debug info. - MMI->setDebugInfoAvailability(true); } void DwarfDebug::finishVariableDefinitions() { @@ -538,6 +538,9 @@ void DwarfDebug::collectDeadVariables() { if (NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu")) { for (MDNode *N : CU_Nodes->operands()) { auto *TheCU = cast<DICompileUnit>(N); + if (TheCU->getEmissionKind() == DICompileUnit::NoDebug) + continue; + // Construct subprogram DIE and add variables DIEs. DwarfCompileUnit *SPCU = static_cast<DwarfCompileUnit *>(CUMap.lookup(TheCU)); @@ -1090,7 +1093,10 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) { // includes the directory of the cpp file being built, even when the file name // is absolute (such as an <> lookup header))) DwarfCompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode()); - assert(TheCU && "Unable to find compile unit!"); + if (!TheCU) + // Once DISubprogram points to the owning CU, we can assert that the CU has + // a NoDebug EmissionKind here. + return; if (Asm->OutStreamer->hasRawTextSupport()) // Use a single line table if we are generating assembly. Asm->OutStreamer->getContext().setDwarfCompileUnitID(0); @@ -1113,7 +1119,10 @@ void DwarfDebug::endFunction(const MachineFunction *MF) { "endFunction should be called with the same function as beginFunction"); if (!MMI->hasDebugInfo() || LScopes.empty() || - !MF->getFunction()->getSubprogram()) { + !MF->getFunction()->getSubprogram() || + // Once DISubprogram points to the owning CU, we can check for a + // CU with a NoDebug EmissionKind here. + !SPMap.lookup(MF->getFunction()->getSubprogram())) { // If we don't have a lexical scope for this function then there will // be a hole in the range information. Keep note of this by setting the // previously used section to nullptr. diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp index fa4b860a58a..aa9ffcf9f3c 100644 --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -137,7 +137,7 @@ static DIScope *getNonCompileUnitScope(DIScope *N) { DICompileUnit *DIBuilder::createCompileUnit( unsigned Lang, StringRef Filename, StringRef Directory, StringRef Producer, bool isOptimized, StringRef Flags, unsigned RunTimeVer, StringRef SplitName, - DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId, bool EmitDebugInfo) { + DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId) { assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) || (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) && @@ -152,15 +152,8 @@ DICompileUnit *DIBuilder::createCompileUnit( nullptr, nullptr, nullptr, nullptr, nullptr, DWOId); // Create a named metadata so that it is easier to find cu in a module. - // Note that we only generate this when the caller wants to actually - // emit debug information. When we are only interested in tracking - // source line locations throughout the backend, we prevent codegen from - // emitting debug info in the final output by not generating llvm.dbg.cu. - if (EmitDebugInfo) { - NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); - NMD->addOperand(CUNode); - } - + NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); + NMD->addOperand(CUNode); trackIfUnresolved(CUNode); return CUNode; } diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 2a60af4b7f3..e63c25484a5 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -39,10 +39,9 @@ DISubprogram *llvm::getDISubprogram(const MDNode *Scope) { } DITypeIdentifierMap -llvm::generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes) { +llvm::generateDITypeIdentifierMap(const Module &M) { DITypeIdentifierMap Map; - for (unsigned CUi = 0, CUe = CU_Nodes->getNumOperands(); CUi != CUe; ++CUi) { - auto *CU = cast<DICompileUnit>(CU_Nodes->getOperand(CUi)); + for (DICompileUnit *CU : M.debug_compile_units()) { DINodeArray Retain = CU->getRetainedTypes(); for (unsigned Ti = 0, Te = Retain.size(); Ti != Te; ++Ti) { if (!isa<DICompositeType>(Retain[Ti])) @@ -79,42 +78,38 @@ void DebugInfoFinder::reset() { } void DebugInfoFinder::InitializeTypeMap(const Module &M) { - if (!TypeMapInitialized) - if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) { - TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes); - TypeMapInitialized = true; - } + if (TypeMapInitialized) + return; + TypeIdentifierMap = generateDITypeIdentifierMap(M); + TypeMapInitialized = true; } void DebugInfoFinder::processModule(const Module &M) { InitializeTypeMap(M); - if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) { - for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) { - auto *CU = cast<DICompileUnit>(CU_Nodes->getOperand(i)); - addCompileUnit(CU); - for (auto *DIG : CU->getGlobalVariables()) { - if (addGlobalVariable(DIG)) { - processScope(DIG->getScope()); - processType(DIG->getType().resolve(TypeIdentifierMap)); - } + for (auto *CU : M.debug_compile_units()) { + addCompileUnit(CU); + for (auto *DIG : CU->getGlobalVariables()) { + if (addGlobalVariable(DIG)) { + processScope(DIG->getScope()); + processType(DIG->getType().resolve(TypeIdentifierMap)); } - for (auto *SP : CU->getSubprograms()) + } + for (auto *SP : CU->getSubprograms()) + processSubprogram(SP); + for (auto *ET : CU->getEnumTypes()) + processType(ET); + for (auto *RT : CU->getRetainedTypes()) + processType(RT); + for (auto *Import : CU->getImportedEntities()) { + auto *Entity = Import->getEntity().resolve(TypeIdentifierMap); + if (auto *T = dyn_cast<DIType>(Entity)) + processType(T); + else if (auto *SP = dyn_cast<DISubprogram>(Entity)) processSubprogram(SP); - for (auto *ET : CU->getEnumTypes()) - processType(ET); - for (auto *RT : CU->getRetainedTypes()) - processType(RT); - for (auto *Import : CU->getImportedEntities()) { - auto *Entity = Import->getEntity().resolve(TypeIdentifierMap); - if (auto *T = dyn_cast<DIType>(Entity)) - processType(T); - else if (auto *SP = dyn_cast<DISubprogram>(Entity)) - processSubprogram(SP); - else if (auto *NS = dyn_cast<DINamespace>(Entity)) - processScope(NS->getScope()); - else if (auto *M = dyn_cast<DIModule>(Entity)) - processScope(M->getScope()); - } + else if (auto *NS = dyn_cast<DINamespace>(Entity)) + processScope(NS->getScope()); + else if (auto *M = dyn_cast<DIModule>(Entity)) + processScope(M->getScope()); } } } diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 0a2dcc1dcf6..bc613ff63c9 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -19,6 +19,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/GVMaterializer.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/LLVMContext.h" @@ -380,6 +381,19 @@ void Module::setDataLayout(const DataLayout &Other) { DL = Other; } const DataLayout &Module::getDataLayout() const { return DL; } +DICompileUnit *Module::debug_compile_units_iterator::operator*() const { + return cast<DICompileUnit>(CUs->getOperand(Idx)); +} +DICompileUnit *Module::debug_compile_units_iterator::operator->() const { + return cast<DICompileUnit>(CUs->getOperand(Idx)); +} + +void Module::debug_compile_units_iterator::SkipNoDebugCUs() { + while (CUs && (Idx < CUs->getNumOperands()) && + ((*this)->getEmissionKind() == DICompileUnit::NoDebug)) + ++Idx; +} + //===----------------------------------------------------------------------===// // Methods to control the materialization of GlobalValues in the Module. // |