Commit Graph

117 Commits

Author SHA1 Message Date
Andrew Young 578b569d65 [FIRRTL] Rename EmitMetadata to CreateSiFIveMetadata
Since this is creating verbatim operations instead of emitting files
directly, `create` makes more sense as a verb.

Since the metadata emitted is specific to SiFive build flows,  this
renames the pass to make it clear that it is not generically useful.
This leaves the pass on by default since the pass will only do anything
if the correct annotations exist.

This change was suggested here:
https://github.com/llvm/circt/pull/1875#discussion_r716070526
2021-09-27 11:42:15 -07:00
Andrew Young 2bd1858dee [FIRRTL][EmitMetadata] Add SitestBlackBox metadata support
This adds another metadata emitter.  This purpose of this pass is to
collect every blackbox module (or extmodule) which will need to be
stubbed or filled in. This excludes blackbox modules which have inlined
or imported verilog.

There are two separate metadata files generated for this: one for
blackboxes instantiated under the DUT as denoted by the
MarkDUTAnnotation.  The other is a list of blackboxes not instantiated
under the DUT.
2021-09-24 12:53:09 -07:00
Andrew Lenharth c4ac7b8fb5
Annotation Scattering and trivial processing Pass (#1808)
Add a pass to handle all annotation scattering. This pass is table driven, with customizable scattering per-annotation-class. When this is fleshed out, it will replace the annotation handling code in the parser.

Right now, this supports a couple testing annotation to make test cases against.

Until this is live in the pipelines, add an option to the parser to bypass annotation handling and scattering to enable testing.
2021-09-22 13:55:55 -05:00
Richard Xia e97cff3fd5
[SV][LowerToHW] Add ExportModuleHierarchy pass. (#1792)
* [LowerToHW] Lower mainModule and DesignUnderTest attributes into moduleHierarchyFile attribute.

Since these are currently only used for the export module hierarchy
pass, these have been replaced with a more generic attribute marking
which modules should have their hierarchies exported to output files.

* [SV] Add ExportModuleHierarchy pass.

This adds a pass that collects the full module hierarchy into a JSON
string, which is then exported as part of an sv.verbatim op. The pass
collects a hierarchy for each module with the firrtl.moduleHierarchyFile
attribute.

The pass can be enabled in firtool by providing the
--export-module-hierarchy option.
2021-09-18 12:14:58 -07:00
Andrew Young 50904ee377
[FIRRTL] Add PrefixModules pass (#1183)
This adds the prefix-modules pass to FIRRTL.  This pass looks for
modules annotated with the `NestedPrefixModulesAnnotation` and prefixes
the names of all modules instantiated underneath it. This pass will
duplicate modules as necessary to give submodules unique names. The
annotation can be attached to module definitions, as well as specific
instances.

The supported annotation is:
```json
{
  class = "sifive.enterprise.firrtl.NestedPrefixModulesAnnotation",
  prefix = "MyPrefix_",
  inclusive = true
}
```

If `inclusive` is false, it will not attach the prefix to target module,
only to modules instantiated underneath it.
2021-09-16 10:55:17 -07:00
Andrew Lenharth ba9c344ace
[FIRTOOL] Allow multiple annotation files (#1674)
A build flow might have multiple annotation files. Allow passing them all.

Co-authored-by: Prithayan Barua <prithayan@gmail.com>
2021-08-31 09:08:45 -05:00
Chris Lattner 83f5500ac8 [firtool] Tidy up some logic, NFC.
No need for "else" after "return" etc.
2021-08-27 12:25:12 -07:00
Chris Lattner 648a7f3e95 [firtool] Refactor firtool.cpp, emit more specific --mlir-timing output.
Just pass down the output filename instead of a lambda, there is no
need for the extra abstraction here.  While here, change the timer
in the various flavors of output to be more specific than "Output".
2021-08-27 10:31:41 -07:00
Chris Lattner c6e386e601 [HWLegalizeModules] Give generated wires (somewhat) useful names 2021-08-21 17:25:01 -07:00
Andrew Young 0413d52355
[firtool] move BlackboxMemory before LowerTypes (#1618)
BlackBoxMemory creates modules with bundles types to replace memory
operations.  If this runs after LowerTypes, then we hit the LowerToHW
pass with a bunch of bundle types around.  This pass is not often used,
and this must have regressed at some point.

This also adds an integration test to ensure that CHIRRTL memories are being
properly lowered to verilog.
2021-08-21 15:29:04 -07:00
Chris Lattner 7ccdb3d8cc [hw] Introduce a HWLegalizeModules pass and a new `disallowPackedArrays` lowering option.
This pass provides a structured way to handle IR features that are not
supported by all tools, and this lowering option reflects a specific
limitation of the Yosys tool.

Right now the pass isn't super helpful: it just rejects unsupported operations
with an error.  This is progress towards Issue #1592.
2021-08-21 13:28:09 -07:00
Andrew Young 0a0ee65287
[FIRRTL] Implement SFC's RemoveCHIRRTL pass (#1540)
This adds an implementation of the RemoveCHIRRTL pass called
LowerCHIRRTL.  This pass takes the CHIRRTL memory operations, `seqmem`
and `combmem`, and transforms them into standard FIRRTL `mem`
operations.
2021-08-21 12:23:56 -07:00
John Demme 21485874c8
[llvm] Update submodule to latest (#1589)
Co-authored-by: Andrew Lenharth <andrew@lenharth.org>
Co-authored-by: Fabian Schuiki <fabian@schuiki.ch>
Co-authored-by: Andrew Young <youngar17@gmail.com>
2021-08-18 19:37:43 -07:00
Fabian Schuiki 0c0f314301
[firtool] Add --parse-only option (#1603)
Add a `--parse-only` option to `firtool` which causes the program to
stop after the FIR/MLIR and annotation input files have been parsed and
processed, and writes the resulting MLIR module to the output. This is
interesting and useful since `firtool` performs a unique combination of
input translation and annotation scattering that is not trivially
reproduced with `circt-translate` and `circt-opt`. Useful for test case
reduction.
2021-08-18 18:36:03 +02:00
Fabian Schuiki c3573eed43
[FIRRTL] Add InferResets pass (#1304)
* Extract reset-related test cases from the existing Scala FIRRTL
  compiler code; specifically from `InferResets`, `CheckResets`,
  `RemoveReset`, and `FullAsyncResetTransform`.

* Add the `InferResets` transformation pass to the FIRRTL dialect, which
  assigns asynchronous resets to registers without reset, and replaces
  `reset` types with either `uint<1>` or `asyncreset`, as appropriate.

* Add the `--infer-resets` option to firtool, on by default.
2021-08-13 12:15:45 +02:00
Fabian Schuiki 3c6987ca74 [firtool] Run the canonicalizer after inlining/imconstprop
Inlining and IMConstProp generate additional opportunities for
canonicalization, especially around registers with invalid/constant
reset signals and values. To leverage these, firtool should run the
canonicalizer again just before going into the output-specific
pipelines.
2021-08-12 19:50:40 +02:00
Fabian Schuiki d6dcf37fcc [firtool] Add split-input-file and verify-diagnostics options
Add the `--split-input-file` and `--verify-diagnostics` options to
firtool. This brings it more in line with other tools such as circt-opt,
and simplifies writing integration tests against firtool.
2021-08-06 19:33:17 +02:00
Hanchen Ye fefe356aab
[FIRRTL] Add a CheckCombCycles pass (#1388)
This pass runs a strongly connected components (SCC) detection to check
combinational cycles in the IR. The current implementation assumes the
firrtl-lower-types and firrtl-expand-whens has been applied before this pass.
2021-08-03 15:35:14 -05:00
Chris Lattner 242f1988c4 [FIRRTL] rename the parser entry points to "importFIRFile". NFC.
The previous names "importFIRRTL" were a bit ambiguous.  What this
really does is parse a .fir file into a firrtl dialect representation.
2021-07-31 09:48:13 -07:00
Andrew Young a1a0188f49 [firtool] Enable `-inline` by default
This turns on the FIRRTL inliner by default.  This pass has some
questionable behaviour where it will delete any module not reachable
from the top level module.  This is an optimization that prevents the
pass from performing uneccesary work, while not leaving unprocessed
modules in the code.  This is also the mechanism through which modules
which had all instances inlined will be deleted. We may want to decide
if this behaviour is desirable before merging this commit.
2021-07-22 20:07:30 -04:00
Hideto Ueno d284a97c4e
[NFC] Eliminate simple canonicalizer (#1454)
* eliminate simple canonicalizer

* small fix

* fix cmake

* remove circt/Transforms

* clang-format
2021-07-22 12:23:01 +09:00
Fabian Schuiki b0a6986b2b [FIRRTL] Merge CheckWidths into InferWidths
Merge the `CheckWidhts` pass into the `InferWidths` pass, which already
has all the necessary information to complain to the user about
uninferred widths. This commit also improves error reporting a bit by
tracking additional location information on the constraint expression
such that we can point the user at the sites where a connection may
cause problems.

Fixes #1297.
2021-07-16 18:44:21 +02:00
Andrew Lenharth 4f7c50791e
[FIRRTL] Replace Lower Types with new version. (#1421)
Rename new version and remove old version.
2021-07-14 13:08:05 -05:00
Andrew Lenharth e0de28f0e2 [NFC] Fix options for lower types 2021-07-08 08:42:12 -07:00
Andrew Lenharth e5246fe83c
[FIRRTL] Rewrite LowerTypes with simpler structure (#1275)
Rewrite LowerTypes to simplify and improve performance.

Walks the operations in reverse order. This lets it visit users before defs. Users can usually be expanded out to multiple operations (think mux of a bundle to muxes of each field) with a temporary subWhatever op inserted. When processing an aggregate producer, we blow out the op as appropriate, then walk the users, often those are subWhatever ops which can be bypassed and deleted. Function arguments are logically last on the operation visit order.

Each processing of an op peels one layer of aggregate type off. Because new ops are inserted immediately above the current up, the walk will visit them next, effectively recusing on the aggregate types, without recusing. These potentially temporary ops (if the aggregate is complex) effectively serve as the worklist. Often aggregates are shallow, so the new ops are the final ones.

There is no global map. When you update an aggregate producer, you build a small vector of it's expansion, which you use to update it's users. Once the users of an aggregate are updated, there is no reason to store mapping data on them any longer.

This structure makes it relatively easy to to do connect-expansion and partial-connect-legalization along the way. connects get processed before their source and dest.

This gives a 40% improvement on a medium sifive core and hasn't been tuned yet.


Co-authored-by: Prithayan Barua <prithayan@gatech.edu>
Co-authored-by: Prithayan Barua <prithayan@gmail.com>
2021-07-06 11:36:54 -05:00
Prithayan Barua 0dca40bc75
[FIRRTL][LowerToHW]Emit warning on unprocessed remaining annotations (#1341)
Emit a warning after lowering `FIRRTL` operations to `HW` dialect, 
if there are `annotations` remaining on the `FIRRTL` operation.
This is required to detect missing passes in FIRRTL dialect to remove the annotations. 
The warnings are disabled by default.


- Use a set to record all the annotations remaining on different operations. 
- Emit a warning for each annotation only once. So if the same annotation is found on different operations, only one warning is emitted.
- Add an option to `LowerFIRRTLToHW` pass to enable the  warnings
  - The option is disabled by defailt
  - Use`emit-annotation-warning=true` to emit the warnings
- Add option `emit-annotation-warning` to `firtool` , which should be passed to `createLowerFIRRTLToHWPass`
- Note: The `emitWarn` will crash when trying to print the `InstanceOp`. Reason for crash:
    1. If we try to print the old `InstanceOp` operation while traversing the operations in a module, the symbol referring to the module is invalid. Hence `getReferencedModule` crashes. 
    2. The traversal is on the new temporary module body, which has moved(`splice`) the old operations,  https://github.com/llvm/circt/blob/main/lib/Conversion/FIRRTLToHW/LowerToHW.cpp#L825
    3. Seems like the original symbol on the operation gets deleted during the `splice`, hence the invalid  temporary IR. 
- To fix the crash, we don't print the operations by using `mlir::emitWarn`, and just print the source location.
- Use `std::mutex` when updating the `StringSet<> alreadyPrinted` in class `CircuitLoweringState`
  - `CircuitLoweringState` object is shared between threads working on modules, hence the lock is required when updating the set. (https://github.com/llvm/circt/blob/main/lib/Conversion/FIRRTLToHW/LowerToHW.cpp#L208)
2021-07-05 18:35:07 -07:00
Andrew Young 4a939ea312
[firtool] Move CSE very early (#1277)
CSE can work with full efficacy on IR without inferrred widths.
Moving it early improves WidthInferrence and LowerTypes performance.
2021-06-16 14:50:38 -07:00
Fabian Schuiki 77ea524da3
[FIRRTL] Add pass to handle grand central data and memory taps (#1178)
* Add a `GrandCentralTaps` pass which consumes the FIRRTL Grand Central
  data and memory taps annotations, and generates the corresponding
  blackbox data tap modules with hierarchical Verilog identifiers
  inside.
2021-06-16 20:04:41 +02:00
Schuyler Eldridge 6da2131b0f
Grand Central Interface Support (#1170)
* [FIRRTL] Add Grand Central Interface Support
* [FIRRTL] Add Grand Central Interface Tests

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-06-16 00:22:06 -04:00
Chris Lattner b6737713ad [firtool] Stop disabling multithreading for the parser. NFC.
We previously disabled multithreading when parsing the input file
to save cost on some mutexes etc, since the parser wasn't threaded.
Now however, the verifier is threaded, and disabling multithreading
is disabling it as well.

Just stop doing this.  This provides an aggregate speedup for me,
e.g. shrinking total firtool time from 29.9s to 26.7s on a large
design (18.6s -> 15.2s in the parser) which is a pretty big speedup.
2021-06-14 22:17:36 -07:00
Fabian Schuiki 1e99c0ac2d
[firtool] Enable width inference by default (#1242)
* Switch the `--infer-widths` option to run by default. The user can
  still disable the pass through `--infer-widths=false`.
2021-06-12 08:16:09 +02:00
Andrew Lenharth 3a179c4336 [FIRTOOL] unify format of cli options for passes [NFC] 2021-06-10 13:12:28 -05:00
Andrew Young c4b2257007
[FIRRTL] Rename Blackbox to BlackBox (#1227)
It was decided that "black box" should be consistently used as two words
in the code base. See #1209.
```
Blackbox     -> BlackBox
the blackbox -> the black box
```
2021-06-09 10:13:20 -07:00
Chris Lattner e73115d596 [firtool] Turn on -imconstprop by default.
To paraphrase Aliaksei over slack, "The people always wanted
imconstprop, what could possibly go wrong" 🙈

Admittedly, I might be paraphrasing that wrong.
2021-06-01 20:24:17 -07:00
Andrew Young 0f378b5f06
[firtool] Enable expand-whens by default (#1174)
This pass has been subjected to fuzz-testing for quite some time, and it
is surprising (in a negative usability sense) that it is not enabled by
default.

Some FIRRTL-to-LLHD tests were using firtool with uninitialized ports,
and this change switched them to use circt-translate instead.
2021-05-28 09:04:57 -07:00
Fabian Schuiki 5f6502c151
[firtool] Add blackbox resource search path option
* In addition to the `--blackbox-path` option which specifies the
  overall search path for black box files (including `BlackBoxPathAnno`
  annotations), add a separate `--blackbox-resource-path` option which
  only affects the `BlackBoxResourceAnno` annotations. These get moved
  into the Scala/sbt artifacts directory, and the resource path should
  generally point there. Path annotations in general will want to remain
  relative to the input FIR file, which this additional enables.
2021-05-27 09:27:24 +02:00
Andrew Lenharth 5046209ee3 [FIRTOOL] formatting 2021-05-26 15:58:19 -05:00
Andrew Lenharth 4dd1845152 [FIRTOOL] Add support for using an arbitrary root directory for blackbox searches. 2021-05-26 15:55:56 -05:00
Fabian Schuiki e539a7bcfb
[firtool] Move width inference before canonicalization (#1147)
* Move the width inference pass up in the pipeline such that it runs
  before the canonicalization passes. This is useful since width
  inference itself does not depend on canonicalization, but in turn
  enables a lot of canonicalization patterns to run.
2021-05-26 10:57:07 +02:00
Chris Lattner 12e2b8efb4 [firtool] really-don't-delete the ModuleOp before quitting. NFC.
This avoids running the destructor for the module before exiting the
firtool process, saving ~6% of "dark" runtime.
2021-05-24 18:19:46 -07:00
Fabian Schuiki 928e6fdb2d
[FIRRTL] Add black box reader pass (#918)
* Add the `BlackBoxReader` transformation pass which is modeled after
  the `BlackBoxSourceHelper` Scala implementation. It honors a set of
  FIRRTL annotations that declare source code for black boxes to be
  copied to an output directory. This pass reads those source files into
  an operation in the IR, such that they can be written to the output
  during emission. Annotation can be done inline, as a separate path, or
  the rather Java-specific resource mechanism.
2021-05-21 20:01:58 +02:00
Andrew Lenharth 15f1687a11 Fix some release and gcc warnings. [NFC] 2021-05-21 10:37:03 -05:00
Fabian Schuiki c10ca772f9
[firtool] Fix whitespace 2021-05-21 16:12:07 +02:00
Andrew Lenharth b4028edb19
enable lower-types by default (#1086) 2021-05-19 14:00:13 -05: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 4d43103122 [RTL->HW] Rename the string "RTL" to "HW"
This makes sure not to rename FIRRTL to HWRTL :-), and I spot checked a
many things to avoid changing general references to RTL (e.g. when referring
to external tools) but I suspect that I missed some.  Please let me know (or
directly correct) any mistakes in this mechanical patch.
2021-05-15 12:44:05 -07:00
Chris Lattner 61e70086c6 [RTL->HW] Move a few more files in conversions and documentation. NFC. 2021-05-15 12:23:45 -07:00
Chris Lattner 91f77cf64b [RTL->HW] Move RTL directory structure/filenames to HW. NFC
This doesn't change the types or stuff declared in the file, just moves
things into place.
2021-05-15 12:07:47 -07:00
Chris Lattner c934a581ab [firtool] Change the firtool driver to exit() instead of return.
The difference is that we no longer run the dtor for the MLIRContext
that we parse a bunch of IR into.  This avoids spending time
deallocating memory, which is pointless immediately before process
exit.
2021-05-14 14:34:28 -07:00
Chris Lattner 22c4082c1b [firtool] Refactor the top level of the tool a bit, NFC. 2021-05-14 14:16:47 -07:00