summaryrefslogtreecommitdiff
path: root/core/src/main/scala/chisel3/RawModule.scala
diff options
context:
space:
mode:
authormergify[bot]2022-11-11 01:40:53 +0000
committerGitHub2022-11-11 01:40:53 +0000
commitc8046636a25474be4c547c6fe9c6d742ea7b1d13 (patch)
treeb637bbb18def8a496f2b1ca40917d7c79cd44c13 /core/src/main/scala/chisel3/RawModule.scala
parentc70e5bebaeaf5b0bd54ee84dc644ddd6973a1b86 (diff)
Change RawModule._commands to a VectorBuilder (backport #2839) (#2841)
* Change RawModule._commands to a VectorBuilder (#2839) * Change RawModule._commands to a VectorBuilder Use the resulting Vector to build the underlying Component's commands and then use those instead of copying the original ArrayBuffer when iterating on commands. Previously, the Component was using a List to hold the commands which is particularly memory inefficient, especially for large modules. * Optimize Converter's handling of Seq[Command] It previously converted the Commands to a List (which, while not captured in the type system, they were already a List) and then used head and tail iteration. This is less efficient with the new underlying Vector implementation. (cherry picked from commit 48a1ef0a3872c6b68d46145764d977926923a270) * Waive false binary compatibility failures Co-authored-by: Jack Koenig <koenig@sifive.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Diffstat (limited to 'core/src/main/scala/chisel3/RawModule.scala')
-rw-r--r--core/src/main/scala/chisel3/RawModule.scala14
1 files changed, 9 insertions, 5 deletions
diff --git a/core/src/main/scala/chisel3/RawModule.scala b/core/src/main/scala/chisel3/RawModule.scala
index f2ce4c70..9668313a 100644
--- a/core/src/main/scala/chisel3/RawModule.scala
+++ b/core/src/main/scala/chisel3/RawModule.scala
@@ -2,7 +2,6 @@
package chisel3
-import scala.collection.mutable.{ArrayBuffer, HashMap}
import scala.util.Try
import scala.language.experimental.macros
import scala.annotation.nowarn
@@ -13,6 +12,7 @@ import chisel3.internal.Builder._
import chisel3.internal.firrtl._
import chisel3.internal.sourceinfo.UnlocatableSourceInfo
import _root_.firrtl.annotations.{IsModule, ModuleTarget}
+import scala.collection.immutable.VectorBuilder
/** Abstract base class for Modules that contain Chisel RTL.
* This abstract base class is a user-defined module which does not include implicit clock and reset and supports
@@ -23,14 +23,18 @@ abstract class RawModule(implicit moduleCompileOptions: CompileOptions) extends
//
// RTL construction internals
//
- private val _commands = ArrayBuffer[Command]()
+ // Perhaps this should be an ArrayBuffer (or ArrayBuilder), but DefModule is public and has Seq[Command]
+ // so our best option is to share a single Seq datastructure with that
+ private val _commands = new VectorBuilder[Command]()
private[chisel3] def addCommand(c: Command) {
require(!_closed, "Can't write to module after module close")
_commands += c
}
- protected def getCommands = {
+ protected def getCommands: Seq[Command] = {
require(_closed, "Can't get commands before module close")
- _commands.toSeq
+ // Unsafe cast but we know that any RawModule uses a DefModule
+ // _component is defined as a var on BaseModule and we cannot override mutable vars
+ _component.get.asInstanceOf[DefModule].commands
}
//
@@ -153,7 +157,7 @@ abstract class RawModule(implicit moduleCompileOptions: CompileOptions) extends
Seq()
}
}
- val component = DefModule(this, name, firrtlPorts, invalidateCommands ++ getCommands)
+ val component = DefModule(this, name, firrtlPorts, invalidateCommands ++: _commands.result())
_component = Some(component)
_component
}