diff options
author | Vedant Kumar <vsk@apple.com> | 2018-07-06 17:32:39 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2018-07-06 17:32:39 +0000 |
commit | 6379a62250cc49a9eb6f7a403eb868c08478bc87 (patch) | |
tree | cc7aca68de3e1ebc68ad24593e6a988e8c8acf58 /llvm/lib/IR/DebugInfoMetadata.cpp | |
parent | a212b0bc18c9095d6580de6a85740114d1e94916 (diff) | |
download | bcm5719-llvm-6379a62250cc49a9eb6f7a403eb868c08478bc87.tar.gz bcm5719-llvm-6379a62250cc49a9eb6f7a403eb868c08478bc87.zip |
[Local] replaceAllDbgUsesWith: Update debug values before RAUW
The replaceAllDbgUsesWith utility helps passes preserve debug info when
replacing one value with another.
This improves upon the existing insertReplacementDbgValues API by:
- Updating debug intrinsics in-place, while preventing use-before-def of
the replacement value.
- Falling back to salvageDebugInfo when a replacement can't be made.
- Moving the responsibiliy for rewriting llvm.dbg.* DIExpressions into
common utility code.
Along with the API change, this teaches replaceAllDbgUsesWith how to
create DIExpressions for three basic integer and pointer conversions:
- The no-op conversion. Applies when the values have the same width, or
have bit-for-bit compatible pointer representations.
- Truncation. Applies when the new value is wider than the old one.
- Zero/sign extension. Applies when the new value is narrower than the
old one.
Testing:
- check-llvm, check-clang, a stage2 `-g -O3` build of clang,
regression/unit testing.
- This resolves a number of mis-sized dbg.value diagnostics from
Debugify.
Differential Revision: https://reviews.llvm.org/D48676
llvm-svn: 336451
Diffstat (limited to 'llvm/lib/IR/DebugInfoMetadata.cpp')
-rw-r--r-- | llvm/lib/IR/DebugInfoMetadata.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp index 5d9e3405880..0124980485d 100644 --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -283,6 +283,19 @@ DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag, Ops); } +Optional<DIBasicType::Signedness> DIBasicType::getSignedness() const { + switch (getEncoding()) { + case dwarf::DW_ATE_signed: + case dwarf::DW_ATE_signed_char: + return Signedness::Signed; + case dwarf::DW_ATE_unsigned: + case dwarf::DW_ATE_unsigned_char: + return Signedness::Unsigned; + default: + return None; + } +} + DIDerivedType *DIDerivedType::getImpl( LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, @@ -733,6 +746,9 @@ bool DIExpression::isValid() const { case dwarf::DW_OP_shra: case dwarf::DW_OP_deref: case dwarf::DW_OP_xderef: + case dwarf::DW_OP_lit0: + case dwarf::DW_OP_not: + case dwarf::DW_OP_dup: break; } } @@ -826,6 +842,42 @@ DIExpression *DIExpression::prependOpcodes(const DIExpression *Expr, return DIExpression::get(Expr->getContext(), Ops); } +DIExpression *DIExpression::appendToStack(const DIExpression *Expr, + ArrayRef<uint64_t> Ops) { + assert(Expr && !Ops.empty() && "Can't append ops to this expression"); + + // Append a DW_OP_deref after Expr's current op list if it's non-empty and + // has no DW_OP_stack_value. + // + // Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?. + Optional<FragmentInfo> FI = Expr->getFragmentInfo(); + unsigned DropUntilStackValue = FI.hasValue() ? 3 : 0; + bool NeedsDeref = + (Expr->getNumElements() > DropUntilStackValue) && + (Expr->getElements().drop_back(DropUntilStackValue).back() != + dwarf::DW_OP_stack_value); + + // Copy Expr's current op list, add a DW_OP_deref if needed, and ensure that + // a DW_OP_stack_value is present. + SmallVector<uint64_t, 16> NewOps; + for (auto Op : Expr->expr_ops()) { + if (Op.getOp() == dwarf::DW_OP_stack_value || + Op.getOp() == dwarf::DW_OP_LLVM_fragment) + break; + Op.appendToVector(NewOps); + } + if (NeedsDeref) + NewOps.push_back(dwarf::DW_OP_deref); + NewOps.append(Ops.begin(), Ops.end()); + NewOps.push_back(dwarf::DW_OP_stack_value); + + // If Expr is a fragment, make the new expression a fragment as well. + if (FI) + NewOps.append( + {dwarf::DW_OP_LLVM_fragment, FI->OffsetInBits, FI->SizeInBits}); + return DIExpression::get(Expr->getContext(), NewOps); +} + Optional<DIExpression *> DIExpression::createFragmentExpression( const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) { SmallVector<uint64_t, 8> Ops; |