Skip to content

[HW] Add IMDCE module rewrites#10007

Open
stomfaig wants to merge 2 commits intollvm:mainfrom
stomfaig:add_mod_rewrites
Open

[HW] Add IMDCE module rewrites#10007
stomfaig wants to merge 2 commits intollvm:mainfrom
stomfaig:add_mod_rewrites

Conversation

@stomfaig
Copy link
Copy Markdown
Contributor

Add module rewriting functions and corresponding tests.

This also includes moving the helper removeElementsAtIndices to Utils from FIRRTL specific code.

@stomfaig
Copy link
Copy Markdown
Contributor Author

cc: @uenoku

@uenoku uenoku self-requested a review March 24, 2026 01:25
// Note that post-order traversal on the instance graph never visit
// unreachable modules so it's safe to erase the module even though
// `modules` seems to be capturing module pointers.
module.erase();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is a certain situation where this erases modules still used by some symbol. I think until we have a proper analysis it's safer not to erase it (and we can run SymbolDCE anyway).

sv.verbatim "{{0}}" { symbols = [@baz] }
// Not reachable from the top level. 
hw.module private @baz() {}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does this also apply to the erase in eraseEmptyModule?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, I think so.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Specifically do you mind if you could check an example in #10084

liveElements.insert(newResult);

use->erase();
instance->erase();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could you update instance graph?

Copy link
Copy Markdown
Member

@uenoku uenoku left a comment

Choose a reason for hiding this comment

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

LGTM other than module removal. For now I think we shouldn't remove empty modules as well; this has been a problem of FIRRTL IMDCE as well.

We need liveness analysis like https://github.com/llvm/llvm-project/blob/main/mlir/lib/Transforms/SymbolDCE.cpp). Basically if the module symbol is not referred by anything, it's ok to remove dead or empty modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants