Skip to content

Commit dd5d2f4

Browse files
authored
Merge pull request #58410 from gottesmm/move-function-dbg-info-dataflow
[debug-info] Implement a global dataflow that propagates debug info for async vars and clones the dbg info after funclet points.
2 parents f1d5751 + 640d590 commit dd5d2f4

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
@@ -448,6 +448,8 @@ PASS(DebugInfoCanonicalizer, "sil-onone-debuginfo-canonicalizer",
448448
"Canonicalize debug info at -Onone by propagating debug info into coroutine funclets")
449449
PASS(PartialApplySimplification, "partial-apply-simplification",
450450
"Transform partial_apply instructions into explicit closure box constructions")
451+
PASS(MovedAsyncVarDebugInfoPropagator, "sil-moved-async-var-dbginfo-propagator",
452+
"Propagate debug info from moved async vars after coroutine funclet boundaries")
451453
PASS(PruneVTables, "prune-vtables",
452454
"Mark class methods that do not require vtable dispatch")
453455
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)