Skip to content

Commit

Permalink
[NFC][Assignment Tracking] Add is/setKillAddress
Browse files Browse the repository at this point in the history
Unlike D140903 this patch folds in treating an empty metadata address component
of a dbg.assign the same as undef because it was already being treated that way
in the AssignmentTrackingAnalysis pass.

Reviewed By: scott.linder

Differential Revision: https://reviews.llvm.org/D141125
  • Loading branch information
OCHyams committed Jan 12, 2023
1 parent 840edd8 commit 83f7f86
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
7 changes: 7 additions & 0 deletions llvm/include/llvm/IR/IntrinsicInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,13 @@ class DbgAssignIntrinsic : public DbgValueInst {
}
void setAssignId(DIAssignID *New);
void setAddress(Value *V);
/// Kill the address component.
void setKillAddress();
/// Check whether this kills the address component. This doesn't take into
/// account the position of the intrinsic, therefore a returned value of false
/// does not guarentee the address is a valid location for the variable at the
/// intrinsic's position in IR.
bool isKillAddress() const;
void setValue(Value *V);
/// \name Casting methods
/// @{
Expand Down
16 changes: 8 additions & 8 deletions llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,11 @@ void AssignmentTrackingLowering::emitDbgValue(
const auto *DAI = cast<DbgAssignIntrinsic>(Source);
// Check the address hasn't been dropped (e.g. the debug uses may not have
// been replaced before deleting a Value).
if (Value *Val = DAI->getAddress()) {
if (DAI->isKillAddress()) {
// The address isn't valid so treat this as a non-memory def.
Kind = LocKind::Val;
} else {
Value *Val = DAI->getAddress();
DIExpression *Expr = DAI->getAddressExpression();
assert(!Expr->getFragmentInfo() &&
"fragment info should be stored in value-expression only");
Expand All @@ -1279,9 +1283,6 @@ void AssignmentTrackingLowering::emitDbgValue(
walkToAllocaAndPrependOffsetDeref(Layout, Val, Expr);
Emit(Val, Expr);
return;
} else {
// The address isn't valid so treat this as a non-memory def.
Kind = LocKind::Val;
}
}

Expand Down Expand Up @@ -1483,11 +1484,10 @@ void AssignmentTrackingLowering::processDbgAssign(DbgAssignIntrinsic &DAI,
// that an assignment happened here, and we know that specific assignment
// was the last one to take place in memory for this variable.
LocKind Kind;
if (isa<UndefValue>(DAI.getAddress())) {
// Address may be undef to indicate that although the store does take
// place, this part of the original store has been elided.
if (DAI.isKillAddress()) {
LLVM_DEBUG(
dbgs() << "Val, Stack matches Debug program but address is undef\n";);
dbgs()
<< "Val, Stack matches Debug program but address is killed\n";);
Kind = LocKind::Val;
} else {
LLVM_DEBUG(dbgs() << "Mem, Stack matches Debug program\n";);
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/IR/IntrinsicInst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ void DbgAssignIntrinsic::setAddress(Value *V) {
MetadataAsValue::get(getContext(), ValueAsMetadata::get(V)));
}

void DbgAssignIntrinsic::setKillAddress() {
if (isKillAddress())
return;
setAddress(UndefValue::get(getAddress()->getType()));
}

bool DbgAssignIntrinsic::isKillAddress() const {
Value *Addr = getAddress();
return !Addr || isa<UndefValue>(Addr);
}

void DbgAssignIntrinsic::setValue(Value *V) {
setOperand(OpValue,
MetadataAsValue::get(getContext(), ValueAsMetadata::get(V)));
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ static void shortenAssignment(Instruction *Inst, uint64_t OldOffsetInBits,
LinkToNothing = DIAssignID::getDistinct(Inst->getContext());
NewAssign->setAssignId(LinkToNothing);
NewAssign->setExpression(CreateDeadFragExpr());
NewAssign->setAddress(UndefValue::get(DAI->getAddress()->getType()));
NewAssign->setKillAddress();
}
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,7 @@ static void salvageDbgAssignAddress(DbgAssignIntrinsic *DAI) {
DAI->setAddress(NewV);
DAI->setAddressExpression(SalvagedExpr);
} else {
DAI->setAddress(UndefValue::get(I->getType()));
DAI->setKillAddress();
}
}

Expand Down

0 comments on commit 83f7f86

Please sign in to comment.