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

gh-93356: Lay out exception handling code at end of code unit #92769

Merged
merged 31 commits into from
Jun 2, 2022

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented May 13, 2022

Closes #93356.

Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

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

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

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

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

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

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

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.

Python/compile.c Outdated Show resolved Hide resolved
@iritkatriel iritkatriel marked this pull request as ready for review May 30, 2022 15:51
@iritkatriel iritkatriel changed the title [WIP] backend detects cold blocks and lays them out at end of function gh-93356: Lay out exception handling code at end of code unit May 30, 2022
Python/compile.c Outdated
Comment on lines 7472 to 7487
while(b && b->b_next) {
basicblock *next = b->b_next;
if (next->b_cold) {
if (next->b_next) {
b->b_next = next->b_next;
next->b_next = NULL;
tail->b_next = next;
tail = next;
}
} else {
b = next;
}
if(next == origtail) {
break;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This took me a while to understand, but maybe that's just the nature of linked list code.

My biggest confusion was that meaningful fallthrough b_next linkages are broken and then re-established. There could maybe be an inner loop to scan for streaks of cold blocks, so that they can all be moved to the end with an assignment each to b.b_next, tail.b_next, last_of_streak.b_next, but I'm not sure if that makes the edge cases easier or harder.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the new version is easier to follow. Let me know.

@sweeneyde
Copy link
Member

LGTM. I think the linked list change is clearer now, thanks.

@iritkatriel iritkatriel added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jun 1, 2022
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit 6a454c8 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jun 1, 2022
@iritkatriel
Copy link
Member Author

Buildbots are happy. 🍾

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.

Lay out exception handling code at end of code unit
4 participants