Skip to content

Commit 1a07e66

Browse files
committed
[debug-info] Implement a global dataflow that propagates debug info for async vars and clones the dbg info after funclet points.
The overall flow of the pass is: 1. We walk over the blocks summarizing the debug info instruction the blocks gen as well as whether or not the block had an async funclet edge with in it. 2. We then perform a simple forward iterative optimistic dataflow using intersection at merge points. At points where we find after merging that we have a conflict and thus need to stop propagation, we insert a debug_value undef. 3. We then walk the CFG again visiting only blocks that we know had async funclet edges. We then walk each said block from top to bottom starting with the propagating gen information and updating as we go, dumping the current set of debug_info we are tracking after each coroutine funclet boundary. rdar://85020571
1 parent ee1b6f1 commit 1a07e66

File tree

7 files changed

+949
-11
lines changed

7 files changed

+949
-11
lines changed

include/swift/SIL/DebugUtils.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,24 +237,26 @@ bool hasNonTrivialNonDebugTransitiveUsers(
237237
/// operators to access functionality from the underlying instruction when
238238
/// needed.
239239
struct DebugVarCarryingInst {
240-
enum class Kind {
240+
enum class Kind : uint8_t {
241241
Invalid = 0,
242242
DebugValue,
243243
AllocStack,
244244
AllocBox,
245245
};
246246

247-
Kind kind;
248247
SILInstruction *inst;
248+
Kind kind;
249+
uintptr_t spareBits : (sizeof(uintptr_t) - sizeof(Kind)) * 8;
249250

250-
DebugVarCarryingInst() : kind(Kind::Invalid), inst(nullptr) {}
251+
DebugVarCarryingInst() : inst(nullptr), kind(Kind::Invalid), spareBits(0) {}
251252
DebugVarCarryingInst(DebugValueInst *dvi)
252-
: kind(Kind::DebugValue), inst(dvi) {}
253+
: inst(dvi), kind(Kind::DebugValue), spareBits(0) {}
253254
DebugVarCarryingInst(AllocStackInst *asi)
254-
: kind(Kind::AllocStack), inst(asi) {}
255-
DebugVarCarryingInst(AllocBoxInst *abi) : kind(Kind::AllocBox), inst(abi) {}
255+
: inst(asi), kind(Kind::AllocStack), spareBits(0) {}
256+
DebugVarCarryingInst(AllocBoxInst *abi)
257+
: inst(abi), kind(Kind::AllocBox), spareBits(0) {}
256258
DebugVarCarryingInst(SILInstruction *newInst)
257-
: kind(Kind::Invalid), inst(nullptr) {
259+
: inst(nullptr), kind(Kind::Invalid), spareBits(0) {
258260
switch (newInst->getKind()) {
259261
default:
260262
return;
@@ -280,6 +282,15 @@ struct DebugVarCarryingInst {
280282
/// '->'. This keeps the wrapper light weight.
281283
SILInstruction *operator->() const { return inst; }
282284

285+
bool operator==(const DebugVarCarryingInst &other) const {
286+
return kind == other.kind && inst == other.inst &&
287+
spareBits == other.spareBits;
288+
}
289+
290+
bool operator!=(const DebugVarCarryingInst &other) const {
291+
return !(*this == other);
292+
}
293+
283294
/// Add support for this struct in `if` statement.
284295
explicit operator bool() const { return bool(kind); }
285296

@@ -351,7 +362,8 @@ struct DebugVarCarryingInst {
351362
case Kind::AllocStack:
352363
return cast<AllocStackInst>(inst)->getWasMoved();
353364
case Kind::AllocBox:
354-
llvm_unreachable("Not implemented");
365+
// We do not support moving alloc box today, so we always return false.
366+
return false;
355367
}
356368
}
357369

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ PASS(MoveFunctionCanonicalization, "sil-move-function-canon",
440440
"function checking.")
441441
PASS(DebugInfoCanonicalizer, "sil-onone-debuginfo-canonicalizer",
442442
"Canonicalize debug info at -Onone by propagating debug info into coroutine funclets")
443+
PASS(MovedAsyncVarDebugInfoPropagator, "sil-moved-async-var-dbginfo-propagator",
444+
"Propagate debug info from moved async vars after coroutine funclet boundaries")
443445
PASS(PruneVTables, "prune-vtables",
444446
"Mark class methods that do not require vtable dispatch")
445447
PASS_RANGE(AllPasses, AADumper, PruneVTables)

lib/SILOptimizer/Mandatory/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ target_sources(swiftSILOptimizer PRIVATE
2121
LexicalLifetimeEliminator.cpp
2222
LowerHopToActor.cpp
2323
MandatoryInlining.cpp
24+
MovedAsyncVarDebugInfoPropagator.cpp
2425
MoveFunctionCanonicalization.cpp
2526
MoveKillsCopyableAddressesChecker.cpp
2627
MoveKillsCopyableValuesChecker.cpp

0 commit comments

Comments
 (0)