llvm / llvm/circt

[FIRRTL][LowerToHW] HW::ModuleNamespace does not work with FIRRTL operations

Open
#5,626 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

```mlir
firrtl.circuit "Test" {
firrtl.module @Test() {
%w1 = firrtl.wire sym @__Test__w2 : !firrtl.uint<1>
%w2 = firrtl.wire {annotations = [{class = "firrtl.transforms.DontTouchAnnotation"}]} : !firrtl.uint<1>
}
}
```

Running: `./bin/circt-opt -pass-pipeline="builtin.module(lower-firrtl-to-hw)" ./test.mlir` gives:

```mlir
module {
hw.module @Test() {
%z_i1 = sv.constantZ : i1
%w1 = hw.wire %z_i1 sym @__Test__w2 : i1
%w2 = hw.wire %z_i1 sym @__Test__w2 : i1
hw.output
}
}
```
The problem is that both `w1` and `w2` now have the same `inner_sym` `@__Test__w2`.

Part of the problem is that we are using the `hw::ModuleNamespace` to create symbols, but this namespace is not properly populated on FIRRTL ops. This partly comes down to the fact that FIRRTL uses `InnerSymAttr` for `inner_sym`s, and HW uses `StringAttrs`.

Also, there are some places in `LowerToHW` where we fail to use the `moduleNamespace` at all when picking an inner symbol name.

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 with the LowerToHW implementation and the HW::ModuleNamespace handling described in the issue. Reproduce the command and FIRRTL input shown, then trace how FIRRTL inner_sym attributes populate the namespace and where LowerToHW selects names without it. Done means the two wires receive distinct inner_sym values and the reproduced output no longer aliases them.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.