Skip to content

Commit 2e1c4fa

Browse files
committed
Simplify the creation of DIExpressions. (NFC)
1 parent 7eeece6 commit 2e1c4fa

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,14 +1002,7 @@ void IRGenDebugInfo::emitVariableDeclaration(
10021002

10031003
// Create the descriptor for the variable.
10041004
llvm::DILocalVariable *Var = nullptr;
1005-
llvm::DIExpression *Expr = DBuilder.createExpression();
10061005

1007-
if (Indirection) {
1008-
// Classes are always passed by reference.
1009-
int64_t Addr[] = { llvm::dwarf::DW_OP_deref };
1010-
Expr = DBuilder.createExpression(Addr);
1011-
// FIXME: assert(Flags == 0 && "Complex variables cannot have flags");
1012-
}
10131006
/// This could be Opts.Optimize if we would also unique DIVariables here.
10141007
bool Optimized = false;
10151008
Var = (ArgNo > 0)
@@ -1027,6 +1020,10 @@ void IRGenDebugInfo::emitVariableDeclaration(
10271020
ElementSizes EltSizes(DITy, DIRefMap, IndirectEnumCases);
10281021
auto Dim = EltSizes.getNext();
10291022
for (llvm::Value *Piece : Storage) {
1023+
SmallVector<uint64_t, 3> Operands;
1024+
if (Indirection)
1025+
Operands.push_back(llvm::dwarf::DW_OP_deref);
1026+
10301027
// There are variables without storage, such as "struct { func foo() {} }".
10311028
// Emit them as constant 0.
10321029
if (isa<llvm::UndefValue>(Piece))
@@ -1053,27 +1050,25 @@ void IRGenDebugInfo::emitVariableDeclaration(
10531050
assert(Dim.SizeInBits < VarSizeInBits
10541051
&& "piece covers entire var");
10551052
assert(OffsetInBits+Dim.SizeInBits <= VarSizeInBits && "pars > totum");
1056-
SmallVector<uint64_t, 3> Elts;
1057-
if (Indirection)
1058-
Elts.push_back(llvm::dwarf::DW_OP_deref);
1059-
Elts.push_back(llvm::dwarf::DW_OP_bit_piece);
1060-
Elts.push_back(OffsetInBits);
1061-
Elts.push_back(Dim.SizeInBits);
1062-
Expr = DBuilder.createExpression(Elts);
1053+
Operands.push_back(llvm::dwarf::DW_OP_bit_piece);
1054+
Operands.push_back(OffsetInBits);
1055+
Operands.push_back(Dim.SizeInBits);
10631056

10641057
auto Size = Dim.SizeInBits;
10651058
Dim = EltSizes.getNext();
10661059
OffsetInBits +=
10671060
llvm::RoundUpToAlignment(Size, Dim.AlignInBits ? Dim.AlignInBits
10681061
: SizeOfByte);
10691062
}
1070-
emitDbgIntrinsic(BB, Piece, Var, Expr, Line, Loc.Col, Scope, DS);
1063+
emitDbgIntrinsic(BB, Piece, Var, DBuilder.createExpression(Operands), Line,
1064+
Loc.Col, Scope, DS);
10711065
}
10721066

10731067
// Emit locationless intrinsic for variables that were optimized away.
10741068
if (Storage.size() == 0) {
10751069
auto *undef = llvm::UndefValue::get(DbgTy.StorageType);
1076-
emitDbgIntrinsic(BB, undef, Var, Expr, Line, Loc.Col, Scope, DS);
1070+
emitDbgIntrinsic(BB, undef, Var, DBuilder.createExpression(), Line, Loc.Col,
1071+
Scope, DS);
10771072
}
10781073
}
10791074

0 commit comments

Comments
 (0)