-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RemoveDIs] Add DPLabels support [3a/3] #82633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
679db62
83c973c
ddad584
eca5848
72821d5
37be2f3
010d4be
e24159c
b4ce4b1
dc8da42
320dfcc
def0a36
8ae9711
ccfe7a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1585,8 +1585,30 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc, | |
return cast<DILocalVariable>(NewVar); | ||
}; | ||
|
||
auto UpdateDPValuesOnInst = [&](Instruction &I) -> void { | ||
for (DPValue &DPV : DPValue::filter(I.getDbgValueRange())) { | ||
auto UpdateDbgLabel = [&](auto *LabelRecord) { | ||
// Point the label record to a fresh label within the new function if | ||
// the record was not inlined from some other function. | ||
if (LabelRecord->getDebugLoc().getInlinedAt()) | ||
return; | ||
DILabel *OldLabel = LabelRecord->getLabel(); | ||
DINode *&NewLabel = RemappedMetadata[OldLabel]; | ||
if (!NewLabel) { | ||
DILocalScope *NewScope = DILocalScope::cloneScopeForSubprogram( | ||
*OldLabel->getScope(), *NewSP, Ctx, Cache); | ||
NewLabel = DILabel::get(Ctx, NewScope, OldLabel->getName(), | ||
OldLabel->getFile(), OldLabel->getLine()); | ||
} | ||
LabelRecord->setLabel(cast<DILabel>(NewLabel)); | ||
}; | ||
|
||
auto UpdateDbgRecordsOnInst = [&](Instruction &I) -> void { | ||
for (DbgRecord &DR : I.getDbgValueRange()) { | ||
if (DPLabel *DPL = dyn_cast<DPLabel>(&DR)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this work with an auto lambda to share the logic for DbgLabelInsts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly - the DPValue code here hasn't been auto-lambda'd. I'll have a play with it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that looks better, done (added a |
||
UpdateDbgLabel(DPL); | ||
continue; | ||
} | ||
|
||
DPValue &DPV = cast<DPValue>(DR); | ||
// Apply the two updates that dbg.values get: invalid operands, and | ||
// variable metadata fixup. | ||
if (any_of(DPV.location_ops(), IsInvalidLocation)) { | ||
|
@@ -1599,13 +1621,11 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc, | |
} | ||
if (!DPV.getDebugLoc().getInlinedAt()) | ||
DPV.setVariable(GetUpdatedDIVariable(DPV.getVariable())); | ||
DPV.setDebugLoc(DebugLoc::replaceInlinedAtSubprogram(DPV.getDebugLoc(), | ||
*NewSP, Ctx, Cache)); | ||
} | ||
}; | ||
|
||
for (Instruction &I : instructions(NewFunc)) { | ||
UpdateDPValuesOnInst(I); | ||
UpdateDbgRecordsOnInst(I); | ||
|
||
auto *DII = dyn_cast<DbgInfoIntrinsic>(&I); | ||
if (!DII) | ||
|
@@ -1614,17 +1634,7 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc, | |
// Point the intrinsic to a fresh label within the new function if the | ||
// intrinsic was not inlined from some other function. | ||
if (auto *DLI = dyn_cast<DbgLabelInst>(&I)) { | ||
if (DLI->getDebugLoc().getInlinedAt()) | ||
continue; | ||
DILabel *OldLabel = DLI->getLabel(); | ||
DINode *&NewLabel = RemappedMetadata[OldLabel]; | ||
if (!NewLabel) { | ||
DILocalScope *NewScope = DILocalScope::cloneScopeForSubprogram( | ||
*OldLabel->getScope(), *NewSP, Ctx, Cache); | ||
NewLabel = DILabel::get(Ctx, NewScope, OldLabel->getName(), | ||
OldLabel->getFile(), OldLabel->getLine()); | ||
} | ||
DLI->setArgOperand(0, MetadataAsValue::get(Ctx, NewLabel)); | ||
UpdateDbgLabel(DLI); | ||
continue; | ||
} | ||
|
||
|
@@ -1658,6 +1668,9 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc, | |
if (const DebugLoc &DL = I.getDebugLoc()) | ||
I.setDebugLoc( | ||
DebugLoc::replaceInlinedAtSubprogram(DL, *NewSP, Ctx, Cache)); | ||
for (DbgRecord &DR : I.getDbgValueRange()) | ||
DR.setDebugLoc(DebugLoc::replaceInlinedAtSubprogram(DR.getDebugLoc(), | ||
*NewSP, Ctx, Cache)); | ||
|
||
// Loop info metadata may contain line locations. Fix them up. | ||
auto updateLoopInfoLoc = [&Ctx, &Cache, NewSP](Metadata *MD) -> Metadata * { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing, since
DbgRecord::print
already dispatches, we could simply replace theDPValue
operator with this, right?