Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netlist track usage #2230

Merged
merged 3 commits into from
Jun 24, 2022
Merged

Netlist track usage #2230

merged 3 commits into from
Jun 24, 2022

Conversation

alex-mckenna
Copy link
Contributor

@alex-mckenna alex-mckenna commented May 31, 2022

When producing sequential and concurrent code, there are restrictions for how the same declared signal can be assigned which depend on the HDL being targeted. In short, these are

  • VHDL: A signal can be assigned continuously, or procedurally with non-blocking assignment. A variable can only be assigned procedurally with blocking assignment.
  • Verilog: A wire can only be assigned continuously. A reg can only be assigned procedurally, but can be assigned both non-blocking and blocking.

When the backend produces HDL, it needs to know the type of a declaration to render it. With the WireOrReg type, this was easy for VHDL, but does not help differentiate between if a signal is intended to be a VHDL signal or variable. A more general type is now provided which provides the extra information to make this choice:

data Blocking = Blocking | NonBlocking
data Usage    = Cont | Proc Blocking

Since a declaration can accept more than one type of assignment, the usage is not tracked with the declaration like WireOrReg was, but tracked in the assignments and a usage map is created for every component (tracking declared signals to their most restrictive use). When producing netlist, the current use of a signal should be checked to ensure that generated code only produces assignments that are valid for the backend being targeted.

Still TODO:

  • Write a changelog entry (see changelog/README.md)
  • Check copyright notices are up to date in edited files

@alex-mckenna alex-mckenna force-pushed the netlist-track-usage branch 4 times, most recently from cb665f9 to 5f90376 Compare June 1, 2022 09:09
Copy link
Member

@leonschoorl leonschoorl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See ^

Copy link
Member

@martijnbastiaan martijnbastiaan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but it'd be great if @christiaanb could give this a glance too.

clash-lib/src/Clash/Netlist/Types.hs Outdated Show resolved Hide resolved
@alex-mckenna alex-mckenna force-pushed the netlist-track-usage branch 2 times, most recently from ec9b281 to 72b5ab3 Compare June 22, 2022 12:55
Alex McKenna added 2 commits June 24, 2022 16:46
In NetDecl', the type of the decl was either a HWType or raw text.
Since only the HWType branch was ever used in Clash, this should
be simplified.
The function `id2identifier` is an unsafe version of `fromCoreId`
in the netlist identifier module. It makes more sense for it to
be defined there, so callers can see it is obviously unsafe.
When producing sequential and concurrent code, there are restrictions
for how the same declared signal can be assigned which depend on the
HDL being targeted. In short, these are

    VHDL: A `signal` can be assigned continuously, or procedurally
    with non-blocking assignment. A `variable` can only be assigned
    procedurally with blocking assignment.

    Verilog: A `wire` can only be assigned continuously. A `reg`
    can only be assigned procedurally, but can be assigned both
    non-blocking and blocking.

When the backend produces HDL, it needs to know the type of a
declaration to render it. With the `WireOrReg` type, this was easy
for VHDL, but does not help differentiate between if a signal is
intended to be a VHDL signal or variable. A more general type is
now provided which provides the extra information to make this
choice:

```haskell
data Blocking = Blocking | NonBlocking
data Usage    = Cont | Proc Blocking
```

Since a declaration can accept more than one type of assignment,
the usage is not tracked with the declaration like `WireOrReg` was,
but tracked in the assignments and a usage map is created for every
component (tracking declared signals to their most restrictive use).
When producing netlist, the current use of a signal should be
checked to ensure that generated code only produces assignments
that are valid for the backend being targeted.
@martijnbastiaan martijnbastiaan merged commit df3d5d1 into master Jun 24, 2022
@martijnbastiaan martijnbastiaan deleted the netlist-track-usage branch June 24, 2022 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants