-
Notifications
You must be signed in to change notification settings - Fork 299
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
[ImportVerilog] [SROA] [Mem2Reg][Canonicalizers]Support Passes for Nested Type #7158
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
I think you probably want to have the It generally makes life easier in the future if ops do only one thing, and you then compose multiple ops to do more complicated things. Here for example, you'd want |
This comment was marked as outdated.
This comment was marked as outdated.
Yeah you are right, that is indeed very annoying. I think you could create a type constraint like Alternatively we could think about whether we actually use the PackedType and UnpackedType base classes often... If not, we might be able to change the type hierarchy such that we don't primarily distinguish between packed/unpacked. |
Thanks @fabianschuiki . It is very professional design. As I understanding HWAggregates Op designing, these kind of ops are all with Pure trait which means memory operations are with other Ops such as hw.wire or something. |
This comment was marked as outdated.
This comment was marked as outdated.
I think except |
If
Maybe we can keep the form the same as before the conversion. Like |
This comment was marked as outdated.
This comment was marked as outdated.
And I think we can lower |
%oldStruct = hw.struct_create("x": %a, "y": %b)
%newStruct = hw.struct_inject %oldStruct, "y", %c
// oldStruct remains unchanged, newStruct looks like this:
// %newStruct = hw.struct_create("x": %a, "y": %c) And I agree with you: we should add the |
@fabianschuiki But hw dialect does not have the op like union_inject, which is weired. |
That is probably because unions don't really have fields that you want to change individually. The fields in a union are just different ways to look at the exact same data. Assigning a union's field is the same thing as replacing the union with a new union which has this field set. So instead of |
Thanks! |
This comment was marked as outdated.
This comment was marked as outdated.
@fabianschuiki It seems it is not creating new struct when lowering to LLVM, refering to circt/test/Conversion/HWToLLVM/convert_aggregates.mlir |
Yes, it lowers directly to the corresponding LLVM |
Doing SROA for module-level variables sounds like a reasonable thing to do! Or maybe that's not even necessary, and Mem2Reg can create the corresponding I wouldn't be too concerned about the naming of variables and structs: the |
It may be lowered to llvm.mlir.undef : !llvm.struct<(i32, i2, i1)> which really create a struct
and this new struct will replace use with old struct
Some pass to construct struct inject chain.
|
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.
Nice! Can you add a test for the folder of the StructInjectOp? I was wondering whether we have folders and constant materialization for structs already. It would be nice to have 😃
Yes, I have added relating test for struct_inject folding test. This test will fold duplicate struct injecting to the same field. |
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 nice! Thanks for doing all this hard work 🥳 Just a minor comment on a bit of possibly unneeded code.
For the new concept of Moore dialect, some operations will be defined as memory-related operations. Modeling
memref
Dialect andLLVM
dialect, the operation relationship is as follows:ReadOp
andblockingAssignOp
are related toloadOp
andstoreOp
.VariableOp
is related toallocaOp
.However, the operations mentioned below are for basic types. This PR will support nested types in the following way:
VariableOp
with nested types is still related toallocaOp
(will be replaced withstructCreateOp
andUnionCreateOp
).structExtractRefOp
is related tostoreOp
.structExtractOp
is related toloadOp
.To implement this:
Since these operations will be lowered to the
hw
dialect, the design largely refers to thehw
dialect.Add the trait
DestructurableAllocationOpInterface
forVariableOp
.Add the trait
DestructurableAccessorOpInterface
forstructExtractOp
andstructExtractRefOp
.Implement the
DestructurableTypeInterface
forstructLikeType
and thereftype
ofstructLikeType
.For local variables:
For global/module-level variables:
structInjectOp
rather thanblockingAssignOp
, becausestructExtractRefOp
has the Destructurable trait, but global variables should not be destructured.structInjectOp
means creating a new struct with new values and other old values.structExtractOp
.Also, remove some unnecessary spaces in other code.
What's more:
To do:
structInjectOp
SSA values.dbg
dialect to keep local variables visible after SROA & Mem2Reg.