@@ -1825,10 +1825,9 @@ static bool isSwiftAsyncContext(const MachineInstr &MI) {
1825
1825
unsigned Reg = isDbgValueDescribedByReg (MI);
1826
1826
if (!Reg)
1827
1827
return false ;
1828
- auto &EntryMBB = MF->front ();
1829
1828
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))
1832
1831
return true ;
1833
1832
++I;
1834
1833
}
@@ -1890,20 +1889,29 @@ bool VarLocBasedLDV::ExtendRanges(MachineFunction &MF, TargetPassConfig *TPC) {
1890
1889
1891
1890
// Only in the case of entry MBB collect DBG_VALUEs representing
1892
1891
// function parameters in order to generate debug entry values for them.
1892
+ SmallVector<MachineInstr *, 8 > AsyncDbgValues;
1893
1893
MachineBasicBlock &First_MBB = *(MF.begin ());
1894
1894
for (auto &MI : First_MBB) {
1895
1895
collectRegDefs (MI, DefinedRegs, TRI);
1896
1896
if (MI.isDebugValue ()) {
1897
1897
// In Swift async functions entry values are preferred, since they
1898
1898
// can be evaluated in both live frames and virtual backtraces.
1899
- if (isSwiftAsyncContext (MI))
1899
+ if (isSwiftAsyncContext (MI)) {
1900
1900
MI.getOperand (3 ).setMetadata (DIExpression::prepend (
1901
1901
MI.getDebugExpression (), DIExpression::EntryValue));
1902
- else
1902
+ AsyncDbgValues.push_back (&MI);
1903
+ } else
1903
1904
recordEntryValue (MI, DefinedRegs, OpenRanges, VarLocIDs);
1904
1905
}
1905
1906
}
1906
1907
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
+
1907
1915
// Initialize per-block structures and scan for fragment overlaps.
1908
1916
for (auto &MBB : MF)
1909
1917
for (auto &MI : MBB)
0 commit comments