Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Fix CSESubAccesses for SubAccesses with flips #2112

Merged
merged 1 commit into from
Mar 11, 2021
Merged

Conversation

jackkoenig
Copy link
Contributor

Fixes a bug in #2099 that is causing Chisel CI to fail.

The flow of a LHS SubAccess node may still be SourceFlow if the type of
the Vec element has a flip. Tweak the logic of CSESubAccesses to check
every Expression flow while recursing instead of just the flow of the
final SubAccess.

This did highlight a shortcoming of CSESubAccesses. Basically, the transform uses nodes to avoid quadratic behavior of RemoveAccesses because nodes are unaffected by ExpandConnects and thus it only lowers the SubAccess once. See #643 for more details on that issue. The shortcoming is that nodes cannot be used to represent bidirectional connections, so CSESubAccesses fundamentally cannot handle dynamic indexing of bidirectional Vecs. I did try, but it doesn't really work with the current approach.

I think a better approach is to fix the quadratic behavior in RemoveAccesses itself, then have CSESubAccesses use wires instead of nodes so that it can also handle bidirectional Vecs. Future work!

Contributor Checklist

  • [NA] Did you add Scaladoc to every public function/method?
  • [NA] Did you update the FIRRTL spec to include every new feature/behavior?
  • Did you add at least one test demonstrating the PR?
  • Did you delete any extraneous printlns/debugging code?
  • Did you specify the type of improvement?
  • Did you state the API impact?
  • Did you specify the code generation impact?
  • Did you request a desired merge strategy?
  • [NA] Did you add text to be included in the Release Notes for this change?

No need for release notes, CSESubAccesses is not yet released.

Type of Improvement

  • bug fix

API Impact

No impact

Backend Code Generation Impact

No impact

Desired Merge Strategy

  • Squash

Release Notes

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels?
  • Did you mark the proper milestone (1.2.x, 1.3.0, 1.4.0) ?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you mark as Please Merge?

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.

Awesome. This is a good, minimal solution to a very tricky problem.

src/main/scala/firrtl/transforms/CSESubAccesses.scala Outdated Show resolved Hide resolved
Comment on lines -24 to +26
expr.foreach(onExpr(outer))
// Stop recursing on any non-Source because flips can make the SubAccess a Source despite the
// overall Expression being a Sink
if (flow(expr) == SourceFlow) expr.foreach(onExpr(outer))
Copy link
Member

Choose a reason for hiding this comment

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

To check my understanding... the implication of this is that we won't CSE all subaccesses, and punt on ones which have weird internal flippedness?

I think this is totally fair.

Copy link
Contributor Author

@jackkoenig jackkoenig Mar 11, 2021

Choose a reason for hiding this comment

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

This comment is really talking about how an Expression that is a Sink may have a SubAccess that is a SourceFlow, eg. from the added tests:

input out : { flip foo : UInt<8> }[2]
...
out[idx].foo <= in.foo

out[idx].foo is a sink, but the out[idx] SubAccess is SourceFlow, the flip on foo is what makes the larger Expression a sink.

Note that this case probably should not ever be handled by this transform, or at least, it would require a lot more sophistication to handle write ports

That being said, this check also stops handling any SubAccesses of bidirectional Vecs. Technically, this transform could handle them if running after ExpandConnects, but it's a little more complicated and I think there's a better way to do it than complicating the logic in this transform, see original PR description. From the other test I added in this PR:

output out : { flip foo : UInt<8>, bar : UInt<8> }[4]
...
out[idx] <= in"

@jackkoenig jackkoenig added the Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI. label Mar 11, 2021
The flow of a LHS SubAccess node may still be SourceFlow if the type of
the Vec element has a flip. Tweak the logic of CSESubAccesses to check
every Expression flow while recursing instead of just the flow of the
final SubAccess.

Co-authored-by: Schuyler Eldridge <[email protected]>
@mergify mergify bot merged commit ed1eb88 into master Mar 11, 2021
mergify bot pushed a commit that referenced this pull request Mar 11, 2021
The flow of a LHS SubAccess node may still be SourceFlow if the type of
the Vec element has a flip. Tweak the logic of CSESubAccesses to check
every Expression flow while recursing instead of just the flow of the
final SubAccess.

Co-authored-by: Schuyler Eldridge <[email protected]>

Co-authored-by: Schuyler Eldridge <[email protected]>
(cherry picked from commit ed1eb88)
@mergify mergify bot added the Backported This PR has been backported to marked stable branch label Mar 11, 2021
mergify bot added a commit that referenced this pull request Mar 11, 2021
The flow of a LHS SubAccess node may still be SourceFlow if the type of
the Vec element has a flip. Tweak the logic of CSESubAccesses to check
every Expression flow while recursing instead of just the flow of the
final SubAccess.

Co-authored-by: Schuyler Eldridge <[email protected]>

Co-authored-by: Schuyler Eldridge <[email protected]>
(cherry picked from commit ed1eb88)

Co-authored-by: Jack Koenig <[email protected]>
@jackkoenig jackkoenig deleted the fix-csesubaccesses branch March 26, 2021 23:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Backported This PR has been backported to marked stable branch bugfix high priority Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants