Commit Graph

2481 Commits

Author SHA1 Message Date
Fabian Schuiki 23ae1a7391
[FIRRTL] Fix handling of new-style NLAs in ExtractInstances (#3345)
Adapt `ExtractInstances` such that it can properly handle the new flavor
of NLAs, where non-local annotations would carry a symbol to a hierpath
that generally only points at their parent module.

The `ExtractInstances` pass had a few assumptions in its implementation
about hierpaths pointing at the annotation target op, and each anno
having a unique hierpath op associated with it. The implementation can
be simplified quite a bit once support for the old-style NLAs can be
ripped out.

This commit also adds explicit tests to check that the old *and* new
style of NLAs are working in parallel.

A nasty corner case still exists when extraction requires an NLA to be
re-routed because the instance has been extracted past the NLA's
original root. If the instance is multiply-extracted, one hierpath gets
turned into multiple hierpaths, which will require special handling of
*everything* with that hierpath. This commit detects the common case
which we can handle and ensures that the hierpath is re-rooted in place,
and produces a warning about a potential breakage of hierpath references
in the corner case.
2022-06-15 12:50:51 -04:00
Will Dietz 9be1e8cd3f
[FIRRTL] ModuleInliner: new NLA support (#3337)
Primarily, differentiate NLA's that target only modules
for use in determining if inlining/flattening makes the NLA dead.
2022-06-15 12:49:46 -04:00
Will Dietz d5999f0ba1
[FIRParser] Handle annotations on instance ports properly. (#3355)
These require adding a symbol to the instance,
if one isn't otherwise already warranted.

Fixes #3340.

This was addressed for memory ports in #2792.
2022-06-15 09:57:52 -05:00
Hideto Ueno bb9803920e
[FIRRTL] Make droppable_name default (#3344)
This commit changes a default value of namekind from
interesting name to droppable name.

This is more comfortable in the situation where we want
to create a dummy unnamed wire for example
`builder.create<WireOp>(result.type())`. Previously this dummy wire
had an interesting name because default value is interesting.
This commit also changes IR representation accordingly.
2022-06-15 19:39:57 +09:00
Hideto Ueno 4aac8ed0b0
Revert "[ExportVerilog] Add an option to enforce wires for expressions with namehint (#3292)" (#3354)
This reverts commit db637d06b7. Since spillWiresForNamehints will not be used immediately at SiFIve, it would be saner to revert this to reduce the complexity of ExportVerilog.
2022-06-15 19:02:51 +09:00
Schuyler Eldridge d7366a63c3
[FIRRTL] Block Removal of Components w/ Annos
Make the presence of an Annotation block the removal of a component.
The presence of an Annotation indicates that some later pass cares about
this wire and it cannot be safely deleted.  Concretely, this enables
downstream passes from NOT having to slap DontTouchAnnotations on things
they care about (which implies, much strong, optimization block
behavior).

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-15 00:36:50 -04:00
Mike Urbach d759856da7
[ExportVerilog] Collect names from declarations before expressions. (#3342)
A situation can occur where a named declaration has its name re-named,
in which case the hw.verilogName is used to indicate the new
name. However, it is possible for collectNames to see a certain
expression that it wants to emit into a temporary, and decides to give
it a generated name that collides with another declaration's generated
hw.verilogName. This can happen if the expression is visited before
the declaration, and results in the declaration receiving a different
unique name, which doesn't match the assigned hw.verilogName.

This isn't a huge problem for local emission, but non-local things
like binds have to be able to trust the hw.verilogName attribute
holds the final name.

The change in this patch splits collectNames to loop over the IR
twice. First collecting names from declarations that may have a
hw.verilogName, and then collecting the rest of the names, and
doing the rest of the work like measuring widths, marking values
to emit, etc.

Some implementation alternatives considered:
  * Compute some sort of data structure containing the names. We're
  moving away from global name data structures in favor of using the
  IR. Computing something locally would need a pass over the IR
  anyway, so which would trade memory for runtime.
  * Modify the hw.verilogName attr to match what ExportVerilog
  selects. We are actively trying to make ExportVerilog mutate the IR
  less, and make hw.verlogName more stable, and this would be the
  opposite.
2022-06-14 13:18:22 -06:00
Andrew Lenharth 0769aac5d4
[FIRRTL] Remove old canonicalization patterns and fix NodeBypass (#3348)
Name removal is no longer a thing we need to do, droppable names subsumes that.  Further, there is an infinite application loop of NodeBypass which is fixed.
2022-06-14 10:56:28 -05:00
Hideto Ueno 0a33ba804f
[PrepareForEmission] Don't copy namehint to all sub expressions (#3313)
This commit fixes a (potential) bug that namehints of variadic ops are 
copied to all lowered sub expressions. Copying sv.namehint to all sub 
expression is weird even though it doesn't cause any bug 
(since namehints created here are not used at all).
2022-06-14 14:12:03 +09:00
Schuyler Eldridge cab91fadb9
[FIRRTL] Update InjectDUTHierarchy for new NLAs (#3331)
Update the InjectDUTHierarchy pass to work for both old-style
NLAs (where an NLA that targets a port/component ends in a
hw::InnerRefAttr) and new-style NLAs (where an NLA that targets a
port/component ends in a module/FlatSymbolRefAttr).

With these changes, InjectDUTHierarchy will reuse the existing DUT path
for components which use it inside the wrapper.  A module target or port
target annotation on the DUT will use a clone of the original path (and
get a new symbol).  This is a more efficient approach as it doesn't
require any walk of the DUT internals to find users.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-13 23:37:33 -04:00
John Demme 761b6107e7
[ExportVerilog] Verilog attribute support for sv.reg and sv.wire (#3330)
Verilog attributes (SV 2017, section 5.12) support for regs and wires. Just like comments on modules, we're adding this support only where we need it since we'll have to reason about it in transformations.
2022-06-13 19:51:58 -07:00
Andrew Lenharth 2adab7e26a
[FIRRTL] Better node bypass in canonicalize. (#3339)
Closes #3319
2022-06-13 21:28:51 -05:00
Andrew Young a89324428e
[FIRRTL] Update Dedup to handle HierPathOp ending on Module (#3309)
This change updates the dedup pass to handle non-local annotations that
use a hierarchical path which ends at the parent module instead of the
annotation target. The main change needed is to track a list of
operations which reference the path operation, as multiple operations
can now share a single path. A follow up commit will change dedup to
produce the new style of path when it changes a local annotation into a
non-local one.
2022-06-13 18:18:34 -07:00
Schuyler Eldridge a417a468fb
[FIRRTL] Update EmitOMIR for New NLA Style (#3336)
Remove internal NLA breadcrumbs that are unnecessarily generated in
EmitOMIR.  These are entirely unused by internal EmitOMIR analyses and
serve no purpose other than to be removed by the pass later.

Change the EmitOMIR pass to remove no hierpath ops.  It cannot safely do
this without computing the uses of a hierpath.  While the pass could be
updated to do this, it would be cleaner to handle hierpath removal with
a common DCE pass.

This change is made to support new NLA-style paths.  With this new
style, multiple NLAs may share the same hierpath ending at a module and
it is thereby unsafe for NLAs to decide to delete a hierpath without
checking for users.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-13 18:41:12 -04:00
Prithayan Barua 31511a79f1
[FIRRTL] Update GrandCentral SignalMapping to handle HierPathOp ending on Module (#3304)
Update GrandCentral SignalMapping to handle HierPathOp ending on Module.
This commit just removes the assert, no special handling logic is required.
2022-06-13 14:01:07 -07:00
Schuyler Eldridge 155c29de4a
[FIRRTL] Cleanup EmitOMIR Test, NFC
Cleanup the EmitOMIR test by using {{LITERAL}} to avoid complex escaped
matches of verbatim symbol substitution, e.g., "{{0}}".  Tighten up one
test that had already been migrated to using this by continuing to check
for the memory name (which needs to remain a regex match).

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-13 10:17:55 -04:00
Schuyler Eldridge f8abdff984
[FIRRTL] Cleanup long lines in EmitOMIR Test, NFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-12 19:32:35 -04:00
Schuyler Eldridge 3f4fb080c4
[FIRRTL] rm NLA Breadcrubms in EmitOMIR Test, NFC
Remove NLA breadcrumbs on instances from the EmitOMIR lit test.  These
are unnecessary after fixes that have landed on master to remove
reliance on breadcrumbs.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-12 19:27:46 -04:00
Schuyler Eldridge 6799e4f4f1
[FIRRTL] Add new-style NLA test of EmitOMIR, NFC
Extend an existing test of EmitOMIR to also check new-style NLAs for
OMIR SRAM Paths.  Specifically, check that EmitOMIR generates a symbol
for a symbol-less memory and that this generates the correct sv.verbatim
XMR path using this symbol.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-12 19:19:27 -04:00
Schuyler Eldridge 697c12181e
[FIRRTL] Minor cleanup of NLA EmitOMIR test, NFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-12 18:59:40 -04:00
Schuyler Eldridge f522572b3e
[FIRRTL] Cleanup NLA test of EmitOMIR, NFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-12 18:57:16 -04:00
Schuyler Eldridge c4ab711c44
[FIRRTL] Add MemToRegOfVec test of old/new NLAs
Add a test of old and new NLA formats to existing MemToRegOfVec tests.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-12 18:20:21 -04:00
Schuyler Eldridge 13a1853fb5
[FIRRTL] Formatting of mem-to-reg-of-vec.mlir, NFC
Cleanup the formatting of the mem-to-reg-of-vec.mlir test to avoid very
long lines.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-12 17:56:46 -04:00
Schuyler Eldridge cd0c462b04
[FIRRTL] Add test of GCT Views new-NLA foramt, NFC
Extend an existing test of GCT Views involving non-local annotations
that arise from deduplication to make sure that this works for the
new-style NLA format where hierarchical paths end in a module.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-12 16:56:35 -04:00
John Demme 2174fb368c
[MSFT] Support for multiple top levels of same module (#3321)
Some designs instantiate the same module more than once. Per-instance
data should be different, so we need a way to specify an "instance" of
the top level
2022-06-10 16:49:41 -07:00
Prithayan Barua 0c52723303
[FIRRTL] Fix ModuleInliner to not rely on nonlocal BreadCrumbs (#3317)
This commit updates the ModuleInliner to not rely on circt.nonlocal
 breadcrumbs and the NLATable analysis.
ModuleInliner uses a MutableNLA data structure to keep track of the updates
 that are required on the HierPathOps without actually updating the HierPathOp
 until the end of the pass. So, the algorithm has an invalid IR, while the pass
 is running, and the IR is updated only at the end. This algorithm doesn't work
 well with the NLATable, since the analysis expects the IR to be valid when the
 NLATable is queried.
For example if we query the NLATable to get the HierPathOps that an InstanceOp
 participates in, NLATable will lookup the namepath of a HierPathOp, but this
 does not work if the HierPathOp is invalid!

So, this PR updates the ModuleInliner to not rely on NLATable and construct an
 internal record of all the HierPathOps that each InstanceOp participates in,
 and keep it up-to-date while the algorithm is running.

While the algorithm is running, an InstanceOp can be renamed, or the HierPathOp
 that the InstanceOp participates in can be renamed. Hence, this PR adds the
 DenseMap<InnerRefAttr, SmallVector<StringAttr>> instOpHierPaths;, which
 records the HierPathOps that the InnerRefAttr corresponding to the InstanceOp
 participates in. This essentially replaces the breadcrumbs on the InstanceOp.

Fixes #3307
2022-06-10 09:26:26 -07:00
Prithayan Barua c6cc346550
[FIRRTL] Update GCT Taps to handle HierPathOp ending in Module (#3303)
This commit updates the GrandCentralTaps to handle HierPathOp ending in modules.
2022-06-10 09:02:52 -07:00
Fabian Schuiki 1cab6f2f0d
[LowerToHW] Disable threading in diagnostic tests; NFC
Add `-mlir-disable-threading` to the LowerToHW diagnostic verification
tests since multi-threaded error reporting is non-deterministic due to
`mlir::failableParallelForEachN` not properly abandoning error reports
for iterations running in parallel with a failing one.
2022-06-10 16:06:40 +02:00
Prithayan Barua 834a8b56d8
[LowerToHW] Fix bug with unmasked RW memory lowering (#3282)
This commit fixes an issue with lowering unmasked RW memories.
If a memory has a single bit mask, then the mask bit can be removed and
combined with the write enable. But if the memory is a ReadWrite memory,
then the enable port is used for both read and write enable. For such a
ReadWrite memory we cannot combine the write mask with the enable, it has
to be combined with the Write Mode. This ensures that if the mask bit is
disabled, then the write should be disabled, but not the read.
2022-06-10 06:20:45 -07:00
Hideto Ueno db637d06b7
[ExportVerilog] Add an option to enforce wires for expressions with namehint (#3292)
This commit introduces a new lowering option to spill wires for expressions
with namehints. Previously, namehints are used only when they are
spilled to temporary wires. However sometimes we want to use verbose outputs, 
so it would be good to have an option to probe expressions with namehints.
2022-06-10 21:44:27 +09:00
Hideto Ueno d1ce66bad7
[ExportVerilog] Add explicit bitcast for sub expressions (#3299)
Unfortunately spyglass infers bitwidth of sub expression incorrectly 
even when they are not toplevel. This commit will surpass the lint warnings.
This revert #3094 and adds explicit bitcast for every sub expression 
when `explicitBitcast` option is true
2022-06-10 03:48:37 +09:00
Hideto Ueno b1d0aacb8a
[FIRRTL] Add DropNamesPass (#3254)
This commit adds a pass `DropNamesPass` to change names to droppable
in order to disable name preservation. The pass walks `FNamableOp` and 
drop their names. This pass should be executed in the very early pipeline 
so that other passes can get more freedom about their names.
2022-06-09 19:02:54 +09:00
Hideto Ueno 8d5891f708
[FIRRTL] Split name preservation semantics into a dedicated attribute (#3247)
This PR adds NameKindAttr to explicitly represent name preservations of node, wire and register ops. Previously, `name` is directly used to represent the preservation kind (useless or interesting name) but it would be nicer to have the information explicitly, considering that name attributes are used as SSA names too. NameKindEnum has two elements, `InterestingName` and `DroppableName`. `InterestingName` must be preserved. 

Example:
```scala
circuit Foo:
  module Foo:
    input a: UInt<1>
    node b = a
    node _c = a
```  

Parse only output:
```mlir
 firrtl.module @Foo(in %a: !firrtl.uint<1>) {
      %b = firrtl.node  %a  : !firrtl.uint<1>
      // same as %b = firrtl.node interesting_name %a: !firrtl.uint<1>
      %_c = firrtl.node droppable_name  %a  : !firrtl.uint<1>
 }
```
2022-06-09 16:59:36 +09:00
Hideto Ueno 6a3b378510
[PrepareForEmission] Use namehint for spilled expression (#3297)
If it is necessary to spill an expression at PrepareForEmission and the expression has
a namehint, it would be better to use the name.
2022-06-09 14:32:56 +09:00
Andrew Young 201654e46a
[FIRRTL][Dedup] Add test for merging when blocks (#3308)
This just adds another test to make sure that we are recursively merging
operations with regions. I'm adding this test to make sure that this
doesn't regress from future refactorings.
2022-06-08 18:38:09 -07:00
Schuyler Eldridge 632ebfd960
[FIRRTL] rm NLA breadcrumbs from more tests, NFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-08 10:44:25 -04:00
Hideto Ueno c6d2d9c757
[FIRRTLFolds] Propagate name attributes (#3255)
This commit makes FIRRTL canonicalizers propagate "name" attribute when we replace operations.
2022-06-07 21:23:50 +09:00
Hideto Ueno 6360bdc946
[CombFolds] Propagate sv.namehint attribute more aggresively (#3269)
Currently sv.namehint is not propagate well at comb canonicalizer. To improve the situation, 
this commit replaces uses of `PatternRewriter::replaceOp` with its wrapper 
`replaceOpAndCopyName` to propagate sv.namehint attribute more aggressively.
2022-06-07 20:03:48 +09:00
Andrew Young e8e095c8dd
[FIRRTL] Properly parse printf assertions with no message (#3286)
The assertion parsing framework would parse the label from
`cover:my-label:` as the message.  This was a mistake in part of the
logic to handle missing labels in such cases as `cover:my message`,
where it would always use label as a message if the message was empty.
Now, it uses the colon to disambiguate the two cases.

As a follow up we should check if it is actually legal to have a missing
label.
2022-06-06 19:31:23 -07:00
Mike Urbach 72a3d33260
Revert "[FIRRTL] Cannonicalize wires to nodes (#3246)" (#3283)
This reverts commit 019280756e.
2022-06-06 13:16:44 -06:00
Christian Ulmann cce079c8ae [StandardToHandshake] Always emit `extmemory`, even when unused
This commit ensures that all memrefs are connected to memory.
2022-06-05 09:42:56 +02:00
Andrew Lenharth 019280756e
[FIRRTL] Cannonicalize wires to nodes (#3246)
When a wire has a single write and the write dominates all reads, we can convert the wire to a node.  Wires and nodes are identically treated, except the connect indirection, so we can convert to a more convenient form.
2022-06-04 15:06:10 -05:00
Will Dietz a79338dac5
[FIRRTL][IMConstProp] unique constants in module entry (#3264)
Fixes #3228.
2022-06-03 17:30:58 -05:00
Prithayan Barua 4ce7875aba
[FIRRTL] Fix unmasked RW memory lowering (#3272)
This commit fixes an issue with lowering unmasked RW memories.
If a memory has a single bit mask, then the mask bit can be removed and
 combined with the write enable. But if the memory is a ReadWrite memory,
 then the enable port is used for both read and write enable. For such a
 ReadWrite memory we cannot combine the write mask with the enable, it has
 to be combined with the Write Mode. This ensures that if the mask bit is
 disabled, then the write should be disabled, but not the read.
2022-06-03 15:21:20 -07:00
Will Dietz e9362babd0
[FIRRTL] Add support for emitting instance paths in signal driving (#3259)
* Relax checks about ports driven multiple times or instantiate multiple
  times, now that we support emitting references that
  differentiate between them.
* NLA's are now allowed (used for differentiating if dedup'd, fancy
  target paths, etc.), and converted into target refs.  Target refs
  start from NLA top unless there is a DUT on the namepath, in which case
  that is the top.
* Symbols/inner_sym's used for as much as possible instead of strings
* In verbatim, track symbols to re-use indices
2022-06-03 17:21:09 -05:00
Schuyler Eldridge a7e31bc565
[FIRRTL] Break out NLA/Symbol LowerType tests, NFC
Refactor NLA and symbol-related tests in lower-types.mlir to live in
separate circuits.  This is done in preparation for making updates to
code which changes these tests.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-02 15:20:09 -04:00
Schuyler Eldridge 32e728be26
[FIRRTL] Cleanup lower-types.mlir subAnno, NFC
Change lower-types.mlir test to use the non-escaped version of subAnno.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-02 15:15:03 -04:00
Schuyler Eldridge 9701b2445e
[FIRRTL] rm more LowerTypes flatten mem tests, NFC
Remove remaining memory flattening tests from lower-types.mlir that are
dead.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-02 14:55:44 -04:00
Schuyler Eldridge d20fbae31d
[FIRRTL] Remove dead lower-types.mlir tests, NFC
Remove tests in lower-types.mlir related to memory flattening.  This
behavior was moved into the LowerMemory pass in ac5036c3b.  ac5036c3b
also turned off these tests, but didn't rip out the tests.  This commit
culls the dead tests/FileCheck lines.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-02 14:46:36 -04:00
Schuyler Eldridge 5137bbae64
[FIRRTL] Test formatting, NFC
Cleanup the lower-types.mlir test to remove long lines, put annotations
on separate lines, etc.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-06-02 14:16:36 -04:00
Andrew Young 6a965dbeb7 [FIRRTL] Improve error message of invalid connection flow
This improves the error message produced when there is an invalid flow
of a connect.

1. We stopped printing the MLIR connect operation itself. Even though
   this is a verifier error, this is a user-facing error and we should
   not be dumping it.
2. Start printing the name of declaration involved in the error message,
   e.g. destination "x" has source flow.
3. Look through subfield operations when looking for the declaration
   location and while printing the declaration name "x.x", which
   provides accurate note declarations.

When the declaration referenced in a connect is an expression such as
`x + x`, we just skip the declaration name.
2022-06-02 09:42:39 -07:00
Christian Ulmann bf9f2d540a [Handshake] Add missing `lsq` attribute to `MemoryOp` 2022-06-02 15:14:41 +02:00
Hideto Ueno 5feec4085b [circt-reduce] Propagate names in `ConnectSourceOperandForwarder`
This commit changes ConnectSourceOperandForwarder to propagate
names of forwarded values.
2022-06-02 15:59:01 +09:00
Will Dietz 380ddc83b5
[SV] use module name for instantation name of extracted module (#3252)
Use module name instead of "InvisibleBind"
2022-06-01 20:32:00 -05:00
Andrew Lenharth fc14c94264 [NFC] Rename firrtl.nla to firrtl.hierpath 2022-06-01 09:22:54 -05:00
Schuyler Eldridge f0db1d60c6
[FIRRTL] Whitespace cleanup, NFC
Cleanup miscellaneous whitespace issues.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-31 21:56:11 -04:00
Schuyler Eldridge 766528762c
[FIRRTL] Always create GCT YAML File
Change Grand Central (GCT) View behavior to always create an output YAML
file, even if there are no GCT Views in the circuit.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-31 15:38:57 -04:00
Schuyler Eldridge c18b4dddb3
Revert "[FIRRTL] Use tap wires for GCT data taps (#3192)"
This reverts commit 56ff012114 as this has
problems with blocking deduplication.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-31 12:24:09 -04:00
Schuyler Eldridge 835d87b6b5
Revert "[FIRRTL] Change Grand Central Views to use Wire Taps and Sink Constants (#3167)"
This reverts commit e60c050478 because
this has issues with blocking deduplication.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-31 12:23:34 -04:00
Morten Borup Petersen 8cbfa4c55f
[SCFToCalyx, Calyx, CalyxToHW] Add support for signed div and rem (#3238)
Adds support both at the front- and back-end level to ensure that all signed `arith` division operators work end-to-end.
Notably, this also changes the semantics of the `DivLibPipe` operator in that it no longer provides both a quotient and remainder through division. This change is motivated by the fact that:
- `arith.div` operations only provide quotients
- `comb.div` operations only provide quotients

As such, this change aligns the calyx division operators to better fit within an MLIR/CIRCT up/downstream context.
2022-05-31 17:36:52 +02:00
Mike Urbach 1e0fb29e4c
[AffineToStaticLogic] Generalize loop bound computation. (#3234)
The loop bound computation previously relied on methods that attempted
to retrieve constant bounds, which would assert if the bounds were
non-constant (i.e. AffineMaps). This switches to use the same upstream
helpers that are used when lowering Affine loops to SCF loops, which
generate constant or dynamic Values using the Arithmetic dialect.

This fixes https://github.com/llvm/circt/issues/3127.
2022-05-28 20:42:32 -06:00
Nandor Licker 32d813436b
[llvm] bump (#3168)
* https://reviews.llvm.org/D124717 changed optional attribute handling in the Python API
* https://reviews.llvm.org/D125604 catches misspelled FileCheck directives
2022-05-28 10:46:42 +03:00
John Demme e00cf85163
[MSFT] Track instance hierarchy through module parameters (#3229)
The MSFT dialect will be specializing modules based on a _per-instance_ basis. In practice, we expect this to be rather sparse. Rather than elaborating the entire design, we've chosen to select implementations based on the instance hierarchy path. So we need a way to know said path. Tracking it through module parameters fills that need.

As a first step, this PR adds a pervasive `__INST_HIER` module parameter during lowering and appends the instance name to it in every module instance.
2022-05-27 19:35:15 -07:00
John Demme 788d40fa5f
[HW] [ExportVerilog] Add parameter concat expression (#3221)
Adds a `ParamExprAttr` opcode for string concatenation. Has a
simplification which merges adjacent strings. Includes ExportVerilog
support.
2022-05-27 15:54:39 -07:00
Andrew Young d9e9fb54bc
[FIRParser] Fix bug extending an APInt to a smaller width (#3226)
We recently removed usages of the deprecated function `sextOrSelf`.
This function allowed you to extend an APInt to a smaller width than it
currently is, becoming a noop.  The replacement function does not allow
doing this, and asserts.  During the cleanup I missed that we had to
guard this usage of `sext` to check the initial bit width before
attempting to sign-extend.

See: https://github.com/llvm/circt/pull/3202
2022-05-27 14:35:56 -07:00
Will Dietz cbee3460b0
[FIRRTL] Fix folds of zero-width values with zero-width constants (#3204)
fix folds of zero-width and zero-width const

Fix by ensuring the commonWidth used for checks
is always at least 1.

Fixes #2514.
2022-05-27 10:54:10 -05:00
Hideto Ueno 8bfdb6eacf
[LowerToHW] Support FIRRTL_BEFORE_INITIAL/FIRRTL_AFTER_INITIAL (#3193)
This commit supports FIRRTL_BEFORE_INITIAL/FIRRTL_AFTER_INITIAL
to inject statements before and after random initialization.
To maintain the relative order of ifdef blocks and initialization, sv.ordered is used.

This also fixes an invalid use of SmallDenseMap::[] which caused very weird
behavior.
2022-05-28 00:23:52 +09:00
Will Dietz 3de7f61096
[FIRRTL] fix cover predicate inversion (#3219)
Handle Cover operations differently than other verification ops, its expression/property works the other way.

Update canonicalization to elide cover(false) like we do assert(true).
2022-05-27 09:35:05 -05:00
Christian Ulmann d8da5b5a09 [HandshakeToFIRRTL] Add initial values to buffer module names
This commit adds the initial values to the names of the buffer modules
to create different modules for different initial values.
2022-05-27 16:22:46 +02:00
Andrew Lenharth 6399d2cf4d
Add an op to constrain output statements in graph regions (#3215)
Since graph regions don't have explicit output order, we add a region which outputs statements in order but is still a graph region. This let's macros which might attach to subsequent operations on expansion or other side-effecting code to be properly sequenced.
2022-05-27 08:03:15 -05:00
Hideto Ueno e49b5a7994
[HWMemSimImpl] Exclude generated memory modules from coverage (#3224)
Memories should be excluded from coverage. This PR adds VCS pragma to exclude
generated memory modules from coverage in HWMemSimImpl.
2022-05-27 21:56:57 +09:00
Hideto Ueno 96ce99b764
[ExportVerilog] Add an option to print debugInfo (#3147)
This commit adds a lowering-option "printDebugInfo" to emit debug information 
directly to output verilog. This emits symbols on ports, wires and registers in the 
comments.
2022-05-27 20:00:36 +09:00
Hideto Ueno fe93210816
[ExportVerilog] Emit a version string only to verilog files (#3174)
This fixes an issue that version string is emitted to non-verilog files
such as json, metadata files #3169. This commit adds an additional flag
`isVerilog` to `FileInfo` so that we can emit version strings
only to verilog files in SharedEmitterState::collectOpsForFile.
Currently, files are regarded as verilog if output file names has ".sv" suffix.
2022-05-27 17:52:40 +09:00
Fabian Schuiki 56ff012114
[FIRRTL] Use tap wires for GCT data taps (#3192)
Instead of directly referring to module ports, this commit changes the
GCT data taps pass to create an auxiliary "tap wire" inside the module.
The wire is connected such that it "observes" the current value of the
port (input or output), and all symbol references generated by GCT are
with respsect to this wire.

This has two distinct advantages:

1.  It removes a major source of symbols on module ports, which block
    port optimizations almost entirely.
2.  It offers a "receptacle" for IMConstProp to propagate constants
    into. This can lead to the tap wire being disconnected from the port
    if the port is only driven to a constant externally, which allows
    for the port to be removed.

Change GCT Data Taps to use a tap wire _for all_ taps, not just ports.
This is done to not block optimizations on tapped wires/nodes/registers
and to provide a constant receptacle for a constant value driven to
these wires.

Change Grand Central (GCT) Data Taps to sink trivial constants produced
by IMCP or canonicalization of "dead wire" taps into the actual data
tap.  The symbol on the "dead wire" tap is then removed to enable it to
be removed.

This causes some problems with existing tests that use invalid or
constant values.  Tests are updated to prevent this via either
DontTouchAnnotations or verbatim expressions (which block
optimizations).

Co-authored-by: Fabian Schuiki <fabian@schuiki.ch>
Co-authored-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-26 23:55:31 -04:00
John Demme 9040885a10 [ExportVerilog] Don't print the parameter type if NoneType
When emitting a module parameter which specifies neither a type nor a
default attribute, don't emit a type. Subsumes a string default since
the type of a StringAttr is NoneType.
2022-05-26 20:35:25 -07:00
Hideto Ueno 2d2f992756
[SVTestExtractCode][LowerToHW] Add coverage exclusion flag to testbench (#3183)
This adds "// VCS coverage exclude_file" comment to modules under testbench to
make coverage accurate. The comment is added to extracted modules at ETC and
modules under testbench (ref #3058).
2022-05-27 11:37:30 +09:00
John Demme 97ba2991c4
[MSFT] Add channel operation (#3203)
A logical, feed-forward connection between a producer and consumer. Can be
pipelined with a number of stages (cycle delay) on a per-instance basis.
`defaultStages` is used when `stages` isn't specified by a
`DynamicInstance`. Non-resettable, for now.

Per-instance specification is not yet supported, so the default pipelining
is always used.
2022-05-26 14:40:43 -07:00
Andrew Young 5613fffdaf
[FIRRTL] rename `mem-to-regOfVec` to `firrtl-mem-to-reg-of-vec` (#3205)
This adds the `firrtl-` prefix to the beginning of the command line
option for this pass, so that we keep our dialect passes namespaced.

I found the use of capital letters in the command line option to be a
unconventional, so I spread it out to the significantly longer
`firrtl-mem-to-reg-of-vec`.  In the future maybe we can think about
renaming this pass.
2022-05-26 12:49:40 -07:00
Schuyler Eldridge fc88564cd2
Revert "[HandshakeToFIRRTL] Add initial values to buffer module names"
This reverts commit 76e38b19f6 due to this
tripping nightly integration tests failures with clang release builds.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-26 10:48:13 -04:00
Christian Ulmann 76e38b19f6 [HandshakeToFIRRTL] Add initial values to buffer module names
This commit adds the initial values to the names of the buffer modules
to create different modules for different initial values.
2022-05-26 12:08:42 +02:00
Prithayan Barua 9902ad8878
[FIRRTL] Remove NLA breadcrumbs from InstanceOps (#3176)
This commit removes the NLA breadcrumbs from the InstanceOps. 
This is part of the changes to port the passes to use NLATable analysis
 instead of depending on the circt.nonlocal annotations on the InstanceOps.
Also, remove the code to update the NLA breadcrumbs.
And, remove the breadcrumb annotations from the lit tests.
2022-05-26 02:06:53 -07:00
Prithayan Barua 8543511f83
[FIRRTL] Update ExtractInstances pass to use NLATable analysis (#3172)
This commit updates the ExtractInstances pass to use the NLATable analysis.
It also removes the updates to circt.nonlocal breadcrumbs on the InstanceOp.
Also update the lit tests to remove the breadcrumbs.
2022-05-26 01:34:28 -07:00
Schuyler Eldridge e60c050478
[FIRRTL] Change Grand Central Views to use Wire Taps and Sink Constants (#3167)
Modify Grand Central (GCT) Views to use read-only wire taps instead of
directly tapping the targeted signals.  This change enables GCT Views to
not block optimizations due to tap points no longer getting inner
symbols (DontTouchAnnotations).

Improve Grand Central (CGCT) views handling to use constants instead of
XMRs when the XMR is tapping a wire/node that is driven by a constant.

E.g., GCT will now generate an XMR like the following where previously
it would XMR to a wire driven by a constant:

    assign Foo.bar.baz = 1'h1;

When this logic is used, also remove the symbol on the tapped wire.  This
effectively causes the constant tap to be a candidate for later DCE and
removes a source of dead wires in the output Verilog.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-25 22:59:02 -04:00
Andrew Young 8a17fe116e
[FIRRTL] Simplify NonLocalAnchor namepath printing (#3179)
Printing the namepath array as a regular attribute means we have a lot
of  overhead to write out all the `hw.innerRefAttr`s.  This changes the
NLA operation printer to print the `namepath` array without the name of
the of the attributes.

Before: `firrtl.nla @nla_1 [#hw.innerNameRef<@Foo::@bar>, #hw.innerNameRef<@Bar::@b>]`
After:    `firrtl.nla @nla_1 [@Foo::@bar, @Bar::@b]`
2022-05-25 16:39:04 -07:00
Andrew Young 5c1a2402aa
[FIRRTL] Remove unused BlackBoxMemory pass (#3187)
The `BlackBoxMemory` pass was an earlier implementation of SFC's
`ReplaceMemMacros` and has since been totally superseded by the newer
`LowerMemory` pass.
2022-05-25 15:29:58 -07:00
Morten Borup Petersen b3f0634e7d
[Calyx] Improve error handling in calyx emitter (#3198) 2022-05-25 22:08:16 +02:00
Schuyler Eldridge 539e148b1d
[FIRRTL] GCT Data/Mem Tap Scattering in LowerAnnotations (#3186)
Move all logic related to Grand Central Data and Memory Tap annotation
scattering from `FIRAnnotations.cpp` into the `LowerAnnotations` pass.

Besides moving the scattering into `LowerAnnotations`, there are a few
additional changes to the actual annotations that are being generated.

Data and memory tap annotations identify an extmodule which is to be
synthesized into a data/mem tap module by the GCT pass. To capture which
synthesized port should tap which signal in the design, annotations are
generated in pairs: one on the extmodule port and one on the thing being
tapped. These used to share the same class name and were only
distinguishable by a `type = "portName"` and `type = "source"` field.
This commit removes this `type` field and generates annotations with the
distinct classes in the following cases:

- `ReferenceDataTapKey` becomes `ReferenceDataTapKey.port` and
  `ReferenceDataTapKey.source`, respectively.
- `DataTapModuleSignalKey` becomes `DataTapModuleSignalKey.port` and
  `DataTapModuleSignalKey.source`, respectively.
- `MemTapAnnotation` becomes `MemTapAnnotation.port`, `MemTapAnnotation.source`,
  and `MemTapAnnotation.blackbox` respectively.
- `DataTapsAnnotation.blackbox` is added.

Furthermore, the `DataTapsAnnotation` that used to be placed on the data
tap extmodule is now called `DataTapsAnnotation.blackbox`. This change
is necessary to since `LowerAnnotations` has to distinguish between the
`DataTapsAnnotation` that requires custom scattering and the subsequent
simplified `DataTapsAnnotation` generated by that scattering which is
simply to be placed on the data tap extmodule.

Integration tests required no modifications, which is reassuring since
this commit attempts to only modify the intermediate representation of
GCT annotations before they are handled in the GCT data taps pass. This
GCT data taps pass tests were updated to match the new annotations. The
annotation scattering tests were migrated from `annotations.fir` into
`annotations.mlir` to match the move from `FIRAnnotations.cpp` into
`LowerAnnotations`.

This commit also adds a test for GCT mem taps on an actual `firrtl.mem`
op again which seems to have gotten lost sometime in the past and caused
a failure in an integration test that wasn't caught in the GCT data taps
pass tests.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Fabian Schuiki <fabian@schuiki.ch>
Co-authored-by: Fabian Schuiki <fabian@schuiki.ch>
2022-05-25 15:40:28 -04:00
Morten Borup Petersen 9fc044c223
[Calyx] Add sign extension support (#3189)
This commit completes support for sign extension in SCFToCalyx, Calyx, and CalyxToHW. A new primitive, `std_extsi` is introduced to perform sign extension whereas `std_pad` implements zero extension.
2022-05-25 19:19:26 +02:00
Andrew Young 658d3afe46
[firtool] Only blackbox SRAMs when `-repl-seq-mem` is specified (#3184)
Due some hasty changes when we realized that `MemToRegOfVec` transform
should not lower all memories, we started blackboxing seq mems which
we shouldn't be.  We need to make sure that the `LowerMemory` pass is
gated on the `repl-seq-mem` flag in firtool, which will allow SRAMs to
be lowered to generated memory modules instead of blackboxes.
2022-05-24 13:15:35 -07:00
Will Dietz 56196d490f
[FIRRTL] basic support for subcircuit signal driving flows (#3153)
* [FIRRTL] basic support for subcircuit signal driving flows

This is handled with a two-step flow:

* main.fir + subCircuit.json --(firtool)--> (normal output) + sigdrive.json (new)
* subcircuit.fir + sigdrive.json --(firtool)--> (normal output)

The new test in 'subcircuit-flow' demonstrates this in action.

There are many limitations, this is meant to just be enough to
support some specific existing use cases only.

See PR for more details.
2022-05-24 13:47:32 -05:00
Schuyler Eldridge 56c6f046b9
[FIRRTL] GCT View Scattering in LowerAnnotations (#3141)
Change firtool to always run LowerAnnotations.  Remove the "--new-anno"
option to conditionally run LowerAnnotations.

Move all logic related to Grand Central (GCT) view annotation scattering
from FIRAnnotations into the LowerAnnotations pass.  In this commit
there are difficult to spot changes to parseAugmentedType and
applyGCTView functions (where the latter is extracted from the body of a
method inside FIRAnnotations):

1. Functions now use ApplyState instead of parameters passed to the
   functions.

2. Any scattered annotations are handled by using ApplyState's ability
   to add annotations to the worklist.  E.g., parseAugmentedType will add a
   new annotation to the worklist for every ground type leaf.

Co-authored-by: Will Dietz <will.dietz@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-24 11:04:48 -04:00
Daniel Resnick 498798cbc6
[HW] Relax parameter evaluation to allow resolution to passed in parameters. (#3159)
This allows a parametric module to instantiate nested parametric modules using
its own parameters.

This change required reworking the HWSpecialize pass, where parametric modules
defer specialization of instantiated parametric modules until after the parent
modules themselves are specialized.
2022-05-23 09:37:16 -06:00
Will Dietz 1bc5e993a2
[FIRRTL] create more strictconnect's (#3045)
Fixups to generate more `strictconnects` where we already intended to, and tree-wide cleanup to simplify and remove redundant helpers methods in favor of `emitConnect`.
2022-05-23 10:10:58 -05:00
John Demme f3e651c647 [MSFT] Tcl output: do not output `|` before subpath
Automatically inserting a pipe before the subpath makes it impossible to
correctly use `[0]` as the subpath, which is necessary for locating bits
in a register.
2022-05-20 15:59:14 -07:00
Chris Gyurgyik 6e518751cc
[SCFToCalyx] [StaticLogicToCalyx] Separate lowerings to Calyx. (#3155)
Begin transition to separating the SCF and StaticLogic conversions to Calyx.
2022-05-20 15:53:56 -07:00
Schuyler Eldridge 91a1b02bd8
[FIRRTL] Improve Error on illegal Non-local Anno
Improve and test the error message generated when a non-local annotation
is seen that LowerAnnotations knows is supposed to only be local.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-20 18:02:43 -04:00
Andrew Young 7f73611331
Pretty print JSON metadata created (#3158)
This change specifies  2-space indentation to the JSON output stream
constructor, which causes the emitted JSON to be pretty printed.  We
don't care too much about minimizing these files, and it was a pain for
humans to read.
2022-05-20 14:53:14 -07:00
John Demme 940d827463
[MSFT] Add an op to place all the bits in a register (#3156)
`PDRegPhysLocationOp` takes a type and a list of physical locations. The
list of physical locations must equal the bit width of the type. The
physical locations are each optional.
2022-05-20 14:36:53 -07:00
Fabian Schuiki 68280a1426
[llvm] Bump LLVM to latest main (#3132)
Changes:

- Add `return failure()` where necessary now that `ParseResult` has
  gained the `LLVM_NODISCARD` attribute.

- Adapt to new MLIR type alias syntax (no longer needs "type"), e.g.
  `!foo = !hw.struct ...` instead of `!foo = type !hw.struct ...`

- Adapt to new attribute self-type parsing. Attributes now derive the
  self-type from syntax like `#attr : !hw.some_type`. No longer need
  an explicit type param `<T>` in stuff like `#firrtl.invalidvalue<T>`.

- Improve `add_circt_doc` to allow for multiple tablegen parameters and
  add `add_circt_dialect_doc` to unify the way dialect documentation is
  generated. The latter also passes the `-dialect` option to tablegen to
  sort out issues in the generated documentation if a dialect
  transitively includes another dialect. (This used to show up as
  multiple doc files having the name of another dialect.)

- Add `let useDefaultTypePrinterParser = 1` and
  `let useDefaultAttributePrinterParser = 1` to the dialect definitions
  where appropriate, since these have become off-by-default upstream.
2022-05-20 20:05:53 +02:00
Prithayan Barua 2167a06a23
[FIRRTL] Set name and file location for Comb memory wrapper module (#3150)
This commit sets the Combinational memory wrapper module name and file location,
instead of the generic "FIRRTLMem_0_2_0_8_16_1_1_1_0_1_0_a" formatted name and
default file location.
Use the name associated with firrtl.mem to derive the wrapper module name, after
appending it with _combMem.
This ensures the correct module prefix is used for the wrapper module. (For
example SiFive prefix for DUT modules and not otherwise).
For memories outside the DUT, set the output file directory to the TestBench
directory if available.
This change requires to add the MemOp to the FirMemory, such that the memory
dedup can be done in LowerToHW.
Use a map memoryNameMap to get the correct HWModuleGeneratedOp names for deduped
memories.
2022-05-20 09:30:59 -07:00
Christian Ulmann f7bb6b460d [Handshake] Add type equality checks to InstanceOp
This commit adds the `SymbolUserOpInterface` to the `InstanceOp` which
is used to enforce type equality of the operation and the `FuncOp` it
calls.
2022-05-20 08:00:45 +02:00
John Demme 0caf8adf96 [Tests] Remove Verilator sanity tests
Resolves #3139.
2022-05-19 13:35:36 -07:00
Chris Gyurgyik c54a303e8c
[SCFToCalyx] Add special case for pipeline stages with side effects only. (#3130)
This is a hot fix for allowing memory stores in the StaticLogic to Calyx pipeline.
2022-05-19 12:58:31 -07:00
Schuyler Eldridge 690259b4f1
[FIRRTL] Whitespace cleanup, NFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-19 13:58:57 -04:00
Schuyler Eldridge f3de52c5a8
Revert "[FSM] Canonicalize away unreachable states (#3020)"
Blameless revert of e1cf64ad00.  This is
done because there are some issues with the approach around
canonicalization that can cause intermittent failures in tests.  This
will be fixed up in #3131.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-17 17:51:36 -04:00
Schuyler Eldridge ba532693bc
[FIRRTL] Composable LowerAnnotations (#3129)
* [FIRRTL] Remove all-or-nothing LowerAnnos

Change the behavior of the LowerAnnos pass to work with existing
annotation scattering.  Previously, use of the `--new-anno` firtool
flag (and backing FIRParser option) would cause ONLY the LowerAnnos pass
to be used.  This changes that to use normal scattering and then apply
LowerAnnos.  This is done to enable piecemeal migration of scattering
work into LowerAnnos.

* [FIRRTL] Make LowerAnnos search non-standard attr

Change the LowerAnnotations pass to only process annotations from a
non-standard attribute on the circuit with key
"annotationsForLowerAnnotations".  This is done to enable the
LowerAnnotations pass to be run _after_ normal annotation processing
inside FIRAnnotations and FIRParser.  This then enables us to migrate
annotations one-by-one from FIRAnnotation/FIRParser handling (by moving
the annotation into "annotationsForLowerAnnotations").  This commit does
not put any annotations into this area for processing.  That will be
handled by subsequent commits.

* [FIRRTL] Add LowerAnnos passthrough in Parser

Modify the FIRRTL parser to let annotations that come in with the key
"annotationsForLowerAnnotations" to be placed in an attribute on the
circuit with this key.  This is currently unused infrastructure that
lets annotations inside FIRAnnotations be put behind this key to let
them be handled by the LowerAnnos pass.

* [FIRRTL] Add isAnnoClassLowered util, NFC

Add a utility, isAnnoClassLowered, that returns true if an annotation
class name is known to be handled by the LowerAnnotations pass.  This
effectively leaks internal information from the LowerAnnotations-defined
table of known annotations to let parsing/scattering logic know that
these annotations will be handled later.

* [FIRRTL] Skip LowerAnnos Annos During Parsing

Modify the Annotation parser to NOT handle annotations that are known to
LowerAnnotations.  This is done to enable seamless migration from
annotation handling in the parser to annotation handling in
LowerAnnotations.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-17 17:34:34 -04:00
Schuyler Eldridge 57a1b57023
[FIRRTL] Whitespace cleanup, NFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-16 19:41:52 -04:00
Mike Urbach 2f598e9327
[Calyx] Initial Calyx to HW conversion. (#3012)
This adds initial support for converting Calyx to the "core" CIRCT
dialects: HW, Comb, Seq, and SV. This is done in a fairly direct way
using the dialect conversion framework. This is direct in the sense
that a Calyx reg is mapped to a Seq reg, a Calyx assign is mapped to a
SV assign, a Calyx std_add is mapped to a Comb add, etc.

I tried to port big chunks of the Calyx primitives over at once, when
the conversion could be templated and shared. There are still some ops
missing conversions.

I also deviate slightly in the behavior of pipelined ops, like
multiplication. This may lead to slight cycle-by-cycle differences
with the Calyx standard library implementations, but should still
produce functionally identical behavior.

The implementation makes use of lots of SV wires and assigns, in order
to stay simple and in-line with the form of the Calyx IR. These are
massively cleaned up by canonicalization, which can be run after the
conversion.
2022-05-16 15:10:36 -06:00
Mike Urbach 199940346b [ExportVerilog] Future-proof max concat spilling test, NFC.
This is review follow up, to make this test future-proof in case we
change the default setting of this lowering option.
2022-05-16 13:25:53 -06:00
Christian Ulmann 09e8b29a4c [HandshakeToFIRRTL] Add support for PackOp and UnpackOp
This commit introduces lowerings of the operations working on tuples.
TupleTypes are transformed to BundleTypes.
The pack and unpack operations connect the separated values with the
ones encapsulated in the bundle while having similar control logic as
ForkOp and JoinOp.
2022-05-16 08:08:33 +02:00
Nandor Licker 33d1e29f27 [NFC] Renamed seq.compreg test file 2022-05-14 14:02:41 +03:00
Hideto Ueno 5a843ffa60
[LowerToHW] Wrap aynsc reset initiliazation by ifdef (#3128)
This fixes the difference between SFC and MFC in async initializations.
We should enable async initializations only when RANDOMIZE is defined.
2022-05-14 06:51:05 +09:00
Andrew Young 173962b8d0
[FIRRTL] Produce pre-extract seqmem metadata (#3123)
The metadata for seq_mems.json needs to be created before extract
instances runs, since it needs the original paths to the memory
operations.

This PR reverts the recent improvement to metadata emission, which used
symbols to ensure that the metadata reflected changes in the hierarchy.
It also modified the CreateSiFiveMetadata to pass to be able to run
before BlackBoxMemory. This just involved adding one extra annotation
to the list of known BlackBoxReader annotations.

Eventually, we will be getting rid of this particular piece of metadata, and
replacing it with OM.
2022-05-13 10:41:45 -05:00
Mike Urbach d18ca8cb5c
[PrepareForEmission] Spill wires for largish expressions in concat. (#3116)
This adds another heuristic to shouldSpillWire, this time to check if
the number of operands in a single expression inside a concat. If this
exceeds a configurable limit, a wire is spilled. This is to work
around Verilator #3405.

Large expressions inside a concat is worst case O(n^2) in a certain
Verilator optimization, and can effectively hang Verilator on large
designs. Verilator 4.224+ works around this by having a hard limit on
its recursion. Here we break large expressions inside concats
according to a configurable limit to work around the same issue.
See https://github.com/verilator/verilator/issues/3405.
2022-05-13 10:39:39 -05:00
Andrew Lenharth fdab3f0ff5 Don't reuse wires for constants. Fixes async reset lint warnings 2022-05-13 08:37:16 -07:00
Christian Ulmann 05beef09d0 [HandshakeToFIRRTL] Add support for tuple types
This commit introduces lowering for tuple types by transforming them to
BundleTypes.
2022-05-13 08:31:00 +02:00
Prithayan Barua b092a2f2f3
[FIRRTL] Guard the MemToReg transformation with the annotation (#3118)
This commit makes sure that the MemToRegOfVec transformation must run only if
 the annotation "sifive.enterprise.firrtl.ConvertMemToRegOfVecAnnotation$" is
 present on the Circuit op.
Earlier, the assumption was that the transformation can always run by default,
 but in order to match SFC behavior this check is necessary.
Add the check and update all the lit tests accordingly.
2022-05-12 15:12:50 -07:00
Andrew Young 743547a756
[FIRRTL][LowerCHIRRTL] Fix enable inference for aggregates (#3109)
Sequential memory read ports have enable inference when the address is
something with a name.  We missed that using the subfield of an
aggregate does not count as something with a name, and should tie the
enable of the port to 1.

This adds a more complicated check to turn on enable inference for ports
which verifies that the value used is a port, wire, reg, regreset, or
node.
2022-05-12 10:23:46 -07:00
John Demme 541b2b0799
[MSFT] [PyCDE] Attach arbitrary RTL attributes to instances (#3110)
Intended to support "set_instance_assignment -name" tcl output for
arbitrary names and values.
2022-05-12 10:11:14 -07:00
huanghuang 90ae0886aa
[HW Params] Implement common factor elimination for SHR, DIV and MOD. (#2958)
This deals with constant identities like `p1 << 0` into `p1`, `p1 >> 0` into `p1`, `p1 / 1` into `p1` and 
   `p1 % 1` into `0`.
2022-05-12 10:31:32 +08:00
Andrew Lenharth f20d66557c
Fewer Assigns of Constants in ExportVerilog (#3106)
Fold assignments of constants to wires into the wire declaration.
2022-05-11 11:13:06 -05:00
Morten Borup Petersen e8d8b47eb4
[Calyx] Make cell operations symbol-defining (#3100)
Previously, cells were instantiated with `FlatSymbolRefAttr`s but didn't actually use these in a symbol table context.
This commit changes the `CellOpInterface` to expect implementing operations to be symbol-defining operations. A side-effect of this is that we now implicitly check for duplicate instance names (something which was possible beforehand).
2022-05-11 17:31:23 +02:00
Fabian Schuiki ce990fc384
[FIRRTL] Add ExtractSeqMems end-to-end tests (#3103)
Add tests to `test/Dialect/FIRRTL/SFCTests` that specifically check if
the `ExtractSeqMems` portion of the `ExtractInstances` pass composes as
expected with other passes and features such as dedup, OMIR emission,
DUT hierarchy injection, and module prefixing.
2022-05-11 17:03:50 +02:00
Prithayan Barua ddb1f6e8bd
[FIRRTL] Handle memTap on Memories excluded from MemToReg (#3102)
Handle MemTap annotation on Memories that are excluded from `MemToRegOfVec`
 transformation. 
This fixes an issue with the commit #26276bf which updated this pass to only
 work on registers that were generated by `MemToRegOfVec` transformation. The
 assumption here was that every MemOp, should either be lowered to registers
 by `MemToRegOfVec` or to `FMemModuleOp` by `LowerMemory`. So, the GCT pass
 shouldn't expect to see a `MemOp`. 

But yesterday's commit #b923963, updated the `MemToRegOfVec` to exclude
 testbench memories but made the incorrect assumption that testbench memories
 wouldn't have memtap annotations. 
Finally this commit fixes that assumption and handles the Memtap annotation on
 `MemOp`s.
2022-05-11 07:46:57 -07:00
Hideto Ueno 0a542f9694
[LowerToHW] Lower node op with a symbol into read_inout op (#3099)
This commit changes to lower node ops with symbols into read_inout ops of wires.
Considering the concept of the current name preservation, "nodes become wires
if they have names", it would be nice to use existing named wires as much as possible.
This change basically disables optimizations across named nodes at comb levels,
so we can prevent canonicalizers from duplicating expressions.

This change reduces 30% temporary wires and 50% lint warnings related to dead wires
in the large design while improving the simulation performance as well.
2022-05-11 23:43:31 +09:00
Fabian Schuiki a72e131b0e
[FIRRTL] Fix ExtractInstances test comment 2022-05-11 16:35:48 +02:00
Andrew Lenharth e1036215ec When lowering memories, groupID is part of the identity of memories for uniquing, but not part of the identity for the symbol generated. Fix. 2022-05-11 06:11:23 -07:00
Hideto Ueno fa85d715ea
[ExportVerilog] Add extra bitcast to toplevel sub op (#3094)
This commit changes ExportVerilog to emit extra bitcast  to surpass
(false-positive) lint warning.
2022-05-11 07:13:38 -05:00
Fabian Schuiki 61eaddff7f
[FIRRTL] Uniquify extracted instance symbols (#3091)
Fix an issue in the `ExtractInstances` pass where certain diamond-shaped
instantiation arrangements can lead to instances with identical symbol
after extraction.

With this change, the pass uses `ModuleNamespace::newName` to ensure the
instance symbol is unique within the module it is being extracted to.
Fixing this also requires fixing an issue where a black box in a
multiply instantiated parent would not properly filter its non-local
annotations to only contain the ones that go through the parent instance
it was pulled out of.

Fixes #3089.
2022-05-11 11:16:12 +02:00
Prithayan Barua 832de8c7cc
[FIRRTL] Use symbols for metadata emission (#3096)
Fix metadata emission to use Symbols in the VerbatimOp, instead
of embedding the module/instance names in the string.
2022-05-11 00:22:02 -07:00
Prithayan Barua b92396367a
[FIRRTL] Exclude testbench memories from MemToReg, and preserve MemOp (#3098)
Run the MemToRegofVec transformation only on DUT memories and ignore any
 modules in the testbench. Also retain MemOps marked with
 `ExcludeMemFromMemToRegOfVec` annotation.
LowerMemory pass should not error out on CombMems, but just retain them to be
 lowered by HWMemSimImpl to registers.
2022-05-11 00:15:39 -07:00
Morten Borup Petersen a731099840
[Calyx] Add group-invariant code motion pass (#3087)
The assumption here is that any operation which is not a special group operation (`calyx.group_done,calyx.group_go,calyx.assign`) is some form of combinational computation that can be lifted to the wire scope.
2022-05-11 08:38:27 +02:00
Fabian Schuiki a8496ef5e9
[FIRRTL] Extract memory instances (#3093)
Extend the `ExtractInstances` pass such that it marks instances of the
new `FMemModuleOp` as to be extracted. This then allows the pass to
cover the functionality of the original `ExtractSeqMems` pass on the
Scala side of things.

Fixes #3092.
2022-05-11 06:45:03 +02:00
Andrew Lenharth 71e2b11628 Support lowering of firrtl.subaccess 2022-05-10 20:22:26 -07:00
Andrew Young e4ecc625a0
[FIRRTL][CreateSiFiveMetadata] Base metadata on FMemModules (#3069)
This changes the memory-related metadata emitted by this pass to be
created from FMemModules instead of MemOps. The memories will have
already been lowered into modules. The pass can be simplified because
it no longer has to worry about deduplicating the memories itself.
2022-05-10 14:03:48 -07:00
Andrew Young 4717d61d0e
[FIRRTL][LowerMemory] Store MemOp annotations on the instance (#3085)
This changing the memory op lowering to store all annotations that were
attached to the MemOp on the new instance op, instead of on the new
memory module op. This is needed because OMIR trackers distinguish
their type based on the operation they are attached to.
2022-05-10 13:13:13 -07:00
Hideto Ueno 1bcd3f49c2
[PrepareForEmission] Reuse wires for output ports (#3088)
This commit changes to reuse existing wires as placeholder of output ports
when output ports are uniquely assigned to a wire. This change reduces
the number of temporary wires in the large design 15%.
2022-05-11 03:34:51 +09:00
Andrew Young 41ceab3e22
[FIRRTL][LowerMemory] Wire the wrapper module to the blackbox (#3086)
I forgot to do the most important part when creating the wrapper module:
make sure to connect the ports of the wrapper to the inner instance.
2022-05-10 10:47:37 -07:00
Hideto Ueno a9bdc67cf5
[ExportVerilog] Add parentheses around reduction ops if necessary (#3015)
This commit adds extra parentheses around reduction ops (e.g. `&a` and `|b`) when 
their operators are emitted in a row. For example, `foo & &a` becomes `foo & (&a)`.
2022-05-10 21:50:20 +09:00
Andrew Lenharth f1d779bac2
[FIRRTL] Infer 0-length reset vectors as synchronous (#3083)
Fix an issue in `InferResets` where the FIRRTL input would under certain
circumstances contain a zero-length vector of resets like `Reset[0]` but
without any accompanying `x is invalid` statement. This would be the
case for an optional list of resets where the Chisel code would connect
the individual reset wires, but would just emit no connects at all since
none would be present in an empty vector.

The original Scala implementation of `InferResets` seems to either not
have to deal with this issue since zero-length vectors are removed early
on, or it just ignores them for later Verilog emission to discard them.

This commit adjusts the behaviour of `InferResets` to always infer
zero-length reset vectors to `UInt<1>`, similar to how `InvalidValueOp`
is treated.
2022-05-10 13:20:18 +02:00
Hideto Ueno 019eeb8830
[FIRRTL] Track clock values of memory ports precisely (#3079)
We should identify the clocks to be same even if the clock is passed via different wires.
This should prevent creating multiple write ports for combmem. This commit changes to
use `getModuleScopedDriver` to track clock port values.
2022-05-10 17:14:30 +09:00
Morten Borup Petersen fdc98b1e9c
[FSM] Implement graph traits for `fsm.machine` (#3073)
Initial implementation of LLVM graph traits for an FSM machine operation. This will most likely be a useful piece of code for building further transformations, visualizations, ... upon.
2022-05-10 09:30:29 +02:00
Andrew Young cb8d42a76a
[FIRRTL][LowerMemory] Create wrapper module (#3081)
When the SFC lowers memories to ext modules, they also create a wrapper
module which just instantiates the external module.  MFC did not create
this wrapper module, since the extra level of abstraction did not seem
necessary. We have found that to be a drop in replacement for SFC, we
need these wrapper modules so that Module and Instance paths are all
identical. This commit adds wrapper modules following the style of the
SFC.

This commit also fixes how non-local annotations are handled by this
pass.  When the memory operation has a non-local annotation attached, we
need to move the annotation over to the new module, update the NLA to
point to the module instead of the instance, and put an NLA reference on
the instance.
2022-05-09 22:35:08 -07:00
Mike Urbach d8aeb53197
[ExportVerilog] Try to re-use existing inouts when possible. (#3080)
ExportVerilog may end up spilling temporary declarations for
expressions that are already going to be assigned to an inout. Try to
anticipate this in PrepareForEmission, and rewrite the uses of the
expression to read from the inout when possible.
2022-05-09 23:03:58 -06:00
Prithayan Barua 26276bfc85
[FIRRTL] Add the Mem to Registers transformation (#3039)
This commit adds the MemToRegOfVec transformation to the FIRRTL pipeline.
This transformation converts all comb memories, to registers.
The mem tap and Async reset transformation are also updated to align 
with this transformation. 
(More details in the updated FIRRTL doc)
This transformation is enabled by default.
2022-05-09 22:03:02 -07:00
Andrew Young 826fb3e905
[FIRRTL][LowerToHW] Lower `firrtl.memmodule` to `hw.module.ext` (#3068)
This adds the ability to lower FIRRTL memory modules to external module
black boxes. This lowering is almost the same as FIRRTL external
modules, but without having to worry about parameterization or defname.
2022-05-09 19:38:52 -07:00
Andrew Young a3d2dc78ce
[FIRRTL][PrefixModules] Prefix and duplicate FMemModule ops (#3067)
This adds the ability to prefix and potentially duplicate the FIRRTL
memory modules.  When the new memory lowering pipeline takes over, we
can remove the `mem.group` attribute which `PrefixModules` is using to
prevent later deduplication of memories.
2022-05-09 19:38:23 -07:00
Andrew Young 8b559e45cd
[FIRRTL] Add LowerMemory pass (#3065)
This adds a pass to lower memory ops into instance of the new
FMemModuleOps.
2022-05-09 19:37:19 -07:00
Andrew Young 73f12d480f
[FIRRTL] Add AddSeqMemPorts pass (#3064)
This adds a new FIRRTL transformation which looks for
`AddSeqMemPortsAnnotation` and attaches the extra port specified to all
SRAMs under the DUT. The extra ports are always of type UInt<> with a
user specified width. The extra ports are wired up through the top of
the DUT and tied off to 0 in the testharness.

This pass requires that memories have been lowered to modules, and will
emit an error if it finds a regular mem op in the module. This is
because it is not possible to add arbitrary ports to a `mem` op that don't
match the schema of a memory `r`/`w`/`rw` port.
2022-05-09 19:36:57 -07:00
Aliaksei Chapyzhenka 37b7baff75
LLVM bump (as we know it) (#3074)
* LLVM bump (as we know it)

* minor format fix

* DCMAKE_BUILD_TYPE=?

* Update lib/Dialect/MSFT/MSFTOps.cpp

Co-authored-by: Andrew Young <youngar17@gmail.com>

* Update lib/Dialect/FIRRTL/FIRRTLOps.cpp

Co-authored-by: Andrew Young <youngar17@gmail.com>

* Update lib/Dialect/Calyx/CalyxOps.cpp

Co-authored-by: Andrew Young <youngar17@gmail.com>

* removed anon module test

Co-authored-by: Andrew Young <youngar17@gmail.com>
2022-05-09 14:30:14 -07:00
Andrew Young ca28a00b7f
[FIRRTL][FullAsyncResetTransform] Preseve synchronous reset value (#3078)
When the FullAsyncResetTransform replaces the reset of a register it
replaces all other connections to the register with a `mux(reset,
resetValue, originalValue)`.  This caused problems when the value was
connected inside of a When block. The old reset value would become gated
on the When op's condition.  The original reset value needed to have
higher priority than the original conditions. This change adds an
explicit self-connect to the register which is properly muxed with the
reset.

Input:
```firrtl
reg r : UInt<8>, clock with :
  (reset => (reset, UInt<8>(1)))

when cond:
  r <= x
```

Original output:
```firrtl
reg r : UInt<8>, clock with :
  (reset => (async, UInt<8>(0)))

when cond:
  r = mux (reset, UInt<8>(1), x)
```

New output:
```firrtl
reg r : UInt<8>, clock with :
  (reset => (async, UInt<8>(0)))

r <= mux(reset, UInt<8>(1), r)

when cond:
  r = mux (reset, UInt<8>(1), x)
```
2022-05-09 14:00:20 -07:00
Andrew Young 49bd507ff1
[FIRRTL][InferWidths] Support bundles in mux constraint (#3071)
The infer widths pass made the assumption that the arguments to a
`MuxPrimOp` were ground types, and would trigger an assertion trying to
create a `max(high, low)` constraint on the operands.  This changes the
mux constraint generation to recursively constrain the type of the
result to the maximum of the high and low signals.
2022-05-09 09:32:42 -07:00
Christian Ulmann 185a943475 [handshake-runner] Add support for tuple operations
This commit introduces tuple types to the handshake runner. Tuple values
are represented as vectors of values.

Tuples can be feed to the handshake runner by using the `"(val1, ...,
valN)"` syntax.
2022-05-09 17:02:31 +02:00
Mike Urbach 4d26da9746
[FIRRTL] Add output-mlir option to firtool. (#3052)
This works similarly to output-omir: if specified, the final MLIR is
written into this file. This is useful to get the final MLIR output
alongside some other output, especially split-verilog.

This would close https://github.com/llvm/circt/issues/2946.
2022-05-08 21:39:08 -06:00
Andrew Young 15299b68e2
[FIRRTL] Add FMemModule operation (#3063)
This adds a FMemModule operation, which is an external module used for
FIRRTL SRAMs.  It is almost exactly the same, except it doesn't support
FExtModule's parameterization, does not have  a `defname`, and it
contains required attributes for memory metadata. It was convenient to
not use FExtModules with a bunch of extra attributes stored on it to
make sure that the attributes were properly checked.

The set of attributes stored on the memory are those needed to create all
the metadata files.  The types used for the attributes were generally
the same as those used by the memory generator schema. It might make
sense to revisit the types and use signless integer types in the future.

Co-authored-by: Prithayan Barua <prithayan@gmail.com>
2022-05-07 15:52:19 -07:00
Morten Borup Petersen 7cc63a4db0
[Calyx] Make `wires` op a graph region (#3057)
Since we can emit `comb` logic in the `wires` region of a component, I'd also expect backedges to be legal.
2022-05-07 11:45:16 +02:00
Andrew Lenharth 6f550cb956
Preserves FIRRTL names (#3050)
This does a simple wire preservation. This means:

nodes and wires become wires if they have names
names that don't start with '_' are preserved
names don't block constant propgation, but do block deleting wires.
2022-05-06 22:52:10 -05:00
Will Dietz b45a12fb17
ExportVerilog: Add lowering option to force direction/type on each port (#3046) 2022-05-06 17:43:07 -05:00
Will Dietz 29e73d5c20
[FIRRTL] Look through tail/pad ops when checking for reset driver (#3059)
emitConnect will create these operations as needed.

Add regression test.
2022-05-06 15:52:24 -05:00
Hideto Ueno f870b99b0a
[LowerToHW][SVExtractTestCode] Don't extract assertions from testbench (#3058)
We don't have to extract assertions from modules in testbench since
it already separated from DUT. This commit addsfirrtl.extract.do_not_extract
attribue to modules on LowerToHW if they are located in testbench.
And in SVExtractTestCode, we skip extractions if that attribute appears.

This change will hopefully improve simulation performance by reducing overheads
of module instantiations.
2022-05-07 05:30:34 +09:00
Will Dietz 441101642b
FIRRTLFolds: don't crash on vector's connected to wire w/invalid (#3044)
Add test that crashes without this fix.

Fixes #3043.
2022-05-06 12:27:21 -05:00
Morten Borup Petersen 472cb848a7
[Calyx] Factor out various helper functions (#3055)
Factors out functions for building constants and registers in Calyx programs.

Note: For some reason, this change seems to partially apply canonicalization in the `compile-control.mlir` test wherein constants are moved to the cell-scope.
2022-05-06 16:46:09 +02:00
Morten Borup Petersen 4b29e3af87
[Calyx] Verify continuously assigned values (#3048)
The verification ensures that:
- At most one continuous assignment exists for any given value
- A continuously assigned wire has no assignments inside groups.
2022-05-06 10:45:13 +02:00
Fabian Schuiki 30dad68da3
[FIRRTL] Add ExtractInstances pass (#3017)
Add a `ExtractInstances` pass which implements a combined version of the
Scala `ExtractBlackBoxes`, `ExtractClockGates`, and `ExtractSeqMems`
passes. The pass is split into two phases:

As a first step it traverses modules and instances in the design and
marks the ones appropriately annotated for extraction.

In a second step it repeatedly pushes the marked instances up one level
of the hierarchy until they reach the desired parent module (usually
indicated with a `MarkDUTAnnotation`). The extracted instances are then
optionally grouped into a submodule at their extracted location. Finally
the pass also emits a text file indicating where the extracted instances
were originally located in the design.
2022-05-06 09:02:58 +02:00
Christian Ulmann da0c16a8ac [Handshake] Add tuple pack and unpack operations 2022-05-06 08:03:57 +02:00
Schuyler Eldridge a9f6e33314
[LowerToHW] Remove Non-const Async Reset Check
Remove a check that asynchronous reset registers are only reset to
constant values from the LowerToHW conversion.  This check has been
moved into the SFCCompat test.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-05 15:03:31 -04:00
Morten Borup Petersen 8feae132b7
[Calyx] Implement ClkInsertion and ResetInsertion passes (#3047) 2022-05-05 20:01:36 +02:00
Schuyler Eldridge 9729397514
[FIRRTL] Add CheckResets Behavior to SFCCompat (#3049)
Add SFC CheckResets logic to the SFCCompat pass.  This checks that no
async reset initial value is a non-constant when looking through wires,
nodes, connects, and casts.  An error and pass failure is generated if
this fails.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-05 13:26:28 -04:00
Chris Gyurgyik 24a9dfec98
[SCFToCalyx] Add source location metadata for Cider. (#2959) 2022-05-05 09:43:19 -07:00
Schuyler Eldridge a13978527e
[FIRRTL] s/RemoveInvalid/SFCCompat/, NFC
Change RemoveInvalid pass (yet again) to be called SFCCompat.  This
better reflects that this pass is currently and will be later changed to
be where SFC compatible modifications or checks live.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-05 10:28:42 -04:00
Will Dietz df7eb548d1 HW: Add tests for errors with hw.module.generated 2022-05-04 14:08:47 -05:00
Will Dietz ba79554f38
[FIRRTL] remove partialconnect (#3027)
Primarily, this removes PartialConnectOp!

Also adds type checking for partialconnect's in parser.

See PR for details/individual commits.
2022-05-04 13:00:14 -05:00
Hideto Ueno 0be7351e36
[CombFolds] Add a canonicalizer for addr(replicate(..)), orr(replicate(..)) (#3038)
This implements following canonicalizers which improve SiFive's internal designs. 
```
eq(replicate(v), 0) ==> v == 0
eq(replicate(v), -1) ===> v == -1
neq(replicate(v), 0) ==> v != 0
neq(replicate(v), -1) ===> v != -1
```
Close #3036
2022-05-04 23:18:39 +09:00
Will Dietz ef09a13748
FIRParser: don't crash if no main module, print error (#3035)
Also print more specific error in the case of no modules at all.

Fixes #2971.
2022-05-04 08:16:38 -05:00
Hideto Ueno 959f3a4fbf
[ExportVerilog] Make `isExpressionUnableToInline` more liberal (#2974)
This commit removes conditions of `isExpressionUnableToInline` regarding
users in different blocks. Dominance between user and def blocks is guaranteed
even in graph regions and because we are generating temporary wires at the
beginning of blocks, we don't have to check that condition today.
2022-05-04 16:57:49 +09:00
Morten Borup Petersen 0e7ccfe761
[FSM] Make transition guard and action regions optional (#3021)
Guard and action regions are now optional. This is already stated in the dialect rationale, but was not implemented.
2022-05-04 09:17:28 +02:00
Morten Borup Petersen e1cf64ad00
[FSM] Canonicalize away unreachable states (#3020)
Since we currently only allow a single initial state for the state machine, it is a reasonable assumption that any unreasonable states may be pruned as part of canonicalization.
2022-05-04 09:17:13 +02:00
Morten Borup Petersen a560084888
[FSM] Make initial state explicit (#3019)
Previously, the first state in the machine was assumed to be the initial state - I believe being explicit here is important to ensure the machine behaves as intended. Also modified "default" state to "initial" state (seems to be more consistent with litterature).
2022-05-04 08:33:39 +02:00
Schuyler Eldridge 09e675b46b
[FIRRTL] Whitespace cleanup, NFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-03 19:09:26 -04:00
Schuyler Eldridge 0fe725d37a
[FIRRTL] Whitespace cleanup, NFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-03 18:54:53 -04:00
Andrew Young 6c4b12d8e0
[FIRRTL][Dedup] Improve error when module is both NoDedup and MustDedup (#3032)
When a module is not deduplicated due to a NoDedup annotation, the
equivalence checker would compare the module bodies, missing the fact
that the annotation was what blocked deduplication.

This also fixes a bug when the NoDedup and MustDedup annotation pointed
at the same module.  We didn't record the presence of the module when it
was marked NoDedup which caused the MustDedup annotation to claim that
the referenced module did not exist.
2022-05-03 15:26:57 -07:00
Will Dietz 61e5d42e6b
circt-reduce,firtool,llhd-sim: cleanup --help output, put options in category (#2979)
* circt-reduce: cleanup --help output, put options in category

Hides unrelated options from LLVM+co, and makes it easier
to find the most relevant options at glance.

When building CIRCT against LLVM built as shared libraries
(as preferred by many Linux distributions) this greatly
reduces the number of options printed.

* firtool: cleanup --help output, put options in category

Hides unrelated options from LLVM+co, and makes it easier
to find the most relevant options at glance.

When building CIRCT against LLVM built as shared libraries
(as preferred by many Linux distributions) this greatly
reduces the number of options printed.

* llhd-sim: group llhd-sim options in --help output

Hides unrelated options from LLVM+co, and makes it easier
to find the most relevant options at glance.

When building CIRCT against LLVM built as shared libraries
(as preferred by many Linux distributions) this greatly
reduces the number of options printed.

Even for the statically linked version more commonly used
with CIRCT, the help output is significantly reduced.

* llhd-sim: touchup optimizationLevel cl::opt to be static (NFCI)

* test/llhd-sim: Add commandline test

* circt-reduce: check categories in help test

* firtool: check categories in help test

* firtool: add new option to mainCategory too
2022-05-03 16:02:57 -05:00
Richard Xia 167d0e3ae0
[FIRRTL] DUT seq mems paths should start from the DUT module. (#3031)
In the Scala FIRRTL Compiler (SFC), the instance paths to memories in
seq_mems.json and tb_seq_mems.json have a different root module
depending on whether the memory is located within the design-under-test
(DUT).

DUT memory paths should start from the DUT, while testbench memory paths
should start from the testbench (circuit top module).

Co-authored-by: Andrew Lenharth <darthscsi@users.noreply.github.com>
Co-authored-by: Andrew Young <youngar17@gmail.com>
2022-05-03 12:42:25 -07:00
Will Dietz ece82bc44d
[FIRRTL] check flip orientation in connect operations (#3025)
* FIRRTLTypes: check for matching orientation on bundle elements

* FIRParser: don't use passive types when type-checking connect's

* FIRParser: fix debug taps creating newly invalid connect operations

The tap is set to be passive, so direct connect of bundles containing
flip orientations is no longer legal.

For these, break them and connect components.

* RationaleFIRRTL: fix field name in Bar flip example

Otherwise firrtl rejects this code regardless of type canonicalization

* connect-errors.fir: add test, examples from docs

* FIRParser: reuse expression, simplify a bit

As suggested in review, thanks!

* parse-name-preservation: check tap details

Don't only check that tap isn't created as it was previously.
Suggested in review, thanks!

* FIRRTLTypes.h: update comment for areTypesEquivalent

Sync w/comment on definition

* FIRParser: delete some dead code
2022-05-03 13:56:41 -05:00
Nandor Licker dd8b8f6bec
[SV] Added `macro.ref` to reference macros. (#2921)
Replaced verbatim expressions referencing macros with an explicit op.
2022-05-03 21:28:26 +03:00
Will Dietz 3f9878b54b
FIREmitter: give strictconnect same invalid treatment, add test (#3029) 2022-05-03 13:09:37 -05:00
Andrew Young e2369f0a90
[HW] Remove InstanceOp's constaint on the symbol (#2994)
The `HWInstanceOp` has a redundent check that the SymbolRef it has is a
valid HW module operation. This change keeps the more efficient of the
two methods, and remove the slower one.
2022-05-03 09:20:05 -07:00
Christian Ulmann be3f5b530b [Handshake] Add sink materialization for block arguments 2022-05-03 15:44:27 +02:00
Schuyler Eldridge 10ae4179d5
[FIRRTL] Add InjectDUTHierarchy Pass (#2989)
Add a pass that adds a level of hierarchy (indicated by an
InjectDUTHierarchyAnnotation) above the DUT (as indicated by a
MarkDUTAnnotation).

Add an option to enable the InjectDUTHierarchy pass from a command-line
option in firtool.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-05-02 22:20:15 -04:00
Christian Ulmann a2e0dc63d5 [Handshake] Add optional visibility parsing for `FuncOp` 2022-05-02 21:29:07 +02:00
Nandor Licker 300e24414e
[SV] Avoid temporary wires when ReadInOutOp is after use (#3009)
When the ReadInOutOp accessing a register or a wire was after the use of the read value, a temporary wire was emitted.  This patch instead moves both the definition of the read operation and the read itself to the top of the module, ensuring the order is correct and no temporaries are needed.

As a result, the verilog representation of a large design is 0.6% shorter, with thousands of temporaries eliminated.
2022-05-02 14:06:19 +03:00
John Demme 20d125710f
[MSFT] Make dynamic instances hierarchical (#3005)
Create an instance hierarchy root operation. Require dynamic instances
to nest inside of it and only represent a single level of the hierarchy.
Results in a tree which better models the instance hierarchy.
2022-04-29 23:15:01 -07:00
Hideto Ueno 5285d244fb
[FIRRTL][LowerToHW] Insert extra initialization for async regs (#3000)
This commit adds an extra initialization for async registers so
that they are set to initial values if reset signal is enabled at
an initial randomization phase. This matches SFC's behaviour.

Close #2999.
2022-04-30 15:11:04 +09:00
Hideto Ueno 7b342af44f
[FIRRTL] [CheckCombCycles] Improve error message by reconstructing a full cycle (#2970)
This commit tries improving CheckCombCycles's error message by recursively
inspecting instances and recovering a full cycle. Previously it didn't recurse into 
instance's internal so the message is less informative than SFC.
2022-04-29 19:20:58 +09:00
Will Dietz d7b253d905
[FIRRTL][ModuleInliner] fix flatten+inline into multiple instance sites, annotation cleanup (#2998)
* [FIRRTL][ModuleInliner] Add test for inlining flattened module multiple times

This test presently fails.

* [FIRRTL][ModuleInliner] Don't remove flatten annotation immediately

We need to keep it around to know to inline-flatten
should it be visited again (multiple sites, for example),
and to ensure flattening occurs when it is reached in the worklist.

This fixes TestInliningFlatten, but breaks annotation cleanup.

This partially reverts e1709ff509.

* [FIRRTL][ModuleInliner] Fix removing flatten annotations

The previous code removed it from the temporary AnnotationSet object,
not the module itself.  Also the code skipped this line when the
annotation was present (shouldFlatten was true -> continue).

Now the annotation is removed (only) when the module has been flattened.

It may still be visited for inlining on a separate path,
but since flattening has occurred just inlining as normal is fine.
(inlineInto instead of flattenInto).

* [FIRRTL][ModuleInliner] Add test for annotation removal on public modules

This test currently fails, as InlineAnnotation lingers on public modules.

These aren't removed explicitly as previously all inlined modules
became dead and were removed (taking their inline annotation with them).

* [FIRRTL][ModuleInliner] Clean up lingering inline annotations

While walking modules anyway, assert no remaining (live) modules still
have the flatten annotation as these are removed when flattening.
Their presence at this point suggests a bug of some kind.

This change fixes TestPubAnno.

* [FIRRTL][ModuleInliner] Quiet tidy remarks about recursion (NFC)
2022-04-28 15:55:11 -05:00
Andrew Young 1921121662
[FIRRTL] print mem.conf even if there are no memories (#2991)
Currently, when passed `--repl-seq-mem-file=mem.conf` and there are no
memories, we will not emit the `mem.conf` metadata. This changes that
behaviour to create an empty file, which is the same as SFC behaviour.
Some tooling expects this file to be created even if it is empty.  We
made a similar change for `seq_mems.json` and previously decided we
didn't need to have the same behaviour for this file.
2022-04-27 21:19:52 -07:00
Andrew Young 7b72e58cd2
[FIRRTL] Rename `LowerMemory` to `FlattenMemory` (#2992)
The `LowerMemory` pass currently just flatten aggregate datatypes into a
single uint.  I want to separate the logic which lowers memories into
`hw.generatorModule`s out into a different pass, and I want to use the
name `LowerMemory` for that.
2022-04-27 19:22:11 -07:00
Prithayan Barua ac5036c3b3
[FIRRTL] Add a memory flattening pass (#2967)
Create a new pass to flatten the aggregate memory instead of doing it in LowerTypes.
This commit removes the logic from LowerTypes and moves it into a new pass that 
should run before LowerTypes.
2022-04-27 18:24:19 -07:00
Prithayan Barua b9c82fa7bf
[FIRRTL] Add "_ext" suffix to Memory module and instance name (#2982)
Update the memory module name and instance names with an "_ext" suffix to
 match SFC behavior. This commit adds a utility to Namespace, to generate
 a unique new name with a given suffix.
This utility is used to generate the memory module name with "_ext" suffix.
This commit also updates the LowerToHW to add the "_ext" suffix to 
the instance name.
2022-04-27 16:28:57 -07:00
Morten Borup Petersen 6af3152e93
[StandardToHandshake] Fix function type for external FuncOps (#2987) 2022-04-27 17:17:27 +02:00
Morten Borup Petersen 8709992be0
[StandardToHandshake] Support external functions (#2984) 2022-04-27 14:54:30 +02:00
Andrew Young 1f571ad7ab
[FIRRTL][Dedup] Fix MustDedup crash (#2983)
When two modules marked with MustDedup are not deduped with each other,
but they are deduped with something else, we end up trying to compare
the body of a module which was deleted.  This change makes us look up
the module they were actually deduped with to compare the bodies.
2022-04-27 00:11:09 -07:00
Prithayan Barua cdf32d1bc4
[FIRRTL] Make GroupID memory attribute unsigned. NFC (#2975)
Make the GroupID memory attribute as unsigned int, instead of signed.
It is being used to distinguish memories that should not be Deduped.
There are two passes currently updating the GroupID:
PrefixModules pass assigns unique id for each prefix.
CreateSifiveMetadata pass assigns unique id for each memory under
the testharness hierarchy.
This change ensures consistent assumptions and a convention.
2022-04-26 22:18:23 -07:00
Andrew Lenharth 24fd17d0c9
Cmdline flags to deal with subcircuit (#2981)
Cmdline flags to deal with subcircuit.  subcircuits need to print xmrs relative to the DUT, which they don't know due to their separate compilation.  The toplevel module might also have been prefixed.  This is all less than ideal, but the mechanism is expected to be removed from Chisel soon, so this is a stopgap.
2022-04-26 23:16:43 -05:00
Prithayan Barua 0cc96e4804
[FIRRTL] Do not dedup testharness memory (#2977)
This change ensures the testharness memories are not deduped, 
irrespective of the GroupID assigned to them.
It ignores the GroupID assigned to a testharness memory by PrefixModules
 pass, which is currently the only pass that assigns the GroupID.
2022-04-26 20:49:37 -07:00
Schuyler Eldridge 57f5199950 [FIRRTL] GCT-SM Generate Wires for Forced Inputs
Fix a bug in Grand Central (GCT) Signal Mappings (SM) where a forced
input would unintentionally cause more than just the port to be forced.
SystemVerilog force semantics drive the entire net when a port is
forced.  Because CIRCT does not generate a dedicated wire for each
instantiated port (like the Scala-based FIRRTL Compiler does), this can
cause the force to be more broadly applied than the Chisel user intends.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-04-26 20:44:20 -04:00
Schuyler Eldridge 0734850cbf [FIRRTL] Erase GCT-SM Source Drivers
In Grand Central (GCT) Signal Mappings (SM), erase all connects that
drive sources.  The Chisel-level GCT API had been modified to emit
sources as invalidated wires to work around CIRCT running GCT passes
after ExpandWhens (which is when initialization checking happens).
Without removing these drivers, the final circuit winds up with multiple
drivers to the same net type which most simulators will interpret as
"x".

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-04-26 20:44:20 -04:00
Andrew Lenharth 7b7aa2db77 Force expressions to be inlined and not spilled when the names get long 2022-04-26 20:44:20 -04:00
Schuyler Eldridge 0667f2cc07 [FIRRTL] Emit SiFive JSON from GCT Signal Mappings
Update the Grand Central (GCT) Signal Mappings pass to emit SiFive test
configuration JSON.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-04-26 20:44:20 -04:00
Schuyler Eldridge f9bd45ad0d [FIRRTL] Add emitJSON attribute for GCT-SM
Add an attribute to the FIRRTL Circuit-level Grand Central (GCT) Signal
Mappings (SM) annotation to indicate if JSON should be emitted during
the GCT-SM pass.  This effectively encodes if firtool is compiling a
subcircuit (JSON needs to be emitted) vs. firtool is compiling the main
circuit (JSON should not be emitted).

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-04-26 20:44:20 -04:00
Hideto Ueno 4ad617f651
[reduce] Add NodeSymbolRemover reduction (#2965)
This commit adds a new reduction named NodeSymbolRemover to
remove symbols on node operations. This reduction is intended to
clean up symbols created by name preservation.
2022-04-26 21:11:00 +09:00
Hideto Ueno 82cc2bca85
[ExportVerilog] Add a mechanism to control location info emission style (#2952)
This commit adds `LocationInfoStyle` enum to control location info
in output verilog. Specifically we want to distinguish location information
from normal comments more clearly. As one implemention, `WrapInAtSquareBracket`
option is added to emit location information wrapped in `@[` and `]`
such as:
```
assign .. ;	// @[perf/regress/AddNot.fir:3:10, :7:{10,17}]
```
2022-04-26 18:54:46 +09:00
Hideto Ueno e304863e45
[ExportVerilog] Fix an iterator update bug (#2964)
This fixes a bug introduced by 286c483. An iterator is mistakenly incremented in certain execution. Since opIterator is incremented in the beginning of the loop,
we are not actually processing next operations. This causes an assertion failure
on ExportVerilog in internal designs.
2022-04-26 18:14:32 +09:00
Prithayan Barua 0926c4abb6
[FIRRTL] Do not dedup testharness memories (#2968)
This commit adds a unique groupID to each Testharness memory to prevent their
Dedup. This is a temporary fix to match the SFC behavior.
For any memory under the Testharness hierarchy, assign a unique groupID to it.
This pass uses the max unsigned integer to generate the groupIDs, the assumption
being that, it will never conflict with an existing groupID. The groupID will ensure
 that they are not deduped.

Note: Currently, the memory dedup happens during the metadata emission, because
 that is the first pass that requires the name of the final memory module. The plan
is to create a new Memory lowering pass, and move all the memory transformations to it.
2022-04-25 20:47:47 -07:00
Mike Urbach 1c0d5ac1df
[Calyx] Add WireLibOp to represent a wire in Calyx's core library. (#2956)
This is a core Calyx primitive, and semantically is roughly the same
as sv.wire. Add support for it as a UnaryLibraryOp.
2022-04-22 23:42:44 -06:00
Mike Urbach 92e0f93e1a
[Calyx] Update MultPipeOp and DivPipeOp format to round-trip. (#2954)
This aligns the textual IR format, the emitter, and any locations
these ops were constructed in code to the result order defined by the
native  Calyx compiler. This is required for these ops to be able to
round-trip through the native compiler.
2022-04-22 23:39:51 -06:00
Schuyler Eldridge 2c30555318
[FIRRTL] Make GCT Sig. Map. a CircuitOp Pass, NFC
Change the Grand Central (GCT) Signal Mappings pass to be a pass that
operates on the whole FIRRTL circuit instead of on a module.  Continue
to keep its parallel execution behavior.  This is done in preparation
for modifications to the pass to support emission of a JSON structure
necessary for SiFive tooling which requires full-circuit information.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-04-22 11:46:32 -04:00
Hideto Ueno 9fa5ff7e04
[FIRRTL] [CheckCombCycle] Print a cycle while dumping signal names (#2942)
This commit adds `print-simple-cycle` option to print a simple cycle.
With that option, CheckCombCycle pass prints signal names contained
in a cycle (in the order of a cycle path) instead of dumping all
operations in the scc. It is useful for chisel users to debug their
chisel code since the cycle is actually a counterexample. Previous
error message (i.e. dumping all operations in SCC) is intentionally
kept to test the cycle dectection algorithm.
2022-04-22 15:10:09 +09:00
Schuyler Eldridge 5f6826b771
[FIRRTL] Grand Central Testharness Fixes (#2864)
Fix Grand Central to properly handle views/interfaces that are
instantiated in the test harness and not in the DUT.  Specifically,
interfaces and companions are not extracted via binds if they are only
instantiated in the testharness (and a DUT is known via a
MarkDUTAnnotation).

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-04-21 19:16:31 -05:00
Mike Urbach 3f041a87e5
[SV] Allow sv.wire in any non-procedural region. (#2949)
The previous verifier required sv.wire to exist in the top-level body
of a hw.module. This relaxes the verifier to allow wires in any
non-procedural region, which the NonProceduralOp trait already
guaranteed for sv.wire.
2022-04-21 16:00:08 -06:00
Schuyler Eldridge 15b970f4b7
[FIRRTL] Drop GCT Signal Mapping 0-width targets (#2947)
Fix a bug in Grand Central (GCT) signal mappings where a 0-width target
would crash compilation when either compiling the main circuit or the
subcircuit.  Avoid the issue entirely by dropping targets with a zero
width inside the GCT signal mappings pass.  If a module is exclusively
driving zero-width targets, then don't generate an empty mappings
module.

This is done to work around an issue with some SiFive designs where this
pattern is used.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-04-21 17:26:51 -04:00
Andrew Young 4cf7bc9a30
[FIRRTL][ModuleInliner] Don't prefix memory names (#2932)
A memory operation has a name attribute which is used for both the name
of the generated module and all instances of that module.  The
ModuleInliner pass is supposed to prefix the name of instance but not
the name of the module.  This change stops prefixing the memory, which
corrects the name of the module, but gives the incorrect instance name.
The assumption here is that its more important to get the name of the
memory module correct than the instance.
2022-04-21 10:28:55 -07:00
Nandor Licker e4cebcf54c
[Comb] Removed range merging (#2943)
Due to the semantics of 'x' values, range merging is incorrect and it is hereby banished from the Comb dialect.
2022-04-21 19:11:44 +03:00
Prithayan Barua de9b60af9d
[FIRRTL] Handle zero bit Memory data fields (#2931)
Handle zero bit memory data fields correctly when flattening aggregate memory data.
This commit ignores the zero bit data field, and also the corresponding mask bit.
Fixes #2926
2022-04-20 21:29:22 -07:00
Hideto Ueno 4e98c0477c
[SV] Add custom parser for case op (#2930)
This is a follow-up to #2913 to implement custom parser for case op. Also DefaultValuedAttr is used instead of OptionalValuedAttr.
2022-04-21 12:47:23 +09:00
Schuyler Eldridge 892e3f5e43
[FIRRTL] Delete GCT taps that have no ports (#2934)
Fix a bug in the GrandCentralTaps pass where a data tap module that had
no ports would result in external module instantiations in the final
design that had no corresponding implementation.  Change the
GrandCentralTaps pass to delete these modules and their instantiations.
This can arise more frequently due to a recent change to the Grand
Central Chisel API where zero-width taps are now allowed in the API,
generate a tap module, but generate no actual taps.

An alternative implementation would be to generate empty modules which
are cleaned up later.  This seemed wasteful.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-04-20 19:34:25 -04:00
John Demme 5d9b1a4e64
Update LLVM submodule (#2928)
Updating to 6b0bed7ea563624622c3c1fb1a3c90cd32c78db6.
2022-04-20 16:25:01 -07:00
Morten Borup Petersen 7e6cfbf8bc
[HW] Add a parametric `hw.module` instance specialization pass (#2882)
This commit introduces the `-hw-specialize` pass. Any `hw.instance` operation instantiating a parametric `hw.module` will trigger a specialization procedure which resolves all parametric types and values within the module based on the set of provided parameters to the `hw.instance` operation. This specialized module is created as a new `hw.module` and the referring `hw.instance` operation is rewritten to instantiate the newly specialized module.

The intention of this is to have a path for:
1. Writing generic modules ->
2. Specialize module instances ->
3. module inlining ->
4. inline optimization
2022-04-20 18:17:55 +02:00
Andrew Young e6a54c92e2
[FIRParser] Fix partial connect expansion with analog in bundles (#2925)
When the LHS and RHS of a partial connect were the same types, we would
just emit a regular connect.  We forgot to check if there were any
analog types inside the bundle When this is the case, we have to recurse
on the bundle elements and attach the analog fields together.
2022-04-19 14:47:18 -07:00
Andrew Lenharth 28f3193971
Move "ifdef synthesis" outside always block in firrtl lowering (#2922)
Don't generate always blocks with ifdef in them for side effecting operations, generate ifdef with always in them.  This reduces preprocessing work during synthesis and allows merging only verif op's always blocks.
2022-04-19 15:26:19 -05:00
Hideto Ueno 3a7382eacd
[SV] Canonicalize empty IfDefProcedural op (#2924)
This PR implements trivial canonicalization to erase empty ifdefprocedural op.
2022-04-20 05:16:27 +09:00
Hideto Ueno a8e4f864c6
[ExportVerilog] Add emitReplicatedOpsToHeader option (#2889)
This commit adds a new lowering option emitReplicatedOpsToHeader
to create a header file which stores replicated ops.

Currently, this PR creates circt_header.svh under the output
directory and users are expected to manually register the header to their
include paths.
2022-04-19 09:49:00 +09:00
Schuyler Eldridge 4c2f0c42d9
[SV] Skip extraction of bound instances (#2911)
Change Extract Test Code (ETC) behavior to not perform extraction if the
module is already going to be otherwise extracted via a bind.  This
fixes an issue where certain simulators are unhappy if you bind into a
bound instance.

Fixes #2910.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-04-18 18:36:01 -04:00
Schuyler Eldridge a27cb38605
[FIRRTL] Remove Unused Instance Ports (#2852)
Extend FIRRTL's RemoveUnusedPorts pass to also remove ports when a port
is never used by any instantiation.  While seemingly uncommon, this can
happen frequently for certain Chisel utility modules which have
auxiliary ports which are very rarely used, e.g., for Queues or
Arbiters.

Fixes #2850.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-04-18 17:09:49 -04:00
Andrew Young 7abe1d26ba
[FIRRTL][Dedup] enhance error messages for dedup failures (#2887)
A user can add an annotation "MustDedup" which lists modules which they
expect to dedup, and emits an error message when that fails. The error
message produced by a dedup failure doesn't give any hint as to why
deduplication failed. This can be very annoying to debug, and usually
involves diffing the FIRRTL IR modules.

This change adds a diagnostic comparison of two modules, looking for the
first difference between them which would have blocked deduplication.
This comparison ignores differences in port names and bundle element
names the same way that the structural hasher does.

This approach is still not super useful when trying to debug
deduplication failures: it will print the first difference found in the
modules and then bails out. This can help with simple things like when a
wire has a different type and you can easily map it back to the original
Chisel code. For differences in complicated logic, it can be challenging
to map it back to the chisel code and even harder to figure out why
these were emitted differently.
2022-04-18 12:47:18 -07:00
Schuyler Eldridge 543ee9fb14
[SV] Fix HWMemSimImpl Bad Randomization Verilog (#2906)
Fix a bug in the verbatim Verilog created by HWMemSimImpl for
randomizing memories.  This previously relied on an invalid Verilog
construct (bit select out of a concatenation).  This is changed to be
legal by using a temporary register for memory initialization.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-04-18 15:05:31 -04:00
Hideto Ueno 0bf6f27912
[SV] Add `unique`, `priority` constructs for case op (#2913)
This commit supports unique, unique0 and priority constructs for case op. Users can specify them by adding validationQualifier attribute to case op.

Example: 
```mlir
hw.module @Foo(%cond: i1) {
  %fd = hw.constant 0 : i32
  sv.initial {
     sv.case %cond : i1 {validationQualifier = #sv<"validation_qualifier priority">}
     default: {
       sv.fwrite %fd, "zero"
   }
  }
  hw.output
 }
```
```verilog
module Foo(
  input cond);

  initial begin
    priority case (cond)
      default:
        $fwrite(32'h0, "zero");
    endcase
  end // initial
endmodule
```

Close https://github.com/llvm/circt/issues/2907
2022-04-19 02:27:33 +09:00
Prithayan Barua 51220b0acb
[FIRRTL] Set the GroupID at InferReadWrite pass. (#2917)
Set the GroupID for MemOp in InferReadWrite pass.
It was not being set properly after commit 3c6d90d.
2022-04-18 09:13:55 -07:00
Nandor Licker e0fd4846c6 [NFC][HV][SV] Removed HWMemSimImpl from --ir-hw output 2022-04-18 14:43:09 +03:00
Schuyler Eldridge 7ce00e745e
Whitespace cleanup, NFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-04-16 16:58:07 -04:00
Schuyler Eldridge 230c1955f4
Whitespace cleanup, NFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-04-15 19:38:50 -04:00
Richard Xia 9127a771d2
Update LLVM to 1aa4f0bb (#2901)
* [Conversions][Transforms] Add missing includes due to refactoring in upstream MLIR.

LLVM commit 36d3efea15e6202edd64b05de38d8379e2baddb2 removed a few
include statements from mlir/Pass/Pass.h, so we have to update a few of
the files here to add back in some includes.

* [Handshake][SV] Migrate from StrEnumAttr to EnumAttr.

StrEnumAttr was removed in upstream LLVM commit
60e34f8dddb4a3ae5b82e8d55728c021126c4af8. It has been replaced with
EnumAttr, which can do everything that StrEnumAttr could do but more
efficiently.

This affected two specific attributes: Handshake's BufferType, and SV's
ModportDirectionAttr. Both have been converted over to EnumAttrs. Their
parsers had to be updated, since the new EnumAttr no longer likes having
double quotes around the enum value in the assembly format.
Consequently, the tests were also updated.

* Bump llvm to 1aa4f0bb6cc21b7666718f5534c88d03152ddfb1.
2022-04-15 16:07:46 -07:00
Nandor Licker abe722fe5a
[firtool] Add --ir-sv flag (#2902)
Added a separate flag to dump the IR with `sv` ops, replacing `--ir-hw`.
From this point onwards, `--ir-hw` will dump IR in HW form, while `--ir-sv`
will include constructs (such as registers) expanded into SytemVerilog form.
2022-04-15 22:07:18 +03:00
Prithayan Barua 3c6d90d1e6
[FIRRTL] Donot dedup memories with unique Prefix (#2893)
Add an attribute to memory, to prevent memories with different prefix from
 getting deduped. The `PrefixModules` pass can prefix the name for a `MemOp`.
 This prefix should not be ignored when memories with same properties are
 deduped later (during Metadata emission or LowerToHW).

This commit adds the optional `groupID` attribute to the `MemOp`, such that
 it should also be considered when merging all the memories.
2022-04-14 20:18:49 -07:00
Hideto Ueno e83ec4d1de
[FIRRTL][CheckCombCycles] Use FConnectLike (#2896)
This commit replaces ConnectOp with FConnectLike with CheckCombCycles to handle StrictConnectOo as well.
2022-04-15 03:07:45 +09:00
Prithayan Barua 5e014cf27c
[FIRRTL] Fix RetimeModule Annotation. (#2897)
This commit fixes the annotation used to specify the modules that need
 Retiming, it was incorrect earlier. 
Also rename the filename annotation variable to avoid confusion.
And update the doc and lit tests with the correct annotation.
2022-04-14 11:01:51 -07:00
Hideto Ueno f384e24d33
[RemoveInvalid] Support Aggregate (#2891)
* [RemoveInvalid] Support Aggregate

This is a follow-up of cb5d0279 to replace aggregate invalid values
with zero constant.
2022-04-14 20:32:29 +09:00
Richard Xia 654d5e96c8
Update LLVM to 3d4ca8a8c (#2886)
* [FIRRTL][Dedup] Fix hash() to work with new SHA256.final() return type.

This follows the commit in upstream llvm,
330268ba346b679af786879d8f696c8c412a40eb, which changed SHA256.final()
to return a std::array<uint8_t, 32> instead of a StringRef. Although it
would be nice to directly use the SHA digest bytes as the hash key,
DenseMap does not have an implementation of DenseMapInfo for
std::array<uint8_t, N>, so it's easier to continue converting this to a
string for now.

* [LLHD][SCFToCalyx] Update getSuccessorOperands() to match upstream MLIR.

Commit 0c789db541c236abf47265331a2f2b0945aa7b93 in upstream llvm changed
BranchOpInterface's interfaces for getting successor operands.
It removed getMutableSuccessorOperands() and it changed
getSuccessorOperands() to return a new SuccessorOperands object instead
of an Optional<OperandRange>.

This affected LLHD's WaitOp, which implements the BranchOpInterface, and
SCFToCalyx, which calls some of the methods on BranchOpInterface.

For llhd::WaitOp, we now implement getSuccessorOperands() instead of
getMutableSuccessorOperands(), with the appropriate return type.

For SCFToCalyx, we now always work with a non-Optional SuccessorOperands
object, which required updating a few of the usages to not call Optional
methods.

* [Analysis][Scheduling] Explicitly set TypeID for test passes in anonymous namespaces.

This matches upstream LLVM commit
5e50dd048e3a20cde5da5d7a754dfee775ef35d6, where types defined in
anonymous namespaces are no longer allowed to have implicit TypeIDs.
This mostly only affects test passes.

* Bump llvm to 3d4ca8a8c39f772dd6c022220a6eef23238a77f6.

* [LLHD] Mark probeCSE test with XFAIL.

This test started failing after an LLVM submodule update. It is possibly
related to upstream LLVM commit
02da9643506dee4a82353e0f911513279634d846, which changes the behavior of
the upstream MLIR CSE pass to be able to optimize the case where there
are side effectful reads without an intermediate side effectful write.
This test case is now CSE'ing the `llhd.prb` ops into a single op and
returning both copies of it.
2022-04-13 15:11:04 -07:00
Schuyler Eldridge cb5d02799c [FIRRTL] Squash Invalids in RemoveInvalid
Extend the RemoveInvalid pass (formerly RemoveResets) to convert all
invalid values to zero.  This is done to apply the "invalid is zero"
interpretation after all other invalid interpretations have been
resolved.  This replaces logic where this interpretation was
incompletely applied during canonicalization after RemoveResets.

Fixes #2782.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-04-12 18:15:17 -04:00
Schuyler Eldridge c61f6ef69e
[FIRRTL] mv RemoveResets RemoveInvalid, NFC
Change the name of FIRRTL Dialect's RemoveResets pass to RemoveInvalid.
This is done in preparation to add functionality to RemoveResets to
remove all invalid values after it removes resets.  In effect, this pass
is now an "invalid removal" pass.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2022-04-12 18:04:09 -04:00