Skip to content

Commit d4b9446

Browse files
Merge pull request #2769 from adrian-prantl/75904857-2
Improve LiveDebugValues for arm64 Swift async variables.
2 parents b0fe088 + a457c00 commit d4b9446

File tree

2 files changed

+379
-5
lines changed

2 files changed

+379
-5
lines changed

llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,10 +1825,9 @@ static bool isSwiftAsyncContext(const MachineInstr &MI) {
18251825
unsigned Reg = isDbgValueDescribedByReg(MI);
18261826
if (!Reg)
18271827
return false;
1828-
auto &EntryMBB = MF->front();
18291828
unsigned I = 0;
1830-
for (auto R : EntryMBB.liveins()) {
1831-
if (R.PhysReg == Reg && F.hasParamAttribute(I, Attribute::SwiftAsync))
1829+
for (auto R : MF->getRegInfo().liveins()) {
1830+
if (R.first == Reg && F.hasParamAttribute(I, Attribute::SwiftAsync))
18321831
return true;
18331832
++I;
18341833
}
@@ -1890,20 +1889,29 @@ bool VarLocBasedLDV::ExtendRanges(MachineFunction &MF, TargetPassConfig *TPC) {
18901889

18911890
// Only in the case of entry MBB collect DBG_VALUEs representing
18921891
// function parameters in order to generate debug entry values for them.
1892+
SmallVector<MachineInstr *, 8> AsyncDbgValues;
18931893
MachineBasicBlock &First_MBB = *(MF.begin());
18941894
for (auto &MI : First_MBB) {
18951895
collectRegDefs(MI, DefinedRegs, TRI);
18961896
if (MI.isDebugValue()) {
18971897
// In Swift async functions entry values are preferred, since they
18981898
// can be evaluated in both live frames and virtual backtraces.
1899-
if (isSwiftAsyncContext(MI))
1899+
if (isSwiftAsyncContext(MI)) {
19001900
MI.getOperand(3).setMetadata(DIExpression::prepend(
19011901
MI.getDebugExpression(), DIExpression::EntryValue));
1902-
else
1902+
AsyncDbgValues.push_back(&MI);
1903+
} else
19031904
recordEntryValue(MI, DefinedRegs, OpenRanges, VarLocIDs);
19041905
}
19051906
}
19061907

1908+
if (AsyncDbgValues.size()) {
1909+
// Make sure the async entry values are at the very start.
1910+
auto InsertPt = First_MBB.getFirstNonDebugInstr();
1911+
for (auto *MI : llvm::reverse(AsyncDbgValues))
1912+
MI->moveBefore(&*InsertPt);
1913+
}
1914+
19071915
// Initialize per-block structures and scan for fragment overlaps.
19081916
for (auto &MBB : MF)
19091917
for (auto &MI : MBB)

0 commit comments

Comments
 (0)