aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorJack Koenig2021-03-10 20:14:03 -0800
committerGitHub2021-03-11 04:14:03 +0000
commited1eb88d6ccdccd4b5802676cd8b69f5cc357e4f (patch)
treec844703527c883a03f13048ec722f0a339ac4867 /src/main
parentaa24fe3ece6edcd1c121d6aa6860b6de825bb381 (diff)
Fix CSESubAccesses for SubAccesses with flips (#2112)
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 <schuyler.eldridge@sifive.com> Co-authored-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/scala/firrtl/transforms/CSESubAccesses.scala6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/main/scala/firrtl/transforms/CSESubAccesses.scala b/src/main/scala/firrtl/transforms/CSESubAccesses.scala
index 6ed3a5b5..6ca27a83 100644
--- a/src/main/scala/firrtl/transforms/CSESubAccesses.scala
+++ b/src/main/scala/firrtl/transforms/CSESubAccesses.scala
@@ -21,7 +21,9 @@ object CSESubAccesses {
val acc = new mutable.ListBuffer[(SubAccess, Info)]
def onExpr(outer: Statement)(expr: Expression): Unit = {
// Need postorder because we want to visit inner SubAccesses first
- 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))
expr match {
case e: SubAccess if flow(e) == SourceFlow => acc += e -> get_info(outer)
case _ => // Do nothing
@@ -42,6 +44,8 @@ object CSESubAccesses {
// Replaces all right-hand side SubAccesses with References
private def replaceOnSourceExpr(replace: SubAccess => Reference)(expr: Expression): Expression = expr match {
+ // Stop is we ever see a non-SourceFlow
+ case e if flow(e) != SourceFlow => e
// Don't traverse children of SubAccess, just replace it
// Nested SubAccesses are handled during creation of the nodes that the references refer to
case acc: SubAccess if flow(acc) == SourceFlow => replace(acc)