Skip to content

Commit fb8981d

Browse files
committed
Implement Swift async context entry value support in InstrRefBasedLDV.
rdar://85560130
1 parent ccac456 commit fb8981d

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,21 @@ static cl::opt<bool> EmulateOldLDV("emulate-old-livedebugvalues", cl::Hidden,
148148
cl::desc("Act like old LiveDebugValues did"),
149149
cl::init(false));
150150

151+
static bool isSwiftAsyncContext(const MachineFunction &MF, Register Reg) {
152+
const llvm::Function &F = MF.getFunction();
153+
if (!MF.getProperties().hasProperty(
154+
MachineFunctionProperties::Property::TracksLiveness))
155+
return false;
156+
unsigned I = 0;
157+
for (auto R : MF.getRegInfo().liveins()) {
158+
if (R.first == (unsigned)Reg &&
159+
F.hasParamAttribute(I, Attribute::SwiftAsync))
160+
return true;
161+
++I;
162+
}
163+
return false;
164+
}
165+
151166
/// Tracker for converting machine value locations and variable values into
152167
/// variable locations (the output of LiveDebugValues), recorded as DBG_VALUEs
153168
/// specifying block live-in locations and transfers within blocks.
@@ -420,18 +435,20 @@ class TransferTracker {
420435
if (!ShouldEmitDebugEntryValues)
421436
return false;
422437

423-
// Is the variable appropriate for entry values (i.e., is a parameter).
424-
if (!isEntryValueVariable(Var, Prop.DIExpr))
425-
return false;
426-
427438
// Is the value assigned to this variable still the entry value?
428439
if (!isEntryValueValue(Num))
429440
return false;
430441

442+
Register Reg = MTracker->LocIdxToLocID[Num.getLoc()];
443+
444+
// Is the variable appropriate for entry values (i.e., is a parameter).
445+
if (!isEntryValueVariable(Var, Prop.DIExpr) &&
446+
!isSwiftAsyncContext(MF, Reg))
447+
return false;
448+
431449
// Emit a variable location using an entry value expression.
432450
DIExpression *NewExpr =
433451
DIExpression::prepend(Prop.DIExpr, DIExpression::EntryValue);
434-
Register Reg = MTracker->LocIdxToLocID[Num.getLoc()];
435452
MachineOperand MO = MachineOperand::CreateReg(Reg, false);
436453

437454
PendingDbgValues.push_back(emitMOLoc(MO, Var, {NewExpr, Prop.Indirect}));
@@ -958,8 +975,18 @@ bool InstrRefBasedLDV::transferDebugValue(const MachineInstr &MI) {
958975

959976
// MLocTracker needs to know that this register is read, even if it's only
960977
// read by a debug inst.
961-
if (MO.isReg() && MO.getReg() != 0)
978+
if (MO.isReg() && MO.getReg() != 0) {
962979
(void)MTracker->readReg(MO.getReg());
980+
auto *Expr = MI.getDebugExpression();
981+
const llvm::MachineFunction *MF = MI.getParent()->getParent();
982+
if (!(Expr && Expr->isEntryValue()) &&
983+
isSwiftAsyncContext(*MF, MO.getReg())) {
984+
// In Swift async functions entry values are preferred, since they
985+
// can be evaluated in both live frames and virtual backtraces.
986+
const_cast<MachineInstr *>(&MI)->getOperand(3).setMetadata(
987+
DIExpression::prepend(Expr, DIExpression::EntryValue));
988+
}
989+
}
963990

964991
// If we're preparing for the second analysis (variables), the machine value
965992
// locations are already solved, and we report this DBG_VALUE and the value

llvm/test/DebugInfo/MIR/X86/swift-async-entryvalues.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,6 @@ body: |
244244
CALL64r killed renamable $rax, csr_64, implicit $rsp, implicit $ssp, implicit killed $rdi, implicit killed $rsi, implicit killed $r14, implicit-def $rsp, implicit-def $ssp, debug-location !65
245245
$rsp = frame-destroy ADD64ri8 $rsp, 32, implicit-def dead $eflags, debug-location !65
246246
$r14 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !65
247-
RETQ debug-location !65
247+
RET64 debug-location !65
248248
249249
...

0 commit comments

Comments
 (0)