diff options
| author | mergify[bot] | 2023-01-09 22:57:22 +0000 |
|---|---|---|
| committer | GitHub | 2023-01-09 22:57:22 +0000 |
| commit | 12785c6b2b8e378a5aa9db1833df7486d8f2a486 (patch) | |
| tree | d2c33c19c9dca8fc52e522a3de15fdc89ff089a9 | |
| parent | 116210ff806ccdda91b4c3343f78bad66783d0e6 (diff) | |
Improve performance of ChiselEnum annotations (#2923) (#2927)
ChiselEnums check if they should create annotations every time an
instance of them is bound. Because so many annotations would be created,
they check to see if an equivalent annotation has already been added to
the annotations. Previously, this used a linear search of the
annotations, now it uses a HashSet.
(cherry picked from commit 96bde092e449281dc70ebdb05f21695468c3e5fa)
Co-authored-by: Jack Koenig <koenig@sifive.com>
| -rw-r--r-- | core/src/main/scala/chisel3/StrongEnum.scala | 6 | ||||
| -rw-r--r-- | core/src/main/scala/chisel3/internal/Builder.scala | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/core/src/main/scala/chisel3/StrongEnum.scala b/core/src/main/scala/chisel3/StrongEnum.scala index 3c9f4105..c1967949 100644 --- a/core/src/main/scala/chisel3/StrongEnum.scala +++ b/core/src/main/scala/chisel3/StrongEnum.scala @@ -240,11 +240,13 @@ abstract class EnumType(private[chisel3] val factory: EnumFactory, selfAnnotatin case None => EnumComponentChiselAnnotation(this, enumTypeName) } - if (!Builder.annotations.contains(anno)) { + if (!Builder.enumAnnos.contains(anno)) { + Builder.enumAnnos += anno annotate(anno) } - if (!Builder.annotations.contains(factory.globalAnnotation)) { + if (!Builder.enumAnnos.contains(factory.globalAnnotation)) { + Builder.enumAnnos += factory.globalAnnotation annotate(factory.globalAnnotation) } } diff --git a/core/src/main/scala/chisel3/internal/Builder.scala b/core/src/main/scala/chisel3/internal/Builder.scala index d06b7992..fe7d7bea 100644 --- a/core/src/main/scala/chisel3/internal/Builder.scala +++ b/core/src/main/scala/chisel3/internal/Builder.scala @@ -485,6 +485,10 @@ private[chisel3] class DynamicContext( val newAnnotations = ArrayBuffer[ChiselMultiAnnotation]() var currentModule: Option[BaseModule] = None + // Enum annotations are added every time a StrongEnum is bound + // To keep the number down, we keep them unique in the annotations + val enumAnnos = mutable.HashSet[ChiselAnnotation]() + /** Contains a mapping from a elaborated module to their aspect * Set by [[ModuleAspect]] */ @@ -553,6 +557,8 @@ private[chisel3] object Builder extends LazyLogging { def components: ArrayBuffer[Component] = dynamicContext.components def annotations: ArrayBuffer[ChiselAnnotation] = dynamicContext.annotations + def enumAnnos: mutable.HashSet[ChiselAnnotation] = dynamicContext.enumAnnos + // TODO : Unify this with annotations in the future - done this way for backward compatability def newAnnotations: ArrayBuffer[ChiselMultiAnnotation] = dynamicContext.newAnnotations |
