From 760c1ab19971dfb663c74b27734b481148d49696 Mon Sep 17 00:00:00 2001 From: Hsiangkai Wang Date: Thu, 6 Sep 2018 02:22:06 +0000 Subject: [DebugInfo] Do not generate label debug info if it has been processed. In DwarfDebug::collectEntityInfo(), if the label entity is processed in DbgLabels list, it means the label is not optimized out. There is no need to generate debug info for it with null position. llvm-svn: 341513 --- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 67 +++++++++++++++++------------- 1 file changed, 38 insertions(+), 29 deletions(-) (limited to 'llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp') diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 478ccc097d8..4cb9fc6fd7d 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -938,15 +938,15 @@ void DwarfDebug::ensureAbstractEntityIsCreatedIfScoped(DwarfCompileUnit &CU, // Collect variable information from side table maintained by MF. void DwarfDebug::collectVariableInfoFromMFTable( - DwarfCompileUnit &TheCU, DenseSet &Processed) { - SmallDenseMap MFVars; + DwarfCompileUnit &TheCU, DenseSet &Processed) { + SmallDenseMap MFVars; for (const auto &VI : Asm->MF->getVariableDbgInfo()) { if (!VI.Var) continue; assert(VI.Var->isValidLocationForIntrinsic(VI.Loc) && "Expected inlined-at fields to agree"); - InlinedVariable Var(VI.Var, VI.Loc->getInlinedAt()); + InlinedEntity Var(VI.Var, VI.Loc->getInlinedAt()); Processed.insert(Var); LexicalScope *Scope = LScopes.findLexicalScope(VI.Loc); @@ -955,7 +955,8 @@ void DwarfDebug::collectVariableInfoFromMFTable( continue; ensureAbstractEntityIsCreatedIfScoped(TheCU, Var.first, Scope->getScopeNode()); - auto RegVar = llvm::make_unique(Var.first, Var.second); + auto RegVar = llvm::make_unique( + cast(Var.first), Var.second); RegVar->initializeMMI(VI.Expr, VI.Slot); if (DbgVariable *DbgVar = MFVars.lookup(Var)) DbgVar->addMMIEntry(*RegVar); @@ -1209,12 +1210,12 @@ static bool validThroughout(LexicalScopes &LScopes, // Find variables for each lexical scope. void DwarfDebug::collectEntityInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP, - DenseSet &Processed) { + DenseSet &Processed) { // Grab the variable info that was squirreled away in the MMI side-table. collectVariableInfoFromMFTable(TheCU, Processed); for (const auto &I : DbgValues) { - InlinedVariable IV = I.first; + InlinedEntity IV = I.first; if (Processed.count(IV)) continue; @@ -1224,17 +1225,18 @@ void DwarfDebug::collectEntityInfo(DwarfCompileUnit &TheCU, continue; LexicalScope *Scope = nullptr; + const DILocalVariable *LocalVar = cast(IV.first); if (const DILocation *IA = IV.second) - Scope = LScopes.findInlinedScope(IV.first->getScope(), IA); + Scope = LScopes.findInlinedScope(LocalVar->getScope(), IA); else - Scope = LScopes.findLexicalScope(IV.first->getScope()); + Scope = LScopes.findLexicalScope(LocalVar->getScope()); // If variable scope is not found then skip this variable. if (!Scope) continue; Processed.insert(IV); DbgVariable *RegVar = cast(createConcreteEntity(TheCU, - *Scope, IV.first, IV.second)); + *Scope, LocalVar, IV.second)); const MachineInstr *MInsn = Ranges.front().first; assert(MInsn->isDebugValue() && "History must begin with debug value"); @@ -1260,44 +1262,46 @@ void DwarfDebug::collectEntityInfo(DwarfCompileUnit &TheCU, // unique identifiers, so don't bother resolving the type with the // identifier map. const DIBasicType *BT = dyn_cast( - static_cast(IV.first->getType())); + static_cast(LocalVar->getType())); // Finalize the entry by lowering it into a DWARF bytestream. for (auto &Entry : Entries) Entry.finalize(*Asm, List, BT); } - // For each InlinedLabel collected from DBG_LABEL instructions, convert to + // For each InlinedEntity collected from DBG_LABEL instructions, convert to // DWARF-related DbgLabel. for (const auto &I : DbgLabels) { - InlinedLabel IL = I.first; + InlinedEntity IL = I.first; const MachineInstr *MI = I.second; if (MI == nullptr) continue; LexicalScope *Scope = nullptr; + const DILabel *Label = cast(IL.first); // Get inlined DILocation if it is inlined label. if (const DILocation *IA = IL.second) - Scope = LScopes.findInlinedScope(IL.first->getScope(), IA); + Scope = LScopes.findInlinedScope(Label->getScope(), IA); else - Scope = LScopes.findLexicalScope(IL.first->getScope()); + Scope = LScopes.findLexicalScope(Label->getScope()); // If label scope is not found then skip this label. if (!Scope) continue; + Processed.insert(IL); /// At this point, the temporary label is created. /// Save the temporary label to DbgLabel entity to get the /// actually address when generating Dwarf DIE. MCSymbol *Sym = getLabelBeforeInsn(MI); - createConcreteEntity(TheCU, *Scope, IL.first, IL.second, Sym); + createConcreteEntity(TheCU, *Scope, Label, IL.second, Sym); } // Collect info for variables/labels that were optimized out. for (const DINode *DN : SP->getRetainedNodes()) { + if (!Processed.insert(InlinedEntity(DN, nullptr)).second) + continue; LexicalScope *Scope = nullptr; if (auto *DV = dyn_cast(DN)) { - if (!Processed.insert(InlinedVariable(DV, nullptr)).second) - continue; Scope = LScopes.findLexicalScope(DV->getScope()); } else if (auto *DL = dyn_cast(DN)) { Scope = LScopes.findLexicalScope(DL->getScope()); @@ -1466,8 +1470,8 @@ void DwarfDebug::endFunctionImpl(const MachineFunction *MF) { return; } - DenseSet ProcessedVars; - collectEntityInfo(TheCU, SP, ProcessedVars); + DenseSet Processed; + collectEntityInfo(TheCU, SP, Processed); // Add the range of this function to the list of ranges for the CU. TheCU.addRange(RangeSpan(Asm->getFunctionBegin(), Asm->getFunctionEnd())); @@ -1491,16 +1495,21 @@ void DwarfDebug::endFunctionImpl(const MachineFunction *MF) { for (LexicalScope *AScope : LScopes.getAbstractScopesList()) { auto *SP = cast(AScope->getScopeNode()); for (const DINode *DN : SP->getRetainedNodes()) { - if (auto *DV = dyn_cast(DN)) { - // Collect info for variables that were optimized out. - if (!ProcessedVars.insert(InlinedVariable(DV, nullptr)).second) - continue; - ensureAbstractEntityIsCreated(TheCU, DV, DV->getScope()); - assert(LScopes.getAbstractScopesList().size() == NumAbstractScopes - && "ensureAbstractEntityIsCreated inserted abstract scopes"); - } else if (auto *DL = dyn_cast(DN)) { - ensureAbstractEntityIsCreated(TheCU, DL, DL->getScope()); - } + if (!Processed.insert(InlinedEntity(DN, nullptr)).second) + continue; + + const MDNode *Scope = nullptr; + if (auto *DV = dyn_cast(DN)) + Scope = DV->getScope(); + else if (auto *DL = dyn_cast(DN)) + Scope = DL->getScope(); + else + llvm_unreachable("Unexpected DI type!"); + + // Collect info for variables/labels that were optimized out. + ensureAbstractEntityIsCreated(TheCU, DN, Scope); + assert(LScopes.getAbstractScopesList().size() == NumAbstractScopes + && "ensureAbstractEntityIsCreated inserted abstract scopes"); } constructAbstractSubprogramScopeDIE(TheCU, AScope); } -- cgit v1.2.3