Move the complex address expression out of DIVariable and into an extra

argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.

Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.

By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.

The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)

This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.

What this patch doesn't do:

This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.

http://reviews.llvm.org/D4919
rdar://problem/17994491

Thanks to dblaikie and dexonsmith for reviewing this patch!

Note: I accidentally committed a bogus older version of this patch previously.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218787 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Adrian Prantl
2014-10-01 18:55:02 +00:00
parent 0ad623bb0d
commit 02474a32eb
257 changed files with 1534 additions and 1377 deletions

View File

@@ -26,25 +26,30 @@ class DebugLocEntry {
public:
/// A single location or constant.
struct Value {
Value(const MDNode *Var, int64_t i)
: Variable(Var), EntryKind(E_Integer) {
Value(const MDNode *Var, const MDNode *Expr, int64_t i)
: Variable(Var), Expression(Expr), EntryKind(E_Integer) {
Constant.Int = i;
}
Value(const MDNode *Var, const ConstantFP *CFP)
: Variable(Var), EntryKind(E_ConstantFP) {
Value(const MDNode *Var, const MDNode *Expr, const ConstantFP *CFP)
: Variable(Var), Expression(Expr), EntryKind(E_ConstantFP) {
Constant.CFP = CFP;
}
Value(const MDNode *Var, const ConstantInt *CIP)
: Variable(Var), EntryKind(E_ConstantInt) {
Value(const MDNode *Var, const MDNode *Expr, const ConstantInt *CIP)
: Variable(Var), Expression(Expr), EntryKind(E_ConstantInt) {
Constant.CIP = CIP;
}
Value(const MDNode *Var, MachineLocation Loc)
: Variable(Var), EntryKind(E_Location), Loc(Loc) {
Value(const MDNode *Var, const MDNode *Expr, MachineLocation Loc)
: Variable(Var), Expression(Expr), EntryKind(E_Location), Loc(Loc) {
assert(DIVariable(Var).Verify());
assert(DIExpression(Expr).Verify());
}
// The variable to which this location entry corresponds.
const MDNode *Variable;
// Any complex address location expression for this Value.
const MDNode *Expression;
// Type of entry that this represents.
enum EntryType { E_Location, E_Integer, E_ConstantFP, E_ConstantInt };
enum EntryType EntryKind;
@@ -69,7 +74,8 @@ public:
MachineLocation getLoc() const { return Loc; }
const MDNode *getVariableNode() const { return Variable; }
DIVariable getVariable() const { return DIVariable(Variable); }
bool isVariablePiece() const { return getVariable().isVariablePiece(); }
bool isVariablePiece() const { return getExpression().isVariablePiece(); }
DIExpression getExpression() const { return DIExpression(Expression); }
friend bool operator==(const Value &, const Value &);
friend bool operator<(const Value &, const Value &);
};
@@ -90,11 +96,13 @@ public:
// list of values.
// Return true if the merge was successful.
bool MergeValues(const DebugLocEntry &Next) {
if (Begin == Next.Begin && Values.size() > 0 && Next.Values.size() > 0) {
if (Begin == Next.Begin) {
DIExpression Expr(Values[0].Expression);
DIVariable Var(Values[0].Variable);
DIExpression NextExpr(Next.Values[0].Expression);
DIVariable NextVar(Next.Values[0].Variable);
if (Var.getName() == NextVar.getName() &&
Var.isVariablePiece() && NextVar.isVariablePiece()) {
if (Var == NextVar && Expr.isVariablePiece() &&
NextExpr.isVariablePiece()) {
addValues(Next.Values);
End = Next.End;
return true;
@@ -133,8 +141,10 @@ public:
std::sort(Values.begin(), Values.end());
Values.erase(std::unique(Values.begin(), Values.end(),
[](const Value &A, const Value &B) {
return A.getVariable() == B.getVariable();
}), Values.end());
return A.getVariable() == B.getVariable() &&
A.getExpression() == B.getExpression();
}),
Values.end());
}
};
@@ -144,7 +154,10 @@ inline bool operator==(const DebugLocEntry::Value &A,
if (A.EntryKind != B.EntryKind)
return false;
if (A.getVariable() != B.getVariable())
if (A.Expression != B.Expression)
return false;
if (A.Variable != B.Variable)
return false;
switch (A.EntryKind) {
@@ -163,7 +176,8 @@ inline bool operator==(const DebugLocEntry::Value &A,
/// Compare two pieces based on their offset.
inline bool operator<(const DebugLocEntry::Value &A,
const DebugLocEntry::Value &B) {
return A.getVariable().getPieceOffset() < B.getVariable().getPieceOffset();
return A.getExpression().getPieceOffset() <
B.getExpression().getPieceOffset();
}
}