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

Commit

Permalink
Fix invalid references generated by VerilogMemDelays (#2588)
Browse files Browse the repository at this point in the history
Transformation of mem readwriters whose address contain references to
readwriters of mems declared before it would contain invalid references
to untransformed memory readwriter, as the connection is not transformed.
This commit fixes this issue.
  • Loading branch information
Alan-Liang authored Feb 3, 2023
1 parent 84a7db5 commit 94d425f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/scala/firrtl/passes/memlib/VerilogMemDelays.scala
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,18 @@ class MemDelayAndReadwriteTransformer(m: DefModule, passthroughSimpleSyncReadMem
val transformed = m match {
case mod: Module =>
findMemConns(mod.body)
mod.copy(body = Block(transform(mod.body) +: newConns.toSeq))
val bodyx = transform(mod.body)
// Fixup any mem connections being driven by other transformed memories
val newConsx = newConns.map {
case sx if kind(sx.loc) == MemKind =>
val (memRef, _) = Utils.splitRef(sx.loc)
if (passthroughMems(WrappedExpression(memRef)))
sx
else
sx.mapExpr(swapMemRefs)
case sx => sx
}
mod.copy(body = Block(bodyx +: newConsx.toSeq))
case mod => mod
}
}
Expand Down
58 changes: 58 additions & 0 deletions src/test/scala/firrtlTests/VerilogMemDelaySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,62 @@ class VerilogMemDelaySpec extends LeanTransformSpec(Seq(Dependency(VerilogMemDel
res should include("m.write.clk <= clock")
res should include("reg m_write_data_pipe_0 : UInt<8>, clock")
}

it should "VerilogMemDelays should replace expr in connections of previous mems" in {
val input =
"""
|circuit Test :
| module Test :
| input clock : Clock
| input sel : UInt<1>
| input en : UInt<1>
| output v1 : UInt<1>
| output v2 : UInt<1>
|
| mem m1 :
| data-type => UInt<1>
| depth => 2
| read-latency => 0
| write-latency => 1
| readwriter => rw1
| readwriter => rw2
| read-under-write => undefined
| mem m2 :
| data-type => UInt<1>
| depth => 2
| read-latency => 0
| write-latency => 1
| readwriter => rw1
| readwriter => rw2
| read-under-write => undefined
| v1 <= m1.rw2.rdata
| v2 <= m2.rw2.rdata
| m1.rw1.addr <= UInt<1>("h0")
| m2.rw1.addr <= UInt<1>("h0")
| m1.rw1.en <= UInt<1>("h1")
| m2.rw1.en <= UInt<1>("h1")
| m1.rw1.clk <= clock
| m2.rw1.clk <= clock
| m1.rw1.wmode <= en
| m2.rw1.wmode <= en
| m1.rw1.wdata <= UInt<1>("h1")
| m2.rw1.wdata <= UInt<1>("h0")
| m1.rw1.wmask <= en
| m2.rw1.wmask <= UInt<1>("h0")
| m1.rw2.addr <= m2.rw1.rdata
| m2.rw2.addr <= m2.rw1.rdata
| m1.rw2.en <= UInt<1>("h1")
| m2.rw2.en <= UInt<1>("h1")
| m1.rw2.clk <= clock
| m2.rw2.clk <= clock
| m1.rw2.wmode <= en
| m2.rw2.wmode <= en
| m1.rw2.wdata <= UInt<1>("h0")
| m2.rw2.wdata <= UInt<1>("h0")
| m1.rw2.wmask <= en
| m2.rw2.wmask <= UInt<1>("h0")
""".stripMargin

compileTwice(input)
}
}

0 comments on commit 94d425f

Please sign in to comment.