llvm / llvm/circt

[LowerToHW] Define Behavior for Multiple Circuits

Open
#2,298 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Currently, if you compile multiple FIRRTL circuits, only one of them gets lowered. We need to define a behavior here for how this should work and what the resulting HW representation is. Consider the following:

```mlir
module {
firrtl.circuit "Foo" {
firrtl.module @Foo(in %a: !firrtl.uint<1>, out %b: !firrtl.uint<1>) {
firrtl.connect %b, %a : !firrtl.uint<1>, !firrtl.uint<1>
}
}
firrtl.circuit "Bar" {
firrtl.module @Bar(in %a: !firrtl.uint<1>, out %b: !firrtl.uint<1>) {
firrtl.connect %b, %a : !firrtl.uint<1>, !firrtl.uint<1>
}
}
}
```

This produces, after `LowerToHW`:
```mlir
module {
firrtl.circuit "Bar" {
firrtl.module @Bar(in %a: !firrtl.uint<1>, out %b: !firrtl.uint<1>) {
firrtl.connect %b, %a : !firrtl.uint<1>, !firrtl.uint<1>
}
}
hw.module @Foo(%a: i1) -> (b: i1) {
hw.output %a : i1
}
}
```

If allowed to continue after this, eventually `ExportVerilog` will print an error because it doesn't know how to handle a `firrtl.circuit`.

I can think of two behaviors here:

1. This should produce a flat list of modules.
2. (Likely what we need) This should lower each to two lists of modules in a `hw.namespace`-guarded region.

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

Start by tracing the LowerToHW entry point and the later ExportVerilog handling of firrtl.circuit. Compare the flat-module and hw.namespace approaches, determine the intended representation for multiple circuits, and define completion as consistent lowering of every circuit without leaving unsupported firrtl.circuit operations for ExportVerilog.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
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.