llvm / llvm/circt

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

Open
#5,590 2 comments 0 reactions 0 assignees View on GitHub
bug FIRRTL
Dominant language
C++
Stars
2.2k
Forks
524
Avg merge
3d 2h
Merged PRs (30d)
46

Description

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 // 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] (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>) {
^
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the supplied MLIR reproducer and the --lower-firrtl-to-hw entry point, then trace how zero-width signals with inner symbols are handled. Compare the node and port cases shown in the issue, and review the related concerns in #4770 and #3526. Done should prevent referenced symbols from being silently deleted and provide the expected diagnostic or verifier behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.