Skip to content

Commit

Permalink
[NFC][AsmPrinter] Remove dead multi-MMI handling from DwarfFile::addS…
Browse files Browse the repository at this point in the history
…copeVariable

Differential Revision: https://reviews.llvm.org/D158676
  • Loading branch information
slinder1 committed Sep 11, 2023
1 parent 58c108c commit 414ceff
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
38 changes: 17 additions & 21 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,8 @@ ArrayRef<FrameIndexExpr> DbgVariable::getFrameIndexExprs() const {
return FrameIndexExprs;
}

void DbgVariable::addMMIEntry(const DbgVariable &V) {
assert(V.getVariable() == getVariable() && "conflicting variable");
assert(V.getInlinedAt() == getInlinedAt() && "conflicting inlined-at location");

void DbgVariable::addMMIEntry(const DIExpression *Expr, int FI) {
auto &FrameIndexExprs = get<MMILoc>().FrameIndexExprs;
auto &VFrameIndexExprs = V.get<MMILoc>().FrameIndexExprs;

// FIXME: This logic should not be necessary anymore, as we now have proper
// deduplication. However, without it, we currently run into the assertion
Expand All @@ -322,12 +318,10 @@ void DbgVariable::addMMIEntry(const DbgVariable &V) {
return;
}

for (const auto &FIE : VFrameIndexExprs)
// Ignore duplicate entries.
if (llvm::none_of(FrameIndexExprs, [&](const FrameIndexExpr &Other) {
return FIE.FI == Other.FI && FIE.Expr == Other.Expr;
}))
FrameIndexExprs.push_back(FIE);
if (llvm::none_of(FrameIndexExprs, [&](const FrameIndexExpr &Other) {
return FI == Other.FI && Expr == Other.Expr;
}))
FrameIndexExprs.push_back({FI, Expr});

assert((FrameIndexExprs.size() == 1 ||
llvm::all_of(FrameIndexExprs,
Expand Down Expand Up @@ -1574,6 +1568,15 @@ void DwarfDebug::collectVariableInfoFromMFTable(
}

ensureAbstractEntityIsCreatedIfScoped(TheCU, Var.first, Scope->getScopeNode());

if (DbgVariable *DbgVar = MFVars.lookup(Var)) {
if (DbgVar->hasFrameIndexExprs())
DbgVar->addMMIEntry(VI.Expr, VI.getStackSlot());
else
DbgVar->addEntryValueExpr(VI.getEntryValueRegister(), *VI.Expr);
continue;
}

auto RegVar = std::make_unique<DbgVariable>(
cast<DILocalVariable>(Var.first), Var.second);
if (VI.inStackSlot())
Expand All @@ -1582,16 +1585,9 @@ void DwarfDebug::collectVariableInfoFromMFTable(
RegVar->initializeEntryValue(VI.getEntryValueRegister(), *VI.Expr);
LLVM_DEBUG(dbgs() << "Created DbgVariable for " << VI.Var->getName()
<< "\n");

if (DbgVariable *DbgVar = MFVars.lookup(Var)) {
if (DbgVar->hasFrameIndexExprs())
DbgVar->addMMIEntry(*RegVar);
else
DbgVar->addEntryValueExpr(VI.getEntryValueRegister(), *VI.Expr);
} else if (InfoHolder.addScopeVariable(Scope, RegVar.get())) {
MFVars.insert({Var, RegVar.get()});
ConcreteEntities.push_back(std::move(RegVar));
}
InfoHolder.addScopeVariable(Scope, RegVar.get());
MFVars.insert({Var, RegVar.get()});
ConcreteEntities.push_back(std::move(RegVar));
}
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class DbgVariable : public DbgEntity,
/// Get the FI entries, sorted by fragment offset.
ArrayRef<FrameIndexExpr> getFrameIndexExprs() const;
bool hasFrameIndexExprs() const { return holds<MMILoc>(); }
void addMMIEntry(const DbgVariable &V);
void addMMIEntry(const DIExpression *Expr, int FI);

// Translate tag to proper Dwarf tag.
dwarf::Tag getTag() const {
Expand Down
12 changes: 3 additions & 9 deletions llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,15 @@ void DwarfFile::emitStrings(MCSection *StrSection, MCSection *OffsetSection,
StrPool.emit(*Asm, StrSection, OffsetSection, UseRelativeOffsets);
}

bool DwarfFile::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {
void DwarfFile::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {
auto &ScopeVars = ScopeVariables[LS];
const DILocalVariable *DV = Var->getVariable();
if (unsigned ArgNum = DV->getArg()) {
auto Cached = ScopeVars.Args.find(ArgNum);
if (Cached == ScopeVars.Args.end())
ScopeVars.Args[ArgNum] = Var;
else {
Cached->second->addMMIEntry(*Var);
return false;
}
auto Ret = ScopeVars.Args.insert({ArgNum, Var});
assert(Ret.second);
} else {
ScopeVars.Locals.push_back(Var);
}
return true;
}

void DwarfFile::addScopeLabel(LexicalScope *LS, DbgLabel *Label) {
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ class DwarfFile {
MCSymbol *getRnglistsTableBaseSym() const { return RnglistsTableBaseSym; }
void setRnglistsTableBaseSym(MCSymbol *Sym) { RnglistsTableBaseSym = Sym; }

/// \returns false if the variable was merged with a previous one.
bool addScopeVariable(LexicalScope *LS, DbgVariable *Var);
void addScopeVariable(LexicalScope *LS, DbgVariable *Var);

void addScopeLabel(LexicalScope *LS, DbgLabel *Label);

Expand Down

0 comments on commit 414ceff

Please sign in to comment.