Skip to content

Conversation

@fabianschuiki
Copy link
Contributor

Upstream MLIR requires type and attribute storages to define a getAsKey function, and for the return type to be something that implements the corresponding attribute/type walk. Most of our FIRRTL types and attributes predate these requirements. This PR is mostly busy work, adding getAsKey to the types and attributes that don't yet have it, and changing std::pair to std::tuple. (For some reason upstream type/attribute walking works on tuples, but not pairs.) Also add unit tests for attributes and types that ensure the walks actually work.

These tweaks allow circt-reduce to be a lot more clever about which ops it touches, because it can see a lot more symbol uses now. I also expect the InnerSymbolDCE pass to potentially benefit from this, at least if inner symbols are weirdly nested within FIRRTL attributes and types.

Most of this was done by Claude Sonnet 4, with a lot of handholding.

@fabianschuiki fabianschuiki added the enhancement New feature or request 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.

Only lightly reviewed. Looks good.

Copy link
Member

Choose a reason for hiding this comment

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

Lightly reviewed. This looks good.

Builder builder{&context};
};

TEST_F(TypeWalkTest, BundleTypeWalk) {
Copy link
Member

Choose a reason for hiding this comment

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

This kind of test could be golfed down to a single field. Not critical.

Copy link
Member

Choose a reason for hiding this comment

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

Only lightly reviewed.

@seldridge
Copy link
Member

Also, thank you for figuring out that this was the issue and fixing this!

Upstream MLIR requires type and attribute storages to define a
`getAsKey` function, and for the return type to be something that
implements the corresponding attribute/type walk. Most of our FIRRTL
types and attributes predate these requirements. This PR is mostly busy
work, adding `getAsKey` to the types and attributes that don't yet have
it, and changing `std::pair` to `std::tuple`. (For some reason upstream
type/attribute walking works on tuples, but not pairs.) Also add unit
tests for attributes and types that ensure the walks actually work.

These tweaks allow circt-reduce to be a lot more clever about which ops
it touches, because it can see a lot more symbol uses now. I also expect
the `InnerSymbolDCE` pass to potentially benefit from this, at least if
inner symbols are weirdly nested within FIRRTL attributes and types.

Most of this was done by Claude Sonnet 4, with a lot of handholding.
@fabianschuiki fabianschuiki merged commit 04093a8 into main Sep 24, 2025
7 checks passed
@fabianschuiki fabianschuiki deleted the fschuiki/fix-type-walk branch September 24, 2025 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request FIRRTL Involving the `firrtl` dialect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants