llvm / llvm/circt

Circular logic not detected

Open
#3,403 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2.2k
Forks
524
Avg merge
3d 2h
Merged PRs (30d)
46

Description

The following code:
```
module {
hw.module @foo() -> (o: i1) {
%0 = comb.parity %0 : i1
hw.output %0 : i1
}
}
```

is considered correct and produces the following Verilog output (using `circt-opt circular.mlir --export-verilog`):
```
module foo( // circular.mlir:2:3
output o);

wire _GEN = ^_GEN; // circular.mlir:3:10
assign o = _GEN; // circular.mlir:4:5
endmodule
```

analyzing this with Verilator gives the following error:
```
$ verilator circular.v --lint-only
%Error: circular.v:5:13: Wire inputs its own output, creating circular logic (wire x=x)
5 | wire _GEN = ^_GEN;
| ^
%Warning-UNOPTFLAT: circular.v:5:8: Signal unoptimizable: Feedback to clock or circular logic: 'foo._GEN'
5 | wire _GEN = ^_GEN;
| ^~~~
... For warning description see https://verilator.org/warn/UNOPTFLAT?v=4.222
... Use "/* verilator lint_off UNOPTFLAT */" and lint_on around source to disable this message.
circular.v:5:8: Example path: foo._GEN
circular.v:5:13: Example path: ASSIGNW
circular.v:5:8: Example path: foo._GEN
%Error: Exiting due to 1 error(s), 1 warning(s)
```

in other words, this simple circular logic is not detected by the tools.

On a side note: `firtool` seems to hang up on this simple example and other circular examples

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example in circular.mlir with circt-opt --export-verilog and compare it with Verilator's circular-logic diagnostic. Also check the reported firtool hang on this and other circular examples. Done means the tools detect or otherwise reject the circular logic instead of accepting the input and emitting self-referential Verilog.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.