Commit Graph

1222 Commits

Author SHA1 Message Date
Chris Lattner 0db015c28a [HW] Improve TypeAliasType::getTypeDecl.
This makes this more efficient (not doing a full mlir::Module walk to
look up uncached symbols), makes the diagnostics in ExportVerilog
come out with the correct location info again, and changes this accessor
to return null on failure, instead of emitting an error from the accessor.

There are still larger design changes that would make sense here
conceptually, but I'm not going to work on typedefs much.
2021-10-21 14:35:30 -07:00
Fabian Schuiki 4cd37091ef
[FIRRTL] Add OMIR emission pass (#2010)
Add a pass to the FIRRTL dialect that consumes `OMIRAnnotation`s on the
circuit, gathers the tracker nodes back up, and serializes the data back
into a JSON blob.
2021-10-21 20:26:43 +02:00
Fabian Schuiki 86ae1e83ca
[FIRRTL] Add DontTouch annotation helpers
Add additional helper functions to make dealing with DontTouch
annotations more convenient.
2021-10-21 18:51:07 +02:00
Schuyler Eldridge 8e3be7592c
[FIRRTL] Support Prefixing of Grand Central Interfaces (#2020)
Change the Grand Central Views/Interfaces pass to apply an outer
module-level prefix (derived from a NestedPrefixModulesAnnotation that
was handled by the PrefixModules pass) and an inner prefix set by an
optional PrefixInterfacesAnnotation.  Modify RenameModules to set the
outer prefix by adding a "prefix" field to the circuit-level, outermost
AugmentedBundleType.

Supporting this, add a getter to retrieve the "prefix" field of an
AugmentedBundleType.

Add two tests: (1) test that PrefixModules correctly updates Grand
Central interface annotations and (2) test that the GrandCentral pass
correctly applies a prefix coming from PrefixModules and from a
PrefixInterfacesAnnotation.  As part of (2), ensure that the
PrefixInterfacesAnnotation is removed.

Update FIRRTL rationale document with information about how Grand
Central-generated interfaces can be prefixed.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-10-21 11:54:36 -04:00
Schuyler Eldridge 462a75e58b
clang-format fix, NFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-10-21 00:01:06 -04:00
Mike Urbach 8be26b7c9b [Python] Fix bindings after upstream changes to aggregate building.
With the new CMake functionality upstream, we need to set the
ENABLE_AGGREGATION option when we call add_mlir_library. The easiest
way to do this is to just rely on the upstream helper
add_mlir_public_c_api_library, which does this and other important
settings for us.

Also, ensure the MSFT dialect's CAPI marks all of the public functions
as being exported.
2021-10-20 16:51:26 -07:00
cgyurgyik 85285a2ee8 [Calyx] [NFC] A -> An. 2021-10-19 20:39:06 -07:00
cgyurgyik 4a70e0d3c5 [Calyx] [NFC] Add examples for unary library operations as well. 2021-10-19 20:37:55 -07:00
Andrew Young 485b3041f5
[FIRRTL][SV] Use `parseKeywordOrString` (#2013)
The `parseKeywordOrString` function was recently added to the MLIR
parser, and we can simplify some code by using it. We can remove the
functions `parsePort` from SV and `parseIdentifier` from FIRRTL.  These
functions all print a string as a keyword unless it contains illegal
characters, where it would print as a string.
2021-10-19 11:10:27 -07:00
Martin Erhart 3453997c2d
[LLHD] Delete insert ops, revise extract ops (#1992)
Closes #1656 by removing the LLHD insert operations and replacing the extract operations as described in the issue.

Some notes/observations:
- Semantics of accessing out of bounds for both slices and single elements in LLHD were partially implemented to return a default value depending on the type (only for non-signal arrays in `llhd.dyn_extract_slice`) or UB. This PR defines it to be UB as this is also what HW does (I think).
- Field accesses to structs are checked, though.
- Extract slice operations cannot return a wider type (at most equal size), I think this is not the case in HW
- `llhd.sig.array_slice` does not work for a full slice of an array with one element (also `llhd.sig.extract` with signal of `i1`) as it requires a `i0` value as index, but this is not supported by `HWIntegerType` (e.g., `llhd.sig.array_slice %array at %index : (!llhd.sig<!hw.array<1xi32>>) -> !llhd.sig<!hw.array<1xi32>>`). A full slice, however, works for more elements in the array. `hw.array_slice` has the same behavior, I don't know if this is intended, or whether it should be enabled, or returning the same number of elements should be forbidden. Seems a bit inconsistent to me this way.
- Removed `sig` type support for `llhd.shr` in `LLHDToLLVM` as it was wrong in the first place (see #1988 ) and it lowered to an operation removed with this PR. It requires concatenating two signals in some way, this seems too complicated to quickly include in this PR.
2021-10-19 13:08:03 +02:00
Chris Gyurgyik 03c654c135
[Calyx] [NFC] Remove extra `the` in description. 2021-10-18 22:19:05 -07:00
Chris Gyurgyik 51da22ae6d
Use the GroupInterface to establish port driving. (#2018)
Instead of having helper methods with a GroupInterface parameter, we instead add 
InterfaceMethods to the GroupInterface for logic relating to port driving / reading in 
groups.
2021-10-18 22:17:29 -07:00
Andrew Lenharth 3b9d4f278e
[FIRRTL] Add filename option for seq mem metadata emission (#2005)
Support setting the filename for the seqmem metadata.
2021-10-18 08:55:23 -05:00
Martin Erhart aab7c1a212
[LLVM] Bump LLVM to adopt 'pretty accessors' (#2008)
This requires a lot of renaming of operations from the standard dialect to the arith dialect which was split off since the last LLVM bump.
2021-10-18 09:06:14 +02:00
Chris Lattner 4b9a8a328b [ExportVerilog] Move emitTypeDims/printPackedType into ModuleEmitter.
This makes way for dimensions that can refer to declarations within the
module, like parameters.

Note that this exposes some design problems with TypeAliasType.
I just xfailed a test for now (the expected diagnostics are emitted on
the wrong line now) where ExportVerilog is implementing verification of
these decls instead of the verifier.  I will tackle that as its own
separate workstream, since type parameters needs a sound design as well.
2021-10-16 15:33:07 -07:00
Chris Lattner 92213897e2 [HW] Add an !hw.int<x> type, for parameterized integers.
This has a long way to go, but this is a minimal starting point.
2021-10-16 14:48:56 -07:00
John Demme 960e624d7f
[MSFT] [DeviceDB] Teach `walkPlacements` about boundaries (#2000)
`walkPlacements` now takes a bounding rectangle and a primitive type
upon which to filter.
2021-10-15 13:29:53 -07:00
mikeurbach e7e054c494
[Analysis] Add CyclicSchedulingAnalysis to compute a CyclicProblem. (#1997)
This analysis depends on the MemoryDependenceAnalysis and uses the
dependences to compute a partially complete CyclicProblem for each
AffineForOp loop nest.
2021-10-15 10:00:00 -07:00
Andrew Young 2f2473d110
[FIRRTL] Move port directions and names to `firrtl.instance` (#1963)
The primary contribution of this change is to add port directions and
names to the instance op.  This fixes the issue where we had to fetch
this information from the referenced module, which was not guaranteed to
be thread safe.

The printed form of the instance op is now a hybrid between the HW
instance op and a FIRRTL module, printing the entire "module signature"
at the end. This is quite verbose but needs to be in the IR format (i.e.
every op has to be parsable using only local information).

```mlir
firrtl.instance test @simple(in a: !firrtl.uint<1>, out b: !firrtl.uint<1>)
```
2021-10-14 18:14:53 -07:00
Fabian Schuiki b97774d1c6
[FIRRTL] Add missing HW dialect dependency on blackbox reader pass 2021-10-14 19:39:19 +02:00
Julian Oppermann 9a6a6913f8
[Scheduling] Make Problem-constructors explicit^2. (#1994)
Replace the 'using' notation by explicit declarations, and while at it, also add the 'explicit' keyword to these one-argument constructors.
2021-10-13 22:55:40 +02:00
Prithayan Barua d98b9b43ef
[FIRRTL] Flatten FIRRTL memory of aggregate type (#1957)
FIRRTL lowers a memory with an aggregate type into a new memory for every leaf
 element in the memory's data type. This commit adds a flag `--repl-seq-mem`
 to instead lower the memory to a single new memory with flattened data type.
The data and mask bits need to be mapped to the new memory accordingly.
We use BitCastOp to cast the aggregate types to the flattened UInt type.
Mask bits might not have a 1:1 mapping, for example with 
`!firrtl.bundle<a: uint<8>, b: uint<16>`, the flattened data has 24 bits,
 and the 3 bit mask bitwidth. In that case, the mask granularity is 8 and
 the mask bits for element b is repeated once.
The `repl-seq-mem` flag will be enabled by default in a followup PR.
2021-10-13 12:33:05 -07:00
Fabian Schuiki e4878fdef7
[SV] Add sim ctrl and severity message system tasks (#1989)
Extend the SV dialect to cover all simulation control system tasks
(`$stop`, `$finish`, and `$exit`), and all severity message tasks
(`$fatal`, `$error`, `$warning`, `$info`). This change includes added
support for diagnostic verbosity in stop, finish, and fatal, as well as
optional messages and interpolation operands for fatal, error, warning,
and info.

A subsequent PR will make use of these to lower from the FIRRTL dialect.
2021-10-13 17:01:09 +02:00
Andrew Lenharth bcfaf7843e
[HW] Add an attribute to make file lists (#1986)
Add an attribute to indicate the file containing the op should be put in a specific filelist at emission time.  This attribute allows files to exist in multiple filelists.
2021-10-13 07:48:17 -05:00
Fabian Schuiki 33e1eb393a
[FIRRTL] Add message interpolation to verif ops (#1975)
Extend the assert, assume, and cover verification operations to support
optional arguments for interpolation into the message string. Also clean
things up a bit by factoring out the commonalities of the verif ops into
a `VerifOp` parent class.

Adjust the parser for printf-encoded verification ops to leverage the
new message interpolation behaviour, passing through any operands to the
`printf` op. Also update the `LowerToHW` pass to carry the message
interpolation over into the SV dialect.
2021-10-13 09:51:35 +02:00
Prithayan Barua e0d73a9b72
[FIRRTL] Add option to enable FIRRTL memory lowering and metadata (#1987)
Add the `--repl-seq-mem` option to enable memory lowering for macro
 substitution and metadata emission. 
 Changes in this commit:
 1. Enable metadata emission by default, except memory metadata
 2. Add an option `repl-seq-mem` to enable memory metadata emission
 3. Add an option `repl-seq-mem` to generate external module 
    for certain FIRRTL memories, that are candidates for macro substitution.
 4. The requirements for macro replacement:
       1. read latency and write latency of one.
       2. only one readwrite port or write port.
       3. zero or one read port.
       4. undefined read-under-write behavior.

This a subset of changes from the approved PR https://github.com/llvm/circt/pull/1957
<prithayan@gmail.com>
2021-10-12 22:09:12 -07:00
Prithayan Barua 2b5bceb900
[FIRRTL] Add FIRRTL memory summary struct (#1970)
The `FirMemory` is a struct with the relevant `FIRRTL` memory properties. 
It was constructed during `LowerToHW` for lowering the `FIRRTL::MemOp` by 
extracting its attributes.
But the `FirMemory` is also required during the memory metadata generation.
In this checkin we move the `FirMemory` struct out of `LowerToHW` and add it 
to the `FIRRTLOps.h`. 
This also fixes the memory names emitted during the metadata generation.
2021-10-12 14:43:41 -07:00
Andrew Young 100e58f9b7
[FIRRTL] Add InstanceOp builder which takes a module (#1978)
When port directions and names are moved on to the instance op these
fields can be taken directly off of the module.  In many cases this
new builder greatly simplifies the process of creating a new instance operation.
2021-10-12 10:45:28 -07:00
Fabian Schuiki ae55ca7ecd
[SV] Add defer and message support to assertions (#1974)
Add an optional message and list of operands to be interpolated into the
message to the verification operations in the SV dialect (immediate and
concurrent). This message is expected to be printed when the assertion
fails, and is emitted as `... else $error(msg, operands...)`.

Also add a new `defer` field to immediate assertions which allows for
the emission of `assert #0` ("observed deferred assertion") and `assert
final` ("final deferred assertion"). There are use cases in the FIRRTL
dialect that will make use of this feature in a follow-up commit.

This commit also adjusts the parsing/printing of verification ops in the
SV dialect to accomodate the optional label and optional message parts
more easily.
2021-10-12 19:01:52 +02:00
Andrew Young f2f7229c24
[FIRRTL] Remove unused builder for InstanceOp (#1976)
This builder was not used anywhere, so it makes sense to remove it.  It
was originally introduced in 9c8935462b.
2021-10-12 09:57:08 -07:00
Daniel Resnick 544e6fa2ee
[LLVM] Bump LLVM to use result type inference (#1972)
Operations that implement `InferTypeOpInterface` can now omit their result
types in their `assemblyFormat` without needing custom parse and print functions.

`comb.concat` has been updated to take advantage of this.
2021-10-11 18:17:41 -06:00
Martin Erhart 7ada4af1cd
[LLHD] Remove llhd.eq and llhd.neq (#1965)
Replaced by hw.bitcast and comb.icmp
2021-10-11 12:39:56 +02:00
Chris Lattner c42908a9ae [ExportVerilog] Change legalization of module names to be efficient.
Instead of walking the entire design hierarchy to rename a module that
conflicts with a symbol, just add a "verilogName" attribute to it.  This
encodes a simple idea that the verilog name of a module is the contents
of the verilogName attribute or the symbol name if not present, just
like it already is for external modules.
2021-10-10 21:54:03 -07:00
Andrew Lenharth 6f1a67fd58
[SV] Add XMR op (#1948)
XMRs or hirarchical names are really annoying.  They have context-dependent lookup rules.  They resolve to multiple elements.  They resolve to external elements.  They require whole-world assumptions to resolve; resolving on a partial circt might indicate something isn't refereced which really is after linkign in external code.

This implements a purely syntactic XMR.  It does not try to link the name to existing circuit elements, this requires expensive analysis.  Frontends need to mark path elements with don't touch (or equivalent) where they want a path preserved.
2021-10-10 21:29:47 -05:00
Chris Lattner 525b2284a2 [ExportVerilog] Implement renamification for interfaces correctly.
The prior implementation was trying to rename symbols, which is
fraught because they occur in types and would require rebuilding
type hierarchies.  Use GlobalNameTable to handle the needs here
instead.

This fixes Issue #1967
2021-10-10 18:31:58 -07:00
Chris Lattner 8058f253f0 [HW] Use ODS generated accessors instead of stringly typed things,NFC. 2021-10-10 10:24:18 -07:00
Chris Lattner 064cfee98e [HW] add some helpers when working with individual input/output ports. NFC. 2021-10-09 19:39:18 -07:00
cgyurgyik f2962043e5 [Calyx] [NFC] Simplify Direction attribute packing. 2021-10-09 12:48:02 -07:00
Andrew Young f3397f4123
[FIRRTL] Stop declaring FModuleLike attributes as arguments (#1951)
This change removes the `portAnnotations` and `portNames`  attributes
from the FExtModule and FModule op's argument lists. Here are
the differences that this change makes as far as I can tell:

1. Less obvious that these attributes exist on the operation (bad thing)
2. We don't have redundant `portAnnotations()` and
   `getPortAnnotations()` functions defined (good thing)
3. We don't have redundant verification of the attribute from the
   `AnnotationArrayAttr` type constraint and `FModuleLike` verifier
   (might be a good thing).
4. Does not affect the builder methods, as these ops do not use the
   generated builder methods. (no effect)

Given what I have seen in other interfaces, I think this is the way to
go.
2021-10-08 17:36:51 -07:00
Andrew Lenharth e6cde1f094
Support a generalized freechips.rocketchip.annotations.InternalVerifBlackBoxAnnotation in ExtractTestCode (#1956)
Covert freechips.rocketchip.annotations.InternalVerifBlackBoxAnnotation annotations to a generalized set of annotations that works not just for cover, but assert and assume extraction too.  Process those annotations in ExtractTestCode.
2021-10-08 17:49:24 -05:00
Prithayan Barua 7df98af7c7
[FIRRTL] Add BitCastOp folder (#1958)
Add fold patterns for `BitCastOp`. 
1. Input and result types are same, then `BitCast` is redundant
2. If `BitCast`s are chained to form the same result type as the original
 input, then they are redundant.
2021-10-08 13:09:14 -07:00
Morten Borup Petersen cd9976a874
[Handshake] Rename handshake passes (#1955)
Renames the handshake passes to be in line with the naming convention used in the remainder of the CIRCT passes.

- `create-dataflow` -> `lower-std-to-handshake`
- `analyze-dataflow` -> `handshake-analyze`
- `canonicalize-dataflow` -> `handshake-canonicalize`
- `remove-block-structure` -> `handshake-remove-block-structure`
2021-10-08 19:37:18 +01:00
Prithayan Barua b3e68a9370
[FIRRTL] Create memory metadata (#1923)
Add memory metadata emission to `CreatesifiveMetadata`.
The metadata is used for memory macro substitution by memory generator tools.
A subsequent checkin will delay the `CreatesifiveMetadata` pass in 
the FIRRTL pipeline.
2021-10-08 10:08:33 -07:00
Chris Lattner 777491f6b8 [HW] Add a convenience builder for ParamDeclRefAttr, NFC. 2021-10-08 09:55:26 -07:00
Chris Gyurgyik 023d7af1aa
[Calyx] Add portDirections, portAttributes attributes. (#1954)
Add portAttributes and portDirections arguments to ComponentOp. I also remove unpackAttribute, 
as it remains unused (and thus untested). This closes #1950.
2021-10-08 08:04:55 -07:00
Andrew Lenharth 2e861f1232 [NFC] use default value, not optional 2021-10-07 13:51:11 -07:00
Andrew Young c643c6b17d
[FIRRTL][Calyx] Clean up port direction attribute handling (#1946)
This change mostly affects FIRRTL, where Calyx has a small update to
make sure that some previously copied code matches identically.

This change removes the special handing for port directions when there
are zero ports.  Port directions are represented using an APInt as
a bitvector, and since APInts previously did not support 0 bit wide integers
there was some logic to handle this as a special case.  Since APInts
have been updated to allow 0 bit wide integers, this commit removes this
special handling.

In addition to this, some other cleanups included are:
- Moving the port direction logic from FIRRTLInterfaces to
  FIRRTLAttributes.  Since the port direction logic is not tied to the
  FModuleLike interface anymore, it can be used for other things like
  InstanceOps.
- Removing the `direction::attrKey` which was used as the attribute name
  for directions. Since this string is not a part of any OpInterface, it
  is unclear what code should use it. A future change should be made
  to stop using string literals and use
  `FModuleLike::getPortDirectionsAttrName()` where appropriate.
- Fix printing of directions, and make them work with regular streams.
  This lets us use it in `printModuleSignature()`.
- Remove some verification from FExtModule which is already handled by
  FModuleLike.
2021-10-07 12:33:33 -07:00
John Demme 07c2778fa7
[MSFT] [DeviceDB] Add bindings to walk functions (#1942) 2021-10-06 21:46:15 -07:00
John Demme 7738ef9713 [MSFT] Make `msft.instance` a symbol, alias with `InstanceName` 2021-10-06 21:22:43 -07:00
Chris Lattner 16ca802461 [HWLegalizeNames] Merge this into ExportVerilog.
This keeps the structure largely the same, but pulls the implementation
logic over. This needs to be integrated better with the existing logic
in ExportVerilog which does a similar but different thing on the fly.
2021-10-06 15:44:23 -07:00
Chris Lattner 9411838074 [HW] Clean up getVerilogModuleName[Attr] methods, NFC.
It turns out that one HWModuleGeneratedOp method was missing a
definition.  They were also inconsistent.
2021-10-06 15:43:30 -07:00
John Demme 5a4445ec3e [MSFT] [NFC] DeviceDB -> PrimitiveDB, combine all DB code
- Renames DeviceDB to PrimitiveDB.
- Puts both PrimitiveDB and PlacementDB in DeviceDB.h.
- Moves PlacementDB implementation into DeviceDB.cpp.
2021-10-06 14:23:55 -07:00
Andrew Young f1ea4f5914
[FIRRTL] rename FModuleOp::getBodyBlock() to getBody() (#1940)
This change renames the `getBodyBlock()` function to `getBody()`, which matches
the CircuitOp API.  In a module there is only ever one region with one block in
it, and there is rarely a reason to get the Region. Naming this wasn't possible
before as `FunctionLike` was squatting on the `getBody()` name, which has
recently been dropped.
2021-10-06 13:54:06 -07:00
Andrew Young 193c5fc46c
[FIRRTL] Move more logic into the ModuleLike op interface (#1929)
This moves support for port directions, names, types, and (port)
annotations into the `FModuleLike` operation interface.  This also
removes the `FunctionLike` trait from `FExtModules` and `FModule`
operations.

Dropping support for `FuncLike` means that we are free to represent port
types as an array of types, instead of a functional type. This brings
some simplicity as port names and annotations were already arrays.

Another large difference is that we no longer support function argument
attributes.  There was a significant amount of complex code written to
support `argAttrs` and `portAnnotations` at the same time. Removing the
unused `argAttr` support simplified our code and IR printed format.

This work is not totally complete, but I decided to cut it here before
the change became too large.  Some additional follow up work is:
1. Cleaning up the Direction attribute, utilizing new APInt 0 bit
   support.
2. Simplify FModuleOp's inputs TypeContraints so that the real
   verification is done by the FModuleLike verifier. Port existing tests
   over to the new verification logic.
3. Update `InstanceOp` and `MemOp` to use the same function names as
   `FModuleLike`, e.g. `getPortName()` instead of `getPortNameStr()`.
2021-10-06 12:07:56 -07:00
John Demme d488343996
[MSFT] [DeviceDB] Find nearest free location in column (#1937)
Find the nearest primitive in a column to the desired row. Said primitive should be of a given primitive type, and be unoccupied.
2021-10-06 11:12:01 -07:00
Andrew Young 9909253abf
[FIRRTL][InferReset] Keep instance graph properly updated (#1912)
In an earlier change, I made InferResets always mark the InstanceGraph
analysis as preserved, under the assumption that the pass does not
modify the instance graph.  This turns out to be incorrect as it can add
arguments to a module and must recreate the instance ops to reflect
that.

This change adds a function `InstanceGraph::replaceInstance(old, new)`
which allows the InstanceGraph to stay updated by the pass. This is the
first function added to the InstanceGraph to allow updating the cached
analysis.  This function is slightly more efficient then adding a
separate `addInstance(new)` and removeInstance(old)` functions.
2021-10-06 01:11:34 -07:00
Richard Xia d8d7153320
[HWExportModuleHierarchy] Directly emit JSON to a file instead of an sv.verbatim op. (#1931)
* [Support] Factor appendPossiblyAbsolutePath() into lib/Support.

This was duplicated between ExportVerilog.cpp and BlackBoxReader.cpp,
but it is a generally useful utility function.

* [HWExportModuleHierarchy] Directly emit JSON to a file instead of an sv.verbatim op.

Previously this pass created an sv.verbatim op with the entirety of the
module hierarchy JSON file embedded into it, with the expectation that
the --split-verilog mode of firtool would actually be the one to create
it. This is now problematic because we'd like to move name legalization,
into the ExportVerilog pass, which means module names could change after
ExportVerilog runs.

Moving the HWExportModuleHierarchy pass after ExportVerilog guarantees
that names match the final verilog, but that means that
HWExportModuleHierarchy may no longer rely on the sv.verbatim op
output_file method to actually emit the file.

This commit changes HWExportModuleHierarchy to directly write the module
hierarchy JSON files. Note that firtool will now only run the
HWExportModuleHierarchy pass when --split-verilog mode is enabled, since
we now only want to run it when we have an output directory to dump
files to.
2021-10-05 16:53:00 -07:00
Chris Lattner 28b5a881c1 Various code cleanups, NFC.
Clean up some tblgen files and wrap to 80 columns, delete some commented out
code, and improve the export verilog pass names.
2021-10-04 22:30:45 -07:00
Chris Lattner 910ee76fbd [include/circt/Conversion] Flatten out a level of directories, NFC.
Move singleton headers like circt/Conversion/LLHDToLLVM/LLHDToLLVM.h
up to circt/Conversion/LLHDToLLVM.h since that is the only thing in that
directory.
2021-10-04 16:29:31 -07:00
Chris Lattner 0de4aac499 [ExportVerilog] Move into Conversions/ tree.
ExportVerilog was an outlier living as the only child of the Translations
tree, move it into Conversions to be more similar to other passes.
2021-10-04 16:24:12 -07:00
Schuyler Eldridge cb48bb5fc4
Fix linker error, implementation in header file
Fix a linker issue introduced during the ExportVerilog rework.  The
implementation defined for `createExportVerilogFilePass()` was causing
problems as this was included in both `firtool `and `circt-opt`.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-10-04 16:09:29 -04:00
cgyurgyik 1b8dd65a38 [Calyx] [NFC] Add comments next to SymbolTable attribute. 2021-10-04 13:06:22 -07:00
Chris Gyurgyik f9e89e7171
[Calyx] [SCFToCalyx] Change Cell instance name from StringAttr to FlatSymbolRefAttr. (#1924)
Changes a cell's instanceName argument from StringAttr to FlatSymbolRefAttr. This will be necessary for the 
addition of an InvokeOp, which needs to verify that the instance being invoked actually exists. Since primitives 
(namely multi-cycle ones) may also be invokeable, this is required for all cells. This also verifies there is no name
shadowing with symbol names for components and cells.
2021-10-04 13:02:52 -07:00
Chris Lattner 53547513c3 LLVM.h: fix a build warning by forward declaring as class instead of struct.
warning: 'OpConversionPattern' defined as a class template here but previously declared as a struct template
2021-10-04 12:29:34 -07:00
Chris Lattner 93b4f3564f [ExportVerilog] remove support for circt-translate, use circt-opt instead. 2021-10-04 11:58:51 -07:00
Chris Lattner ffea59251e [ExportVerilog] Start moving ExportVerilog to being a pass.
ExportVerilog was initially conceived as a translation that read the
IR and printed out verilog text.  However, it evolved to being a pass
that mutates the IR (e.g. its prepare pass).  As such, it makes more
sense to model it in CIRCT as a transformation: we want to be able to
run passes after it in the pass pipeline, e.g. to generate metadata.

This takes one step towards that, adding new entrypoints that make it
available in circt-opt.
2021-10-04 11:21:06 -07:00
Chris Lattner 5b996b85c6 [SVPasses] remove some unneeded forward declars, NFC. 2021-10-04 11:04:21 -07:00
John Demme 12720afe41
[MSFT] Use a DeviceDB to seed a PlacementDB (#1922)
Just checks validity of placements for now.
2021-10-02 17:40:40 -07:00
John Demme ee2a93886c
[MSFT] Adding DeviceDB (#1921)
Created a DeviceDB which doesn't do anything yet. The `devType` to
`primitiveType` change got wrapped up in this change.
2021-10-02 01:28:24 -07:00
John Demme ede291cdd5 [MSFT] Rename `devType` to `primitiveType` on PhysLocation attribute 2021-10-01 23:13:06 -07:00
John Demme daa5dc503e [MSFT] Rename DeviceType enum to PrimitiveType 2021-10-01 22:09:52 -07:00
Parker Mitchell f76fadad6e
[MSFT] Rename DeviceDB to PlacementDB (#1894)
No functional changes. This PR simply renames DeviceDB to PlacementDB within the MSFT dialect. The "DeviceDB" name may be used in a future PR and live alongside the PlacementDB.
2021-10-01 18:24:10 -07:00
Schuyler Eldridge 36a3253887
Object Model 2.0, Part 1: Read in OM 2.0 (#1915)
Add a new option to firtool, "--omir-file <file>", which will parse an
Object Model 2.0 JSON file into an OMIRAnnotation.  This only handles
parsing.  No scattering is performed.

Add one test that the "--omir-file <file>" option used to ingest an
Object Mdoel 2.0 JSON file works for firtool.  Check that the
information in the OMIR is preserved and is wrapped in an
OMIRAnnotation on the circuit.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-10-01 20:55:54 -04:00
Schuyler Eldridge 65ac10458e
[FIRRTL] Make source locator parsing a util, NFC
Move the source locator parsing inside FIRRTL's parser into a utility
method called maybeStringToLocation.  Make this change because source
locators can show up in places other than FIRRTL text.  Namely, source
locators are used inside Object Model 2.0 JSON (and could also show up
in annotations).

Note: this utility has a super, super wacky API and should be cleaned up
later.  However, this intentionally done (for now) as a direct, NFC
conversion of the existing code inside the parser.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-10-01 20:18:41 -04:00
John Demme d046e6a7ec
[MSFT] Removing C++ generator code (#1918)
We've switched to Python-based generators. Ping-ponging between IR modifying
C++ and IR modifying Python was a massive mistake for pointer safety reasons.
2021-10-01 16:24:15 -07:00
Prithayan Barua 1b8bfe9aa2
[FIRRTL] Add a bitcast operation to FIRRTL dialect (#1905)
Add a new `bitcast` operation to `FIRRTL` dialect, which will be directly
lowered to `hw::bitcast` operation.
The `bitcast` operation can be used to directly cast a `vector` or `bundle`
type to a flattened `uint`, without blowing out the fields.
This operation will be used to simplify lowering of aggregate memory data
type in `LowerTypes`.
2021-10-01 15:26:47 -07:00
Daniel Resnick 4f21e44d52
[Comb] Simplify comb.concat signature to omit result type (#1880)
Removes the result type from the comb.concat type signature since it can be
deduced from the inputs.

For example, this previous signature:
```mlir
%0 = comb.concat %false, %b : (i1, i4) -> i5
```

is simplified to:
```mlir
%0 = comb.concat %false, %b : i1, i4
```

Address #1623.
2021-10-01 13:30:25 -06:00
cgyurgyik ed590197cb [Calyx] [NFC] Check SingleBlock for Then and Else regions of IfOp. 2021-10-01 09:19:43 -07:00
cgyurgyik 24fc833bed [Calyx] [NFC] Add sanity assertions to verify containers are `SingleBlock`ed. 2021-10-01 09:14:55 -07:00
Chris Gyurgyik 3860557ded
[Calyx] [SCFToCalyx] Initialize bodies upon build. (#1914)
Adds builders to initialize bodies for IfOp, WhileOp, CombGroupOp, GroupOp, WiresOp, and ControlOp. 
This also removes their default builders, since it would be odd to want a Calyx container without a body. 
The rest is necessary clean-up in SCFToCalyx and CompileControl. Closes #1884.
2021-10-01 08:56:42 -07:00
Chris Gyurgyik a3b49ba593
[Calyx] [SCFToCalyx] Add simplified builders for `SeqOp` and `ParOp`. (#1909)
Add builders for SeqOp and ParOp that add the body (Block *) for you already. First part of #1884.
2021-09-30 13:52:44 -07:00
Chris Gyurgyik 51a53e48eb
[Calyx] Add canonicalization for empty bodies. (#1907)
This adds canonicalization patterns for empty IfOp, WhileOp, SeqOp, and ParOp bodies. For the former two, 
we also check to see if the (optional) Group and conditional are used. if not, we remove them as well. This also 
loosens the verification restrictions for empty bodies in a WhileOp and IfOp. IMO, these are still valid with an 
empty body.
2021-09-30 07:42:52 -07:00
Fabian Schuiki 51c9985c20
[FIRRTL] Add first implementation of EmitSignalMappings (#1665)
Add a first implementation of Grand Central's `EmitSignalMappings` pass,
which populates a module in a circuit with `force` statements and
cross-module references that access things in a second circuit. This 
requires a lot of polishing and ironing out of kinks and the design in 
general later, but this is a first bare-bones implementation in the 
spirit of the other Grand Central passes (use verbatim SV to get 
something going, even if it's brittle and needs some cleaning up later).

To avoid having to deal with the issue that `EmitSignalMappings` 
actually operates on two circuits in parallel, the current 
implementation only operates on the circuit where the `force` statements
are to be inserted, and uses some text manipulation to guess what name 
the forced/probed things in the remote circuit will end up having in the 
output Verilog. This will need proper XMRs in the future, but works as a 
first shot.

Co-authored-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-09-30 10:16:44 +02:00
Fabian Schuiki 30e5e78104
[FIRRTL] Rework CircuitNamespace::newName, NFC
Apply @lattner's suggestion in #1903 to have just a single `newName`
implementation that takes a twine, and use twine's fast-path for the
StringRef case to make things quick.
2021-09-30 10:12:37 +02:00
Chris Gyurgyik 729d9280ea
[Calyx] Add enhancements to common tail elimination for `IfOp`. (#1895)
This adds a pattern for when then and else regions are both ParOps. It also takes into consideration 
the parent region of the IfOp, since we don't want to unintentionally change the behavior when pulling 
out EnableOps. I also do not touch anything that's not immediately within the given ParOp's body; 
doing so may also change the behavior of the program. The case where the then and else regions are 
different, e.g. SeqOp and ParOp, should never pull out an EnableOp; it will always produce worse code.
2021-09-29 20:37:27 -07:00
Fabian Schuiki 4dbcc435c2
[FIRRTL] Make CircuitNamespace helper public (#1903)
Move the `CircuitNamespace` helper struct from the current Grand Central
source files into a public header file. This acts like a symbol table
specifically for `firrtl.circuit` ops and is useful for avoiding name
conflicts when generating additional modules.
2021-09-29 19:40:10 +02:00
Chris Lattner 90677b4d62 [HW Parameters] Add support for shrs/divs/divu/rems/remu.
This gives us the full complement (except sub) of binary operators.
2021-09-28 22:45:00 -07:00
Chris Lattner a533e66eeb [HW Params] Implement basic canonicalizations and checking.
This is progress towards resolving Issue #1847.
2021-09-28 21:53:41 -07:00
Chris Lattner d9b1a90079 [Comb] Replace CombIntegerType with HWIntegerType. NFC
This just shares common logic instead of copy/pasting it.
2021-09-28 21:12:27 -07:00
cgyurgyik ef7bdd252d [Calyx] [NFC] Use stricter Block existence, not Region existence for IfOp. 2021-09-28 18:54:31 -07:00
Julian Oppermann 360c4e7a0f
[Scheduling] Refactor validation framework. (#1888)
... from component-specific checkers/verifiers to property-specifc methods.
2021-09-28 20:48:28 +02:00
Julian Oppermann bff070fa32
[Scheduling] Define modulo scheduling problem. (#1886) 2021-09-28 10:08:44 +02:00
Andrew Lenharth caa1f0be41 InterfaceInstance optionally defines a symbol. ExportVerilog wasn't picking this up durring collectInstanceSymbolsAndBinds since it didn't implement SymbolOpInterface 2021-09-27 19:42:49 -07:00
Chris Gyurgyik e2ab279f38
[Calyx] Add verifier for ParOp. (#1892)
Adds a simpler verifier for ParOp that only looks within the given body (and not nested regions). 
Anything stricter requires more careful thinking.
2021-09-27 13:01:37 -07:00
Martin Erhart ffb9cd2f86
[LLHD] Generate types, attributes and their storages using tablegen (#1782) 2021-09-27 21:33:01 +02:00
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
Chris Gyurgyik 142503d3b7
[Calyx] [SCFToCalyx] Add collapse-control canonicalization pattern for IfOp, SeqOp and ParOp. (#1883)
Adds some canonicalization methods for SeqOp and ParOp to replace the pattern rewrite in SCFToCalyx. 
This is similar to the native compiler's Collapse Control pass. For the cells section, uses CHECK-DAG 
since we don't particularly care what order the cells are listed in. This was previously causing test failures, 
after adding the -canonicalize flag.
2021-09-27 11:33:13 -07:00
Chris Lattner f9e483c700 [ParamExprAttr] Take constrol of construction so we can canonicalize. NFC. 2021-09-27 09:33:47 -07:00
Chris Lattner 7f5550b1ed [HW Params] Tidy up constant folding from comb nodes, add And/Or/Xor. 2021-09-27 09:25:48 -07:00
Chris Lattner 1116dbbee6 [HW] Generalize ParamBinaryAttr and rename to ParamExprAttr.
This adds support for multi-arity operators, adds support for some
shifts, and extends folding of add to param add for arbitrary arity.
2021-09-26 22:34:18 -07:00
Chris Lattner e8b21a3653 [ParamBinaryAttr] add a nicer builder. 2021-09-26 21:49:22 -07:00
Chris Lattner 2650cee557 [HW] Teach that hw.param.value is ConstantLike and foldable.
Implement a simple fold from comb.add to hw.param.value to show this,
but there is more to be done before this gets generalized.
2021-09-26 18:43:41 -07:00
Chris Lattner f0600f06a3 [HW] Verify the expression in a hw.param.value is correct. 2021-09-26 18:13:55 -07:00
Chris Lattner c3b2b46de8 [HW] Rename isCombinatorial -> isCombinational. NFC.
We agreed awhile ago that this was the right name.
2021-09-26 17:58:53 -07:00
Chris Lattner 98263fed75 [HW Parameters] add the hw.param.value op.
This projects an parameter expression into an SSA value, just like
hw.constant does for simple integer constants.
2021-09-26 17:55:01 -07:00
Chris Gyurgyik b58fa87623
[Calyx] Use native compiler representation for guarded assignments and ports. (#1879)
Switches the GroupGoOp, GroupDoneOp, and AssignOp to match the native compiler representation. 
We're still pretty dependent on the native compiler, so it seems right to keep the IRs as similar as 
possible. Closes #1873.
2021-09-25 07:55:31 -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 Young f4bfc260a2 [FIRRTL] Add EmitMetada pass with RetimeModulesAnnotation support
This adds a new `EmitMetadata` pass to FIRRTL which a dumping ground for
any simple metadata generation passes that don't make sense to implement
as a standalone pass.  The first pass implemented is `RetimeModules`
which just collects the name of any annotated module and emits it into a
JSON array.
2021-09-24 12:53:09 -07:00
Andrew Young ef83a402af [HW] Make OutputFileAttr a AttrDef instead of StructAttr
This moves OutputFileAttr from an AttrDef to a StructAttr.  This
StructAttr prevented us from puting member functions on the attribute
which were need.

This adds the ability to normalize filenames when creating an
OutputFileAttr, which is helpful when creating these from FIRRTL
annotations.

This also removes the cmake magic for generating StructAttrs in the HW
dialect, as there were none left.
2021-09-24 12:53:09 -07:00
Prithayan Barua ebd8269c89
[FIRRTL] Add support for multi-bit FIRRTL Memory mask type, NFC (#1864)
Add support to add multi-bit mask type for FIRRTL memories.
This is required for flattening an aggregate memory data type, and enabling 
a finer mask granularity by extracting individual bits from the memory data element.

The mask width was hard coded to 1 bit, this PR will remove that restriction.
2021-09-24 12:02:28 -07:00
Morten Borup Petersen f5441a2d4a
[HandshakeToFIRRTL] Add support for index_cast, zexti and trunci ops (#1865)
zexti and trunci operations generate handshake components which wrap around FIRRTL `pad` and `bits` operations. The builder for each of these ops is used to support `index_cast`, which pads or truncates an input type compared to the fixed index-width (64 bits).
2021-09-24 08:15:58 +01:00
John Demme a132ba6d48 [MSFT] Lower msft::ModuleOp before lowering msft::InstanceOp
The `hw::InstanceOp` (which `msft::InstanceOp` lowers to) convenience
builder gets its argNames and resultNames from the `hw::HWModuleOp`. So we
have to lower `msft::MSFTModuleOp` before we lower `msft::InstanceOp`.
2021-09-23 20:38:40 -07:00
Fabian Schuiki beb6f967ce
[FIRRTL] Validate reg async reset value is constant at LowerToHW Time (#1444)
* [FIRRTL] Rename ResetType to AnyResetType, add actual ResetType

The FIRRTL dialect currently has things like `AsyncResetType` or
`ClockType` which are the actual types, but `ResetType` is a constraint
that captures `asyncreset`, `reset`, and `uint<1>`. Rename this to
`AnyResetType` and add a `ResetType` that represents the actual
buildable `firrtl.reset` type in analogy to the others.

* [FIRRTL] Add async reset const check to LowerToHW

When lowering a `firrtl.regreset` with async reset in `LowerToHW`, check
that the reset value is a constant. This is a common constraint imposed
by EDA software and is enforced on the Scala side as well (in the
CheckResets pass).

This also finally enables the `async-reset-errors.mlir` integration test
that we had for quite a while now.
2021-09-23 21:11:13 -04:00
Schuyler Eldridge 79cbbc8428
[Analysis] Fix compiler warning
Fix a compiler warning where a struct was forward declared as a class.
Apparently this can cause linker problems with the Microsoft C++ ABI.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-09-23 20:33:54 -04:00
Chris Gyurgyik 069faf81d8
[Calyx] [NFC] Remove completed TODO. 2021-09-23 15:33:47 -07:00
Chris Gyurgyik c49dc11d6f
[Calyx] [SCFToCalyx] Add builders with no guard. (#1872)
Add builders that don't require a guard for AssignOp and the GroupOp ports. Now, we no longer need to add
an empty Value constructor for `guard` when building the operation.
2021-09-23 14:58:12 -07:00
mikeurbach 82b9de0f35
[Analysis] Add a DependenceAnalysis for checking memory accesses. (#1845)
This is currently a simple class that traverses pairs of Affine memory
access operations and uses the upstream `checkMemrefAccessDependence`
function. The results are stored in a convenient data structure that
can be queried to inform scheduling decisions. A test pass is added,
which outputs the results as attributes for verification.
2021-09-23 15:47:41 -06:00
Chris Gyurgyik 815029c851
Add IfOp helpers. (#1870)
Add helper methods for the IfOp. The IfOp inherits from CalyxContainer, which has the SingleBlock trait, 
so it should be guaranteed that each region has a single block. I've renamed the getters to remain in line 
with the getBody helper for other Calyx containers.
2021-09-23 09:38:58 -07:00
John Demme 99f0092cac
[Python] Fix Python Bindings (#1858)
Closes #1810 

The changes to `hw.module` and `hw.instance` make them incompatible with `msft.module` and `msft.instance` as far as the python bindings are concerned. I'm not sure what I want to do here so I've marked that test as `xfail` for the moment.
2021-09-23 02:14:14 -07:00
Chris Gyurgyik d75874d194
[Calyx] [SCFToCalyx] Add EnableOp builder which doesn't require the `compiledGroups` attribute. (#1854)
The compiledGroups attribute is only used during the (currently incomplete) lowering process of Calyx IR 
to signify which groups are attributed to the calyx.enable during compilation. This maintains the invariant 
that all Group symbols are referenced throughout the life time of a Calyx program. This PR adds another 
builder to skip initializing it. Closes #1844.
2021-09-22 18:50:19 -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
Chris Lattner a0afaa44f4 [HW] Add simple expressions to the parameter support.
This includes export verilog and legalizenames support.

This is just a minimal first step.  It has several issues that we
need to improve over time:

1) Support variadic operators.
2) Support better .mlir syntax
3) Precedence aware printing in generated verilog.
2021-09-22 09:34:56 -07:00
Chris Lattner 2ac86dd319 [HW] Move the WUW Enum into the hw namespace for consistency.
The mechanism for this is a bit weird, see this bug for discussion:
https://bugs.llvm.org/show_bug.cgi?id=51932
2021-09-21 17:35:14 -07:00
Chris Lattner 2821d08959 [HW] rename the parameter attributes to be more consistent.
The declaration of a parameter is now a ParamDeclAttr.  A reference
expression to it is a ParamDeclRefAttr, verbatim expres are
ParamVerbatimAttr.
2021-09-21 17:12:05 -07:00
mikeurbach f5526f992a
[StaticLogic] Add new PipelineWhile operation. (#1759)
https://llvm.discourse.group/t/rfc-representing-pipelined-loops/4171/1
for more discussion.

This defines the operation's syntax more or less as discussed,
including round-trip tests for the five running examples we've had.

In order to reduce test churn, the existing PipelineOp and the
StandardToStaticLogic pass are left untouched for now. Ultimately, the
new pipeline operation could replace the existing PipelineOp.
2021-09-21 17:45:36 -06:00
Prithayan Barua 34d3ed999e
[SV][ExportVerilog] Add symbol to verbatim macro substitution (#1798)
The verbatim op can be used for macro substitution with values. This PR adds 
support for macro substitution with symbols.
For example, 
```mlir 
sv.verbatim  "MACRO({{0}}, {{1}} reg={{4}}, {{3}})"
          (%add, %xor)  : i8,i8
          {symbols= [@reg1, @module1, @instance1]}
```
In the above operation, `0` and `1` will be replaced by `%add` and `%xor` ,
 `4` with the verilog name of the symbol `@instance1`  and `3` with the 
verilog name of the symbol `@module1`.

Changes in this commit:
1. Add the optional array of symbols as an attribute to the `VerbatimOp`
2. Add a type constraint for an array of `FlatSymbolRefAttr`, this can be pushed to `mlir`.
3. Update `ExportVerilog` to get the verilog name for any symbol. Most of the changes 
                     in `ExportVerilog` is just to ensure the final symbol names can be tracked.                    
4. Update docs and test cases.
2021-09-21 16:09:35 -07:00
Andrew Young cdba88ff7f
[SV] Make sv.interface a SingleBlock region (#1825)
When the MLIR parser reads in an empty region it does not create a
block.  The SymbolTable trait requires that the region has a block.
Adding the SingleBlock trait to the interface operation fixes this
issue.
2021-09-21 12:20:18 -07:00
Morten Borup Petersen 728406e122
[SCFToCalyx] Add calyx::ProgramOp conversion [2/13] (#1813)
* [SCFToCalyx] Add calyx::ProgramOp conversion [2/13]

This commit introduces logic for converting a top-level MLIR 'module' into a calyx::ProgramOp.
The implementation works around an issue/restriction of the current infrastructure, being that a top-level 'module' cannot be overwritten. see: https://llvm.discourse.group/t/de-privileging-moduleop-in-translation-apis/3733/26

Furthermore, an input program is legalized using a `ConversionTarget`.
2021-09-21 18:41:59 +01:00
Chris Gyurgyik 9e58c585e8
[Calyx] Add entry-point component attribute to ProgramOp. (#1819)
This takes a similar approach to the FIRRTL structure. We define an entry-point component by 
using its name in the ProgramOp. This is guaranteed to be unique since each ComponentOp 
name is a `Symbol`.
2021-09-21 08:52:13 -07:00
Schuyler Eldridge 7271abaf46
[HW] Add write-under-write enum attr
Add a new enumerated attribute that defines the write-under-write
behavior of HW memories.  Two flavors are added: (1) undefined behavior
and (2) port-ordered behavior.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-09-21 00:43:56 -04:00
Morten Borup Petersen e4731d4b5b
[SCFToCalyx] Add SCFToCalyx boilerplate [1/13] (#1812)
This is the initial commit for the SCFToCalyx pass. The commit sets up the boilerplate required for adding a new conversion pass.
2021-09-20 23:56:47 +01:00
Chris Lattner c0de60c9bb [HW] Add a ParameterAttr::getWithName member to consolidate helpers. 2021-09-19 21:36:26 -07:00
Chris Lattner ddb16da7a1 [HW] Replace getParameterNoValue with ParameterAttr::get members, NFC. 2021-09-19 21:33:26 -07:00
Chris Lattner 9d1a362dfd [HW] Move ParameterAttr from StructAttr to AttrDef
This makes it more efficient by storing it as a first-class attribute,
rather than as an interpreted dictionary.  This exposes a bunch of
ways in which StructAttr is unnecessarily different than AttrDef,
which is filed as LLVM PR 51909
2021-09-19 21:17:55 -07:00
Chris Lattner 7d0a5a1d87 [FIRRTL] Use some default fields of AttrDef instead of specifying them, NFC. 2021-09-19 21:17:30 -07:00
Chris Lattner c8d11ec6e4 [HW] Verify parameter values for modules and localparam. 2021-09-19 17:04:29 -07:00
Chris Lattner 08e46ac976 [HW] Verify that instance parameters are structurally correct. 2021-09-19 15:58:39 -07:00
Chris Lattner d22f1dc019 Move sv.verbatim.parameter up to the HW dialect.
This also renames it to hw.verbatim.parameter.value, and gives it a
proper type.  This makes it possible to do attribute checking without
the overhead of introducing an attribute interface.
2021-09-19 15:28:50 -07:00
Chris Lattner 3390221cdd Two files that were supposed to go with the previous patch. 🤦 2021-09-19 13:58:00 -07:00
Chris Lattner 12ab97af33 [HW] Introduce ParameterRefAttr, allowing use of parameter values in a module body.
This is still missing validation of the attributes, but does include
ExportVerilog support.
2021-09-19 13:55:28 -07:00
Chris Lattner e1e7e0feaf [SV] Switch LocalParamOp to take an attribute instead of SSA value.
This keeps params and attributes in different domains.  This will
allow better enforcement of valid parameter values in the verifier.
2021-09-19 12:33:01 -07:00
John Demme 0f7bb1b2ce [ESI] Fixing Capnp code to use new parameters model 2021-09-18 18:44:52 -07:00
Chris Lattner 6e21c285bd [HW] Remove support for old-style parameters entirely.
This completes Issue #1489.
2021-09-18 17:49:31 -07:00
Chris Lattner 74eda94c4f [LowerToHW] Switch to the new HW parameter module.
This also switches the module build() methods to take an ArrayAttr for
parameters instead of an ArrayRef<ParameterAttr>.  This is more consistent
with instances and is easier to work with.
2021-09-18 17:12:22 -07:00
Chris Lattner 2ac8f90d84 [HWLegalizeNames] Propagate renamed parameters to instances correctly. 2021-09-18 16:25:58 -07:00
Chris Lattner 18746a3b4f [HW] Add IR parser/printer/verifier support for new-style instance parameters. 2021-09-18 15:57:47 -07:00
Chris Lattner 47a6ddbe59 [HW] rename "defaultValue" to just "value" in ParameterAttr. NFC. 2021-09-18 15:20:49 -07:00
Chris Lattner a1e08007f0 [HW] Rename the 'parameters' member of hw.instance to 'oldParameters'.
We're going to get a new model for parameters here and I want to make
room for it.  Both models will have to co-exist for a while.
2021-09-18 14:57:42 -07: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
Chris Lattner 471e60ceaf [HW] Add support for parameter decls to the hw.module* operations.
This adds IR support to parse and print them, but there is no export
verilog support yet.
2021-09-17 17:48:38 -07:00
Chris Lattner 97f3149214 [HW] Split custom attributes out to their own .td file. NFC. 2021-09-17 14:46:58 -07:00
John Demme 67fd0f8e6d [MSFT] Python bindings for ops and changes to make them work
- Adds python bindings for MSFTModuleOp and InstanceOp.
- Re-use as much as possible from `circt.hw._hw_ops_ext`. Required changes to
  ODS definitions.
- Found and fixed some bugs.
2021-09-17 00:16:49 -07:00
cgyurgyik 853c97d073 [Calyx] [obvious] Use a boolean to determine whether ElseRegion exists.
Also pass in the Operation's body instead of using a Region index. This
seems slightly easier to read and also templating is no longer a
necessity.
2021-09-16 22:51:58 -07:00
Chris Gyurgyik b9e0dbc603
[Calyx] [NFC] Emitter now emits `ElseRegion`. (#1804)
Fixes the emitter so that an `ElseRegion` for the `IfOp` is emitted, if it exists. This required 
adding a regionIndex variable to determine whether the current region should be the ThenRegion 
or ElseRegion of an IfOp.
2021-09-16 22:41:04 -07:00
John Demme 88abe4dbb3
[MSFT] Lower `MSFTModuleOp`s to `HWModuleOp`s (#1803) 2021-09-16 20:35:01 -07:00
John Demme 3f738e2017
[MSFT] Add `MSFTModuleOp` (#1801)
Adds a moduleop to the MSFT dialect. For now, it's mostly like hw.module but adds parameters to represent the specific parameterization of a parameterized module. Also necessarily adds a msft.output since hw.output expects to be in a hw.module.

Step 3 of #1755.
2021-09-16 12:48:39 -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
Chris Lattner 072abc36c9 [APInt] use new cleaner APInt methods, NFC. 2021-09-16 09:37:41 -07:00
John Demme cdf21a8e7c [HW] [NFC] Finish move of `printModuleSignature` into shared header. 2021-09-16 01:12:36 -07:00
Hideto Ueno 45dd44b23d
[FIRRTL] Replace some lowerings with UnrealizedConversionCastOp (#1784)
* [FIRRTL] Replace StdIntCastOp/AnalogInOutCastOp/AsPassivePrimOp/AsNonPassivePrimOp with UnrealizedConversionCastOp

* refactor

* fix lower type

* fix

* fix lowerToHw
2021-09-15 13:59:32 +09:00
John Demme af8b1f500e
[HW] [NFC] Extract out printing/parsing functions for modules (#1773) 2021-09-14 19:50:41 -07:00
Chris Gyurgyik ddf3b84fba
[HW] [MSFT] Remove unnecessary assertions in `getReferencedModule` and add SymbolOpUserInterface to MSFT InstanceOp. (#1787)
Remove a lot of assertions and checks that are validated by the ODS and `verifyInstanceOp` function. Secondly,
use SymbolOpUserInterface in MSFT dialect to avoid O(n) lookup when verifying the InstanceOp.
2021-09-14 17:30:02 -07:00
cgyurgyik d3164681db [obvious] [Calyx] Use SymbolUserOpInterface. 2021-09-14 16:14:18 -07:00
Chris Gyurgyik 3287496640
[Calyx] [obvious] Update documentation for ComponentOp. 2021-09-14 15:08:05 -07:00
Chris Lattner 3d19aa7854 [HW] Enhance hw.instance to carry input/result port names.
This makes both hw.module* and hw.instance carry an argNames/resultNames
array attribute for the port names, and the verifier checks that they
line up.

This makes various queries on the instances much much faster (because
you don't need to resolve the module being referenced) and makes the
code more obviously correct in multithreaded situations.
2021-09-14 11:06:34 -07:00
Chris Gyurgyik d599e6cf4f
[Calyx] Add combinational trait. (#1781)
This adds a combinational trait to Calyx operations. We can throw this on all non-memory operations for now, 
since they are all combinational. Eventually we'll need to split this off. Closes #1739. Also fixes a bug where it 
was considering a memory load as a store, since the address ports are used when both storing and loading to 
a MemoryOp. A test is added to verify this no longer occurs.
2021-09-14 07:26:04 -07:00
Chris Gyurgyik 0465fa3780
[Calyx] Verify that sources of group ports and assignments are not logically complex. (#1774)
As discussed in #1769, some verifiers should be added to avoid giving the sources of group ports / assignments 
logically complex expressions. Also adds a verifier to ensure that GroupOp isn't being used as a CombGroupOp, and 
makes the necessary refactoring. This will be removed when native Calyx supports complex arguments for sources.
2021-09-13 22:32:24 -07:00
John Demme cf2433a6c6
[Seq] [CompRegOp] Make 'name' non-optional but allow it to be empty (#1772)
Make `seq.compreg`'s name follow the same semantics of `sv.reg`.
2021-09-13 21:13:47 -07:00
Chris Gyurgyik 8f8a156041
[Calyx] Verify CombGroupOp is combinational and certain primitive ports are driven together. (#1764)
This PR focuses on (2) objectives. First, verifying that combinational groups are indeed combinational. 
Combinational components are not supported yet, so component instances are always assumed to be 
combinational for now. Second, we also verify that certain ports are written or read together. For example, 
it does not make sense to write to a register without write_en being high. To aid in this, I added helper 
functions to access certain ports on primitive operations.
2021-09-13 17:12:06 -07:00
Chris Lattner e37c8833f7 [HW] Introduce a new ModulePortInfo which more cleanly delineates between input/outputs ports. NFC. 2021-09-12 21:54:25 -07:00
Chris Lattner b6988dd725 [HW/FIRRTL] Rename ModulePortInfo to just "PortInfo" NFC.
This applies to both instances and modules, and the more verbose name
doesn't help anyway.
2021-09-12 21:18:41 -07:00
Chris Lattner 18df843aa3 [HW] Change hw.instance syntax to include port names.
This pulls the port names and port types inline into the argument list,
and adds result port names to the output signature.  This increases readability
and is a stepping stone to hw.instance maintaining its own port names.
2021-09-12 17:54:53 -07:00
Chris Lattner f7ff083296 [HW] Generalize methods like getModulePortInfo to work on instances.
This is NFC other than changing a verification error due to an earlier
check.  This is plumbing to make way for port names being stored on
instances.
2021-09-12 15:24:49 -07:00
Chris Lattner da2ab3563c [HW] Switch InstanceOp's printer to a custom printer hook. NFC.
This makes room for printing port names in the argument and result
list.  Unfortunately we cannot use a custom<> directive with result
types, so we have to take over printing for the whole thing.
2021-09-12 13:09:39 -07:00
Prithayan Barua 6c6feea5d0
[FIRRTL][LowerToHW] Generate concurrent verification statements (#1768)
Add support for lowering to concurrent instead of immediate verification statements.
This emulates the SFC behavior of lowering printf encoded verification statements to concurrent statements.
1. Added `isConcurrent` attribute to `FIRRTL`  `assert/assume/cover`, and set the attribute only when lowering printf encoded statements.
2. Added a enum attribute `eventControl` with default value set to `AtPosEdge`, this can be used to represent the `sv::EventControlAttr`.  FIRRTL dialect is not using the `eventControl` attribute currently.
3. Also update the `LowerToHW` to lower the corresponding concurrent statements, depending on the `isConcurrent` attribute.
4. Add corresponding test cases.
2021-09-11 21:43:35 -07:00
Chris Lattner 5d759dd630 [HW] Add convenience builders for InstanceOp when you have a module already. NFC. 2021-09-11 12:02:28 -07:00
Chris Gyurgyik fb1ba5a36f
[Calyx] Add support for primitive port attributes. (#1762)
dds support for attributes on primitive ports. No emission is necessary for the ports of 
a primitive. Calyx primitive attributes are already supported as well. This closes #1744.
2021-09-10 12:22:31 -07:00
Andrew Lenharth 980a83aafa
[FIRRTL] Move name dropping later in the pipeline (#1767)
Part of #1758, move name dropping later in the pipeline. This makes the parser simpler, but more importantly, keeps names around until after we've processed annotations, some of which produce better output or might require the original names.
2021-09-10 11:51:52 -05:00
John Demme 8637a2abcf
[MSFT] Lower msft.instance to hw.instance (#1760)
Add a very straight-forward lowering of `msft::InstanceOp` to `hw::InstanceOp`. Part 2 of #1755.
2021-09-09 18:21:38 -07:00
John Demme 1ac16bb08b
[MSFT] Introduce `InstanceOp` (#1756)
`msft.instance` is intended to be like `hw.instance` but with headroom for MSFT-specific additions. It will lower to `hw.instance`. This just creates the op.

Step one of #1755 .
2021-09-09 14:09:48 -07:00
Fabian Schuiki 00d9fd353c
[FIRRTL] Add verbatim.wire operation
Add a `firrtl.verbatim.wire` operation which is similar to `*.expr` but
the resulting value has wire semantics. This is useful if the verbatim
string refers to a wire or port, and allows verbatims to be used in
connects or force statements.
2021-09-09 19:42:21 +02:00
Fabian Schuiki 3628ee5f8e
[FIRRTL] Add force operation
Add a `firrtl.force` operation which properly lowers to the
corresponding `sv.force` operation. There is additional discussion in
PR #1665 regarding the proliferation of these operations. If we end up
replicating a lot of the SV ops in the FIRRTL dialect, we might want to
look into ways to use casts and a general scheme to reuse the SV ops to
work with the FIRRTL-typed values directly.

This change unblocks work on the Grand Central signal driving PR for
now, but we'll have to revisit these ops likely in the future.
2021-09-09 19:40:22 +02:00
Fabian Schuiki 4fd92559b0
[SV] Allow InOutType for VerbatimExprOp
Allow the `sv.verbatim.expr` operation to produce an `InOutType` as
well, which is useful if the verbatim expression refers to a wire or
por. Operations such as `sv.force` can then be used to drive the expr.
2021-09-09 19:29:38 +02:00
John Demme 1b6d3ddc99 [MSFT] [NFC] Breaking up tablegen code 2021-09-08 20:58:54 -07:00
John Demme 17ba90d780
[Seq] Make `CompRegOp` name optional (#1754)
- Allow `seq.compreg` to be unnamed.
- Fixed the python integration test
2021-09-08 20:54:06 -07:00
John Demme 8dbd3890c9
[Seq] Give `CompRegOp` an optional name (#1751) 2021-09-08 19:28:59 -07:00
Schuyler Eldridge 5fbf9974e1
[Calyx] Remove C++20 Features, NFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-09-08 17:26:48 -04:00
Schuyler Eldridge 5e15a5bc0d
[Calyx] Use llvm::Optional over std::optional
Change PortInfo::getAttribute to return an llvm::Optional instead of
std::optional.  Generally, llvm:: is preferred over std:: and this also
works around MSVC wanting <optional> to be explicitly included for the
std:: variant to work.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-09-08 15:51:05 -04:00
Andrew Young 4637efd2db
[FIRRTL] Rename Directions enum to In and Out (#1748)
This switches the Direction enum cases from `Input` and `Output` to `In`
and `Out`, which matches the text we print in the IR.  This was
suggested in a review here:
https://github.com/llvm/circt/pull/1731#discussion_r703565808
2021-09-08 12:46:01 -07:00
Chris Gyurgyik 2f0ff9bda3
[Calyx] Parse attributes for BlockArguments and emit Calyx attributes. (#1727)
This PR is a collective effort to add Calyx attributes and emit them in the native compiler. This requires the addition of 
attributes for BlockArguments. The second part of the effort is proper emission of attributes that are found in the native 
compiler. Lastly, we add an optional attribute dictionary to the ComponentOp.
2021-09-08 11:16:19 -07:00
Andrew Young e38fa006ba
[HW] Implement SymbolUserOpInterface for HW's IntanceOp (#1747)
This speeds up verification by using a prebuilt symbol table to look up
the referenced module instead of a linear walk of the IR.  A similar
change was recently made to the FIRRTL InstanceOp in 438ffeb0.
2021-09-08 10:04:28 -07:00
Schuyler Eldridge ae75dfa7a9
[FIRRTL] Rewrite Grand Central Views/Interfaces, Add XMR Support (#1496)
Rewrite the Grand Central Views/Interface pass to fully support the
Grand Central Chisel API.  Specifically, enable support for interfaces
that instantiate other interfaces, support n-dimensional vectors of
interfaces, and add generation of XMRs to drive the interfaces.

Change Grand Central annotation scattering to represent interfaces with
a recursive structure.  Interfaces which instantiate other interfaces
will show up as BundleTypes in the elements where they are instantiated.
This keeps the interface representation intact until the Grand Central
pass can choose to handle this however it wants.

Also, change scattering to using numeric IDs instead of relying on string
matching to keep track of interface membership.

Add an MLIR Attribute hierarchy to represent this recursive structure.
Use this to factor out verification logic from business logic that
generates interfaces.

After this rewrite, the pass now works in the following way:

1. Extraction information is pulled out from the circuit along with
   annotations that describe the interfaces.

2. The full circuit is walked to build up information about companions,
   parents, and leaves that will be connected to the interface.

3. Interface annotations on the circuit are then recursively walked to
   generate interfaces, instantiate interfaces, and generate XMRs in a
   "mappings" file that drives the interfaces.

A CircuitNamespace utility is added to generate unique symbols for
interfaces and binds that need to be created.

Interfaces (and other collateral) are only extracted if an
ExtractGrandCentralAnnotation is present.  This is a deviation from the
Scala FIRRTL Compiler Grand Central pass where absence of that
annotation will cause an assert to fire.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-09-08 01:55:23 -04:00
Schuyler Eldridge d88b9cf4ab
[FIRRTL] Move InstancePaths to InstanceGraph, NFC
Make the GrandCentralTaps utility "InstancePaths" generally available by
moving it out of the anonymous namespace in GrandCentralTaps and into
circt::firrtl to cohabitate with InstanceGraph.  This is a generally
useful utility for computing paths.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-09-08 01:30:58 -04:00
Chris Gyurgyik 3d37a773dd
[Calyx] Rename ComponentPortInfo to PortInfo. (#1737)
With the introduction of the CellInterface, port information is needed for more than just components.
This changes ComponentPortInfo to just PortInfo.
2021-09-07 21:49:08 -07:00
Morten Borup Petersen b7a493429f
[Calyx] Implement combinational groups (#1736)
* [Calyx] Implement combinational groups

Adds a new kind of groups `CombOpGroup` for representing combinational groups. Fixes #1735.

- Combinational groups have no terminators.
- `group_go` and `group_done` are implicitly not allowed in comb_groups since they only accept `GroupOp`s as a parent.
- A new interface `GroupOpInterface` has been implemented to allow for sharing most of the logic for validation/emission of both `GroupOp` and `CombGroupOp`

Some of the tests in errors.mlir were failing - i suspect this is due to changes in the ordering of how validators are applied. Modified where necessary to isolate the error that is tested for.
2021-09-07 17:19:54 +01:00
Andrew Young 438ffeb010
[FIRRTL] implement SymbolUserOpInterface for InstanceOp (#1730)
This interface improves the performance of the instance op verifier by
using a pre-populated symbol table to look up the referenced module.
2021-09-06 22:50:51 -07:00
Andrew Young 47bfbee987
[ExportVerilog] Flip the default output of `sv.alwaysComb` ops (#1709)
We have decided that we want the default options in CIRCT to make use of
newer SystemVerilog constructs which improve the quality of output. In
the initial commit for adding a lowering option for `alwaysComb`
printing, we defaulted to print `always_comb` as `always @(*)`. This
flips the default setting and the changes the flag name to
`noAlwaysComb`, which is more in line with our desired output.

This is probably not the end of our efforts to customize the lowering of
`alwaysComb`: `always @(*)` and `always_comb` are not 100% equivalent
and have differences in their behavior at time 0.
2021-09-06 22:44:16 -07:00
Chris Gyurgyik 0b676c018a
[Calyx] Add emission for component Block Arguments. (#1726)
Before, there was an early short-circuit to ensure that if the Value has no defining operation, we would not 
TypeSwitch on it. A block argument will not have a defining operation. This led to the problem in #1724; 
since %done is a block argument of the ComponentOp, we just short-circuited. This pull request now 
checks to see if the value is a BlockArgument, and emits the respective port.
2021-09-06 07:58:37 -07:00
Chris Gyurgyik 9ba1dd32c5
[Calyx] [Obvious] Nit change to line limit. 2021-09-05 15:20:24 -07:00
Chris Gyurgyik 42f9e0a05a
[Calyx] [Obvious] Add licensing to CalyxInterfaces 2021-09-05 15:16:08 -07:00