AsmPrinter: Stop storing MDLocalVariable in DebugLocEntry

Stop storing the `MDLocalVariable` in the `DebugLocEntry::Value`s.  We
generate the list of `DebugLocEntry`s separately for each
variable/inlined-at pair, so the variable never actually changes here.

This is effectively NFC (aside from saving some memory and CPU time).

llvm-svn: 235202
This commit is contained in:
Duncan P. N. Exon Smith 2015-04-17 16:33:37 +00:00
parent fba25d6e9b
commit 546c8be967
2 changed files with 19 additions and 31 deletions

View File

@ -28,27 +28,23 @@ class DebugLocEntry {
public: public:
/// \brief A single location or constant. /// \brief A single location or constant.
struct Value { struct Value {
Value(const MDNode *Var, const MDNode *Expr, int64_t i) Value(const MDNode *Expr, int64_t i)
: Variable(Var), Expression(Expr), EntryKind(E_Integer) { : Expression(Expr), EntryKind(E_Integer) {
Constant.Int = i; Constant.Int = i;
} }
Value(const MDNode *Var, const MDNode *Expr, const ConstantFP *CFP) Value(const MDNode *Expr, const ConstantFP *CFP)
: Variable(Var), Expression(Expr), EntryKind(E_ConstantFP) { : Expression(Expr), EntryKind(E_ConstantFP) {
Constant.CFP = CFP; Constant.CFP = CFP;
} }
Value(const MDNode *Var, const MDNode *Expr, const ConstantInt *CIP) Value(const MDNode *Expr, const ConstantInt *CIP)
: Variable(Var), Expression(Expr), EntryKind(E_ConstantInt) { : Expression(Expr), EntryKind(E_ConstantInt) {
Constant.CIP = CIP; Constant.CIP = CIP;
} }
Value(const MDNode *Var, const MDNode *Expr, MachineLocation Loc) Value(const MDNode *Expr, MachineLocation Loc)
: Variable(Var), Expression(Expr), EntryKind(E_Location), Loc(Loc) { : Expression(Expr), EntryKind(E_Location), Loc(Loc) {
assert(isa<MDLocalVariable>(Var));
assert(cast<MDExpression>(Expr)->isValid()); assert(cast<MDExpression>(Expr)->isValid());
} }
/// The variable to which this location entry corresponds.
const MDNode *Variable;
/// Any complex address location expression for this Value. /// Any complex address location expression for this Value.
const MDNode *Expression; const MDNode *Expression;
@ -74,7 +70,6 @@ public:
const ConstantFP *getConstantFP() const { return Constant.CFP; } const ConstantFP *getConstantFP() const { return Constant.CFP; }
const ConstantInt *getConstantInt() const { return Constant.CIP; } const ConstantInt *getConstantInt() const { return Constant.CIP; }
MachineLocation getLoc() const { return Loc; } MachineLocation getLoc() const { return Loc; }
DIVariable getVariable() const { return cast<MDLocalVariable>(Variable); }
bool isBitPiece() const { return getExpression()->isBitPiece(); } bool isBitPiece() const { return getExpression()->isBitPiece(); }
DIExpression getExpression() const { DIExpression getExpression() const {
return cast_or_null<MDExpression>(Expression); return cast_or_null<MDExpression>(Expression);
@ -103,11 +98,9 @@ public:
bool MergeValues(const DebugLocEntry &Next) { bool MergeValues(const DebugLocEntry &Next) {
if (Begin == Next.Begin) { if (Begin == Next.Begin) {
DIExpression Expr = cast_or_null<MDExpression>(Values[0].Expression); DIExpression Expr = cast_or_null<MDExpression>(Values[0].Expression);
DIVariable Var = cast_or_null<MDLocalVariable>(Values[0].Variable);
DIExpression NextExpr = DIExpression NextExpr =
cast_or_null<MDExpression>(Next.Values[0].Expression); cast_or_null<MDExpression>(Next.Values[0].Expression);
DIVariable NextVar = cast_or_null<MDLocalVariable>(Next.Values[0].Variable); if (Expr->isBitPiece() && NextExpr->isBitPiece()) {
if (Var == NextVar && Expr->isBitPiece() && NextExpr->isBitPiece()) {
addValues(Next.Values); addValues(Next.Values);
End = Next.End; End = Next.End;
return true; return true;
@ -144,12 +137,12 @@ public:
// Remove any duplicate entries by dropping all but the first. // Remove any duplicate entries by dropping all but the first.
void sortUniqueValues() { void sortUniqueValues() {
std::sort(Values.begin(), Values.end()); std::sort(Values.begin(), Values.end());
Values.erase(std::unique(Values.begin(), Values.end(), Values.erase(
[](const Value &A, const Value &B) { std::unique(
return A.getVariable() == B.getVariable() && Values.begin(), Values.end(), [](const Value &A, const Value &B) {
A.getExpression() == B.getExpression(); return A.getExpression() == B.getExpression();
}), }),
Values.end()); Values.end());
} }
/// \brief Lower this entry into a DWARF expression. /// \brief Lower this entry into a DWARF expression.
@ -170,9 +163,6 @@ inline bool operator==(const DebugLocEntry::Value &A,
if (A.Expression != B.Expression) if (A.Expression != B.Expression)
return false; return false;
if (A.Variable != B.Variable)
return false;
switch (A.EntryKind) { switch (A.EntryKind) {
case DebugLocEntry::Value::E_Location: case DebugLocEntry::Value::E_Location:
return A.Loc == B.Loc; return A.Loc == B.Loc;

View File

@ -734,7 +734,6 @@ void DwarfDebug::collectVariableInfoFromMMITable(
// Get .debug_loc entry for the instruction range starting at MI. // Get .debug_loc entry for the instruction range starting at MI.
static DebugLocEntry::Value getDebugLocValue(const MachineInstr *MI) { static DebugLocEntry::Value getDebugLocValue(const MachineInstr *MI) {
const MDNode *Expr = MI->getDebugExpression(); const MDNode *Expr = MI->getDebugExpression();
const MDNode *Var = MI->getDebugVariable();
assert(MI->getNumOperands() == 4); assert(MI->getNumOperands() == 4);
if (MI->getOperand(0).isReg()) { if (MI->getOperand(0).isReg()) {
@ -745,14 +744,14 @@ static DebugLocEntry::Value getDebugLocValue(const MachineInstr *MI) {
MLoc.set(MI->getOperand(0).getReg()); MLoc.set(MI->getOperand(0).getReg());
else else
MLoc.set(MI->getOperand(0).getReg(), MI->getOperand(1).getImm()); MLoc.set(MI->getOperand(0).getReg(), MI->getOperand(1).getImm());
return DebugLocEntry::Value(Var, Expr, MLoc); return DebugLocEntry::Value(Expr, MLoc);
} }
if (MI->getOperand(0).isImm()) if (MI->getOperand(0).isImm())
return DebugLocEntry::Value(Var, Expr, MI->getOperand(0).getImm()); return DebugLocEntry::Value(Expr, MI->getOperand(0).getImm());
if (MI->getOperand(0).isFPImm()) if (MI->getOperand(0).isFPImm())
return DebugLocEntry::Value(Var, Expr, MI->getOperand(0).getFPImm()); return DebugLocEntry::Value(Expr, MI->getOperand(0).getFPImm());
if (MI->getOperand(0).isCImm()) if (MI->getOperand(0).isCImm())
return DebugLocEntry::Value(Var, Expr, MI->getOperand(0).getCImm()); return DebugLocEntry::Value(Expr, MI->getOperand(0).getCImm());
llvm_unreachable("Unexpected 4-operand DBG_VALUE instruction!"); llvm_unreachable("Unexpected 4-operand DBG_VALUE instruction!");
} }
@ -865,7 +864,6 @@ DwarfDebug::buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
DEBUG({ DEBUG({
dbgs() << CurEntry->getValues().size() << " Values:\n"; dbgs() << CurEntry->getValues().size() << " Values:\n";
for (auto Value : CurEntry->getValues()) { for (auto Value : CurEntry->getValues()) {
Value.getVariable()->dump();
Value.getExpression()->dump(); Value.getExpression()->dump();
} }
dbgs() << "-----\n"; dbgs() << "-----\n";