Commit Graph

262 Commits

Author SHA1 Message Date
Schuyler Eldridge de45d55ffa
Whitespace cleanup in test/ and *.td, NFC
NFC whitespace cleanup of tests and ODS files involving:

  - Removal of trailing whitespace
  - Addition of newlines to end of files if not already present

(I keep running into spurious whitespace changes due to save settings in
my editor.  I'm then spending a fun amount of time doing interactive git
staging to work around this.  This is attempting to do a one-shot
cleanup to make this better.  We need a longer-term, automated solution
here, though.)

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-07-09 18:24:57 -04:00
Andrew Young fd662f991c
[PrettifyVerilog] Sink constants into the block where they are used (#1306)
This change makes the PrettifyVerilog pass duplicate constant ops into
the block where they are used. Sinking constants will allow the verilog
exporter to inline the expression instead of creating a `localparam`.
2021-06-22 13:45:31 -07:00
Andrew Lenharth 1d01aa85e6 Deal with use before def in extract test code.
Closes #1256
2021-06-11 14:21:19 -07:00
Prithayan Barua 8e5d4fb74c
[HW] Don't remove Registers if symbol present on it. (#1247)
Add a check in RegOp::canonicalize to filter sv::RegOp with symbols. Don't canonicalize registers with symbols on them.
2021-06-11 11:38:35 -07:00
Prithayan Barua 6c343b073e
[SV] Add SystemVerilog force,release statement to SV dialect. (#1239)
Add the force statement to SV dialect. force is a procedural continuous assignment statements.
A force can be applied to nets as well as to variables.

From the spec ::
A force statement to a variable shall override a procedural assignment or an assign procedural continuous
assignment to the variable until a release procedural statement is executed on the variable. When released,
then if the variable does not currently have an active assign procedural continuous assignment, the variable
shall not immediately change value. The variable shall maintain its current value until the next procedural
assignment or procedural continuous assignment to the variable. Releasing a variable that currently has an
active assign procedural continuous assignment shall immediately reestablish that assignment.

Constraints :
The left-hand side of the assignment can be a variable, a net, a constant bit-select of a vector net, a part-select of a vector net, or a concatenation. It cannot be a memory word (array reference)
or a bit-select or a part-select of a vector variable.
2021-06-11 06:20:01 -07:00
Andrew Lenharth 16bd6b7c23
[ExportVerilog] Ensure stable names (#1189)
[ExportVerilog] Ensure stable names

Name legalization is happening twice, once via a dedicated pass, again in export verilog.  This changes export verilog to not change the name of any port, wire, register, or instance durring emission, depending instead on legalize-names having done so already.  This is done by pre-populating the name table durring the prepare phase with incoming names, so that subsequent temporary names will never displace input names.
2021-06-02 17:34:08 -05:00
Andrew Lenharth 04cdf0a486
sv.bind op for encoding system verilog bind statements (#1135)
sv.bind op for encoding system verilog bind statements.  Bind is a syntax for an out-of-line instance declaration which happens logically at the end of the target module.  This form refers to an instance in the IR to do the heavy lifting.
2021-05-28 09:57:19 -05:00
Prithayan Barua 70ce6621bb
Update the Generator Callout Pass (#1038)
1. Randomly generate temporary output file name for the generator program. (Instead of taking a user specified input file name)
2. Use llvm::sys::path::filename and llvm::sys::path::parent_path to extract the executable name and program path.
3. Add emitError for cases when the genertor executable fails.
4. RTLGeneratorSchemaOp required attributes are stringAttrs, remove the dyn_cast
2021-05-19 08:34:01 -07:00
Chris Lattner ab1766c130 [HW->RTL] Rename testsuite and laggard files. 2021-05-15 14:39:11 -07:00
Chris Lattner 53b1c077d6 [RTL->HW] Rename C++ namespace, command line flags and a bunch of other stuff. 2021-05-15 14:33:45 -07:00
Chris Lattner e31e8a3e3d [RTL->HW] Rename the rtl dialect to hw dialect in MLIR syntax. 2021-05-15 14:24:43 -07:00
Andrew Lenharth e117ac01bd
Attach symbols to instances, wires, and regs. (#1044)
Attach symbols to instances, wires, and regs.

Wires, instances, and registers define externally visible names in verilog.  Model this with optional symbols for those which are public.

Update the rational doc with notes on symbols and visibility.
2021-05-13 10:59:29 -05:00
Chris Lattner 64b3c0347d [RTLMemSimImpl] Tidy up a few things.
This changes the generated modules to be at the same point in the MLIR module
as their generator nodes were, instead of forcing them to the bottom.  This
just makes the IR more controllable from the frontend.  This is the cause of
the testcase update.
2021-05-08 16:00:20 -07:00
Chris Lattner 21d00968cf [PrettifyVerilog] Add a new pass to improve quality of ExportVerilog.
We want ExportVerilog to be self contained and as simple as we can get
away with, which means we need a separate pass to handle elective
cleanups that don't effect correctness.  This pass starts by addressing
a simple pet peeve of mine with unary operators.
2021-05-05 10:31:24 -07:00
Andrew Lenharth 2e11065461
[VerilogQuality] Remove muxes feeding registers their old value (#965)
When a mux feeds an assign to a register and one branch of the mux is the register's old value, we can turn that into a conditional assign. This results in much cleaner verilog output.
2021-04-27 10:43:52 -05:00
Chris Lattner 00b068f2a4 Switch firtool and the testsuite to SimpleCanonicalizer.
This also stops linking it into circt-opt to make sure we don't accidentally
add new uses of the old pass.
2021-04-25 17:21:48 -07:00
Prithayan Barua f029897368
[RTL] Generator callout pass (#908)
* [RTL] Generator Callout Pass
-  This pass calls an external program for all the `rtl.module.generated` nodes.
-  The corresponding `rtl.generator.schema` node is used for the port names.
-  The value for each port name is parsed from the attribute on the `rtl.module.generated` nodes.
-  The `rtl.module.generated` node is removed from the IR.
-   The module is then declared as an external module, whose definition is present in a file with the module name.
-  The file name in which the module definition exists is added as an attribute to the external module declaration.
2021-04-23 11:45:41 -07:00
Andrew Lenharth 260179d212
firrtl memory generator node lowering (#915)
Lower firrtl memory nodes into a simulation model.  RW ports, which are underspecified in FIRRTL as implemented as a single port with latency = max(readLatency, writeLatency).  This lowering uses 'x in some places were output is undefined.
2021-04-13 17:54:29 -05:00
Chris Lattner b6b3cb9f9f [RTL] Store port names more efficiently in rtl.module and friends.
This also improves the printing and parsing of ext modules and other
things to print with pretty syntax, and eliminates the rtl.name
attribute.

This new design is MUCH faster, uses less memory, and is simpler to
work with for passes.  It eliminates a bunch of dictionary attr with a
single rtl.name key in it, and gets us out of making a bunch of arg1
attributes on the module itself.

This is the RTL half of Issue #872.
2021-04-02 23:05:36 -07:00
John Demme fefe8a211d [RTL] Fix type parsing bug (broken 'rtl' elision on struct)
Struct 'rtl.' was being elided on printing, but not on parsing.
2021-04-02 22:52:47 -07:00
Chris Lattner 1955aa3b90 [SV] Require names on sv.reg and sv.wire.
The -rtl-legalize-names was crashing on these ops that were lacking a name.
It isn't helpful to make these attributes optional when we can represent this
state as an empty string.  Such a design defines away a class of bugs like this.

This fixes ISsue #855.
2021-03-30 22:40:30 -07:00
Chris Lattner 58a1e181b7 [tests] Don't run --rtl-legalize-names as part of the ExportVerilog tests.
It has its own testcases.  This makes the ExportVerilog tests simpler and
more self-contained.
2021-03-30 16:21:41 -07:00
Andrew Lenharth e4fc39261d
Remove sv.yield and update canonical pattern matches to match mlir updates (#830)
Remove sv.yield and update canonical pattern matches to match mlir updates
2021-03-26 15:51:10 -05:00
Fabian Schuiki 9f02e9c27c
[ExportVerilog] Use LegalNamesAnalysis to determine module names (#807)
* Refactor the MLIR module level emission in ExportVerilog such that it
  has a separate but symmetrical `UnifiedEmitter` and `SplitEmitter`.
  These either emit Verilog into one large file, or one separate file
  per module and interface. This will also provide a way to inject the
  results of LegalNamesAnalysis into the emission process.

* Add `isNameValid` to SV dialect to check if a string contains only
  characters that are legal for SV identifiers.

* Verify that module names contain only allowed characters when emitting
  them in ExportVerilog. Do no longer sanitize the module names but rely
  on a separate pass on the IR to do so.

* Run the RTLLegalizeNamesPass when emitting Verilog with firtool.

* Check for name consistency in split-verilog test case.

* Run `circt-opt --rtl-legalize-names` before `circt-translate
  --export-verilog` to ensure names are legal for emission.

* Update the expected output in the rtl-dialect.mlir test, since the
  separate renaming pass now ensures that the two `arrZero` ports do no
  longer conflict in the output. Also the index on `reg_2` has shifted
  by one due to an intentional conflict caused through `inout_0` to
  check for proper renaming.

* Add explicit check for sanitization of an instance with unsavoury
  name.

* Rename the `rtl.module.extern @reg` in the sv-interfaces.mlir test,
  since the renaming pass cannot just go rename external modules. This
  should probably become an error check at a later stage.

* Emit a diagnostic in the `RTLLegalizeNamesPass` if an extern module
  has an invalid name.

* Add test cases that check for these diagnostics.
2021-03-25 21:21:17 +01:00
Fabian Schuiki 9ceca83a7b
[SV] Add RTL legal names analysis and renaming pass (#770)
* Move `resolveKeywordConflict` and `sanitizeName` from ExportVerilog to
  the SV dialect. This makes it easier to perform name sanitization at
  an earlier stage already.

* Add name accessor convenience functions for the `rtl.instance` and
  `sv.interface` operations.

* Add an analysis pass that establishes sanitized and uniquified names
  for modules, interfaces, ports, wires, and registers in the SV and RTL
  dialects. This pass will allow Verilog output to become more stable
  and for it to have predictable names.

* Add a name legalization pass that applies the sanitized and uniquified
  names determined by the LegalNamesAnalysis to the IR, transforming it.
2021-03-23 13:53:24 +01:00
Chris Lattner 3c7e83e67c [RTLCleanup] Merge always_comb blocks in the same module. 2021-03-19 22:44:25 -07:00
Chris Lattner 18cbbbddc2 [SV] Add sv.alwayscomb and verilog emitter support for it. 2021-03-19 22:36:10 -07:00
Schuyler Eldridge 073fa3736b
Revert "[SV] Check IfDefProceduralOp is in a procedural region (#776)"
This reverts commit b0d72ca280.

This broke lowering of FIRRTL memories and registers.  Reverting this
for now.
2021-03-18 14:05:50 -04:00
Hideto Ueno b0d72ca280
[SV] Check IfDefProceduralOp is in a procedural region (#776)
* [SV] Fix invalid use of IfDefProceduralOp

* [SV] Check IfDefProceduralOp is in a procedural region

* clang-format
2021-03-18 21:58:58 +09:00
Chris Lattner 9c76ccc1af [SV] Give pretty SSA names to sv.verbatim.expr, sv.constantx, and sv.constantz. 2021-03-15 08:41:42 -07:00
Chris Lattner f6f59c971d [SV] Rename sv.textual_value to sv.verbatim.expr to align with sv.verbatim. 2021-03-15 08:17:36 -07:00
Hideto Ueno b4878a560c
[SV] Verify behavioral constructs are in procedural regions (#768) 2021-03-15 20:15:40 +09:00
Chris Lattner 59c114ee22 [SV] Expand sv.textual_value to do operand substitutions so we can use it for macros. 2021-03-13 12:07:12 -08:00
Hideto Ueno 4d48b77be0
[SV] Invert IfOp if thenBlock is empty (#761)
* [SV] Invert IfOp if thenBlock is empty

* clang-format
2021-03-13 11:35:34 +09:00
Hideto Ueno 565d4595c4
[SV] Add NonProceduralOp trait (#735)
* [SV] Add NonProceduralOp trait

* add tests

* add wire op

* clang-format

* clang-format
2021-03-09 00:08:08 +09:00
Hideto Ueno a7c363739a
[SV] Verify if/fatal/casez/finish are in procedural regions (#734)
* [SV] Verify if/fatal/casez/finish are in procedural regions

* add test cases
2021-03-07 10:26:01 +09:00
Hideto Ueno ebea102bc0
[SV] Verify fwrite/bpassign/passign are in a procedural region (#719)
* [SV] Verify fwrite/bpassign/passign are in a procedual region

* Only check direct op

* adjust test

* fix tests
2021-03-06 10:32:32 +09:00
Andrew Lenharth ca0a68f45d
Constant to generate 'x and 'z (#730)
Constant op for x and z
2021-03-05 16:21:38 -06:00
Hideto Ueno 50105063fd
[SV] Remove if/ifdef/always/initial op if they are empty (#703)
* [SV] Canonicalize ifdef/always/initial op if they are empty

* temporal

* add test and fix logic for IfDef

* add for ifop

* Update SVOps.cpp

* address comment

* add not

* fix test
2021-03-05 09:17:58 +09:00
Chris Lattner 967282dd9d [SV] Add a new sv.casez operation with parser and printer support.
Nothing generates this and this isn't supported by ExportVerilog yet.
2021-02-28 16:02:48 -08:00
Hideto Ueno 3b880dd421
[SV] Canonicalize sv.if true and sv.if false (#660)
* [SV] Canonicalize sv.if true and sv.if false

* fix

* Remove unused include
2021-03-01 00:23:21 +09:00
Hideto Ueno 30668d990a
[RTL] [Comb] Move comb.constant to rtl (#673)
* Move comb.constant to rtl

* add missing

* fix

* fix ExportVerilog and example

* format

* format

* remove unnecessary header

* materialize constant

* format

* rebase

* fix

* clang-format
2021-02-27 17:29:15 +09:00
Prithayan Barua 6bd3f5ae11
[RTLCleanup] Merge Always block (#684)
* Add support for merging always block
* In addition to alwaysFF block, also merge always blocks
2021-02-26 12:56:02 -08:00
Hideto Ueno 5237190d22
[Comb] Fix constant syntax (#637)
* [Comb] Fix constant syntax

* Fix doc and missed tests

* fix
2021-02-23 12:10:58 +09:00
Chris Lattner 29c476ba40 [RTLCleanup] Merge initial blocks within a module. 2021-02-21 11:46:06 -08:00
Chris Lattner cf5db259ea Rename testcase to align with pass name, nfc. 2021-02-21 11:23:53 -08:00
Chris Lattner 623e7ed584 [RTLCleanup] Merge consequtive procedural if's with the same condition.
This also fixes ifdef merging to only merge ifdefs with the same condition :-)
2021-02-21 11:23:06 -08:00
Chris Lattner ee01f0817b [RTLCleanup] Add support for merging procedural ifdefs.
This refactors the code a bit to split between procedural and graph
regions (which are semantically very different).  This also changes
the merging code to merge "down" instead of "up" which doesn't matter
for graph regions but is required for procedural regions.
2021-02-21 10:37:12 -08:00
Chris Lattner 93db31b6f7 [SV] Change ifdef ops to have a canonical way to represent ifndef.
Before we'd use "!FOO" as an identifier to get an inverted conditional.
Such a representation gives us two different ways to represent the same
thing and unnecessarily makes transformations on ifdefs (like merging
of them) more complicated.

Instead just put inverted logic into the else block, and have the verilog
exporter print a ifdef with no "then" as ifndef.

This patch also merges the code I duplicated in the verilog emitter for
the two ifdef cases.
2021-02-20 22:59:38 -08:00
Chris Lattner 286e2de23f Rename the AlwaysFusion pass to RTLCleanup, NFC. 2021-02-20 22:32:35 -08:00
Chris Lattner 9c62dc7102 [AlwaysFusion] Implement fusion of equivalent sv.ifdef nodes. 2021-02-20 22:26:14 -08:00
Chris Lattner 20b04d2369 [AlwaysFusion] Fix merging in the presence of top-level #ifdefs.
This changes the pass to do a post-order walk of the region tree, in
preparation for other changes.
2021-02-20 21:40:36 -08:00
Chris Lattner 334798e4a2 [AlwaysFusion] Make this pass be specific to RTLModuleOp instead of
being invoked on arbitrary ops.
2021-02-20 21:30:23 -08:00
John Demme 6bd0b93ab9
[RTL] Create new 'comb' dialect and move all the RTL combinational ops into it (#599) 2021-02-16 16:04:52 -08:00
Andrew Lenharth 08a04091f6
Rename externmodule to module.extern in preparation for other module types (#577) 2021-02-11 13:22:57 -06:00
Andrew Young da80538e9f [SV] Add pass to merge AlwaysFF operations
This adds a pass to merge `sv.alwaysff` operations with identical
conditions.  Due to the design of this operation it is trivial to check
if we meet the conditions for merging this operation.  This pass is
structured to not depend on the RTL dialect, and does not assume that
the `sv.alwaysff` operations are in an RTL module.  They do, however,
need to be in a graph region to work.

Although `sv.alwaysff` regions are not graph regions, they are limited
to having a single block.  This pass takes advantage of this to quickly
splice blocks together when merging operations.
2021-02-03 12:17:46 -08:00
Andrew Lenharth abdbf464d4
Rework alwaysff syntax [NFC] (#509) 2021-01-26 10:18:30 -06:00
Andrew Lenharth ce5241c4fb
Always_ff support with explicit resets and reset style (sync/async) (#491)
Always_ff support with explicit resets and reset style (sync/async).  Reset blocks are tracked as part of this node to simplify merging always blocks with similar style resets.  Keeping different always blocks for different reset styles of registers is driven from tool requirements and style guidelines.
2021-01-22 14:27:35 -06:00
Andrew Lenharth 9e2b0966df
Support optional else block for sv.if (#415)
Support optional else block for sv.if
2021-01-07 09:57:43 -06:00
Chris Lattner 6e17aa6c11 [SV] extend the sv.always block to support zero or more conditions.
This allows each to have their own event and supports @* for the zero
case.
2020-12-29 16:25:14 -08:00
Chris Lattner 0f164dab5c [SV] Generalize the sv.alwaysat_posedge op to an sv.always op.
This allows generation of negedge and edge triggers.
2020-12-29 11:40:56 -08:00
Andrew Young 0cd056917a Shuffle around the tests
- Move conversion tests to Conversion
- Move dialect tests to Dialect
- Capitalize dialect names
- Move LLHD export tests into the dialect
- Move FIRRTL import tests into the dialect
2020-12-23 13:54:39 -05:00