[llvm] d13341d - [RemoveDIs][NFC] Remove getAssignmentMarkers (#153214)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 13 02:56:22 PDT 2025
Author: Orlando Cazalet-Hyams
Date: 2025-08-13T10:56:19+01:00
New Revision: d13341db26fde0cb9764222f6d36db8b786d6119
URL: https://github.com/llvm/llvm-project/commit/d13341db26fde0cb9764222f6d36db8b786d6119
DIFF: https://github.com/llvm/llvm-project/commit/d13341db26fde0cb9764222f6d36db8b786d6119.diff
LOG: [RemoveDIs][NFC] Remove getAssignmentMarkers (#153214)
getAssignmentMarkers was for debug intrinsics. getDVRAssignmentMarkers
is used for DbgRecords.
Added:
Modified:
llvm/include/llvm/IR/DebugInfo.h
llvm/lib/IR/DebugInfo.cpp
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/DebugInfo.h b/llvm/include/llvm/IR/DebugInfo.h
index c529a86309a94..cc9e7b0c77bdd 100644
--- a/llvm/include/llvm/IR/DebugInfo.h
+++ b/llvm/include/llvm/IR/DebugInfo.h
@@ -195,38 +195,8 @@ inline AssignmentInstRange getAssignmentInsts(const DbgVariableRecord *DVR) {
return getAssignmentInsts(DVR->getAssignID());
}
-//
-// Utilities for enumerating llvm.dbg.assign intrinsic from an assignment ID.
-//
-/// High level: this is an iterator for llvm.dbg.assign intrinsics.
-/// Implementation details: this is a wrapper around Value's User iterator that
-/// dereferences to a DbgAssignIntrinsic ptr rather than a User ptr.
-class DbgAssignIt
- : public iterator_adaptor_base<DbgAssignIt, Value::user_iterator,
- typename std::iterator_traits<
- Value::user_iterator>::iterator_category,
- DbgAssignIntrinsic *, std::ptr
diff _t,
- DbgAssignIntrinsic **,
- DbgAssignIntrinsic *&> {
-public:
- DbgAssignIt(Value::user_iterator It) : iterator_adaptor_base(It) {}
- DbgAssignIntrinsic *operator*() const { return cast<DbgAssignIntrinsic>(*I); }
-};
-/// A range of llvm.dbg.assign intrinsics.
-using AssignmentMarkerRange = iterator_range<DbgAssignIt>;
-/// Return a range of dbg.assign intrinsics which use \ID as an operand.
-/// Iterators invalidated by deleting an intrinsic contained in this range.
-LLVM_ABI AssignmentMarkerRange getAssignmentMarkers(DIAssignID *ID);
-/// Return a range of dbg.assign intrinsics for which \p Inst performs the
+/// Return a range of dbg_assign records for which \p Inst performs the
/// assignment they encode.
-/// Iterators invalidated by deleting an intrinsic contained in this range.
-inline AssignmentMarkerRange getAssignmentMarkers(const Instruction *Inst) {
- if (auto *ID = Inst->getMetadata(LLVMContext::MD_DIAssignID))
- return getAssignmentMarkers(cast<DIAssignID>(ID));
- else
- return make_range(Value::user_iterator(), Value::user_iterator());
-}
-
inline SmallVector<DbgVariableRecord *>
getDVRAssignmentMarkers(const Instruction *Inst) {
if (auto *ID = Inst->getMetadata(LLVMContext::MD_DIAssignID))
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index ab8ecee2a81e0..65d48408438b7 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -1896,29 +1896,8 @@ AssignmentInstRange at::getAssignmentInsts(DIAssignID *ID) {
return make_range(MapIt->second.begin(), MapIt->second.end());
}
-AssignmentMarkerRange at::getAssignmentMarkers(DIAssignID *ID) {
- assert(ID && "Expected non-null ID");
- LLVMContext &Ctx = ID->getContext();
-
- auto *IDAsValue = MetadataAsValue::getIfExists(Ctx, ID);
-
- // The ID is only used wrapped in MetadataAsValue(ID), so lets check that
- // one of those already exists first.
- if (!IDAsValue)
- return make_range(Value::user_iterator(), Value::user_iterator());
-
- return make_range(IDAsValue->user_begin(), IDAsValue->user_end());
-}
-
void at::deleteAssignmentMarkers(const Instruction *Inst) {
- auto Range = getAssignmentMarkers(Inst);
- SmallVector<DbgVariableRecord *> DVRAssigns = getDVRAssignmentMarkers(Inst);
- if (Range.empty() && DVRAssigns.empty())
- return;
- SmallVector<DbgAssignIntrinsic *> ToDelete(Range.begin(), Range.end());
- for (auto *DAI : ToDelete)
- DAI->eraseFromParent();
- for (auto *DVR : DVRAssigns)
+ for (auto *DVR : getDVRAssignmentMarkers(Inst))
DVR->eraseFromParent();
}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index d7a2ef722c846..24335348f82dd 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -267,12 +267,10 @@ Instruction *InstCombinerImpl::SimplifyAnyMemSet(AnyMemSetInst *MI) {
MI->getContext(), APInt::getSplat(Len * 8, FillC->getValue()));
StoreInst *S = Builder.CreateStore(FillVal, Dest, MI->isVolatile());
S->copyMetadata(*MI, LLVMContext::MD_DIAssignID);
- auto replaceOpForAssignmentMarkers = [FillC, FillVal](auto *DbgAssign) {
+ for (DbgVariableRecord *DbgAssign : at::getDVRAssignmentMarkers(S)) {
if (llvm::is_contained(DbgAssign->location_ops(), FillC))
DbgAssign->replaceVariableLocationOp(FillC, FillVal);
- };
- for_each(at::getAssignmentMarkers(S), replaceOpForAssignmentMarkers);
- for_each(at::getDVRAssignmentMarkers(S), replaceOpForAssignmentMarkers);
+ }
S->setAlignment(Alignment);
if (MI->isAtomic())
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 8093e44245d20..37004b956aba8 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -545,15 +545,8 @@ static void shortenAssignment(Instruction *Inst, Value *OriginalDest,
};
// Insert an unlinked dbg.assign intrinsic for the dead fragment after each
- // overlapping dbg.assign intrinsic. The loop invalidates the iterators
- // returned by getAssignmentMarkers so save a copy of the markers to iterate
- // over.
- auto LinkedRange = at::getAssignmentMarkers(Inst);
- SmallVector<DbgVariableRecord *> LinkedDVRAssigns =
- at::getDVRAssignmentMarkers(Inst);
- SmallVector<DbgAssignIntrinsic *> Linked(LinkedRange.begin(),
- LinkedRange.end());
- auto InsertAssignForOverlap = [&](auto *Assign) {
+ // overlapping dbg.assign intrinsic.
+ for (DbgVariableRecord *Assign : at::getDVRAssignmentMarkers(Inst)) {
std::optional<DIExpression::FragmentInfo> NewFragment;
if (!at::calculateFragmentIntersect(DL, OriginalDest, DeadSliceOffsetInBits,
DeadSliceSizeInBits, Assign,
@@ -563,11 +556,11 @@ static void shortenAssignment(Instruction *Inst, Value *OriginalDest,
// cautious and unlink the whole assignment from the store.
Assign->setKillAddress();
Assign->setAssignId(GetDeadLink());
- return;
+ continue;
}
// No intersect.
if (NewFragment->SizeInBits == 0)
- return;
+ continue;
// Fragments overlap: insert a new dbg.assign for this dead part.
auto *NewAssign = static_cast<decltype(Assign)>(Assign->clone());
@@ -576,9 +569,7 @@ static void shortenAssignment(Instruction *Inst, Value *OriginalDest,
if (NewFragment)
SetDeadFragExpr(NewAssign, *NewFragment);
NewAssign->setKillAddress();
- };
- for_each(Linked, InsertAssignForOverlap);
- for_each(LinkedDVRAssigns, InsertAssignForOverlap);
+ }
}
/// Update the attributes given that a memory access is updated (the
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index d6e27aa20730b..06a92bde4fde1 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -320,15 +320,6 @@ static DebugVariable getAggregateVariable(DbgVariableRecord *DVR) {
DVR->getDebugLoc().getInlinedAt());
}
-DbgVariableRecord *UnwrapDbgInstPtr(DbgInstPtr P, DbgVariableRecord *Unused) {
- (void)Unused;
- return static_cast<DbgVariableRecord *>(cast<DbgRecord *>(P));
-}
-DbgAssignIntrinsic *UnwrapDbgInstPtr(DbgInstPtr P, DbgAssignIntrinsic *Unused) {
- (void)Unused;
- return static_cast<DbgAssignIntrinsic *>(cast<Instruction *>(P));
-}
-
/// Find linked dbg.assign and generate a new one with the correct
/// FragmentInfo. Link Inst to the new dbg.assign. If Value is nullptr the
/// value component is copied from the old dbg.assign to the new.
@@ -348,10 +339,9 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
uint64_t SliceSizeInBits, Instruction *OldInst,
Instruction *Inst, Value *Dest, Value *Value,
const DataLayout &DL) {
- auto MarkerRange = at::getAssignmentMarkers(OldInst);
auto DVRAssignMarkerRange = at::getDVRAssignmentMarkers(OldInst);
// Nothing to do if OldInst has no linked dbg.assign intrinsics.
- if (MarkerRange.empty() && DVRAssignMarkerRange.empty())
+ if (DVRAssignMarkerRange.empty())
return;
LLVM_DEBUG(dbgs() << " migrateDebugInfo\n");
@@ -435,11 +425,10 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
}
::Value *NewValue = Value ? Value : DbgAssign->getValue();
- auto *NewAssign = UnwrapDbgInstPtr(
+ DbgVariableRecord *NewAssign = cast<DbgVariableRecord>(cast<DbgRecord *>(
DIB.insertDbgAssign(Inst, NewValue, DbgAssign->getVariable(), Expr,
Dest, DIExpression::get(Expr->getContext(), {}),
- DbgAssign->getDebugLoc()),
- DbgAssign);
+ DbgAssign->getDebugLoc())));
// 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.
@@ -3232,8 +3221,7 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
// In theory we should call migrateDebugInfo here. However, we do not
// emit dbg.assign intrinsics for mem intrinsics storing through non-
// constant geps, or storing a variable number of bytes.
- assert(at::getAssignmentMarkers(&II).empty() &&
- at::getDVRAssignmentMarkers(&II).empty() &&
+ assert(at::getDVRAssignmentMarkers(&II).empty() &&
"AT: Unexpected link to non-const GEP");
deleteIfTriviallyDead(OldPtr);
return false;
@@ -3382,13 +3370,11 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
Value *AdjustedPtr = getNewAllocaSlicePtr(IRB, OldPtr->getType());
if (IsDest) {
// Update the address component of linked dbg.assigns.
- auto UpdateAssignAddress = [&](auto *DbgAssign) {
+ for (DbgVariableRecord *DbgAssign : at::getDVRAssignmentMarkers(&II)) {
if (llvm::is_contained(DbgAssign->location_ops(), II.getDest()) ||
DbgAssign->getAddress() == II.getDest())
DbgAssign->replaceVariableLocationOp(II.getDest(), AdjustedPtr);
- };
- for_each(at::getAssignmentMarkers(&II), UpdateAssignAddress);
- for_each(at::getDVRAssignmentMarkers(&II), UpdateAssignAddress);
+ }
II.setDest(AdjustedPtr);
II.setDestAlignment(SliceAlign);
} else {
@@ -3986,8 +3972,7 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
Store->getPointerOperand(), Store->getValueOperand(),
DL);
} else {
- assert(at::getAssignmentMarkers(Store).empty() &&
- at::getDVRAssignmentMarkers(Store).empty() &&
+ assert(at::getDVRAssignmentMarkers(Store).empty() &&
"AT: unexpected debug.assign linked to store through "
"unbounded GEP");
}
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index deabacc592c7f..1436e479ba091 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3321,12 +3321,10 @@ bool SimplifyCFGOpt::speculativelyExecuteBB(BranchInst *BI,
// %merge = select %cond, %two, %one
// store %merge, %x.dest, !DIAssignID !2
// dbg.assign %merge, "x", ..., !2
- auto replaceVariable = [OrigV, S](auto *DbgAssign) {
+ for (DbgVariableRecord *DbgAssign :
+ at::getDVRAssignmentMarkers(SpeculatedStore))
if (llvm::is_contained(DbgAssign->location_ops(), OrigV))
DbgAssign->replaceVariableLocationOp(OrigV, S);
- };
- for_each(at::getAssignmentMarkers(SpeculatedStore), replaceVariable);
- for_each(at::getDVRAssignmentMarkers(SpeculatedStore), replaceVariable);
}
// Metadata can be dependent on the condition we are hoisting above.
More information about the llvm-commits
mailing list