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

Fix RemoveAccesses, delete CSESubAccesses #2157

Merged
merged 2 commits into from
Mar 29, 2021
Merged

Conversation

jackkoenig
Copy link
Contributor

CSESubAccesses was intended to be a simple workaround for a quadratic
performance bug in RemoveAccesses but ended up having tricky corner
cases and was hard to get right. The solution to the RemoveAccesses
bug--quadratic expansion of dynamic indexes of vecs of aggreate
type--turned out to be quite simple and makes CSESubAccesses much less
useful and not worth fixing.

Note that we didn't really have extensive tests of RemoveAccesses so I just sort of converted the CSESubAccesses tests over to a new RemoveAccessesSpec.

Contributor Checklist

  • 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?
  • Did you add text to be included in the Release Notes for this change?

Type of Improvement

  • bug fix (by deleting CSESubAccesses)
  • performance improvement (handles cases not handled by CSESubAccesses)

API Impact

No impact (CSESubAccesses was never released)

Backend Code Generation Impact

This will likely affect some temporary numbering but should have minimal impact over all.

Desired Merge Strategy

  • Squash

Release Notes

Fix performance bug in RemoveAccesses

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?

@jackkoenig jackkoenig added this to the 1.4.x milestone Mar 26, 2021
Comment on lines +123 to +142
// Only called on RefLikes that definitely have a SubAccess
// Must accept Expression because that's the output type of fixIndices
def removeSource(e: Expression): Expression = {
val rs = getLocations(e)
rs.find(x => x.guard != one) match {
case None => throwInternalError(s"removeSource: shouldn't be here - $e")
case Some(_) =>
val (wire, temp) = create_temp(e)
val temps = create_exps(temp)
def getTemp(i: Int) = temps(i % temps.size)
stmts += wire
rs.zipWithIndex.foreach {
case (x, i) if i < temps.size =>
stmts += IsInvalid(get_info(s), getTemp(i))
stmts += Conditionally(get_info(s), x.guard, Connect(get_info(s), getTemp(i), x.base), EmptyStmt)
case (x, i) =>
stmts += Conditionally(get_info(s), x.guard, Connect(get_info(s), getTemp(i), x.base), EmptyStmt)
}
temp
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note this diff is just removing the match since we only ever call this on RefLikeExpressions, the match is redundant.

//case w: WSubIndex => removeSource(w)
//case w: WSubField => removeSource(w)
case ref: RefLikeExpression =>
if (hasAccess(ref)) removeSource(fixIndices(ref)) else ref
case x => x.map(fixSource)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The diff above here is the real meat of the PR, by recursing until you see the SubAccess for RHS subaccesses ("Sources"), you end up always expanding the entire aggregate. This changes it to match on the outermost RefLikeExpression it can to ensure that we respect any SubFields or SubIndexes when doing the expansion. This is the fix.

CSESubAccesses was intended to be a simple workaround for a quadratic
performance bug in RemoveAccesses but ended up having tricky corner
cases and was hard to get right. The solution to the RemoveAccesses
bug--quadratic expansion of dynamic indexes of vecs of aggreate
type--turned out to be quite simple and makes CSESubAccesses much less
useful and not worth fixing.
@jackkoenig jackkoenig force-pushed the fix-remove-accesses-perf-bug branch from 1a317a3 to 549992e Compare March 26, 2021 23:38
Copy link
Contributor

@chick chick left a comment

Choose a reason for hiding this comment

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

lgtm

@jackkoenig jackkoenig added the Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI. label Mar 29, 2021
@mergify mergify bot merged commit a41af6f into master Mar 29, 2021
mergify bot pushed a commit that referenced this pull request Mar 29, 2021
CSESubAccesses was intended to be a simple workaround for a quadratic
performance bug in RemoveAccesses but ended up having tricky corner
cases and was hard to get right. The solution to the RemoveAccesses
bug--quadratic expansion of dynamic indexes of vecs of aggreate
type--turned out to be quite simple and makes CSESubAccesses much less
useful and not worth fixing.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit a41af6f)
@mergify mergify bot added the Backported This PR has been backported to marked stable branch label Mar 29, 2021
mergify bot added a commit that referenced this pull request Mar 29, 2021
CSESubAccesses was intended to be a simple workaround for a quadratic
performance bug in RemoveAccesses but ended up having tricky corner
cases and was hard to get right. The solution to the RemoveAccesses
bug--quadratic expansion of dynamic indexes of vecs of aggreate
type--turned out to be quite simple and makes CSESubAccesses much less
useful and not worth fixing.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit a41af6f)

Co-authored-by: Jack Koenig <[email protected]>
@jackkoenig jackkoenig deleted the fix-remove-accesses-perf-bug branch April 8, 2021 02:02
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 Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI. release issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants