Index: lib/CodeGen/AsmPrinter/CodeViewDebug.h =================================================================== --- lib/CodeGen/AsmPrinter/CodeViewDebug.h +++ lib/CodeGen/AsmPrinter/CodeViewDebug.h @@ -277,11 +277,11 @@ void emitInlinedCallSite(const FunctionInfo &FI, const DILocation *InlinedAt, const InlineSite &Site); - using InlinedVariable = DbgValueHistoryMap::InlinedVariable; + using InlinedEntity = DbgValueHistoryMap::InlinedEntity; void collectVariableInfo(const DISubprogram *SP); - void collectVariableInfoFromMFTable(DenseSet &Processed); + void collectVariableInfoFromMFTable(DenseSet &Processed); // Construct the lexical block tree for a routine, pruning emptpy lexical // scopes, and populate it with local variables. Index: lib/CodeGen/AsmPrinter/CodeViewDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -1048,7 +1048,7 @@ } void CodeViewDebug::collectVariableInfoFromMFTable( - DenseSet &Processed) { + DenseSet &Processed) { const MachineFunction &MF = *Asm->MF; const TargetSubtargetInfo &TSI = MF.getSubtarget(); const TargetFrameLowering *TFI = TSI.getFrameLowering(); @@ -1060,7 +1060,7 @@ assert(VI.Var->isValidLocationForIntrinsic(VI.Loc) && "Expected inlined-at fields to agree"); - Processed.insert(InlinedVariable(VI.Var, VI.Loc->getInlinedAt())); + Processed.insert(InlinedEntity(VI.Var, VI.Loc->getInlinedAt())); LexicalScope *Scope = LScopes.findLexicalScope(VI.Loc); // If variable scope is not found then skip this variable. @@ -1196,15 +1196,15 @@ } void CodeViewDebug::collectVariableInfo(const DISubprogram *SP) { - DenseSet Processed; + DenseSet Processed; // Grab the variable info that was squirreled away in the MMI side-table. collectVariableInfoFromMFTable(Processed); for (const auto &I : DbgValues) { - InlinedVariable IV = I.first; + InlinedEntity IV = I.first; if (Processed.count(IV)) continue; - const DILocalVariable *DIVar = IV.first; + const DILocalVariable *DIVar = cast(IV.first); const DILocation *InlinedAt = IV.second; // Instruction ranges, specifying where IV is accessible. Index: lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h =================================================================== --- lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h +++ lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h @@ -33,20 +33,19 @@ public: using InstrRange = std::pair; using InstrRanges = SmallVector; - using InlinedVariable = - std::pair; - using InstrRangesMap = MapVector; + using InlinedEntity = std::pair; + using InstrRangesMap = MapVector; private: InstrRangesMap VarInstrRanges; public: - void startInstrRange(InlinedVariable Var, const MachineInstr &MI); - void endInstrRange(InlinedVariable Var, const MachineInstr &MI); + void startInstrRange(InlinedEntity Var, const MachineInstr &MI); + void endInstrRange(InlinedEntity Var, const MachineInstr &MI); // Returns register currently describing @Var. If @Var is currently // unaccessible or is not described by a register, returns 0. - unsigned getRegisterForVar(InlinedVariable Var) const; + unsigned getRegisterForVar(InlinedEntity Var) const; bool empty() const { return VarInstrRanges.empty(); } void clear() { VarInstrRanges.clear(); } @@ -63,14 +62,14 @@ /// a temporary (assembler) label before it. class DbgLabelInstrMap { public: - using InlinedLabel = std::pair; - using InstrMap = MapVector; + using InlinedEntity = std::pair; + using InstrMap = MapVector; private: InstrMap LabelInstr; public: - void addInstr(InlinedLabel Label, const MachineInstr &MI); + void addInstr(InlinedEntity Label, const MachineInstr &MI); bool empty() const { return LabelInstr.empty(); } void clear() { LabelInstr.clear(); } Index: lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp +++ lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp @@ -42,7 +42,7 @@ return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : 0; } -void DbgValueHistoryMap::startInstrRange(InlinedVariable Var, +void DbgValueHistoryMap::startInstrRange(InlinedEntity Var, const MachineInstr &MI) { // Instruction range should start with a DBG_VALUE instruction for the // variable. @@ -57,7 +57,7 @@ Ranges.push_back(std::make_pair(&MI, nullptr)); } -void DbgValueHistoryMap::endInstrRange(InlinedVariable Var, +void DbgValueHistoryMap::endInstrRange(InlinedEntity Var, const MachineInstr &MI) { auto &Ranges = VarInstrRanges[Var]; // Verify that the current instruction range is not yet closed. @@ -68,7 +68,7 @@ Ranges.back().second = &MI; } -unsigned DbgValueHistoryMap::getRegisterForVar(InlinedVariable Var) const { +unsigned DbgValueHistoryMap::getRegisterForVar(InlinedEntity Var) const { const auto &I = VarInstrRanges.find(Var); if (I == VarInstrRanges.end()) return 0; @@ -78,7 +78,7 @@ return isDescribedByReg(*Ranges.back().first); } -void DbgLabelInstrMap::addInstr(InlinedLabel Label, const MachineInstr &MI) { +void DbgLabelInstrMap::addInstr(InlinedEntity Label, const MachineInstr &MI) { assert(MI.isDebugLabel() && "not a DBG_LABEL"); LabelInstr[Label] = &MI; } @@ -86,15 +86,14 @@ namespace { // Maps physreg numbers to the variables they describe. -using InlinedVariable = DbgValueHistoryMap::InlinedVariable; -using RegDescribedVarsMap = std::map>; -using InlinedLabel = DbgLabelInstrMap::InlinedLabel; +using InlinedEntity = DbgValueHistoryMap::InlinedEntity; +using RegDescribedVarsMap = std::map>; } // end anonymous namespace // Claim that @Var is not described by @RegNo anymore. static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo, - InlinedVariable Var) { + InlinedEntity Var) { const auto &I = RegVars.find(RegNo); assert(RegNo != 0U && I != RegVars.end()); auto &VarSet = I->second; @@ -108,7 +107,7 @@ // Claim that @Var is now described by @RegNo. static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo, - InlinedVariable Var) { + InlinedEntity Var) { assert(RegNo != 0U); auto &VarSet = RegVars[RegNo]; assert(!is_contained(VarSet, Var)); @@ -249,7 +248,7 @@ const DILocalVariable *RawVar = MI.getDebugVariable(); assert(RawVar->isValidLocationForIntrinsic(MI.getDebugLoc()) && "Expected inlined-at fields to agree"); - InlinedVariable Var(RawVar, MI.getDebugLoc()->getInlinedAt()); + InlinedEntity Var(RawVar, MI.getDebugLoc()->getInlinedAt()); if (unsigned PrevReg = DbgValues.getRegisterForVar(Var)) dropRegDescribedVar(RegVars, PrevReg, Var); @@ -266,7 +265,7 @@ // When collecting debug information for labels, there is no MCSymbol // generated for it. So, we keep MachineInstr in DbgLabels in order // to query MCSymbol afterward. - InlinedLabel L(RawLabel, MI.getDebugLoc()->getInlinedAt()); + InlinedEntity L(RawLabel, MI.getDebugLoc()->getInlinedAt()); DbgLabels.addInstr(L, MI); } } @@ -289,10 +288,10 @@ LLVM_DUMP_METHOD void DbgValueHistoryMap::dump() const { dbgs() << "DbgValueHistoryMap:\n"; for (const auto &VarRangePair : *this) { - const InlinedVariable &Var = VarRangePair.first; + const InlinedEntity &Var = VarRangePair.first; const InstrRanges &Ranges = VarRangePair.second; - const DILocalVariable *LocalVar = Var.first; + const DILocalVariable *LocalVar = cast(Var.first); const DILocation *Location = Var.second; dbgs() << " - " << LocalVar->getName() << " at "; Index: lib/CodeGen/AsmPrinter/DwarfCompileUnit.h =================================================================== --- lib/CodeGen/AsmPrinter/DwarfCompileUnit.h +++ lib/CodeGen/AsmPrinter/DwarfCompileUnit.h @@ -216,7 +216,7 @@ void finishEntityDefinition(const DbgEntity *Entity); /// Find abstract variable associated with Var. - using InlinedVariable = DbgValueHistoryMap::InlinedVariable; + using InlinedEntity = DbgValueHistoryMap::InlinedEntity; DbgEntity *getExistingAbstractEntity(const DINode *Node); void createAbstractEntity(const DINode *Node, LexicalScope *Scope); Index: lib/CodeGen/AsmPrinter/DwarfDebug.h =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.h +++ lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -408,8 +408,7 @@ return InfoHolder.getUnits(); } - using InlinedVariable = DbgValueHistoryMap::InlinedVariable; - using InlinedLabel = DbgLabelInstrMap::InlinedLabel; + using InlinedEntity = DbgValueHistoryMap::InlinedEntity; void ensureAbstractEntityIsCreated(DwarfCompileUnit &CU, const DINode *Node, @@ -552,7 +551,7 @@ /// Populate LexicalScope entries with variables' info. void collectEntityInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP, - DenseSet &ProcessedVars); + DenseSet &ProcessedVars); /// Build the location list for all DBG_VALUEs in the /// function that describe the same variable. @@ -561,7 +560,7 @@ /// Collect variable information from the side table maintained by MF. void collectVariableInfoFromMFTable(DwarfCompileUnit &TheCU, - DenseSet &P); + DenseSet &P); /// Emit the reference to the section. void emitSectionReference(const DwarfCompileUnit &CU); Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -939,15 +939,15 @@ // 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); @@ -956,7 +956,8 @@ 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); @@ -1210,12 +1211,12 @@ // 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; @@ -1225,17 +1226,18 @@ 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"); @@ -1261,44 +1263,46 @@ // 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()); @@ -1467,8 +1471,8 @@ 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())); @@ -1492,16 +1496,21 @@ 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); } Index: test/DebugInfo/Generic/debug-label.ll =================================================================== --- test/DebugInfo/Generic/debug-label.ll +++ test/DebugInfo/Generic/debug-label.ll @@ -11,6 +11,7 @@ ; CHECK-NEXT: DW_AT_decl_file [DW_FORM_data1] {{.*}}debug-label.c ; CHECK-NEXT: DW_AT_decl_line [DW_FORM_data1] {{.*}}7 ; CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] {{.*}}{{0x[0-9a-f]+}} +; CHECK-NOT: DW_AT_name [DW_FORM_strp] {{.*}}"top" ; ; RUN: llc -fast-isel=false -O0 -o - %s | FileCheck %s -check-prefix=ASM ; @@ -64,8 +65,9 @@ !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: false, emissionKind: FullDebug, enums: !2) !1 = !DIFile(filename: "debug-label.c", directory: "./") !2 = !{} +!3 = !{!10} !4 = !{i32 2, !"Debug Info Version", i32 3} -!6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: false, unit: !0, retainedNodes: !2) +!6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: false, unit: !0, retainedNodes: !3) !7 = !DISubroutineType(types: !8) !8 = !{!9, !9, !9} !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)