1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00

[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
This commit is contained in:
Hsiangkai Wang 2018-09-06 02:22:06 +00:00
parent 35d13c1feb
commit c7272d28a4
8 changed files with 72 additions and 64 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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 ";

View File

@ -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(); }

View File

@ -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);

View File

@ -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)
if (!Processed.insert(InlinedEntity(DN, nullptr)).second)
continue;
ensureAbstractEntityIsCreated(TheCU, DV, DV->getScope());
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");
} else if (auto *DL = dyn_cast<DILabel>(DN)) {
ensureAbstractEntityIsCreated(TheCU, DL, DL->getScope());
}
}
constructAbstractSubprogramScopeDIE(TheCU, AScope);
}

View File

@ -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);

View File

@ -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 -O0 -o - %s | FileCheck %s -check-prefix=ASM
;
@ -61,8 +62,9 @@ declare void @llvm.dbg.label(metadata)
!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)