Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIRRTL][LowerLayers] Cannot send rwprobe out of layer #7365

Closed
dtzSiFive opened this issue Jul 22, 2024 · 2 comments
Closed

[FIRRTL][LowerLayers] Cannot send rwprobe out of layer #7365

dtzSiFive opened this issue Jul 22, 2024 · 2 comments
Labels
bug Something isn't working FIRRTL Involving the `firrtl` dialect

Comments

@dtzSiFive
Copy link
Contributor

Consider this design, which exposes a RWProbe to a wire in a layer:

FIRRTL version 4.0.0

circuit L:
  layer T, bind:

  public module L:
    output p : RWProbe<UInt<1>, T>

    layerblock T:
      wire w : UInt<1>
      connect w, UInt<1>(0)
      define p = rwprobe(w)

Presently this produces an error after LowerLayers:

layers-rwprobe.fir:12:18: error: 'firrtl.ref.rwprobe' op has non-local target
      define p = rwprobe(w)
                 ^
layers-rwprobe.fir:12:18: note: see current operation: %2 = "firrtl.ref.rwprobe"() {target = #hw.innerNameRef<@L::@sym>} : () -> !firrtl.rwprobe<uint<1>>

IR failing the above verification:

// -----// IR Dump After LowerLayers Failed (firrtl-lower-layers) //----- //
"firrtl.circuit"() ({
  "sv.verbatim"() {format_string = "`ifndef layers_L_T\0A`define layers_L_T", output_file = #hw.output_file<"layers_L_T.sv", excludeFromFileList>, symbols = []} : () -> ()
  "firrtl.module"() ({
  ^bb0(%arg1: !firrtl.rwprobe<uint<1>>):
    %1 = "firrtl.constant"() {value = 0 : ui1} : () -> !firrtl.uint<1>
    %2 = "firrtl.wire"() {annotations = [], inner_sym = #hw<innerSym@sym>, name = "w", nameKind = #firrtl<name_kind droppable_name>} : () -> !firrtl.uint<1>
    "firrtl.matchingconnect"(%2, %1) : (!firrtl.uint<1>, !firrtl.uint<1>) -> ()
    %3 = "firrtl.ref.rwprobe"() {target = #hw.innerNameRef<@L::@sym>} : () -> !firrtl.rwprobe<uint<1>>
    "firrtl.ref.define"(%arg1, %3) : (!firrtl.rwprobe<uint<1>>, !firrtl.rwprobe<uint<1>>) -> ()
  }) {annotations = [], convention = #firrtl<convention internal>, layers = [], portAnnotations = [], portDirections = array<i1: true>, portLocations = [loc(unknown)], portNames = ["p"], portSyms = [], portTypes = [!firrtl.rwprobe<uint<1>>], sym_name = "L_T", sym_visibility = "private"} : () -> ()
  "firrtl.module"() ({
  ^bb0(%arg0: !firrtl.rwprobe<uint<1>>):
    %0 = "firrtl.instance"() {annotations = [], inner_sym = #hw<innerSym@t>, layers = [], lowerToBind, moduleName = @L_T, name = "t", nameKind = #firrtl<name_kind droppable_name>, output_file = #hw.output_file<"layers_L_T.sv", excludeFromFileList>, portAnnotations = [[]], portDirections = array<i1: true>, portNames = ["p"]} : () -> !firrtl.rwprobe<uint<1>>
    "firrtl.ref.define"(%arg0, %0) : (!firrtl.rwprobe<uint<1>>, !firrtl.rwprobe<uint<1>>) -> ()
  }) {annotations = [], convention = #firrtl<convention scalarized>, layers = [], portAnnotations = [[]], portDirections = array<i1: true>, portLocations = [loc("layers-rwprobe.fir":7:12)], portNames = ["p"], portSyms = [], portTypes = [!firrtl.rwprobe<uint<1>>], sym_name = "L"} : () -> ()
  "sv.verbatim"() {format_string = "`endif // layers_L_T", output_file = #hw.output_file<"layers_L_T.sv", excludeFromFileList>, symbols = []} : () -> ()
}) {annotations = [], name = "L"} : () -> ()

Looks like LowerLayers needs to learn to rewrite the inner-refs used by operations it sinks.

cc #7144

@dtzSiFive dtzSiFive added bug Something isn't working FIRRTL Involving the `firrtl` dialect labels Jul 22, 2024
@dtzSiFive
Copy link
Contributor Author

Related, splitting the declaration from its rwprobe creation:

FIRRTL version 4.0.0

circuit L:
  layer T, bind:

  public module L:
    output p : RWProbe<UInt<1>, T>

    wire w : UInt<1>
    connect w, UInt<1>(0)
    layerblock T:
      define p = rwprobe(w)

Produces:

layers-rwprobe-2.fir:12:18: error: 'firrtl.ref.rwprobe' op has non-local target
      define p = rwprobe(w)
                 ^
layers-rwprobe-2.fir:12:18: note: see current operation: %0 = "firrtl.ref.rwprobe"() {target = #hw.innerNameRef<@L::@sym>} : () -> !firrtl.rwprobe<uint<1>>
// -----// IR Dump After LowerLayers Failed (firrtl-lower-layers) //----- //
"firrtl.circuit"() ({
  "sv.verbatim"() {format_string = "`ifndef layers_L_T\0A`define layers_L_T", output_file = #hw.output_file<"layers_L_T.sv", excludeFromFileList>, symbols = []} : () -> ()
  "firrtl.module"() ({
  ^bb0(%arg1: !firrtl.rwprobe<uint<1>>):
    %3 = "firrtl.ref.rwprobe"() {target = #hw.innerNameRef<@L::@sym>} : () -> !firrtl.rwprobe<uint<1>>
    "firrtl.ref.define"(%arg1, %3) : (!firrtl.rwprobe<uint<1>>, !firrtl.rwprobe<uint<1>>) -> ()
  }) {annotations = [], convention = #firrtl<convention internal>, layers = [], portAnnotations = [], portDirections = array<i1: true>, portLocations = [loc(unknown)], portNames = ["p"], portSyms = [], portTypes = [!firrtl.rwprobe<uint<1>>], sym_name = "L_T", sym_visibility = "private"} : () -> ()
  "firrtl.module"() ({
  ^bb0(%arg0: !firrtl.rwprobe<uint<1>>):
    %0 = "firrtl.wire"() {annotations = [], inner_sym = #hw<innerSym@sym>, name = "w", nameKind = #firrtl<name_kind droppable_name>} : () -> !firrtl.uint<1>
    %1 = "firrtl.constant"() {value = 0 : ui1} : () -> !firrtl.uint<1>
    "firrtl.matchingconnect"(%0, %1) : (!firrtl.uint<1>, !firrtl.uint<1>) -> ()
    %2 = "firrtl.instance"() {annotations = [], layers = [], lowerToBind, moduleName = @L_T, name = "t", nameKind = #firrtl<name_kind droppable_name>, output_file = #hw.output_file<"layers_L_T.sv", excludeFromFileList>, portAnnotations = [[]], portDirections = array<i1: true>, portNames = ["p"]} : () -> !firrtl.rwprobe<uint<1>>
    "firrtl.ref.define"(%arg0, %2) : (!firrtl.rwprobe<uint<1>>, !firrtl.rwprobe<uint<1>>) -> ()
  }) {annotations = [], convention = #firrtl<convention scalarized>, layers = [], portAnnotations = [[]], portDirections = array<i1: true>, portLocations = [loc("layers-rwprobe-2.fir":7:12)], portNames = ["p"], portSyms = [], portTypes = [!firrtl.rwprobe<uint<1>>], sym_name = "L"} : () -> ()
  "sv.verbatim"() {format_string = "`endif // layers_L_T", output_file = #hw.output_file<"layers_L_T.sv", excludeFromFileList>, symbols = []} : () -> ()
}) {annotations = [], name = "L"} : () -> ()

This one's trickier.

It's not possible to always sink the rwprobe target into the layer (could have other users, or target a port).

dtzSiFive added a commit to dtzSiFive/circt that referenced this issue Jul 22, 2024
dtzSiFive added a commit to dtzSiFive/circt that referenced this issue Jul 22, 2024
dtzSiFive added a commit to dtzSiFive/circt that referenced this issue Jul 22, 2024
@dtzSiFive
Copy link
Contributor Author

Second example as written I think should be rejected -- Layers shouldn't have access to write targets outside the layer. This is handled by #7372 .

So I believe that PR as well as #7369 (teaching LowerLayers to support this when it is possible -- target is within the same layer) will resolve this.

dtzSiFive added a commit to dtzSiFive/circt that referenced this issue Aug 6, 2024
Fixes first example in llvm#7365 .

Add error path to LowerLayers so anything that goes wrong
can fail the pass.
dtzSiFive added a commit to dtzSiFive/circt that referenced this issue Aug 8, 2024
Fixes first example in llvm#7365 .

Add error path to LowerLayers so anything that goes wrong
can fail the pass.
dtzSiFive added a commit to dtzSiFive/circt that referenced this issue Aug 8, 2024
Fixes first example in llvm#7365 .

Add error path to LowerLayers so anything that goes wrong
can fail the pass.
dtzSiFive added a commit to dtzSiFive/circt that referenced this issue Aug 12, 2024
Fixes first example in llvm#7365 .

Add error path to LowerLayers so anything that goes wrong
can fail the pass.
dtzSiFive added a commit to dtzSiFive/circt that referenced this issue Aug 15, 2024
Fixes first example in llvm#7365 .

Add error path to LowerLayers so anything that goes wrong
can fail the pass.
dtzSiFive added a commit that referenced this issue Aug 22, 2024
Fixes first example in #7365 .

Add error path to LowerLayers so anything that goes wrong
can fail the pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working FIRRTL Involving the `firrtl` dialect
Projects
None yet
Development

No branches or pull requests

1 participant