circt icon indicating copy to clipboard operation
circt copied to clipboard

[FIRRTL][LowerToHW] Zero-width signals with inner symbol are silently deleted, breaking users

Open dtzSiFive opened this issue 1 year ago • 2 comments

Consider this MLIR example:

module {
  firrtl.circuit "OMIRField" {
    firrtl.module @OMIRField(in %x_b: !firrtl.uint<0>, out %y_b: !firrtl.uint<0>) {
      %n_b = firrtl.node sym @omir_sym %x_b : !firrtl.uint<0>
      firrtl.strictconnect %y_b, %n_b : !firrtl.uint<0>
    }
  }
  sv.verbatim "Testing {{0}}" {symbols = [#hw.innerNameRef<@OMIRField::@omir_sym>]}
}

Feeding through LowerToHW: circt-opt --lower-firrtl-to-hw produces:

module {
  sv.verbatim "Testing {{0}}" {symbols = [#hw.innerNameRef<@OMIRField::@omir_sym>]}
  hw.module @OMIRField() {
    hw.output
  }
}

And if run through firtool directly, produces:

omir_zw_field_issue.mlir:8:3: error: cannot get name for symbol #hw.innerNameRef<@OMIRField::@omir_sym>
  sv.verbatim "Testing {{0}}" {symbols = [#hw.innerNameRef<@OMIRField::@omir_sym>]}
  ^
omir_zw_field_issue.mlir:8:3: note: see current operation: "sv.verbatim"() {format_string = "Testing {{0}}", symbols = [#hw.innerNameRef<@OMIRField::@omir_sym>]} : () -> ()
// Generated by CIRCT 1.46.0g20230714_98d0bf5
Testing <INVALID>	// omir_zw_field_issue.mlir:8:3
module OMIRField();	// omir_zw_field_issue.mlir:3:5
endmodule

The non-failing error isn't great and should be fixed (cc #4770 for similar in adjacent code). Also, this should be caught by the verifier in HW but that support isn't in place yet (cc #3526).


Moving the symbol to a port produces an error, modified input:

module {
  firrtl.circuit "OMIRField" {
    firrtl.module @OMIRField(in %x_b: !firrtl.uint<0> sym @omir_sym, out %y_b: !firrtl.uint<0>) {
      %n_b = firrtl.node %x_b : !firrtl.uint<0>
      firrtl.strictconnect %y_b, %n_b : !firrtl.uint<0>
    }
  }
  sv.verbatim "Testing {{0}}" {symbols = [#hw.innerNameRef<@OMIRField::@omir_sym>]}
}

Error:

omir_zw_field_issue.mlir:3:33: error: zero width port "x_b" is referenced by name [#hw<innerSym@omir_sym>] (e.g. in an XMR) but must be removed
    firrtl.module @OMIRField(in %x_b: !firrtl.uint<0> sym @omir_sym, out %y_b: !firrtl.uint<0>) {
                                ^

dtzSiFive avatar Jul 14 '23 17:07 dtzSiFive