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

[SV] Add sv.func, sv.return and sv.func.call operations #7003

Merged
merged 5 commits into from
May 16, 2024

Conversation

uenoku
Copy link
Member

@uenoku uenoku commented May 8, 2024

This PR (separated from #6977) adds function call constructs (sv.func, sv.return and sv.func.call) to SV dialect.

  • sv.func -- this op is between hw.module and func.func. This op implement interfaces PortList, HWModuleLike and FunctionOpInterface. Similar to hw.module, we can preserve argument names and mix the order of input and output arguments. Following func.func empty body indicates that the op is a declaration. Currently sv/func is defined as "automatic" function in SV.
  • sv.return -- terminator for sv.func. We cannot reuse neither hw.output nor func.func since they have constraints on parent op(and I think it's not reasonable to loose them).
  • sv.func.call and sv.func.call.procedural. Two operations are added because output arguments cannot be used non-procedural regions.

@uenoku uenoku requested a review from darthscsi as a code owner May 8, 2024 11:55
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.

Very cool 🥳

FunctionOpInterface, HasParent<"mlir::ModuleOp">]> {
let summary = "A System Verilog function";
let description = [{
`sv.func` reresents System Verilog function in SV spec 13.4.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`sv.func` reresents System Verilog function in SV spec 13.4.
`sv.func` reresents SystemVerilog function in SV spec 13.4.

Can you also mention which exact version of the spec this is? They tend to insert paragraphs, which makes the numbering unstable. Something like see IEEE 1800-2017 section 13.4 "section title" maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added! Thank you for great suggestion!

Comment on lines +2406 to +2414
// Non-procedural call cannot have output arguments.
if (referencedOp.getNumOutputs() != 1 ||
!referencedOp.getExplicitlyReturnedType()) {
auto diag = emitError()
<< "function called in a non-procedural region must "
"return a single result";
diag.attachNote(referencedOp.getLoc()) << "doesn't satisfy the constraint";
return failure();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@uenoku
Copy link
Member Author

uenoku commented May 16, 2024

I'm going to merge the PR. Post-merge review is welcomed. The current implementation around a return value is slightly hacky especially the use of "sv.func.explicitly_returned". Probably a better way would be to introduce HWFunctionType with an explicit return type but I'll consider it as a follow-up.

@uenoku uenoku merged commit bd259e7 into main May 16, 2024
4 checks passed
@uenoku uenoku deleted the dev/hidetou/sv-func-pr branch May 16, 2024 07:52
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

2 participants