-
Notifications
You must be signed in to change notification settings - Fork 417
[MooreToCore] Add UnionType conversion support (Fixes #9570) #9571
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
base: main
Are you sure you want to change the base?
Conversation
- Add UnionType and UnpackedUnionType to hw::UnionType converters - Add UnionCreateOp, UnionExtractOp, UnionExtractRefOp conversion patterns - Fix UnionCreateOp::verify() to compare input type instead of result type - Extend LLHD SigStructExtractOp to support both struct and union types - Add comprehensive union conversion test Fixes crash in circt-verilog when processing SystemVerilog union types. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
tobiasgrosser
left a comment
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.
LGTM, except https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements.
This requires more input from @fabianschuiki @maerhart @TaoBi22 @KavyaChopra04 or @fzi-hielscher.
Co-authored-by: Tobias Grosser <github@grosser.es>
Co-authored-by: Tobias Grosser <github@grosser.es>
Co-authored-by: Tobias Grosser <github@grosser.es>
Co-authored-by: Tobias Grosser <github@grosser.es>
Co-authored-by: Tobias Grosser <github@grosser.es>
Thank you for the corrections. I am still familiarizing myself with the LLVM project and appreciate the support. |
| }); | ||
|
|
||
| // hw::ModuleType conversion to handle module signatures | ||
| typeConverter.addConversion([&](hw::ModuleType type) -> std::optional<Type> { |
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.
Is this conversion necessary? populateHWModuleLikeTypeConversionPattern should already take care of module signatures.
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.
I appreciate your correction. You're right, the new conversion isn't needed, so I've removed it.
dad8b19
- Remove unnecessary hw::ModuleType type conversion as populateHWModuleLikeTypeConversionPattern already handles module signature conversion at the operation level - Improve UnionCreateOp::verify() error messages to show actual types and distinguish between type mismatch and field not found - Fix union test case syntax (use i32 instead of !moore.i32 for member types inside union/struct) - Add UnionCreateOp verifier test cases Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add test case for llhd.sig.struct_extract with union types - Add error test case for invalid union field extraction - Verify that SigStructExtractOp correctly handles both struct and union types as requested by reviewer Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
fzi-hielscher
left a comment
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.
Thanks
Summary
This PR adds complete support for SystemVerilog union type conversion in the MooreToCore pass, fixing a crash when processing union types with
circt-verilog.Fixes #9570
Problem
When processing SystemVerilog code containing union types,
circt-verilog --ir-hwwould crash with an assertion failure because the MooreToCore conversion pass lacked support for union type conversion.Example crash (from #9570):
Solution
This PR implements:
UnionTypeandUnpackedUnionTypetohw::UnionTypeUnionCreateOp→hw::UnionCreateOpUnionExtractOp→hw::UnionExtractOpUnionExtractRefOp→llhd::SigStructExtractOpUnionCreateOp::verify()which was incorrectly comparingmember.typewithresultTypeinstead ofinputTypeSigStructExtractOpto support both struct and union typesbasic.mlirChanges
SigStructExtractOpfor union supportUnionCreateOpTesting
New Tests
@Uniontest module covering all union operationsunion_create,union_extract, andunion_extract_refVerification
Design Decisions
SigStructExtractOpnow handles both structs and unions rather than creating a separate union-specific opBackward Compatibility
✅ All changes are backward compatible:
Related Issues
Fixes #9570 - Crash when processing SystemVerilog union types in MooreToCore conversion.
Checklist