Commit Graph

3998 Commits

Author SHA1 Message Date
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
Morten Borup Petersen f267f27d1e [Calyx] Fix crash in `GroupOp::getGoOp` before go-insertion pass has run 2022-05-10 10:33:41 +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 e856539faf [FIRRTL][LowerMemory] Add port recording helper, NFC
This simplifies the code, and makes the Module port logic more similar
to the Instance port logic. This should hopefully fix an issue MSVC had
with the initializer_list constructor used.
2022-05-09 23:11:19 -07:00
Andrew Young 5a3a724bc6 Fix narrowing conversion warning when compiling with MSVC 2022-05-09 23:11:19 -07: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 bd7bf0b3ec
[FIRRTL] Fix some passes to work with the new FMemModule (#3066)
This fixes a couple places that have the baked in assumption that there
are only 2 module types.
2022-05-09 19:37:48 -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
Hideto Ueno 0d23cbdacb
[SV] Add a builder to take a validation qualifier (#3075)
This commit adds a builder to sv::CaseOp which takes a validation qualifier as
an argument. This is separated from https://github.com/llvm/circt/pull/3024.
2022-05-09 12:34:12 +09:00
Hideto Ueno 4624efcd95 [ExportVerilog] Enable `encounteredError` when symbol name is not found, NFC
This commit replaces `op->emitError` uses with `EmitterBase::emitOpError`
so that `encounteredError` is enabled when symbol name is not found.
2022-05-09 11:52:06 +09: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
Andrew Young 09f6c0b7fb
[FIRRTL] Fix module port insertion helper (#3062)
The helper accidentally inserted the block arguments in the reverse
order that it was supposed to. This was happening because each block
argument was inserted one at a time, causing us to have to increase the
insertion index by 1 every time we insert an argument.
2022-05-07 11:26:58 -07:00
Andrew Young e5358de8ce
[FIRRTL] Add error message to AnnotationArray type constraint (#3061)
This type constraint was missing an error message, causing the error
message to be very cryptic.
2022-05-07 10:47:47 -07:00
Andrew Young 0786cd7175
[FIRRTL] formatting, NFC
clang-tidy was complaining about this one line in other PRs.  Not sure
why it didn't get filtered out.
2022-05-07 09:16:44 -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
Prithayan Barua b4ad9b98b2
[FIRRTL] Move extractInstance pass before GCT (#3060)
This commit moves the ExtractInstances pass before the GCT passes.
GCT passes can embed the instance paths into Verbatim ops, which can later be
 updated by the ExtractInstances pass, causing incorrect instance paths being
 generated into the verilog.
This commit should fix that bug with invalid instance paths.
2022-05-06 16:21:57 -07: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
Will Dietz 4dbaf1d07f
locationStyleInfo: add doc blurb, add to cl::opt help (#3056) 2022-05-06 11:45:59 -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
Hideto Ueno 047c9acac3 [LoweringOptions] Use consume_front, NFC
This commit replaces `startswith` + `drop_front` with `consume_front`.
2022-05-06 21:09:23 +09: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