circt icon indicating copy to clipboard operation
circt copied to clipboard

[FIRRTL] Compile time regression in `filterAnnotation` in LowerTypes

Open uenoku opened this issue 1 year ago • 4 comments
trafficstars

filterAnnotation filters annotations for a given field id but the current implementation travers every annotation. It takes O(NM) where N is a size of an annotation and M is maximum field id. This could be problematic when port is a large vector (e.g. 2^16 elements) and each leaf field has an annotation (e.g. dontTouch is scattered to each element).

uenoku avatar Nov 29 '23 07:11 uenoku

This is reproducer:

//> using scala "2.13.11"
//> using lib "org.chipsalliance::chisel::6.0.0-M3"
//> using plugin "org.chipsalliance:::chisel-plugin::6.0.0-M3"
//> using options "-unchecked", "-deprecation", "-language:reflectiveCalls", "-feature", "-Xcheckinit", "-Xfatal-warnings", "-Ywarn-dead-code", "-Ywarn-unused", "-Ymacro-annotations"

import chisel3._
import circt.stage.ChiselStage
import chisel3.dontTouch

class Foo extends Module {
  val a = IO(Input(Vec(65536, Bool())))
  a.map(dontTouch(_))
}

object Main extends App {
  /*println(
    ChiselStage.emitCHIRRTL(
      gen = new Foo
    )
  )*/
  println(
    ChiselStage.emitSystemVerilog(
      gen = new Foo,
      firtoolOpts = Array("-disable-all-randomization", "-strip-debug-info")
    )
  )
}

uenoku avatar Nov 29 '23 11:11 uenoku

Can you post the .fir file?

darthscsi avatar Nov 29 '23 15:11 darthscsi

Sure, fir file is fairly big. issue6466.tar.gz

uenoku avatar Nov 29 '23 15:11 uenoku

/> using scala "2.13.11"
//> using repository sonatype-s01:snapshots
//> using lib "org.chipsalliance::chisel::6.0.0-M3+117-2372b1c4-SNAPSHOT"
//> using plugin "org.chipsalliance:::chisel-plugin::6.0.0-M3+117-2372b1c4-SNAPSHOT"

//> using options "-unchecked", "-deprecation", "-language:reflectiveCalls", "-feature", "-Xcheckinit", "-Xfatal-warnings", "-Ywarn-dead-code", "-Ywarn-unused", "-Ymacro-annotations"

import chisel3._
import circt.stage.ChiselStage
import chisel3.dontTouch

class Foo extends Module {
  val a = IO(Input(Vec(65536, Bool())))
  val b = IO(Output(Vec(65536, Bool())))
  val r = Reg(Vec(65536, Bool()))
  r := a
  b := r
  r.map(dontTouch(_))
}

object Main extends App {
  /*println(
   ChiselStage.emitCHIRRTL(
    gen = new Foo
  ))*/
  println(
    ChiselStage.emitSystemVerilog(
     gen = new Foo,
      firtoolOpts = Array("-disable-all-randomization", "-strip-debug-info", "-verbose-pass-executions")
    )
   )
}

Note that we still need to fix the lower types even when lower-signature is enabled by default if we lower internal signals.

uenoku avatar Dec 07 '23 09:12 uenoku