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] Lower layers does not update HPs of non-local annotations #7144

Open
youngar opened this issue Jun 7, 2024 · 0 comments
Assignees
Labels
FIRRTL Involving the `firrtl` dialect

Comments

@youngar
Copy link
Member

youngar commented Jun 7, 2024

Given this firrtl IR:

FIRRTL version 4.0.0
circuit Top: %[[ {"class": "circt.test", "target": "~Top|Top/foo:Foo>w"} ]]
  layer A, bind:

  public module Top:
    inst foo of Foo
    inst bar of Foo
  module Foo:
    layerblock A:
      wire w : UInt<8>
      invalidate w

compiling with firtool -parse-only test.fir gives the following IR:

module {
  firrtl.circuit "Top" {
    hw.hierpath private @nla [@Top::@sym, @Foo]
    firrtl.layer @A  bind {
    }
    firrtl.module @Top() attributes {convention = #firrtl<convention scalarized>} {
      firrtl.instance foo sym @sym interesting_name @Foo()
      firrtl.instance bar interesting_name @Foo()
    }
    firrtl.module private @Foo() {
      firrtl.layerblock @A {
        %w = firrtl.wire interesting_name {annotations = [{circt.nonlocal = @nla, class = "circt.test"}]} : !firrtl.uint<8>
        %invalid_ui8 = firrtl.invalidvalue : !firrtl.uint<8>
        firrtl.matchingconnect %w, %invalid_ui8 : !firrtl.uint<8>
      }
    }
  }
}

After LowerLayers runs we get this IR:

// -----// IR Dump After LowerLayers (firrtl-lower-layers) //----- //
firrtl.circuit "Top" {
  sv.verbatim "`ifndef layers_Top_A\0A`define layers_Top_A" {output_file = #hw.output_file<"layers_Top_A.sv", excludeFromFileList>}
  hw.hierpath private @nla [@Top::@sym, @Foo]
  firrtl.module @Top() attributes {convention = #firrtl<convention scalarized>} {
    firrtl.instance foo sym @sym @Foo()
    firrtl.instance bar @Foo()
  }
  firrtl.module private @Foo_A() {
    %w = firrtl.wire {annotations = [{circt.nonlocal = @nla, class = "circt.test"}]} : !firrtl.uint<8>
    %c0_ui8 = firrtl.constant 0 : !firrtl.uint<8>
    firrtl.matchingconnect %w, %c0_ui8 : !firrtl.uint<8>
  }
  firrtl.module private @Foo() {
    firrtl.instance a {lowerToBind, output_file = #hw.output_file<"layers_Top_A.sv", excludeFromFileList>} @Foo_A()
  }
  sv.verbatim "`endif // layers_Top_A" {output_file = #hw.output_file<"layers_Top_A.sv", excludeFromFileList>}
}

This issue is that the non-local annotation on wire w is not updated when the wire is moved in to a module Foo_A, and corresponding hierpath operation still points to @Foo. I.e.
hw.hierpath private @nla [@Top::@sym, @Foo]
should be
hw.hierpath private @nla [@Top::@sym, @Foo::@a_sym, @Foo_A]
and the instance of Foo_A needs a new symbol a_sym.

Note that we can't just modify the original HierpathOp, since it may have other users which were not moved, so we must create a new Hierpath op.

This currently does not trigger a verifier error, which has a tracking issue here: #4896
A similar issue was tackled here: #6717

@youngar youngar added the FIRRTL Involving the `firrtl` dialect label Jun 7, 2024
@youngar youngar changed the title [FIRRTL][LowerLayers] Lower layers does not update NLAs of non-local annotations [FIRRTL][LowerLayers] Lower layers does not update HPs of non-local annotations Jun 7, 2024
@rwy7 rwy7 self-assigned this Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FIRRTL Involving the `firrtl` dialect
Projects
None yet
Development

No branches or pull requests

2 participants