-
Notifications
You must be signed in to change notification settings - Fork 281
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] Add support for UnionCreate op. #5081
Conversation
This adds support for `hw::UnionCreateOp` to ExportVerilog. It works by emitting a bit concatenation and assigning it to a wire with a union type. Each union member may have a prepadding, which is decided by the member's offset size, and a postpadding to ensure that each union element is the same size. The resulting bitconcat is `{prepadding, data, postpadding}`. If there is no padding for a particular member, then bitconcat will not be used. The following example has no offsets, but the member `a` requires post-padding of `1` bit. ```mlir hw.module @unionCreate(%in: i1) -> (out: !hw.union<a: i1, b: i2>) { %0 = hw.union_create "a", %in : !hw.union<a: i1, b: i2> hw.output %0 : !hw.union<a: i1, b: i2> } ``` ```verilog module unionCreate( input in, output union packed { struct packed {logic a; logic [0:0] __post_padding_a;} a;logic [1:0] b;} out ); assign out = {in, 1'h0}; endmodule ```
f377010
to
a1144aa
Compare
|
||
// If the element has no padding, emit it directly. | ||
if (elementWidth == unionWidth) { | ||
emitSubExpr(op.getInput(), Selection); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uenoku I'm not sure if this is the correct precedence here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UnionCreate seems to be spilled to a wire so there is no correctness issue but I think LowestPrecedence
is better. There is an extra parentheses for the following example:
hw.module @unionCreate(%in: i2) -> (out: !hw.union<a: i2, b: i2>) {
%add = comb.add %in, %in : i2
%0 = hw.union_create "a", %add : !hw.union<a: i2, b: i2>
hw.output %0 : !hw.union<a: i2, b: i2>
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed here: #5091
Thanks Hideto!
Sorry about the noise -- was looking at an old rev. |
Thanks for taking a look @teqdruid, I would be grateful for any post-merge suggestions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, though I'm also not sure about the precedence.
This adds support for
hw::UnionCreateOp
to ExportVerilog. It works by emitting a bit concatenation and assigning it to a wire with a union type. Each union member may have a prepadding, which is decided by the member's offset size, and a postpadding to ensure that each union element is the same size. The resulting bitconcat is{prepadding, data, postpadding}
. If there is no padding for a particular member, then bitconcat will not be used.The following example has no offsets, but the member
a
requires post-padding of1
bit.