Skip to content

Commit

Permalink
[Instruction] Set metadata uses to undef on deletion
Browse files Browse the repository at this point in the history
Summary:
Replace any extant metadata uses of a dying instruction with undef to
preserve debug info accuracy. Some alternatives include:

- Treat Instruction like any other Value, and point its extant metadata
  uses to an empty ValueAsMetadata node. This makes extant dbg.value uses
  trivially dead (i.e. fair game for deletion in many passes), leading to
  stale dbg.values being in effect for too long.

- Call salvageDebugInfoOrMarkUndef. Not needed to make instruction removal
  correct. OTOH results in wasted work in some common cases (e.g. when all
  instructions in a BasicBlock are deleted).

This came up while discussing some basic cases in
https://reviews.llvm.org/D80052.

Reviewers: jmorse, TWeaver, aprantl, dexonsmith, jdoerfert

Subscribers: jholewinski, qcolombet, hiraditya, jfb, sstefan1, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80264
  • Loading branch information
vedantk committed May 21, 2020
1 parent bf242c0 commit 77ffce6
Show file tree
Hide file tree
Showing 6 changed files with 8,629 additions and 8,555 deletions.
13 changes: 13 additions & 0 deletions llvm/lib/IR/Instruction.cpp
Expand Up @@ -43,6 +43,19 @@ Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,

Instruction::~Instruction() {
assert(!Parent && "Instruction still linked in the program!");

// Replace any extant metadata uses of this instruction with undef to
// preserve debug info accuracy. Some alternatives include:
// - Treat Instruction like any other Value, and point its extant metadata
// uses to an empty ValueAsMetadata node. This makes extant dbg.value uses
// trivially dead (i.e. fair game for deletion in many passes), leading to
// stale dbg.values being in effect for too long.
// - Call salvageDebugInfoOrMarkUndef. Not needed to make instruction removal
// correct. OTOH results in wasted work in some common cases (e.g. when all
// instructions in a BasicBlock are deleted).
if (isUsedByMetadata())
ValueAsMetadata::handleRAUW(this, UndefValue::get(getType()));

if (hasMetadataHashEntry())
clearMetadataHashEntries();
}
Expand Down

0 comments on commit 77ffce6

Please sign in to comment.