llvm / llvm/circt

[firtool][ExportVerilog] Inline CSE'd Expressions

Open
#2,674 0 comments 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

Currently, `firtool` isn't inlining expressions which would help Verilog readability. This is coming from CSE'd expressions which are then not re-inlined.

Consider the following:

```scala
circuit Foo :
module Foo :
input a : UInt<1>
input b : UInt<1>
input c : UInt<1>
input d : UInt<1>
output e : UInt<1>
output f : UInt<1>

node _x_T = or(a, b)
node _x_T_1 = or(c, d)
node x = or(_x_T, _x_T_1)
node _y_T = or(a, b)
node _y_T_1 = and(c, d)
node y = or(_y_T, _y_T_1)
e <= x
f <= y
```

With `firtool`, this produces:

```verilog
module Foo( // Foo.fir:2:10
input a, b, c, d,
output e, f);

wire _x_T = a | b; // Foo.fir:10:17
assign e = _x_T | c | d; // Foo.fir:2:10, :12:14
assign f = _x_T | c & d; // Foo.fir:2:10, :14:19, :15:14
endmodule
```

The SFC produces:

```verilog
module Foo(
input a,
input b,
input c,
input d,
output e,
output f
);
assign e = a | b | (c | d);
assign f = a | b | c & d;
endmodule
```

In this situation, it would be better to not emit the CSE'd temporary `a | b` and instead emit it inline.

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

Use the FIRRTL example in the issue as the reproduction and start by tracing firtool's ExportVerilog flow, focusing on how CSE'd expressions become emitted temporaries. Done means the shared a | b expression is inlined in the generated Verilog rather than emitted as a temporary, while the shown outputs remain correct.

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
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.