Skip to content

[lldb][swift] Increase number of Rows inspected when unwinding async functions #10698

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

Conversation

felipepiovezan
Copy link

@felipepiovezan felipepiovezan commented May 17, 2025

We were overly conservatives in our initial estimations: if callee saved
registers are used, they are usually spilled first, increasing the
number of rows in the prologue.

This also revealed a bug in computing the offset of a vector iterator:

-  int row_idx = fp_locs.end() - it;
+  int row_idx = it - fp_locs.begin();

Testing this is unfortunately difficult: a way of forcing register
spilling is required. For now, this commit tweaks one of the existing
tests in a way that seems to reliably spill more registers, but there
are no guarantees this will continue to be the case. Other testing
mechanisms need to be created.

@felipepiovezan felipepiovezan requested a review from a team as a code owner May 17, 2025 02:02
@felipepiovezan
Copy link
Author

@swift-ci test

@felipepiovezan felipepiovezan force-pushed the felipe/tweak_unwind_rows branch from 9c8ca42 to 8137dee Compare May 19, 2025 04:06
@felipepiovezan
Copy link
Author

@swift-ci test

@jasonmolenda
Copy link

jasonmolenda commented May 19, 2025

I spoke in DM with Felipe about one small concern, the AAPCS ABI has 10 general purpose registers marked callee-preserved, and 8 floating point registers. If they're stored with STP instructions, that means we can have the initial unwind state row, two standard prologue rows, and then 9 rows of registers being stored to stack before the stack pointer is copied into the frame pointer, worst possible case?
This is very UNLIKELY, and if the function is a leaf function the compiler will prefer to use volatile registers that don't need to be saved, but I think it is possible.

…functions

We were overly conservatives in our initial estimations: if callee saved
registers are used, they are usually spilled first, increasing the
number of rows in the prologue.

This also revealed a bug in computing the offset of a vector iterator:

```
-  int row_idx = fp_locs.end() - it;
+  int row_idx = it - fp_locs.begin();
```

Testing this is unfortunately difficult: a way of forcing register
spilling is required. For now, this commit tweaks one of the existing
tests in a way that seems to reliably spill more registers, but there
are no guarantees this will continue to be the case. Other testing
mechanisms need to be created.
@felipepiovezan felipepiovezan force-pushed the felipe/tweak_unwind_rows branch from 8137dee to 00ccdc2 Compare May 19, 2025 14:45
@felipepiovezan
Copy link
Author

felipepiovezan commented May 19, 2025

I spoke in DM with Felipe about one small concern, the AAPCS ABI has 10 general purpose registers marked callee-preserved, and 8 floating point registers. If they're stored with STP instructions, that means we can have the initial unwind state row, two standard prologue rows, and then 9 rows of registers being stored to stack before the stack pointer is copied into the frame pointer, worst possible case? This is very UNLIKELY, and if the function is a leaf function the compiler will prefer to use volatile registers that don't need to be saved, but I think it is possible.

Based on this conversation, I've pushed an update to increase this threshold to 12, and add some sub-optimal testing. As mntioned in the commit message, I'll need to investigate reliable ways of forcing register spilling as a follow up

@felipepiovezan
Copy link
Author

@swift-ci test

@felipepiovezan
Copy link
Author

felipepiovezan commented May 19, 2025

Github is not showing the windows CI link, but it is running here: https://ci-external.swift.org/job/apple-llvm-project-pull-request-windows/2071/

@felipepiovezan
Copy link
Author

The windows CI finished and was successful, but somehow github is not showing that..

@felipepiovezan
Copy link
Author

@swift-ci test windows platform

@adrian-prantl adrian-prantl merged commit 3307906 into swiftlang:swift/release/6.2 May 20, 2025
3 checks passed
@felipepiovezan felipepiovezan deleted the felipe/tweak_unwind_rows branch May 21, 2025 03:00
felipepiovezan added a commit that referenced this pull request May 30, 2025
…functions (#10698)

We were overly conservatives in our initial estimations: if callee saved
registers are used, they are usually spilled first, increasing the
number of rows in the prologue.

This also revealed a bug in computing the offset of a vector iterator:

```
-  int row_idx = fp_locs.end() - it;
+  int row_idx = it - fp_locs.begin();
```

Testing this is unfortunately difficult: a way of forcing register
spilling is required. For now, this commit tweaks one of the existing
tests in a way that seems to reliably spill more registers, but there
are no guarantees this will continue to be the case. Other testing
mechanisms need to be created.

(cherry picked from commit 3307906)
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.

3 participants