8000 [firrtl] Move LowerLayers after LowerXMR by seldridge · Pull Request #8405 · llvm/circt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[firrtl] Move LowerLayers after LowerXMR #8405

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

Merged

Conversation

seldridge
Copy link
Member
@seldridge seldridge commented Apr 9, 2025

Move the LowerLayers pass after the LowerXMR pass. To do this, all
passes at the end of the CHIRRTL to Low FIRRTL pipeline are moved after
LowerXMR. This is necessary because the LowerLayers pass cannot, at
present, be moved after the passes at the end of the pipeline.

This is done to enable forcing out of layers. By lowering probes to XMRs,
the layers can be lowered trivially to modules/instances and their XMRs
will now (seemingly) magically just work. By doing the loweirng in this
way, it avoids ever having to represent an input probe in the FIRRTL
dialect.

A consequence of this is that there are now simplifying
assumptions (preconditions) that can be made about the LowerLayers pass:

  1. It will never see a number of probe ops because the LowerXMR pass has
    a postcondition that all of these are removed.

  2. Input and output ports can never be created on modules created from
    layer blocks.

While I am generally always in favor of passes being relocatable anywhere
in the pipeline, this is one pass that really does not make sense to be
relocatable. In effect, this pass is part of the lowering from FIRRTL to
HW. There is no point in being able to use it earlier in the pipeline.
That said, it still is tested to work with things which we may one-day
preserve, like WhenOps.

Todo

  • Handle zero width

@seldridge seldridge requested a review from darthscsi as a code owner April 9, 2025 20:07
@seldridge seldridge requested a review from rwy7 April 9, 2025 20:08
@seldridge seldridge marked this pull request as draft April 10, 2025 01:54
@seldridge seldridge force-pushed the dev/seldridge/firrtl-lower-layers-support-clone-xmrref-ops branch from 772757e to 38b6bef Compare April 12, 2025 03:39
@seldridge seldridge changed the title [firrtl] Clone XMRRef Ops into layers [firrtl] Move LowerLayers after LowerXMR Apr 12, 2025
@seldridge
Copy link
Member Author

The changes in this PR introduce a lot of unreachable code in LowerLayers. I will clean this up as long as there is consensus that we want to enforce the precondition that LowerXMR runs before this always (and thereby certain ops will never be seen). It is possible to continue to support this, but it will not be load bearing in firtool.

@seldridge seldridge changed the base branch from main to dev/seldridge/hw-factor-out-hierpath-builder April 12, 2025 03:49
@seldridge seldridge force-pushed the dev/seldridge/firrtl-lower-layers-support-clone-xmrref-ops branch from f3ae7e8 to d3c4abb Compare April 14, 2025 17:08
@seldridge seldridge force-pushed the dev/seldridge/hw-factor-out-hierpath-builder branch from febc89c to 3057138 Compare April 14, 2025 17:08
Base automatically changed from dev/seldridge/hw-factor-out-hierpath-builder to main April 14, 2025 18:02
@seldridge seldridge force-pushed the dev/seldridge/firrtl-lower-layers-support-clone-xmrref-ops branch from 1bcc6d0 to 4319a18 Compare April 16, 2025 00:49
@seldridge seldridge marked this pull request as ready for review April 16, 2025 00:51
@seldridge seldridge requested review from youngar and dtzSiFive April 16, 2025 00:53
Comment on lines 348 to 377
if (type_isa<FStringType>(operand.getType())) {
localBuilder.setInsertionPoint(op);
replacement = localBuilder.clone(*operand.getDefiningOp())->getResult(0);
replacements.insert({operand, replacement});
return replacement; 8000
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You are replacing operand with result 0, when it should match the original result number, which you can only get if you check that operand is an OpResult. If operand is a block argument then this should fail gracefully. It doesn't seem like there is a reachable bug here, but I think it would be easier to understand if it was written more defensively.

@seldridge
Copy link
Member Author

40a9685 fixes a bug where when capturing an instance port, a node needs to be created. This matches the behavior of LowerXMR. The buggy behavior before this is that this would XMR directly to the instance which is just wrong.

@seldridge seldridge force-pushed the dev/seldridge/firrtl-lower-layers-support-clone-xmrref-ops branch 2 times, most recently from 90ab8c5 to 6927b0a Compare April 19, 2025 00:00
Move the `LowerLayers` pass after the `LowerXMR` pass.  To do this, all
passes at the end of the CHIRRTL to Low FIRRTL pipeline are moved after
`LowerXMR`.  This is necessary because the `LowerLayers` pass cannot, at
present, be moved after the passes at the end of the pipeline.

This is done to enable forcing out of layers.  By lowering probes to XMRs,
the layers can be lowered trivially to modules/instances and their XMRs
will now (seemingly) magically just work.  By doing the loweirng in this
way, it avoids ever having to represent an input probe in the FIRRTL
dialect.

A consequence of this is that there are now simplifying
assumptions (preconditions) that can be made about the `LowerLayers` pass:

1. It will never see a number of probe ops because the `LowerXMR` pass has
   a postcondition that all of these are removed.

2. Input and output ports can never be created on modules created from
   layer blocks.

While I am generally always in favor of passes being relocatable anywhere
in the pipeline, this is one pass that really does _not_ make sense to be
relocatable.  In effect, this pass is part of the lowering from FIRRTL to
HW.  There is no point in being able to use it earlier in the pipeline.
That said, it still is tested to work with things which we may one-day
preserve, like `WhenOp`s.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
@seldridge seldridge force-pushed the dev/seldridge/firrtl-lower-layers-support-clone-xmrref-ops branch from 6927b0a to 9425597 Compare April 21, 2025 23:15
@seldridge
Copy link
Member Author

Thanks for the review @rwy7. I will merge this after running some internal tests. I'm slating to get this into the 1.115.0 release this week.

@seldridge
Copy link
Member Author

I have this passing regressions internally, though cherry-picked onto the 1.114.1 tag.

@seldridge seldridge merged commit 5cffc85 into main Apr 24, 2025
5 checks passed
@seldridge seldridge deleted the dev/seldridge/firrtl-lower-layers-support-clone-xmrref-ops branch April 24, 2025 15:02
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
0