aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAlbert Chen2020-04-10 20:12:19 -0700
committerGitHub2020-04-11 03:12:19 +0000
commiteb52a5c6aafab90bf923bc9a7904fc8daf983ad4 (patch)
tree4631afb66934c9a946f2159936a7cd6df16ad4bd /src/main
parent54ff9451f285cc18bca0ab519e013ff8326538b8 (diff)
EliminateTargetPaths: don't duplicate modules with only one instance (#1504)
* EliminateTargetPaths: add lone instance test cases * EliminateTargetPaths: don't rename lone instances * get rid of trailing comma Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala b/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala
index e741a32b..00f2ad6a 100644
--- a/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala
+++ b/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala
@@ -155,7 +155,51 @@ class EliminateTargetPaths extends Transform {
throw NoSuchTargetException(s"""Some targets have illegal paths that cannot be resolved/eliminated: $string""")
}
- val (newCircuit, renameMap) = run(state.circuit, targets)
+ // get rid of path prefixes of modules with only one instance so we don't rename them
+ val isSingleInstMod: String => Boolean = {
+ val cache = mutable.Map.empty[String, Boolean]
+ mod => cache.getOrElseUpdate(mod, iGraph.findInstancesInHierarchy(mod).size == 1)
+ }
+ val firstRenameMap = RenameMap()
+ val nonSingletonTargets = targets.foldLeft(Seq.empty[IsMember]) {
+ case (acc, t: IsComponent) if t.asPath.nonEmpty =>
+ val origPath = t.asPath
+ val (singletonPrefix, rest) = origPath.partition {
+ case (_, OfModule(mod)) =>
+ isSingleInstMod(mod)
+ }
+
+ if (singletonPrefix.size > 0) {
+ val module = singletonPrefix.last._2.value
+ val circuit = t.circuit
+ val newIsModule =
+ if (rest.isEmpty) {
+ ModuleTarget(circuit, module)
+ } else {
+ val (Instance(inst), OfModule(ofMod)) = rest.last
+ val path = rest.dropRight(1)
+ InstanceTarget(circuit, module, path, inst, ofMod)
+ }
+ val newTarget = t match {
+ case r: ReferenceTarget => r.setPathTarget(newIsModule)
+ case i: InstanceTarget => newIsModule
+ }
+ firstRenameMap.record(t, Seq(newTarget))
+ newTarget +: acc
+ } else {
+ t +: acc
+ }
+ case (acc, t) => t +: acc
+ }
+
+ val (newCircuit, nextRenameMap) = run(state.circuit, nonSingletonTargets)
+
+ val renameMap =
+ if (firstRenameMap.hasChanges) {
+ firstRenameMap andThen nextRenameMap
+ } else {
+ nextRenameMap
+ }
val iGraphx = new InstanceGraph(newCircuit)
val newlyUnreachableModules = iGraphx.unreachableModules diff iGraph.unreachableModules