llvm / llvm/circt

[FIRRTL] Grand Central Views Don't Check Heterogeneous Vectors

Open
#4,246 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.2k
Forks
524
Avg merge
3d 2h
Merged PRs (30d)
46

Description

You can currently hand-craft a Grand Central View of an `AugmentedVectorType` that has different sized things and the view will build an interface where everything has the type of the first element. While this is, I think, impossible to hit from Chisel, we should catch this and error.

An example looks like:

```mlir
firrtl.circuit "InterfaceGroundType" attributes {
annotations = [
{
class = "sifive.enterprise.grandcentral.AugmentedBundleType",
defName = "VectorView",
elements = [
{
class = "sifive.enterprise.grandcentral.AugmentedVectorType",
elements = [
{
class = "sifive.enterprise.grandcentral.AugmentedGroundType",
name = "foo",
id = 4 : i64
},
{
class = "sifive.enterprise.grandcentral.AugmentedGroundType",
name = "bar",
id = 5 : i64
}
],
name = "vector"
}
],
id = 3 : i64,
name = "VectorView"
}
]
} {
firrtl.module @Companion() attributes {
annotations = [
{
class = "sifive.enterprise.grandcentral.ViewAnnotation.companion",
defName = "VectorView",
id = 3 : i64,
name = "VectorView"
}
]
} {

// These are dummy references created for the purposes of the test.
%_ui0 = firrtl.verbatim.expr "???" : () -> !firrtl.uint<0>
%_ui1 = firrtl.verbatim.expr "???" : () -> !firrtl.uint<1>
%_ui2 = firrtl.verbatim.expr "???" : () -> !firrtl.uint<2>
%ref_ui0 = firrtl.ref.send %_ui0 : !firrtl.uint<0>
%ref_ui1 = firrtl.ref.send %_ui1 : !firrtl.uint<1>
%ref_ui2 = firrtl.ref.send %_ui2 : !firrtl.uint<2>

%ui1 = firrtl.ref.resolve %ref_ui1 : !firrtl.ref>
%foo = firrtl.node %ui1 {
annotations = [
{
class = "sifive.enterprise.grandcentral.AugmentedGroundType",
id = 4 : i64
}
]
} : !firrtl.uint<1>

%ui2 = firrtl.ref.resolve %ref_ui2 : !firrtl.ref>
%bar = firrtl.node %ui2 {
annotations = [
{
class = "sifive.enterprise.grandcentral.AugmentedGroundType",
id = 5 : i64
}
]
} : !firrtl.uint<2>

}
firrtl.module @InterfaceGroundType() attributes {
annotations = [
{
class = "sifive.enterprise.grandcentral.ViewAnnotation.parent",
id = 3 : i64,
name = "VectorView"
}
]
} {
firrtl.instance companion @Companion()
}
}
```

This produces the following. The problem is that the interface signal is a `!hw.uarray<2xi1>`, but this is being driven by a `!firrtl.uint<1>` for the first element and a `!firrtl.uint<2>` for the second element:

```mlir
module {
firrtl.circuit "InterfaceGroundType" {
firrtl.module @Companion() {
%0 = sv.interface.instance sym @__VectorView_VectorView__ {name = "VectorView"} : !sv.interface<@VectorView>
%1 = firrtl.verbatim.expr "???" : () -> !firrtl.uint<0>
%2 = firrtl.verbatim.expr "???" : () -> !firrtl.uint<1>
%3 = firrtl.verbatim.expr "???" : () -> !firrtl.uint<2>
%4 = firrtl.ref.send %1 : !firrtl.uint<0>
%5 = firrtl.ref.send %2 : !firrtl.uint<1>
%6 = firrtl.ref.send %3 : !firrtl.uint<2>
%7 = firrtl.ref.resolve %5 : !firrtl.ref>
%foo = firrtl.node %7 : !firrtl.uint<1>
%8 = firrtl.ref.resolve %6 : !firrtl.ref>
%bar = firrtl.node %8 : !firrtl.uint<2>
sv.verbatim "assign {{1}}.vector[0] = {{0}};"(%7) : !firrtl.uint<1> {symbols = [#hw.innerNameRef<@Companion::@__VectorView_VectorView__>]}
sv.verbatim "assign {{1}}.vector[1] = {{0}};"(%8) : !firrtl.uint<2> {symbols = [#hw.innerNameRef<@Companion::@__VectorView_VectorView__>]}
}
firrtl.module @InterfaceGroundType() {
firrtl.instance companion @Companion()
}
sv.interface @VectorView attributes {comment = "VCS coverage exclude_file"} {
sv.interface.signal @vector : !hw.uarray<2xi1>
}
}
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing Grand Central View handling for AugmentedVectorType and reproduce the supplied MLIR example with differently sized elements. Done means heterogeneous vectors are rejected with an error instead of producing an interface typed from the first element; the payload names no files or tests to run.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.