-
Notifications
You must be signed in to change notification settings - Fork 0
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
P4HIR: an experimental MLIR dialect that models P4C IR #20
Comments
I have also been thinking of starting something like this. Partially because I wanted to learn more about MLIR-style compilers. Is the work planned to be open-source? I would consider contributing it as an extension first (and with that a separate repository), since LLVM is such a large dependency. It might be a good idea to have this back end produce code that is executable by a target, e.g., BMv2. Not sure if that is also planned. |
Yes, open-source is the plan! I think having a separate repo is a good idea. I've been working in a local P4C fork in a subdirectory. But it shall be straightforward to move to a separate repo. |
Agree with this! My thought is that the BMv2 JSON format could be defined as another MLIR dialect, and the BMv2 backend could be ported to be transformations from P4HIR dialect to the BMv2 dialect, with a relatively trivial final codegen from BMv2 dialect to BMv2 JSON. This might be a great idea for a standalone follow-up work, once we have a relatively mature P4HIR that covers enough P4C IR to be useful. |
After talking to @asl today, I learned that there is an existing work that basically does this already: https://github.com/barinsim/p4c-mlir Here's my summary of what this project does:
I feel this could be a pretty good starting point for further development. But as @asl suggested, maybe we should hold one step back and present a detailed design for review before diving into the implementation. @barinsim If you are still working on this and are interested in upstreaming these work, maybe we could have some discussions? |
I've been working on this project recently, and will do a lightning talk about it in the upcoming 2024 P4 Workshop. This issue is created for presenting the proposal, tracking the progress, and inviting further discussions with the community.
Proposal
P4HIR (P4 High-level IR) is an experimental MLIR dialect that aims to model the existing P4C IR by supporting bi-directional translations to and from the P4C IR. In more detail:
The current proposal is pretty high-level. There are a lot to figure out in the technical details. I'd like to discuss with the community on those as we make progress pushing this idea forward.
Plan and progress
Other notes
P4C - MLIR concepts mapping
To give a brief introduction to MLIR for P4C developers, we can map some P4C concepts to corresponding MLIR concepts.
.def
file.td
file (ODS, TableGen)The text was updated successfully, but these errors were encountered: