Commit Graph

262 Commits

Author SHA1 Message Date
Hideto Ueno 1a404d6056
[SV] Add DPI import op (#7005)
This PR adds an op `sv.func.dpi.import` for "emitting" DPI import statement. `sv.func.dpi.import` doesn't declare function but it takes a function symbol to emit import statement. This design is similar to what `sv.macro.ref/def` does and it enables us to decouple function declaration and emission. 

```
// CHECK-LABEL: import "DPI-C" linkage_name = function void function_declare1(
// CHECK-NEXT:    input [1:0] in_0,
// CHECK-NEXT:                out_0,
// CHECK-NEXT:                in_1,
// CHECK-NEXT:    output out_1
// CHECK-NEXT: );
sv.func.dpi.import linkage "linkage_name" @function_declare1
```
2024-05-16 18:53:46 +09:00
Hideto Ueno bd259e788a
[SV] Add sv.func, sv.return and sv.func.call operations (#7003)
This PR adds function call constructs (sv.func, sv.return and sv.func.call) to SV dialect. 

* `sv.func` -- this op is between hw.module and func.func. This op implement interfaces `PortList`, `HWModuleLike` and `FunctionOpInterface`. Similar to hw.module, we can preserve argument names and mix the order of input and output arguments. Following func.func empty body indicates that the op is a declaration. Currently sv/func is defined as "automatic" function in SV.
* `sv.return` -- terminator for sv.func. We cannot reuse neither hw.output nor func.func since they have constraints on parent op(and I think it's not reasonable to loose them). 
* `sv.func.call` and `sv.func.call.procedural`. Two operations are added because output arguments cannot be used non-procedural regions.
2024-05-16 16:52:38 +09:00
Schuyler Eldridge 08fb99b930
[SV][Verif] Extract verif ops in SVExtractTestCode (#6865)
Fix a bug where SVExtractTestCode was not extracting asserts, assumes, and
covers from the verif dialect.  This resulted in unexpected end-to-end
"failures" from Chisel where Chisel asserts, assumes, and covers were not
extracted and left in the design.

Fixes #6864.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-03-24 00:54:24 -04:00
Will Dietz b8333b5e10
Fix a few FileCheck directive typos. (#6853) 2024-03-19 17:46:44 -05:00
Nandor Licker 6d40b286c2
[Emit] Copy fragments into modules created by ExtractTestCode (#6843) 2024-03-18 16:32:24 +02:00
Nandor Licker e8d919f3ef
[SV] Verify macro reference symbols (#6780) 2024-03-04 17:51:24 +02:00
Nandor Licker 156702db11 [NFC][SV] Declare macros in most SV tests 2024-03-04 04:13:01 -08:00
Nandor Licker a956b8b77e
[SV] Use a symbol in macro identifiers (#6777)
Macro identifiers now use a proper symbol to handle references.
The verifiers are not yet enabled as more intrusive pipeline changes are required, to be done in follow-ups.
2024-03-04 13:12:27 +02:00
Hideto Ueno f2ce415812
[SVExtractTestCode] Privatize generated modules (#6519)
Modules generated by ETC are currently marked as public but it should be private. This change allows the compiler to freely rename and reorder ports or names on them.
2023-12-13 23:04:41 +09:00
Nandor Licker 53cf75911a
[Seq] Move the HWMemSimImpl pass to seq (#6409)
The pass relies on `seq` items, creating a circular dependency between SV and Seq.
It better belongs to the seq dialect, alongside options and ops it related to.
Moving forward, this should be merged into FIR memory lowerings.
2023-11-13 11:19:21 +02:00
Jake Taylor 97c770c095
[HWLegalizeModules] Lower types-like packed array handling (#5355) (#6402)
This PR refactors HWLegalizeModules to something more like existing lower types passes in order to support more complex patterns such as array concatenations. Several new tests are also added.

Fix https://github.com/llvm/circt/issues/5355.
2023-11-11 03:04:19 +09:00
Andrew Lenharth 12d168633c
[HW] round trip ModuleType non-ssa values (#6287)
Treat blockargs like other values and let the asm name hint interface compute names for them. If the port name is a legal ssa name, it will be used, otherwise the legalization will compute a new name based on the port name. This has stable round-tripping after the first round, which is consistent with other ops which provide ssa name hints.
2023-10-13 14:25:00 -07:00
Prithayan Barua cbe82b9674
[ExtractTestCode] Use non-empty unqiue port names (#6283)
Update ETC to add non-empty and unique port names.

---------

Co-authored-by: Nandor Licker <n@ndor.email>
2023-10-12 07:21:03 -07:00
Hideto Ueno 080f275376
[Namespace] Return an empty string for empty string. (#6284)
Previously Namespace::newName could return empty string for empty string.
This is a problematic behaivor since primary use cases of Namespace is
symbol generation but empty string cannot be used a symbol.

For example HWExportModuleHierarchy crashed with an instance with an
empty name.

This commit fixes the issue by pre-registering empty string in a constructor of
Namespace.
2023-10-12 05:25:56 +09:00
Andrew Lenharth 164dbaf9cd
[HW] Change printer for modules (#6205)
This is quite invasive.  This converts from the functiontype printer to the moduletype printer.

---------

Co-authored-by: Mike Urbach <mikeurbach@gmail.com>
2023-09-28 16:30:15 -05:00
Schuyler Eldridge 1698632b81 [SV][HW] Stable port order in SVExtractTestCode
Change the BFS of operations used to compute backwards slices in
SVExtractTestCode to, instead, use a DFS of operands.  This ensures that
any intermediary operations which may show up do not cause the ports of
extracted modules to change.

This was triggered by addition of the `seq.from_clock` operation to cause
the BFS discovery order of roots to change.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-09-08 10:10:29 -07:00
Nandor Licker 4d379d7cc5
[FIRRTL][Seq] Lower `firrtl.clock` to `seq.clock` (#6055) 2023-09-07 01:11:35 +03:00
Morten Borup Petersen 1d6fa4813b
[SV] Fix --hw-eliminate-inout-ports (#6037)
Fixes a bug where an inout input was being eliminated which resulted in the block argument list shifting, but input->output replacements were not being updated correctly.

Fixed by keeping to-be-output values as temporary operations instead of an in-memory array of values. By doing so, any value replacements performed by other patterns will also affect the temporary output operations.
... that pattern should maybe be factored out and given a name - seems like a generic thing where we want to store a value for later use, but that value may be replaced at any point in time.
2023-09-06 10:56:07 +02:00
Morten Borup Petersen 63aab570d6
[SV] Add suffix options to --hw-eliminate-inout-ports (#5925) 2023-08-24 11:19:59 +02:00
Andrew Lenharth 5e187e6d68 [NFC] Move more code from FunctionOpInterface. Also remove invalid test. 2023-08-23 10:18:56 -05:00
Mike Urbach bde0bb99d7
Bump LLVM to dd115e5a9bc7
This bumps llvm.  There is an upstream bug which affects DC.join.  Some folders and tests are disabled due to this.

---------

Co-authored-by: Andrew Young <youngar17@gmail.com>
Co-authored-by: Andrew Lenharth <andrew@lenharth.org>
2023-08-04 12:46:45 -05:00
Hideto Ueno 344a5ac8fc
[SVExtractTestCode] Inline input only modules even when no operation is extracted (#5771)
Currently we only inline input only modulse when op is extracted.
However if a module only contains input only modules there might
be no extraction and hence we might end up having input only modules.
2023-08-04 01:07:30 +09:00
Will Dietz cafcb146a8 [NFC] Fix missing colon after FileCheck directives. 2023-07-28 12:30:01 -05:00
Schuyler Eldridge 02157b2879
[HW] Consistent HWMemSimImpl ignore-read-enable
Fix an inconsistency between the handling of read ports and read-write
ports when running HWMemSimImpl with the "ignore-read-enable"
option (firtool option "-ignore-read-enable-mem").  After #5700, this
would cause the enable line of a read-write read port to have no effect.
I.e., the memory would always read even if not enabled.  Change this to
align with the behavior of read ports where the memory always returns the
last read address.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-07-27 17:23:15 -04:00
Nandor Licker 636d4a4240
[HWMemSimImpl] Fix RW port enable gating (#5700)
Co-authored-by: Nandor Licker <nandorl@sifive.com>
2023-07-27 18:50:31 +03:00
Hideto Ueno feebfdce84
[SVExtractTestCode] Fix a bug that instance inlining doesn't update inner symbols and clone sv.bind (#5679)
Close https://github.com/llvm/circt/issues/5665. This commit fixes a bug that
bound instances are accidentally erased. When inlining input only modules it's necessary
to clone bind statements for bound instances in the module. Previously single bind op is shared by multiple instances, as a result ExportVerilog only emits a bind statement for one of them.
2023-07-26 16:18:17 +09:00
Will Dietz c70c8dce0d
[SV] Add constraint and test rejecting subst w/o message (#5666)
Split from #4502.
2023-07-24 10:25:53 -05:00
Morten Borup Petersen 0e47744834
[HW/SV] Add `hw.inout` elimination pass (#5390)
Adds a pass which analyses the module hierarchy to eliminate `inout` ports in favor of:
1. poking holes through the module hierarchy (explicit in/output ports)
2. raising `sv.assign`/`sv.read_inout` operations to the definition point of the `hw.inout` value.

This is unarbited, and only allows for multiple-readers, single-writer scenarios. Currently only supports `sv.assign`, as well as `hw.inout` input ports.
2023-07-12 10:44:29 +02:00
Schuyler Eldridge 4740516f57
[SV] Cleanup HWExportModuleHierarchyPass
Cleanup the `HWExportModuleHierarchyPass` pass in the following ways:

  1. Do not emit JSON directly, but rely use `sv.verbatim` operations with
  substitutions.

  2. Move `HWExportModuleHierarchyPass` before `ExportVerilog` (again).
  Given that (1) is happening, this must happen.  Both (1) and (2)
  effectively undo the work in #1931.

  3. Use a `hw::ModuleNamespace` to ensure unique symbols are created for
  substitutions.  This motivated some refactoring of the
  `HWExportModuleHierarchyPass` from a `struct` to a `class` since it now
  has private members. (This aligns with LLVM coding guidelines.)

  4. Update existing tests to expect the new `sv.verbatim` JSON.

  5. Add a new `firtool` end-to-end test baed on #5478.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-06-27 17:40:45 -04:00
Schuyler Eldridge 36fc9b3d65
[SV] Use hw.verilogName in hierarchy emission
Change HWExportModuleHierarchy to use the optional "hw.verilogName" of an
instance as opposed to blindly using the instance name.  The latter may be
wrong if the former is set.

Fixes #5478.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-06-26 14:40:26 -04:00
Hideto Ueno 24cf2f22e9
[ETC] Use name/namehint as a port name (#5464)
Fix #5459. Use namehints and name attributes on module boundary as port names of extracted modules. Also improve instance op logic a bit to avoid unnecessary linear search.
2023-06-23 18:53:25 +09:00
Hideto Ueno ff159a901c
[SVExtractTestCode] Clone constants even when used by designs as well (#5466)
Fix #5465. This fixes an issue that constants used by both designs and testcode.
2023-06-23 18:52:49 +09:00
Hideto Ueno eb53062968
[ETC] Don't erase operations used by dead module instances #5357
Fix #5356. There is an edge case that ETC wrongly erase an extracted operation which is still used by (dead) module instances. This issue can be fixed by appropriately updating opsToErase based on opsAiive. inlineInputOnly is reordered since it depends on opsToErase.
2023-06-12 02:46:55 +09:00
Hideto Ueno 0a67d92405
[ETC] Extract registers and instances if not in design (#5331)
This commit extends ETC to extract registers. 
In order to enable the same generic logic to extract registers, the
pass has been moved earlier in the firtool pipeline, so it can work at
the seq.firreg level of abstraction, which behaves just like an
instance. As firreg registers introduce cycles in dataflow by nature, this commit 
changes extraction mechanism so that we can find and extract maximum subset 
of testcode. Previously we were tracking dataflow until it reaches least fixedpoint 
of verification parts, but instead we can first compute least fixedpoint of design 
parts and subtract it from entire modules. 
---------

Co-authored-by: Mike Urbach <mikeurbach@gmail.com>
2023-06-08 18:11:21 +09:00
Hideto Ueno e780e3e714
[HWCleanUp] Remove always_comb (#5175)
It's illegal to merge different always_comb in general as it might implicitly 
have data dependency each other. Fix #5171
2023-05-24 01:19:59 +09:00
Nandor Licker c7100bed69
[HW][SV] Allow control of initial blocks setting memories (#5237)
Added a separate macro to bypass synthesis and enable initial blocks setting memories lowered through `HWMemSimImpl`.

Co-authored-by: Nandor Licker <nandorl@sifive.com>
2023-05-22 08:45:32 +03:00
Nandor Licker b60dee9849
[SV] Add lowering option to emit separate always blocks (#5211) 2023-05-17 21:48:01 +03:00
Andrew Lenharth 39ffcf81d8
[SV] Macro definitions and declarations with arguments (#5149)
This adds a macro.decl to declare the existance and arguments of a macro.
This adds a macro.def to define a macro body.

Since macros can be defined multiple times, I separate the declaration of a macro from the definitions.

Update firrtl to use the new ops instead of verbatim.

By their nature macros cannot always know the type of the result of their use, so we leave it to each call site to declare what this is, which is not a change from the exisiting code.
2023-05-10 11:03:44 -05:00
Mike Urbach 4eda457b51
[ETC] Don't relocate instances that were only in extracted test code. (#5064)
These don't actually belong in the testbench directory; they are still
part of the design. So for now, simply leave them in the directory
they were initially declared.
2023-04-21 12:29:18 -07:00
Fabian Schuiki db9f7c4c50
[Seq] Add enums for RUW/WUW behavior of memories (#5007)
The HW dialect currently defines a `WUWAttr` to capture the
write-under-write behavior of memories. FIRRTL memories also specify a
read-under-write behavior, which suggests that we also need a `RUWAttr`.
Since these attributes talk specifically about the behavior of
sequential circuit elements, it seems sensible to move them into the Seq
dialect.

This commit adds a `RUWAttr` and a `WUWAttr` enum to the Seq dialect and
updates the FIRRTL dialect and `HWMemSimImpl` lowering to work with
these new attributes. The `WUWAttr` in HW is removed.

This change is a preparation step for later adding a `seq.firmem`
operation to capture the semantics of FIRRTL memories more precisely at
the HW dialect level in Seq.

Changes to tests are related to teh new `RUWAttr` being encoded as `i32`
instead of the manual cast to `ui32` we had before.
2023-04-11 22:03:08 -07:00
Hideto Ueno 7b8f3c2a43
[SV] Introduce SV for op (#4879)
This introduces SV for operation e.g.:
```mlir
    sv.for %i = %c0_i2 to %c-1_i2 step %c1_i2 : i2 {
      %RANDOM = sv.macro.ref.se< "RANDOM"> : i32
      %index = sv.array_index_inout %_RANDOM[%i] : !hw.inout<uarray<3xi32>>, i2
      sv.bpassign %index, %RANDOM : i32
    }
```
which corresponds to:
```verilog
 for (logic [1:0] i = 2'h0; i < 2'h3; i = i + 2'h1) begin
    _RANDOM[i] = `RANDOM;
 end
```

The `sv.for` operation in System Verilog defines a for statement that requires
three SSA operands: `lowerBounds`, `upperBound`, and `step`. It functions
similarly to `scf.for`, where the loop iterates the induction variable from
`lowerBound` to `upperBound` with a step size of `step`, i.e:

```
 for (logic ... indVar = lowerBound; indVar < upperBound; indVar += step) begin
  end
```

It's important to note that since we are using a bit precise type instead of a Verilog
`integer` type, users must be cautious about potential overflow. For example, if
you wish to iterate over all 2-bit values, you must use a 3-bit value as the
induction variable type.
2023-04-10 14:52:18 +09:00
Mike Urbach 3dcf278d9b
[ETC] Enhance instance extraction to extract dependent instances. (#4910)
We previously extracted instances that only feed the test code. This
change enhances that logic to also extract instances that may feed
other instances, which transitively only feed the test code. This also
works for instances that potentially feed each other, cyclicly, and
otherwise only feed the test code.
2023-04-03 20:09:42 -06:00
Nandor Licker db3ebecda4
[HWMemSimSimpl] Add rw_addr_collision = yes to memories with registered read addresses (#4852)
If the read latency is 1, Vivado issues a warning since the behaviour under a collision
is undefined. This change forces write_first behaviour by adding the appropriate annotation.

Co-authored-by: Nandor Licker <nandorl@sifive.com>
2023-03-20 09:45:31 +02:00
Fabian Schuiki d6133c44d1
[Support] Add `ImplicitSSAName` directive for string attributes (#4821)
Move the `{parse,print}ImplicitSSAName` directive currently used by the
SystemC dialect into the support library and make the SV dialect use it
as well. This directive works on a `StringAttr` instead of the entire
attribute dictionary of the operation, which has a few advantages:

- Name is an explicit ODS attribute on the operation
- Name gets automatically elided in attr-dict printing (TableGen elides
  all ODS-defined attributes)
- The fact that the "name" attribute has a specific meaning is exposed
  in ODS more explicitly, and the assembly format makes this more
  apparent by having a dedicated `name <ATTR>` portion.

NFC besides the change in assembly format.
2023-03-15 17:02:58 -07:00
Fabian Schuiki 811f79d37a
[SV] Move emitAsComment to SVAttributeAttr; remove SVAttributesAttr (#4743)
* [SV] Move emitAsComment to SVAttributeAttr; remove SVAttributesAttr

Move the `emitAsComments` flag from `SVAttributesAttr` (plural) to
`SVAttributeAttr` (singular). Then remove `SVAttributesAttr` (plural)
since it only contains a single array field after `emitAsComments` is
gone.

Add add, remove, and read-modify-write functions to deal with SV
attributes on operations more conveniently. Also enforce deduplicated
SV attributes where easily possible. The new functions now allow for
easy addition and removal of individual SV attributes.

Adapt ExportVerilog to handle the fact that emission as comments is now
a per-attribute option. The emission code now can emit multiple
`/*...*/` and `(*...*)` groups if needed, but tries to pack as many
consecutive attributes with the same `emitAsComment` flag into one
group.

* [ExportVerilog] PP-ify SV attribute emission.

* Test pretty-printing of SV attributes on statements.

* Tweak whitespaces between SV attributes

---------

Co-authored-by: Will Dietz <will.dietz@sifive.com>
2023-03-01 14:34:54 -08:00
Will Dietz d87ebfa0f3
[SV][ETC] Name port after instance.result_name, as well. (#4640)
Fix case where port is named "" (_GEN), teach to grab name from instance.

Add test based on case found in the wild.
2023-02-08 11:32:01 -06:00
Hideto Ueno 2b612a2dcd
[HWLegalizeModules] Legalize aggregate constant (#4626)
This PR extends HWLegalizeModules to support aggregate constants. 
Also `signalPassFailure` is called when we fail to legalize expressions.


Fix https://github.com/llvm/circt/issues/4623.
2023-02-07 19:56:28 +09:00
Schuyler Eldridge b6dd1c3ecd
[HWMemSimImpl] Add Memory File Initialization
Add support to HWMemSimImpl for doing file-based memory initialization.
This comes in two flavors:

  1. Inline initialization
  2. Bind-based initialization

In (1), a ReadMemOp is used to initialize the memory from a file.
In (2), a separate module is created that initializes the memory via
ReadMemOp using an XMRRefOp.  This new module is then instantiated in
the memory module via a bind.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-02-06 23:43:39 -05:00
Schuyler Eldridge a29c037ca8
[SV] Change ReadMemOp to use SSA Value
Change the existing ReadMemOp to use an SSA Value for its destination
memory as opposed to a symbol.  This more closely models how the
operation actually works and enables the operation to be used to be used
with XMRRefOp to initialize memories that are not in the current module.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-02-03 18:15:13 -05:00
Mike Urbach d571b4c079 [SV] Fix SVExtractTestCode to not add unnecessary input values.
Don't add values to the input set if they are the result of an op we
are already going to clone. In the case of cycles, such values might
get erased as part of an instance's forward dataflow. Regardless, they
are unnecessary ports into the test code module.
2023-01-09 18:32:03 -07:00