Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize memory use of naming prefixes #2471

Merged
merged 3 commits into from
Apr 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions core/src/main/scala/chisel3/internal/Builder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,10 @@ private[chisel3] trait HasId extends InstanceId {
// Contains the seed computed automatically by the compiler plugin
private var auto_seed: Option[String] = None

// Prefix at time when this class is constructed
private val construction_prefix: Prefix = Builder.getPrefix

// Prefix when the latest [[suggestSeed]] or [[autoSeed]] is called
private var prefix_seed: Prefix = Nil
// Prefix for use in naming
// - Defaults to prefix at time when object is created
// - Overridden when [[suggestSeed]] or [[autoSeed]] is called
private var naming_prefix: Prefix = Builder.getPrefix

// Post-seed hooks called to carry the suggested seeds to other candidates as needed
private var suggest_postseed_hooks: List[String => Unit] = Nil
Expand All @@ -134,7 +133,7 @@ private[chisel3] trait HasId extends InstanceId {
private[chisel3] def forceAutoSeed(seed: String): this.type = {
auto_seed = Some(seed)
for (hook <- auto_postseed_hooks.reverse) { hook(seed) }
prefix_seed = Builder.getPrefix
naming_prefix = Builder.getPrefix
this
}

Expand All @@ -150,7 +149,7 @@ private[chisel3] trait HasId extends InstanceId {
*/
def suggestName(seed: => String): this.type = {
if (suggested_seed.isEmpty) suggested_seed = Some(seed)
prefix_seed = Builder.getPrefix
naming_prefix = Builder.getPrefix
for (hook <- suggest_postseed_hooks.reverse) { hook(seed) }
this
}
Expand Down Expand Up @@ -189,12 +188,12 @@ private[chisel3] trait HasId extends InstanceId {
}

if (hasSeed) {
Some(buildName(seedOpt.get, prefix_seed.reverse))
Some(buildName(seedOpt.get, naming_prefix.reverse))
} else {
defaultSeed.map { default =>
defaultPrefix match {
case Some(p) => buildName(default, p :: construction_prefix.reverse)
case None => buildName(default, construction_prefix.reverse)
case Some(p) => buildName(default, p :: naming_prefix.reverse)
case None => buildName(default, naming_prefix.reverse)
}
}
}
Expand Down Expand Up @@ -222,6 +221,8 @@ private[chisel3] trait HasId extends InstanceId {
val candidate_name = _computeName(prefix, Some(default)).get
val available_name = namespace.name(candidate_name)
setRef(Ref(available_name))
// Clear naming prefix to free memory
naming_prefix = Nil
}

private var _ref: Option[Arg] = None
Expand Down