diff options
author | Stephen Tozer <stephen.tozer@sony.com> | 2019-05-16 14:41:01 +0000 |
---|---|---|
committer | Stephen Tozer <stephen.tozer@sony.com> | 2019-05-16 14:41:01 +0000 |
commit | 6f59b4b6d95c3de98eee3f83cc53dc4eb943f7a2 (patch) | |
tree | 1754ab3b7851155c545ad0d8f77c494b6e763190 /llvm/lib/Transforms/Utils/Local.cpp | |
parent | 17624a9aad190441d22b30eb008328d92625aa95 (diff) | |
download | llvm-6f59b4b6d95c3de98eee3f83cc53dc4eb943f7a2.zip llvm-6f59b4b6d95c3de98eee3f83cc53dc4eb943f7a2.tar.gz llvm-6f59b4b6d95c3de98eee3f83cc53dc4eb943f7a2.tar.bz2 |
Resubmit: [Salvage] Change salvage debug info implementation to use DW_OP_LLVM_convert where needed
Fixes issue: https://bugs.llvm.org/show_bug.cgi?id=40645
Previously, LLVM had no functional way of performing casts inside of a
DIExpression(), which made salvaging cast instructions other than Noop casts
impossible. With the recent addition of DW_OP_LLVM_convert this salvaging is
now possible, and so can be used to fix the attached bug as well as any cases
where SExt instruction results are lost in the debugging metadata. This patch
introduces this fix by expanding the salvage debug info method to cover these
cases using the new operator.
Differential revision: https://reviews.llvm.org/D61184
llvm-svn: 360902
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 2a4e905..04e6cbb 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1690,8 +1690,27 @@ DIExpression *llvm::salvageDebugInfoImpl(Instruction &I, // No-op casts and zexts are irrelevant for debug info. if (CI->isNoopCast(DL) || isa<ZExtInst>(&I)) return SrcDIExpr; - return nullptr; - } else if (auto *GEP = dyn_cast<GetElementPtrInst>(&I)) { + + Type *Type = CI->getType(); + // Casts other than Trunc or SExt to scalar types cannot be salvaged. + if (Type->isVectorTy() || (!isa<TruncInst>(&I) && !isa<SExtInst>(&I))) + return nullptr; + + Value *FromValue = CI->getOperand(0); + unsigned FromTypeBitSize = FromValue->getType()->getScalarSizeInBits(); + + unsigned ToTypeBitSize = Type->getScalarSizeInBits(); + + // The result of the cast will be sign extended iff the instruction is a + // SExt; signedness is otherwise irrelevant on the expression stack. + unsigned Encoding = + isa<SExtInst>(&I) ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned; + + return applyOps({dwarf::DW_OP_LLVM_convert, FromTypeBitSize, Encoding, + dwarf::DW_OP_LLVM_convert, ToTypeBitSize, Encoding}); + } + + if (auto *GEP = dyn_cast<GetElementPtrInst>(&I)) { unsigned BitWidth = M.getDataLayout().getIndexSizeInBits(GEP->getPointerAddressSpace()); // Rewrite a constant GEP into a DIExpression. |