-
Notifications
You must be signed in to change notification settings - Fork 177
Fix RemoveAccesses, delete CSESubAccesses #2157
Conversation
// 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 | ||
} |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
1a317a3
to
549992e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
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)
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]>
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
Type of Improvement
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
Release Notes
Fix performance bug in RemoveAccesses
Reviewer Checklist (only modified by reviewer)
Please Merge
?