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

Support for op= assignments in the frontend/midend #5108

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

Conversation

ChrisDodd
Copy link
Contributor

  • these are parsed as IR::OpAssignmentStatements
  • they are (optionally) converted to normal assignments in the frontend
  • they may be kept as special nodes by backends that desire to treat them specially (making it easier to generate 2-operands instructions)
  • frontend and midend passes are all made aware of the new IR node kinds and deal with them appropriately (either disabling transforms or fixing them to be correct in the presence of OpAssignmentStatements

@fruffy fruffy added core Topics concerning the core segments of the compiler (frontend, midend, parser) p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/). labels Jan 22, 2025
@fruffy
Copy link
Collaborator

fruffy commented Jan 22, 2025

There was a similar PR once but it was never resolved #3669. I guess this one supersedes it.

Related P4-specification issue: p4lang/p4-spec#1139

@jafingerhut
Copy link
Contributor

It seems like a good idea to have a test case that has side effects in the l-value, e.g. something like hdr.mystack[f(x)] += 1;, where f(x) is some expression with a side effect that should only be executed once. Perhaps the f(x) could be replaced with a call to v1model's random extern function? https://github.com/p4lang/p4c/blob/main/p4include/v1model.p4#L367

- these are parsed as IR::OpAssignmentStatements
- they are (optionally) converted to normal assignments in the frontend
- they may be kept as special nodes by backends that desire to treat
  them specially (making it easier to generate 2-operands instructions)
- frontend and midend passes are all made aware of the new IR node kinds
  and deal with them appropriately (either disabling transforms or
  fixing them to be correct in the presence of OpAssignmentStatements

Signed-off-by: Chris Dodd <cdodd@nvidia.com>
@ChrisDodd
Copy link
Contributor Author

It seems like a good idea to have a test case that has side effects in the l-value,

I added this in a second testcase, as well as pulling in @rst0git's testcase

rst0git and others added 2 commits January 22, 2025 22:37
This patch adds support for compound assignment expressions
of the form `E1 op= E2`.

Signed-off-by: Radostin Stoyanov <radostin.stoyanov@eng.ox.ac.uk>
Signed-off-by: Chris Dodd <cdodd@nvidia.com>
Signed-off-by: Chris Dodd <cdodd@nvidia.com>
@fruffy
Copy link
Collaborator

fruffy commented Jan 22, 2025

The P4Testgen failures are because of crashes in BMv2. It is possible that the generated JSON is invalid.

@ChrisDodd
Copy link
Contributor Author

The P4Testgen failures are because of crashes in BMv2. It is possible that the generated JSON is invalid.

The .stf test I wrote by hand works fine, so BMv2 is at least reading the JSON and running that packet correctly.

The testgen script seems to be creating tests with packets that are too short (the p4 program expects a packet with 48 bytes of headers), so it is getting PacketTooShort in the parser and then apparently crashing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Topics concerning the core segments of the compiler (frontend, midend, parser) 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.

4 participants