Skip to content

Conversation

@fabianschuiki
Copy link
Contributor

The Dedup pass currently handles module instances and class objects explictly in order to update the referenced module/class after deduplication. This does not consider types and attributes on any other operations, such as wires with a !firrtl.class<...> type. These also need to be updated.

Instead of adding more special cases, make use of the attribute/type walker and replacer infrastructure of MLIR that now works properly with FIRRTL types. When hashing a module, take note of all operations that have a symbol name nested somewhere in their attributes of types, and store them in a symbolSensitiveOps list as part of the module info. Once deduplication is done, visit those ops and replace all occurrences of outdated symbols with their post-dedup replacement. This can get rid of the special handling of ClassOp and ObjectOp, and also covers WireOp and attributes/types on any other op.

This came up as a dedup failure in a real-world design.

The Dedup pass currently handles module instances and class objects
explictly in order to update the referenced module/class after
deduplication. This does not consider types and attributes on any other
operations, such as wires with a `!firrtl.class<...>` type. These also
need to be updated.

Instead of adding more special cases, make use of the attribute/type
walker and replacer infrastructure of MLIR that now works properly with
FIRRTL types. When hashing a module, take note of all operations that
have a symbol name nested somewhere in their attributes of types, and
store them in a `symbolSensitiveOps` list as part of the module info.
Once deduplication is done, visit those ops and replace all occurrences
of outdated symbols with their post-dedup replacement. This can get rid
of the special handling of ClassOp and ObjectOp, and also covers WireOp
and attributes/types on any other op.

This came up as a dedup failure in a real-world design.
@fabianschuiki fabianschuiki added the bug Something isn't working label Sep 24, 2025
@fabianschuiki fabianschuiki added the FIRRTL Involving the `firrtl` dialect label Sep 24, 2025
Copy link
Member

@seldridge seldridge left a comment

Choose a reason for hiding this comment

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

This is way cleaner! This is also future proofing this for any other ops which could have symbols in attributes as opposed to needing to keep doing fixups. Nice work.

Copy link
Member

Choose a reason for hiding this comment

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

The mutation of hasSeenSymbol is a bit difficult to follow. I was trying to think if there was a better way to handle this like adding a return value to the update methods. This is non-blocking and only for consideration.

Comment on lines -1485 to -1488
/// This fixes up ClassLikes with ClassType ports, when the classes have
/// deduped. For each ClassType port, if the object reference being assigned is
/// a different type, update the port type. Returns true if the ClassOp was
/// updated and the associated ObjectOps should be updated.
Copy link
Member

Choose a reason for hiding this comment

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

Getting rid of this is great!

@fabianschuiki
Copy link
Contributor Author

@mikeurbach pointed out that classes were supposed to be nominally typed, and we have added them to FIRRTL's dedup as a hack at some point. So instead of requiring class/object op fixups, these ops should never participate in dedup in the first place. I'm going to give that a spin in parallel.

@fabianschuiki
Copy link
Contributor Author

I think I'm going to land this, since it fixes bugs in the current implementation. We'll probably want an option on firtool to disable class deduplication entirely, such that various flows can migrate over gracefully.

@fabianschuiki fabianschuiki merged commit b49ac30 into main Sep 30, 2025
7 checks passed
@fabianschuiki fabianschuiki deleted the fschuiki/update-ops-after-dedup branch September 30, 2025 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working FIRRTL Involving the `firrtl` dialect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants