llvm / circt

Circuit IR Compilers and Tools
https://circt.org
Other
1.67k stars 296 forks source link

[FIRRTL] Blackboxed memory instance name not prefixed by inlinining #2933

Closed youngar closed 2 years ago

youngar commented 2 years ago

This issue is really low priority, just wanted to record it. Inlining a module instance should cause the names of all things to be prefixed with the instance's name. The issue in MFC is that memories have a single name representing the module name and the instance name, and so we have no way to modify the name of one without the other.

test.fir

 circuit Top:
  module Top:
    input r : {addr: UInt<4>, en: UInt<1>, clk: Clock,  flip data: UInt<8>}
    input w : {addr: UInt<4>, en: UInt<1>, clk: Clock, data: UInt<8>, mask: UInt<1>}

    inst bar of Bar
    bar.r <= r
    bar.w <= w

  module Bar:
    input r : {addr: UInt<4>, en: UInt<1>, clk: Clock,  flip data: UInt<8>}
    input w : {addr: UInt<4>, en: UInt<1>, clk: Clock, data: UInt<8>, mask: UInt<1>}

    mem memory:
      data-type => UInt<8>
      depth => 16
      reader => r
      writer => w
      read-latency => 1
      write-latency => 1
      read-under-write => undefined
    memory.r <= r
    memory.w <= w

test.anno.json

[
    {
      "class":"firrtl.passes.InlineAnnotation",
      "target":"Top.Bar"
    }
]

Running through MFC ./bin/firtool --repl-seq-mem -repl-seq-mem-file=out.conf --strip-debug-info test.fir --annotation-file=test.anno.json

  memory_ext memory (
    .R0_addr (r_addr),
    .R0_en   (r_en),
    .R0_clk  (r_clk),
    .W0_addr (w_addr),
    .W0_en   (w_en & w_mask),
    .W0_clk  (w_clk),
    .W0_data (w_data),
    .R0_data (r_data)
  );

The name of the instance should be bar_memory.

Running through SFC: firrtl -i test.fir -o test -frsq -c:Top:-o:out.conf --inline Top.Bar

memory bar_memory (
    .R0_addr(bar_memory_R0_addr),
    .R0_en(bar_memory_R0_en),
    .R0_clk(bar_memory_R0_clk),
    .R0_data(bar_memory_R0_data),
    .W0_addr(bar_memory_W0_addr),
    .W0_en(bar_memory_W0_en),
    .W0_clk(bar_memory_W0_clk),
    .W0_data(bar_memory_W0_data),
    .W0_mask(bar_memory_W0_mask)
  );
youngar commented 2 years ago

Fixed by https://github.com/llvm/circt/pull/3065