diff options
author | Orlando Cazalet-Hyams <orlando.hyams@sony.com> | 2023-12-12 14:57:51 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-12 14:57:51 +0000 |
commit | c4e764ea24eb02b6ec34038061cee8ff94c0f34c (patch) | |
tree | 61de6147b448c1324dba8049060b4928c8618168 /llvm/lib/Transforms/Utils/Local.cpp | |
parent | f22a65c158b4195120e250bf5decaed3ea5ac3bd (diff) | |
download | llvm-c4e764ea24eb02b6ec34038061cee8ff94c0f34c.zip llvm-c4e764ea24eb02b6ec34038061cee8ff94c0f34c.tar.gz llvm-c4e764ea24eb02b6ec34038061cee8ff94c0f34c.tar.bz2 |
[RemoveDIs] Update ConvertDebugDeclareToDebugValue after #72276 (#73508)
That patch was missing a recent change to the non-DPValue StoreInst overload.
Add it to the DPValue version. This is tested by
`llvm/tests/Transforms/Mem2Reg/dbg_declare_to_value_conversions.ll`,
which already has `--try-experimental-debuginfo-iterators`. It doesn't
fail currently because until #74090 lands the declares are not converted
to DPValues.
The tests will become "live" once #74090 lands (see for more info).
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index ff92abb..63dcb64 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1775,23 +1775,37 @@ void llvm::ConvertDebugDeclareToDebugValue(DPValue *DPV, StoreInst *SI, DebugLoc NewLoc = getDebugValueLoc(DPV); - if (!valueCoversEntireFragment(DV->getType(), DPV)) { - // FIXME: If storing to a part of the variable described by the dbg.declare, - // then we want to insert a DPValue.value for the corresponding fragment. - LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to DPValue: " << *DPV - << '\n'); - // For now, when there is a store to parts of the variable (but we do not - // know which part) we insert an DPValue record to indicate that we know - // nothing about the variable's content. - DV = UndefValue::get(DV->getType()); - ValueAsMetadata *DVAM = ValueAsMetadata::get(DV); - DPValue *NewDPV = new DPValue(DVAM, DIVar, DIExpr, NewLoc.get()); - SI->getParent()->insertDPValueBefore(NewDPV, SI->getIterator()); + // If the alloca describes the variable itself, i.e. the expression in the + // dbg.declare doesn't start with a dereference, we can perform the + // conversion if the value covers the entire fragment of DII. + // If the alloca describes the *address* of DIVar, i.e. DIExpr is + // *just* a DW_OP_deref, we use DV as is for the dbg.value. + // We conservatively ignore other dereferences, because the following two are + // not equivalent: + // dbg.declare(alloca, ..., !Expr(deref, plus_uconstant, 2)) + // dbg.value(DV, ..., !Expr(deref, plus_uconstant, 2)) + // The former is adding 2 to the address of the variable, whereas the latter + // is adding 2 to the value of the variable. As such, we insist on just a + // deref expression. + bool CanConvert = + DIExpr->isDeref() || (!DIExpr->startsWithDeref() && + valueCoversEntireFragment(DV->getType(), DPV)); + if (CanConvert) { + insertDbgValueOrDPValue(Builder, DV, DIVar, DIExpr, NewLoc, + SI->getIterator()); return; } + // FIXME: If storing to a part of the variable described by the dbg.declare, + // then we want to insert a dbg.value for the corresponding fragment. + LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to dbg.value: " << *DPV + << '\n'); assert(UseNewDbgInfoFormat); - // Create a DPValue directly and insert. + + // For now, when there is a store to parts of the variable (but we do not + // know which part) we insert an dbg.value intrinsic to indicate that we + // know nothing about the variable's content. + DV = UndefValue::get(DV->getType()); ValueAsMetadata *DVAM = ValueAsMetadata::get(DV); DPValue *NewDPV = new DPValue(DVAM, DIVar, DIExpr, NewLoc.get()); SI->getParent()->insertDPValueBefore(NewDPV, SI->getIterator()); |