diff options
author | Orlando Cazalet-Hyams <orlando.hyams@sony.com> | 2024-07-08 10:14:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-08 10:14:59 +0100 |
commit | f50f7a7aa0b897ef91361d7dc159f3262d142bdc (patch) | |
tree | 462d78f0c7806299019bc045ced2e5ebe2ec095a /llvm/lib/IR/DebugInfoMetadata.cpp | |
parent | deb6b6038c3dcdca7ce21abca4fddffbe53b1403 (diff) | |
download | llvm-f50f7a7aa0b897ef91361d7dc159f3262d142bdc.zip llvm-f50f7a7aa0b897ef91361d7dc159f3262d142bdc.tar.gz llvm-f50f7a7aa0b897ef91361d7dc159f3262d142bdc.tar.bz2 |
[NFC] Add DIExpression::extractLeadingOffset (#97719)
Patch [2/x] to fix structured bindings debug info in SROA.
It extracts a constant offset from the DIExpression if there is one and fills
RemainingOps with the ops that come after it.
This function will be used in a subsequent patch.
Diffstat (limited to 'llvm/lib/IR/DebugInfoMetadata.cpp')
-rw-r--r-- | llvm/lib/IR/DebugInfoMetadata.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp index 161a30d..b4f7a9d 100644 --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -1760,6 +1760,45 @@ bool DIExpression::extractIfOffset(int64_t &Offset) const { return false; } +bool DIExpression::extractLeadingOffset( + int64_t &OffsetInBytes, SmallVectorImpl<uint64_t> &RemainingOps) const { + OffsetInBytes = 0; + RemainingOps.clear(); + + auto SingleLocEltsOpt = getSingleLocationExpressionElements(); + if (!SingleLocEltsOpt) + return false; + + auto ExprOpEnd = expr_op_iterator(SingleLocEltsOpt->end()); + auto ExprOpIt = expr_op_iterator(SingleLocEltsOpt->begin()); + while (ExprOpIt != ExprOpEnd) { + uint64_t Op = ExprOpIt->getOp(); + if (Op == dwarf::DW_OP_deref || Op == dwarf::DW_OP_deref_size || + Op == dwarf::DW_OP_deref_type || Op == dwarf::DW_OP_LLVM_fragment || + Op == dwarf::DW_OP_LLVM_extract_bits_zext || + Op == dwarf::DW_OP_LLVM_extract_bits_sext) { + break; + } else if (Op == dwarf::DW_OP_plus_uconst) { + OffsetInBytes += ExprOpIt->getArg(0); + } else if (Op == dwarf::DW_OP_constu) { + uint64_t Value = ExprOpIt->getArg(0); + ++ExprOpIt; + if (ExprOpIt->getOp() == dwarf::DW_OP_plus) + OffsetInBytes += Value; + else if (ExprOpIt->getOp() == dwarf::DW_OP_minus) + OffsetInBytes -= Value; + else + return false; + } else { + // Not a const plus/minus operation or deref. + return false; + } + ++ExprOpIt; + } + RemainingOps.append(ExprOpIt.getBase(), ExprOpEnd.getBase()); + return true; +} + bool DIExpression::hasAllLocationOps(unsigned N) const { SmallDenseSet<uint64_t, 4> SeenOps; for (auto ExprOp : expr_ops()) |