Skip to content

Commit d13341d

Browse files
authored
[RemoveDIs][NFC] Remove getAssignmentMarkers (llvm#153214)
getAssignmentMarkers was for debug intrinsics. getDVRAssignmentMarkers is used for DbgRecords.
1 parent d35686b commit d13341d

File tree

6 files changed

+18
-97
lines changed

6 files changed

+18
-97
lines changed

llvm/include/llvm/IR/DebugInfo.h

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -195,38 +195,8 @@ inline AssignmentInstRange getAssignmentInsts(const DbgVariableRecord *DVR) {
195195
return getAssignmentInsts(DVR->getAssignID());
196196
}
197197

198-
//
199-
// Utilities for enumerating llvm.dbg.assign intrinsic from an assignment ID.
200-
//
201-
/// High level: this is an iterator for llvm.dbg.assign intrinsics.
202-
/// Implementation details: this is a wrapper around Value's User iterator that
203-
/// dereferences to a DbgAssignIntrinsic ptr rather than a User ptr.
204-
class DbgAssignIt
205-
: public iterator_adaptor_base<DbgAssignIt, Value::user_iterator,
206-
typename std::iterator_traits<
207-
Value::user_iterator>::iterator_category,
208-
DbgAssignIntrinsic *, std::ptrdiff_t,
209-
DbgAssignIntrinsic **,
210-
DbgAssignIntrinsic *&> {
211-
public:
212-
DbgAssignIt(Value::user_iterator It) : iterator_adaptor_base(It) {}
213-
DbgAssignIntrinsic *operator*() const { return cast<DbgAssignIntrinsic>(*I); }
214-
};
215-
/// A range of llvm.dbg.assign intrinsics.
216-
using AssignmentMarkerRange = iterator_range<DbgAssignIt>;
217-
/// Return a range of dbg.assign intrinsics which use \ID as an operand.
218-
/// Iterators invalidated by deleting an intrinsic contained in this range.
219-
LLVM_ABI AssignmentMarkerRange getAssignmentMarkers(DIAssignID *ID);
220-
/// Return a range of dbg.assign intrinsics for which \p Inst performs the
198+
/// Return a range of dbg_assign records for which \p Inst performs the
221199
/// assignment they encode.
222-
/// Iterators invalidated by deleting an intrinsic contained in this range.
223-
inline AssignmentMarkerRange getAssignmentMarkers(const Instruction *Inst) {
224-
if (auto *ID = Inst->getMetadata(LLVMContext::MD_DIAssignID))
225-
return getAssignmentMarkers(cast<DIAssignID>(ID));
226-
else
227-
return make_range(Value::user_iterator(), Value::user_iterator());
228-
}
229-
230200
inline SmallVector<DbgVariableRecord *>
231201
getDVRAssignmentMarkers(const Instruction *Inst) {
232202
if (auto *ID = Inst->getMetadata(LLVMContext::MD_DIAssignID))

llvm/lib/IR/DebugInfo.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,29 +1896,8 @@ AssignmentInstRange at::getAssignmentInsts(DIAssignID *ID) {
18961896
return make_range(MapIt->second.begin(), MapIt->second.end());
18971897
}
18981898

1899-
AssignmentMarkerRange at::getAssignmentMarkers(DIAssignID *ID) {
1900-
assert(ID && "Expected non-null ID");
1901-
LLVMContext &Ctx = ID->getContext();
1902-
1903-
auto *IDAsValue = MetadataAsValue::getIfExists(Ctx, ID);
1904-
1905-
// The ID is only used wrapped in MetadataAsValue(ID), so lets check that
1906-
// one of those already exists first.
1907-
if (!IDAsValue)
1908-
return make_range(Value::user_iterator(), Value::user_iterator());
1909-
1910-
return make_range(IDAsValue->user_begin(), IDAsValue->user_end());
1911-
}
1912-
19131899
void at::deleteAssignmentMarkers(const Instruction *Inst) {
1914-
auto Range = getAssignmentMarkers(Inst);
1915-
SmallVector<DbgVariableRecord *> DVRAssigns = getDVRAssignmentMarkers(Inst);
1916-
if (Range.empty() && DVRAssigns.empty())
1917-
return;
1918-
SmallVector<DbgAssignIntrinsic *> ToDelete(Range.begin(), Range.end());
1919-
for (auto *DAI : ToDelete)
1920-
DAI->eraseFromParent();
1921-
for (auto *DVR : DVRAssigns)
1900+
for (auto *DVR : getDVRAssignmentMarkers(Inst))
19221901
DVR->eraseFromParent();
19231902
}
19241903

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,10 @@ Instruction *InstCombinerImpl::SimplifyAnyMemSet(AnyMemSetInst *MI) {
267267
MI->getContext(), APInt::getSplat(Len * 8, FillC->getValue()));
268268
StoreInst *S = Builder.CreateStore(FillVal, Dest, MI->isVolatile());
269269
S->copyMetadata(*MI, LLVMContext::MD_DIAssignID);
270-
auto replaceOpForAssignmentMarkers = [FillC, FillVal](auto *DbgAssign) {
270+
for (DbgVariableRecord *DbgAssign : at::getDVRAssignmentMarkers(S)) {
271271
if (llvm::is_contained(DbgAssign->location_ops(), FillC))
272272
DbgAssign->replaceVariableLocationOp(FillC, FillVal);
273-
};
274-
for_each(at::getAssignmentMarkers(S), replaceOpForAssignmentMarkers);
275-
for_each(at::getDVRAssignmentMarkers(S), replaceOpForAssignmentMarkers);
273+
}
276274

277275
S->setAlignment(Alignment);
278276
if (MI->isAtomic())

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -545,15 +545,8 @@ static void shortenAssignment(Instruction *Inst, Value *OriginalDest,
545545
};
546546

547547
// Insert an unlinked dbg.assign intrinsic for the dead fragment after each
548-
// overlapping dbg.assign intrinsic. The loop invalidates the iterators
549-
// returned by getAssignmentMarkers so save a copy of the markers to iterate
550-
// over.
551-
auto LinkedRange = at::getAssignmentMarkers(Inst);
552-
SmallVector<DbgVariableRecord *> LinkedDVRAssigns =
553-
at::getDVRAssignmentMarkers(Inst);
554-
SmallVector<DbgAssignIntrinsic *> Linked(LinkedRange.begin(),
555-
LinkedRange.end());
556-
auto InsertAssignForOverlap = [&](auto *Assign) {
548+
// overlapping dbg.assign intrinsic.
549+
for (DbgVariableRecord *Assign : at::getDVRAssignmentMarkers(Inst)) {
557550
std::optional<DIExpression::FragmentInfo> NewFragment;
558551
if (!at::calculateFragmentIntersect(DL, OriginalDest, DeadSliceOffsetInBits,
559552
DeadSliceSizeInBits, Assign,
@@ -563,11 +556,11 @@ static void shortenAssignment(Instruction *Inst, Value *OriginalDest,
563556
// cautious and unlink the whole assignment from the store.
564557
Assign->setKillAddress();
565558
Assign->setAssignId(GetDeadLink());
566-
return;
559+
continue;
567560
}
568561
// No intersect.
569562
if (NewFragment->SizeInBits == 0)
570-
return;
563+
continue;
571564

572565
// Fragments overlap: insert a new dbg.assign for this dead part.
573566
auto *NewAssign = static_cast<decltype(Assign)>(Assign->clone());
@@ -576,9 +569,7 @@ static void shortenAssignment(Instruction *Inst, Value *OriginalDest,
576569
if (NewFragment)
577570
SetDeadFragExpr(NewAssign, *NewFragment);
578571
NewAssign->setKillAddress();
579-
};
580-
for_each(Linked, InsertAssignForOverlap);
581-
for_each(LinkedDVRAssigns, InsertAssignForOverlap);
572+
}
582573
}
583574

584575
/// Update the attributes given that a memory access is updated (the

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,6 @@ static DebugVariable getAggregateVariable(DbgVariableRecord *DVR) {
320320
DVR->getDebugLoc().getInlinedAt());
321321
}
322322

323-
DbgVariableRecord *UnwrapDbgInstPtr(DbgInstPtr P, DbgVariableRecord *Unused) {
324-
(void)Unused;
325-
return static_cast<DbgVariableRecord *>(cast<DbgRecord *>(P));
326-
}
327-
DbgAssignIntrinsic *UnwrapDbgInstPtr(DbgInstPtr P, DbgAssignIntrinsic *Unused) {
328-
(void)Unused;
329-
return static_cast<DbgAssignIntrinsic *>(cast<Instruction *>(P));
330-
}
331-
332323
/// Find linked dbg.assign and generate a new one with the correct
333324
/// FragmentInfo. Link Inst to the new dbg.assign. If Value is nullptr the
334325
/// value component is copied from the old dbg.assign to the new.
@@ -348,10 +339,9 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
348339
uint64_t SliceSizeInBits, Instruction *OldInst,
349340
Instruction *Inst, Value *Dest, Value *Value,
350341
const DataLayout &DL) {
351-
auto MarkerRange = at::getAssignmentMarkers(OldInst);
352342
auto DVRAssignMarkerRange = at::getDVRAssignmentMarkers(OldInst);
353343
// Nothing to do if OldInst has no linked dbg.assign intrinsics.
354-
if (MarkerRange.empty() && DVRAssignMarkerRange.empty())
344+
if (DVRAssignMarkerRange.empty())
355345
return;
356346

357347
LLVM_DEBUG(dbgs() << " migrateDebugInfo\n");
@@ -435,11 +425,10 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
435425
}
436426

437427
::Value *NewValue = Value ? Value : DbgAssign->getValue();
438-
auto *NewAssign = UnwrapDbgInstPtr(
428+
DbgVariableRecord *NewAssign = cast<DbgVariableRecord>(cast<DbgRecord *>(
439429
DIB.insertDbgAssign(Inst, NewValue, DbgAssign->getVariable(), Expr,
440430
Dest, DIExpression::get(Expr->getContext(), {}),
441-
DbgAssign->getDebugLoc()),
442-
DbgAssign);
431+
DbgAssign->getDebugLoc())));
443432

444433
// If we've updated the value but the original dbg.assign has an arglist
445434
// then kill it now - we can't use the requested new value.
@@ -3232,8 +3221,7 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
32323221
// In theory we should call migrateDebugInfo here. However, we do not
32333222
// emit dbg.assign intrinsics for mem intrinsics storing through non-
32343223
// constant geps, or storing a variable number of bytes.
3235-
assert(at::getAssignmentMarkers(&II).empty() &&
3236-
at::getDVRAssignmentMarkers(&II).empty() &&
3224+
assert(at::getDVRAssignmentMarkers(&II).empty() &&
32373225
"AT: Unexpected link to non-const GEP");
32383226
deleteIfTriviallyDead(OldPtr);
32393227
return false;
@@ -3382,13 +3370,11 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
33823370
Value *AdjustedPtr = getNewAllocaSlicePtr(IRB, OldPtr->getType());
33833371
if (IsDest) {
33843372
// Update the address component of linked dbg.assigns.
3385-
auto UpdateAssignAddress = [&](auto *DbgAssign) {
3373+
for (DbgVariableRecord *DbgAssign : at::getDVRAssignmentMarkers(&II)) {
33863374
if (llvm::is_contained(DbgAssign->location_ops(), II.getDest()) ||
33873375
DbgAssign->getAddress() == II.getDest())
33883376
DbgAssign->replaceVariableLocationOp(II.getDest(), AdjustedPtr);
3389-
};
3390-
for_each(at::getAssignmentMarkers(&II), UpdateAssignAddress);
3391-
for_each(at::getDVRAssignmentMarkers(&II), UpdateAssignAddress);
3377+
}
33923378
II.setDest(AdjustedPtr);
33933379
II.setDestAlignment(SliceAlign);
33943380
} else {
@@ -3986,8 +3972,7 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
39863972
Store->getPointerOperand(), Store->getValueOperand(),
39873973
DL);
39883974
} else {
3989-
assert(at::getAssignmentMarkers(Store).empty() &&
3990-
at::getDVRAssignmentMarkers(Store).empty() &&
3975+
assert(at::getDVRAssignmentMarkers(Store).empty() &&
39913976
"AT: unexpected debug.assign linked to store through "
39923977
"unbounded GEP");
39933978
}

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3321,12 +3321,10 @@ bool SimplifyCFGOpt::speculativelyExecuteBB(BranchInst *BI,
33213321
// %merge = select %cond, %two, %one
33223322
// store %merge, %x.dest, !DIAssignID !2
33233323
// dbg.assign %merge, "x", ..., !2
3324-
auto replaceVariable = [OrigV, S](auto *DbgAssign) {
3324+
for (DbgVariableRecord *DbgAssign :
3325+
at::getDVRAssignmentMarkers(SpeculatedStore))
33253326
if (llvm::is_contained(DbgAssign->location_ops(), OrigV))
33263327
DbgAssign->replaceVariableLocationOp(OrigV, S);
3327-
};
3328-
for_each(at::getAssignmentMarkers(SpeculatedStore), replaceVariable);
3329-
for_each(at::getDVRAssignmentMarkers(SpeculatedStore), replaceVariable);
33303328
}
33313329

33323330
// Metadata can be dependent on the condition we are hoisting above.

0 commit comments

Comments
 (0)