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

[WIP] backend detects cold blocks and lays them out at end of function #92769

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented May 13, 2022

This version does the cold block detection through control flow. Currently excluding two cases that need to be fixed:

  1. fallthrough from cold block to warm block (need to replace fall through by explicit jump)
  2. generators and coroutine (I don't know yet why they don't work, so for now I skip them).

@iritkatriel iritkatriel requested a review from markshannon as a code owner May 13, 2022
@iritkatriel iritkatriel marked this pull request as draft May 13, 2022
Copy link
Member

@markshannon markshannon left a comment

Would it better to add a warm parameter to mark_reachable?
mark_warm, mark_cold and mark_reachable are all doing the same thing, except for which edges they follow.

Python/compile.c Outdated Show resolved Hide resolved
@markshannon
Copy link
Member

@markshannon markshannon commented May 13, 2022

Why does fall through from a cold block to a warm block need to be treated specially?

Unless I'm mistaken:
warm_set = reachable(follow_exception_edges=False)
reachable_set = reachable(follow_exception_edges=True)
cold_set = reachable_set - warm_set
Am I missing something?

@iritkatriel
Copy link
Member Author

@iritkatriel iritkatriel commented May 13, 2022

Why does fall through from a cold block to a warm block need to be treated specially?

Unless I'm mistaken: warm_set = reachable(follow_exception_edges=False) reachable_set = reachable(follow_exception_edges=True) cold_set = reachable_set - warm_set Am I missing something?

We can't change b->next of a block with a fallthrough.

@markshannon
Copy link
Member

@markshannon markshannon commented May 13, 2022

We can't change b->next of a block with a fallthrough.

You could convert it to a jump and eliminate the fallthrough edge.

@iritkatriel
Copy link
Member Author

@iritkatriel iritkatriel commented May 13, 2022

We can't change b->next of a block with a fallthrough.

You could convert it to a jump and eliminate the fallthrough edge.

That's the idea. But there could already be a conditional jump there, so if we don't want to have to worry about multiple jumps in the same block for the remaining parts of the assembler, it needs to be a new block.

…gs calculated only once. don't pass compiler/assembler around as much
@iritkatriel
Copy link
Member Author

@iritkatriel iritkatriel commented May 13, 2022

Would it better to add a warm parameter to mark_reachable?
mark_warm, mark_cold and mark_reachable are all doing the same thing, except for which edges they follow.

My first version did mark_cold/warm at the same time as mark_reachable. But I had a situation where the graph changed between that time and the time when I can do the push_cold_to_end. So now mark cold/warm happens just before push_cold_to_end. I could possibly share the code though.

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

Successfully merging this pull request may close these issues.

None yet

3 participants