Skip to content
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

Reserve stack space for passing values between uops #126612

Closed
mpage opened this issue Nov 9, 2024 · 1 comment
Closed

Reserve stack space for passing values between uops #126612

mpage opened this issue Nov 9, 2024 · 1 comment
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@mpage
Copy link
Contributor

mpage commented Nov 9, 2024

Feature or enhancement

Proposal:

We occasionally want to pass values between the uops that are composed to form a specialized instruction. The natural (only?) way to do this is to pass them on the stack. This is possible if the stack effect of the generic instruction is greater than or equal to the number of values being passed, but may not be possible otherwise, because the stack size is calculated by using the stack effect of only the generic instructions.

I'm running into this as I try to make LOAD_ATTR_MODULE thread-safe in free-threaded builds. I would like to pass the module dict's keys object from _CHECK_ATTR_MODULE to _LOAD_ATTR_MODULE. Unfortunately, LOAD_ATTR has a stack effect of 0 or 1 and the module needs to remain on the stack, so we are not guaranteed to have sufficient stack space to pass the keys object.

Here are a few possible solutions:

  1. Modify the metadata generator and bytecode compiler to compute the maximum stack effect of each specialized instruction in a family, and use the maximum the when considering the effect that an instruction has on the maximum stack depth. This is the most comprehensive solution, but is quite complicated.
  2. Allow pushing and popping a handful of values beyond the maximum stack depth, similar to how the red zone works.
  3. Add space for a small number of extra values (1 or 2) after we've calculated the stack depth. This limits the number of values that can be passed safely, but is quite simple.

I think (3) is probably the best option; it's simple and should work for most cases.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@mpage mpage added type-feature A feature request or enhancement interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Nov 9, 2024
@mpage mpage self-assigned this Nov 9, 2024
@mpage
Copy link
Contributor Author

mpage commented Nov 9, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant