diff options
author | Bjorn Pettersson <bjorn.a.pettersson@ericsson.com> | 2018-07-03 11:29:00 +0000 |
---|---|---|
committer | Bjorn Pettersson <bjorn.a.pettersson@ericsson.com> | 2018-07-03 11:29:00 +0000 |
commit | 8dd6cf711f75f296cdeae2be7c6760b29cc68f57 (patch) | |
tree | a1e3029820549696b5c0108370d8382bbc1e0dac /llvm/lib | |
parent | fd171f2f893d0bf1e7d2af0200c31a7df32b2553 (diff) | |
download | bcm5719-llvm-8dd6cf711f75f296cdeae2be7c6760b29cc68f57.tar.gz bcm5719-llvm-8dd6cf711f75f296cdeae2be7c6760b29cc68f57.zip |
[DebugInfo] Corrections for salvageDebugInfo
Summary:
When salvaging a dbg.declare/dbg.addr we should not add
DW_OP_stack_value to the DIExpression
(see test/Transforms/InstCombine/salvage-dbg-declare.ll).
Consider this example
%vla = alloca i32, i64 2
call void @llvm.dbg.declare(metadata i32* %vla, metadata !1, metadata !DIExpression())
Instcombine will turn it into
%vla1 = alloca [2 x i32]
%vla1.sub = getelementptr inbounds [2 x i32], [2 x i32]* %vla, i64 0, i64 0
call void @llvm.dbg.declare(metadata [2 x i32]* %vla1.sub, metadata !19, metadata !DIExpression())
If the GEP can be eliminated, then the dbg.declare will be salvaged
and we should get
%vla1 = alloca [2 x i32]
call void @llvm.dbg.declare(metadata [2 x i32]* %vla1, metadata !19, metadata !DIExpression())
The problem was that salvageDebugInfo did not recognize dbg.declare
as being indirect (%vla1 points to the value, it does not hold the
value), so we incorrectly got
call void @llvm.dbg.declare(metadata [2 x i32]* %vla1, metadata !19, metadata !DIExpression(DW_OP_stack_value))
I also made sure that llvm::salvageDebugInfo and
DIExpression::prependOpcodes do not add DW_OP_stack_value to
the DIExpression in case no new operands are added to the
DIExpression. That way we avoid to, unneccessarily, turn a
register location expression into an implicit location expression
in some situations (see test11 in test/Transforms/LICM/sinking.ll).
Reviewers: aprantl, vsk
Reviewed By: aprantl, vsk
Subscribers: JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D48837
llvm-svn: 336191
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/DebugInfoMetadata.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 9 |
2 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp index a9f96e2549d..217cec3e937 100644 --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -803,6 +803,9 @@ DIExpression *DIExpression::prepend(const DIExpression *Expr, bool DerefBefore, DIExpression *DIExpression::prependOpcodes(const DIExpression *Expr, SmallVectorImpl<uint64_t> &Ops, bool StackValue) { + // If there are no ops to prepend, do not even add the DW_OP_stack_value. + if (Ops.empty()) + StackValue = false; if (Expr) for (auto Op : Expr->expr_ops()) { // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment. diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index eb13ae0f499..722f645d1a5 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1605,8 +1605,13 @@ void llvm::salvageDebugInfo(Instruction &I) { auto doSalvage = [&](DbgInfoIntrinsic *DII, SmallVectorImpl<uint64_t> &Ops) { auto *DIExpr = DII->getExpression(); - DIExpr = - DIExpression::prependOpcodes(DIExpr, Ops, DIExpression::WithStackValue); + if (!Ops.empty()) { + // Do not add DW_OP_stack_value for DbgDeclare and DbgAddr, because they + // are implicitly pointing out the value as a DWARF memory location + // description. + bool WithStackValue = isa<DbgValueInst>(DII); + DIExpr = DIExpression::prependOpcodes(DIExpr, Ops, WithStackValue); + } DII->setOperand(0, wrapMD(I.getOperand(0))); DII->setOperand(2, MetadataAsValue::get(I.getContext(), DIExpr)); LLVM_DEBUG(dbgs() << "SALVAGE: " << *DII << '\n'); |