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

[ExportVerilog][HW] Introduce HWEmittableModuleLike interface and use it for Prepare, NFC #7004

Merged
merged 2 commits into from
Jun 6, 2024

Conversation

uenoku
Copy link
Member

@uenoku uenoku commented May 8, 2024

This is separated from #6977. This changes pre-passes for ExportVerilog to run on HWEmittableModuleLike instead of HWModuleOp. #6977 is going to add a support for SV func op and legalization needs to be ran on SV func as well.

HWEmittableModuleLike is a new interface that inherits Emittable+HWModuleLike. I considered to use a trait but we cannot use a trait for pass scheduling so an interface is used.

@teqdruid
Copy link
Contributor

teqdruid commented May 9, 2024

I'm not sure this is a good idea. Ops that implement hwmodulelike don't necessarily have semantics which directly map to systemverilog semantics. Have you searched for ops that implement it to ensure that we want them to be directly emitted to verilog?

To be clear, I'm not sure it's a bad idea either.

@uenoku
Copy link
Member Author

uenoku commented May 9, 2024

Thank you for the feedback and that's good point. I thought HWModuleOps feed into ExportVerilog are assumed to be emittable as SV but I agree that it would be nicer to explicitly check that.

I'd like to propose to use Emittable trait

def Emittable : NativeOpTrait<"Emittable"> {
let cppNamespace = "::circt::emit";
}
and run PrepareForEmission on HWModuleLike with Emittable trait (or extend Emittable trait to op interface).

@teqdruid
Copy link
Contributor

Thank you for the feedback and that's good point. I thought HWModuleOps feed into ExportVerilog are assumed to be emittable as SV but I agree that it would be nicer to explicitly check that.

I'd like to propose to use Emittable trait

def Emittable : NativeOpTrait<"Emittable"> {
let cppNamespace = "::circt::emit";
}

and run PrepareForEmission on HWModuleLike with Emittable trait (or extend Emittable trait to op interface).

Does ExportVerilog / PrepareForEmission already depend on (know about) the Emission dialect?

I'm more comfortable with HWModuleLike ops to have to opt-in to Emittable. I'd be even more comfortable if Emittable were an OpInterface with a bool emittedToVerilog() method.

This raises the question: why do we want all HWModuleLike ops to be capable of being emitted to Verilog? Why not lower them into HWModuleOps? Is there a specific use-case?

@teqdruid
Copy link
Contributor

Or is this intended for preparation only? In that case, I think that any op which implements a future method like Emittable.shouldBePreparedForSVEmission() (or whatever name) should get legalized -- regardless of whether or not it implements HWModuleLike. Given that you probably need things like ports when preparing, though, this can be considered future work so long as it's documented as a restriction.

@uenoku
Copy link
Member Author

uenoku commented May 13, 2024

Does ExportVerilog / PrepareForEmission already depend on (know about) the Emission dialect?

Yes.

This raises the question: why do we want all HWModuleLike ops to be capable of being emitted to Verilog? Why not lower them into HWModuleOps? Is there a specific use-case?

sv.func is the first use case that is not HWModuleop and also needs PrepareForeEmission. HWModuleLike provides sufficient interface for PrepareForEmisson especially regarding port name legalization.

Or is this intended for preparation only?

Yes. PrepareForEmission and probably PrettifyVerilog.

@teqdruid
Copy link
Contributor

ok. I have no problem with this assuming that you do something with the Emittable trait.

Base automatically changed from dev/hidetou/sv-func-pr to main May 16, 2024 07:52
@uenoku uenoku requested a review from darthscsi as a code owner May 16, 2024 07:52
@uenoku uenoku changed the title [ExportVerilog] Make ExportVerilog robust for HWModuleLike, NFC [ExportVerilog][HW] Introduce HWEmittableModuleLike interface and use it for Prepare, NFC Jun 4, 2024
@uenoku
Copy link
Member Author

uenoku commented Jun 4, 2024

@teqdruid Sorry for the late update. I iterated a bit more and I'm inclined to introduce a new interface HWEmittableModuleLike which inherits HWModuleLike and Emittable to run SV specific legalization.
PrepareForEmission, PrettifyVerilog and HWLegalizeModule should be converted into interface pass (in the current PR only PrepareForEmission is modified).

I thought it might make sense to put this interface to SV but I end up adding the interface to HW due to the dependency around HWModuleLike.

@uenoku uenoku requested a review from fabianschuiki June 4, 2024 12:11
module.walk([&](HWModuleOp op) { modulesToPrepare.push_back(op); });
SmallVector<HWEmittableModuleLike> modulesToPrepare;
module.walk(
[&](HWEmittableModuleLike op) { modulesToPrepare.push_back(op); });
Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't need to be walk so will change it.

Copy link
Contributor

@dtzSiFive dtzSiFive left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for iterating on this.

include/circt/Dialect/HW/HWOpInterfaces.td Outdated Show resolved Hide resolved
include/circt/Dialect/HW/HWOpInterfaces.td Outdated Show resolved Hide resolved
Copy link
Contributor

@fabianschuiki fabianschuiki left a comment

Choose a reason for hiding this comment

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

LGTM! 🥳

@teqdruid
Copy link
Contributor

teqdruid commented Jun 6, 2024

This approach sounds reasonable to me. Had a quick look through the diff and it looks about right to me.

@uenoku uenoku merged commit 927a376 into main Jun 6, 2024
4 checks passed
@uenoku uenoku deleted the dev/hidetou/prepare-nfc branch June 6, 2024 15:33
uenoku added a commit that referenced this pull request Jun 7, 2024
… and use it for Prepare, NFC (#7004)"

This reverts commit 927a376.
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.

None yet

4 participants