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

Commit

Permalink
Speed up Deduplication (bp #1602) (#1619)
Browse files Browse the repository at this point in the history
* Remove expensive .distinct in Dedup

(cherry picked from commit 36227e9)

* Remove accidental hashing of all Modules in Dedup

(cherry picked from commit 71e922c)

Co-authored-by: Jack Koenig <koenig@sifive.com>
  • Loading branch information
mergify[bot] and jackkoenig authored May 14, 2020
1 parent 7bb0cfc commit 3510590
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/main/scala/firrtl/transforms/Dedup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ class DedupModules extends Transform {
val dedupMap = DedupModules.deduplicate(c, noDedups.toSet, annos, renameMap)

// Use old module list to preserve ordering
val dedupedModules = c.modules.map(m => dedupMap(m.name)).distinct
// Lookup what a module deduped to, if its a duplicate, remove it
val dedupedModules = c.modules.flatMap { m =>
val mx = dedupMap(m.name)
if (mx.name == m.name) Some(mx) else None
}

val cname = CircuitName(c.main)
val map = dedupMap.map { case (from, to) =>
Expand Down Expand Up @@ -421,7 +425,11 @@ object DedupModules {
val dedupedName2module = tag2name.map({ case (tag, name) => name -> DedupModules.dedupInstances(top, name, moduleMap, name2name, renameMap) })

// Build map from original name to corresponding deduped module
val name2module = tag2all.flatMap({ case (tag, names) => names.map(n => n -> dedupedName2module(tag2name(tag))) })
// It is important to flatMap before looking up the DefModules so that they aren't hashed
val name2module: Map[String, DefModule] =
tag2all.flatMap { case (tag, names) => names.map(_ -> tag) }
.mapValues(tag => dedupedName2module(tag2name(tag)))
.toMap

// Build renameMap
val indexedTargets = mutable.HashMap[String, IndexedSeq[ReferenceTarget]]()
Expand All @@ -433,7 +441,7 @@ object DedupModules {
}
}

name2module.toMap
name2module
}

def computeIndexedNames(main: String, m: DefModule): IndexedSeq[ReferenceTarget] = {
Expand Down

0 comments on commit 3510590

Please sign in to comment.