@@ -555,6 +555,8 @@ static void cacheDIVar(FrameDataInfo &FrameData,
555
555
};
556
556
CacheIt (findDbgDeclares (V));
557
557
CacheIt (findDVRDeclares (V));
558
+ CacheIt (findDbgCoroFrameEntrys (V));
559
+ CacheIt (findDVRCoroFrameEntrys (V));
558
560
}
559
561
}
560
562
@@ -1156,6 +1158,46 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
1156
1158
for_each (DVRs, SalvageOne);
1157
1159
}
1158
1160
1161
+ TinyPtrVector<DbgCoroFrameEntryInst *> DICoros =
1162
+ findDbgCoroFrameEntrys (Def);
1163
+ TinyPtrVector<DbgVariableRecord *> DVRCoros = findDVRCoroFrameEntrys (Def);
1164
+ // Try best to find dbg.coroframe_entry. If the spill is a temp, there may
1165
+ // not be a direct dbg.coroframe_entry. Walk up the load chain to find one
1166
+ // from an alias.
1167
+ if (F->getSubprogram ()) {
1168
+ auto *CurDef = Def;
1169
+ while (DICoros.empty () && DVRCoros.empty () && isa<LoadInst>(CurDef)) {
1170
+ auto *LdInst = cast<LoadInst>(CurDef);
1171
+ // Only consider ptr to ptr same type load.
1172
+ if (LdInst->getPointerOperandType () != LdInst->getType ())
1173
+ break ;
1174
+ CurDef = LdInst->getPointerOperand ();
1175
+ if (!isa<AllocaInst, LoadInst>(CurDef))
1176
+ break ;
1177
+ DICoros = findDbgCoroFrameEntrys (CurDef);
1178
+ DVRCoros = findDVRCoroFrameEntrys (CurDef);
1179
+ }
1180
+ }
1181
+
1182
+ auto SalvageOneCoro = [&](auto *DDI) {
1183
+ // This dbg.coroframe_entry is preserved for all coro-split function
1184
+ // fragments. It will be unreachable in the main function, and
1185
+ // processed by coro::salvageDebugInfo() by the Cloner. However, convert
1186
+ // it to a dbg.declare to make sure future passes don't have to deal
1187
+ // with a dbg.coroframe_entry.
1188
+ DbgVariableRecord *NewDVR = new DbgVariableRecord (
1189
+ ValueAsMetadata::get (CurrentReload), DDI->getVariable (),
1190
+ DDI->getExpression (), DDI->getDebugLoc (),
1191
+ DbgVariableRecord::LocationType::Declare);
1192
+ Builder.GetInsertPoint ()->getParent ()->insertDbgRecordBefore (
1193
+ NewDVR, Builder.GetInsertPoint ());
1194
+ // This dbg.coroframe_entry is for the main function entry point. It
1195
+ // will be deleted in all coro-split functions.
1196
+ coro::salvageDebugInfo (ArgToAllocaMap, *DDI, false /* UseEntryValue*/ );
1197
+ };
1198
+ for_each (DICoros, SalvageOneCoro);
1199
+ for_each (DVRCoros, SalvageOneCoro);
1200
+
1159
1201
// If we have a single edge PHINode, remove it and replace it with a
1160
1202
// reload from the coroutine frame. (We already took care of multi edge
1161
1203
// PHINodes by normalizing them in the rewritePHIs function).
@@ -1954,10 +1996,10 @@ void coro::salvageDebugInfo(
1954
1996
1955
1997
DVI.replaceVariableLocationOp (OriginalStorage, Storage);
1956
1998
DVI.setExpression (Expr);
1957
- // We only hoist dbg.declare today since it doesn't make sense to hoist
1958
- // dbg.value since it does not have the same function wide guarantees that
1959
- // dbg.declare does .
1960
- if (isa<DbgDeclareInst>(DVI)) {
1999
+ // We only hoist dbg.declare and dbg.coroframe_entry today since it doesn't
2000
+ // make sense to hoist dbg.value since it does not have the same function wide
2001
+ // guarantees that dbg.declare and dbg.coroframe_entry do .
2002
+ if (isa<DbgDeclareInst>(DVI) || isa<DbgCoroFrameEntryInst>(DVI) ) {
1961
2003
std::optional<BasicBlock::iterator> InsertPt;
1962
2004
if (auto *I = dyn_cast<Instruction>(Storage)) {
1963
2005
InsertPt = I->getInsertionPointAfterDef ();
@@ -1982,7 +2024,7 @@ void coro::salvageDebugInfo(
1982
2024
Function *F = DVR.getFunction ();
1983
2025
// Follow the pointer arithmetic all the way to the incoming
1984
2026
// function argument and convert into a DIExpression.
1985
- bool SkipOutermostLoad = DVR.isDbgDeclare ();
2027
+ bool SkipOutermostLoad = DVR.isDbgDeclare () || DVR. isDbgCoroFrameEntry () ;
1986
2028
Value *OriginalStorage = DVR.getVariableLocationOp (0 );
1987
2029
1988
2030
auto SalvagedInfo =
@@ -1996,10 +2038,11 @@ void coro::salvageDebugInfo(
1996
2038
1997
2039
DVR.replaceVariableLocationOp (OriginalStorage, Storage);
1998
2040
DVR.setExpression (Expr);
1999
- // We only hoist dbg.declare today since it doesn't make sense to hoist
2000
- // dbg.value since it does not have the same function wide guarantees that
2001
- // dbg.declare does.
2002
- if (DVR.getType () == DbgVariableRecord::LocationType::Declare) {
2041
+ // We only hoist dbg.declare and dbg.coroframe_entry today since it doesn't
2042
+ // make sense to hoist dbg.value since it does not have the same function wide
2043
+ // guarantees that dbg.declare and dbg.coroframe_entry do.
2044
+ if (DVR.getType () == DbgVariableRecord::LocationType::Declare ||
2045
+ DVR.getType () == DbgVariableRecord::LocationType::CoroFrameEntry) {
2003
2046
std::optional<BasicBlock::iterator> InsertPt;
2004
2047
if (auto *I = dyn_cast<Instruction>(Storage)) {
2005
2048
InsertPt = I->getInsertionPointAfterDef ();
@@ -2014,6 +2057,11 @@ void coro::salvageDebugInfo(
2014
2057
InsertPt = F->getEntryBlock ().begin ();
2015
2058
if (InsertPt) {
2016
2059
DVR.removeFromParent ();
2060
+ // If there is a dbg.coroframe_entry being reinserted, insert it as a
2061
+ // dbg.declare instead, so that subsequent passes don't have to deal with
2062
+ // a dbg.coroframe_entry.
2063
+ if (DVR.getType () == DbgVariableRecord::LocationType::CoroFrameEntry)
2064
+ DVR.Type = DbgVariableRecord::LocationType::Declare;
2017
2065
(*InsertPt)->getParent ()->insertDbgRecordBefore (&DVR, *InsertPt);
2018
2066
}
2019
2067
}
0 commit comments