From 8bdc969f95571fa22b39612d3e3acc69268cf2f0 Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Tue, 30 Jan 2018 12:49:44 -0800 Subject: Fix bug incorrectly propagating constants on submodule inputs Two instances of the same module could collide in counting the number of instances of each Module. This could lead to constants being propagated on inputs when it is incorrect to do so. Fixes #734 --- src/main/scala/firrtl/transforms/ConstantPropagation.scala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/scala/firrtl/transforms/ConstantPropagation.scala b/src/main/scala/firrtl/transforms/ConstantPropagation.scala index ca48cbb5..b767ef65 100644 --- a/src/main/scala/firrtl/transforms/ConstantPropagation.scala +++ b/src/main/scala/firrtl/transforms/ConstantPropagation.scala @@ -407,8 +407,13 @@ class ConstantPropagation extends Transform { mod.module -> children.map(i => i.name -> i.module).toMap }) - // Module name to number of instances - val instCount: Map[String, Int] = iGraph.getVertices.groupBy(_.module).mapValues(_.size) + // This is a *relative* instance count, ie. how many there are when you visit each Module once + // (even if it is instantiated multiple times) + val instCount: Map[String, Int] = iGraph.getEdgeMap.foldLeft(Map(c.main -> 1)) { + case (cs, (_, values)) => values.foldLeft(cs) { + case (counts, value) => counts.updated(value.module, counts.getOrElse(value.module, 0) + 1) + } + } // DiGraph using Module names as nodes, destination of edge is a parent Module val parentGraph: DiGraph[String] = iGraph.reverse.transformNodes(_.module) -- cgit v1.2.3 From c9d3e257bff74235a75ff5530051e419b9ce8005 Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Tue, 30 Jan 2018 12:53:56 -0800 Subject: Make Constant Propagation respect dontTouch on registers --- src/main/scala/firrtl/transforms/ConstantPropagation.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/scala/firrtl/transforms/ConstantPropagation.scala b/src/main/scala/firrtl/transforms/ConstantPropagation.scala index b767ef65..d08a7e6b 100644 --- a/src/main/scala/firrtl/transforms/ConstantPropagation.scala +++ b/src/main/scala/firrtl/transforms/ConstantPropagation.scala @@ -367,7 +367,7 @@ class ConstantPropagation extends Transform { // Const prop registers that are fed only a constant or a mux between and constant and the // register itself // This requires that reset has been made explicit - case Connect(_, lref @ WRef(lname, ltpe, RegKind, _), expr) => expr match { + case Connect(_, lref @ WRef(lname, ltpe, RegKind, _), expr) if !dontTouches.contains(lname) => expr match { case lit: Literal => nodeMap(lname) = constPropExpression(pad(lit, ltpe)) case Mux(_, tval: WRef, fval: Literal, _) if weq(lref, tval) => -- cgit v1.2.3