Skip to content

[DebugInfo] Prepend deref to existing DebugValueInsts#89254

Draft
Snowy1803 wants to merge 6 commits into
swiftlang:mainfrom
Snowy1803:prepend-deref
Draft

[DebugInfo] Prepend deref to existing DebugValueInsts#89254
Snowy1803 wants to merge 6 commits into
swiftlang:mainfrom
Snowy1803:prepend-deref

Conversation

@Snowy1803
Copy link
Copy Markdown
Member

@Snowy1803 Snowy1803 commented May 19, 2026

Based on #89224

Instead of having to recreate new debug value instructions when a deref operator needs to be prepended (in passes where an object is moved to the stack), it is now possible to prepend a deref in place.

When a reconstruction block exists, the only correct way to prepend a deref is by adding a load at the start of the reconstruction block, as the reconstruction block is interpreted before the DIExpr.
Otherwise, a bit is set on the DebugValueInst to signal that a deref operator must be prepended to the DIExpr returned by getVarInfo.

All passes have been updated to use this new prependDeref rather than SILBuilder::createDebugValueAddr, so this function has also been removed.

Snowy1803 added 6 commits May 18, 2026 18:00
Debug values have their own, more powerful, type chain check.
AllocStackInst have a deref, so this check would be ignored, and
AllocBoxInst doesn't support storing a different type.
Load instructions aren't handled in LLVM's salvageDebugInfo due to how
unpredictable LLVM's optimization passes can be. In Swift, we only add
loads to debug reconstruction blocks if we know it is correct.
Instead of having to recreate new debug value instructions when a
deref operator needs to be prepended (in passes where an object is
moved to the stack), it is now possible to prepend a deref in place.

When a reconstruction block exists, the only correct way to prepend
a deref is by adding a load at the start of the reconstruction block,
as the reconstruction block is interpreted before the DIExpr.

Otherwise, a bit is set on the DebugValueInst to signal that a deref
operator must be prepended to the DIExpr returned by getVarInfo. This
bit cannot be set if a reconstruction block exists.
Replace uses of createDebugValueAddr in passes, that were used to
rewrite debug value instructions with a prepended deref, to use the
prependDeref function to prepend it in place.
Replace the use of createDebugValueAddr in salvageLoadDebugInfo, that
was used to rewrite debug value instructions with a prepended deref, to
use the prependDeref function to prepend it in place, and move it to the
correct place.
Remove the now unused SILBuilder::createDebugValueAddr function. Passes
must always update existing debug value instructions rather than
recreating new ones, and emitDebugDescription has been updated to just
prepend an op_deref. This was the last remnant of DebugValueAddrInst.
@Snowy1803
Copy link
Copy Markdown
Member Author

@swift-ci test

1 similar comment
@Snowy1803
Copy link
Copy Markdown
Member Author

@swift-ci test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant