diff options
| author | Jack Koenig | 2018-01-30 18:11:00 -0800 |
|---|---|---|
| committer | GitHub | 2018-01-30 18:11:00 -0800 |
| commit | 57025111d3bc872da726e31e3e9a1e4895593266 (patch) | |
| tree | 70de3e10760efef858ca78a4e181e28d30984abe /src/main | |
| parent | 47d2bb1f447644ee0bcc44701bc84018cc5795b9 (diff) | |
| parent | c9d3e257bff74235a75ff5530051e419b9ce8005 (diff) | |
Merge pull request #735 from freechipsproject/fix-const-prop
Fix Bugs in Constant Propagation
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/scala/firrtl/transforms/ConstantPropagation.scala | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/main/scala/firrtl/transforms/ConstantPropagation.scala b/src/main/scala/firrtl/transforms/ConstantPropagation.scala index ca48cbb5..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) => @@ -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) |
