AsmPrinter: Rewrite initialization of DbgVariable, NFC

There are three types of `DbgVariable`:
  - alloca variables, created based on the MMI table,
  - register variables, created based on DBG_VALUE instructions, and
  - optimized-out variables.

This commit reconfigures `DbgVariable` to make it easier to tell which
kind we have, and make initialization a little clearer.

For MMI/alloca variables, `FrameIndex.size()` must always equal
`Expr.size()`, and there shouldn't be an `MInsn`.  For register
variables (with a `MInsn`), `FrameIndex` must be empty, and `Expr`
should have 0 or 1 element depending on whether it has a complex
expression (registers with multiple locations use `DebugLocListIndex`).
Optimized-out variables shouldn't have any of these fields.

Moreover, this separates DBG_VALUE initialization until after the
variable is created, simplifying logic in a future commit that changes
`collectVariableInfo()` to stop creating empty .debug_loc entries/lists.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240243 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2015-06-21 16:50:43 +00:00
parent 87f860c737
commit 01a8dc8ca6
3 changed files with 85 additions and 64 deletions

View File

@@ -678,8 +678,7 @@ DbgVariable *DwarfDebug::getExistingAbstractVariable(InlinedVariable IV) {
void DwarfDebug::createAbstractVariable(const DILocalVariable *Var,
LexicalScope *Scope) {
auto AbsDbgVariable =
make_unique<DbgVariable>(Var, /* IA */ nullptr, /* Expr */ nullptr, this);
auto AbsDbgVariable = make_unique<DbgVariable>(Var, /* IA */ nullptr, this);
InfoHolder.addScopeVariable(Scope, AbsDbgVariable.get());
AbstractVariables[Var] = std::move(AbsDbgVariable);
}
@@ -722,10 +721,9 @@ void DwarfDebug::collectVariableInfoFromMMITable(
if (!Scope)
continue;
const DIExpression *Expr = cast_or_null<DIExpression>(VI.Expr);
ensureAbstractVariableIsCreatedIfScoped(Var, Scope->getScopeNode());
auto RegVar =
make_unique<DbgVariable>(Var.first, Var.second, Expr, this, VI.Slot);
auto RegVar = make_unique<DbgVariable>(Var.first, Var.second, this);
RegVar->initializeMMI(VI.Expr, VI.Slot);
if (InfoHolder.addScopeVariable(Scope, RegVar.get()))
ConcreteVariables.push_back(std::move(RegVar));
}
@@ -870,6 +868,14 @@ DwarfDebug::buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
}
}
DbgVariable *DwarfDebug::createConcreteVariable(LexicalScope &Scope,
InlinedVariable IV) {
ensureAbstractVariableIsCreatedIfScoped(IV, Scope.getScopeNode());
ConcreteVariables.push_back(
make_unique<DbgVariable>(IV.first, IV.second, this));
InfoHolder.addScopeVariable(&Scope, ConcreteVariables.back().get());
return ConcreteVariables.back().get();
}
// Find variables for each lexical scope.
void DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU,
@@ -898,12 +904,11 @@ void DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU,
continue;
Processed.insert(IV);
DbgVariable *RegVar = createConcreteVariable(*Scope, IV);
const MachineInstr *MInsn = Ranges.front().first;
assert(MInsn->isDebugValue() && "History must begin with debug value");
ensureAbstractVariableIsCreatedIfScoped(IV, Scope->getScopeNode());
ConcreteVariables.push_back(make_unique<DbgVariable>(MInsn, this));
DbgVariable *RegVar = ConcreteVariables.back().get();
InfoHolder.addScopeVariable(Scope, RegVar);
RegVar->initializeDbgValue(MInsn);
// Check if the first DBG_VALUE is valid for the rest of the function.
if (Ranges.size() == 1 && Ranges.front().second == nullptr)
@@ -930,15 +935,9 @@ void DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU,
// Collect info for variables that were optimized out.
for (const DILocalVariable *DV : SP->getVariables()) {
if (!Processed.insert(InlinedVariable(DV, nullptr)).second)
continue;
if (LexicalScope *Scope = LScopes.findLexicalScope(DV->getScope())) {
ensureAbstractVariableIsCreatedIfScoped(InlinedVariable(DV, nullptr),
Scope->getScopeNode());
ConcreteVariables.push_back(make_unique<DbgVariable>(
DV, /* IA */ nullptr, /* Expr */ nullptr, this));
InfoHolder.addScopeVariable(Scope, ConcreteVariables.back().get());
}
if (Processed.insert(InlinedVariable(DV, nullptr)).second)
if (LexicalScope *Scope = LScopes.findLexicalScope(DV->getScope()))
createConcreteVariable(*Scope, InlinedVariable(DV, nullptr));
}
}