@@ -148,6 +148,21 @@ static cl::opt<bool> EmulateOldLDV("emulate-old-livedebugvalues", cl::Hidden,
148
148
cl::desc (" Act like old LiveDebugValues did" ),
149
149
cl::init(false ));
150
150
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
+
151
166
// / Tracker for converting machine value locations and variable values into
152
167
// / variable locations (the output of LiveDebugValues), recorded as DBG_VALUEs
153
168
// / specifying block live-in locations and transfers within blocks.
@@ -420,18 +435,20 @@ class TransferTracker {
420
435
if (!ShouldEmitDebugEntryValues)
421
436
return false ;
422
437
423
- // Is the variable appropriate for entry values (i.e., is a parameter).
424
- if (!isEntryValueVariable (Var, Prop.DIExpr ))
425
- return false ;
426
-
427
438
// Is the value assigned to this variable still the entry value?
428
439
if (!isEntryValueValue (Num))
429
440
return false ;
430
441
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
+
431
449
// Emit a variable location using an entry value expression.
432
450
DIExpression *NewExpr =
433
451
DIExpression::prepend (Prop.DIExpr , DIExpression::EntryValue);
434
- Register Reg = MTracker->LocIdxToLocID [Num.getLoc ()];
435
452
MachineOperand MO = MachineOperand::CreateReg (Reg, false );
436
453
437
454
PendingDbgValues.push_back (emitMOLoc (MO, Var, {NewExpr, Prop.Indirect }));
@@ -958,8 +975,18 @@ bool InstrRefBasedLDV::transferDebugValue(const MachineInstr &MI) {
958
975
959
976
// MLocTracker needs to know that this register is read, even if it's only
960
977
// read by a debug inst.
961
- if (MO.isReg () && MO.getReg () != 0 )
978
+ if (MO.isReg () && MO.getReg () != 0 ) {
962
979
(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
+ }
963
990
964
991
// If we're preparing for the second analysis (variables), the machine value
965
992
// locations are already solved, and we report this DBG_VALUE and the value
0 commit comments