Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions llvm/lib/Transforms/Scalar/SROA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
uint64_t SliceSizeInBits, Instruction *OldInst,
Instruction *Inst, Value *Dest, Value *Value,
const DataLayout &DL) {
// If we want allocas to be migrated using this helper then we need to ensure
// that the BaseFragments map code still works. A simple solution would be
// to choose to always clone alloca dbg_assigns (rather than sometimes
// "stealing" them).
assert(!isa<AllocaInst>(Inst) && "Unexpected alloca");

auto DVRAssignMarkerRange = at::getDVRAssignmentMarkers(OldInst);
// Nothing to do if OldInst has no linked dbg.assign intrinsics.
if (DVRAssignMarkerRange.empty())
Expand Down Expand Up @@ -425,11 +431,22 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
Inst->setMetadata(LLVMContext::MD_DIAssignID, NewID);
}

::Value *NewValue = Value ? Value : DbgAssign->getValue();
DbgVariableRecord *NewAssign = cast<DbgVariableRecord>(cast<DbgRecord *>(
DIB.insertDbgAssign(Inst, NewValue, DbgAssign->getVariable(), Expr,
Dest, DIExpression::get(Expr->getContext(), {}),
DbgAssign->getDebugLoc())));
DbgVariableRecord *NewAssign;
if (IsSplit) {
::Value *NewValue = Value ? Value : DbgAssign->getValue();
NewAssign = cast<DbgVariableRecord>(cast<DbgRecord *>(
DIB.insertDbgAssign(Inst, NewValue, DbgAssign->getVariable(), Expr,
Dest, DIExpression::get(Expr->getContext(), {}),
DbgAssign->getDebugLoc())));
} else {
// The store is not split, simply steal the existing dbg_assign.
NewAssign = DbgAssign;
NewAssign->setAssignId(NewID); // FIXME: Can we avoid generating new IDs?
NewAssign->setAddress(Dest);
if (Value)
NewAssign->replaceVariableLocationOp(0u, Value);
assert(Expr == NewAssign->getExpression());
}

// If we've updated the value but the original dbg.assign has an arglist
// then kill it now - we can't use the requested new value.
Expand Down Expand Up @@ -460,9 +477,10 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
// noted as slightly offset (in code) from the store. In practice this
// should have little effect on the debugging experience due to the fact
// that all the split stores should get the same line number.
NewAssign->moveBefore(DbgAssign->getIterator());

NewAssign->setDebugLoc(DbgAssign->getDebugLoc());
if (NewAssign != DbgAssign) {
NewAssign->moveBefore(DbgAssign->getIterator());
NewAssign->setDebugLoc(DbgAssign->getDebugLoc());
}
LLVM_DEBUG(dbgs() << "Created new assign: " << *NewAssign << "\n");
};

Expand Down
Loading