diff options
author | Hsiangkai Wang <hsiangkai@gmail.com> | 2018-09-06 02:22:06 +0000 |
---|---|---|
committer | Hsiangkai Wang <hsiangkai@gmail.com> | 2018-09-06 02:22:06 +0000 |
commit | 760c1ab19971dfb663c74b27734b481148d49696 (patch) | |
tree | 458f62d2d267c4b9557651e012a3246534096baa /llvm/lib/CodeGen | |
parent | 5a53760f6504d7da6bb0419b7646d8cff208ebe4 (diff) | |
download | bcm5719-llvm-760c1ab19971dfb663c74b27734b481148d49696.tar.gz bcm5719-llvm-760c1ab19971dfb663c74b27734b481148d49696.zip |
[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
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h | 4 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp | 25 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h | 17 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 67 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h | 7 |
7 files changed, 69 insertions, 63 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index 8c5c5478d01..760833dba0c 100644 --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -1048,7 +1048,7 @@ CodeViewDebug::createDefRangeGeneral(uint16_t CVRegister, bool InMemory, } void CodeViewDebug::collectVariableInfoFromMFTable( - DenseSet<InlinedVariable> &Processed) { + DenseSet<InlinedEntity> &Processed) { const MachineFunction &MF = *Asm->MF; const TargetSubtargetInfo &TSI = MF.getSubtarget(); const TargetFrameLowering *TFI = TSI.getFrameLowering(); @@ -1060,7 +1060,7 @@ void CodeViewDebug::collectVariableInfoFromMFTable( 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::calculateRanges( } void CodeViewDebug::collectVariableInfo(const DISubprogram *SP) { - DenseSet<InlinedVariable> Processed; + DenseSet<InlinedEntity> 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<DILocalVariable>(IV.first); const DILocation *InlinedAt = IV.second; // Instruction ranges, specifying where IV is accessible. diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h index 7f9a427f813..c466a33d0cc 100644 --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h @@ -277,11 +277,11 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase { 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<InlinedVariable> &Processed); + void collectVariableInfoFromMFTable(DenseSet<InlinedEntity> &Processed); // Construct the lexical block tree for a routine, pruning emptpy lexical // scopes, and populate it with local variables. diff --git a/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp b/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp index 8fb4382efd3..bb2fa7d9c72 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp @@ -42,7 +42,7 @@ static unsigned isDescribedByReg(const MachineInstr &MI) { 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 @@ void DbgValueHistoryMap::startInstrRange(InlinedVariable Var, 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 @@ void DbgValueHistoryMap::endInstrRange(InlinedVariable Var, 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 @@ unsigned DbgValueHistoryMap::getRegisterForVar(InlinedVariable Var) const { 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 @@ void DbgLabelInstrMap::addInstr(InlinedLabel Label, const MachineInstr &MI) { namespace { // Maps physreg numbers to the variables they describe. -using InlinedVariable = DbgValueHistoryMap::InlinedVariable; -using RegDescribedVarsMap = std::map<unsigned, SmallVector<InlinedVariable, 1>>; -using InlinedLabel = DbgLabelInstrMap::InlinedLabel; +using InlinedEntity = DbgValueHistoryMap::InlinedEntity; +using RegDescribedVarsMap = std::map<unsigned, SmallVector<InlinedEntity, 1>>; } // 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 @@ static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo, // 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 @@ void llvm::calculateDbgEntityHistory(const MachineFunction *MF, 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 @@ void llvm::calculateDbgEntityHistory(const MachineFunction *MF, // 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 @@ void llvm::calculateDbgEntityHistory(const MachineFunction *MF, 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<DILocalVariable>(Var.first); const DILocation *Location = Var.second; dbgs() << " - " << LocalVar->getName() << " at "; diff --git a/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h b/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h index 589bcce1295..660d2ff551b 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h +++ b/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h @@ -33,20 +33,19 @@ class DbgValueHistoryMap { public: using InstrRange = std::pair<const MachineInstr *, const MachineInstr *>; using InstrRanges = SmallVector<InstrRange, 4>; - using InlinedVariable = - std::pair<const DILocalVariable *, const DILocation *>; - using InstrRangesMap = MapVector<InlinedVariable, InstrRanges>; + using InlinedEntity = std::pair<const DINode *, const DILocation *>; + using InstrRangesMap = MapVector<InlinedEntity, InstrRanges>; 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 @@ public: /// a temporary (assembler) label before it. class DbgLabelInstrMap { public: - using InlinedLabel = std::pair<const DILabel *, const DILocation *>; - using InstrMap = MapVector<InlinedLabel, const MachineInstr *>; + using InlinedEntity = std::pair<const DINode *, const DILocation *>; + using InstrMap = MapVector<InlinedEntity, const MachineInstr *>; 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(); } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h index ab67c43f6f2..9bf1ce18b3a 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h @@ -216,7 +216,7 @@ public: 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); 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<InlinedVariable> &Processed) { - SmallDenseMap<InlinedVariable, DbgVariable *> MFVars; + DwarfCompileUnit &TheCU, DenseSet<InlinedEntity> &Processed) { + SmallDenseMap<InlinedEntity, DbgVariable *> 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<DbgVariable>(Var.first, Var.second); + auto RegVar = llvm::make_unique<DbgVariable>( + cast<DILocalVariable>(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<InlinedVariable> &Processed) { + DenseSet<InlinedEntity> &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<DILocalVariable>(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<DbgVariable>(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<DIBasicType>( - static_cast<const Metadata *>(IV.first->getType())); + static_cast<const Metadata *>(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<DILabel>(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<DILocalVariable>(DN)) { - if (!Processed.insert(InlinedVariable(DV, nullptr)).second) - continue; Scope = LScopes.findLexicalScope(DV->getScope()); } else if (auto *DL = dyn_cast<DILabel>(DN)) { Scope = LScopes.findLexicalScope(DL->getScope()); @@ -1466,8 +1470,8 @@ void DwarfDebug::endFunctionImpl(const MachineFunction *MF) { return; } - DenseSet<InlinedVariable> ProcessedVars; - collectEntityInfo(TheCU, SP, ProcessedVars); + DenseSet<InlinedEntity> 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<DISubprogram>(AScope->getScopeNode()); for (const DINode *DN : SP->getRetainedNodes()) { - if (auto *DV = dyn_cast<DILocalVariable>(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<DILabel>(DN)) { - ensureAbstractEntityIsCreated(TheCU, DL, DL->getScope()); - } + if (!Processed.insert(InlinedEntity(DN, nullptr)).second) + continue; + + const MDNode *Scope = nullptr; + if (auto *DV = dyn_cast<DILocalVariable>(DN)) + Scope = DV->getScope(); + else if (auto *DL = dyn_cast<DILabel>(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); } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h index d9353a7d01b..23aa2ba094e 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -406,8 +406,7 @@ class DwarfDebug : public DebugHandlerBase { return InfoHolder.getUnits(); } - using InlinedVariable = DbgValueHistoryMap::InlinedVariable; - using InlinedLabel = DbgLabelInstrMap::InlinedLabel; + using InlinedEntity = DbgValueHistoryMap::InlinedEntity; void ensureAbstractEntityIsCreated(DwarfCompileUnit &CU, const DINode *Node, @@ -550,7 +549,7 @@ class DwarfDebug : public DebugHandlerBase { /// Populate LexicalScope entries with variables' info. void collectEntityInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP, - DenseSet<InlinedVariable> &ProcessedVars); + DenseSet<InlinedEntity> &ProcessedVars); /// Build the location list for all DBG_VALUEs in the /// function that describe the same variable. @@ -559,7 +558,7 @@ class DwarfDebug : public DebugHandlerBase { /// Collect variable information from the side table maintained by MF. void collectVariableInfoFromMFTable(DwarfCompileUnit &TheCU, - DenseSet<InlinedVariable> &P); + DenseSet<InlinedEntity> &P); /// Emit the reference to the section. void emitSectionReference(const DwarfCompileUnit &CU); |