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

[LowerFIRRTLToHW] Create less wires with instance ports #5510

Merged
merged 1 commit into from
Jun 28, 2023

Conversation

youngar
Copy link
Member

@youngar youngar commented Jun 28, 2023

When we lower input ports on instances, if there are zero or multiple writers to the input port, we create a wire and use that as the operand to the new instance operation. There was a change to this code to use hw::WireOps, which have their input value as an operand. Since hw::WireOp's cannot have multiple writers, the code is now "the last writer wins". The wire's input is updated when processing connect-like operations - we will replace the previous writer to the wire.

We already have a helper in this code to gracefully handle this situation called createBackedge. A backedge is a placeholder for a value which will be determined later. We can use a backedge as an operand to the lowered instance op, and when we find the connect operation driving a value to the old instance port, replace the backedge with the driven value.

The backedge helper in this pass gracefully handles undriven backedges and combinational loops of backedges; if a backedge has not been replaced by the end of the module body, it will be replaced with an undriven wire.

An assert had to be removed which prevented a backedge from being updated multiple times. Regular connect ops were updated to support backedges, instead of just strict connects.

This change is NFC in the FIRRTL pipeline, where the corner cases of combinational loops and undriven ports are illegal. This better supports the two illegal cases of undriven inputs and combinational loops. In the future we should replace all usages of createTmpHWWireOp with the backedge helpers.

When we lower input ports on instances, if there are zero or multiple
writers to the input port, we create a wire and use that as the operand
to the new instance operation.  There was a change to this code to use
`hw::WireOps`, which have their input value as an operand.  Since
`hw::WireOp`'s cannot have multiple writers, the code is now "the last
writer wins".  The wire's input is updated  when processing connect-like
operations - we will replace the previous writer to the wire.

We already have a helper in this code to gracefully handle this
situation called `createBackedge`.  A backedge is a placeholder for a
value which will be determined later.  We can use a backedge as an
operand to the lowered instance op, and when we find the connect
operation driving a value to the old instance port, replace the backedge
with the driven value.

The backedge helper in this pass gracefully handles undriven backedges
and combinational loops of backedges; if a backedge has not been
replaced by the end of the module body, it will be replaced with an
undriven wire.

An assert had to be removed which prevented a backedge from being
updated multiple times. Regular ~Connect ops were updated to support
backedges, instead of just strict connects.

This change is NFC in the FIRRTL pipeline, where the corner cases of
combinational loops and undriven ports are illegal. This better supports
the two illegal cases of undriven inputs and combinational loops. In the
future we should replace all usages of `createTmpHWWireOp` with the
backedge helpers.
@youngar youngar added the FIRRTL Involving the `firrtl` dialect label Jun 28, 2023
Copy link
Contributor

@fabianschuiki fabianschuiki left a comment

Choose a reason for hiding this comment

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

LGTM! I love how this gets rid of another batch of temporary wires 🎉

Copy link
Contributor

@dtzSiFive dtzSiFive left a comment

Choose a reason for hiding this comment

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

Amazing improvement, LGTM!

@youngar youngar merged commit 7ddbf6b into llvm:main Jun 28, 2023
@youngar youngar deleted the firrtl-to-hw-ports branch June 28, 2023 19:43
calebmkim pushed a commit to andrewb1999/circt that referenced this pull request Jul 12, 2023
When we lower input ports on instances, if there are zero or multiple
writers to the input port, we create a wire and use that as the operand
to the new instance operation.  There was a change to this code to use
`hw::WireOps`, which have their input value as an operand.  Since
`hw::WireOp`'s cannot have multiple writers, the code is now "the last
writer wins".  The wire's input is updated  when processing connect-like
operations - we will replace the previous writer to the wire.

We already have a helper in this code to gracefully handle this
situation called `createBackedge`.  A backedge is a placeholder for a
value which will be determined later.  We can use a backedge as an
operand to the lowered instance op, and when we find the connect
operation driving a value to the old instance port, replace the backedge
with the driven value.

The backedge helper in this pass gracefully handles undriven backedges
and combinational loops of backedges; if a backedge has not been
replaced by the end of the module body, it will be replaced with an
undriven wire.

An assert had to be removed which prevented a backedge from being
updated multiple times. Regular connect ops were updated to support
backedges, instead of just strict connects.

This change is NFC in the FIRRTL pipeline, where the corner cases of
combinational loops and undriven ports are illegal. This better supports
the two illegal cases of undriven inputs and combinational loops. In the
future we should replace all usages of `createTmpHWWireOp` with the
backedge helpers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FIRRTL Involving the `firrtl` dialect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants