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

Add @likely/@unlikely annotations for blocks #4979

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ChrisDodd
Copy link
Contributor

These will generally be used by backends and simply passed through the frontend/midend, so not much is needed here.

Perhaps some frontend passes (in particular, DoSimplifyControlFlow in frontends/p4/simplify.cpp) could be extended to understand these -- currently, any annotations on a block will inhibit combining the blocks, whereas @likely/@unlikely on a block should not inhibit combining it with a block with no annotation (the annotation should be on the resulting combined block).

See discussion in p4lang/p4-spec#1308

@fruffy fruffy added the p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/). label Oct 24, 2024
@kfcripps kfcripps requested a review from asl October 24, 2024 13:28
@ChrisDodd ChrisDodd marked this pull request as draft October 24, 2024 21:48
@ChrisDodd ChrisDodd force-pushed the cdodd-likely branch 3 times, most recently from d86089f to d482036 Compare October 28, 2024 03:35
@ChrisDodd ChrisDodd marked this pull request as ready for review October 28, 2024 03:36
@ChrisDodd ChrisDodd force-pushed the cdodd-likely branch 2 times, most recently from 46257c9 to 1847985 Compare October 31, 2024 20:28
Copy link
Contributor

@vlstill vlstill left a comment

Choose a reason for hiding this comment

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

Perhaps some frontend passes (in particular, DoSimplifyControlFlow in frontends/p4/simplify.cpp) could be extended to understand these -- currently, any annotations on a block will inhibit combining the blocks, whereas @likely/@unlikely on a block should not inhibit combining it with a block with no annotation (the annotation should be on the resulting combined block).

Sounds reasonable. Is there a risk that the annotation will currently inhibit some optimization? That would be very unfortunate.

However, if we start merging blocks where the annotations don't match exactly, could we end up with both @likely and @unlikely on a single blocks? What should be done then? Imagine code like this:

if (some_runtime_condition) @likely {
    if (some_condition_compiler_proves_true) @unlikely {
        code;
    }
}

obviously, this example is a bit pathological as the code claims the branch is unlikely, but the compiler proves it can be taken always.

- fix a few places annotations on blocks are accidentally lost
- allow merging blocks with same annotation

Signed-off-by: Chris Dodd <cdodd@nvidia.com>
Signed-off-by: Chris Dodd <cdodd@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants