Skip to content

[DebugInfo] Salvage all stores #72964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 25, 2024

Conversation

Snowy1803
Copy link
Member

@Snowy1803 Snowy1803 commented Apr 11, 2024

Salvage all stores and store_borrow in salvageDebugInfo. Instead of having a special case in Mem2Reg, we can have a more generic implementation which replaces stores with the expected debug info.

Now that Mem2Reg doesn't drop as much info (99.7% less variables dropped by the pass), this also removes the special case in GenericSpecializer (debug values would otherwise be duplicated)

Also, when salvaging stores, we now use the VarInfo's Loc and Scope properties to indicate the declaration of the variable, and use the location of the store for the location where the debug value is set, instead of using a hacky workaround for arguments only.

This PR also adds special support for salvaging copy_addr in the CopyForwarding pass, using the same system for salvaging stores. CopyForwarding is no longer dropping debug info.

This decreases the number of lost variables in the standard library at the SIL level by 1.3%, and doesn't change significantly the amount of variables at the DWARF level.

@Snowy1803
Copy link
Member Author

@swift-ci please test

@Snowy1803 Snowy1803 force-pushed the mem2reg-salvage-store branch from f6deefd to a4b456b Compare April 11, 2024 00:39
@Snowy1803
Copy link
Member Author

Looks like the number of lost variables has actually regressed with the last changes. Needs more work

@Snowy1803 Snowy1803 marked this pull request as draft April 11, 2024 01:07
@Snowy1803 Snowy1803 force-pushed the mem2reg-salvage-store branch 4 times, most recently from f379f65 to 86b6db9 Compare April 18, 2024 22:59
@Snowy1803 Snowy1803 removed the request for review from felipepiovezan April 18, 2024 23:00
@Snowy1803 Snowy1803 force-pushed the mem2reg-salvage-store branch 4 times, most recently from 4ea59e5 to 190a46c Compare April 19, 2024 22:48
@Snowy1803 Snowy1803 marked this pull request as ready for review April 19, 2024 22:49
@Snowy1803
Copy link
Member Author

@swift-ci please test

@@ -1826,6 +1826,39 @@ void swift::endLifetimeAtLeakingBlocks(SILValue value,
});
}

// Replace a store with an appropriate debug value.
static void transferStoreDebugValue(DebugVarCarryingInst DefiningInst,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does DefiningInst imply that this will only work for

%1 = alloc_stack ..., var x
store %1 

and not

%1 = alloc_stack ...
debug_value, var x
store %1

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a DebugVarCarryingInst, so it will be called in both cases: in the first case DefiningInst will be the alloc_stack, in the second case the DefiningInst is the debug_value

@Snowy1803 Snowy1803 force-pushed the mem2reg-salvage-store branch 2 times, most recently from 7229561 to c1e7b49 Compare April 22, 2024 22:58
@Snowy1803
Copy link
Member Author

@swift-ci please test

@Snowy1803
Copy link
Member Author

@swift-ci please test source compatibility

@Snowy1803 Snowy1803 force-pushed the mem2reg-salvage-store branch from c1e7b49 to 23530a0 Compare April 23, 2024 20:12
@Snowy1803 Snowy1803 force-pushed the mem2reg-salvage-store branch from 23530a0 to 584d1db Compare April 25, 2024 01:25
@Snowy1803
Copy link
Member Author

I dropped the commit about uninhabited types, it was causing an infinite loop, and it isn't that impactful

@Snowy1803
Copy link
Member Author

@swift-ci please test

@Snowy1803
Copy link
Member Author

@swift-ci please test source compatibility

/// Returns this location with the auto-generated and prologue bits stripped.
/// These bits only make sense for instructions, and should be stripped for
/// variables.
SILLocation strippedForDebugVariable() const {
Copy link
Contributor

@adrian-prantl adrian-prantl Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SILLocation strippedForDebugVariable() const {
SILLocation cloneWithoutFlags() const {

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.

2 participants