summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authormergify[bot]2022-08-05 00:59:23 +0000
committerGitHub2022-08-05 00:59:23 +0000
commitdb18ae16a26dab5231ca83172c88b9735a977582 (patch)
tree484c0d45240f9db07437f15d0fe15cac1e04db67 /core
parent945416c628656498be7a98dcd4899f2b9e830c00 (diff)
Replace some options with nullable vars (backport #2658) (#2659)
* Replace some options with nullable vars (#2658) Co-authored-by: Jack Koenig <koenig@sifive.com> (cherry picked from commit ac460bfeb16c8e7d0dc00975bb03f73c0fea2103) # Conflicts: # core/src/main/scala/chisel3/internal/Builder.scala * Fix backport conflicts (#2661) Co-authored-by: Zachary Yedidia <zyedidia@gmail.com>
Diffstat (limited to 'core')
-rw-r--r--core/src/main/scala/chisel3/Data.scala10
-rw-r--r--core/src/main/scala/chisel3/internal/Builder.scala30
2 files changed, 27 insertions, 13 deletions
diff --git a/core/src/main/scala/chisel3/Data.scala b/core/src/main/scala/chisel3/Data.scala
index 592ebe25..956c7996 100644
--- a/core/src/main/scala/chisel3/Data.scala
+++ b/core/src/main/scala/chisel3/Data.scala
@@ -501,14 +501,15 @@ abstract class Data extends HasId with NamedComponent with SourceInfoDoc {
// Binding stores information about this node's position in the hardware graph.
// This information is supplemental (more than is necessary to generate FIRRTL) and is used to
// perform checks in Chisel, where more informative error messages are possible.
- private var _binding: Option[Binding] = None
+ private var _bindingVar: Binding = null // using nullable var for better memory usage
+ private def _binding: Option[Binding] = Option(_bindingVar)
// Only valid after node is bound (synthesizable), crashes otherwise
protected[chisel3] def binding: Option[Binding] = _binding
protected def binding_=(target: Binding) {
if (_binding.isDefined) {
throw RebindingException(s"Attempted reassignment of binding to $this, from: ${target}")
}
- _binding = Some(target)
+ _bindingVar = target
}
// Similar to topBindingOpt except it explicitly excludes SampleElements which are bound but not
@@ -540,14 +541,15 @@ abstract class Data extends HasId with NamedComponent with SourceInfoDoc {
// Both are only valid after binding is set.
// Direction of this node, accounting for parents (force Input / Output) and children.
- private var _direction: Option[ActualDirection] = None
+ private var _directionVar: ActualDirection = null // using nullable var for better memory usage
+ private def _direction: Option[ActualDirection] = Option(_directionVar)
private[chisel3] def direction: ActualDirection = _direction.get
private[chisel3] def direction_=(actualDirection: ActualDirection) {
if (_direction.isDefined) {
throw RebindingException(s"Attempted reassignment of resolved direction to $this")
}
- _direction = Some(actualDirection)
+ _directionVar = actualDirection
}
private[chisel3] def stringAccessor(chiselType: String): String = {
diff --git a/core/src/main/scala/chisel3/internal/Builder.scala b/core/src/main/scala/chisel3/internal/Builder.scala
index 61f94f8f..25f4c44c 100644
--- a/core/src/main/scala/chisel3/internal/Builder.scala
+++ b/core/src/main/scala/chisel3/internal/Builder.scala
@@ -88,10 +88,19 @@ trait InstanceId {
private[chisel3] trait HasId extends InstanceId {
private[chisel3] def _onModuleClose: Unit = {}
- private[chisel3] var _parent: Option[BaseModule] = Builder.currentModule
+ // using nullable var for better memory usage
+ private var _parentVar: BaseModule = Builder.currentModule.getOrElse(null)
+ private[chisel3] def _parent: Option[BaseModule] = Option(_parentVar)
+ private[chisel3] def _parent_=(target: Option[BaseModule]): Unit = {
+ _parentVar = target.getOrElse(null)
+ }
// Set if the returned top-level module of a nested call to the Chisel Builder, see Definition.apply
- private[chisel3] var _circuit: Option[BaseModule] = None
+ private var _circuitVar: BaseModule = null // using nullable var for better memory usage
+ private[chisel3] def _circuit: Option[BaseModule] = Option(_circuitVar)
+ private[chisel3] def _circuit_=(target: Option[BaseModule]): Unit = {
+ _circuitVar = target.getOrElse(null)
+ }
private[chisel3] val _id: Long = Builder.idGen.next
@@ -100,10 +109,12 @@ private[chisel3] trait HasId extends InstanceId {
override def equals(that: Any): Boolean = super.equals(that)
// Contains suggested seed (user-decided seed)
- private var suggested_seed: Option[String] = None
+ private var suggested_seedVar: String = null // using nullable var for better memory usage
+ private def suggested_seed: Option[String] = Option(suggested_seedVar)
// Contains the seed computed automatically by the compiler plugin
- private var auto_seed: Option[String] = None
+ private var auto_seedVar: String = null // using nullable var for better memory usage
+ private def auto_seed: Option[String] = Option(auto_seedVar)
// Prefix for use in naming
// - Defaults to prefix at time when object is created
@@ -131,7 +142,7 @@ private[chisel3] trait HasId extends InstanceId {
private[chisel3] def autoSeed(seed: String): this.type = forceAutoSeed(seed)
// Bypass the overridden behavior of autoSeed in [[Data]], apply autoSeed even to ports
private[chisel3] def forceAutoSeed(seed: String): this.type = {
- auto_seed = Some(seed)
+ auto_seedVar = seed
for (hook <- auto_postseed_hooks.reverse) { hook(seed) }
naming_prefix = Builder.getPrefix
this
@@ -159,7 +170,7 @@ private[chisel3] trait HasId extends InstanceId {
* @return this object
*/
def suggestName(seed: => String): this.type = {
- if (suggested_seed.isEmpty) suggested_seed = Some(seed)
+ if (suggested_seed.isEmpty) suggested_seedVar = seed
naming_prefix = Builder.getPrefix
for (hook <- suggest_postseed_hooks.reverse) { hook(seed) }
this
@@ -171,7 +182,7 @@ private[chisel3] trait HasId extends InstanceId {
private[chisel3] def forceFinalName(seed: String): this.type = {
// This could be called with user prefixes, ignore them
noPrefix {
- suggested_seed = Some(seed)
+ suggested_seedVar = seed
this.suggestName(seed)
}
}
@@ -212,11 +223,12 @@ private[chisel3] trait HasId extends InstanceId {
naming_prefix = Nil
}
- private var _ref: Option[Arg] = None
+ private var _refVar: Arg = null // using nullable var for better memory usage
+ private def _ref: Option[Arg] = Option(_refVar)
private[chisel3] def setRef(imm: Arg): Unit = setRef(imm, false)
private[chisel3] def setRef(imm: Arg, force: Boolean): Unit = {
if (_ref.isEmpty || force) {
- _ref = Some(imm)
+ _refVar = imm
}
}
private[chisel3] def setRef(parent: HasId, name: String): Unit = setRef(Slot(Node(parent), name))