aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/DebugInfo.cpp
diff options
context:
space:
mode:
authorStephen Tozer <stephen.tozer@sony.com>2024-01-23 16:38:49 +0000
committerGitHub <noreply@github.com>2024-01-23 16:38:49 +0000
commitd3a6a90ae5e80b074293ebfbcb2f15da9c57acc5 (patch)
tree4fb4e83cd4da17e49f213252fac51e7244be1a51 /llvm/lib/IR/DebugInfo.cpp
parent6cf37dd504d0466bd9f34e29712d60759ef8180f (diff)
downloadllvm-d3a6a90ae5e80b074293ebfbcb2f15da9c57acc5.zip
llvm-d3a6a90ae5e80b074293ebfbcb2f15da9c57acc5.tar.gz
llvm-d3a6a90ae5e80b074293ebfbcb2f15da9c57acc5.tar.bz2
[RemoveDIs][DebugInfo] Enable creation of DPVAssigns, update outstanding AT tests (#79148)
This is the final patch for DPVAssign support, implementing the actual creation of DPVAssigns and allowing them to be converted along with dbg.values and dbg.declares. Numerous tests landed in previous patches will no longer be rotten after this patch lands (previously they would trivially pass due to DPVAssigns not actually being used), and a further batch of tests have been added here that require the changes in this patch before they pass.
Diffstat (limited to 'llvm/lib/IR/DebugInfo.cpp')
-rw-r--r--llvm/lib/IR/DebugInfo.cpp114
1 files changed, 63 insertions, 51 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 2e64d0db5..e332748 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -1816,8 +1816,12 @@ void at::RAUW(DIAssignID *Old, DIAssignID *New) {
void at::deleteAll(Function *F) {
SmallVector<DbgAssignIntrinsic *, 12> ToDelete;
+ SmallVector<DPValue *, 12> DPToDelete;
for (BasicBlock &BB : *F) {
for (Instruction &I : BB) {
+ for (auto &DPV : I.getDbgValueRange())
+ if (DPV.isDbgAssign())
+ DPToDelete.push_back(&DPV);
if (auto *DAI = dyn_cast<DbgAssignIntrinsic>(&I))
ToDelete.push_back(DAI);
else
@@ -1826,6 +1830,8 @@ void at::deleteAll(Function *F) {
}
for (auto *DAI : ToDelete)
DAI->eraseFromParent();
+ for (auto *DPV : DPToDelete)
+ DPV->eraseFromParent();
}
/// Get the FragmentInfo for the variable if it exists, otherwise return a
@@ -2056,9 +2062,9 @@ std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
}
/// Returns nullptr if the assignment shouldn't be attributed to this variable.
-static CallInst *emitDbgAssign(AssignmentInfo Info, Value *Val, Value *Dest,
- Instruction &StoreLikeInst,
- const VarRecord &VarRec, DIBuilder &DIB) {
+static void emitDbgAssign(AssignmentInfo Info, Value *Val, Value *Dest,
+ Instruction &StoreLikeInst, const VarRecord &VarRec,
+ DIBuilder &DIB) {
auto *ID = StoreLikeInst.getMetadata(LLVMContext::MD_DIAssignID);
assert(ID && "Store instruction must have DIAssignID metadata");
(void)ID;
@@ -2082,7 +2088,7 @@ static CallInst *emitDbgAssign(AssignmentInfo Info, Value *Val, Value *Dest,
// Discard stores to bits outside this variable.
if (FragStartBit >= FragEndBit)
- return nullptr;
+ return;
StoreToWholeVariable = FragStartBit <= VarStartBit && FragEndBit >= *Size;
}
@@ -2097,8 +2103,17 @@ static CallInst *emitDbgAssign(AssignmentInfo Info, Value *Val, Value *Dest,
}
DIExpression *AddrExpr =
DIExpression::get(StoreLikeInst.getContext(), std::nullopt);
- return DIB.insertDbgAssign(&StoreLikeInst, Val, VarRec.Var, Expr, Dest,
- AddrExpr, VarRec.DL);
+ if (StoreLikeInst.getParent()->IsNewDbgInfoFormat) {
+ auto *Assign = DPValue::createLinkedDPVAssign(
+ &StoreLikeInst, Val, VarRec.Var, Expr, Dest, AddrExpr, VarRec.DL);
+ (void)Assign;
+ LLVM_DEBUG(if (Assign) errs() << " > INSERT: " << *Assign << "\n");
+ return;
+ }
+ auto *Assign = DIB.insertDbgAssign(&StoreLikeInst, Val, VarRec.Var, Expr,
+ Dest, AddrExpr, VarRec.DL);
+ (void)Assign;
+ LLVM_DEBUG(if (Assign) errs() << " > INSERT: " << *Assign << "\n");
}
#undef DEBUG_TYPE // Silence redefinition warning (from ConstantsContext.h).
@@ -2185,12 +2200,8 @@ void at::trackAssignments(Function::iterator Start, Function::iterator End,
I.setMetadata(LLVMContext::MD_DIAssignID, ID);
}
- for (const VarRecord &R : LocalIt->second) {
- auto *Assign =
- emitDbgAssign(*Info, ValueComponent, DestComponent, I, R, DIB);
- (void)Assign;
- LLVM_DEBUG(if (Assign) errs() << " > INSERT: " << *Assign << "\n");
- }
+ for (const VarRecord &R : LocalIt->second)
+ emitDbgAssign(*Info, ValueComponent, DestComponent, I, R, DIB);
}
}
}
@@ -2206,32 +2217,38 @@ bool AssignmentTrackingPass::runOnFunction(Function &F) {
// storage" is limited to Allocas). We'll use this to find dbg.declares to
// delete after running `trackAssignments`.
DenseMap<const AllocaInst *, SmallPtrSet<DbgDeclareInst *, 2>> DbgDeclares;
+ DenseMap<const AllocaInst *, SmallPtrSet<DPValue *, 2>> DPVDeclares;
// Create another similar map of {storage : variables} that we'll pass to
// trackAssignments.
StorageToVarsMap Vars;
+ auto ProcessDeclare = [&](auto *Declare, auto &DeclareList) {
+ // FIXME: trackAssignments doesn't let you specify any modifiers to the
+ // variable (e.g. fragment) or location (e.g. offset), so we have to
+ // leave dbg.declares with non-empty expressions in place.
+ if (Declare->getExpression()->getNumElements() != 0)
+ return;
+ if (!Declare->getAddress())
+ return;
+ if (AllocaInst *Alloca =
+ dyn_cast<AllocaInst>(Declare->getAddress()->stripPointerCasts())) {
+ // FIXME: Skip VLAs for now (let these variables use dbg.declares).
+ if (!Alloca->isStaticAlloca())
+ return;
+ // Similarly, skip scalable vectors (use dbg.declares instead).
+ if (auto Sz = Alloca->getAllocationSize(*DL); Sz && Sz->isScalable())
+ return;
+ DeclareList[Alloca].insert(Declare);
+ Vars[Alloca].insert(VarRecord(Declare));
+ }
+ };
for (auto &BB : F) {
for (auto &I : BB) {
- DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(&I);
- if (!DDI)
- continue;
- // FIXME: trackAssignments doesn't let you specify any modifiers to the
- // variable (e.g. fragment) or location (e.g. offset), so we have to
- // leave dbg.declares with non-empty expressions in place.
- if (DDI->getExpression()->getNumElements() != 0)
- continue;
- if (!DDI->getAddress())
- continue;
- if (AllocaInst *Alloca =
- dyn_cast<AllocaInst>(DDI->getAddress()->stripPointerCasts())) {
- // FIXME: Skip VLAs for now (let these variables use dbg.declares).
- if (!Alloca->isStaticAlloca())
- continue;
- // Similarly, skip scalable vectors (use dbg.declares instead).
- if (auto Sz = Alloca->getAllocationSize(*DL); Sz && Sz->isScalable())
- continue;
- DbgDeclares[Alloca].insert(DDI);
- Vars[Alloca].insert(VarRecord(DDI));
+ for (auto &DPV : I.getDbgValueRange()) {
+ if (DPV.isDbgDeclare())
+ ProcessDeclare(&DPV, DPVDeclares);
}
+ if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(&I))
+ ProcessDeclare(DDI, DbgDeclares);
}
}
@@ -2247,35 +2264,30 @@ bool AssignmentTrackingPass::runOnFunction(Function &F) {
trackAssignments(F.begin(), F.end(), Vars, *DL);
// Delete dbg.declares for variables now tracked with assignment tracking.
- for (auto &P : DbgDeclares) {
- const AllocaInst *Alloca = P.first;
- auto Markers = at::getAssignmentMarkers(Alloca);
- SmallVector<DPValue *> DPMarkers = at::getDPVAssignmentMarkers(Alloca);
+ auto DeleteSubsumedDeclare = [&](const auto &Markers, auto &Declares) {
(void)Markers;
- (void)DPMarkers;
- for (DbgDeclareInst *DDI : P.second) {
- // Assert that the alloca that DDI uses is now linked to a dbg.assign
+ for (auto *Declare : Declares) {
+ // Assert that the alloca that Declare uses is now linked to a dbg.assign
// describing the same variable (i.e. check that this dbg.declare has
// been replaced by a dbg.assign). Use DebugVariableAggregate to Discard
// the fragment part because trackAssignments may alter the
// fragment. e.g. if the alloca is smaller than the variable, then
// trackAssignments will create an alloca-sized fragment for the
// dbg.assign.
- assert(llvm::any_of(Markers,
- [DDI](DbgAssignIntrinsic *DAI) {
- return DebugVariableAggregate(DAI) ==
- DebugVariableAggregate(DDI);
- }) ||
- llvm::any_of(DPMarkers, [DDI](DPValue *DPV) {
- return DebugVariableAggregate(DPV) ==
- DebugVariableAggregate(DDI);
- }));
- // Delete DDI because the variable location is now tracked using
+ assert(llvm::any_of(Markers, [Declare](auto *Assign) {
+ return DebugVariableAggregate(Assign) ==
+ DebugVariableAggregate(Declare);
+ }));
+ // Delete Declare because the variable location is now tracked using
// assignment tracking.
- DDI->eraseFromParent();
+ Declare->eraseFromParent();
Changed = true;
}
- }
+ };
+ for (auto &P : DbgDeclares)
+ DeleteSubsumedDeclare(at::getAssignmentMarkers(P.first), P.second);
+ for (auto &P : DPVDeclares)
+ DeleteSubsumedDeclare(at::getDPVAssignmentMarkers(P.first), P.second);
return Changed;
}