Skip to content
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

[LowerFirMem] Insert memory modules before first user #5587

Merged

Conversation

fabianschuiki
Copy link
Contributor

Currently the LowerFirMem pass inserts HWModuleGeneratedOps all the way at the top of the file. This is problematic since passes like FIRRTL's LowerToHW will produce an SV preamble with macro definitions that the memories want to rely on. Inserting the memory modules at the top of the file puts them before the macro definitions that they rely on.

This commit changes the insertion point of memory modules, making them appear as late as possible in the IR, basically just before the first module that instantiates the memory. This ensures that the memory modules are always placed after that preamble and makes their location more logical within the IR.

Currently the `LowerFirMem` pass inserts `HWModuleGeneratedOp`s all the
way at the top of the file. This is problematic since passes like
FIRRTL's `LowerToHW` will produce an SV preamble with macro definitions
that the memories want to rely on. Inserting the memory modules at the
top of the file puts them before the macro definitions that they rely
on.

This commit changes the insertion point of memory modules, making them
appear as late as possible in the IR, basically just before the first
module that instantiates the memory. This ensures that the memory
modules are always placed after that preamble and makes their location
more logical within the IR.
@fabianschuiki fabianschuiki added FIRRTL Involving the `firrtl` dialect Seq Involving the `seq` dialect labels Jul 13, 2023
Copy link
Contributor

@jackkoenig jackkoenig left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix! Inserting before the first use is neat. How does this interact with emitting 1 file per module? I assume that happens after this pass so it's just a non-issue?

@fabianschuiki
Copy link
Contributor Author

Thanks for the quick fix! Inserting before the first use is neat. How does this interact with emitting 1 file per module? I assume that happens after this pass so it's just a non-issue?

Yeah that happens later should just work. That emission mode has some separate logic that replicates the macros for each output file, but keeps the IR in the same order.

@fabianschuiki fabianschuiki merged commit 98d0bf5 into main Jul 14, 2023
@fabianschuiki fabianschuiki deleted the fschuiki/fix-lower-firmem-module-insertion-point branch July 14, 2023 00:15
Copy link
Contributor

@darthscsi darthscsi left a comment

Choose a reason for hiding this comment

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

These are in a graph region. The order of declaration shouldn't matter, export verilog is responsible for getting the macros out first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FIRRTL Involving the `firrtl` dialect Seq Involving the `seq` dialect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants