Skip to content

Conversation

@fabianschuiki
Copy link
Contributor

  • Make the eager inliner not remove instances that are part of an NLA.
  • Make the annotation remover not remove NLAs that have remaining uses after some annotations referencing it were removed.
  • Make the constantifier not match on existing constants, and not replace operations that have the "inner_sym" attribute.

@fabianschuiki fabianschuiki added FIRRTL Involving the `firrtl` dialect Reducer Related to `circt-reduce` labels Sep 18, 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.

LGTM

Comment on lines -959 to +969
struct EagerInliner : public OpReduction<firrtl::InstanceOp> {
struct EagerInliner : public OpReduction<InstanceOp> {
Copy link
Member

Choose a reason for hiding this comment

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

Nice to keep this tidy.

Comment on lines +1044 to +1068
/// Check if inlining the referenced module into the parent module would cause
/// inner symbol collisions.
bool hasInnerSymbolCollisions(FModuleOp referencedModule,
FModuleOp parentModule) {
// Get the inner symbol tables for both modules
auto &targetTable = innerSymTables->getInnerSymbolTable(referencedModule);
auto &parentTable = innerSymTables->getInnerSymbolTable(parentModule);

// Check if any inner symbol name in the target module already exists
// in the parent module. Return failure() if a collision is found to stop
// the walk early.
LogicalResult walkResult = targetTable.walkSymbols(
[&](StringAttr name,
const hw::InnerSymTarget &target) -> LogicalResult {
// Check if this symbol name exists in the parent module
if (parentTable.lookup(name)) {
// Collision found, return failure to stop the walk
return failure();
}
return success();
});

// If the walk failed, it means we found a collision
return failed(walkResult);
}
Copy link
Member

Choose a reason for hiding this comment

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

I kind of like this style of eagerly exit if the reduction pattern isn't trivially applicable. This is in contrast with trying to do a bunch of work to clean this up. I think this makes sense because the inner symbols will get dropped with other reductions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agreed! It's also very annoying if the pattern applies too eagerly and then leads to invalid IR in a lot of cases. That just sends the reducer into busy work rabbit holes that don't really improve the reduction. 😞

@fabianschuiki fabianschuiki force-pushed the fschuiki/even-more-vibe-reductions branch from 1719f3f to b509ec6 Compare September 19, 2025 22:25
@fabianschuiki fabianschuiki force-pushed the fschuiki/dedup-class-types branch 2 times, most recently from 7f021be to 59096e8 Compare September 20, 2025 00:17
@fabianschuiki fabianschuiki force-pushed the fschuiki/even-more-vibe-reductions branch from b509ec6 to 2fec994 Compare September 20, 2025 00:17
Base automatically changed from fschuiki/dedup-class-types to main September 20, 2025 00:18
- Make the eager inliner not remove instances that are part of an NLA.
- Make the annotation remover not remove NLAs that have remaining uses
  after some annotations referencing it were removed.
- Make the constantifier not match on existing constants, and not
  replace operations that have the "inner_sym" attribute.
@fabianschuiki fabianschuiki force-pushed the fschuiki/even-more-vibe-reductions branch from 2fec994 to ac4f5c3 Compare September 20, 2025 00:18
Avoid pruning unused operations that have inner symbols.
Add a helper struct that collects all inner references under a root op
into a set. This is pretty pessimistic and specific to the reducer. Make
use of this in the `NodeSymbolRemover` FIRRTL reduction to only remove
symbols from ops if there are no references to them.
Do not externalize modules if they are involved in inner refs. Use the
new `InnerRefUses` helper for this, with a few extensions.
Since most reduction patterns need information about whether an op is
referenced by its symbol name or inner symbol name, also keep track of
regular symbol references in `InnerSymbolUses`. This will allow us to
get rid of many uses of `SymbolUserMap`.
Add a reduction pattern for the Emit dialect that simply deletes all
Emit ops with high priority, since these often do not affect whether a
circt-reduce test case is interesting.
Use the new `InnerSymbolUses` helper to make the OperationPruner and
UnusedSymbolPruner more accurate by not deleting operations that still
have references to them, which is very likely to break the IR.
Run canonicalization before CSE, since CSE will otherwise do a limited
form of canonicalization that keeps finding minimal reductions, sending
the reducer into a rabbit hole of minimal incremental improvements.
@fabianschuiki fabianschuiki merged commit d3e792b into main Sep 20, 2025
7 checks passed
@fabianschuiki fabianschuiki deleted the fschuiki/even-more-vibe-reductions branch September 20, 2025 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FIRRTL Involving the `firrtl` dialect Reducer Related to `circt-reduce`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants