Skip to content

Commit

Permalink
Don't let the main module become deduped out of existence. (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
ucbjrl authored and mergify[bot] committed Feb 21, 2019
1 parent ad0c4ce commit b383382
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/scala/firrtl/transforms/Dedup.scala
Expand Up @@ -373,13 +373,17 @@ object DedupModules {
val iGraph = new InstanceGraph(circuit)
(iGraph.moduleMap, iGraph.moduleOrder.reverse)
}
val top = CircuitTarget(circuit.main)

val main = circuit.main
val top = CircuitTarget(main)
val (tag2all, tagMap) = buildRTLTags(top, moduleLinearization, noDedups, annotations)

// Set tag2name to be the best dedup module name
val moduleIndex = circuit.modules.zipWithIndex.map{case (m, i) => m.name -> i}.toMap
def order(l: String, r: String): String = if (moduleIndex(l) < moduleIndex(r)) l else r
def order(l: String, r: String): String = {
if (l == main) l
else if (r == main) r
else if (moduleIndex(l) < moduleIndex(r)) l else r
}

// Maps a module's tag to its deduplicated module
val tag2name = mutable.HashMap.empty[String, String]
Expand Down
21 changes: 21 additions & 0 deletions src/test/scala/firrtlTests/transforms/DedupTests.scala
Expand Up @@ -532,5 +532,26 @@ class DedupModuleTests extends HighTransformSpec {
cs.annotations.toSeq should not contain (SingleTargetDummyAnnotation(A.ref("x")))
cs.deletedAnnotations.isEmpty should be (true)
}
"main" should "not be deduped even if it's the last module" in {
val input =
"""circuit main:
| module dupe:
| input in: UInt<8>
| output out: UInt<8>
| out <= in
| module main:
| input in: UInt<8>
| output out: UInt<8>
| out <= in
""".stripMargin
val check =
"""circuit main:
| module main:
| input in: UInt<8>
| output out: UInt<8>
| out <= in
""".stripMargin
execute(input, check, Seq.empty)
}
}

0 comments on commit b383382

Please sign in to comment.