llvm / llvm/circt

[LowerToHW] An Error Should Be Generated if ForceNameAnnotation Would Not Be Unique

Open
#4,354 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Currently, two `ForceNameAnnotation`s can set an instance within the same module to the same name. The later one will eventually lose when it is uniqued by `PrepareForEmission`/`ExporVerilog`. This should instead be an error:

Consider the following which is trying to set all instances inside `ForceNameTop` to be called `Foo`:

```mlir
firrtl.circuit "ForceNameTop" {
firrtl.hierpath private @nla_1 [@ForceNameTop::@sym_foo, @ForceNameSubmodule]
firrtl.hierpath private @nla_2 [@ForceNameTop::@sym_bar, @ForceNameSubmodule]
firrtl.module private @ForceNameSubmodule() attributes {annotations = [
{circt.nonlocal = @nla_1,
class = "chisel3.util.experimental.ForceNameAnnotation", name = "Foo"},
{circt.nonlocal = @nla_2,
class = "chisel3.util.experimental.ForceNameAnnotation", name = "Foo"}
]} {}
firrtl.module @ForceNameTop() {
firrtl.instance Foo @ForceNameSubmodule()
firrtl.instance foo sym @sym_foo @ForceNameSubmodule()
firrtl.instance bar sym @sym_bar @ForceNameSubmodule()
}
}
```

After `LowerToHW` this has two instances with the same `verilogName`:

```mlir
module {
hw.module private @ForceNameSubmodule() {
hw.output
}
hw.module @ForceNameTop() {
hw.instance "Foo" @ForceNameSubmodule() -> ()
hw.instance "foo" sym @sym_foo @ForceNameSubmodule() -> () {hw.verilogName = "Foo"}
hw.instance "bar" sym @sym_bar @ForceNameSubmodule() -> () {hw.verilogName = "Foo"}
hw.output
}
}
```

This is fine and will generate sane Verilog below. However, this may be surprising to a user. Verilog is:

```verilog
// Generated by CIRCT unknown git version
module ForceNameSubmodule();
endmodule

module ForceNameTop();
ForceNameSubmodule Foo_0 ();
ForceNameSubmodule Foo ();
ForceNameSubmodule Foo_1 ();
endmodule
```

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 at the LowerToHW entry point and trace how PrepareForEmission and ExporVerilog handle ForceNameAnnotation names. The change is complete when duplicate forced names within one module produce an error instead of being uniqued into generated Verilog names; use the issue's MLIR example to exercise the 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.