-
Notifications
You must be signed in to change notification settings - Fork 31
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 Moore MIR dialect and move codegen to CIRCT #235
Comments
@maerhart What do you think about this plan? |
Sounds great to me! Just wondering whether we can use (part of) the SV dialect in the lowering chain from SV AST to HW/Comb/LLHD. And whether this would make sense at all since the SV dialect is targeted at printing and we are focussed on lowering. How would such a Moore MIR dialect look like? What exactly is the goal of HIR? |
I think you're right and it'll probably be difficult to use the SV dialect directly from the start. That dialect is being driven largely by what is needed for good Verilog emission, which may be a use case very distinct from representing SV from a frontend point of view. I'm not saying that they shouldn't share as much as possible, but given the different design goals it sounds like a better approach to first build out the Moore-specific dialect, and then try to nudge that and the SV dialect in CIRCT closer together, and increase the reuse between them.
Yeah I was thinking about something like you describe. MIR should be the "final bastion" of SV and be a truthful representation of the semantics of the input file, with all ambiguities and implicitness removed, and all types fully known. So pretty much what you describe: operations for all the constructs, expressions, and statements that SV has to offer. This would include all the classes, verification craziness like properties and sequences, clocking blocks, programs, interfaces, packages, assertions, and much more.
The initial goal in Moore was to get around a few limitations in the early days of the AST and query system. It was intended to offer a way to resolve syntactic ambiguities (for example the cast I could totally see operations survive all the way from the AST down to the MIR. In the Rust world I was very careful to prevent mutation of the ops in the different IRs, to enforce safety and make passes purely additive. But in MLIR with the mutation galore and rampant unsafety of C++, we can basically start to mutate operations as we see fit. For example, we might just have one single
You are totally right that replicating a lot of the ops just for the sake of providing a few restrictions on them (like "here the types need to be known") is probably wasteful. We could also just declare "MIR" as being a subset of all the Moore dialect operations, with certain additional restrictions on types. |
My suggestion would be to start with the minimum that is needed to represent the MIR and move codegen over to CIRCT. I'm pretty sure this will already instruct quite a few design decisions, and requires implementing the fully resolved SV type system as a start. Then we can look into having implicit casts inserted on the CIRCT side, and start to move monomorphization over to CIRCT as well 😄 |
Thank you for the detailed description! I completely agree with that. I already started with a skeleton dialect for Moore MIR, some types and three ops forming a simple example plus lowering to HW/LLHD here. |
Wow this is some seriously amazing work! I love it 🎉! Let me add some comments right to the commit itself. It's great that you went for a minimal working example. I would suggest that we try to merge this into upstream CIRCT as soon as possible, to keep the PRs small and easy for people to digest. Then it can evolve within CIRCT. |
Thanks for the quick feedback! I did some cleanup and addressed your comments. The diff against main is here. Let me know if there's anything else I should change or if it's ready for a PR. We just have to wait until the LLVM Submodule update PR is merged as I used the new type assembly format feature for convenience. |
Cool thanks a lot, this looks great! Since we're only working with 3 types at the moment (and the LLVM submodule update upstream might take a while to get merged), would it make sense to just use the old-school manual type parsing approach instead to unblock this PR? |
Yeah that's actually an easy change. I rebased to the old LLVM version and opened the PR in CIRCT. |
#234 implements code generation by linking against the CIRCT project and using MLIR to generate and emit assembly. As a first step towards moving more of Moore's code over to MLIR, we should add a "Moore MIR" dialect to CIRCT.
This dialect should aim to model the
mir::Rvalue
andmir::Lvalue
representations, and add new MLIR ops to represent the remaining SV statements and declarations (modules, processes, instances, variables, nets, assigns, conditionals, loops -- basically everything thatcodegen.rs
knows how to emit code for, but isn't currently captured as part of themir
module). This is likely to require adding a full implementation ofsvlog/ty.rs
in CIRCT.Once this dialect exists, we can raise the level of abstraction in
codegen.rs
and emit the Moore MIR dialect instead of all the low level HW/Comb/LLHD/Standard. The translation from MIR to those low-level dialects can then move into the CIRCT project as a dedicated lowering pass. This is phenomenal because MIR being an MLIR dialect will allow us to write very concise tests that check code generation for specific SV features and semantics without the whole parser and type checking in the loop. The MIR then ends up representing a full SV design with all types and implicit operations resolved to explicit things -- making it essentially an SV semantics dialect.Todo
src/svlog/ty.rs
)moore.mir.*
operations to represent the Moore MIRcodegen.rs
instead of low-level dialectsThe text was updated successfully, but these errors were encountered: